<?php // Defines __k_def('C2_STR_ALPHA', '[^[:alpha:]_:./ -]'); __k_def('C2_STR_ALNUM', '[^[:alnum:]_:./ -]'); __k_def('C2_STR_NUM', '[^[:digit:].-]'); __k_def('C2_STR_EMAIL', '[^[:alnum:]@_./ -]'); class c2Str { public function __construct() { } public static function lower($s = '') { return C2_MB ? mb_strtolower($s) : strtolower($s); } public static function trunc($s = '', $l = C2_STR_LENGTH) { if ($l == 0) { return $s; } return C2_MB ? mb_substr(trim($s), 0, $l) : substr(trim($s), 0, $l); } public static function sql($s = '') { return '\'' . addslashes($s) . '\''; } public static function a2f($arr = NULL, $def = '*', $sql = false) { if (empty($arr)) { return $def;
<?php __k_def('C2_PDB_LIMIT', 100); __k_def('C2_PDB_LENGTH', 64); __k_def('C2_PDB_TIME', true); __k_def('C2_PDB_TS', 'Y-m-d H:i:s'); __k_def('C2_PDB_MTS', 'Y-m-d H:i:s.u'); class c2PDB implements ArrayAccess { private $__cfg; /**< config array */ private $__con; /**< database connection object */ // Constructor public function __construct($cfg = NULL) { if (empty($cfg)) { throw new c2Ex(__METHOD__); } /*! \param $config System profile which contains DB connection parameters */ $this->__cfg = $cfg; $this->_setcon(NULL); } // begin ArrayAccess interface public function offsetSet($offset, $value) { /*! ArrayAccess interface */ $this->__cfg[$offset] = $value; }
<?php __k_def('C2_SYS_ERR', true); class c2Sys extends c2Ses { public function __construct($cfg = NULL) { parent::__construct($cfg); } private function __ac($p = NULL, $a = NULL, $s = true) { try { if ($s) { $r = $this->ProcRow($p, $a); } else { $r = $this->Proc($p, $a); } } catch (Exception $e) { throw new c2Ex(__METHOD__ . (C2_SYS_ERR ? "\n" . $e->getMessage() : "")); } return $r; } protected function _u_rd($id = NULL) { return $this->__ac('u_rd', array($id), true); } protected function _g_rd($id = NULL) { return $this->__ac('g_rd', array($id), true); } protected function _u_iltr($u = NULL)
function __k_init($enc = 'UTF-8', $exc = NULL) { __k_def('C2_STR_LENGTH', 32); __k_def('C2_STR_REGEXP', '[^[:alnum:]_.-]'); __k_def('C2_JSON_OBC', false); __k_def('C2_DEBUG_LEVEL', 9); __k_def('C2_CLI', PHP_SAPI == 'cli' ? true : false); __k_def('C2_OB', true); __k_def('C2_EOL', C2_CLI ? PHP_EOL : '<br>' . PHP_EOL); __k_def('C2_MB', extension_loaded('mbstring')); __k_def('C2_TZ', 'CET'); __k_def('C2_ERR', true); date_default_timezone_set(C2_TZ); // encoding __k_obs(); __k_enc($enc); // errors if (C2_ERR) { register_shutdown_function('__k_sd'); set_error_handler('__k_err'); } // exceptions if (function_exists($exc)) { set_exception_handler($exc); } return true; }
<?php __k_def('C2_REQ_LENGTH', 128); __k_def('C2_REQ_TYPE', 'POST'); __k_def('C2_REQ_OBC', C2_JSON_OBC); class c2Req { public function __construct() { } public static function req($id = NULL, $def = NULL, $c = true, $s = true, $l = C2_REQ_LENGTH) { $t = "_" . C2_REQ_TYPE; global ${$t}; $v = (!isset(${$t}[$id]) or ${$t}[$id] == '') ? $def : ${$t}[$id]; if ($c) { unset(${$t}[$id]); } if ($s && !empty($v)) { $v = c2Str::trunc(c2Str::alnum($v), $l); } return $v; } public static function get($id = NULL, $def = NULL, $c = true, $s = true, $l = C2_REQ_LENGTH) { return self::req($id, $def, $c, $s, $l); } public static function jreq($id = NULL, $def = NULL, $l = C2_REQ_LENGTH) { return json_decode(self::req($id, $def, true, true, true, $l)); }
<?php __k_def('C2_SES_LENGTH', 128); class c2Ses extends c2PDB { // time cache protected $_time; protected $_msec; public function __construct($cfg = NULL) { parent::__construct($cfg); $this->_time = time(); $this->_msec = microtime(); // register session handlers session_set_save_handler(array(&$this, 'open'), array(&$this, 'close'), array(&$this, 'read'), array(&$this, 'write'), array(&$this, 'destroy'), array(&$this, 'gc')); } // end construct protected function _s($s = NULL) { return __k_str($s, C2_SES_LENGTH); } public function cookie() { // outdate the cookie if (session_id() != "" || isset($_COOKIE[session_name()])) { setcookie(session_name(), '', 0); } } // Open the session public function open($sp = NULL, $sn = NULL) {