コード例 #1
0
ファイル: admin_lang.php プロジェクト: erico-deh/ocPortal
 /**
  * The actualiser to translate code (called externally, and may operate on many lang files).
  *
  * @return tempcode		The UI
  */
 function set_lang_code_2()
 {
     $lang = post_param('lang');
     $lang_files = get_lang_files(fallback_lang());
     foreach (array_keys($lang_files) as $lang_file) {
         $for_base_lang = get_lang_file_map(fallback_lang(), $lang_file, true);
         $for_base_lang_2 = get_lang_file_map($lang, $lang_file, false);
         $descriptions = get_lang_file_descriptions(fallback_lang(), $lang_file);
         $out = '';
         foreach ($for_base_lang_2 + $for_base_lang as $key => $now_val) {
             $val = post_param('l_' . $key, array_key_exists($key, $for_base_lang_2) ? $for_base_lang_2[$key] : $now_val);
             if (str_replace(chr(10), '\\n', $val) != $now_val || !array_key_exists($key, $for_base_lang) || $for_base_lang[$key] != $val || !file_exists(get_file_base() . '/lang/' . fallback_lang() . '/' . $lang_file . '.ini')) {
                 // if it's changed from default ocPortal, or not in default ocPortal, or was already changed in language file, or whole file is not in default ocPortal
                 $out .= $key . '=' . str_replace(chr(10), '\\n', $val) . "\n";
             }
         }
         if ($out != '') {
             $path = get_custom_file_base() . '/lang_custom/' . filter_naughty($lang) . '/' . filter_naughty($lang_file) . '.ini';
             $path_backup = $path . '.' . strval(time());
             if (file_exists($path)) {
                 @copy($path, $path_backup) or intelligent_write_error($path_backup);
                 sync_file($path_backup);
             }
             $myfile = @fopen($path, 'wt');
             if ($myfile === false) {
                 intelligent_write_error($path);
             }
             fwrite($myfile, "[descriptions]\n");
             foreach ($descriptions as $key => $description) {
                 if (fwrite($myfile, $key . '=' . $description . "\n") == 0) {
                     warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                 }
             }
             fwrite($myfile, "\n[strings]\n");
             fwrite($myfile, $out);
             fclose($myfile);
             fix_permissions($path);
             sync_file($path);
             $path_backup2 = $path . '.latest_in_ocp_edit';
             @copy($path, $path_backup2) or intelligent_write_error($path_backup2);
             sync_file($path_backup2);
         }
     }
     $title = get_page_title('TRANSLATE_CODE');
     log_it('TRANSLATE_CODE');
     require_code('view_modes');
     erase_cached_language();
     erase_cached_templates();
     // Show it worked / Refresh
     $url = post_param('redirect', '');
     if ($url == '') {
         return inform_screen($title, do_lang_tempcode('SUCCESS'));
     }
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
コード例 #2
0
ファイル: lang.php プロジェクト: erico-deh/ocPortal
 /**
  * Get the human-readable form of a language id, or a language entry from a language INI file.
  *
  * @param  ID_TEXT		The language id
  * @param  ?mixed			The first token [string or tempcode] (replaces {1}) (NULL: none)
  * @param  ?mixed			The second token [string or tempcode] (replaces {2}) (NULL: none)
  * @param  ?mixed			The third token (replaces {3}). May be an array of [of string], to allow any number of additional args (NULL: none)
  * @param  ?LANGUAGE_NAME The language to use (NULL: users language)
  * @param  boolean		Whether to cause ocPortal to exit if the lookup does not succeed
  * @return ?mixed			The human-readable content (NULL: not found). String normally. Tempcode if tempcode parameters.
  */
 function _do_lang($codename, $token1 = NULL, $token2 = NULL, $token3 = NULL, $lang = NULL, $require_result = true)
 {
     $pos = strpos($codename, ':');
     if ($pos !== false) {
         require_lang(substr($codename, 0, $pos));
         $codename = substr($codename, $pos + 1);
     }
     global $LANGUAGE, $USER_LANG_CACHED, $RECORD_LANG_STRINGS, $XSS_DETECT, $PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED;
     if ($RECORD_LANG_STRINGS) {
         global $RECORDED_LANG_STRINGS;
         $RECORDED_LANG_STRINGS[$codename] = 1;
     }
     if ($lang === NULL) {
         $lang = $USER_LANG_CACHED === NULL ? user_lang() : $USER_LANG_CACHED;
     }
     if (!isset($LANGUAGE[$lang][$codename]) && (!array_key_exists($lang, $LANGUAGE) || !array_key_exists($codename, $LANGUAGE[$lang]))) {
         global $PAGE_CACHE_LAZY_LOAD, $PAGE_CACHE_LANGS_REQUESTED, $LANG_REQUESTED_LANG;
         if ($PAGE_CACHE_LAZY_LOAD) {
             $PAGE_CACHE_LAZY_LOAD = false;
             // We can't be lazy any more, but we will keep growing our pool so hopefully CAN be lazy the next time
             foreach ($PAGE_CACHE_LANGS_REQUESTED as $request) {
                 list($that_codename, $that_lang) = $request;
                 unset($LANG_REQUESTED_LANG[$that_lang][$that_codename]);
                 require_lang($that_codename, $that_lang, NULL, true);
             }
             $ret = _do_lang($codename, $token1, $token2, $token3, $lang, $require_result);
             if ($ret === NULL) {
                 $PAGE_CACHE_LANG_LOADED[$lang][$codename] = NULL;
                 if ($GLOBALS['MEM_CACHE'] !== NULL) {
                     persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED);
                 } else {
                     @rewind($PAGE_CACHE_FILE);
                     @ftruncate($PAGE_CACHE_FILE, 0);
                     @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED));
                 }
             }
             return $ret;
         }
         require_all_open_lang_files($lang);
     }
     if ($lang == 'xxx') {
         return 'xxx';
     }
     // Helpful for testing language compliancy. We don't expect to see non x's if we're running this language
     if (!isset($LANGUAGE[$lang][$codename]) && (!array_key_exists($lang, $LANGUAGE) || !array_key_exists($codename, $LANGUAGE[$lang]))) {
         if ($lang != fallback_lang()) {
             $ret = do_lang($codename, $token1, $token2, $token3, fallback_lang(), $require_result);
             if ($codename == 'charset') {
                 switch (strtolower($lang)) {
                     case 'ar':
                     case 'bg':
                     case 'zh-CN':
                     case 'zh-TW':
                     case 'hr':
                     case 'cs':
                     case 'da':
                     case 'nl':
                     case 'fi':
                     case 'fr':
                     case 'de':
                     case 'el':
                     case 'hi':
                     case 'it':
                     case 'ja':
                     case 'ko':
                     case 'pl':
                     case 'pt':
                     case 'ro':
                     case 'ru':
                     case 'es':
                     case 'sv':
                         $ret = 'utf-8';
                         break;
                 }
             } elseif (substr($codename, 0, 3) == 'FC_') {
                 $ret = ocp_mb_substr(trim(do_lang(substr($codename, 3), $token1, $token2, $token3, $lang)), 0, 1);
             } elseif ($codename == 'locale') {
                 $ret = strtolower($lang) . '_' . strtoupper($lang);
             } else {
                 $ret2 = strtolower($codename) != $codename ? google_translate($ret, $lang) : $ret;
                 if ($ret2 != $ret) {
                     $ret = $ret2;
                 }
             }
             if ($PAGE_CACHE_FILE !== NULL) {
                 if (!isset($PAGE_CACHE_LANG_LOADED[$lang][$codename]) && isset($PAGE_CACHE_LANG_LOADED[fallback_lang()][$codename])) {
                     $PAGE_CACHE_LANG_LOADED[$lang][$codename] = $ret;
                     // Will have been cached into fallback_lang() from the nested do_lang call, we need to copy it into our cache bucket for this language
                     if ($GLOBALS['MEM_CACHE'] !== NULL) {
                         persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED);
                     } else {
                         @rewind($PAGE_CACHE_FILE);
                         @ftruncate($PAGE_CACHE_FILE, 0);
                         @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED));
                     }
                 }
             }
             return $ret;
         } else {
             if ($require_result) {
                 global $USER_LANG_LOOP, $REQUIRE_LANG_LOOP;
                 //print_r(debug_backtrace());
                 if ($USER_LANG_LOOP == 1) {
                     critical_error('RELAY', 'Missing language code: ' . escape_html($codename) . '. This language code is required to produce error messages, and thus a critical error was prompted by the non-ability to show less-critical error messages. It is likely the source language files (lang/' . fallback_lang() . '/*.ini) for ocPortal on this website have been corrupted.');
                 }
                 if ($REQUIRE_LANG_LOOP >= 2) {
                     return '';
                 }
                 // Probably failing to load global.ini, so just output with some text missing
                 require_code('view_modes');
                 erase_cached_language();
                 fatal_exit(do_lang_tempcode('MISSING_LANG_ENTRY', escape_html($codename)));
             } else {
                 return NULL;
             }
         }
     }
     if ($PAGE_CACHE_FILE !== NULL) {
         if (!isset($PAGE_CACHE_LANG_LOADED[$lang][$codename])) {
             $PAGE_CACHE_LANG_LOADED[$lang][$codename] = $LANGUAGE[$lang][$codename];
             if ($GLOBALS['MEM_CACHE'] !== NULL) {
                 persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED);
             } else {
                 @rewind($PAGE_CACHE_FILE);
                 @ftruncate($PAGE_CACHE_FILE, 0);
                 @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED));
             }
         }
     }
     // Put in parameters
     static $non_plural_non_vowel = array('1', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z');
     $looked_up = $LANGUAGE[$lang][$codename];
     if ($looked_up === NULL) {
         return NULL;
     }
     // Learning cache pool has told us this string definitely does not exist
     $out = str_replace('\\n', "\n", $looked_up);
     $plural_or_vowel_check = strpos($out, '|') !== false;
     if ($XSS_DETECT) {
         ocp_mark_as_escaped($out);
     }
     if ($token1 !== NULL) {
         if (is_object($token1) && $token2 === NULL || $token2 !== NULL && is_object($token2)) {
             $bits = preg_split('#\\{\\d[^\\}]*\\}#', $out, 2, PREG_SPLIT_OFFSET_CAPTURE);
             $ret = new ocp_tempcode();
             foreach ($bits as $bit) {
                 if ($XSS_DETECT) {
                     ocp_mark_as_escaped($bit[0]);
                 }
                 $at = $bit[1];
                 if ($at != 0) {
                     if ($out[$at - 2] == '1') {
                         $ret->attach($token1);
                     } elseif ($out[$at - 2] == '2') {
                         $ret->attach($token2);
                     } elseif ($plural_or_vowel_check && substr($out[$at - 2], 0, 2) == '1|') {
                         $exploded = explode('|', $out[$at - 2]);
                         $_token = $token1->evaluate();
                         $_token_denum = str_replace(',', '', $_token);
                         $ret->attach(in_array(is_numeric($_token_denum) ? $_token_denum : strtolower(substr($_token, 0, 1)), $non_plural_non_vowel) ? $exploded[1] : $exploded[2]);
                     } elseif ($plural_or_vowel_check && substr($out[$at - 2], 0, 2) == '2|') {
                         $exploded = explode('|', $out[$at - 2]);
                         $_token = $token2->evaluate();
                         $_token_denum = str_replace(',', '', $_token);
                         $ret->attach(in_array(is_numeric($_token_denum) ? $_token_denum : strtolower(substr($_token, 0, 1)), $non_plural_non_vowel) ? $exploded[1] : $exploded[2]);
                     }
                 }
                 $ret->attach($bit[0]);
             }
             return $ret;
         } elseif ($token1 !== NULL) {
             $out = str_replace('{1}', $token1, $out);
             if ($plural_or_vowel_check) {
                 $_token_denum = str_replace(',', '', $token1);
                 $out = preg_replace('#\\{1\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : strtolower(substr($token1, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out);
             }
             if ($XSS_DETECT && ocp_is_escaped($token1)) {
                 ocp_mark_as_escaped($out);
             }
         }
         if ($token2 !== NULL) {
             if ($XSS_DETECT) {
                 $escaped = ocp_is_escaped($out);
             }
             $out = str_replace('{2}', $token2, $out);
             if ($plural_or_vowel_check) {
                 $_token_denum = str_replace(',', '', $token1);
                 $out = preg_replace('#\\{2\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : strtolower(substr($token2, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out);
             }
             if ($XSS_DETECT && ocp_is_escaped($token2) && $escaped) {
                 ocp_mark_as_escaped($out);
             }
             if ($token3 !== NULL) {
                 $i = 3;
                 if (!is_array($token3)) {
                     $token3 = array($token3);
                 }
                 foreach ($token3 as $token) {
                     if ($XSS_DETECT) {
                         $escaped = ocp_is_escaped($out);
                     }
                     $out = str_replace('{' . strval($i) . '}', $token, $out);
                     if ($plural_or_vowel_check) {
                         $_token_denum = str_replace(',', '', $token);
                         $out = preg_replace('#\\{' . strval($i) . '\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : strtolower(substr($token, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out);
                     }
                     if ($XSS_DETECT && ocp_is_escaped($token) && $escaped) {
                         ocp_mark_as_escaped($out);
                     }
                     $i++;
                 }
             }
         }
     }
     return $out;
 }
コード例 #3
0
ファイル: language.php プロジェクト: erico-deh/ocPortal
 /**
  * Standard modular run function.
  *
  * @return tempcode	Results
  */
 function run()
 {
     require_code('view_modes');
     erase_cached_language();
     return new ocp_tempcode();
 }
コード例 #4
0
ファイル: global2.php プロジェクト: erico-deh/ocPortal
/**
 * Standard code module initialisation function.
 */
function init__global2()
{
    global $BOOTSTRAPPING, $CHECKING_SAFEMODE, $BAD_WORD_CHARS, $FIXED_WORD_CHARS, $FIXED_WORD_CHARS_HTML, $BROWSER_DECACHEING, $CHARSET, $TEMP_CHARSET, $RELATIVE_PATH, $CURRENTLY_HTTPS, $RUNNING_SCRIPT_CACHE, $SERVER_TIMEZONE, $HAS_SET_ERROR_HANDLER, $DYING_BADLY, $XSS_DETECT, $SITE_INFO, $JAVASCRIPTS, $JAVASCRIPT, $CSSS, $IN_MINIKERNEL_VERSION, $EXITING, $FILE_BASE, $MOBILE, $CACHE_TEMPLATES, $BASE_URL_HTTP, $BASE_URL_HTTPS, $WORDS_TO_FILTER, $FIELD_RESTRICTIONS, $VALID_ENCODING, $CONVERTED_ENCODING, $MICRO_BOOTUP, $MICRO_AJAX_BOOTUP, $QUERY_LOG, $_CREATED_FILES, $CURRENT_SHARE_USER, $CACHE_FIND_SCRIPT;
    if (str_replace(array('on', 'true', 'yes'), array('1', '1', '1'), strtolower(ini_get('output_buffering'))) == '1') {
        @ob_end_clean();
    }
    if (array_key_exists('HTTP_X_REWRITE_URL', $_SERVER)) {
        foreach ($_GET as $key => $val) {
            if ($key[0] == '?') {
                unset($_GET[$key]);
                $_GET[substr($key, 1)] = $val;
            }
        }
        $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    } elseif (!array_key_exists('REQUEST_URI', $_SERVER) && !array_key_exists('REQUEST_URI', $_ENV)) {
        $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
        $first = true;
        foreach ($_GET as $key => $val) {
            $_SERVER['REQUEST_URI'] .= $first ? '?' : '&';
            $_SERVER['REQUEST_URI'] .= urlencode($key) . '=' . urlencode($val);
            $first = false;
        }
    }
    if (array_key_exists('SCRIPT_FILENAME', $_SERVER) && !array_key_exists('PHP_SELF', $_SERVER)) {
        $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_FILENAME'];
    } elseif (array_key_exists('SCRIPT_NAME', $_SERVER) && defined('HIPHOP_PHP')) {
        $_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'];
    }
    @header('Expires: Mon, 20 Dec 1998 01:00:00 GMT');
    @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    @header('Cache-Control: no-cache, max-age=0');
    @header('Pragma: no-cache');
    // for proxies, and also IE
    if (is_file('closed.html') && get_param_integer('keep_force_open', 0) == 0) {
        if (strpos($_SERVER['PHP_SELF'], 'upgrader.php') === false && strpos($_SERVER['PHP_SELF'], 'execute_temp.php') === false && (!isset($SITE_INFO['no_extra_closed_file']) || $SITE_INFO['no_extra_closed_file'] == '0')) {
            if (@strpos($_SERVER['SERVER_SOFTWARE'], 'IIS') === false) {
                header('HTTP/1.0 503 Service Temporarily Unavailable');
            }
            header('Location: ' . (is_file($RELATIVE_PATH . 'closed.html') ? 'closed.html' : '../closed.html'));
            exit;
        }
    }
    // Cover up holes in old PHP versions functionality
    if (!function_exists('str_word_count')) {
        /**
         * Isolate the words in the input string.
         *
         * @param  string			String to count words in
         * @param  integer		The format
         * @set    0 1 2
         * @return mixed			Typically a list - the words of the input string
         */
        function str_word_count($input, $format = 0)
        {
            //count words
            $pattern = "/[^(\\w|\\d|\\'|\"|\\.|\\!|\\?|;|,|\\|\\/|\\-\\-|:|\\&|@)]+/";
            $all_words = trim(preg_replace($pattern, ' ', $input));
            $a = array();
            $pos = 0;
            while (true) {
                $old_pos = $pos;
                $pos = strpos($all_words, ' ', $pos);
                if ($pos === false) {
                    $a[$old_pos] = substr($all_words, $old_pos);
                    break;
                }
                $a[$old_pos] = substr($all_words, $old_pos, $pos - $old_pos);
            }
            if ($format == 0) {
                return count($a);
            }
            return $a;
        }
    }
    if (!function_exists('html_entity_decode')) {
        /**
         * Decode the HTML entitity encoded input string.
         *
         * @param  string			The text to decode
         * @param  integer		The quote style code
         * @param  ?string		Character set to decode to (NULL: default)
         * @return string			The decoded text
         */
        function html_entity_decode($input, $quote_style, $charset = NULL)
        {
            unset($quote_style);
            unset($charset);
            /*			// NB: &nbsp does not go to <space>. It's not something you use with html escaping, it's for hard-space-formatting. URL's don't contain spaces, but that's due to URL escaping (%20)
            			$replace_array=array(
            				'&amp;'=>'&',
            				'&gt;'=>'>',
            				'&lt;'=>'<',
            				'&#039;'=>'\'',
            				'&quot;'=>'"',
            			);
            
            			foreach ($replace_array as $from=>$to)
            			{
            				$input=str_replace($from,$to,$input);
            			}
            
            			return $input;*/
            $trans_tbl = get_html_translation_table(HTML_ENTITIES);
            $trans_tbl = array_flip($trans_tbl);
            return strtr($input, $trans_tbl);
        }
    }
    if (version_compare(phpversion(), '4.3.0') >= 0) {
        if (!function_exists('unichrm_hex')) {
            /**
             * Convert a unicode character number to a unicode string. Callback for preg_replace.
             *
             * @param  array					Regular expression match array.
             * @return ~string				Converted data (false: could not convert).
             */
            function unichrm_hex($matches)
            {
                return unichr(hexdec($matches[1]));
            }
        }
        if (!function_exists('unichrm')) {
            /**
             * Convert a unicode character number to a unicode string. Callback for preg_replace.
             *
             * @param  array					Regular expression match array.
             * @return ~string				Converted data (false: could not convert).
             */
            function unichrm($matches)
            {
                return unichr(intval($matches[1]));
            }
        }
        if (!function_exists('unichr')) {
            /**
             * Convert a unicode character number to a HTML-entity enabled string, using lower ASCII characters where possible.
             *
             * @param  integer				Character number.
             * @return ~string				Converted data (false: could not convert).
             */
            function unichr($c)
            {
                if ($c <= 0x7f) {
                    return chr($c);
                } else {
                    return '#&' . strval($c) . ';';
                }
            }
        }
    }
    $BOOTSTRAPPING = 1;
    $CHECKING_SAFEMODE = false;
    $BAD_WORD_CHARS = array(chr(128), chr(130), chr(131), chr(132), chr(133), chr(134), chr(135), chr(136), chr(137), chr(138), chr(139), chr(140), chr(142), chr(145), chr(146), chr(147), chr(148), chr(149), chr(150), chr(151), chr(152), chr(153), chr(154), chr(155), chr(156), chr(158), chr(159));
    $FIXED_WORD_CHARS = array('(EUR-)', ',', '{f.}', '"', '...', '-|-', '=|=', '^', '{%o}', '{~S}', '<', 'CE', '{~Z}', "'", "'", '"', '"', '-', '-', '--', '~', '(TM)', '{~s}', '>', 'ce', '{~z}', '{.Y.}');
    // some of these are Comcode shortcuts. We can't use entities as we can't assume we're converting into Comcode.
    $FIXED_WORD_CHARS_HTML = array('&#8364;', '&#8218;', '&#402;', '&#8222;', '&hellip;', '&#8224;', '&#8225;', '&#710;', '&#8240;', '&#352;', '&#8249;', '&#338;', '&#381;', "&lsquo;", "&rsquo;", '&ldquo;', '&rdquo;', '&bull;', '&ndash;', '&mdash;', '&#732;', '&trade;', '&#353;', '&#8250;', '&#339;', '&#382;', '&#376;');
    $RUNNING_SCRIPT_CACHE = array();
    $BROWSER_DECACHEING = NULL;
    $CHARSET = NULL;
    $TEMP_CHARSET = NULL;
    $CURRENTLY_HTTPS = NULL;
    $CACHE_FIND_SCRIPT = array();
    error_reporting(E_ALL);
    @ini_set('html_errors', '1');
    @ini_set('docref_root', 'http://www.php.net/manual/en/');
    @ini_set('docref_ext', '.php');
    $SERVER_TIMEZONE = function_exists('date_default_timezone_get') ? @date_default_timezone_get() : ini_get('date.timezone');
    @ini_set('date.timezone', 'UTC');
    if (function_exists('date_default_timezone_set')) {
        date_default_timezone_set('UTC');
    }
    // Needed for HPHP
    $HAS_SET_ERROR_HANDLER = false;
    $DYING_BADLY = false;
    // If ocPortal is bailing out uncontrollably, setting this will make sure the error hander does not try and suppress
    $XSS_DETECT = function_exists('ocp_mark_as_escaped');
    $GLOBALS['DEBUG_MODE'] = (!array_key_exists('debug_mode', $SITE_INFO) || $SITE_INFO['debug_mode'] == '1') && (is_dir(get_file_base() . '/.svn') || is_dir(get_file_base() . '/.git') || function_exists('ocp_mark_as_escaped')) && (!array_key_exists('keep_no_debug_mode', $_GET) || $_GET['keep_no_debug_mode'] == '0');
    $GLOBALS['SEMI_DEBUG_MODE'] = (!array_key_exists('debug_mode', $SITE_INFO) || $SITE_INFO['debug_mode'] == '1') && (is_dir(get_file_base() . '/.svn') || is_dir(get_file_base() . '/.git') || function_exists('ocp_mark_as_escaped'));
    if (function_exists('set_time_limit')) {
        @set_time_limit(60);
    }
    if ($GLOBALS['DEBUG_MODE']) {
        if (function_exists('set_time_limit')) {
            @set_time_limit(10);
        }
        @ini_set('ocproducts.type_strictness', '1');
        @ini_set('ocproducts.xss_detect', '1');
    }
    if ($GLOBALS['DEBUG_MODE']) {
        require_code('developer_tools');
    }
    $JAVASCRIPTS = array('javascript' => 1, 'javascript_thumbnails' => 1);
    if ($GLOBALS['CURRENT_SHARE_USER'] !== NULL || get_domain() == 'myocp.com') {
        $JAVASCRIPTS['javascript_ajax'] = 1;
    }
    $CSSS = array('no_cache' => 1, 'global' => 1);
    // Try and make the PHP environment as we need it
    if (function_exists('set_magic_quotes_runtime')) {
        @set_magic_quotes_runtime(0);
    }
    // @'d because it's deprecated and PHP 5.3 may give an error
    @ini_set('auto_detect_line_endings', '0');
    @ini_set('include_path', '');
    @ini_set('default_socket_timeout', '60');
    @ini_set('allow_url_fopen', '0');
    @ini_set('suhosin.executor.disable_emodifier', '1');
    // Extra security if suhosin is available
    @ini_set('suhosin.executor.multiheader', '1');
    // Extra security if suhosin is available
    @ini_set('suhosin.executor.disable_eval', '0');
    @ini_set('suhosin.executor.eval.whitelist', '');
    @ini_set('suhosin.executor.func.whitelist', '');
    // Load most basic config
    $IN_MINIKERNEL_VERSION = 0;
    $EXITING = 0;
    if (array_key_exists('use_ocf', $_GET) && running_script('upgrader')) {
        $SITE_INFO['forum_type'] = 'ocf';
        $SITE_INFO['ocf_table_prefix'] = $SITE_INFO['table_prefix'];
    }
    $CACHE_TEMPLATES = true;
    // The URL to our install (no trailing /)
    $BASE_URL_HTTP = NULL;
    $BASE_URL_HTTPS = NULL;
    $WORDS_TO_FILTER = NULL;
    $FIELD_RESTRICTIONS = NULL;
    $VALID_ENCODING = false;
    $CONVERTED_ENCODING = false;
    if (!isset($MICRO_BOOTUP)) {
        $MICRO_BOOTUP = 0;
    }
    if (!isset($MICRO_AJAX_BOOTUP)) {
        $MICRO_AJAX_BOOTUP = 0;
    }
    require_code_no_override('version');
    if ($MICRO_BOOTUP == 0 && $MICRO_AJAX_BOOTUP == 0) {
        //@header('X-Powered-By: ocPortal '.ocp_version_full().' (PHP '.phpversion().')');
        @header('X-Powered-By: ocPortal');
        // Better to keep it vague, for security reasons
        $QUERY_LOG = false;
        if (isset($_REQUEST['special_page_type']) && $_REQUEST['special_page_type'] == 'query') {
            $QUERY_LOG = true;
        }
    }
    // Most critical things
    require_code('support');
    // A lot of support code is present in this
    srand(make_seed());
    mt_srand(make_seed());
    if ($MICRO_BOOTUP == 0 && $MICRO_AJAX_BOOTUP == 0) {
        if (running_script('index') && count($_POST) == 0) {
            $bot_type = get_bot_type();
            if ($bot_type !== NULL && isset($SITE_INFO['fast_spider_cache']) && $SITE_INFO['fast_spider_cache'] != '0') {
                fast_spider_cache(true);
            }
        }
    }
    require_code('caches');
    // Recently taken out of 'support' so makes sense to load it here
    require_code('database');
    // There's nothing without the database
    if ((!isset($SITE_INFO['known_suexec']) || $SITE_INFO['known_suexec'] == '0') && !is_writable_wrap(get_file_base() . '/.htaccess')) {
        require_code('support2');
        if (ip_banned(get_ip_address())) {
            critical_error('BANNED');
        }
    }
    if (running_script('messages') && get_param('action', 'new') == 'new' && get_param_integer('routine_refresh', 0) == 0) {
        require_code('chat_poller');
        chat_poller();
    }
    if ($MICRO_BOOTUP == 0) {
        load_user_stuff();
    }
    // For any kind of niceness we need these. The order is chosen for complex dependency reasons - don't mess with it
    if ($MICRO_AJAX_BOOTUP == 0) {
        require_code('themes');
        // Output needs to know about themes
        require_code('templates');
        // So that we can do error templates
        require_code('tempcode');
        // Output is done with tempcode
        if ($MICRO_BOOTUP == 0) {
            require_code('comcode');
            // Much output goes through comcode
        }
    }
    require_code('zones');
    // Zone is needed because zones are where all ocPortal pages reside
    require_code('config');
    // Config is needed for much active stuff
    if (get_option('collapse_user_zones', true) === '1' && $RELATIVE_PATH == 'site') {
        get_base_url();
        /*force calculation first*/
        $RELATIVE_PATH = '';
    }
    require_code('users');
    // Users are important due to permissions
    if ($MICRO_BOOTUP == 0 && $MICRO_AJAX_BOOTUP == 0) {
        if (running_script('index') && count($_POST) == 0) {
            if (isset($SITE_INFO['any_guest_cached_too']) && $SITE_INFO['any_guest_cached_too'] == '1' && is_guest(NULL, true)) {
                fast_spider_cache(false);
            }
        }
    }
    $CACHE_TEMPLATES = (get_option('is_on_template_cache') == '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 ($MICRO_AJAX_BOOTUP == 0) {
        require_code('temporal');
        // Date/time functions
        require_code('files');
        // Contains fix_permissions, needed for 'lang'
        require_code('lang');
        // So that we can do language stuff (e.g. errors)
        convert_data_encodings();
        if ($MICRO_BOOTUP == 0) {
            require_code('permissions');
            // So we can check access
        }
    }
    // At this point we can display errors nicely
    $GLOBALS['SUPPRESS_ERROR_DEATH'] = false;
    set_error_handler('ocportal_error_handler');
    if (function_exists('error_get_last')) {
        register_shutdown_function('catch_fatal_errors');
    }
    $HAS_SET_ERROR_HANDLER = true;
    if ($MICRO_BOOTUP == 0) {
        if (method_exists($GLOBALS['FORUM_DRIVER'], 'forum_layer_initialise')) {
            $GLOBALS['FORUM_DRIVER']->forum_layer_initialise();
        }
    }
    if ($MICRO_AJAX_BOOTUP == 0) {
        $JAVASCRIPT = new ocp_tempcode();
    }
    if ($MICRO_BOOTUP == 0) {
        if ($IN_MINIKERNEL_VERSION != 1 && $MICRO_AJAX_BOOTUP == 0) {
            has_cookies();
            // Will determine at early point whether we have cookie support
            get_num_users_site();
            // Will kill site if there are too many users
        }
    }
    require_code('urls');
    // URL building is crucial
    @header('Content-type: text/html; charset=' . get_charset());
    if ($MICRO_AJAX_BOOTUP == 0 && $MICRO_BOOTUP == 0) {
        // Before anything gets outputted
        handle_logins();
        require_code('site');
        // This powers the site (top level page generation)
        // Are we installed?
        get_option('site_name');
    }
    // Our logging (change false to true for temporarily changing it so staff get logging)
    if (get_option('log_php_errors') == '1') {
        @ini_set('log_errors', '1');
        if (addon_installed('errorlog')) {
            @ini_set('error_log', get_custom_file_base() . '/data_custom/errorlog.php');
        }
    }
    if ($MICRO_BOOTUP == 0 && $MICRO_AJAX_BOOTUP == 0 && (get_option('display_php_errors') == '1' || running_script('upgrader') || has_specific_permission(get_member(), 'see_php_errors'))) {
        @ini_set('display_errors', '1');
    } elseif (!$GLOBALS['DEBUG_MODE']) {
        @ini_set('display_errors', '0');
    }
    // G-zip?
    @ini_set('zlib.output_compression', get_option('gzip_output') == '1' ? 'On' : 'Off');
    if (function_exists('setlocale') && $MICRO_AJAX_BOOTUP == 0) {
        $locales = explode(',', do_lang('locale'));
        setlocale(LC_ALL, $locales[0]);
        @setlocale(LC_ALL, $locales);
        unset($locales);
    }
    if ($MICRO_AJAX_BOOTUP == 0 && $MICRO_BOOTUP == 0 && (!isset($SITE_INFO['no_installer_checks']) || $SITE_INFO['no_installer_checks'] == '0')) {
        if (is_file(get_file_base() . '/install.php') && !is_file(get_file_base() . '/install_ok') && running_script('index')) {
            warn_exit(do_lang_tempcode('MUST_DELETE_INSTALLER'));
        }
    }
    if ($MICRO_AJAX_BOOTUP == 0 && $MICRO_BOOTUP == 0) {
        $changed_base_url = !array_key_exists('base_url', $SITE_INFO) && get_long_value('last_base_url') !== get_base_url(false);
        if (running_script('index') && (is_browser_decacheing() || $changed_base_url)) {
            require_code('view_modes');
            erase_tempcode_cache();
            erase_cached_templates(!$changed_base_url);
            erase_comcode_cache();
            erase_cached_language();
            persistant_cache_empty();
            if ($changed_base_url) {
                require_lang('zones');
                require_code('zones3');
                erase_comcode_page_cache();
                set_long_value('last_base_url', get_base_url(false));
            }
        }
        if (has_zone_access(get_member(), 'adminzone')) {
            $JAVASCRIPTS['javascript_staff'] = 1;
            $JAVASCRIPTS['javascript_ajax'] = 1;
            if (addon_installed('occle')) {
                $JAVASCRIPTS['javascript_button_occle'] = 1;
            }
        }
        if (addon_installed('realtime_rain') && get_option('bottom_show_realtime_rain_button', true) === '1') {
            $JAVASCRIPTS['javascript_button_realtime_rain'] = 1;
        }
    }
    /*ocp_memory_profile('startup');
    	$func=get_defined_functions();
    	print_r($func['user']);*/
    if (tacit_https() || is_page_https(get_zone_name(), get_page_name())) {
        @header('Cache-Control: private');
        @header('Pragma: private');
    }
    $BOOTSTRAPPING = 0;
    if ($GLOBALS['SEMI_DEBUG_MODE'] && $MICRO_AJAX_BOOTUP == 0) {
        if ($GLOBALS['SEMI_DEBUG_MODE']) {
            /*if ((mt_rand(0,2)==1) && ($GLOBALS['DEBUG_MODE']) && (running_script('index')))	We know this works now, so let's stop messing up our development speed
            		{
            			require_code('view_modes');
            			erase_cached_templates(true); // Stop anything trying to read a template cache item (E.g. CSS, JS) that might not exist!
            		}*/
            if (strpos(ocp_srv('HTTP_REFERER'), ocp_srv('HTTP_HOST')) !== false && strpos(ocp_srv('HTTP_REFERER'), 'keep_devtest') !== false && !running_script('attachment') && !running_script('upgrader') && strpos(ocp_srv('HTTP_REFERER'), 'login') === false && is_null(get_param('keep_devtest', NULL))) {
                $_GET['keep_devtest'] = '1';
                fatal_exit('URL not constructed properly: development mode in use but keep_devtest was not specified. This indicates that links have been made without build_url (in PHP) or keep_stub (in Javascript). Whilst not fatal this time, failure to use these functions can cause problems when your site goes live. See the ocPortal codebook for more details.');
            } else {
                $_GET['keep_devtest'] = '1';
            }
        }
        if (browser_matches('true_xhtml') && get_value('html5') !== '1' && get_value('html5') !== '_true' && get_param_integer('keep_no_xhtml', 0) == 0 && !running_script('upgrader')) {
            @header('Content-type: application/xhtml+xml; charset=' . get_charset());
        }
        if (isset($_CREATED_FILES)) {
            /**
             * Run after-tests for debug mode, to make sure coding standards are met.
             */
            function debug_mode_aftertests()
            {
                global $_CREATED_FILES, $_MODIFIED_FILES;
                // Use the info from ocProduct's custom PHP version to make sure that all files that were created/modified got synched as they should have been.
                foreach ($_CREATED_FILES as $file) {
                    if (substr($file, 0, strlen(get_file_base())) == get_file_base() && substr($file, -4) != '.log' && basename($file) != 'permissioncheckslog.php') {
                        @exit(escape_html('File not permission-synched: ' . $file));
                    }
                }
                foreach ($_MODIFIED_FILES as $file) {
                    if (strpos($file, '_cache') === false && substr($file, 0, strlen(get_file_base())) == get_file_base() && substr($file, -4) != '.log' && basename($file) != 'permissioncheckslog.php') {
                        @exit(escape_html('File not change-synched: ' . $file));
                    }
                }
                global $TITLE_CALLED, $SCREEN_TEMPLATE_CALLED, $EXITING;
                if (is_null($SCREEN_TEMPLATE_CALLED) && $EXITING == 0 && strpos(ocp_srv('PHP_SELF'), 'index.php') !== false) {
                    @exit(escape_html('No screen template called.'));
                }
                if (!$TITLE_CALLED && (is_null($SCREEN_TEMPLATE_CALLED) || $SCREEN_TEMPLATE_CALLED != '') && $EXITING == 0 && strpos(ocp_srv('PHP_SELF'), 'index.php') !== false) {
                    @exit(escape_html('No title used on screen.'));
                }
            }
            register_shutdown_function('debug_mode_aftertests');
        }
        if (ocp_srv('SCRIPT_FILENAME') != '' && $GLOBALS['DEBUG_MODE'] && strpos(ocp_srv('SCRIPT_FILENAME'), 'data_custom') === false) {
            if (@strlen(file_get_contents(ocp_srv('SCRIPT_FILENAME'), FILE_TEXT)) > 4500) {
                fatal_exit('Entry scripts (front controllers) should not be shoved full of code.');
            }
        }
    }
    // FirePHP console support, only for administrators
    if ((get_param_integer('keep_firephp', 0) == 1 || get_param_integer('keep_queries', 0) == 1) && ($GLOBALS['FORUM_DRIVER']->is_super_admin(get_member()) || $GLOBALS['IS_ACTUALLY_ADMIN'])) {
        require_code('firephp');
    }
    $default_memory_limit = get_value('memory_limit');
    if (is_null($default_memory_limit) || $default_memory_limit == '' || $default_memory_limit == '0' || $default_memory_limit == '-1') {
        $default_memory_limit = '64M';
    }
    @ini_set('memory_limit', $default_memory_limit);
    if (isset($GLOBALS['FORUM_DRIVER']) && $GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) {
        if (get_param_integer('keep_avoid_memory_limit', 0) == 1) {
            disable_php_memory_limit();
        }
        $memory_test = get_param_integer('keep_memory_limit_test', 0);
        if ($memory_test != 0 && $memory_test <= 32) {
            @ini_set('memory_limit', strval($memory_test) . 'M');
        }
    }
    if (get_option('sitewide_im', true) === '1' && running_script('index') && get_param('type', 'misc', true) != 'room') {
        require_code('chat');
        enter_chat_lobby();
    }
    // Startup hooks
    if (!running_script('upgrader')) {
        $startup_hooks = find_all_hooks('systems', 'startup');
        foreach (array_keys($startup_hooks) as $hook) {
            require_code('hooks/systems/startup/' . filter_naughty_harsh($hook));
            $ob = object_factory('Hook_startup_' . filter_naughty_harsh($hook), true);
            if ($ob === NULL) {
                continue;
            }
            $ob->run($MICRO_BOOTUP, $MICRO_AJAX_BOOTUP, 0);
        }
        if ($CURRENT_SHARE_USER !== NULL && float_to_raw_string(ocp_version_number()) != get_value('version')) {
            require_code('upgrade');
            clear_caches_2();
            version_specific();
            upgrade_modules();
            ocf_upgrade();
        }
    }
}
コード例 #5
0
ファイル: upgrade.php プロジェクト: erico-deh/ocPortal
/**
 * Clear many caches.
 */
function clear_caches_1()
{
    require_code('view_modes');
    erase_cached_templates();
    erase_cached_language();
}
コード例 #6
0
ファイル: addons.php プロジェクト: erico-deh/ocPortal
/**
 * Uninstall an addon.
 *
 * @param  string			Name of the addon
 */
function uninstall_addon($name)
{
    $addon_row = read_addon_info($name);
    require_code('zones2');
    require_code('zones3');
    require_code('abstract_file_manager');
    // Clear some cacheing
    require_code('view_modes');
    require_code('zones2');
    require_code('zones3');
    erase_comcode_page_cache();
    erase_tempcode_cache();
    persistant_cache_empty();
    erase_cached_templates();
    erase_cached_language();
    global $HOOKS_CACHE;
    $HOOKS_CACHE = array();
    // Remove addon info from database, modules, blocks, and files
    $last = array();
    foreach ($addon_row['addon_files'] as $filename) {
        if (@file_exists(get_file_base() . '/' . $filename)) {
            $test = $GLOBALS['SITE_DB']->query_value('addons_files', 'COUNT(*)', array('filename' => $filename));
            if ($test <= 1) {
                if (substr($filename, 0, 37) == 'sources/hooks/systems/addon_registry/') {
                    $last[] = $filename;
                    continue;
                }
                $matches = array();
                if (preg_match('#([^/]*)/?pages/modules(_custom)?/(.*)\\.php#', $filename, $matches) != 0) {
                    uninstall_module($matches[1], $matches[3]);
                }
                if (preg_match('#sources(_custom)?/blocks/(.*)\\.php#', $filename, $matches) != 0) {
                    uninstall_block($matches[2]);
                }
                if (preg_match('#^([^/]*)/index.php#', $filename, $matches) != 0) {
                    actual_delete_zone_lite($matches[1]);
                }
                if ($filename != 'mod.inf' && $filename != 'mod.php' && $filename != '' && substr($filename, -1) != '/') {
                    $last[] = $filename;
                }
            }
        }
    }
    foreach ($last as $filename) {
        afm_delete_file($filename);
    }
    $GLOBALS['SITE_DB']->query_delete('addons_files', array('addon_name' => $addon_row['addon_name']));
    $GLOBALS['SITE_DB']->query_delete('addons_dependencies', array('addon_name' => $addon_row['addon_name']));
    $GLOBALS['SITE_DB']->query_delete('addons', array('addon_name' => $addon_row['addon_name']), '', 1);
    global $ADDON_INSTALLED_CACHE;
    unset($ADDON_INSTALLED_CACHE[$addon_row['addon_name']]);
    if (function_exists('persistent_cache_set')) {
        persistent_cache_set('ADDONS_INSTALLED', $ADDON_INSTALLED_CACHE, true);
    }
    log_it('UNINSTALL_ADDON', $addon_row['addon_name']);
}
コード例 #7
0
ファイル: lang.php プロジェクト: erico-deh/ocPortal
/**
 * Get the human-readable form of a language id, or a language entry from a language INI file.
 *
 * @param  ID_TEXT		The language id
 * @param  ?mixed			The first token [string or tempcode] (replaces {1}) (NULL: none)
 * @param  ?mixed			The second token [string or tempcode] (replaces {2}) (NULL: none)
 * @param  ?mixed			The third token (replaces {3}). May be an array of [of string], to allow any number of additional args (NULL: none)
 * @param  ?LANGUAGE_NAME The language to use (NULL: users language)
 * @param  boolean		Whether to cause ocPortal to exit if the lookup does not succeed
 * @return ?mixed			The human-readable content (NULL: not found). String normally. Tempcode if tempcode parameters.
 */
function _do_lang($codename, $token1 = NULL, $token2 = NULL, $token3 = NULL, $lang = NULL, $require_result = true)
{
    global $LANGUAGE, $USER_LANG_CACHED, $RECORD_LANG_STRINGS, $XSS_DETECT, $PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED;
    if ($lang === NULL) {
        $lang = $USER_LANG_CACHED === NULL ? user_lang() : $USER_LANG_CACHED;
    }
    if ($GLOBALS['SEMI_DEBUG_MODE']) {
        $pos = strpos($codename, '=');
        if ($pos !== false) {
            // Find loaded file with smallest levenstein distance to current page
            $best = mixed();
            $best_for = NULL;
            global $LANGS_REQUESTED;
            foreach (array_keys($LANGS_REQUESTED) as $possible) {
                $dist = levenshtein(get_page_name(), $possible);
                if (is_null($best) || $best > $dist) {
                    $best = $dist;
                    $best_for = $possible;
                }
            }
            $save_path = get_file_base() . '/lang/' . fallback_lang() . '/' . $best_for . '.ini';
            if (!is_file($save_path)) {
                $save_path = get_file_base() . '/lang_custom/' . fallback_lang() . '/' . $best_for . '.ini';
            }
            // Tack language strings onto this file
            list($codename, $value) = explode('=', $codename, 2);
            $myfile = fopen($save_path, 'at');
            fwrite($myfile, "\n" . $codename . '=' . $value);
            fclose($myfile);
            // Fake-load the string
            $LANGUAGE[$lang][$codename] = $value;
            // Go through all required files, doing a string replace if needed
            $included_files = get_included_files();
            foreach ($included_files as $inc) {
                $orig_contents = file_get_contents($inc);
                $contents = str_replace("'" . $codename . '=' . $value . "'", "'" . $codename . "'", $orig_contents);
                if ($orig_contents != $contents) {
                    $myfile = fopen($inc, 'wt');
                    fwrite($myfile, $contents);
                    fclose($myfile);
                }
            }
        }
    }
    $there = isset($LANGUAGE[$lang][$codename]);
    if (!$there) {
        $pos = strpos($codename, ':');
        if ($pos !== false) {
            require_lang(substr($codename, 0, $pos), NULL, NULL, !$require_result);
            $codename = substr($codename, $pos + 1);
        }
        $there = isset($LANGUAGE[$lang][$codename]);
    }
    if ($RECORD_LANG_STRINGS) {
        global $RECORDED_LANG_STRINGS;
        $RECORDED_LANG_STRINGS[$codename] = 1;
    }
    if (!$there && (!isset($LANGUAGE[$lang]) || !array_key_exists($codename, $LANGUAGE[$lang]))) {
        global $PAGE_CACHE_LAZY_LOAD, $PAGE_CACHE_LANGS_REQUESTED, $LANG_REQUESTED_LANG;
        if ($PAGE_CACHE_LAZY_LOAD) {
            $PAGE_CACHE_LAZY_LOAD = false;
            // We can't be lazy any more, but we will keep growing our pool so hopefully CAN be lazy the next time
            foreach ($PAGE_CACHE_LANGS_REQUESTED as $request) {
                list($that_codename, $that_lang) = $request;
                unset($LANG_REQUESTED_LANG[$that_lang][$that_codename]);
                require_lang($that_codename, $that_lang, NULL, true);
            }
            $ret = _do_lang($codename, $token1, $token2, $token3, $lang, $require_result);
            if ($ret === NULL) {
                $PAGE_CACHE_LANG_LOADED[$lang][$codename] = NULL;
                if ($GLOBALS['MEM_CACHE'] !== NULL) {
                    persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED);
                } else {
                    open_page_cache_file();
                    @rewind($PAGE_CACHE_FILE);
                    @flock($PAGE_CACHE_FILE, LOCK_EX);
                    @ftruncate($PAGE_CACHE_FILE, 0);
                    @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED));
                    @flock($PAGE_CACHE_FILE, LOCK_UN);
                }
            }
            return $ret;
        }
        require_all_open_lang_files($lang);
    }
    if ($lang == 'xxx') {
        return 'xxx';
    }
    // Helpful for testing language compliancy. We don't expect to see non x's if we're running this language
    if (!isset($LANGUAGE[$lang][$codename]) && ($require_result || !isset($LANGUAGE[$lang]) || !array_key_exists($codename, $LANGUAGE[$lang]))) {
        if ($lang != fallback_lang()) {
            $ret = do_lang($codename, $token1, $token2, $token3, fallback_lang(), $require_result);
            if ($PAGE_CACHE_FILE !== NULL) {
                if (!isset($PAGE_CACHE_LANG_LOADED[$lang][$codename]) && isset($PAGE_CACHE_LANG_LOADED[fallback_lang()][$codename])) {
                    $PAGE_CACHE_LANG_LOADED[$lang][$codename] = $PAGE_CACHE_LANG_LOADED[fallback_lang()][$codename];
                    // Will have been cached into fallback_lang() from the nested do_lang call, we need to copy it into our cache bucket for this language
                    if ($GLOBALS['MEM_CACHE'] !== NULL) {
                        persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED);
                    } else {
                        open_page_cache_file();
                        @rewind($PAGE_CACHE_FILE);
                        @flock($PAGE_CACHE_FILE, LOCK_EX);
                        @ftruncate($PAGE_CACHE_FILE, 0);
                        @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED));
                        @flock($PAGE_CACHE_FILE, LOCK_UN);
                    }
                }
            }
            return $ret;
        } else {
            if ($require_result) {
                global $USER_LANG_LOOP, $REQUIRE_LANG_LOOP;
                //print_r(debug_backtrace());
                if ($USER_LANG_LOOP == 1) {
                    critical_error('RELAY', 'Missing language code: ' . escape_html($codename) . '. This language code is required to produce error messages, and thus a critical error was prompted by the non-ability to show less-critical error messages. It is likely the source language files (lang/' . fallback_lang() . '/*.ini) for ocPortal on this website have been corrupted.');
                }
                if ($REQUIRE_LANG_LOOP >= 2) {
                    return '';
                }
                // Probably failing to load global.ini, so just output with some text missing
                require_code('view_modes');
                erase_cached_language();
                require_code('site');
                attach_message(do_lang_tempcode('MISSING_LANG_ENTRY', escape_html($codename)), 'warn');
                return '';
            } else {
                return NULL;
            }
        }
    }
    if ($PAGE_CACHE_FILE !== NULL) {
        if (!isset($PAGE_CACHE_LANG_LOADED[$lang][$codename]) && (!isset($PAGE_CACHE_LANG_LOADED[$lang]) || !array_key_exists($codename, $PAGE_CACHE_LANG_LOADED[$lang]))) {
            $PAGE_CACHE_LANG_LOADED[$lang][$codename] = $LANGUAGE[$lang][$codename];
            if ($GLOBALS['MEM_CACHE'] !== NULL) {
                persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED);
            } else {
                open_page_cache_file();
                @rewind($PAGE_CACHE_FILE);
                @flock($PAGE_CACHE_FILE, LOCK_EX);
                @ftruncate($PAGE_CACHE_FILE, 0);
                @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED));
                @flock($PAGE_CACHE_FILE, LOCK_UN);
            }
        }
    }
    // Put in parameters
    static $non_plural_non_vowel = array('1', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z', '{');
    $looked_up = $LANGUAGE[$lang][$codename];
    if ($looked_up === NULL) {
        return NULL;
        // Learning cache pool has told us this string definitely does not exist
    }
    $out = str_replace('\\n', "\n", $looked_up);
    $plural_or_vowel_check = strpos($out, '|') !== false;
    if ($XSS_DETECT) {
        ocp_mark_as_escaped($out);
    }
    if ($token1 !== NULL) {
        if (is_object($token1) && $token2 === NULL || $token2 !== NULL && is_object($token2)) {
            $bits = preg_split('#\\{\\d[^\\}]*\\}#', $out, 2, PREG_SPLIT_OFFSET_CAPTURE);
            $ret = new ocp_tempcode();
            foreach ($bits as $bit) {
                if ($XSS_DETECT) {
                    ocp_mark_as_escaped($bit[0]);
                }
                $at = $bit[1];
                if ($at != 0) {
                    if ($out[$at - 2] == '1') {
                        $ret->attach($token1);
                    } elseif ($out[$at - 2] == '2') {
                        $ret->attach($token2);
                    } elseif ($plural_or_vowel_check && substr($out[$at - 2], 0, 2) == '1|') {
                        $exploded = explode('|', $out[$at - 2]);
                        $_token = $token1->evaluate();
                        $_token_denum = str_replace(',', '', $_token);
                        $ret->attach(in_array(is_numeric($_token_denum) ? $_token_denum : ocp_mb_strtolower(ocp_mb_substr($_token, 0, 1)), $non_plural_non_vowel) ? $exploded[1] : $exploded[2]);
                    } elseif ($plural_or_vowel_check && substr($out[$at - 2], 0, 2) == '2|') {
                        $exploded = explode('|', $out[$at - 2]);
                        $_token = $token2->evaluate();
                        $_token_denum = str_replace(',', '', $_token);
                        $ret->attach(in_array(is_numeric($_token_denum) ? $_token_denum : ocp_mb_strtolower(ocp_mb_substr($_token, 0, 1)), $non_plural_non_vowel) ? $exploded[1] : $exploded[2]);
                    }
                }
                $ret->attach($bit[0]);
            }
            return $ret;
        } elseif ($token1 !== NULL) {
            $out = str_replace('{1}', $token1, $out);
            if ($plural_or_vowel_check) {
                $_token_denum = str_replace(',', '', $token1);
                $out = preg_replace('#\\{1\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : ocp_mb_strtolower(ocp_mb_substr($token1, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out);
            }
            if ($XSS_DETECT && ocp_is_escaped($token1)) {
                ocp_mark_as_escaped($out);
            }
        }
        if ($token2 !== NULL) {
            if ($XSS_DETECT) {
                $escaped = ocp_is_escaped($out);
            }
            $out = str_replace('{2}', $token2, $out);
            if ($plural_or_vowel_check) {
                $_token_denum = str_replace(',', '', $token1);
                $out = preg_replace('#\\{2\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : ocp_mb_strtolower(ocp_mb_substr($token2, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out);
            }
            if ($XSS_DETECT && ocp_is_escaped($token2) && $escaped) {
                ocp_mark_as_escaped($out);
            }
            if ($token3 !== NULL) {
                $i = 3;
                if (!is_array($token3)) {
                    $token3 = array($token3);
                }
                foreach ($token3 as $token) {
                    if ($XSS_DETECT) {
                        $escaped = ocp_is_escaped($out);
                    }
                    $out = str_replace('{' . strval($i) . '}', $token, $out);
                    if ($plural_or_vowel_check) {
                        $_token_denum = str_replace(',', '', $token);
                        $out = preg_replace('#\\{' . strval($i) . '\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : ocp_mb_strtolower(ocp_mb_substr($token, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out);
                    }
                    if ($XSS_DETECT && ocp_is_escaped($token) && $escaped) {
                        ocp_mark_as_escaped($out);
                    }
                    $i++;
                }
            }
        }
    }
    return $out;
}