Запись [f:main/sky.php] < dev.sky.1.001
Версия 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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | <?php defined('START') or die; # For Licence and Disclaimer of this code, see http://coresky.net/license # Filename: unique # Portname: mysqli_ php module (clear cloud) function trace($var, $show_error = false, $line = 0, $file = '', $context = null) { global $sky; if (!isset($sky)) return; if ($sky->debug || $sky->s_prod_error && true === $show_error) { is_string($var) or $var = var_export($var, true); if (is_string($show_error)) $var = "$show_error: $var" and $show_error = false; if ($has_deep = !$file) { $deep = 1 + $line; $trace = debug_backtrace(); $file = $trace[$line]['file']; $line = $trace[$line]['line']; } $error = "$file:$line:\n" . html($var); if ($show_error) { $sky->was_error = true; if (CLI) echo $has_deep ? "\n$file:$line:\n$var\n\n" : "\n$var\n\n"; if ($sky->s_prod_error) { $sky->error_prod .= NOW . ' - ' . START; if (in_array(START, ['front', 'admin'])) $sky->error_prod .= ' uri: ' . html(URI); $sky->error_prod .= "\n$error\n\n"; } } if ($sky->debug) { if ($show_error) { $sky->tracing .= "$file:$line:\n" . '<div class="error">' . html($var) . "</div>\n"; ob_start(); debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $backtrace = html(ob_get_clean()); if ($sky->error_on_page) { $sky->errors .= sprintf("<h1>%s</h1><pre>$error\n\n$backtrace</pre>", $sky->error_title ? $sky->error_title : 'User Error'); $sky->error_title = ''; if ($str = $sky->context($context, $has_deep ? $deep : 2)) $sky->errors .= "<pre>$str</pre>"; } else { $sky->tracing .= "BACKTRACE:\n$backtrace\n"; if (AJAX) exit; if (!CLI) echo "<br /><b>SKY:</b> " . html($var) . " at <b>$file</b> on line <b>$line</b>"; } $sky->tracing .= "\n"; } else $sky->tracing .= "$error\n\n"; } } } function sql($sql, $deep = 1) { global $sky; if (in_array($mode = $sql[0], ['+', '-', '~', '@', '%', '^', '>'])) $sql = substr($sql, 1); if ($run = '^' != $mode) $result = mysqli_query($sky->idc, $sql); if (($sky->debug || $sky->s_prod_error) && $deep && $run) { $sky->qn++; if ($no = mysqli_errno($sky->idc)) $sky->error_title = 'SQL Error'; trace(($no ? "ERROR in MySQL - $no: " . mysqli_error($sky->idc) . "\n" : '') . "SQL: $sql", (bool)$no, $deep); } switch (strtolower(substr($sql, 0, 6))) { case 'delete': case 'update': case 'replac': return mysqli_affected_rows($sky->idc); case 'insert': return mysqli_insert_id($sky->idc); default: switch ($mode) { case '+': $ary = mysqli_fetch_row($result); return $ary ? $ary[0] : null; case '-': return mysqli_fetch_row($result); case '~': return mysqli_fetch_assoc($result); case '@': return fetch($result, 0); case '%': return fetch($result, 0, 'assoc'); case '^': return sprintf("\$q = sql('%s', %d);", escape($sql, "'\\"), 1 + $deep) . fetch; case '>': return mysqli_fetch_object($result); } } return $result; } function sqlf() { $ary = func_get_args(); $func = 'global $sky; return is_array($v) ? $sky->join("' . strtolower(substr($sql = array_shift($ary), 0, 1)) . '", $v) : $v;'; return sql(vsprintf($sql, array_map(create_function('$v', $func), $ary)), 2); } function sqls($sql, $deep = 1) { global $sky; if ($sky->begin_transaction && $sky->was_error) return false; $result = mysqli_multi_query($sky->idc, $sql); if (($sky->debug || $sky->s_prod_error) && $deep) { $sky->qn++; if ($no = mysqli_errno($sky->idc)) $sky->error_title = 'SQL Error'; trace("SQLs: $sql" . ($no ? ",\nERROR in MySQL - $no: " . mysqli_error($sky->idc) : ''), (bool)$no, $deep); } if ($result) do { if ($result = mysqli_store_result($sky->idc)) mysqli_free_result($result); } while (mysqli_more_results($sky->idc) && mysqli_next_result($sky->idc)); return $result; } function fetch($q, $p = false, $func = 'row') { if (is_bool($p)) return $p ? mysqli_fetch_row($q) : mysqli_fetch_assoc($q); if ('obj' === $p) return mysqli_fetch_object($q); $func = "mysqli_fetch_$func"; for ($cnt = mysqli_num_fields($q), $ary = []; $r = $func($q); ) { $key = current(array_splice($r, $p, 1)); if (1 == $cnt) $ary[] = $key; else $ary[$key] = 2 == $cnt ? current($r) : $r; } mysqli_free_result($q); return $ary; } define('fetch', 'if ($r = mysqli_fetch_assoc($q)) extract($r, EXTR_PREFIX_ALL, "r"); else mysqli_free_result($q); return $r;'); define('row', 'return $row = $sky->row($query);'); function cnt($q, $rows = true) { return $rows ? mysqli_num_rows($q) : mysqli_num_fields($q); } function html($str, $hide_percent = true, $mode = ENT_COMPAT) { $str = htmlspecialchars($str, $mode, ENC); return $hide_percent && 'front' == START ? str_replace('%', '%', $str) : $str; } function unhtml($str, $mode = ENT_QUOTES) { # list($month, $day, $year) = sscanf('Январь 01 2000', "%s %d %d"); return html_entity_decode($str, $mode, ENC); } function escape($in, $char = false) { if (is_array($in)) return array_map(create_function('$v', 'global $idc; return "\'" . mysqli_real_escape_string($idc, $v) . "\'";'), $in); if (is_string($char)) { $dst = array_map(create_function('$v', 'return "\\\\$v";'), $src = str_split($char)); return strtr($in, array_combine($src, $dst)); } global $idc; return $char ? mysqli_real_escape_string($idc, $in) : "'" . mysqli_real_escape_string($idc, $in) . "'"; } function unescape($in, $char = false) { if (is_string($char)) { $src = array_map(create_function('$v', 'return "\\\\$v";'), $dst = str_split($char)); return strtr($in, array_combine($src, $dst)); } $char or $in = substr($in, 1, -1); return strtr($in, ['\0' => "\x00", '\n' => "\n", '\r' => "\r", '\\\\' => "\\", '\\\'' => "'", '\"' => '"', '\Z' => "\x1a"]); } function strand($n = 23) { $str = 'abcdefghjkmnpqrstuvwxyzACDEFGHJKLMNPQRSTUVWXYZ2345679'; # length == 53 if ($n != 7) $str .= 'o0Ol1iIB8'; # skip for passwords (9 chars) for ($ret = '', $i = 0; $i < $n; $i++, $ret .= $str[rand(0, 7 == $n ? 52 : 61)]); return $ret; } function strcut($str, $n = 300) { $text = mb_substr($str, 0, $n, ENC); return mb_strlen($str, ENC) > $n ? mb_substr($text, 0, mb_strrpos($text, ' ', ENC) - mb_strlen($text, ENC), ENC) . ' ...' : $text; } function pad($n = 3) { return str_repeat(' ', $n); } function pad00($str, $n = 2) { return str_pad($str, $n, 0, STR_PAD_LEFT); } function unl($str) { return str_replace(["\r\n", "\r"], "\n", $str); } class SKY { public $mem = []; public $reg = []; public $error_prod = ''; public $errors = ''; public $tracing = ''; public $idc = false; public $qn = 0; public $gpc = 'console, no parameters'; public $result = []; public $i = 0; function __construct() { global $sky, $idc, $PROFILES, $DIR, $me; $this->debug = DEBUG; !isset($sky) or exit('SKY exist'); $this->idc =& $idc; $this->nob = NOB && 'front' == START || CLI; if (CLI) $this->gpc = '$argv = ' . html(var_export($GLOBALS['argv'], true)); srand((double) microtime() * 1000000); define('DIR', $DIR = realpath(__DIR__ . '/..')); defined('WWW') or define('WWW', ''); defined('AJAX') or define('AJAX', 0); define('DATE_DT', 'Y-m-d H:i:s'); define('I_YEAR', 365 * 24 * 3600); @$PROFILES or $PROFILES = ['Anonymous', 'Root', 'Registered']; $me = 'return define("me", "?" . ($me = substr(basename(__FILE__), 1, -23)));'; set_error_handler([$this, 'error']); set_exception_handler([$this, 'exception']); spl_autoload_register([$this, 'autoload']); } function autoload($name) { trace("autoload($name)"); if ('_' == $name[1] && in_array($name[0], ['c', 't', 'm'])) { is_file($file = "main/mvc/$name.php") ? require $file : 't' == $name[0] && eval("class $name extends SKY_MODEL_T {}"); } else { require sprintf('main/class/%s.php', strtolower($name)); } } function &load() { $tmemo = sql("+select tmemo from memory where id=3"); $this->explode('s', $tmemo, 'update memory set dt=now(), tmemo=%s where id=3'); if ($this->debug |= intval($this->s_trace_prod || CLI && $this->s_trace_cli)) error_reporting(E_ALL); if ($this->s_trace_prod) $this->mem['s'][0] = true; if ($this->debug && $this->s__jumped) { $this->tracing .= $this->s__jumped; $this->s__jumped = 0; } date_default_timezone_set($this->s_php_tz); sql("set time_zone = '$this->s_sql_tz'"); define('NOW', date(DATE_DT)); return $this->mem['s'][3]; } function error($no, $error, $file, $line, $context) { #user_error($error, E_USER_WARNING); if (error_reporting() & $no && $this->debug) { $errs = [E_NOTICE => 'Notice', E_WARNING => 'Warning']; $this->error_title = 'PHP ' . ($name = isset($errs[$no]) ? $errs[$no] : "ErrorNo_$no"); trace("$name: $error", true, $line, $file, $context); } return true; } function exception($e) { $this->error_title = 'Exception'; trace('Exception: ' . $e->getMessage(), true, 1); } function context($ary = -1, $deep = 1) { if (-1 === $ary) return function_exists('get_context') ? get_context(1 + $deep) : ''; if (is_null($ary)) return ''; # else array if (function_exists('filter_context')) return filter_context($ary); $out = ''; # $ary as reference! foreach ($ary as $k => $v) if (is_scalar($v) && 's_' != substr($k, 0, 2)) $out .= "\$$k = " . html(var_export($v, 1)) . ";\n"; return substr($out, 0, 1000); } function __get($name) { if ('s_' == substr($name, 0, 2)) return array_key_exists($name = substr($name, 2), $this->mem['s'][3]) ? $this->mem['s'][3][$name] : ''; return isset($this->reg[$name]) ? $this->reg[$name] : ''; } function __set($name, $value) { if ('s_' == substr($name, 0, 2)) { $this->mem['s'][0] = true; $this->mem['s'][3][substr($name, 2)] = $value; } else $this->reg[$name] = $value; } function __call($name, $args) { is_object($this->extend) or trace("Method \$sky->$name not found", true); return call_user_func_array([$this->extend, $name], $args); } function save($k, $v = 0, $char = 's') { isset($this->mem[$char]) or $this->mem[$char] = [true, '', $v, []]; if (is_array($k)) $this->mem[$char][3] = $k + $this->mem[$char][3]; elseif (is_null($v)) unset($this->mem[$char][3][$k]); else $this->mem[$char][3][$k] = $v; return $this->mem[$char][0] = true; } function begin($lock_table = false) { if ($this->was_error || $this->begin_transaction) return false; trace('transaction started', false, 1); if (!$this->debug && !$this->s_prod_error) $this->s_prod_error = $this->debug_begin = true; $this->begin_transaction = mysqli_autocommit($this->idc, false) or trace(mysqli_error($this->idc), true, 1); if (!$this->begin_transaction && $this->debug_begin) $this->s_prod_error = $this->debug_begin = false; if ($this->begin_transaction && ($this->lock_table = $lock_table)) sql("lock tables $lock_table", 2); return $this->begin_transaction; } function end($par = true) { if ($this->debug_begin) $this->s_prod_error = $this->debug_begin = false; if (!$this->begin_transaction) return; ($ok = !$this->was_error && mysqli_commit($this->idc)) ? mysqli_autocommit($this->idc, true) : mysqli_rollback($this->idc); if ($this->lock_table) sql("unlock tables", 2); trace('transaction finished', false, 1); $this->begin_transaction = $this->lock_table = false; return !$ok && is_callable($par) ? $par() : $ok && $par; } function join($x, $ary, $by = ', ') { $keys = array_keys($ary); $vals = array_values($ary); if (in_array($x, ['i', 'r'])) return '(' . implode($by, $keys) . ') values (' . implode($by, $vals) . ')'; if ($x = $x && 'u' != $x && is_string($keys[0])) $by = ' and '; return implode($by, array_map(create_function('$k, $v', 'return is_int($k) ? $v : "$k' . ($x ? '' : ' = ') . '$v";'), $keys, $vals)); } function date($in = 0) { if (is_string($in)) $in = strtotime($in); return date($this->s_date_format ? $this->s_date_format : 'd.m.Y H:i', $in); # :s } function format($in, $func = '') { # 2do return ;#function_exists("for_$func") ? } function result($i = -1, $value = 0) { if (-1 == $i) return $this->i ? $this->result[$this->i - 1] : 0; } function &explode($char, &$orig, $upd = '') { $this->mem[$char] = [false, $orig, $upd, []]; if ($orig) foreach (explode("\n", unl($orig)) as $v) { list($k, $v) = explode(' ', $v, 2); $this->mem[$char][3][$k] = '_' == $k[0] ? unescape($v, true) : $v; } return $this->mem[$char][3]; } function implode($char, $return = false) { $fun = 'global $idc; return "$k " . ("_" == $k[0] ? mysqli_real_escape_string($idc, $v) : $v);'; $new = implode("\n", array_map(create_function('$k,$v', $fun), array_keys($this->mem[$char][3]), array_values($this->mem[$char][3]))); $this->mem[$char][0] = false; if ($return) return $new; $new == $this->mem[$char][1] or mysqli_query($this->idc, sprintf($this->mem[$char][2], escape($new))); } function free($q) { mysqli_free_result($q); } function &row($query) { if ($row = is_array($query) ? (object)$query : mysqli_fetch_object($query)) { if (is_callable($this->callback_row)) call_user_func($this->callback_row, $row); } else { mysqli_free_result($query); $this->callback_row = null; } return $row; } function short($str) { $n = substr_count($str, "\n"); if ($n > 10) { } elseif (strlen($str) > 500) $x = 300; else return $str; $back = '<br>' . a('back', ($href = 'href="javascript:;" onclick=') . '"sky.short()"') . '<br>'; return substr($str, 0, $x) . a('more..', $href . '"sky.short(this)"') . tag($back . substr($str, $x) . $back, 'style="display:none"'); } function tracing($plus = '', $ajax = AJAX) { if (defined('me')) $plus .= sprintf("\nVIEW FILE: %s_%s.php", 'admin' == START ? 'admin/' : '', substr(me, 1)); $plus .= "\nDIR: " . DIR . "\n$this->tracing$this->gpc"; $plus .= sprintf("\n---\n%s: script execution time: %01.3f sec, SQL queries: $this->qn", NOW, microtime(true) - START_TS); $this->traced = true; if ($this->lock_table) mysqli_query($this->idc, "unlock tables"); if ($ajax) mysqli_query($this->idc, sprintf("update memory set tmemo=%s where id=1", escape($plus))); return $plus; } function __toString() { return $this->code; } function __destruct() { # object $sky not exists for GLOBALS since now if ($this->error_prod) { mysqli_query($this->idc, "update memory set tmemo=substr(concat(" . escape($this->error_prod) . ",tmemo),1,5000) where id=4"); } if (!$this->traced && $this->debug) { # if script die if ($this->debug > 2) $this->debug = 2; # cannot call translate() ($sky not exists) $plus = START . " autotrace\n\n"; if (!CLI) $str = $this->tail_x($plus); elseif ($this->was_error || CLI && $this->s_trace_cli) $str = $this->tracing($plus, true); else $str = ''; if (!CLI && !$this->nob) { # $this->error_on_page echo css(['pub/wing.css']) . '<h1>Dying...</h1><pre id="trace">' . "$str</pre>"; while (@ob_end_flush()); } } foreach ($this->mem as $char => &$mem) if ($mem[0] && $mem[2]) { if ('s' == $char) { $this->s_trace_prod = 0; # single click done if (is_array($this->s_amenu)) $this->s_amenu = serialize($this->s_amenu); } $this->implode($char); } mysqli_close($this->idc); } } |
• N1: WRITE FILE: main/debug.php
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 | <?php defined('START') or die; if (DEV && !file_exists($js = WWW . 'pub/' . basename(_JS))) { file_put_contents($sky->s_js = $js, file_get_contents(_JS)) or exit("Cannot save `$js`"); } if (@$s_init_needed) { init_reset(sql("+select tmemo from memory where id=5")); $sky->save('init_needed', null); } function init_reset($code) { if (!DEV) return; foreach (explode("\n", unl($code)) as $line) { if ($line) list($key, $val) = explode(' ', $line, 2); else continue; switch ($key) { case 'htaccess': foreach (explode(' ', $line) as $dir) if ($dir && file_exists($dir) && !file_exists($file = "$dir/.htaccess")) file_put_contents($file, "deny from all\n"); break; case 'index': foreach (explode(' ', $line) as $dir) if ($dir && file_exists($dir) && !file_exists($file = "$dir/index.htm")) file_put_contents($file, "<html><body>Forbidden folder</body></html>\n"); break; case 'php': $php = 0; if (is_numeric($val)) { $php = sql("+select tmemo from memory where id=$val union select '' as tmemo"); sql("delete from memory where id=$val"); } elseif (is_file($val)) $php = '?>' . file_get_contents($val); if ($php) eval($php); break; } } } function check_other() { $u = array_keys(fetch(sql("explain users"), 0)); $v = array_keys(fetch(sql("explain visitors"), 0)); $c = array_intersect($u, $v); if (count($c) == 1 && 'id' == current($c)) return ''; return "<h1>Other Errors</h1><pre>users vs visitors columns:\n\n" . print_r($c, true) . '</pre>'; # html() } # function get_context() {} - 2do # function filter_context() {} - 2do function dummy_txt($chars = 0) { $s = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua'; $ary = explode(' ', $s); for ($j = 0, $str = '', $cnt = rand(2, 10); $chars ? true : $j < $cnt; $j++) { $str .= $chars ? $ary[rand(0, count($ary) - 1)] . ' ' : "<p>$s</p>"; if ($chars && strlen($str) > $chars) return substr($str, 0, $chars); } return $str; } function dummy_gen($table, $size = null) { $ary = []; $txt = 0; foreach (sql("@explain $table") as $c => $r) { $ary[$c] = "return "; if ('auto_increment' == $r[4]) $ary[$c] .= "'null';"; elseif (preg_match("/^[a-z]*text$/i", $r[0])) $ary[$c] .= 'escape(dummy_txt());' and $txt = 1; elseif ('datetime' == $r[0]) $ary[$c] .= 'escape(date(DATE_DT, time() - rand(0, 3600 * 24 * 7)));'; elseif (preg_match("/varchar\((\d+)\)/", $r[0], $m)) $ary[$c] .= "escape(dummy_txt($m[1] > 15 ? rand(9, $m[1] - 5) : $m[1]));"; elseif ('YES' == $r[1]) $ary[$c] .= "'null';"; elseif (!is_null($r[3])) $ary[$c] .= "\"'$r[3]';\""; else $ary[$c] .= "rand(0, 9);"; } if (is_null($size)) $size = $txt ? 300 : 5; for ($i = 0; $i < $size; $i++) { $ins = $ary; foreach ($ins as &$v) $v = eval($v); sqlf("insert into $table %s", $ins); } } |
• N2: SQL:
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 | CREATE TABLE `memory` (
`id` int(11) unsigned NOT NULL auto_increment,
`name` varchar(100) NOT NULL,
`code` varchar(100) default NULL,
`imemo` int(11) NOT NULL default '0',
`cmemo` varchar(255) default NULL,
`tmemo` mediumtext,
`dt` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
insert into memory (name, tmemo) values('ajax', '');
insert into memory (name, tmemo) values('cron', '');
insert into memory (name, tmemo) values('conf', '');
insert into memory (name, tmemo) values('error', '');
insert into memory (name, tmemo) values('init', '');
insert into memory (name, tmemo) values('reset', '');
insert into memory (name, tmemo) values('backup', '');
|
• N3: UPDATE CELL: memory.3.tmemo
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 | php_tz Europe/Kiev
sql_tz +2:00
trace_root 1
trace_cli 1
prod_error 1
c_manda 0
j_manda 0
c_name sky
c_upd 60
visit 5
clear interval 29 day
scheme_2 100
reg_req 0
cache_act 1
cache_sec 300
trace_prod 0
cache_fast 0
title The SKY. null site
keywords sky, coresky, crystallization, ideal code, sky net
desc The name of this project is "SKY."
email
cron_dt
online 0
guard_exc pub/ckeditor pub/tinymce lib
init_needed 1
allow_submenu 11111111111
crypt 0
last_update 2016-09-09 20:01:37
tables_name
tables_struct
amenu
_jumped 0
sky 1.000 22 89 104
js
|
• N4: END:
Записи Codebase (89)
Статус SKY.
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