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