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