/**
 * A template has not been structurally cached, so compile it and store in the cache.
 *
 * @param  ID_TEXT			The theme the template is in the context of
 * @param  PATH				The path to the template file
 * @param  ID_TEXT			The codename of the template (e.g. foo)
 * @param  ID_TEXT			The actual codename to use for the template (e.g. thin_foo)
 * @param  LANGUAGE_NAME	The language the template is in the context of
 * @param  string				File type suffix of template file
 * @param  ?ID_TEXT			The theme to cache in (NULL: main theme)
 * @return tempcode			The compiled tempcode
 */
function _do_template($theme, $path, $codename, $_codename, $lang, $suffix, $theme_orig = NULL)
{
    if (is_null($theme_orig)) {
        $theme_orig = $theme;
    }
    $base_dir = ($theme == 'default' && ($suffix != '.css' || strpos($path, '/css_custom') === false) ? get_file_base() : get_custom_file_base()) . '/themes/';
    global $CACHE_TEMPLATES, $FILE_ARRAY, $TEMPLATE_PREVIEW_OP, $MEM_CACHE;
    if (isset($FILE_ARRAY)) {
        $html = unixify_line_format(file_array_get('themes/' . $theme . $path . $codename . $suffix));
    } else {
        $html = unixify_line_format(file_get_contents($base_dir . filter_naughty($theme . $path . $codename) . $suffix, FILE_TEXT));
    }
    if (strpos($html, '{$,Parser hint: pure}') !== false) {
        return make_string_tempcode(preg_replace('#\\{\\$,.*\\}#U', '/*no minify*/', $html));
    }
    if ($GLOBALS['SEMI_DEBUG_MODE'] && strpos($html, '.innerHTML') !== false && strpos($html, 'Parser hint: .innerHTML okay') === false) {
        require_code('site');
        attach_message('Do not use the .innerHTML property in your Javascript because it will not work in true XHTML (when the browsers real XML parser is in action). Use ocPortal\'s global setInnerHTML/getInnerHTML functions.', 'warn');
    }
    // Strip off trailing final lines from single lines templates. Editors often put these in, and it causes annoying "visible space" issues
    if (substr($html, -1, 1) == chr(10) && substr_count($html, chr(10)) == 1) {
        $html = substr($html, 0, strlen($html) - 1);
    }
    if ($TEMPLATE_PREVIEW_OP) {
        $test = post_param($codename, NULL);
        if (!is_null($test)) {
            $html = post_param($test . '_new');
        }
    }
    $result = template_to_tempcode($html, 0, false, $codename, $theme, $lang);
    if ($CACHE_TEMPLATES && ($suffix == '.tpl' || $codename == 'no_cache')) {
        if (!is_null($MEM_CACHE)) {
            persistant_cache_set(array('TEMPLATE', $theme, $lang, $_codename), $result->to_assembly(), strpos($path, 'default/templates/') !== false);
        } else {
            $path2 = get_custom_file_base() . '/themes/' . $theme_orig . '/templates_cached/' . filter_naughty($lang) . '/';
            $myfile = @fopen($path2 . filter_naughty($_codename) . $suffix . '.tcd', 'wb');
            if ($myfile === false) {
                if (@mkdir($path2, 0777)) {
                    require_code('files');
                    fix_permissions($path2, 0777);
                } else {
                    if (file_exists($path2 . filter_naughty($_codename) . $suffix . '.tcd')) {
                        warn_exit(do_lang_tempcode('WRITE_ERROR', $path2 . filter_naughty($_codename) . $suffix . '.tcd'));
                    } else {
                        warn_exit(do_lang_tempcode('WRITE_ERROR_CREATE', $path2 . filter_naughty($_codename) . $suffix . '.tcd'));
                    }
                }
            } else {
                fwrite($myfile, $result->to_assembly($lang));
                fclose($myfile);
                fix_permissions($path2 . filter_naughty($_codename) . $suffix . '.tcd');
            }
        }
    }
    return $result;
}
Esempio n. 2
0
/**
 * Handle GET URLs requesting embedded media files.
 */
