private function scan_theme_files($dir_or_file = false, $recursion = 0)
 {
     require_once WPML_ST_PATH . '/inc/potx.php';
     global $sitepress, $sitepress_settings;
     if ($dir_or_file === false) {
         $dir_or_file = $this->current_path;
     }
     $this->add_stat(sprintf(__('Scanning theme folder: %s', 'wpml-string-translation'), $dir_or_file), true);
     $dh = opendir($dir_or_file);
     while ($dh && false !== ($file = readdir($dh))) {
         if (0 === strpos($file, '.')) {
             continue;
         }
         if (is_dir($dir_or_file . "/" . $file)) {
             $recursion++;
             $this->add_stat(str_repeat("\t", $recursion) . sprintf(__('Opening folder: %s', 'wpml-string-translation'), $dir_or_file . "/" . $file));
             $this->scan_theme_files($dir_or_file . "/" . $file, $recursion);
             $recursion--;
         } elseif (preg_match('#(\\.php|\\.inc)$#i', $file)) {
             // THE potx way
             $this->add_stat(str_repeat("\t", $recursion) . sprintf(__('Scanning file: %s', 'wpml-string-translation'), $dir_or_file . "/" . $file));
             $this->add_scanned_file($dir_or_file . "/" . $file);
             _potx_process_file($dir_or_file . "/" . $file, 0, array($this, 'store_results'), '_potx_save_version', $this->get_default_domain());
         } else {
             $this->add_stat(str_repeat("\t", $recursion) . sprintf(__('Skipping file: %s', 'wpml-string-translation'), $dir_or_file . "/" . $file));
         }
     }
     if ($dir_or_file == TEMPLATEPATH && TEMPLATEPATH != STYLESHEETPATH) {
         $this->scan_theme_files(STYLESHEETPATH);
         $double_scan = false;
     }
     if (!$recursion && (empty($double_scan) || !$double_scan)) {
         global $__icl_registered_strings;
         $this->add_stat(__('Done scanning files', 'wpml-string-translation'));
         $sitepress_settings['st']['theme_localization_domains'] = array_keys($this->get_domains_found());
         $sitepress->save_settings($sitepress_settings);
         closedir($dh);
         $scanned_files = join('</li><li>', $this->get_scanned_files());
         $pre_stat = __('= Your theme was scanned for texts =', 'wpml-string-translation') . '<br />';
         $pre_stat .= __('The following files were processed:', 'wpml-string-translation') . '<br />';
         $pre_stat .= '<ol style="font-size:10px;"><li>' . $scanned_files;
         $pre_stat .= '</li></ol>';
         $pre_stat .= sprintf(__('WPML found %s strings. They were added to the string translation table.', 'wpml-string-translation'), count($__icl_registered_strings));
         $pre_stat .= '<br /><a href="#" onclick="jQuery(this).next().toggle();return false;">' . __('More details', 'wpml-string-translation') . '</a>';
         $pre_stat .= '<textarea style="display:none;width:100%;height:150px;font-size:10px;">';
         $this->add_stat($pre_stat, true);
         $this->add_stat('</textarea>');
     }
 }
