Record [f:main/front.php] < dev.sky.1.001
Version 1.001
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | <?php defined('START') or die; # For Licence and Disclaimer of this code, see http://coresky.net/license function cache($file = 0, $sec = 0) { global $sky, $front; if (!$sky->s_cache_act) return; # caching off $front->label(); if ($file) { # begin $file = "var/hard/_$file.html"; if (-1 == $sec) { @unlink($file); return; } $front->cache_file = $file; $sec or $sec = $sky->mem['s'][3]['cache_sec']; is_file($front->cache_file) and $s = stat($front->cache_file) and $s['mtime'] + $sec > time() or $front->cache_data = 1; # file required! } else { # end $tail = ob_get_clean(); echo $front->cache_data && file_put_contents($front->cache_file, $front->cache_data .= $tail) ? $front->cache_data : file_get_contents($front->cache_file); $front->cache_file = $front->cache_data = ''; $sky->traced or ob_start(); } } function t() { # situational translation $ary = func_get_args(); global $sky; $sky->trans_i or $sky->trans_i = 0; if ($args = $ary) $str = array_shift($ary); else { if ($sky->trans_i++ % 2) $str = ob_get_clean(); else return ob_start(); } if (is_array(@$ary[0])) $ary = $ary[0]; if (isset($sky->trans_late[$str])) $str = $sky->trans_late[$str]; elseif (3 == DEBUG) $sky->reg['trans_coll'][$str] = $sky->trans_i; $args or print $str; return $ary ? vsprintf($str, $ary) : $str; } class SKY_FRONT { const PROC = ' if ($sky->body) { $front->view(); if ($front->vars) extract($front->vars, EXTR_REFS); } if ($sky->layout) { if ("main" != $sky->layout) { require "$sky->style/y_$sky->layout.php"; exit; } } else { if ($sky->body) eval($sky); $sky->tail_x(); exit; }'; public $code; public $vars; public $label = []; public $cache_file = ''; public $cache_data = ''; public $cc = false; public $mc = false; function __get($name) { global $sky; return $sky->$name; } function __set($name, $value) { global $sky; $sky->reg[$name] = $value; } function __construct() { global $user, $sky; $user->v_layout or $user->v_layout = 'main'; if ('mobile' == PAGE || 'pc' == PAGE) { $user->v_layout = 'pc' == PAGE ? 'main' : 'mobile'; jump(in_array($sky->lref, ['logout', 'mobile', 'pc']) ? false : $sky->lref); } $this->_v = $this->_y = []; } function translate($coll = 0) { global $sky; if ($coll) { # write new AJAX or trace($coll, 'Collected new translations'); $function = sprintf('return "\t1\t$v\t%s\t" . escape($k, true);', PAGE . "\t" . (int)START_TS); $new = escape("\n" . implode("\n", array_map(create_function('$k,$v', $function), array_keys($coll), $coll))); mysqli_query($sky->idc, "update _lang set tmemo=trim('\n' from concat(tmemo,$new))"); } else { # read 2 translate $sky->trans_coll = []; $default = LG == DEFAULT_LANG; $two = sql("@select lang, tmemo from _lang where " . ($default ? "lang='" . LG . "'" : "lang in ('" . DEFAULT_LANG . "','" . LG . "')")); $k = array_filter(explode("\n", $two[DEFAULT_LANG]), create_function('$v', 'return "\t" == $v[0];')); $v = $default ? $k : array_filter(explode("\n", $two[LG]), create_function('$v', 'return "\t" == $v[0];')); $function = create_function('$v', '$v = explode("\t", $v); return unescape($v[5], true);'); $sky->trans_late = array_combine(array_map($function, $k), array_map($function, $v)); if (DEBUG > 3) trace($sky->trans_late, '$sky->trans_late'); } } function pdaxt() { global $user; if (DEV || $user->id == 1 || $user->adm_allowed) { echo js("function trace(str) { box('<pre>' + str + '</pre>', sky.xt); sky.show(); }") . '<span class="pdaxt">'; echo DEV ? a('P', 'http://' . _PUBLIC) : 'P'; echo DEV && is_dir('_dev') ? a('D', LINK . 'dev.php') : 'D'; echo $user->auth ? a('A', LINK . 'adm') : 'A'; echo a('X', "javascript:$.post('index.php?AJAX=ajax',{},trace); returnfalse;") . a('T', "javascript:trace($('#trace').html())") . '</span>'; } } function body($in, $label = false) { if ($label) $this->body = $label; if (true === $in) $this->layout = $this->body = ''; elseif ('' === $in) $this->layout = ''; elseif (!is_null($in)) $this->body = $in; } function label($ob = '', $deep = 0) { if ($this->cache_file && !$this->cache_data) return true; # cache file OK $ob or $ob = ob_get_clean(); $ok = $deep < 10; $trace = ''; if ($ok && preg_match_all("/%(PHP|HTML)_([A-Z\d_]+)%/", $ob, $match, PREG_SET_ORDER)) { foreach ($match as $m) if ($trace .= ", $m[0]" and !isset($this->label[$m[0]])) { $label = strtolower($m[2]); if (DEV && 'r_' == substr($label, 0, 2)) $file = tag(html($m[0]), 'class="red_label"'); else { $ext = strtolower($m[1]); ob_start(); if ($file = @file_get_contents("$this->style/e_$label.$ext")) { if ('php' == $ext) call_user_func(function($label_code) { eval("?>$label_code"); }, $file); } else { $this->_v = []; $mc = method_exists($this->mc, "e_$label"); $this->body($mc ? $this->mc->{"e_$label"}() : $this->cc->{"e_$label"}(), $label); if ($this->body) $this->sub_view(); } if ($bf = ob_get_clean()) $file = $bf; } $this->label[$m[0]] = $file; } if (DEBUG === 3) trace("LABELS: [$deep]$trace", 0, 2); $this->label(strtr($ob, $this->label), ++$deep); } else { if ($this->cache_file && $this->cache_data) $this->cache_data = $this->cache_data === 1 ? $ob : $this->cache_data . $ob; else echo $ob; $this->traced or ob_start(); if (!$ok) trace('LABELS: recursion error', true); elseif (DEBUG === 3 && !$deep) trace("LABELS: [0], no work", 0, 2); return $ok; } } function json($ary, $cb_name = false) { foreach ($ary as &$one) if (is_object($one)) $one = $this->object($one); $this->content_type = 'Content-Type: application/json; charset=' . ENC; $out = json_encode($ary); echo $cb_name ? "$_GET[$cb_name]($out);" : $out; $this->layout = ''; trace($ary, '->echo_json()'); return json_last_error(); } function vars(&$v, $k, $_) { if ('_' != @$k[1]) $k = $_ . $k; else switch ($k[0]) { case 'h': if (is_array($v)) array_walk_recursive($v, create_function('&$v, $k', '"_" !== @$k[1] or "h" != $k[0] or $v = html($v);')); else $v = html($v); break; case 'e': if (isset($v['query'])) { $v += ['row' => sprintf('if (!$sky->callback_row){ $query = $%s->query; $sky->callback_row = %s; }', $k, isset($v['callback']) ? "\${$k}->callback" : 'true') . row]; } $v = (object)$v; break; case 'k': case 'd': $d = 'd' == $k[0]; $k = substr($k, 2); if ($d) break; return $GLOBALS['k_']->{$k} = $v; } $this->vars[$k] = $v; } function object($obj) { ob_start(); array_walk($obj, function ($v, $body) { if (is_int($body)) return print $v; if (!is_array($v)) return trace('SKY_FRONT::object() syntax error', true); global $sky, $front; $sky->body = $body; $sky->reg['_v'] =& $v; $front->sub_view(); }); return ob_get_clean(); } function sub_view($eval = true) { global $sky; if (is_array($sky->body)) $sky->body = (object)$sky->body; if ($eval) { $code = $sky->code; $sky->code = ''; } if ($obj = is_object($sky->body)) { $sky->code .= 'echo $front->object($sky->body);'; # imperfect design } elseif (count($part = explode('.', $sky->body)) > 1) { if (!$file = @file_get_contents("$sky->style/_$part[0].php")) return false; # 2do mobile style list (,$sky->body,) = explode("#$part[1]#", $file, 3); $sky->code .= 'eval(' . var_export($sky->body, true) . ');'; } elseif ('_' == $sky->body) { # virtual view page ? $sky->code .= 'echo $v_content;'; } elseif (is_file($file = "$sky->style/_$sky->body.php")) { $sky->code .= "require '$file';"; } else return false; if ($eval) { if (count($this->vars) > $this->y_size) array_splice($this->vars, $this->y_size); if (!$obj) array_walk($sky->reg['_v'], [$this, 'vars'], 'v_'); call_user_func(function() { global $sky, $front, $k_, $me; extract($front->vars, EXTR_REFS); eval($sky->code); }); $sky->code = $code; } return true; } function view($label = false) { global $sky, $k_; if (is_array($sky->body)) { # json output $sky->code = '$front->json($sky->body, $sky->jsonp);'; return $sky->layout = ''; } array_walk($sky->reg['_y'], [$this, 'vars'], 'y_'); $this->y_size = count($this->vars); array_walk($sky->reg['_v'], [$this, 'vars'], 'v_'); if ($sky->layout) { if (1 & $k_->midlab) $sky->code = '$front->label();'; $sky->code .= 'echo \'<div style="display:none" id="err-top"></div>\';'; } $err = is_numeric($sky->body) && 404 == $sky->body || !$this->sub_view(false) && $this->layout; if ($err) $sky->code .= '$front->error();'; if ((2 & $k_->midlab) && $this->layout) $sky->code .= '$front->label();'; } function error() { global $sky, $user, $k_, $me; if ($user->ky_error) { if (is_file($file = "$sky->style/_ky.php")) require $file; else { $ok = sprintf(span_g, 'work OK'); $fail = sprintf(span_r, 'NOT work'); echo '<h1>Your browser not adjusted!</h1><p>This web-application require to work:</p><ul>'; if ($sky->s_c_manda) printf('<li>COOKIES - %s</li>', $user->ky_c ? $fail : $ok); if ($sky->s_j_manda) printf('<li>JAVASCRIPT - %s</li>', $user->ky_j ? $fail : $ok); echo '</ul><p>Please fix problem and <a href="ky_reset">click this</a> to get access!</p>'; } } else { header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); if (404 != $sky->body) trace("View file `$sky->style/_$sky->body.php` not exist", true); $k_->refresh = DEBUG ? null : '3!' . $sky->lref; if (is_file($file = "$sky->style/_404.php")) require $file; else echo "<h1>Error 404 - $k_->title</h1>"; # $k_->title = 'Error 404'; # add main/mvc/error_c.php ? } } } |
Codebase entries (89)
SKY. status
Current version: 1.001
Coresky records: 22
Local (DEV) records: 89
Web (all) records: 105
Download: dev.php
Coresky records: 22
Local (DEV) records: 89
Web (all) records: 105
Download: dev.php