Dotclear

source: plugins/buildtools/class.dc.maintenance.buildtools.php @ 1978:42d6677a2f22

Revision 1978:42d6677a2f22, 2.2 KB checked in by Dsls, 12 years ago (diff)

small code fix in buildtools (thx JCDenis)

Line 
1<?php
2
3
4class dcMaintenanceBuildtools extends dcMaintenanceTask
5{
6     protected $group = 'other';
7
8     protected function init()
9     {
10          $this->task         = __('Generate fake l10n');
11          $this->success           = __('fake l10n file generated.');
12          $this->error        = __('Failed to generate fake l10n file.');
13     }
14
15     public function execute()
16     {
17          global $core;
18          $widget = $this->core->plugins->getModules("widgets");
19          include $widget['root'].'/_default_widgets.php';
20         
21          $faker = new l10nFaker($GLOBALS['core']);
22          $faker->generate_file();
23          return true;
24     }
25}
26
27class l10nFaker {
28     protected $core;
29     protected $bundled_plugins;
30     
31     public function __construct($core) {
32          $this->core = $core;
33          $this->bundled_plugins = array(
34               "aboutConfig","akismet","antispam","attachments","blogroll",
35               "blowupConfig","daInstaller","fairTrackbacks","importExport",
36               "maintenance","pages","pings","simpleMenu","tags","themeEditor",
37               "userPref","widgets"
38          );
39          $this->core->media = new dcMedia($this->core);
40     }
41
42     protected function fake_l10n($str) {
43          return sprintf('__("%s");'."\n",str_replace('"','\\"',$str));
44     }
45     public function generate_file() {
46          global $__widgets;
47          global $__autoload;
48         
49          $main = "<?php\n";
50          $plugin = "<?php\n";
51          $main .= "# Media sizes\n\n";
52          foreach ($this->core->media->thumb_sizes as $k=> $v) {
53               $main .= $this->fake_l10n($v[2]);
54          }
55          $post_types = $this->core->getPostTypes();
56          $main .= "\n# Post types \n\n";
57          foreach ($post_types as $k => $v) {
58               $main .= $this->fake_l10n($v['label']);
59          }
60          $ws = $this->core->auth->user_prefs->favorites;
61          $main .= "\n# Favorites \n\n";
62          foreach ($ws->dumpPrefs() as $k => $v) {
63               $fav = unserialize($v['value']);
64               $main .= $this->fake_l10n($fav['title']);
65          }
66          file_put_contents(dirname($__autoload['dcCore']).'/_fake_l10n.php', $main);
67          $plugin .= "\n# Plugin names \n\n";
68          foreach ($this->bundled_plugins as $id) {
69               $p = $this->core->plugins->getModules($id);
70               $plugin .= $this->fake_l10n($p['desc']);
71          }
72          $plugin .= "\n# Widget settings names \n\n";
73          $widgets = $__widgets->elements();
74          foreach ($widgets as $w) {
75               $plugin .= $this->fake_l10n($w->desc());
76          }
77          mkdir(dirname(__FILE__)."/../_fake_plugin");
78          file_put_contents(dirname(__FILE__).'/../_fake_plugin/_fake_l10n.php', $plugin);
79     }
80}
Note: See TracBrowser for help on using the repository browser.

Sites map