function handle_self_referencing_embedment()
{
    // If this is self-referring to CSS or logo
    if (array_key_exists('type', $_GET)) {
        $type = $_GET['type'];
        if ($type == 'ajax_ftp_details') {
            header('Content-Type: text/plain');
            if (!function_exists('ftp_connect')) {
                echo do_lang('NO_PHP_FTP');
                exit;
            }
            $conn = false;
            $domain = trim(get_param('ftp_domain'));
            $port = 21;
            if (strpos($domain, ':') !== false) {
                list($domain, $_port) = explode(':', $domain, 2);
                $port = intval($_port);
            }
            if (function_exists('ftp_ssl_connect')) {
                $conn = @ftp_ssl_connect($domain, $port);
            }
            $ssl = $conn !== false;
            $username = get_param('ftp_username');
            $password = get_param('ftp_password');
            $ssl = $conn !== false;
            if ($ssl && !@ftp_login($conn, $username, $password)) {
                $conn = false;
                $ssl = false;
            }
            if ($conn === false) {
                $conn = ftp_connect($domain, $port);
            }
            if ($conn === false) {
                echo do_lang('NO_FTP_CONNECT');
                exit;
            }
            if (!$ssl && !@ftp_login($conn, $username, $password)) {
                echo do_lang('NO_FTP_LOGIN', @strval($php_errormsg));
                ftp_close($conn);
                exit;
            }
            $ftp_folder = get_param('ftp_folder');
            if (substr($ftp_folder, -1) != '/') {
                $ftp_folder .= '/';
            }
            if (!@ftp_chdir($conn, $ftp_folder)) {
                echo do_lang('NO_FTP_DIR', @strval($php_errormsg), '1');
                ftp_close($conn);
                exit;
            }
            $files = @ftp_nlist($conn, '.');
            if ($files === false) {
                $files = array();
                if (@ftp_rename($conn, 'install.php', 'install.php')) {
                    $files = array('install.php', 'data.ocp');
                }
            }
            if (!in_array('install.php', $files)) {
                echo do_lang('NO_FTP_DIR', @strval($php_errormsg), '2');
            }
            ftp_close($conn);
            exit;
        }
        if ($type == 'ajax_db_details') {
            header('Content-Type: text/plain');
            global $SITE_INFO;
            if (!isset($SITE_INFO)) {
                $SITE_INFO = array();
            }
            $SITE_INFO['db_type'] = get_param('db_type');
            require_code('database');
            if (get_param('db_site') == '') {
                $db = new database_driver(get_param('db_forums'), get_param('db_forums_host'), get_param('db_forums_user'), get_param('db_forums_password'), '', true);
            } else {
                $db = new database_driver(get_param('db_site'), get_param('db_site_host'), get_param('db_site_user'), get_param('db_site_password'), '', true);
            }
            $connection =& $db->connection_write;
            if (count($connection) > 4) {
                call_user_func_array(array($db->static_ob, 'db_get_connection'), $connection);
            }
            exit;
        }
        if ($type == 'logo') {
            header('Content-type: image/png');
            if (!file_exists(get_file_base() . '/themes/default/images/' . get_site_default_lang() . '/logo/trimmed-logo.png')) {
                $out = file_array_get('themes/default/images/' . get_site_default_lang() . '/logo/trimmed-logo.png');
                echo $out;
            } else {
                print file_get_contents(get_file_base() . '/themes/default/images/' . get_site_default_lang() . '/logo/trimmed-logo.png');
                exit;
            }
            exit;
        }
        if ($type == 'contract') {
            header('Content-type: image/png');
            if (!file_exists(get_file_base() . '/themes/default/images/contract.png')) {
                $out = file_array_get('themes/default/images/contract.png');
                echo $out;
            } else {
                print file_get_contents(get_file_base() . '/themes/default/images/contract.png');
                exit;
            }
            exit;
        }
        if ($type == 'expand') {
            header('Content-type: image/png');
            if (!file_exists(get_file_base() . '/themes/default/images/expand.png')) {
                $out = file_array_get('themes/default/images/expand.png');
                echo $out;
            } else {
                print file_get_contents(get_file_base() . '/themes/default/images/expand.png');
                exit;
            }
            exit;
        }
        if (substr($type, 0, 15) == 'themes/default/') {
            header('Content-type: image/png');
            if (!file_exists(get_file_base() . '/' . $type)) {
                $out = file_array_get(filter_naughty($type));
                echo $out;
            } else {
                print file_get_contents(get_file_base() . '/' . filter_naughty($type));
                exit;
            }
            exit;
        }
        if ($type == 'css') {
            header('Content-Type: text/css');
            if (!file_exists(get_file_base() . '/themes/default/css/global.css')) {
                $file = file_array_get('themes/default/css/global.css');
            } else {
                $file = file_get_contents(get_file_base() . '/themes/default/css/global.css', FILE_TEXT);
            }
            $file = preg_replace('#\\{\\$IMG;?\\,([^,\\}\']+)\\}#', 'install.php?type=themes/default/images/${1}.png', $file);
            require_code('tempcode_compiler');
            $css = template_to_tempcode($file, 0, false, '');
            $file = $css->evaluate();
            print $file;
            exit;
        }
        if ($type == 'css_2') {
            header('Content-Type: text/css');
            if (!file_exists(get_file_base() . '/themes/default/css/install.css')) {
                $file = file_array_get('themes/default/css/install.css');
                echo $file;
            } else {
                $file = file_get_contents(get_file_base() . '/themes/default/css/install.css', FILE_TEXT);
            }
            $file = preg_replace('#\\{\\$IMG\\,([^,\\}\']+)\\}#', 'themes/default/images/${1}.png', $file);
            require_code('tempcode_compiler');
            $css = template_to_tempcode($file, 0, false, '');
            $file = $css->evaluate();
            print $file;
            exit;
        }
        exit;
    }
}
Esempio n. 3
0
/**
 * Load up a language file, compiling it (it's not cached yet).
 *
 * @param  ID_TEXT			The language file name
 * @param  ?LANGUAGE_NAME	The language (NULL: uses the current language)
 * @param  ?string			The language type (lang_custom, or custom) (NULL: normal priorities are used)
 * @set    lang_custom custom
 * @param  PATH				Where we are cacheing too
 * @param  boolean			Whether to just return if there was a loading error
 * @return boolean			Whether we FAILED to load
 */
