showContent(); } // Something wasn't found? catch (NotFoundException $e) { self::trigger404(); } // Or are they just sneaking into areas they don't belong? catch (NotAllowedException $e) { if (Registry::get('user')->isGuest()) self::kickGuest(); else self::trigger403(); } catch (UserFacingException $e) { $debug_info = ErrorHandler::getDebugInfo($e->getTrace()); ErrorHandler::display($e->getMessage(), $debug_info, false); } catch (Exception $e) { ErrorHandler::handleError(E_USER_ERROR, 'Unspecified exception: ' . $e->getMessage(), $e->getFile(), $e->getLine()); } catch (Error $e) { ErrorHandler::handleError(E_USER_ERROR, 'Fatal error: ' . $e->getMessage(), $e->getFile(), $e->getLine()); } } /** * Kicks a guest to a login form, redirecting them back to this page upon login. */ public static function kickGuest($title = null, $message = null) { $form = new LogInForm('Log in'); $form->adopt(new Alert($title ?? '', $message ?? 'You need to be logged in to view this page.', 'danger')); $form->setRedirectUrl($_SERVER['REQUEST_URI']); $page = new MainTemplate('Login required'); $page->appendStylesheet(BASEURL . '/css/admin.css'); $page->adopt($form); $page->html_main(); exit; } public static function trigger400() { header('HTTP/1.1 400 Bad Request'); $page = new MainTemplate('Bad request'); $page->adopt(new DummyBox('Bad request', '
The server does not understand your request.
')); $page->html_main(); exit; } public static function trigger403() { header('HTTP/1.1 403 Forbidden'); $page = new MainTemplate('Access denied'); $page->adopt(new DummyBox('Forbidden', 'You do not have access to the page you requested.
')); $page->html_main(); exit; } public static function trigger404() { header('HTTP/1.1 404 Not Found'); $page = new MainTemplate('Page not found'); if (Registry::has('user') && Registry::get('user')->isAdmin()) { $page->appendStylesheet(BASEURL . '/css/admin.css'); } $page->adopt(new DummyBox('Well, this is a bit embarrassing!', 'The page you requested could not be found. Don\'t worry, it\'s probably not your fault. You\'re welcome to browse the website, though!
', 'errormsg')); $page->addClass('errorpage'); $page->html_main(); exit; } }