| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | function xcache_validateFileName($name) |
|---|
| 4 | { |
|---|
| 5 | return preg_match('!^[a-zA-Z0-9._-]+$!', $name); |
|---|
| 6 | } |
|---|
| 7 | |
|---|
| 8 | function get_language_file_ex($name, $l, $s) |
|---|
| 9 | { |
|---|
| 10 | static $lmap = array( |
|---|
| 11 | 'zh' => 'zh-simplified', |
|---|
| 12 | 'zh-hk' => 'zh-traditional', |
|---|
| 13 | 'zh-tw' => 'zh-traditional', |
|---|
| 14 | ); |
|---|
| 15 | static $smap = array( |
|---|
| 16 | 'gbk' => 'gb2312', |
|---|
| 17 | 'gb18030' => 'gb2312', |
|---|
| 18 | ); |
|---|
| 19 | |
|---|
| 20 | if (isset($lmap[$l])) { |
|---|
| 21 | $l = $lmap[$l]; |
|---|
| 22 | } |
|---|
| 23 | $file = "$name-$l-$s.lang.php"; |
|---|
| 24 | if (xcache_validateFileName($file) && file_exists($file)) { |
|---|
| 25 | return $file; |
|---|
| 26 | } |
|---|
| 27 | if (isset($smap[$s])) { |
|---|
| 28 | $s = $smap[$s]; |
|---|
| 29 | $file = "$name-$l-$s.lang.php"; |
|---|
| 30 | if (xcache_validateFileName($file) && file_exists($file)) { |
|---|
| 31 | return $file; |
|---|
| 32 | } |
|---|
| 33 | } |
|---|
| 34 | $file = "$name-$l.lang.php"; |
|---|
| 35 | if (xcache_validateFileName($file) && file_exists($file)) { |
|---|
| 36 | return $file; |
|---|
| 37 | } |
|---|
| 38 | return null; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | function get_language_file($name) |
|---|
| 42 | { |
|---|
| 43 | global $config; |
|---|
| 44 | $s = strtolower($config['charset']); |
|---|
| 45 | if (!empty($config['lang'])) { |
|---|
| 46 | $l = strtolower($config['lang']); |
|---|
| 47 | $file = get_language_file_ex($name, $l, $s); |
|---|
| 48 | if (!isset($file)) { |
|---|
| 49 | $l = strtok($l, ':-'); |
|---|
| 50 | $file = get_language_file_ex($name, $l, $s); |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | else if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|---|
| 54 | foreach (explode(',', str_replace(' ', '', $_SERVER['HTTP_ACCEPT_LANGUAGE'])) as $l) { |
|---|
| 55 | $l = strtok($l, ':;'); |
|---|
| 56 | $file = get_language_file_ex($name, $l, $s); |
|---|
| 57 | if (isset($file)) { |
|---|
| 58 | $config['lang'] = $l; |
|---|
| 59 | break; |
|---|
| 60 | } |
|---|
| 61 | if (strpos($l, '-') !== false) { |
|---|
| 62 | $ll = strtok($l, ':-'); |
|---|
| 63 | $file = get_language_file_ex($name, $ll, $s); |
|---|
| 64 | if (isset($file)) { |
|---|
| 65 | $config['lang'] = $l; |
|---|
| 66 | break; |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | return isset($file) ? $file : "$name-en.lang.php"; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | function _T($str) |
|---|
| 75 | { |
|---|
| 76 | if (isset($GLOBALS['strings'][$str])) { |
|---|
| 77 | return $GLOBALS['strings'][$str]; |
|---|
| 78 | } |
|---|
| 79 | if (!empty($GLOBALS['config']['show_todo_strings'])) { |
|---|
| 80 | return '<span style="color:red">' . htmlspecialchars($str) . '</span>'; |
|---|
| 81 | } |
|---|
| 82 | return $str; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | function stripaddslashes_array($value, $mqs = false) |
|---|
| 86 | { |
|---|
| 87 | if (is_array($value)) { |
|---|
| 88 | foreach($value as $k => $v) { |
|---|
| 89 | $value[$k] = stripaddslashes_array($v, $mqs); |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | else if(is_string($value)) { |
|---|
| 93 | $value = $mqs ? str_replace('\'\'', '\'', $value) : stripslashes($value); |
|---|
| 94 | } |
|---|
| 95 | return $value; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | function ob_filter_path_nicer_default($list_html) |
|---|
| 99 | { |
|---|
| 100 | $sep = DIRECTORY_SEPARATOR; |
|---|
| 101 | $docRoot = $_SERVER['DOCUMENT_ROOT']; |
|---|
| 102 | if ($sep != '/') { |
|---|
| 103 | $docRoot = str_replace('/', $sep, $docRoot); |
|---|
| 104 | } |
|---|
| 105 | $list_html = str_replace($docRoot, "{DOCROOT}" . (substr($docRoot, -1) == $sep ? $sep : ""), $list_html); |
|---|
| 106 | $xcachedir = realpath(dirname(__FILE__) . "$sep..$sep"); |
|---|
| 107 | $list_html = str_replace($xcachedir . $sep, "{XCache}$sep", $list_html); |
|---|
| 108 | if ($sep == '/') { |
|---|
| 109 | $list_html = str_replace("/home/", "{H}/", $list_html); |
|---|
| 110 | } |
|---|
| 111 | return $list_html; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | error_reporting(E_ALL); |
|---|
| 116 | ini_set('display_errors', 'On'); |
|---|
| 117 | define('REQUEST_TIME', time()); |
|---|
| 118 | |
|---|
| 119 | if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc()) { |
|---|
| 120 | $mqs = (bool) ini_get('magic_quotes_sybase'); |
|---|
| 121 | $_GET = stripaddslashes_array($_GET, $mqs); |
|---|
| 122 | $_POST = stripaddslashes_array($_POST, $mqs); |
|---|
| 123 | $_REQUEST = stripaddslashes_array($_REQUEST, $mqs); |
|---|
| 124 | unset($mqs); |
|---|
| 125 | } |
|---|
| 126 | ini_set('magic_quotes_runtime', '0'); |
|---|
| 127 | |
|---|
| 128 | $config = array(); |
|---|
| 129 | include("./config.default.php"); |
|---|
| 130 | if (file_exists("./config.php")) { |
|---|
| 131 | include("./config.php"); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | include(get_language_file("common")); |
|---|
| 135 | if (empty($config['lang'])) { |
|---|
| 136 | $config['lang'] = 'en-us'; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | header("Cache-Control: no-cache, must-revalidate"); |
|---|
| 140 | header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); |
|---|
| 141 | |
|---|
| 142 | ?> |
|---|