Запись [f:main/wing.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 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | <?php defined('START') or die; # For Licence and Disclaimer of this code, see http://coresky.net/license # This file designed for 'front' and 'admin' enter points, but not for 'cron' # Filename: unique /* $user->id $user->vid $user->pid $user->gid $user->auth * */ class SKY_USER { public $row = []; public $root = 0; public $js = ''; protected $cookie; protected $pretty; function __get($name) { if ('_' == $name[1] && in_array($char = $name[0], ['v', 'u'])) return (string)@$GLOBALS['sky']->mem[$char][3][substr($name, 2)]; return array_key_exists($name, $this->row) ? $this->row[$name] : ''; } function __set($name, $value) { if ('_' == $name[1] && in_array($char = $name[0], ['v', 'u'])) $GLOBALS['sky']->save(substr($name, 2), $value, $char); $this->row[$name] = $value; } function __construct() { global $sky, $IP, $UA, $PVAL; $hash = md5($IP . $UA . @$_SERVER['HTTP_X_FORWARDED_FOR']); $pretty = preg_match("/^\w{23}$/", $this->cookie = (string) @$GLOBALS["c_$sky->s_c_name"]); $upd_visitors = "update visitors set vmemo=%s where id="; if ($this->row = sqlf("~select %s from visitors v left join users u on (u.id = abs(v.uid)) where%s hash='$hash' and v.ip='$IP'", [ 'v.*', 'u.*', 'v.id as vid', 'ifnull(u.id, 0) as user_id', "now() - interval $sky->s_visit minute > v.dt_l as visit", 'now() <= v.dt_l + interval 1 second as flood', 'now() > v.dt_l + interval 1 hour as banend', ], $pretty ? " sky='$this->cookie' or " : '')) { $this->pretty = $pretty = $this->cookie === $this->row['sky']; $fs = $this->flags; if ($ban = $fs[0]) { $this->banend or die; # hard ban by visitor row $fs[0] = $ban = 0; } if ($this->row['id'] = $pretty ? $this->user_id : 0) $this->row['auth'] = $this->uid > 0 ? 1 : 2; $this->row['pid'] = intval($this->row['pid']); if (1 == $this->pid) { $this->root = 1; if ($sky->s_trace_root && 2 == $this->auth) $sky->debug = $this->root = 2; } $ary = [ 'dt_l' => 'now()', 'uri' => escape(URI), 'clk_total' => 'clk_total+1', 'clk_visit' => $this->visit ? 1 : 'clk_visit+1', ]; if ($sky->eref) $ary += ['ref' => escape($sky->eref)]; if ($IP != $this->ip) $ary += ['ip' => "'$IP'"]; if ($pretty && $this->hash) $ary += ['hash' => 'null']; if ($this->visit) $ary += ['dt_v' => 'now()', 'cnt_visit' => 'cnt_visit+1', 'sky' => $this->cookize()]; if (!$pretty) { $this->cookize($this->sky); $this->cookie_off = true; } if ($_POST || $this->banend) { if ($this->flood && $this->clk_flood > 28) $ban = $fs[0] = 1; # set hard ban when > 29 flood clicks $ary += ['clk_flood' => $this->flood ? 'clk_flood+1' : 0]; } $this->row['v'] = $sky->explode('v', $this->row['vmemo'], $upd_visitors . $this->vid); if ($this->v_jumped_from) { $this->jumped_from = $this->v_jumped_from; $this->v_jumped_from = ''; } if ($fs[7] && !$this->jumped_from) { $fs[5] = (int)!$pretty; $fs[6] = (int)!(AJAX && '_ini__' == PAGE && '_' == $PVAL); $fs[7] = 0; } $fs[2] = (int)!$_COOKIE; $fs[3] = (int)!$pretty; $fs[4] = (int)($UA != $this->v_ua); $ary += ['flags' => "'$fs'"]; sqlf("update visitors set %s where id=$this->vid", $ary); $ban && die; # hard ban by visitor row $this->row['u'] = $this->id ? $sky->explode('u', $this->row['umemo'], "update users set umemo=%s where id=$this->id") : []; $this->ky_c = $fs[5] && $sky->s_c_manda; $this->ky_j = $fs[6] && $sky->s_j_manda; $this->ky_error = $this->ky_c || $this->ky_j; } else { # $sky->s_c_manda $this->vid = sqlf("insert into visitors %s", [ 'sky' => $this->cookize(), 'hash' => "'$hash'", 'ip' => "'$IP'", 'dt_0' => 'now()', 'dt_l' => 'now()', 'dt_v' => 'now()', 'vmemo' => escape($v = $this->vmemo()), 'ref' => escape($sky->eref), 'uri' => escape(URI), # 2 3 4 5 6 7 # ban is_bot no-any-cookie no-pretty ua-changed no-sky-cookie no-javascript not-tested 'flags' => sprintf("'0%d%d%d---1'", IS_BOT, !$_COOKIE, !$pretty), ]); $this->row = [ 'v' => $sky->explode('v', $v, $upd_visitors . $this->vid), 'vid' => $this->vid, 'user_id' => 0, 'id' => 0, 'pid' => 0, ]; $this->js = "sky.load_c = '_ini__';"; } if (DEBUG > 2) trace($this->row, '$user->row'); } private function cookize($value = false, $session = false) { global $sky; if (!$value) for ($i = 0; sqlf("+select count(1) from visitors where sky='%s'", $value = strand()); $i++ < 90 or exit); $t2s = $session ? 0 : ceil(START_TS + I_YEAR); $srv = false === strpos(SNAME, '.') ? '' : (SNAME == DOMAIN ? SNAME : '.' . DOMAIN); setcookie($sky->s_c_name, $this->cookie = $value, $t2s, PATH, $srv, 'https' == PROTO) or exit('cookie'); return "'$value'"; } private function vmemo() { global $UA, $sky; return "ua $UA\nlg_0 $sky->lg_browser\nlg $sky->lg_browser"; } function passwd($str, $salt = 0) { $salt or $salt = '$1$' . strand(8) . '$'; return crypt($str, $salt); } function register($data, $uid = 0) { global $sky, $s_crypt; if (!$uid && is_array($data)) { # step 1 $or = ''; if (isset($data['login'])) { if (!preg_match(RE_LOGIN, $data['login'] = strtolower($data['login']))) return 4; if (in_array($data['login'], m_ary::reserved_names())) return 2; $or = " or login='$data[login]'"; } if (!preg_match(RE_PASSW, $data['passw']) || !preg_match(RE_EMAIL, $data['email'])) return 4; if (sql("+select count(1) from users where email='$data[email]'$or")) return 3; $data['access'] = strand(30); if ($s_crypt) $data['passw'] = $this->passwd($data['passw']); return $data + ['id' => sqlf("insert into users %s", escape($data))]; } elseif (is_numeric($uid) && $uid > 0 && preg_match("/^[\d\w]{23}$/i", $data)) { # step 2 (e-mail confirmation) return sql("update users set state='act' where id=$uid and access='$data'"); } return 0; } function login($to = false) { global $sky, $p_login, $p_password, $p_mem; $this->auth or sleep(1); !$this->id or 'admin' == START and 1 == $this->auth or die; if (preg_match(RE_LOGIN, $p_login = strtolower(@$p_login))) $src = "login='$p_login'"; else $src = preg_match(RE_EMAIL, $p_login) ? "email='$p_login'" : 0; $src && preg_match(RE_PASSW, @$p_password) && $this->pretty or die; $r = sql("~select * from users where $src and state='act'"); if ($sky->s_crypt ? $r['passw'] == $this->passwd($p_password, $r['passw']) : $r['passw'] == $p_password) { $this->row = $r + $this->row; $this->row['auth'] = $this->auth ? 2 : 1; sqlf("update visitors set uid=%d, dt_l=now() where id=$this->vid", 2 == $this->auth ? -$this->id : $this->id); sql("update users set dt_u=now() where id=$this->id"); isset($p_mem) or 'admin' == START or $this->cookize($this->cookie, true); } if ($this->id && !AJAX) jump($to); return $this->id; } function logout($to = false, $update_user = []) { global $sky; if ($this->auth) { sqlf("update users set %s where id=$this->id", $update_user + ['dt_u' => 'now()']); sqlf("update visitors set uid=%d where id=$this->vid", $sky->error_on_page || is_null($to) ? 0 : $this->id); } is_null($to) or jump(false === $to && $sky->lref ? $sky->lref : $to); } function deny() { $args = func_get_args(); return !call_user_func_array(['SKY_USER', 'allow'], $args); } function allow() { if (1 == $this->pid) return true; # superuser can full access $args = func_get_args() or $args = [[]]; return in_array($this->pid, is_array($args[0]) ? $args[0] : $args); } } class SKY_WING extends SKY { const PROC = ' $sky = new SKY_WING; $s_cnt = extract($sky->load(), EXTR_PREFIX_ALL | EXTR_REFS, "s") or exit("err mem"); if ($sky->debug) require "main/debug.php"; if ("admin" == START) { $file = sprintf("admin/%s.php", AJAX ? "_$PAGE" : "index"); if (is_file($file) && $user->adm_allowed) { require $file; exit; } $PAGE = "adm"; $sky->error_on_page = true; }'; protected $err = []; protected $ai_name = ''; public $user = 0; function &load() { global $SNAME, $LINK, $URI, $IP, $UA, $PAGE, $PVAL, $WHAT, $WVAL, $user, $adm, $lgt, $k_; $IP = @$_SERVER['REMOTE_ADDR']; $this->reg['post'] = @$GLOBALS['HTTP_RAW_POST_DATA']; $this->content_type = 'Content-Type: text/html; charset=' . ENC; $this->error_on_page = 'front' == START; $this->nob or ob_start(); $mem =& parent::load(); $this->lg_browser = preg_match("/^ru/i", @$_SERVER['HTTP_ACCEPT_LANGUAGE']) ? 'ru' : 'en'; define('PROTO', @$_SERVER['HTTPS'] ? 'https' : 'http'); define('SNAME', $SNAME = $_SERVER['SERVER_NAME']); $no_lg = '.' != $SNAME[2]; define('DOMAIN', SNAME); define('PATH', preg_replace("|^(.*/)[^/]*$|", "$1", $_SERVER['SCRIPT_NAME'])); define('URI', $URI = preg_replace("|^[\w/]*/|", '', @$_SERVER['REQUEST_URI'])); define('span_r', '<span style="color:red">%s</span>'); define('span_g', '<span style="color:green">%s</span>'); define('span_b', '<span style="color:blue">%s</span>'); define('RE_LOGIN', '/^[a-z][a-z_\d]{1,29}$/'); define('RE_PASSW', '/^\S{5,15}$/'); define('RE_EMAIL', '/^([\w\-]+\.)*[\w\-]+@([\w\-]+\.)+[a-z]{2,7}$/i'); define('RE_PHONE', '/^\+?\d{10,12}$/'); define('TPL_FORM', '<dl><dt>%s</dt><dd>%s</dd></dl>'); define('TPL_CHECKBOX', '<input type="checkbox" name="id[]" value="%s"%s />'); define('TPL_HIDDEN', '<input type="hidden" name="%s" value="%s" />'); define('TPL_META', '<meta name="%s" content="%s" />'); define('MAGIC', (int)get_magic_quotes_gpc()); $UA = preg_replace("|[\r\n\t]+|", ' ', @$_SERVER['HTTP_USER_AGENT']); define('IS_BOT', (int)!preg_match("#firefox/|msie \d|opera/|safari/|chrome/#i", $UA)); $referer = @$_SERVER['HTTP_REFERER']; $re = '~^' . PROTO . '://([a-z]{2}\.)?' . DOMAIN . PATH . '(.*)$~'; $this->lref = preg_match($re, $referer, $m) ? ($m[1] ? (substr(SNAME, 0, 3) == $m[1] && $m[2] ? $m[2] : $referer) : false) : false; $this->eref = $m ? false : $referer; for (; list($k, $v) = each($_POST); $GLOBALS["p_$k"] = is_array($v) ? $v : addslashes($_POST[$k] = MAGIC ? stripslashes($v) : $v)); # str_replace('%', '%', for (; list($k, $v) = each($_COOKIE); $GLOBALS["c_$k"] = addslashes($v)) if (MAGIC) $_COOKIE[$k] = $v = stripslashes($v); foreach ($_FILES as $k => $v) $GLOBALS["f_$k"] = $v; foreach ($_GET as $k => $v) $_GET[$k] = $GLOBALS["g_$k"] = MAGIC && !is_array($v) ? stripslashes($v) : $v; reset($_GET); define('PAGE', $PAGE = $_GET ? key($_GET) : 'main'); $PVAL = $_GET ? $_GET[$PAGE] : ''; if (is_string($WVAL = next($_GET))) $WHAT = key($_GET); else $WHAT = $WVAL = ''; reset($_GET); reset($_POST); reset($_FILES); reset($_COOKIE); $this->user = $user = new SKY_USER; define('LINK', $LINK = PROTO . "://" . DOMAIN . PATH); if ($this->debug) { $this->gpc = "\$_GET: " . html(var_export($_GET, true)) . "\n"; $this->gpc .= "\$_POST: " . html(var_export($_POST, true)) . "\n"; $this->gpc .= "\$_FILES: " . html(var_export($_FILES, true)) . "\n"; $this->gpc .= "\$_COOKIE: " . html(var_export($_COOKIE, true)) . "\n"; } if ('index.php?AJAX=ajax' == URI && (DEBUG || $user->root)) { $this->debug = false; echo sql("+select tmemo from memory where id=1"); # show X-trace } if ('admin' == START && !$this->s_amenu) { $files = array_map(create_function('$v', 'return substr(basename($v), 1, -4);'), glob('admin/_*.php')); $files = array_merge(array_splice($files, array_search('main', $files), 1), $files); $buttons = implode("\t", array_map(create_function('$v', 'return ucfirst($v);'), $files)); $root_access = ceil(count($files) / 7) . "\t" . implode("\t", array_keys($files)); $this->s_amenu = [-2 => $uris = implode("\t", $files), -1 => $buttons, $uris, $root_access]; jump('?main=3'); } $k_ = (object)[ 'midlab' => 1, 'tkd' => [$this->s_title, $this->s_keywords, $this->s_description], 'js' => $user->js, 'type' => in_array($PVAL, ['list', 'edit', 'new']) ? $PVAL : ($PVAL && 'p' != $PVAL ? 'show' : 'list'), ]; if ($user->pid) { $this->s_amenu = unserialize($this->s_amenu); $ary = explode("\t", @$this->s_amenu[$user->pid]); $adm = (object)[ 'files' => explode("\t", $this->s_amenu[-2]), 'names' => explode("\t", $this->s_amenu[-1]), 'uris' => explode("\t", $this->s_amenu[0]), 'rows' => $ary ? array_shift($ary) : 0, 'cr' => $ary, ]; $user->adm_allowed = $adm->rows && $adm->cr; } return $mem; } function head($plus = '') { global $k_, $v_h1; if (!$this->error_on_page) { # admin section $k_->title = '%TITLE%'; $k_->head = '%HEAD%'; } if (!isset($k_->title) && isset($v_h1)) $k_->title = $v_h1; $k_->title = html(isset($k_->title) ? "$k_->title - {$k_->tkd[0]}" : $k_->tkd[0]); isset($k_->metak) or $k_->metak = $k_->tkd[1]; isset($k_->metad) or $k_->metad = $k_->tkd[2]; isset($k_->head) or $k_->head = ''; if (@$k_->refresh) { list($secs, $link) = explode('!', $k_->refresh); $k_->head .= sprintf('<meta http-equiv="refresh" content="%d%s">', $secs, $link ? ";url=$link" : ''); } $plus .= "<title>$k_->title" . '</title><meta http-equiv="content-type" content="text/html; charset=utf-8" />'; $plus .= js([$this->s_js ? $this->s_js : _JS, 'pub/wing.js']); if ($k_->js) $plus .= js($k_->js); if (!$this->error_on_page) $plus .= js(['pub/admin.js']) . css(['pub/admin.css']); else $plus .= 'mobile' == $this->layout ? js(['pub/mobile.js']) . css(['pub/mobile.css']) : js(['pub/front.js']) . css(['pub/front.css']); $plus .= tag(['keywords' => html($k_->metak), 'description' => html($k_->metad)]); if (is_dir('_dev') && $this->error_on_page) $plus .= js(['_dev/util/visual.js']) . css(['_dev/util/visual.css']); echo $plus . '<link href="pub/favicon.ico" rel="shortcut icon" type="image/x-icon" />' . $k_->head; } function tail($link = true, $plus = '', $err = '') { global $front; if ($this->error_on_page && !$this->nob) $front->label(); if ($this->debug) { trace(array_keys($this->mem), 'KEYS of: $this->mem'); if (4 == $this->debug && !AJAX) $plus .= "\n\n---\nLAST AJAX:\n" . sql("+select tmemo from memory where id=1", false) . "\n\n"; if (!DEV && $this->s_trace_prod) $this->tracing($plus, true); else { if ($this->errors) { $err = check_other() . "$this->errors<h1>Tracing</h1>" . tag($this->tracing($plus), 'id="trace"', 'pre'); } else { if ($link && DEV) echo a('see tracing', "javascript:$('#trace').toggle();scrollBy(0,700)"); if ($this->was_error) echo check_other() . tag($this->tracing($plus), 'id="trace"', 'pre') . js("$('span.error')[0].scrollIntoView();"); else echo tag($this->tracing($plus), 'style="display:none" id="trace"', 'pre'); } } } if ($this->error_on_page && $err) echo "<div id=\"err-bottom\">$err</div>"; else while (@ob_end_flush()); } function tail_x($plus = '') { $buffered = ob_get_level(); # can be hidden when download if (AJAX) {} $stdout = $buffered ? ob_get_clean() : ''; if ($plus && !CLI) $this->errors .= "<h1>Dying...!</h1>"; if (DEV && AJAX && $this->errors && $buffered) { if (!$plus) $this->errors = check_other() . $this->errors; $this->content_type = 'Content-Type: application/json; charset=' . ENC; $stdout = json_encode(['catch_error' => "$this->errors<h1>Stdout</h1>" . html($stdout)]); } if ($buffered) { header($this->content_type); echo $stdout; if ($this->debug && !$plus && strlen($stdout) < 100) trace($stdout, 'STDOUT'); } return $this->debug ? $this->tracing($plus, true) : ''; } function tracing($plus = '', $ajax = AJAX) { global $front; if ($this->debug) $this->tracing = 'AJAX: ' . html((int)AJAX . "\nURI: " . URI . "\n\$sky->lref: $this->lref") . "\n\n" . $this->tracing; if ($this->debug > 1) { #'DIR: ' . getcwd() . "\nAJAX: " if (3 == $this->debug && $this->error_on_page && $this->trans_coll) $front->translate($this->trans_coll); flush(); $plus .= 'Request headers:' . html(substr(print_r(getallheaders(), true), 7, -2)); $plus .= 'Response headers:' . html(substr(print_r(apache_response_headers(), true), 7, -2)); # headers_list() } return parent::tracing($plus, $ajax); } function insert($table, $set = [], $save_struct = true) { $ary = $this->values($table, $set, $save_struct); if ($this->err) return false; return sqlf("insert into $table (`%s`) values (%s)", implode("`\n,`", array_keys($ary)), implode("\n,", $ary)); } function update($table, $id, $set = [], $save_struct = true) { $ary = $this->values($table, $set, $save_struct); if ($this->err) return false; array_walk($ary, create_function('&$v, $k', '$v = "`$k` = $v";')); return sqlf("update $table set\n%s where %s", implode(",\n", $ary), is_numeric($id) ? "$this->ai_name=$id" : $id); } function replace($table, $id = 0, $set = [], $save_struct = true) { return $id ? $this->update($table, $id, $set, $save_struct) : $this->insert($table, $set, $save_struct); } function get_errors($by = '<br>') { return implode($by, $this->err); } function get_table($table, $save_struct = false, $force = false) { $pos = $force ? false : array_search($table, explode(' ', $this->s_tables_name)); if (false !== $pos) { $struct = explode("\t", $this->s_tables_struct); return explode(' ', $struct[$pos]); } $q = sql("explain $table"); if (mysqli_errno($this->idc)) return; for ($struct = []; $r = fetch($q, true); ) $struct[] = $r[0] . ('datetime' == $r[1] ? '.N' : ('auto_increment' == $r[5] ? '.A' : '')); if ($save_struct) { $this->s_tables_name = trim("$this->s_tables_name $table"); # 2do: force $this->s_tables_struct = trim("$this->s_tables_struct\t" . implode(' ', $struct)); } return $struct; } function set_tables($ary = false) { if (true === $ary) $ary = array_filter(fetch(sql('show tables'), 0), create_function('$v', 'return !DEV || "_dev_" != substr($v, 0, 5);')); elseif (false === $ary) $ary = []; for ($struct = []; list( , $one) = each($ary); ) $struct[] = implode(' ', $this->get_table($one, false, true)); $this->s_tables_name = implode(' ', $ary); $this->s_tables_struct = implode("\t", $struct); } protected function values($table, $set, $save_struct) { $ary = []; $in_set = $set; if (true === $set) $set = []; foreach ($this->get_table($table, $save_struct) as $col) { in_array($x = substr($col, -2), ['.A', '.N']) and $col = substr($col, 0, -2); '.A' == $x and $this->ai_name = $col; $vall = true === $in_set && isset($_POST[$col]); if ('.N' == $x && !$vall) { if (!isset($set[$col])) $ary[$col] = 'now()'; # datetime column, set to now() as default elseif (false === $set[$col]) continue; # dont touch datetime column if set to false } if ($vall || isset($set[$col]) && is_array($set[$col])) { # validation if ($vall) $set[$col] = [".+", ucfirst($col) . ' can\'t be empty']; $val = isset($set[$col][2]) ? $set[$col][2] : trim($_POST[$col]); $rule = $set[$col][0]; $err = false; if (!$set[$col][1]) { $err = call_user_func($rule, $val); } elseif (is_array($val)) { foreach($val as $c) preg_match("~$rule~", $c) or $err = $set[$col][1]; } else preg_match("~$rule~", $val) or $err = $set[$col][1]; if (false === $err) $ary[$col] = sprintf("'%s'", isset($set[$col][2]) ? $set[$col][2] : $GLOBALS["p_$col"]); else $this->err[$col] = $err; } elseif (isset($set[$col])) $ary[$col] = $set[$col]; elseif (isset($_POST[$col])) $ary[$col] = "'" . $GLOBALS["p_$col"] . "'"; } return $ary; } } function val($re, $in = false) { is_array($in) or $in = false === $in ? $_POST : [$in]; is_array($re) or $re = [$re]; foreach ($re as $name => $one) { if (is_int($name)) { if (!is_numeric(@$in[$one])) return false; } elseif (!preg_match($one, @$in[$name])) return false; } return true; } function menu($act, $ary, $tpl = '', $by = '</li><li>', $class = 'menu') { if (!$tpl) { $tpl = defined('TPL_MENU') ? TPL_MENU : '?%s'; $by = ' '; } array_walk($ary, create_function('&$v, $k, $tpl', "\$v = sprintf('<a href=\"' . \$tpl . '\">%s</a>', \$k, \$v);"), $tpl); if (isset($ary[$act])) $ary[$act] = '<a class="active"' . substr($ary[$act], 2); return '</li><li>' == $by ? sprintf('<ul class="%s"><li>%s</li></ul>', $class, implode($by, $ary)) : implode($by, $ary); } function jump($uri = '', $code = 0) { # $uri : '' - self::(refresh), true - self::main, false - front::main if ('' === $uri) $uri = URI; elseif (!is_string($uri)) $uri = $uri && 'admin' == START ? 'adm' : ''; elseif ('?' == $uri[0] && 'admin' == START) $uri = "adm$uri"; global $sky; $to = preg_match("@^https?://@i", $uri) ? $uri : LINK . $uri; header("Location: $to", true, $code ? $code : null); # if (!headers_sent($file, $line)) {} if (DEBUG) $sky->s__jumped = sprintf("<pre class=\"jump\">JUMP {\n%s\n\n} JUMP TO $to</pre>\n\n", $sky->tracing()); if ($sky->user) $sky->user->v_jumped_from = URI ? URI : 'main'; exit; } function pagination($cnt, $ipp = 15, $ipl = 5) { $html = $k0 = $k1 = $prev = $next = ''; $pc = 0; $x = strpos(URI, '?') ? '&' : '?'; $uri = URI; $uri = preg_match("/p=(\d+)/", $uri, $m) ? preg_replace("/(p=)(\d+)/", "$1\$i", $uri) : "$uri{$x}p=\$i"; $current = $m ? $m[1] - 1 : 0; $code = 'return "' . $uri . '";'; if ($cnt > $ipp) { $pc = floor($cnt / $ipp) + ($cnt % $ipp ? 1 : 0); if ($pc > $ipl) { $spage = $current - floor($ipl / 2) + 1; $epage = $current + floor($ipl / 2) + 1; if ($spage < 1) { $spage = 1; $epage = $ipl; } elseif($epage > $pc) { $spage = $pc - $ipl + 1; $epage = $pc; } } else { $spage = 1; $epage = $pc; } $k0 = $epage - $spage + 1 == $ipl; $k1 = $epage > $spage; $i = $current ? $current : 1; $prev = $k1 ? eval($code) : ''; $i = $current + 1 == $pc ? $pc : $current + 2; $next = $k1 ? eval($code) : ''; $i = 1; global $sky; $x = explode('~', $sky->pagination ? $sky->pagination : 'pagination~active~First~Prev~Next~Last'); if ($k1) $html .= sprintf('<ul class="%s">', $x[0]); if ($k0) $html .= sprintf('<li><a href="%s">%s</a></li><li><a class="btn-prev" href="%s">%s</a></li>', eval($code), $x[2], $prev, $x[3]); for ($i = $spage; $i <= $epage; $i++) $html .= sprintf( '<li%s><a href="%s">%d</a></li>', $i == $current + 1 ? sprintf(' class="%s"', $x[1]) : '', eval($code), $i ); $i = $pc; if ($k0) $html .= sprintf('<li><a class="btn-next" href="%s">%s</a></li><li><a href="%s">%s</a></li>', $next, $x[4], eval($code), $x[5]); if ($k1) $html .= '</ul>'; } return [$html, $current * $ipp, $current + 1, $pc, $prev, $next]; } function option($selected, $table, $order = 'id') { if (is_string($table)) { if (strchr($table, ' ')) $q = sql($table); else { $where = strlen($order) == 1 ? " where left(name,1)='$order'" : ''; if ($where) $order = 'name'; $q = sql("select * from $table$where order by $order"); } $table = []; while ($r = mysqli_fetch_row($q)) $table[$r[0]] = $r[1]; } for ($out = ''; list($k, $v) = each($table); $out .= tag($v, sprintf('value="%s"%s', $k, (string)$selected == $k ? ' selected' : ''), 'option')); return $out; } function radio($name, $checked, $ary, $by = ' ') { $tpl = '<label><input type="radio" name="%s" value="%s"%s /> %s</label>%s'; for ($out = ''; list($k, $v) = each($ary); $out .= sprintf($tpl, $name, $k, (string)$checked == $k ? ' checked' : '', $v, $by)); return $out; } function a($a, $href = '', $x = '') { $href or $href = "http://$a/"; return sprintf('<a href="%s"%s>%s</a>', $href, $x ? ' ' . trim($x) : '', $a); } function js($x = '', $p2 = true) { if (is_string($x)) return '<script type="text/javascript">' . $x . ($x && $p2 ? '</script>' : ''); for ($js = ''; list(, $src) = each($x); $js .= sprintf('<script type="text/javascript" src="%s"></script>', $src)); return $js; } function css($x = '', $p2 = 'screen') { if (is_string($x)) return '<style type="text/css">' . $x . ($x && $p2 ? '</style>' : ''); for ($css = ''; list(, $src) = each($x); $css .= sprintf('<link type="text/css" href="%s" media="%s" rel="stylesheet" />', $src, $p2)); return $css; } function tag($in, $x = 'class="fr"', $tag = 'div') { if (is_scalar($in)) return "<$tag" . ($x ? ' ' : '') . trim($x) . ">$in</$tag>"; for ($tag = ''; list($k, $v) = each($in); $tag .= sprintf(TPL_META, $k, $v)); return $tag; } function th($ary, $x = '') { for ($tr = $x ? "<table $x><tr>\n" : '<tr>'; list($k, $v) = each($ary);) $tr .= is_int($k) ? "<th>$v</th>\n" : "<th $v>$k</th>\n"; return "\n$tr</tr>\n"; } function td($ary, $x = '') { for ($tr = $x ? "<tr $x>\n" : "<tr>\n"; list(, $v) = each($ary);) $tr .= is_array($v) ? "<td $v[1]>$v[0]</td>\n" : "<td>$v</td>\n"; return "\n$tr</tr>\n"; } function hidden($set = "id", $r = 0) { is_array($set) or $set = [$set => $r]; for ($out = ''; list($name, $val) = each($set); ) { is_string($name) or $name = $val and $val = isset($r[$name]) ? $r[$name] : ''; $out .= sprintf(TPL_HIDDEN, $name, html($val)); } return $out; } function form($r, $set, $x = '', $form = true) { $html = $form ? '<form method="post" enctype="multipart/form-data">' : ''; if ($_POST) $r = $_POST + $r; foreach ($set as $name => $ary) { $nn = is_int($name); if (!is_array($ary)) { if ($nn) { $html .= $ary; continue; } else $ary = ['hidden', $ary]; } switch ($ary[0]) { case 'hidden': $html .= sprintf('<input type="hidden" name="%s" value="%s" />', $name, html(isset($r[$name]) ? $r[$name] : @$ary[1]) ); break; case 'textarea': $html .= sprintf('<p>%s<textarea name="%s"%s>%s</textarea></p>', $ary[1], $name, isset($ary[2]) ? ' ' . trim($ary[2]) : '', html(@$r[$name]) ); break; case 'radio': $s = ''; foreach ($ary[2] as $v => $desc) $s .= sprintf('<label><input type="radio" name="%s" value="%s"%s /> %s</label> ', $name, $v, ($v == (isset($r[$name]) ? $r[$name] : @$ary[3]) ? ' checked' : '') . (@$ary[4] ? " $ary[4]" : ''), $desc ); $html .= sprintf(TPL_FORM, $ary[1], $s); break; case 'checkbox': $html .= sprintf(tag(TPL_FORM, '', 'label'), tag(sprintf('<input type="checkbox" name="%s" value="%s"%s /> ', $name, isset($ary[4]) ? $ary[4] : 1, ((isset($r[$name]) ? $r[$name] : @$ary[3]) ? ' checked' : '') . (@$ary[2] ? ' ' . trim($ary[2]) : '') )), $ary[1]); break; case 'select': $html .= sprintf(tag(TPL_FORM, '', 'label'), $ary[1], sprintf('<select name="%s"%s>%s</select>', $name, isset($ary[3]) ? ' ' . trim($ary[3]) : '', option(@$r[$name], $ary[2]) )); break; default: # text password file button submit reset image + HTML5 inputs if (is_int($name)) { $s = '' or is_array($ary[0]) or $ary = [$ary]; foreach ($ary as $one) $s .= sprintf('<input type="%s" value="%s"%s /> ', $one[0], html($one[1]), @$one[2] ? ' ' . trim($one[2]) : ''); $html .= sprintf(TPL_FORM, ' ', $s); } else { $html .= sprintf(tag(TPL_FORM, '', 'label'), $ary[1], sprintf( '<input type="%s" name="%s" value="%s"%s /> ', $ary[0] ? $ary[0] : 'text', $name, html(isset($r[$name]) ? $r[$name] : @$ary[3]), @$ary[2] ? ' ' . trim($ary[2]) : '' )); } break; } } return $form ? "$html</form>" : $html; } |
en | WARNING! This table used by util/v_database.php:9 ********************************************************************* |
•
N1:
SQL:
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 | CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`login` varchar(50) DEFAULT NULL,
`passw` varchar(50) NOT NULL,
`email` varchar(100) NOT NULL,
`pid` int(1) NOT NULL DEFAULT '0',
`state` enum('ini','act','del','blk') NOT NULL DEFAULT 'ini',
`uname` varchar(100) DEFAULT NULL,
`phone` varchar(12) DEFAULT NULL,
`pack_sent` int(11) unsigned DEFAULT '0',
`access` char(30) DEFAULT NULL,
`ava` varchar(100) DEFAULT NULL,
`dt_r` datetime DEFAULT NULL,
`dt_u` datetime DEFAULT NULL,
`umemo` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
insert into users (login, passw, email, pid, state) values('root', 'xroot', 'your@gmail.com', 1, 'act');
CREATE TABLE `visitors` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`uid` int(11) DEFAULT NULL,
`flags` char(8) NOT NULL DEFAULT '0000---1',
`ip` varchar(50) NOT NULL,
`uri` varchar(250) NOT NULL,
`ref` varchar(250) NOT NULL,
`captcha` varchar(10) DEFAULT NULL,
`cnt_visit` int(11) unsigned NOT NULL DEFAULT '1',
`clk_visit` int(11) unsigned NOT NULL DEFAULT '1',
`clk_total` int(11) unsigned NOT NULL DEFAULT '1',
`clk_flood` int(11) unsigned NOT NULL DEFAULT '0',
`dt_0` datetime NOT NULL,
`dt_v` datetime NOT NULL,
`dt_l` datetime NOT NULL,
`sky` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`hash` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`vmemo` text,
PRIMARY KEY (`id`),
KEY `ucode` (`sky`),
KEY `ip_addr` (`ip`),
KEY `dt_last` (`dt_l`),
KEY `user_id` (`uid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
•
N2:
WRITE FILE: pub/wing.css
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 | .fr {
float: right;
}
.fl {
float: left;
}
.clear {
clear: both;
}
.red_label {
background-color: red;
color: white;
display: inline;
}
img, table {
border: 0;
}
.w100 {
width: 100%;
}
#trace {
width: 100%;
text-align:left;
overflow: auto;
background: #005;
color: #0f0;
margin:0 auto;
}
img.right {
border: 1px solid #ccc;
float: right;
margin-left: 15px;
padding: 5px;
}
img.left {
border: 1px solid #ccc;
float: left;
margin-right: 15px;
padding: 5px;
}
ul.pagination {
margin: 0;
padding: 0;
display: inline;
}
ul.pagination li {
margin: 0 2px;
padding: 0 3px;
display: inline;
}
ul.pagination li.active {
background: blue;
}
ul.pagination li.active a {
color: white !important;
text-decoration: none;
}
.red-link {
color: red;
}
a.red-link:hover {
background: red;
color: white;
}
.error {
background-color: red;
color: #fff;
width: 100%;
display: table;
margin: 0;
font-family: monospace;
}
.jump {
background-color: #000;
color: #fff;
width: 100%;
display: table;
margin: 0;
}
#err-top h1 {
color: red;
background-color: pink;
margin-bottom: 0;
padding-left: 12px;
}
div#box {
position: fixed;
z-index: 1000;
left: 0; top: 0;
background-color: rgba(0,0,0, 0.5);
}
div#box div#box-in {
position: fixed;
background-color: rgba(255,255,255, 1);
overflow: auto;
}
.esc {
position: fixed;
z-index: 1001;
}
.esc a {
padding: 2px 3px;
background-color: rgba(255,255,255, 1);
}
div#selector {
position: fixed;
background-color: rgba(255,255,255, 1);
}
.pdaxt a {
margin:0 1px !important;
padding:0 2px !important;
}
|
•
N3:
WRITE FILE: pub/wing.js
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 |
var sky = {
version: 0.1,
id: 0,
mode: '', // visual or debug
err: 0,
load_c: false,
load_r: 0,
load_v: '',
false: function() {
return false;
},
key: {27: this.false},
xt: {backgroundColor:'rgba(0,0,85,1)', color:'#0f0', width:$(window).width() - 100, height:$(window).height() - 100},
hide: function() {
sky.key[27] = sky.false;
$('#box').click(sky.false).hide().children('div.esc').remove();
$('#box-in').html('');
},
show: function() {
sky.key[27] = sky.hide;
$('#box').click(this.hide).prepend('<div class="esc"><a href="javascript:;" class="red-link fr">Esc - Close [X]</a></div>');
$('#box .esc').css('width', $('#box-in').width() - 20);
sky.resize();
},
resize: function() {
var wh = $(window).height(), ww = $(window).width(), t;
$('#box').css({width:ww, height:wh}).children().css({left:(ww-$('#box-in').width())/2, top: t = (wh-$('#box-in').height())/2});
$('#box div:first').css('top', t - 19);
$('#content').css({minHeight: wh - $('#foot').height() - $('#head').height() - 50});
},
bg: '#ded url(pub/img/bg.png)',
background_obj: false,
bgs: function(el) {
if (!el) el = $('#box-in');
sky.background_obj = {el:el, css:el.css('background')};
el.css('background', 'url(pub/img/ajax2.gif)');
},
bgh: function(bg) {
if (sky.background_obj) {
sky.background_obj.el.css('background', bg ? bg : sky.background_obj.css);
sky.background_obj = false;
}
}
}
function box(html, x) {
var def = {backgroundColor:'rgba(255,255,255,1)', color:'#000', width:500, height:500};
$('#box').click(sky.false).show().children('#box-in').html(html).css(x ? x : def).click(sky.false);
if ('' === x) sky.show();
sky.resize();
}
function ajax(c_, post, func, cc) {
var pval = 'number' == typeof c_ ? 'ajax' + (c_ ? c_ : '') : (c_ ? c_ : 'ajax'),
m = document.location.href.match(/^.+?\/(\w*)(\?(\w+).*?)?(#.*)?$/),
page = cc ? cc : (m && m[1] ? m[1] : 'main'),
__page = 'adm' == page && m && m[3] ? m[3] : page;
$.post('index.php?AJAX=' + page + '&' + __page + '=' + pval, post ? post : '', function(r) {
if ('undefined' !== typeof r.catch_error) box(r.catch_error, '');
else if (sky.is_debug && r.match(/^<br ?\/>[\r\n]+<b>(Parse|Fatal) error</g)) box(r, '');
else if ('function' == typeof func) func(r, 0);
else if ('string' == typeof func) $('#' + func).html(r);
else if ('object' == typeof func) func.html(r);
else if ('' != r) alert(r);
});
}
$(function() {
var html = '<div id="box" style="display:none"><div id="box-in"></div></div>'
+ '<div style="opacity:0;position:absolute;left:0;top:0;z-index:-1000"><img src="pub/img/ajax2.gif" /></div>';
// set box
$('body').prepend(html).keydown(function(e) {
if ('function' == typeof sky.key[e.keyCode]) try {
sky.key[e.keyCode]();
} catch(e) {}
});
if (sky.err = $('#err-bottom')) sky.err = $('#err-top').show().html($('#err-bottom').html()), $('#err-bottom').remove();
sky.resize();
$(window).resize(sky.resize);
if (sky.load_c) ajax('_', sky.load_v, sky.load_r, sky.load_c);
});
|
Записи 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