Esempio n. 1
0
function JB_merge_language_files($force_update = false)
{
    if (JB_DEMO_MODE == 'YES') {
        return;
    }
    global $label;
    // load in the main english_default labels
    $source_label = array();
    include_once jb_get_english_default_dir() . 'english_default.php';
    // the master lang/english_default
    $source_label = array_merge($source_label, $label);
    // default english labels
    unset($label);
    $label = array();
    $last_mtime = filemtime(jb_get_english_default_dir() . 'english_default.php');
    // load the english_default.php labels for all themes
    //
    global $JB_LANG_THEMES;
    $themes = $JB_LANG_THEMES;
    if (isset($_REQUEST['jb_theme'])) {
        // Admin->Main Config, Admin-> Languagess
        if (isset($_REQUEST['lang_code'])) {
            $lang = $_REQUEST['lang_code'];
            // comes from Admin->Languages
        } else {
            $lang = $_SESSION['LANG'];
        }
        $themes[$lang] = $_REQUEST['jb_theme'];
    }
    $themes = array_unique($themes);
    // get the english_default.php for each theme
    foreach ($themes as $key => $theme) {
        $theme_path = JB_get_theme_dir() . $theme . '/';
        if (file_exists($theme_path . 'lang/english_default.php')) {
            include $theme_path . 'lang/english_default.php';
            $source_label = array_merge($source_label, $label);
            // default english labels
            unset($label);
            $label = array();
            $m_time = filemtime($theme_path . "lang/english_default.php");
            if ($m_time > $last_mtime) {
                $last_mtime = $m_time;
            }
        }
    }
    if ($force_update) {
        $last_mtime = time();
    }
    // Now we should have all the source labels in $source_label and
    // last modification time in $last_mtime
    // Grab all the languages installed
    $sql = "SELECT * FROM lang  ";
    $result = JB_mysql_query($sql) or die(mysql_error());
    // Now merge the english_default.php strings with the language files
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        // now that we have all the source labels, we can merge them with
        // the langauge file. Any key that is present in the source, but
        // not present
        if (is_writable(jB_get_lang_dir() . $row['lang_filename'])) {
            if ($last_mtime > filemtime(jB_get_lang_dir() . $row['lang_filename'])) {
                echo "Merging language strings for " . jb_escape_html($row['lang_filename']) . ".. <br>";
                // Now merge the english defaults with the langauge file
                include jB_get_lang_dir() . $row['lang_filename'];
                // customized labels
                $dest_label = array_merge($source_label, $label);
                $label = null;
                // write out the new file:
                $out = "<?php\n";
                $out .= "///////////////////////////////////////////////////////////////////////////\n";
                $out .= "// IMPORTANT NOTICE\n";
                $out .= "///////////////////////////////////////////////////////////////////////////\n";
                $out .= "// This file was generated by a script!\n";
                $out .= "// (JB_merge_language_files() function)\n";
                $out .= "// Please do not edit the language files by hand\n";
                $out .= "// - please always use the Language Translation / Editing tool found\n";
                $out .= "// in Admin->Languages\n";
                $out .= "// To add a new phrase for the \$label, please edit english_default.php, and\n";
                $out .= "// then vist Admin->Main Summary where the language files will be\n";
                $out .= "// automatically merged with this file.\n";
                $out .= "///////////////////////////////////////////////////////////////////////////\n";
                foreach ($dest_label as $key => $val) {
                    $val = str_replace("'", "\\'", $val);
                    $out .= "\$label['{$key}']='" . JB_clean_str($val) . "'; \n";
                }
                $out .= "?>\n";
                $handler = fopen(jB_get_lang_dir() . $row['lang_filename'], "w");
                fputs($handler, $out);
                fclose($handler);
            }
        } else {
            echo "<font color='red'><b>- " . jB_get_lang_dir() . $row['lang_filename'] . " file is not writable. Give write permissions (" . decoct(JB_NEW_FILE_CHMOD) . ") to " . jB_get_lang_dir() . $row['lang_filename'] . " file and then disable & re-enable this plugin</b></font><br>";
        }
    }
    if ($out) {
        echo " Done.<br>";
    }
}
Esempio n. 2
0
# You can obtain one at http://mozilla.org/MPL/2.0/.
###########################################################################
@set_time_limit(280);
ini_set('session.gc_maxlifetime', 60 * 60 * 4);
// 4 hours
require '../config.php';
require "admin_common.php";
//ini_set (session.use_trans_sid, false);
JB_admin_header('Admin->Translation / Editing Tool');
$label = array();
$sql = "SELECT * FROM lang WHERE lang_code='" . jb_escape_sql($_REQUEST['target_lang']) . "' ";
$result = JB_mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$lang_filename = $row['lang_filename'];
$lang_name = $row['name'];
include jb_get_english_default_dir() . "english_default.php";
// main english default
JBPLUG_append_english_default_labels();
// require the english_defult.php files for the modules
JB_theme_append_english_default_labels();
$source_label = $label;
// default english labels
include jB_get_lang_dir() . $lang_filename;
$dest_label = $label;
// dest labels
// preload the source code, preg the hash key and use it as a key for the line
$handle = fopen(jB_get_lang_dir() . "english_default.php", "rb");
while ($buffer = fgets($handle, 4096)) {
    if (preg_match('#\\$label\\[.([a-z0-9_]+).\\].*#i', $buffer, $m)) {
        $source_code[$m[1]] = $buffer;
    }
Esempio n. 3
0
function JBPLUG_merge_english_default_files()
{
    JBPLUG_require_all_plugins();
    global $_JB_PLUGINS;
    $source_label = array();
    // load in the main english_default labels
    include_once jb_get_english_default_dir() . "english_default.php";
    // the master lang/english_default
    $source_label = array_merge($source_label, $label);
    // default english labels
    $label = array();
    $last_mtime = filemtime(jb_get_english_default_dir() . "english_default.php");
    $sql = "SELECT * FROM lang  ";
    $result = JB_mysql_query($sql);
    // Now merge the english_default.php strings with the language files
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        echo "Merging language strings for " . jb_escape_html($row['lang_filename']) . "..<br>";
        /// for each of the plugins, load in the plugin's english default
        foreach ($_JB_PLUGINS as $class => $obj) {
            $plugin_english_default_path = dirname(__FILE__) . "/plugins/{$class}/lang/english_default.php";
            if (!file_exists($plugin_english_default_path)) {
                continue;
                // skip
            }
            include_once $plugin_english_default_path;
            // load the labels from the plugins
            $source_label = array_merge($source_label, $label);
            $label = array();
            $m_time = filemtime($plugin_english_default_path);
            if ($m_time > $last_mtime) {
                $last_mtime = $m_time;
            }
        }
        // now that we have all the source labels, we can merge them with
        // the langauge file. Any key that is present in the source, but
        // not present in the language file then we merge it.
        if (is_writable(jB_get_lang_dir() . $row['lang_filename'])) {
            if ($last_mtime > filemtime(jB_get_lang_dir() . $row['lang_filename'])) {
                // Now merge the english defaults with the langauge file
                include jB_get_lang_dir() . $row['lang_filename'];
                // customized labels
                $dest_label = array_merge($source_label, $label);
                $label = array();
                // write out the new file:
                $out = "<?php\n";
                $out .= "///////////////////////////////////////////////////////////////////////////\n";
                $out .= "// IMPORTANT NOTICE\n";
                $out .= "///////////////////////////////////////////////////////////////////////////\n";
                $out .= "// This file was generated by a script!\n";
                $out .= "// (JBPLUG_merge_english_default_files() function)\n";
                $out .= "// Please do not edit the language files by hand\n";
                $out .= "// - please always use the Language Translation / Editing tool found\n";
                $out .= "// in Admin->Languages\n";
                $out .= "// To add a new phrase for the \$label, please edit english_default.php, and\n";
                $out .= "// then vist Admin->Main Summary where the language files will be\n";
                $out .= "// automatically merged with this file.\n";
                $out .= "///////////////////////////////////////////////////////////////////////////\n";
                foreach ($dest_label as $key => $val) {
                    $val = str_replace("'", "\\'", $val);
                    $out .= "\$label['{$key}']='" . JB_clean_str($val) . "'; \n";
                }
                $out .= "?>\n";
                $handler = fopen(jB_get_lang_dir() . $row['lang_filename'], "w");
                fputs($handler, $out);
                fclose($handler);
            }
        } else {
            echo "<font color='red'><b>- " . jB_get_lang_dir() . $row['lang_filename'] . " file is not writable. Give write permissions (" . decoct(JB_NEW_FILE_CHMOD) . ") to " . jB_get_lang_dir() . $row['lang_filename'] . " file and then disable & re-enable this plugin</b></font><br>";
        }
        echo " Done.<br>";
    }
}