Пример #1
0
 protected function add_translations($contexts, $context_prefix)
 {
     if ($contexts) {
         $path = $this->current_path;
         $mo_files = icl_st_get_mo_files($path);
         foreach ((array) $mo_files as $m) {
             $i = preg_match('#[-]?([a-z_]+)\\.mo$#i', $m, $matches);
             if ($i && ($lang = $this->get_lang_code($matches[1]))) {
                 $tr_pairs = icl_st_load_translations_from_mo($m);
                 foreach ($tr_pairs as $original => $translation) {
                     foreach ($contexts as $tld) {
                         $this->fix_existing_string_with_wrong_context($original, $context_prefix . $tld);
                         if ($this->add_translation($original, $translation, $lang, $context_prefix . $tld)) {
                             break;
                         }
                     }
                 }
             }
         }
     }
 }
 function tl_rescan_p()
 {
     global $wpdb, $sitepress_settings;
     set_time_limit(0);
     if (preg_replace('#M$#', '', ini_get('memory_limit')) < 128) {
         ini_set('memory_limit', '128M');
     }
     $plugins = array();
     if (!empty($_POST['plugin'])) {
         foreach ($_POST['plugin'] as $plugin) {
             $plugins[] = array('file' => $plugin, 'mu' => 0);
             // regular plugins
         }
     }
     if (!empty($_POST['mu-plugin'])) {
         foreach ($_POST['mu-plugin'] as $plugin) {
             $plugins[] = array('file' => $plugin, 'mu' => 1);
             //mu plugins
         }
     }
     $scan_stats = '';
     foreach ($plugins as $p) {
         $plugin = $p['file'];
         if (false !== strpos($plugin, '/') && !$p['mu']) {
             $plugin = dirname($plugin);
         }
         if ($p['mu']) {
             $plugin_path = WPMU_PLUGIN_DIR . '/' . $plugin;
         } else {
             $plugin_path = WP_PLUGIN_DIR . '/' . $plugin;
         }
         $scan_stats .= icl_st_scan_plugin_files($plugin_path);
         if ($_POST['icl_load_mo'] && !$p['mu']) {
             $mo_files = icl_st_get_mo_files($plugin_path);
             foreach ($mo_files as $m) {
                 $i = preg_match('#[-]([a-z_]+)\\.mo$#i', $m, $matches);
                 if ($i && ($lang = $wpdb->get_var("SELECT code FROM {$wpdb->prefix}icl_locale_map WHERE locale='" . $matches[1] . "'"))) {
                     $tr_pairs = icl_st_load_translations_from_mo($m);
                     foreach ($tr_pairs as $original => $translation) {
                         $string_id = icl_get_string_id($original, 'plugin ' . basename($plugin_path));
                         if (!$wpdb->get_var("SELECT id FROM {$wpdb->prefix}icl_string_translations WHERE string_id={$string_id} AND language='{$lang}'")) {
                             icl_add_string_translation($string_id, $lang, $translation, ICL_STRING_TRANSLATION_COMPLETE);
                         }
                     }
                 }
             }
         }
     }
     echo '1|' . $scan_stats;
     exit;
 }
         $plugin = $p['file'];
         if (false !== strpos($plugin, '/') && !$p['mu']) {
             $plugin = dirname($plugin);
         }
         if ($p['mu']) {
             $plugin_path = WPMU_PLUGIN_DIR . '/' . $plugin;
         } else {
             $plugin_path = WP_PLUGIN_DIR . '/' . $plugin;
         }
         $scan_stats .= icl_st_scan_plugin_files($plugin_path);
         if ($_POST['icl_load_mo'] && !$p['mu']) {
             $mo_files = icl_st_get_mo_files($plugin_path);
             foreach ($mo_files as $m) {
                 $i = preg_match('#[-]([a-z_]+)\\.mo$#i', $m, $matches);
                 if ($i && ($lang = $wpdb->get_var("SELECT code FROM {$wpdb->prefix}icl_locale_map WHERE locale='" . $matches[1] . "'"))) {
                     $tr_pairs = icl_st_load_translations_from_mo($m);
                     foreach ($tr_pairs as $original => $translation) {
                         $string_id = icl_get_string_id($original, 'plugin ' . basename($plugin_path));
                         if (!$wpdb->get_var["SELECT id FROM {$wpdb->prefix}icl_string_translations WHERE string_id={$string_id} AND language='{$lang}'"]) {
                             icl_add_string_translation($string_id, $lang, $translation, ICL_STRING_TRANSLATION_COMPLETE);
                         }
                     }
                 }
             }
         }
     }
     echo '1|' . $scan_stats;
     break;
 case 'save_ct_user_pref':
     $users = $wpdb->get_col("SELECT id FROM {$wpdb->users}");
     foreach ($users as $uid) {