Beispiel #1
0
 public function message($msg, $jumpurl = '')
 {
     if (core::gpc('ajax')) {
         $arr = array('servererror' => '', 'status' => 1, 'message' => $msg);
         echo core::json_encode($arr);
         exit;
     } else {
         echo $msg;
         exit;
     }
 }
Beispiel #2
0
 public function display($file, $json = array())
 {
     if (!core::gpc('ajax', 'R')) {
         extract($this->vars, EXTR_SKIP);
         include $this->gettpl($file);
         // json 格式,约定为格式。
     } else {
         ob_start();
         extract($this->vars, EXTR_SKIP);
         include $this->gettpl($file);
         $body = ob_get_contents();
         ob_end_clean();
         $json = array('servererror' => '', 'status' => 1, 'message' => array('width' => 400, 'height' => 300, 'pos' => 'center', 'title' => '默认窗口标题', 'body' => ''));
         $json['message'] = array_merge($json['message'], $this->json);
         $this->fetch_json_header($body, $json['message']);
         $json['message']['body'] = $body;
         echo core::json_encode($json);
     }
 }
Beispiel #3
0
 public static function to_json($e)
 {
     if (DEBUG) {
         $arr = self::format_exception($e);
         $backinfo = '';
         foreach ($arr['backtracelist'] as $v) {
             $backinfo .= "{$v['file']} [{$v['line']}] : {$v['class']}{$v['type']}{$v['function']}({$v['args']})\r\n";
         }
         $s = "{$arr['message']}\r\n File: {$arr['file']} [{$arr['line']}] \r\n \r\n {$backinfo}";
         $s = str_replace(array('&nbsp;', '<br />', '&gt;', '&lt;'), array(' ', "\r\n", '>', '<'), $s);
         $s = preg_replace('#[\\r\\n]+#', "\n", $s);
     } else {
         $s = $e->getMessage();
     }
     $s = preg_replace('# \\S*[/\\\\](.+?\\.php)#', ' \\1', $s);
     //$s = preg_replace('#[\\x80-\\xff]{2}#', '?', $s);// 替换掉 gbk, 否则 json_encode 会报错!
     $arr = array('servererror' => $s);
     return core::json_encode($arr);
 }
Beispiel #4
0
 public static function exception_handle($e)
 {
     // 避免死循环
     DEBUG && ($_SERVER['exception'] = 1);
     core::ob_clean();
     log::write($e->getMessage() . ' File: ' . $e->getFile() . ' [' . $e->getLine() . ']');
     $s = '';
     if (DEBUG) {
         try {
             if (self::gpc('ajax', 'R')) {
                 $s = xn_exception::to_json($e);
             } else {
                 //!core::is_cmd() && header('Content-Type: text/html; charset=UTF-8');
                 $s = xn_exception::to_html($e);
             }
         } catch (Exception $e) {
             $s = get_class($e) . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine();
         }
     } else {
         if (self::gpc('ajax', 'R')) {
             $s = core::json_encode(array('servererror' => $e->getMessage()));
         } else {
             $s = $e->getMessage();
         }
     }
     echo $s;
     exit;
 }
Beispiel #5
0
 /**
  * Custom error handler.
  *
  * Catches all errors (not exceptions) and creates an ErrorException.
  * ErrorException then can caught by Yaf\ErrorController.
  *
  * @param integer $errno the error number.
  * @param string $errstr the error message.
  * @param string $errfile the file where error occured.
  * @param integer $errline the line of the file where error occured.
  *
  * @throws ErrorException
  */
 static function error_handler($errno, $errstr, $errfile, $errline)
 {
     // 防止死循环
     $errortype = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Runtime Notice');
     $errnostr = isset($errortype[$errno]) ? $errortype[$errno] : 'Unknonw';
     // 运行时致命错误,直接退出。并且 debug_backtrace()
     $s = "[{$errnostr}] : {$errstr} in File {$errfile}, Line: {$errline}";
     // 抛出异常,记录到日志
     //echo $errstr;
     if (DEBUG && empty($_SERVER['exception'])) {
         throw new Exception($s);
     } else {
         log::write($s . date('Y-M-D H:i:s', $_SERVER['time']));
         //$s = preg_replace('# \S*[/\\\\](.+?\.php)#', ' \\1', $s);
         if (core::gpc('ajax', 'R')) {
             core::ob_clean();
             //$s = preg_replace('#[\\x80-\\xff]{2}#', '?', $s);// 替换掉 gbk, 否则 json_encode 会报错!
             // 判断错误级别,决定是否退出。
             if ($errno != E_NOTICE && $errno != E_USER_ERROR && $errno != E_USER_NOTICE && $errno != E_USER_WARNING) {
                 $s = core::json_encode(array('servererror' => $s));
                 throw new Exception($s);
                 exit;
             } else {
                 $_SERVER['notice_error'] .= $s;
                 // 继续执行。
             }
         } else {
             //echo $s;
             // 继续执行。
         }
     }
     return 0;
 }
Beispiel #6
0
 public function update($key, $data)
 {
     return $this->saekv->set($key, core::json_encode($data));
 }