function require_lang_compile($codename, $lang, $type, $cache_path, $ignore_errors = false)
{
    global $LANGUAGE, $REQUIRE_LANG_LOOP, $LANG_LOADED_LANG;
    $desire_cache = function_exists('get_option') && (get_option('is_on_lang_cache', true) == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1) && get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache', NULL) !== 0;
    if ($desire_cache) {
        if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 0) {
            global $DECACHED_COMCODE_LANG_STRINGS;
            // Cleanup language strings
            if (!$DECACHED_COMCODE_LANG_STRINGS) {
                $DECACHED_COMCODE_LANG_STRINGS = true;
                $comcode_lang_strings = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => '!'), '', NULL, NULL, true);
                if (!is_null($comcode_lang_strings)) {
                    $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => '!'));
                    foreach ($comcode_lang_strings as $comcode_lang_string) {
                        delete_lang($comcode_lang_string['string_index']);
                    }
                }
            }
        }
        $load_target = array();
    } else {
        $load_target =& $LANGUAGE[$lang];
    }
    global $FILE_ARRAY;
    if (@is_array($FILE_ARRAY) && file_array_exists('lang/' . $lang . '/' . $codename . '.ini')) {
        $lang_file = 'lang/' . $lang . '/' . $codename . '.ini';
        $file = file_array_get($lang_file);
        _get_lang_file_map($file, $load_target, NULL, true);
        $bad = true;
    } else {
        $bad = true;
        $dirty = false;
        // Load originals
        $lang_file = get_file_base() . '/lang/' . $lang . '/' . filter_naughty($codename) . '.ini';
        if (file_exists($lang_file)) {
            _get_lang_file_map($lang_file, $load_target, NULL, false);
            $bad = false;
        }
        // Load overrides now if they are there
        if ($type != 'lang') {
            $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini';
            if (!file_exists($lang_file) && get_file_base() != get_custom_file_base()) {
                $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini';
            }
            if (!file_exists($lang_file)) {
                $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.po';
                if (!file_exists($lang_file)) {
                    $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '-' . strtolower($lang) . '.po';
                }
            }
        }
        if ($type != 'lang' && file_exists($lang_file)) {
            _get_lang_file_map($lang_file, $load_target, NULL, false);
            $bad = false;
            $dirty = true;
            // Tainted from the official pack, so can't store server wide
        }
        // NB: Merge op doesn't happen in require_lang. It happens when do_lang fails and then decides it has to force a recursion to do_lang(xx,fallback_lang()) which triggers require_lang(xx,fallback_lang()) when it sees it's not loaded
        if ($bad && $lang != fallback_lang()) {
            require_lang($codename, fallback_lang(), $type, $ignore_errors);
            $REQUIRE_LANG_LOOP--;
            $fallback_cache_path = get_custom_file_base() . '/lang_cached/' . fallback_lang() . '/' . $codename . '.lcd';
            if (file_exists($fallback_cache_path)) {
                require_code('files');
                @copy($fallback_cache_path, $cache_path);
                fix_permissions($cache_path);
            }
            if (!array_key_exists($lang, $LANG_LOADED_LANG)) {
                $LANG_LOADED_LANG[$lang] = array();
            }
            $LANG_LOADED_LANG[$lang][$codename] = 1;
            return $bad;
        }
        if ($bad) {
            if ($ignore_errors) {
                return true;
            }
            if ($codename != 'critical_error' || $lang != get_site_default_lang()) {
                fatal_exit(do_lang_tempcode('MISSING_LANG_FILE', escape_html($codename), escape_html($lang)));
            } else {
                critical_error('CRIT_LANG');
            }
        }
    }
    if (is_null($GLOBALS['MEM_CACHE'])) {
        // Cache
        if ($desire_cache) {
            $file = @fopen($cache_path, 'wt');
            // Will fail if cache dir missing .. e.g. in quick installer
            if ($file) {
                if (fwrite($file, serialize($load_target)) > 0) {
                    // Success
                    fclose($file);
                    require_code('files');
                    fix_permissions($cache_path);
                } else {
                    // Failure
                    fclose($file);
                    @unlink($cache_path);
                }
            }
        }
    } else {
        persistant_cache_set(array('LANG', $lang, $codename), $load_target, !$dirty);
    }
    if ($desire_cache) {
        $LANGUAGE[$lang] += $load_target;
    }
    return $bad;
}
Esempio n. 4
0
/**
 * Parse the specified INI file, and get an array of what it found.
 *
 * @param  ?PATH			The path to the ini file to open (NULL: given contents in $file instead)
 * @param  ?string		The contents of the file (NULL: the file needs opening)
 * @return array			A map of the contents of the ini files
 */
