diff --git a/e107_core/controllers/system/error.php b/e107_core/controllers/system/error.php index 02e0ebc2b..a2a6a51ca 100644 --- a/e107_core/controllers/system/error.php +++ b/e107_core/controllers/system/error.php @@ -48,28 +48,7 @@ class core_system_error_controller extends eController */ public function actionForbidden() { - $response = $this->getResponse(); - $response->setRenderMod('error403'); - $response->addHeader('HTTP/1.0 403 Forbidden'); - - $tp = e107::getParser(); - $tpl = e107::getCoreTemplate('error', '403'); - $sc = e107::getScBatch('error'); - - $title = LAN_ERROR_TITLE; - $subtitle = LAN_ERROR_4; - $caption = LAN_ERROR_45; - $content = LAN_ERROR_5 . '
' . LAN_ERROR_6 . '

' . LAN_ERROR_2; - - $sc->setVars(array( - 'title' => $title, - 'subtitle' => $subtitle, - 'caption' => $caption, - 'content' => $content, - )); - - $body = $tp->parseTemplate($tpl, true, $sc); - $this->addBody($body); + e107::getError()->render(403); } /** @@ -77,28 +56,7 @@ class core_system_error_controller extends eController */ public function actionNotfound() { - $response = $this->getResponse(); - $response->setRenderMod('error404'); - $response->addHeader('HTTP/1.0 404 Not Found'); - - $tp = e107::getParser(); - $tpl = e107::getCoreTemplate('error', '404'); - $sc = e107::getScBatch('error'); - - $title = LAN_ERROR_TITLE; - $subtitle = LAN_ERROR_7; - $caption = LAN_ERROR_45; - $content = LAN_ERROR_21 . '
' . LAN_ERROR_9; - - $sc->setVars(array( - 'title' => $title, - 'subtitle' => $subtitle, - 'caption' => $caption, - 'content' => $content, - )); - - $body = $tp->parseTemplate($tpl, true, $sc); - $this->addBody($body); + e107::getError()->render(404); } } diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 7685f16ab..a386b823b 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -135,88 +135,89 @@ class e107 * @var array */ protected static $_known_handlers = array( - 'UserHandler' => '{e_HANDLER}user_handler.php', - 'comment' => '{e_HANDLER}comment_class.php', - 'convert' => '{e_HANDLER}date_handler.php', - 'db' => '{e_HANDLER}mysql_class.php', - 'e107Email' => '{e_HANDLER}mail.php', - 'e107_event' => '{e_HANDLER}event_class.php', + 'UserHandler' => '{e_HANDLER}user_handler.php', + 'comment' => '{e_HANDLER}comment_class.php', + 'convert' => '{e_HANDLER}date_handler.php', + 'db' => '{e_HANDLER}mysql_class.php', + 'e107Email' => '{e_HANDLER}mail.php', + 'e107_event' => '{e_HANDLER}event_class.php', 'e107_db_debug' => '{e_HANDLER}db_debug_class.php', - 'e107_traffic' => '{e_HANDLER}traffic_class.php', - 'e107_user_extended' => '{e_HANDLER}user_extended_class.php', - 'e107plugin' => '{e_HANDLER}plugin_class.php', - 'e_chart' => '{e_HANDLER}chart_class.php', - 'e_core_session' => '{e_HANDLER}session_handler.php', - 'e_admin_controller' => '{e_HANDLER}admin_ui.php', - 'e_admin_controller_ui' => '{e_HANDLER}admin_ui.php', - 'e_admin_dispatcher' => '{e_HANDLER}admin_ui.php', - 'e_admin_form_ui' => '{e_HANDLER}admin_ui.php', - 'e_admin_log' => '{e_HANDLER}admin_log_class.php', - 'e_front_model' => '{e_HANDLER}model_class.php', - 'e_admin_model' => '{e_HANDLER}model_class.php', - 'e_admin_request' => '{e_HANDLER}admin_ui.php', - 'e_admin_response' => '{e_HANDLER}admin_ui.php', - 'e_admin_ui' => '{e_HANDLER}admin_ui.php', + 'e107_traffic' => '{e_HANDLER}traffic_class.php', + 'e107_user_extended' => '{e_HANDLER}user_extended_class.php', + 'e107plugin' => '{e_HANDLER}plugin_class.php', + 'e_chart' => '{e_HANDLER}chart_class.php', + 'e_core_session' => '{e_HANDLER}session_handler.php', + 'e_admin_controller' => '{e_HANDLER}admin_ui.php', + 'e_admin_controller_ui' => '{e_HANDLER}admin_ui.php', + 'e_admin_dispatcher' => '{e_HANDLER}admin_ui.php', + 'e_admin_form_ui' => '{e_HANDLER}admin_ui.php', + 'e_admin_log' => '{e_HANDLER}admin_log_class.php', + 'e_front_model' => '{e_HANDLER}model_class.php', + 'e_admin_model' => '{e_HANDLER}model_class.php', + 'e_admin_request' => '{e_HANDLER}admin_ui.php', + 'e_admin_response' => '{e_HANDLER}admin_ui.php', + 'e_admin_ui' => '{e_HANDLER}admin_ui.php', 'e_ajax_class' => '{e_HANDLER}e_ajax_class.php', - 'e_array' => '{e_HANDLER}core_functions.php', // Old ArrayStorage. - 'e_bbcode' => '{e_HANDLER}bbcode_handler.php', - 'e_bb_base' => '{e_HANDLER}bbcode_handler.php', - 'e_file' => '{e_HANDLER}file_class.php', - 'e_form' => '{e_HANDLER}form_handler.php', - 'e_jshelper' => '{e_HANDLER}js_helper.php', - 'e_media' => '{e_HANDLER}media_class.php', - 'e_menu' => '{e_HANDLER}menu_class.php', - 'e_model' => '{e_HANDLER}model_class.php', - 'e_navigation' => '{e_HANDLER}sitelinks_class.php', - 'e_news_item' => '{e_HANDLER}news_class.php', - 'e_news_tree' => '{e_HANDLER}news_class.php', - 'e_object' => '{e_HANDLER}model_class.php', - 'e_online' => '{e_HANDLER}online_class.php', - 'e_parse' => '{e_HANDLER}e_parse_class.php', - 'e_parser' => '{e_HANDLER}e_parse_class.php', - 'e_parse_shortcode' => '{e_HANDLER}shortcode_handler.php', - 'e_ranks' => '{e_HANDLER}e_ranks_class.php', - 'e_shortcode' => '{e_HANDLER}shortcode_handler.php', - 'e_system_user' => '{e_HANDLER}user_model.php', - 'e_upgrade' => '{e_HANDLER}e_upgrade_class.php', - 'e_user_model' => '{e_HANDLER}user_model.php', - 'e_user' => '{e_HANDLER}user_model.php', + 'e_array' => '{e_HANDLER}core_functions.php', // Old ArrayStorage. + 'e_bbcode' => '{e_HANDLER}bbcode_handler.php', + 'e_bb_base' => '{e_HANDLER}bbcode_handler.php', + 'e_file' => '{e_HANDLER}file_class.php', + 'e_form' => '{e_HANDLER}form_handler.php', + 'e_jshelper' => '{e_HANDLER}js_helper.php', + 'e_media' => '{e_HANDLER}media_class.php', + 'e_menu' => '{e_HANDLER}menu_class.php', + 'e_model' => '{e_HANDLER}model_class.php', + 'e_navigation' => '{e_HANDLER}sitelinks_class.php', + 'e_news_item' => '{e_HANDLER}news_class.php', + 'e_news_tree' => '{e_HANDLER}news_class.php', + 'e_object' => '{e_HANDLER}model_class.php', + 'e_online' => '{e_HANDLER}online_class.php', + 'e_parse' => '{e_HANDLER}e_parse_class.php', + 'e_parser' => '{e_HANDLER}e_parse_class.php', + 'e_parse_shortcode' => '{e_HANDLER}shortcode_handler.php', + 'e_ranks' => '{e_HANDLER}e_ranks_class.php', + 'e_shortcode' => '{e_HANDLER}shortcode_handler.php', + 'e_system_user' => '{e_HANDLER}user_model.php', + 'e_upgrade' => '{e_HANDLER}e_upgrade_class.php', + 'e_user_model' => '{e_HANDLER}user_model.php', + 'e_user' => '{e_HANDLER}user_model.php', 'e_user_extended_structure_tree' => '{e_HANDLER}user_model.php', - 'e_userperms' => '{e_HANDLER}user_handler.php', - 'e_validator' => '{e_HANDLER}validator_class.php', - 'e_vars' => '{e_HANDLER}model_class.php', - 'ecache' => '{e_HANDLER}cache_handler.php', - 'eController' => '{e_HANDLER}application.php', - 'eDispatcher' => '{e_HANDLER}application.php', - 'eException' => '{e_HANDLER}application.php', - 'eFront' => '{e_HANDLER}application.php', - 'eHelper' => '{e_HANDLER}application.php', - 'eIPHandler' => '{e_HANDLER}iphandler_class.php', - 'email_validation_class' => '{e_HANDLER}mail_validation_class.php', - 'eMessage' => '{e_HANDLER}message_handler.php', - 'eRequest' => '{e_HANDLER}application.php', - 'eResponse' => '{e_HANDLER}application.php', - 'eRouter' => '{e_HANDLER}application.php', - 'eUrl' => '{e_HANDLER}e107Url.php', - 'eUrlConfig' => '{e_HANDLER}application.php', - 'eUrlRule' => '{e_HANDLER}application.php', - 'Hybrid_Auth' => '{e_HANDLER}hybridauth/Hybrid/Auth.php', - 'language' => '{e_HANDLER}language_class.php', - 'news' => '{e_HANDLER}news_class.php', - 'notify' => '{e_HANDLER}notify_class.php', - 'override' => '{e_HANDLER}override_class.php', - 'rater' => '{e_HANDLER}rate_class.php', - 'redirection' => '{e_HANDLER}redirection_class.php', - 'secure_image' => '{e_HANDLER}secure_img_handler.php', - 'sitelinks' => '{e_HANDLER}sitelinks_class.php', - 'themeHandler' => '{e_HANDLER}theme_handler.php', - 'user_class' => '{e_HANDLER}userclass_class.php', + 'e_userperms' => '{e_HANDLER}user_handler.php', + 'e_validator' => '{e_HANDLER}validator_class.php', + 'e_vars' => '{e_HANDLER}model_class.php', + 'ecache' => '{e_HANDLER}cache_handler.php', + 'eController' => '{e_HANDLER}application.php', + 'eDispatcher' => '{e_HANDLER}application.php', + 'eException' => '{e_HANDLER}application.php', + 'eFront' => '{e_HANDLER}application.php', + 'eHelper' => '{e_HANDLER}application.php', + 'eIPHandler' => '{e_HANDLER}iphandler_class.php', + 'email_validation_class' => '{e_HANDLER}mail_validation_class.php', + 'eMessage' => '{e_HANDLER}message_handler.php', + 'eRequest' => '{e_HANDLER}application.php', + 'eResponse' => '{e_HANDLER}application.php', + 'eRouter' => '{e_HANDLER}application.php', + 'eUrl' => '{e_HANDLER}e107Url.php', + 'eUrlConfig' => '{e_HANDLER}application.php', + 'eUrlRule' => '{e_HANDLER}application.php', + 'Hybrid_Auth' => '{e_HANDLER}hybridauth/Hybrid/Auth.php', + 'language' => '{e_HANDLER}language_class.php', + 'news' => '{e_HANDLER}news_class.php', + 'notify' => '{e_HANDLER}notify_class.php', + 'override' => '{e_HANDLER}override_class.php', + 'rater' => '{e_HANDLER}rate_class.php', + 'redirection' => '{e_HANDLER}redirection_class.php', + 'secure_image' => '{e_HANDLER}secure_img_handler.php', + 'sitelinks' => '{e_HANDLER}sitelinks_class.php', + 'themeHandler' => '{e_HANDLER}theme_handler.php', + 'user_class' => '{e_HANDLER}userclass_class.php', 'user_class_admin' => '{e_HANDLER}userclass_class.php', - 'userlogin' => '{e_HANDLER}login.php', - 'validatorClass' => '{e_HANDLER}validator_class.php', - 'xmlClass' => '{e_HANDLER}xml_class.php', + 'userlogin' => '{e_HANDLER}login.php', + 'validatorClass' => '{e_HANDLER}validator_class.php', + 'xmlClass' => '{e_HANDLER}xml_class.php', 'e107MailManager' => '{e_HANDLER}mail_manager_class.php', - 'e_library_manager' => '{e_HANDLER}library_manager.php' + 'e_library_manager' => '{e_HANDLER}library_manager.php', + 'error_page' => '{e_HANDLER}error_page_class.php', ); /** @@ -3059,6 +3060,16 @@ class e107 } + /** + * Retrieve error page handler. + * + * @return error_page + */ + public static function getError() + { + return self::getSingleton('error_page', true); + } + /** * Parses an array into a valid, rawurlencoded query string. This differs from http_build_query() as we need to diff --git a/e107_handlers/error_page_class.php b/e107_handlers/error_page_class.php new file mode 100644 index 000000000..1eb5125b4 --- /dev/null +++ b/e107_handlers/error_page_class.php @@ -0,0 +1,217 @@ +template = 400; + $this->title = LAN_ERROR_35; + $this->caption = LAN_ERROR_45; + $this->content = LAN_ERROR_36; + } + + /** + * Set a "Authentication Failed" error page. + */ + private function setPageUnauthorized() + { + header('HTTP/1.1 401 Unauthorized', true, 401); + + $this->template = 401; + $this->title = LAN_ERROR_1; + $this->caption = LAN_ERROR_45; + $this->content = LAN_ERROR_2 . '
' . LAN_ERROR_3; + } + + /** + * Set a "Access forbidden" error page. + */ + private function setPageForbidden() + { + header('HTTP/1.1 403 Forbidden', true, 403); + + $this->template = 403; + $this->title = LAN_ERROR_4; + $this->caption = LAN_ERROR_45; + $this->content = LAN_ERROR_5 . '
' . LAN_ERROR_6 . '

' . LAN_ERROR_2; + } + + /** + * Set a "Not Found" error page. + */ + private function setPageNotFound() + { + header('HTTP/1.1 404 Not Found', true, 404); + + $this->template = 404; + $this->title = LAN_ERROR_7; + $this->caption = LAN_ERROR_45; + $this->content = LAN_ERROR_21 . '
' . LAN_ERROR_9; + } + + /** + * Set a "Internal server error" error page. + */ + private function setPageInternalServerError() + { + header('HTTP/1.1 500 Internal Server Error', true, 500); + + $this->template = 500; + $this->title = LAN_ERROR_10; + $this->caption = LAN_ERROR_14; + $this->content = LAN_ERROR_11 . '
' . LAN_ERROR_12; + } + + /** + * Set a "Unknown" error page. + */ + private function setPageUnknown() + { + header('HTTP/1.1 501 Not Implemented', true, 501); + + $errorQuery = htmlentities($_SERVER['QUERY_STRING']); + + $this->template = 'DEFAULT'; + $this->title = LAN_ERROR_13 . ' (' . $errorQuery . ')'; + $this->caption = LAN_ERROR_14; + $this->content = LAN_ERROR_15; + } + + /** + * Set error page. + * + * @param int $status_code + * The HTTP status code to use for the error page, defaults to 404. + * Status codes are defined in RFC 2616. + * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html + */ + public function set($status_code = 404) + { + switch($status_code) + { + case 400: + $this->setPageBadRequest(); + break; + + case 401: + $this->setPageUnauthorized(); + break; + + case 403: + $this->setPageForbidden(); + break; + + case 404: + $this->setPageNotFound(); + break; + + case 500: + $this->setPageInternalServerError(); + break; + + default: + $this->setPageUnknown(); + break; + } + } + + /** + * Renders and delivers an error page to the browser. + * + * @param int $status_code + * The HTTP status code to use for the error page, defaults to 404. + * Status codes are defined in RFC 2616. + * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html + */ + public function render($status_code = null) + { + if(!defined('ERR_PAGE_ACTIVE')) + { + define("ERR_PAGE_ACTIVE", true); + } + + if($status_code) + { + $this->set($status_code); + } + + $tp = e107::getParser(); + $tpl = e107::getCoreTemplate('error', $this->template); + $sc = e107::getScBatch('error'); + + $sc->setVars(array( + 'title' => LAN_ERROR_TITLE, // Oops! + 'subtitle' => $this->title, + 'caption' => $this->caption, + 'content' => $this->content, + )); + + $body = $tp->parseTemplate($tpl, true, $sc); + e107::getRender()->tablerender('', $body); + } + +} diff --git a/error.php b/error.php index 816b4d9e3..f745fa60f 100644 --- a/error.php +++ b/error.php @@ -21,15 +21,6 @@ $_E107 = array( require_once("class2.php"); -// Start session if required. -if(!session_id()) -{ - session_start(); -} - -// Include language file. -e107::coreLan('error'); - /** * Class error_front. @@ -63,92 +54,29 @@ class error_front switch($this->errorNumber) { case 400: - header('HTTP/1.1 400 Bad Request'); - - $subtitle = LAN_ERROR_35; // Error 400 - Bad Request - $caption = LAN_ERROR_45; - $content = LAN_ERROR_36 . '
' . LAN_ERROR_3; + e107::getError()->render(400); break; case 401: - header('HTTP/1.1 401 Unauthorized'); - - $subtitle = LAN_ERROR_1; // Error 401 - Authentication Failed - $caption = LAN_ERROR_45; - $content = LAN_ERROR_2 . '
' . LAN_ERROR_3; + e107::getError()->render(401); break; case 403: - header('HTTP/1.1 403 Forbidden'); - - $subtitle = LAN_ERROR_4; // Error 403 - Access forbidden - $caption = LAN_ERROR_45; - $content = LAN_ERROR_5 . '
' . LAN_ERROR_6 . '

' . LAN_ERROR_2; + e107::getError()->render(403); break; case 404: - header('HTTP/1.1 404 Not Found'); - - $subtitle = LAN_ERROR_7; // Error 404 - Document Not Found - $caption = LAN_ERROR_45; - $content = LAN_ERROR_21 . '
' . LAN_ERROR_9; - - $errFrom = isset($_SESSION['e107_http_referer']) ? $_SESSION['e107_http_referer'] : $_SERVER['HTTP_REFERER']; - - if(strlen($errFrom)) - { - $content .= '
'; - $content .= '
'; - $content .= LAN_ERROR_23 . ' ' . $errFrom . ' '; - $content .= LAN_ERROR_24; - } - + e107::getError()->render(404); break; case 500: - header('HTTP/1.1 500 Internal Server Error'); - - $subtitle = LAN_ERROR_10; // Error 500 - Internal server error - $caption = LAN_ERROR_14; - $content = LAN_ERROR_11 . '
' . LAN_ERROR_12; - break; - - case 999: - if(!defset('E107_DEBUG_LEVEL', false)) - { - e107::redirect(); - } - - $this->errorNumber = 'DEFAULT'; // Use default template. - - $subtitle = LAN_ERROR_33; - $caption = LAN_ERROR_14; - $content = '
' . print_r($_SERVER) . print_r($_REQUEST) . '
'; + e107::getError()->render(500); break; default: - $this->errorNumber = 'DEFAULT'; // Use default template. - $errorQuery = htmlentities($_SERVER['QUERY_STRING']); - - $subtitle = LAN_ERROR_13 . ' (' . $errorQuery . ')'; // Error - Unknown - $caption = LAN_ERROR_14; - $content = LAN_ERROR_15; + e107::getError()->render('unknown'); break; } - - $tp = e107::getParser(); - $tpl = e107::getCoreTemplate('error', $this->errorNumber); - $sc = e107::getScBatch('error'); - - $sc->setVars(array( - 'title' => LAN_ERROR_TITLE, - 'subtitle' => $subtitle, - 'caption' => $caption, - 'content' => $content, - )); - - $body = $tp->parseTemplate($tpl, true, $sc); - e107::getRender()->tablerender('', $body); } }