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