예제 #2
0
function icl_st_scan_plugin_files($plugin, $recursion = 0)
{
    require_once ICL_PLUGIN_PATH . '/inc/potx.php';
    static $recursion, $scanned_files = array();
    static $scan_stats = false;
    global $icl_scan_plugin_found_domains, $icl_st_p_scan_plugin_id, $sitepress, $sitepress_settings;
    if (!$recursion) {
        $icl_st_p_scan_plugin_id = str_replace(WP_PLUGIN_DIR . '/', '', $plugin);
        $icl_st_p_scan_plugin_id = str_replace(WPMU_PLUGIN_DIR . '/', '', $icl_st_p_scan_plugin_id);
    }
    if (is_file($plugin) && !$recursion) {
        // case of one-file plugins
        $scan_stats = sprintf(__('Scanning file: %s', 'wpml-string-translation'), $plugin) . PHP_EOL;
        _potx_process_file($plugin, 0, '__icl_st_scan_plugin_files_store_results', '_potx_save_version', POTX_API_7);
        $scanned_files[] = $plugin;
    } else {
        $dh = opendir($plugin);
        while (false !== ($file = readdir($dh))) {
            if (0 === strpos($file, '.')) {
                continue;
            }
            if (is_dir($plugin . "/" . $file)) {
                $recursion++;
                $scan_stats .= str_repeat("\t", $recursion - 1) . sprintf(__('Opening folder: %s', 'wpml-string-translation'), "/" . $file) . PHP_EOL;
                icl_st_scan_plugin_files($plugin . "/" . $file, $recursion);
                $recursion--;
            } elseif (preg_match('#(\\.php|\\.inc)$#i', $file)) {
                $scan_stats .= str_repeat("\t", $recursion) . sprintf(__('Scanning file: %s', 'wpml-string-translation'), "/" . $file) . PHP_EOL;
                $scanned_files[] = "/" . $file;
                _potx_process_file($plugin . "/" . $file, 0, '__icl_st_scan_plugin_files_store_results', '_potx_save_version', POTX_API_7);
            } else {
                $scan_stats .= str_repeat("\t", $recursion) . sprintf(__('Skipping file: %s', 'wpml-string-translation'), "/" . $file) . PHP_EOL;
            }
        }
    }
    if (!$recursion) {
        global $__icl_registered_strings;
        if (is_null($__icl_registered_strings)) {
            $__icl_registered_strings = array();
        }
        $scan_stats .= __('Done scanning files', 'wpml-string-translation') . PHP_EOL;
        /*
        if(is_array($icl_scan_plugin_found_domains)){
            $existing_domains = $sitepress_settings['st']['plugins_localization_domains'];
            if(is_array($existing_domains)){
                $sitepress_settings['st']['plugins_localization_domains'] = array_unique(array_merge(array_keys($icl_scan_plugin_found_domains), $existing_domains));
            }else{
                $sitepress_settings['st']['plugins_localization_domains'] = array_keys($icl_scan_plugin_found_domains);
            }
            $sitepress->save_settings($sitepress_settings);
        }
        */
        unset($icl_st_p_scan_plugin_id);
        $scan_stats = '<textarea style="width:100%;height:150px;font-size:10px;">' . $scan_stats . "\n" . count($scanned_files) . ' scanned files' . "\n";
        if (count($__icl_registered_strings)) {
            $scan_stats .= sprintf(__('WPML found %s strings. They were added to the string translation table.', 'wpml-string-translation'), count($__icl_registered_strings)) . "\n";
        } else {
            $scan_stats .= __('No strings found.', 'wpml-string-translation') . "\n";
        }
        $scan_stats .= '</textarea>';
        $scan_stats_ret = $scan_stats;
        $scan_stats = false;
        return $scan_stats_ret;
    }
}
 function plugin_po_file_download($file = false, $recursion = 0)
 {
     global $__wpml_st_po_file_content;
     if (empty($file) && !empty($_GET['file'])) {
         $file = WP_PLUGIN_DIR . '/' . $_GET['file'];
     }
     if (empty($file)) {
         return;
     }
     if (is_null($__wpml_st_po_file_content)) {
         $__wpml_st_po_file_content = '';
     }
     require_once ICL_PLUGIN_PATH . '/inc/potx.php';
     if (is_file($file) && WP_PLUGIN_DIR == dirname($file)) {
         _potx_process_file($file, 0, '__pos_scan_store_results', '_potx_save_version', POTX_API_7);
     } else {
         if (!$recursion) {
             $file = dirname($file);
         }
         if (is_dir($file)) {
             $dh = opendir($file);
             while ($dh && false !== ($f = readdir($dh))) {
                 if (0 === strpos($f, '.')) {
                     continue;
                 }
                 $this->plugin_po_file_download($file . '/' . $f, $recursion + 1);
             }
         } elseif (preg_match('#(\\.php|\\.inc)$#i', $file)) {
             _potx_process_file($file, 0, '__pos_scan_store_results', '_potx_save_version', POTX_API_7);
         }
     }
     if (!$recursion) {
         $po = "";
         $po .= '# This file was generated by WPML' . PHP_EOL;
         $po .= '# WPML is a WordPress plugin that can turn any WordPress site into a full featured multilingual content management system.' . PHP_EOL;
         $po .= '# https://wpml.org' . PHP_EOL;
         $po .= 'msgid ""' . PHP_EOL;
         $po .= 'msgstr ""' . PHP_EOL;
         $po .= '"Content-Type: text/plain; charset=utf-8\\n"' . PHP_EOL;
         $po .= '"Content-Transfer-Encoding: 8bit\\n"' . PHP_EOL;
         $po_title = 'WPML_EXPORT';
         if (isset($_GET['context'])) {
             $po_title .= '_' . $_GET['context'];
         }
         $po .= '"Project-Id-Version:' . $po_title . '\\n"' . PHP_EOL;
         $po .= '"POT-Creation-Date: \\n"' . PHP_EOL;
         $po .= '"PO-Revision-Date: \\n"' . PHP_EOL;
         $po .= '"Last-Translator: \\n"' . PHP_EOL;
         $po .= '"Language-Team: \\n"' . PHP_EOL;
         $translation_language = 'en';
         if (isset($_GET['translation_language'])) {
             $translation_language = $_GET['translation_language'];
         }
         $po .= '"Language:' . $translation_language . '\\n"' . PHP_EOL;
         $po .= '"MIME-Version: 1.0\\n"' . PHP_EOL;
         $po .= $__wpml_st_po_file_content;
         header("Content-Type: application/force-download");
         header("Content-Type: application/octet-stream");
         header("Content-Type: application/download");
         header('Content-Transfer-Encoding: binary');
         header("Content-Disposition: attachment; filename=\"" . basename($file) . ".po\"");
         header("Content-Length: " . strlen($po));
         echo $po;
         exit(0);
     }
 }
