Dotclear

source: plugins/buildtools/class.dc.maintenance.buildtools.php @ 3731:3770620079d4

Revision 3731:3770620079d4, 2.8 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Simplify licence block at the beginning of each file

Line 
1<?php
2/**
3 * @brief buildtools, a plugin for Dotclear 2
4 *
5 * @package Dotclear
6 * @subpackage Plugins
7 *
8 * @copyright Olivier Meunier & Association Dotclear
9 * @copyright GPL-2.0-only
10 */
11
12class dcMaintenanceBuildtools extends dcMaintenanceTask
13{
14    protected $tab   = 'dev';
15    protected $group = 'l10n';
16
17    protected function init()
18    {
19        $this->task        = __('Generate fake l10n');
20        $this->success     = __('fake l10n file generated.');
21        $this->error       = __('Failed to generate fake l10n file.');
22        $this->description = __('Generate a php file that contents strings to translate that are not be done with core tools.');
23    }
24
25    public function execute()
26    {
27        global $core;
28        $widget = $this->core->plugins->getModules("widgets");
29        include $widget['root'] . '/_default_widgets.php';
30
31        $faker = new l10nFaker($GLOBALS['core']);
32        $faker->generate_file();
33        return true;
34    }
35}
36
37class l10nFaker
38{
39    protected $core;
40    protected $bundled_plugins;
41
42    public function __construct($core)
43    {
44        $this->core            = $core;
45        $this->bundled_plugins = explode(',', DC_DISTRIB_PLUGINS);
46        $this->core->media     = new dcMedia($this->core);
47    }
48
49    protected function fake_l10n($str)
50    {
51        return sprintf('__("%s");' . "\n", str_replace('"', '\\"', $str));
52    }
53    public function generate_file()
54    {
55        global $__widgets;
56        global $__autoload;
57
58        $main   = "<?php\n";
59        $plugin = "<?php\n";
60        $main .= "# Media sizes\n\n";
61        foreach ($this->core->media->thumb_sizes as $k => $v) {
62            $main .= $this->fake_l10n($v[2]);
63        }
64        $post_types = $this->core->getPostTypes();
65        $main .= "\n# Post types \n\n";
66        foreach ($post_types as $k => $v) {
67            $main .= $this->fake_l10n($v['label']);
68        }
69        $ws = $this->core->auth->user_prefs->favorites; // Favs old school !
70        if ($ws) {
71            $main .= "\n# Favorites \n\n";
72            foreach ($ws->dumpPrefs() as $k => $v) {
73                $fav = unserialize($v['value']);
74                $main .= $this->fake_l10n($fav['title']);
75            }
76        }
77        file_put_contents(dirname($__autoload['dcCore']) . '/_fake_l10n.php', $main);
78        $plugin .= "\n# Plugin names \n\n";
79        foreach ($this->bundled_plugins as $id) {
80            $p = $this->core->plugins->getModules($id);
81            $plugin .= $this->fake_l10n($p['desc']);
82        }
83        $plugin .= "\n# Widget settings names \n\n";
84        $widgets = $__widgets->elements();
85        foreach ($widgets as $w) {
86            $plugin .= $this->fake_l10n($w->desc());
87        }
88        mkdir(dirname(__FILE__) . "/../_fake_plugin");
89        file_put_contents(dirname(__FILE__) . '/../_fake_plugin/_fake_l10n.php', $plugin);
90    }
91}
Note: See TracBrowser for help on using the repository browser.

Sites map