function better_parse_ini_file($filename, $file = NULL)
{
    // NB: 'file()' function not used due to slowness compared to file_get_contents then explode
    if (is_null($file)) {
        global $FILE_ARRAY;
        if (@is_array($FILE_ARRAY)) {
            $file = file_array_get($filename);
        } else {
            $file = file_get_contents($filename, FILE_TEXT);
        }
    }
    $ini_array = array();
    $lines = explode(chr(10), $file);
    foreach ($lines as $line) {
        $line = rtrim($line);
        if ($line == '') {
            continue;
        }
        if ($line[0] == '#') {
            continue;
        }
        $bits = explode('=', $line, 2);
        if (isset($bits[1])) {
            list($property, $value) = $bits;
            $value = trim($value, '"');
            $ini_array[$property] = $value;
        }
    }
    return $ini_array;
}
Esempio n. 5
0
/**
 * A template has not been structurally cached, so compile it and store in the cache.
 *
 * @param  ID_TEXT			The theme the template is in the context of
 * @param  PATH				The path to the template file
 * @param  ID_TEXT			The codename of the template (e.g. foo)
 * @param  ID_TEXT			The actual codename to use for the template (e.g. foo_mobile)
 * @param  LANGUAGE_NAME	The language the template is in the context of
 * @param  string				File type suffix of template file (e.g. .tpl)
 * @param  ?ID_TEXT			The theme to cache in (NULL: main theme)
 * @return tempcode			The compiled tempcode
 */
