$this->save_settings($iclsettings); } $filtered_id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE); $filtered_from_lang = filter_input(INPUT_POST, 'from_lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE); $filtered_to_lang = filter_input(INPUT_POST, 'to_lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE); echo '1|' . intval($filtered_id) . '|' . $this->get_language_status_text($filtered_from_lang, $filtered_to_lang); break; case 'icl_theme_localization_type': $theme_localization_type = @intval($_POST['icl_theme_localization_type']); icl_set_setting('theme_localization_type', $theme_localization_type, true); $theme_localization_load_td = @intval($_POST['icl_theme_localization_load_td']); icl_set_setting('theme_localization_load_textdomain', $theme_localization_load_td, true); $filtered_textdomain_value = filter_input(INPUT_POST, 'textdomain_value'); icl_set_setting('gettext_theme_domain_name', $filtered_textdomain_value, true); if ($theme_localization_type == 1) { icl_st_scan_theme_files(); } elseif ($theme_localization_type == 2) { $parent_theme = get_template_directory(); $child_theme = get_stylesheet_directory(); $languages_folders = array(); if ($found_folder = icl_tf_determine_mo_folder($parent_theme)) { $languages_folders['parent'] = $found_folder; } if ($parent_theme != $child_theme && ($found_folder = icl_tf_determine_mo_folder($child_theme))) { $languages_folders['child'] = $found_folder; } icl_set_setting('theme_language_folders', $languages_folders, true); } echo '1|' . $theme_localization_type; break; case 'icl_ct_user_pref':
function tl_rescan() { global $wpdb, $sitepress_settings; $scan_stats = icl_st_scan_theme_files(); if (isset($_POST['icl_load_mo']) && $_POST['icl_load_mo']) { $mo_files = icl_st_get_mo_files(TEMPLATEPATH); foreach ((array) $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) { foreach ($sitepress_settings['st']['theme_localization_domains'] as $tld) { $string_id = icl_get_string_id($original, 'theme ' . $tld); if ($string_id) { break; } } if (!$wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}icl_string_translations WHERE string_id=%d AND language=%s", $string_id, $lang))) { icl_add_string_translation($string_id, $lang, $translation, ICL_STRING_TRANSLATION_COMPLETE); } } } } } echo '1|' . $scan_stats; exit; }
function icl_st_scan_theme_files($dir = false, $recursion = 0) { require_once ICL_PLUGIN_PATH . '/inc/potx.php'; static $scan_stats = false; static $recursion, $scanned_files = array(); global $icl_scan_theme_found_domains, $sitepress, $sitepress_settings; if ($dir === false) { $dir = TEMPLATEPATH; } if (!$scan_stats) { $scan_stats = sprintf(__('Scanning theme folder: %s', 'wpml-string-translation'), $dir) . PHP_EOL; } $dh = opendir($dir); while (false !== ($file = readdir($dh))) { if ($file == "." || $file == "..") { continue; } if (is_dir($dir . "/" . $file)) { $recursion++; $scan_stats .= str_repeat("\t", $recursion) . sprintf(__('Opening folder: %s', 'wpml-string-translation'), $dir . "/" . $file) . PHP_EOL; icl_st_scan_theme_files($dir . "/" . $file, $recursion); $recursion--; } elseif (preg_match('#(\\.php|\\.inc)$#i', $file)) { // THE potx way $scan_stats .= str_repeat("\t", $recursion) . sprintf(__('Scanning file: %s', 'wpml-string-translation'), $dir . "/" . $file) . PHP_EOL; $scanned_files[] = $dir . "/" . $file; _potx_process_file($dir . "/" . $file, 0, '__icl_st_scan_theme_files_store_results', '_potx_save_version', POTX_API_7); } else { $scan_stats .= str_repeat("\t", $recursion) . sprintf(__('Skipping file: %s', 'wpml-string-translation'), $dir . "/" . $file) . PHP_EOL; } } if ($dir == TEMPLATEPATH && TEMPLATEPATH != STYLESHEETPATH) { static $double_scan = true; icl_st_scan_theme_files(STYLESHEETPATH); $double_scan = false; } if (!$recursion && (empty($double_scan) || !$double_scan)) { global $__icl_registered_strings; $scan_stats .= __('Done scanning files', 'wpml-string-translation') . PHP_EOL; $sitepress_settings['st']['theme_localization_domains'] = array_keys($icl_scan_theme_found_domains); $sitepress->save_settings($sitepress_settings); closedir($dh); $scan_stats_all = __('= Your theme was scanned for texts =', 'wpml-string-translation') . '<br />' . __('The following files were processed:', 'wpml-string-translation') . '<br />' . '<ol style="font-size:10px;"><li>' . join('</li><li>', $scanned_files) . '</li></ol>' . sprintf(__('WPML found %s strings. They were added to the string translation table.', 'wpml-string-translation'), count($__icl_registered_strings)) . '<br /><a href="#" onclick="jQuery(this).next().toggle();return false;">' . __('More details', 'wpml-string-translation') . '</a>' . '<textarea style="display:none;width:100%;height:150px;font-size:10px;">' . $scan_stats . '</textarea>'; return $scan_stats_all; } }
break; case 'icl_st_send_strings_all': icl_translation_send_untranslated_strings(explode(',', $_POST['languages'])); echo '1'; break; case 'icl_save_theme_localization_type': $icl_tl_type = (int) $_POST['icl_theme_localization_type']; $iclsettings['theme_localization_type'] = $icl_tl_type; if ($icl_tl_type == 1) { icl_st_scan_theme_files(); } $this->save_settings($iclsettings); echo '1|' . $icl_tl_type; break; case 'icl_tl_rescan': $scan_stats = icl_st_scan_theme_files(); if ($_POST['icl_load_mo']) { $mo_files = icl_st_get_mo_files(TEMPLATEPATH); foreach ((array) $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) { foreach ($this->settings['st']['theme_localization_domains'] as $tld) { $string_id = icl_get_string_id($original, 'theme ' . $tld); if ($string_id) { break; } } 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);