| [123] | 1 | <?php |
|---|
| 2 | |
|---|
| [1053] | 3 | class Cycle |
|---|
| 4 | { |
|---|
| 5 | var $values; |
|---|
| 6 | var $i; |
|---|
| 7 | var $count; |
|---|
| 8 | |
|---|
| 9 | function Cycle($v) |
|---|
| 10 | { |
|---|
| 11 | $this->values = func_get_args(); |
|---|
| 12 | $this->i = -1; |
|---|
| 13 | $this->count = count($this->values); |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | function next() |
|---|
| 17 | { |
|---|
| 18 | $this->i = ($this->i + 1) % $this->count; |
|---|
| 19 | return $this->values[$this->i]; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | function cur() |
|---|
| 23 | { |
|---|
| 24 | return $this->values[$this->i]; |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | function reset() |
|---|
| 28 | { |
|---|
| 29 | $this->i = -1; |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | function switcher($name, $options) |
|---|
| 34 | { |
|---|
| 35 | $n = isset($_GET[$name]) ? $_GET[$name] : null; |
|---|
| 36 | $html = array(); |
|---|
| 37 | foreach ($options as $k => $v) { |
|---|
| 38 | $html[] = sprintf('<a href="?%s=%s"%s>%s</a>', $name, $k, $k == $n ? ' class="active"' : '', $v); |
|---|
| 39 | } |
|---|
| 40 | return implode('', $html); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | function moduleswitcher() |
|---|
| 44 | { |
|---|
| 45 | global $module, $modules; |
|---|
| 46 | $html = array(); |
|---|
| 47 | foreach ($modules as $k => $v) { |
|---|
| 48 | $html[] = sprintf('<a href="../%s/"%s>%s</a>', $k, $k == $module ? ' class="active"' : '', $v); |
|---|
| 49 | } |
|---|
| 50 | return implode('', $html); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | function th($name, $attrs = null) |
|---|
| 54 | { |
|---|
| 55 | $translated = __($name); |
|---|
| 56 | if ($translated == $name) { |
|---|
| 57 | $translated = "$name|$name"; |
|---|
| 58 | } |
|---|
| 59 | list($text, $title) = explode('|', $translated, 2); |
|---|
| 60 | return sprintf('%s<th%s id="%s" title="%s"><a href="javascript:" onclick="resort(this); return false">%s</a></th>%s' |
|---|
| 61 | , "\t" |
|---|
| 62 | , $attrs ? " $attrs" : "" |
|---|
| 63 | , $name, htmlspecialchars(trim($title)), trim($text) |
|---|
| 64 | , "\n"); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| [783] | 67 | function xcache_validateFileName($name) |
|---|
| 68 | { |
|---|
| [1056] | 69 | if (!preg_match('!^[a-zA-Z0-9._-]+$!', $name)) { |
|---|
| 70 | var_dump($name); |
|---|
| 71 | } |
|---|
| [783] | 72 | return preg_match('!^[a-zA-Z0-9._-]+$!', $name); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| [1053] | 75 | function get_language_file_ex($name, $lang) |
|---|
| [123] | 76 | { |
|---|
| [1053] | 77 | static $langMap = array( |
|---|
| [123] | 78 | 'zh' => 'zh-simplified', |
|---|
| 79 | 'zh-hk' => 'zh-traditional', |
|---|
| 80 | 'zh-tw' => 'zh-traditional', |
|---|
| 81 | ); |
|---|
| 82 | |
|---|
| [1053] | 83 | if (isset($langMap[$lang])) { |
|---|
| 84 | $lang = $langMap[$lang]; |
|---|
| [123] | 85 | } |
|---|
| [1056] | 86 | else if (!xcache_validateFileName($lang)) { |
|---|
| 87 | return null; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| [1053] | 90 | $file = "$name-$lang.lang.php"; |
|---|
| [1056] | 91 | if (file_exists($file)) { |
|---|
| [123] | 92 | return $file; |
|---|
| 93 | } |
|---|
| 94 | return null; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | function get_language_file($name) |
|---|
| 98 | { |
|---|
| [902] | 99 | global $config; |
|---|
| 100 | if (!empty($config['lang'])) { |
|---|
| [1053] | 101 | $lang = strtolower($config['lang']); |
|---|
| 102 | $file = get_language_file_ex($name, $lang); |
|---|
| [134] | 103 | if (!isset($file)) { |
|---|
| [1053] | 104 | $lang = strtok($lang, ':-'); |
|---|
| 105 | $file = get_language_file_ex($name, $lang); |
|---|
| [134] | 106 | } |
|---|
| [123] | 107 | } |
|---|
| 108 | else if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|---|
| [1053] | 109 | foreach (explode(',', str_replace(' ', '', $_SERVER['HTTP_ACCEPT_LANGUAGE'])) as $lang) { |
|---|
| 110 | $lang = strtok($lang, ':;'); |
|---|
| 111 | $file = get_language_file_ex($name, $lang); |
|---|
| [123] | 112 | if (isset($file)) { |
|---|
| [1053] | 113 | $config['lang'] = $lang; |
|---|
| [123] | 114 | break; |
|---|
| 115 | } |
|---|
| [1053] | 116 | if (strpos($lang, '-') !== false) { |
|---|
| 117 | $file = get_language_file_ex($name, strtok($lang, ':-')); |
|---|
| [123] | 118 | if (isset($file)) { |
|---|
| [1053] | 119 | $config['lang'] = $lang; |
|---|
| [123] | 120 | break; |
|---|
| 121 | } |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | return isset($file) ? $file : "$name-en.lang.php"; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| [1038] | 128 | function _($str) |
|---|
| [123] | 129 | { |
|---|
| 130 | if (isset($GLOBALS['strings'][$str])) { |
|---|
| 131 | return $GLOBALS['strings'][$str]; |
|---|
| 132 | } |
|---|
| [902] | 133 | if (!empty($GLOBALS['config']['show_todo_strings'])) { |
|---|
| [1038] | 134 | return '<span style="color:red">' . htmlspecialchars($str) . '</span>|'; |
|---|
| [123] | 135 | } |
|---|
| 136 | return $str; |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| [1038] | 139 | function __($str) |
|---|
| 140 | { |
|---|
| 141 | return _($str); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | function N_($str) |
|---|
| 145 | { |
|---|
| 146 | return $str; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| [1053] | 149 | function number_formats($a, $keys) |
|---|
| 150 | { |
|---|
| 151 | foreach ($keys as $k) { |
|---|
| 152 | $a[$k] = number_format($a[$k]); |
|---|
| 153 | } |
|---|
| 154 | return $a; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | function size($size) |
|---|
| 158 | { |
|---|
| 159 | $size = (int) $size; |
|---|
| 160 | if ($size < 1024) |
|---|
| 161 | return number_format($size, 2) . ' b'; |
|---|
| 162 | |
|---|
| 163 | if ($size < 1048576) |
|---|
| 164 | return number_format($size / 1024, 2) . ' K'; |
|---|
| 165 | |
|---|
| 166 | return number_format($size / 1048576, 2) . ' M'; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | function age($time) |
|---|
| 170 | { |
|---|
| 171 | if (!$time) return ''; |
|---|
| 172 | $delta = REQUEST_TIME - $time; |
|---|
| 173 | |
|---|
| 174 | if ($delta < 0) { |
|---|
| 175 | $delta = -$delta; |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | static $seconds = array(1, 60, 3600, 86400, 604800, 2678400, 31536000); |
|---|
| 179 | static $name = array('s', 'm', 'h', 'd', 'w', 'M', 'Y'); |
|---|
| 180 | |
|---|
| 181 | for ($i = 6; $i >= 0; $i --) { |
|---|
| 182 | if ($delta >= $seconds[$i]) { |
|---|
| 183 | $ret = (int) ($delta / $seconds[$i]); |
|---|
| 184 | return $ret . ' ' . $name[$i]; |
|---|
| 185 | } |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | return '0 s'; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| [418] | 191 | function stripaddslashes_array($value, $mqs = false) |
|---|
| 192 | { |
|---|
| 193 | if (is_array($value)) { |
|---|
| 194 | foreach($value as $k => $v) { |
|---|
| 195 | $value[$k] = stripaddslashes_array($v, $mqs); |
|---|
| 196 | } |
|---|
| 197 | } |
|---|
| 198 | else if(is_string($value)) { |
|---|
| 199 | $value = $mqs ? str_replace('\'\'', '\'', $value) : stripslashes($value); |
|---|
| 200 | } |
|---|
| 201 | return $value; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| [902] | 204 | function ob_filter_path_nicer_default($list_html) |
|---|
| 205 | { |
|---|
| 206 | $sep = DIRECTORY_SEPARATOR; |
|---|
| 207 | $docRoot = $_SERVER['DOCUMENT_ROOT']; |
|---|
| [926] | 208 | if ($sep != '/') { |
|---|
| 209 | $docRoot = str_replace('/', $sep, $docRoot); |
|---|
| 210 | } |
|---|
| [953] | 211 | $list_html = str_replace(">$docRoot", ">{DOCROOT}" . (substr($docRoot, -1) == $sep ? $sep : ""), $list_html); |
|---|
| [902] | 212 | $xcachedir = realpath(dirname(__FILE__) . "$sep..$sep"); |
|---|
| [953] | 213 | $list_html = str_replace(">$xcachedir$sep", ">{XCache}$sep", $list_html); |
|---|
| [902] | 214 | if ($sep == '/') { |
|---|
| [953] | 215 | $list_html = str_replace(">/home/", ">{H}/", $list_html); |
|---|
| [902] | 216 | } |
|---|
| 217 | return $list_html; |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| [123] | 220 | error_reporting(E_ALL); |
|---|
| [181] | 221 | ini_set('display_errors', 'On'); |
|---|
| [123] | 222 | define('REQUEST_TIME', time()); |
|---|
| 223 | |
|---|
| [549] | 224 | if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc()) { |
|---|
| [418] | 225 | $mqs = (bool) ini_get('magic_quotes_sybase'); |
|---|
| 226 | $_GET = stripaddslashes_array($_GET, $mqs); |
|---|
| 227 | $_POST = stripaddslashes_array($_POST, $mqs); |
|---|
| 228 | $_REQUEST = stripaddslashes_array($_REQUEST, $mqs); |
|---|
| [902] | 229 | unset($mqs); |
|---|
| [418] | 230 | } |
|---|
| 231 | ini_set('magic_quotes_runtime', '0'); |
|---|
| 232 | |
|---|
| [902] | 233 | $config = array(); |
|---|
| [1053] | 234 | if (file_exists("./config.default.php")) { |
|---|
| 235 | include("./config.default.php"); |
|---|
| 236 | } |
|---|
| 237 | include("../config.default.php"); |
|---|
| 238 | if (file_exists("../config.php")) { |
|---|
| 239 | include("../config.php"); |
|---|
| 240 | } |
|---|
| [123] | 241 | if (file_exists("./config.php")) { |
|---|
| 242 | include("./config.php"); |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| [1056] | 245 | include(get_language_file("../common/common")); |
|---|
| [1053] | 246 | |
|---|
| 247 | $modules = array(); |
|---|
| 248 | if (file_exists("../cacher/index.php")) { |
|---|
| 249 | $modules["cacher"] = _("Cacher"); |
|---|
| [125] | 250 | } |
|---|
| [1053] | 251 | if (file_exists("../coverager/index.php")) { |
|---|
| 252 | $modules["coverager"] = _("Coverager"); |
|---|
| 253 | } |
|---|
| [951] | 254 | header("Cache-Control: no-cache, must-revalidate"); |
|---|
| 255 | header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); |
|---|
| 256 | |
|---|
| [123] | 257 | ?> |
|---|