protected function throw403() { Typecho_Response::setStatus(403); $this->response->throwJson(array('status' => '403 Forbidden.')); }
/** * 输出错误页面 * * @access public * @param mixed $exception 错误信息 * @return void */ public static function error($exception) { $isException = is_object($exception); $message = ''; if ($isException) { $code = $exception->getCode(); $message = $exception->getMessage(); } else { $code = $exception; } $charset = self::$charset; if ($isException && $exception instanceof Typecho_Db_Exception) { $code = 500; @error_log($message); //覆盖原始错误信息 $message = 'Database Server Error'; if ($exception instanceof Typecho_Db_Adapter_Exception) { $code = 503; $message = 'Error establishing a database connection'; } else { if ($exception instanceof Typecho_Db_Query_Exception) { $message = 'Database Query Error'; } } } else { switch ($code) { case 500: $message = 'Server Error'; break; case 404: $message = 'Page Not Found'; break; default: $code = 'Error'; break; } } /** 设置http code */ if (is_numeric($code) && $code > 200) { Typecho_Response::setStatus($code); } $message = nl2br($message); if (defined('__TYPECHO_EXCEPTION_FILE__')) { require_once __TYPECHO_EXCEPTION_FILE__; } else { echo <<<EOF <!DOCTYPE html> <html lang="en"> <head> <meta charset="{$charset}"> <title>{$code}</title> <style> html { padding: 50px 10px; font-size: 16px; line-height: 1.4; color: #666; background: #F6F6F3; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } html, input { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; } body { max-width: 500px; _width: 500px; padding: 30px 20px; margin: 0 auto; background: #FFF; } ul { padding: 0 0 0 40px; } .container { max-width: 380px; _width: 380px; margin: 0 auto; } </style> </head> <body> <div class="container"> {$message} </div> </body> </html> EOF; } exit; }
/** * 输出错误页面 * * @access public * @param mixed $exception 错误信息 * @return void */ public static function error($exception) { $isException = is_object($exception); if ($isException) { $code = $exception->getCode(); $message = $exception->getMessage(); } else { $code = $exception; } require_once 'Typecho/Response.php'; $charset = self::$charset; if ($isException && $exception instanceof Typecho_Db_Exception) { $code = 500; @error_log($message); //覆盖原始错误信息 $message = 'Database Server Error'; if ($exception instanceof Typecho_Db_Adapter_Exception) { $code = 503; $message = 'Error establishing a database connection'; } else { if ($exception instanceof Typecho_Db_Query_Exception) { $message = 'Database Query Error'; } } } else { switch ($code) { case 500: $message = 'Server Error'; break; case 404: $message = 'Page Not Found'; break; default: $code = 'Error'; break; } } /** 设置http code */ if (is_numeric($code) && $code > 200) { require_once 'Typecho/Response.php'; Typecho_Response::setStatus($code); } $message = nl2br($message); if (defined('__TYPECHO_EXCEPTION_FILE__')) { require_once __TYPECHO_EXCEPTION_FILE__; } else { echo <<<EOF <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset={$charset}" /> <title>{$code}</title> <style type="text/css"> body { background: #f7fbe9; font-family: "Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana; } #error { background: #333; width: 360px; margin: 0 auto; margin-top: 100px; color: #fff; padding: 10px; -moz-border-radius-topleft: 4px; -moz-border-radius-topright: 4px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-top-left-radius: 4px; -webkit-border-top-right-radius: 4px; -webkit-border-bottom-left-radius: 4px; -webkit-border-bottom-right-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; } h1 { padding: 10px; margin: 0; font-size: 36px; } p { padding: 0 20px 20px 20px; margin: 0; font-size: 12px; } img { padding: 0 0 5px 260px; } </style> </head> <body> <div id="error"> <h1>{$code}</h1> <p>{$message}</p> <img src="?464D-E63E-9D08-97E2-16DD-6A37-BDEC-6021" /> </div> </body> </html> EOF; } exit; }