function _do_template($theme, $path, $codename, $_codename, $lang, $suffix, $theme_orig = NULL)
{
    if (is_null($theme_orig)) {
        $theme_orig = $theme;
    }
    if (is_null($GLOBALS['CURRENT_SHARE_USER'])) {
        $base_dir = ($theme == 'default' && ($suffix != '.css' || strpos($path, '/css_custom') === false) ? get_file_base() : get_custom_file_base()) . '/themes/';
    } else {
        $base_dir = get_custom_file_base() . '/themes/';
        if (!is_file($base_dir . $theme . $path . $codename . $suffix)) {
            $base_dir = get_file_base() . '/themes/';
        }
    }
    global $CACHE_TEMPLATES, $FILE_ARRAY, $TEMPLATE_PREVIEW_OP, $MEM_CACHE;
    if (isset($FILE_ARRAY)) {
        $html = unixify_line_format(file_array_get('themes/' . $theme . $path . $codename . $suffix));
    } else {
        $html = unixify_line_format(file_get_contents($base_dir . filter_naughty($theme . $path . $codename) . $suffix, FILE_TEXT));
    }
    if ($GLOBALS['SEMI_DEBUG_MODE'] && strpos($html, '.innerHTML') !== false && !running_script('install') && strpos($html, 'Parser hint: .innerHTML okay') === false) {
        attach_message('Do not use the .innerHTML property in your Javascript because it will not work in true XHTML (when the browsers real XML parser is in action). Use ocPortal\'s global setInnerHTML/getInnerHTML functions.', 'warn');
    }
    // Strip off trailing final lines from single lines templates. Editors often put these in, and it causes annoying "visible space" issues
    if (substr($html, -1, 1) == chr(10) && substr_count($html, chr(10)) == 1) {
        $html = substr($html, 0, strlen($html) - 1);
    }
    if ($TEMPLATE_PREVIEW_OP) {
        $test = post_param($codename, NULL);
        if (!is_null($test)) {
            $html = post_param($test . '_new');
        }
    }
    $result = template_to_tempcode($html, 0, false, $suffix != '.tpl' ? '' : $codename, $theme_orig, $lang);
    if ($CACHE_TEMPLATES && !$TEMPLATE_PREVIEW_OP && ($suffix == '.tpl' || $codename == 'no_cache')) {
        $path2 = get_custom_file_base() . '/themes/' . $theme_orig . '/templates_cached/' . filter_naughty($lang) . '/';
        $myfile = @fopen($path2 . filter_naughty($_codename) . $suffix . '.tcp', 'wb');
        if ($myfile === false) {
            @mkdir(dirname($path2), 0777);
            fix_permissions(dirname($path2), 0777);
            sync_file(dirname($path2));
            if (@mkdir($path2, 0777)) {
                fix_permissions($path2, 0777);
                sync_file($path2);
            } else {
                if ($codename == 'SCREEN_TITLE') {
                    critical_error('PASSON', do_lang('WRITE_ERROR', escape_html($path2 . filter_naughty($_codename) . $suffix . '.tcp')));
                }
                // Bail out hard if would cause a loop
                intelligent_write_error($path2 . filter_naughty($_codename) . $suffix . '.tcp');
            }
        } else {
            $data_to_write = '<' . '?php' . chr(10) . $result->to_assembly($lang) . chr(10) . '?' . '>';
            if (fwrite($myfile, $data_to_write) >= strlen($data_to_write)) {
                // Success
                fclose($myfile);
                require_code('files');
                fix_permissions($path2 . filter_naughty($_codename) . $suffix . '.tcp');
            } else {
                // Failure
                fclose($myfile);
                @unlink($path2 . filter_naughty($_codename) . $suffix . '.tcp');
                // Can't leave this around, would cause problems
            }
        }
    }
    return $result;
}
Esempio n. 6
0
 /**
  * Load up a language file, compiling it (it's not cached yet).
  *
  * @param  ID_TEXT			The language file name
  * @param  ?LANGUAGE_NAME	The language (NULL: uses the current language)
  * @param  ?string			The language type (lang_custom, or custom) (NULL: normal priorities are used)
  * @set    lang_custom custom
  * @param  PATH				Where we are cacheing too
  * @param  boolean			Whether to just return if there was a loading error
  * @return boolean			Whether we FAILED to load
  */
 function require_lang_compile($codename, $lang, $type, $cache_path, $ignore_errors = false)
 {
     global $LANGUAGE, $REQUIRE_LANG_LOOP, $LANG_LOADED_LANG;
     $desire_cache = function_exists('get_option') && (get_option('is_on_lang_cache', true) == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1) && get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache', NULL) !== 0;
     if ($desire_cache) {
         if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 0) {
             global $DECACHED_COMCODE_LANG_STRINGS;
             // Cleanup language strings
             if (!$DECACHED_COMCODE_LANG_STRINGS) {
                 $DECACHED_COMCODE_LANG_STRINGS = true;
                 $comcode_lang_strings = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => '!'), '', NULL, NULL, true);
                 if (!is_null($comcode_lang_strings)) {
                     $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => '!'));
                     foreach ($comcode_lang_strings as $comcode_lang_string) {
                         delete_lang($comcode_lang_string['string_index']);
                     }
                 }
             }
         }
         $load_target = array();
     } else {
         $load_target =& $LANGUAGE[$lang];
     }
     global $FILE_ARRAY;
     if (@is_array($FILE_ARRAY) && file_array_exists('lang/' . $lang . '/' . $codename . '.ini')) {
         $lang_file = 'lang/' . $lang . '/' . $codename . '.ini';
         $file = file_array_get($lang_file);
         _get_lang_file_map($file, $load_target, NULL, true);
         $bad = true;
     } else {
         $bad = true;
         $dirty = false;
         // Load originals
         $lang_file = get_file_base() . '/lang/' . $lang . '/' . filter_naughty($codename) . '.ini';
         if (file_exists($lang_file)) {
             _get_lang_file_map($lang_file, $load_target, NULL, false);
             $bad = false;
         }
         // Load overrides now if they are there
         if ($type != 'lang') {
             $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini';
             if (!file_exists($lang_file) && get_file_base() != get_custom_file_base()) {
                 $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini';
             }
             if (!file_exists($lang_file)) {
                 $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.po';
                 if (!file_exists($lang_file)) {
                     $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '-' . strtolower($lang) . '.po';
                 }
             }
         }
         if ($type != 'lang' && file_exists($lang_file)) {
             _get_lang_file_map($lang_file, $load_target, NULL, false);
             $bad = false;
             $dirty = true;
             // Tainted from the official pack, so can't store server wide
         }
         // NB: Merge op doesn't happen in require_lang. It happens when do_lang fails and then decides it has to force a recursion to do_lang(xx,fallback_lang()) which triggers require_lang(xx,fallback_lang()) when it sees it's not loaded
         if ($bad && $lang != fallback_lang()) {
             require_lang($codename, fallback_lang(), $type, $ignore_errors);
             $REQUIRE_LANG_LOOP--;
             $fallback_cache_path = get_custom_file_base() . '/lang_cached/' . fallback_lang() . '/' . $codename . '.lcd';
             if (file_exists($fallback_cache_path)) {
                 require_code('files');
                 $fallback_map = unserialize(file_get_contents($fallback_cache_path));
                 $sep = '<span class="notranslate">----</span>';
                 $to_translate = '';
                 $i = 0;
                 $from = 0;
                 $lang_codes = array_keys($fallback_map);
                 foreach ($fallback_map as $value) {
                     if (strlen($to_translate . $sep . $to_translate) >= 3000) {
                         $translated = preg_split('#<span class="notranslate">[^<>]*----[^<>]*</span>#', google_translate($to_translate, $lang));
                         foreach ($translated as $j => $t_value) {
                             if (strtolower($lang_codes[$from + $j]) == $lang_codes[$from + $j]) {
                                 $t_value = $fallback_map[$lang_codes[$from + $j]];
                             }
                             if ($lang_codes[$from + $j] == 'locale') {
                                 $t_value = strtolower($lang) . '_' . strtoupper($lang);
                             }
                             $fallback_map[$lang_codes[$from + $j]] = $t_value;
                             $load_target[$lang_codes[$from + $j]] = $t_value;
                         }
                         $from = $i;
                         $to_translate = '';
                     }
                     if ($to_translate != '') {
                         $to_translate .= $sep;
                     }
                     $to_translate .= $value;
                     $i++;
                 }
                 $translated = preg_split('#<span class="notranslate">[^<>]*----[^<>]*</span>#', google_translate($to_translate, $lang));
                 foreach ($translated as $j => $t_value) {
                     if (strtolower($lang_codes[$from + $j]) == $lang_codes[$from + $j]) {
                         $t_value = $fallback_map[$lang_codes[$from + $j]];
                     }
                     if ($lang_codes[$from + $j] == 'locale') {
                         $t_value = strtolower($lang) . '_' . strtoupper($lang);
                     }
                     $fallback_map[$lang_codes[$from + $j]] = $t_value;
                     $load_target[$lang_codes[$from + $j]] = $t_value;
                 }
                 if (function_exists('ocp_mb_substr') && $codename == 'dates') {
                     foreach (array_keys($fallback_map) as $key) {
                         if (substr($key, 0, 3) == 'FC_') {
                             $test = ocp_mb_substr(trim($fallback_map[substr($key, 3)]), 0, 1, true);
                             if ($test !== false) {
                                 $fallback_map[$key] = $test;
                             }
                         }
                     }
                 }
                 $myfile = fopen($cache_path, 'wb');
                 fwrite($myfile, serialize($fallback_map));
                 fclose($myfile);
                 fix_permissions($cache_path);
             }
             if (!array_key_exists($lang, $LANG_LOADED_LANG)) {
                 $LANG_LOADED_LANG[$lang] = array();
             }
             $LANG_LOADED_LANG[$lang][$codename] = 1;
             if (!$bad) {
                 $LANGUAGE[$lang] += $fallback_map;
             }
             return $bad;
         }
         if ($bad) {
             if ($ignore_errors) {
                 return true;
             }
             if ($codename != 'critical_error' || $lang != get_site_default_lang()) {
                 fatal_exit(do_lang_tempcode('MISSING_LANG_FILE', escape_html($codename), escape_html($lang)));
             } else {
                 critical_error('CRIT_LANG');
             }
         }
     }
     if (is_null($GLOBALS['MEM_CACHE'])) {
         // Cache
         if ($desire_cache) {
             $file = @fopen($cache_path, 'wt');
             // Will fail if cache dir missing .. e.g. in quick installer
             if ($file) {
                 if (fwrite($file, serialize($load_target)) > 0) {
                     // Success
                     fclose($file);
                     require_code('files');
                     fix_permissions($cache_path);
                 } else {
                     // Failure
                     fclose($file);
                     @unlink($cache_path);
                 }
             }
         }
     } else {
         persistant_cache_set(array('LANG', $lang, $codename), $load_target, !$dirty);
     }
     if ($desire_cache) {
         $LANGUAGE[$lang] += $load_target;
     }
     return $bad;
 }