예제 #4
0
            break;
        case '--debug':
            $files = array(__FILE__);
            break;
        case '--auto':
            $files = _potx_explore_dir('', '*', POTX_API_CURRENT, TRUE);
            break;
    }
}
// Fall back to --auto, if --files are not specified
if (empty($files)) {
    $files = _potx_explore_dir('', '*', POTX_API_CURRENT, TRUE);
}
foreach ($files as $file) {
    potx_status('status', "Processing {$file}...\n");
    _potx_process_file($file);
}
_potx_build_files(POTX_STRING_RUNTIME, $build_mode);
_potx_build_files(POTX_STRING_INSTALLER, POTX_BUILD_SINGLE, 'installer');
_potx_write_files();
potx_status('status', "\nDone.\n");
return;
// These are never executed, you can run potx-cli.php on itself to test it
// -----------------------------------------------------------------------------
$a = t("Double quoted test string");
$b = t("Test string with %variable", array('%variable' => t('variable replacement')));
$c = t('Single qouted test string');
$d = t("Special\ncharacters");
$e = t('Special\\ncharacters');
$f = t("Embedded {$variable}");
$g = t('Embedded $variable');
 private function scan_plugin_files($dir_or_file = false, $recursion = 0)
 {
     require_once WPML_ST_PATH . '/inc/potx.php';
     global $icl_st_p_scan_plugin_id;
     if ($dir_or_file === false) {
         $dir_or_file = $this->current_path;
     }
     if (wpml_st_file_path_is_valid($dir_or_file)) {
         if (!$recursion) {
             $icl_st_p_scan_plugin_id = str_replace(WP_PLUGIN_DIR . '/', '', $dir_or_file);
             $icl_st_p_scan_plugin_id = str_replace(WPMU_PLUGIN_DIR . '/', '', $icl_st_p_scan_plugin_id);
         }
         if (is_file($dir_or_file) && !$recursion) {
             // case of one-file plugins
             $this->add_stat(sprintf(__('Scanning file: %s', 'wpml-string-translation'), $dir_or_file));
             _potx_process_file($dir_or_file, 0, array($this, 'store_results'), '_potx_save_version', $this->get_default_domain());
             $this->add_scanned_file($dir_or_file);
         } else {
             $dh = opendir($dir_or_file);
             while ($dh && false !== ($file = readdir($dh))) {
                 if (0 === strpos($file, '.')) {
                     continue;
                 }
                 if (is_dir($dir_or_file . "/" . $file)) {
                     $recursion++;
                     $this->add_stat(str_repeat("\t", $recursion - 1) . sprintf(__('Opening folder: %s', 'wpml-string-translation'), "/" . $file));
                     $this->scan_plugin_files($dir_or_file . "/" . $file, $recursion);
                     $recursion--;
                 } elseif (preg_match('#(\\.php|\\.inc)$#i', $file)) {
                     $this->add_stat(str_repeat("\t", $recursion) . sprintf(__('Scanning file: %s', 'wpml-string-translation'), "/" . $file));
                     $this->add_scanned_file("/" . $file);
                     _potx_process_file($dir_or_file . "/" . $file, 0, array($this, 'store_results'), '_potx_save_version', $this->get_default_domain());
                 } else {
                     $this->add_stat(str_repeat("\t", $recursion) . sprintf(__('Skipping file: %s', 'wpml-string-translation'), "/" . $file));
                 }
             }
         }
     } else {
         $this->add_stat(str_repeat("\t", $recursion) . sprintf(__('Invalid file: %s', 'wpml-string-translation'), "/" . $dir_or_file));
     }
     if (!$recursion) {
         unset($icl_st_p_scan_plugin_id);
     }
 }