/** * General Error Page * * Takes an error message as input * and displays it using the specified template. * * @param string $message Error Message * @param int $code HTTP Header code * * @return void */ public static function halt($message, $code = 404) { Response::getSoul()->setStatus($code); if (Config::getSoul()->APP_DEBUG == false) { $message = '404 Not Found.'; } $tplPath = Config::getSoul()->ERROR_TPL; if ($tplPath == null || !Helper::isFile(Config::getSoul()->APP_FULL_PATH . '/views/' . $tplPath . '.html')) { $tpl = '<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Kotori.php 500 Internal Error</title> <meta name="robots" content="NONE,NOARCHIVE"> <style type="text/css"> html * { padding:0; margin:0; } body * { padding:10px 20px; } body * * { padding:0; } body { font:small sans-serif; background:#eee; } body>div { border-bottom:1px solid #ddd; } h1 { font-weight:normal; margin-bottom:.4em; } h1 span { font-size:60%; color:#666; font-weight:normal; } table { border:none; border-collapse: collapse; width:100%; } td, th { vertical-align:top; padding:2px 3px; } th { width:12em; text-align:right; color:#666; padding-right:.5em; } #info { background:#f6f6f6; } #info p {font-size: 16px} #summary { background: #ffc; } #explanation { background:#eee; border-bottom: 0px none; } </style> </head> <body> <div id="summary"> <h1>Kotori.php Internal Error <span>(500)</span></h1> <table class="meta"> <tr> <th>Request Method:</th> <td>' . strtoupper($_SERVER['REQUEST_METHOD']) . '</td> </tr> <tr> <th>Request URL:</th> <td>' . Request::getSoul()->getBaseUrl() . ltrim($_SERVER['REQUEST_URI'], '/') . '</td> </tr> </table> </div> <div id="info"> ' . $message . ' </div> <div id="explanation"> <p> You\'re seeing this error because you have <code>APP_DEBUG = True</code> in your index.php file. Change that to <code>False</code>, and Kotori.php will display a standard 404 page. </p> </div> </body> </html>'; } else { $tpl = file_get_contents(Config::getSoul()->APP_FULL_PATH . '/views/' . $tplPath . '.html'); } $tpl = str_replace('{$message}', $message, $tpl); $htmlParser = htmlParserFactory::construct(); $tpl = $htmlParser->compress($tpl); exit($tpl); }
/** * Display Output * * Processes and sends finalized output data to the browser along * * @param string $tpl Template Path * @return void */ public function display($tpl = '') { if ('' === $tpl) { $tpl = CONTROLLER_NAME . '/' . ACTION_NAME; } $this->_viewPath = $this->_tplDir . $tpl . '.html'; if (!Helper::isFile($this->_viewPath)) { throw new \Exception('Template is not existed.'); } unset($tpl); ob_start(); extract($this->_data, EXTR_OVERWRITE); include $this->_viewPath; $buffer = ob_get_contents(); ob_get_clean(); $output = Helper::comment() . preg_replace('|</body>.*?</html>|is', '', $buffer, -1, $count) . Trace::getSoul()->showTrace(); if ($count > 0) { $output .= '</body></html>'; } echo $output; }