Пример #1
0
 public static function init($reinit = false, $config = array())
 {
     self::$active_debug_mode = false;
     self::$allow_backtrace_sql = isset($_REQUEST['sql_backtrace']);
     self::$debugger_cookie = !empty($_COOKIE['debugger']) ? $_COOKIE['debugger'] : '';
     if ($reinit) {
         Registry::registerCache('debugger', SESSION_ALIVE_TIME, Registry::cacheLevel('time'), true);
         self::$actives = fn_get_storage_data('debugger_active');
         self::$actives = !empty(self::$actives) ? unserialize(self::$actives) : array();
         $active_in_registry = !empty(self::$actives[self::$debugger_cookie]) && time() - self::$actives[self::$debugger_cookie] < 0 ? true : false;
     }
     $debugger_token = !empty($config) ? $config['debugger_token'] : Registry::get('config.debugger_token');
     switch (true) {
         case defined('AJAX_REQUEST') && substr($_REQUEST['dispatch'], 0, 8) !== 'debugger':
             break;
         case defined('DEBUG_MODE') && DEBUG_MODE == true:
         case !$reinit && (!empty(self::$debugger_cookie) || isset($_REQUEST[$debugger_token])):
             self::$active_debug_mode = true;
             break;
         case !$reinit:
             break;
             // next if reinit
         // next if reinit
         case !empty(self::$debugger_cookie) && !empty($active_in_registry):
             self::$active_debug_mode = true;
             break;
         case isset($_REQUEST[$debugger_token]):
             $salt = '';
             if ($_SESSION['auth']['user_type'] == 'A' && $_SESSION['auth']['is_root'] == 'Y') {
                 $user_admin = db_get_row('SELECT email, password FROM ?:users WHERE user_id = ?i', $_SESSION['auth']['user_id']);
                 $salt = $user_admin['email'] . $user_admin['password'];
             }
             if ($debugger_token != self::DEFAULT_TOKEN || !empty($salt)) {
                 // for non-default token allow full access
                 self::$debugger_cookie = substr(md5(SESSION::getId() . $salt), 0, 8);
                 $active_in_registry = true;
                 self::$active_debug_mode = true;
             }
             if (AREA == 'C' && !empty($_REQUEST[$debugger_token])) {
                 if (!empty(self::$actives[$_REQUEST[$debugger_token]]) && time() - self::$actives[$_REQUEST[$debugger_token]] < 0) {
                     $active_in_registry = true;
                     self::$debugger_cookie = $_REQUEST[$debugger_token];
                     self::$active_debug_mode = true;
                 }
             }
             fn_set_cookie('debugger', self::$debugger_cookie, SESSION_ALIVE_TIME);
             break;
     }
     if ($reinit && self::$active_debug_mode && !empty(self::$debugger_cookie)) {
         self::$actives[self::$debugger_cookie] = time() + self::EXPIRE_DEBUGGER;
         fn_set_storage_data('debugger_active', serialize(self::$actives));
         $active_in_registry = true;
     }
     if ($reinit && !empty(self::$debugger_cookie) && empty($active_in_registry)) {
         fn_set_cookie('debugger', '', 0);
         unset(self::$actives[self::$debugger_cookie]);
         fn_set_storage_data('debugger_active', serialize(self::$actives));
     }
     return self::$active_debug_mode;
 }