/** * @internal Fetch action handler * @attribute[RequestParam('languages','array',false)] */ function Fetch($languages = false) { global $CONFIG; $this->_contentdiv->content("<h1>Fetch strings</h1>"); $response = $this->request(array('action' => 'list_languages')); if (!$languages) { $div = $this->_contentdiv->content(new Form()); foreach ($response->list as $lang) { $cb = $div->content(new CheckBox('languages[]')); $cb->value = $lang->code; $div->content($cb->CreateLabel($lang->name . " ({$lang->code}, {$lang->percentage}% complete)")); $div->content("<br/>"); } $a = $div->content(new Anchor('#', 'Select all')); $a->script("\$('#{$a->id}').click(function(){ \$('input','#{$div->id}').attr('checked',true); });"); $div->content(" "); $div->AddSubmit("Fetch"); $pid = $GLOBALS['CONFIG']['translation']['sync']['poeditor_project_id']; $div->content("<br/><a href='http://poeditor.com/projects/view?id={$pid}' target='_blank'>Open POEditor.com</a>"); return; } $head = array(); foreach ($response->list as $lang) { $head[$lang->code] = array('percentage_complete' => $lang->percentage / 100, 'percentage_empty' => 1 - $lang->percentage / 100, 'syntax_error_qty' => 0); } $info = "\$GLOBALS['translation']['properties'] = " . var_export($head, true); $defaults = $this->fetchTerms($CONFIG['localization']['default_language']); foreach (array_unique($languages) as $lang) { $lang = strtolower($lang); $data = $lang == $CONFIG['localization']['default_language'] ? $defaults : $this->fetchTerms($lang, $defaults); $strings = "\$GLOBALS['translation']['strings'] = " . var_export($data, true); file_put_contents($CONFIG['translation']['data_path'] . $lang . '.inc.php', "<?php\n{$info};\n{$strings};\n"); $this->_contentdiv->content("<div>Created translation file for {$lang}</div>"); } $ds = model_datasource($GLOBALS['CONFIG']['translation']['sync']['datasource']); $ds->ExecuteSql("TRUNCATE TABLE wdf_unknown_strings"); $this->_contentdiv->content("<div>Cleared the unknown strings table</div>"); foreach (cache_list_keys() as $key) { if (starts_with($key, 'lang_')) { cache_del($key); } } $this->_contentdiv->content("<div>Cleared the string cache</div>"); }
/** * @internal Fetch action handler * @attribute[RequestParam('languages','array',false)] */ function Fetch($languages = false) { global $CONFIG; $this->_contentdiv->content("<h1>Fetch strings</h1>"); $db_languages = $this->ds->ExecuteSql("SELECT DISTINCT lang FROM wdf_translations ORDER BY lang")->Enumerate('lang', false); $max = $this->ds->ExecuteScalar("SELECT MAX(cnt) FROM (SELECT count(*) as cnt FROM wdf_translations GROUP BY lang) AS x"); foreach ($db_languages as $i => $lang) { $count = $this->ds->ExecuteScalar("SELECT count(*) FROM wdf_translations WHERE lang=?", $lang); $db_languages[$i] = new stdClass(); $db_languages[$i]->name = Localization::getCultureInfo($lang)->EnglishName; $db_languages[$i]->code = $lang; $db_languages[$i]->percentage = round($count / $max * 100, 0); } if (!$languages) { $div = $this->_contentdiv->content(new Form()); foreach ($db_languages as $lang) { $cb = $div->content(new CheckBox('languages[]')); $cb->value = $lang->code; $div->content($cb->CreateLabel($lang->name . " ({$lang->code}, {$lang->percentage}% complete)")); $div->content("<br/>"); } $a = $div->content(new Anchor('#', 'Select all')); $a->script("\$('#{$a->id}').click(function(){ \$('input','#{$div->id}').attr('checked',true); });"); $div->content(" "); $div->AddSubmit("Fetch"); return; } $head = array(); foreach ($db_languages as $lang) { $head[$lang->code] = array('percentage_complete' => $lang->percentage / 100, 'percentage_empty' => 1 - $lang->percentage / 100, 'syntax_error_qty' => 0); } $info = "\$GLOBALS['translation']['properties'] = " . var_export($head, true); $defaults = $this->fetchTerms($CONFIG['localization']['default_language']); foreach (array_unique($languages) as $lang) { $lang = strtolower($lang); $data = $lang == $CONFIG['localization']['default_language'] ? $defaults : $this->fetchTerms($lang, $defaults); $strings = "\$GLOBALS['translation']['strings'] = " . var_export($data, true); file_put_contents($CONFIG['translation']['data_path'] . $lang . '.inc.php', "<?php\n{$info};\n{$strings};\n"); $this->_contentdiv->content("<div>Created translation file for {$lang}</div>"); } $ds = model_datasource($GLOBALS['CONFIG']['translation']['sync']['datasource']); $ds->ExecuteSql("TRUNCATE TABLE wdf_unknown_strings"); $this->_contentdiv->content("<div>Cleared the unknown strings table</div>"); foreach (cache_list_keys() as $key) { if (starts_with($key, 'lang_')) { cache_del($key); } } $this->_contentdiv->content("<div>Cleared the string cache</div>"); }
/** * @internal SysAdmin cache manager. * @attribute[RequestParam('search','string',false)] * @attribute[RequestParam('show_info','bool',false)] * @attribute[RequestParam('kind','string','Search key')] */ function Cache($search, $show_info, $kind) { $this->content("<h1>Cache contents</h1>"); $form = $this->content(new Form()); $form->AddText('search', $search); $form->AddSubmit('Search key')->name = 'kind'; $form->AddSubmit('Search content')->name = 'kind'; $form->content(' '); $form->content(new Anchor(buildQuery('sysadmin', 'cacheclear'), 'Clear the complete cache')); if (system_is_module_loaded('globalcache')) { $form->content(' '); $form->content(new Anchor(buildQuery('sysadmin', 'cache', 'show_info=1'), 'Global cache info')); } $form->content('<div><b>Predefined searches:</b><br/>'); foreach ($this->PrefedinedCacheSearches as $s) { $form->content(new Anchor(buildQuery('sysadmin', 'cache', "search={$s}"), "{$s}")); $form->content(' '); } $form->content('</div>'); if (!isset($_SESSION['admin_handler_last_cache_searches'])) { $_SESSION['admin_handler_last_cache_searches'] = array(); } if (count($_SESSION['admin_handler_last_cache_searches']) > 0) { $form->content('<div><b>Last searches:</b><br/>'); foreach ($_SESSION['admin_handler_last_cache_searches'] as $s) { list($k, $s) = explode(":", $s); $form->content(new Anchor(buildQuery('sysadmin', 'cache', "search={$s}" . ($k != 'key' ? '&kind=Search content' : '')), "{$k}:{$s}")); $form->content(' '); } $form->content('</div>'); } if ($show_info && system_is_module_loaded('globalcache')) { $form->content("<pre>" . globalcache_info() . "</pre>"); } if ($search) { if (!in_array($search, $this->PrefedinedCacheSearches)) { $_SESSION['admin_handler_last_cache_searches'][] = $kind == 'Search content' ? "content:{$search}" : "key:{$search}"; $_SESSION['admin_handler_last_cache_searches'] = array_unique($_SESSION['admin_handler_last_cache_searches']); } $this->content("<br/>"); $tabform = $this->content(new Form()); $tabform->action = buildQuery('sysadmin', 'cachedelmany'); $tab = $tabform->content(new Table())->addClass('bordered'); $tab->SetHeader('', 'key', 'action'); $q = buildQuery('sysadmin', 'cachedel'); foreach (cache_list_keys() as $key) { $found = $kind == 'Search content' ? stripos(render_var(cache_get($key, "")), $search) !== false : stripos($key, $search) !== false; if ($found) { $cb = new CheckBox('keys[]'); $cb->value = $key; $del = new Anchor('', 'delete'); $del->onclick = "\$.post('{$q}',{key:'" . addslashes($key) . "'},function(){ \$('#{$del->id}').parents('.tr').fadeOut(function(){ \$(this).remove(); }); })"; $tab->AddNewRow($cb, $key, $del); } } $footer = $tab->Footer()->NewCell(); $footer->colspan = 2; $footer->content(new Anchor('', 'all'))->onclick = "\$('#{$tab->id} .tbody input').prop('checked',true);"; $footer->content(' '); $footer->content(new Anchor('', 'none'))->onclick = "\$('#{$tab->id} .tbody input').prop('checked',false)"; $footer = $tab->Footer()->NewCell(); $footer->content(new Anchor('', 'delete'))->onclick = "\$('#{$tabform->id}').submit()"; } }