1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 04:38:27 +01:00

Introduce e107::setErrorPage() for delivering an error page to the browser.

This commit is contained in:
lonalore 2016-12-15 10:06:54 +01:00
parent d9f3d487f7
commit 2667537fd1
4 changed files with 305 additions and 199 deletions

View File

@ -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 . '<br/>' . LAN_ERROR_6 . '<br/><br/>' . LAN_ERROR_2;
$sc->setVars(array(
'title' => $title,
'subtitle' => $subtitle,
'caption' => $caption,
'content' => $content,
));
$body = $tp->parseTemplate($tpl, true, $sc);
$this->addBody($body);
e107::setErrorPage(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 . '<br/>' . LAN_ERROR_9;
$sc->setVars(array(
'title' => $title,
'subtitle' => $subtitle,
'caption' => $caption,
'content' => $content,
));
$body = $tp->parseTemplate($tpl, true, $sc);
$this->addBody($body);
e107::setErrorPage(404);
}
}

View File

@ -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,53 @@ class e107
}
/**
* Sends error page contents to the browser as HTML.
*
* @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
*
* @return void
*/
public static function setErrorPage($status_code = 404)
{
if(!defined('ERR_PAGE_ACTIVE'))
{
define("ERR_PAGE_ACTIVE", true);
}
$errorPage = self::getSingleton('error_page', true);
switch ($status_code)
{
case 400:
$errorPage->deliverPageBadRequest();
break;
case 401:
$errorPage->deliverPageUnauthorized();
break;
case 403:
$errorPage->deliverPageForbidden();
break;
case 404:
$errorPage->deliverPageNotFound();
break;
case 500:
$errorPage->deliverPageInternalServerError();
break;
default:
$errorPage->deliverPageUnknown();
break;
}
}
/**
* Parses an array into a valid, rawurlencoded query string. This differs from http_build_query() as we need to

View File

@ -0,0 +1,172 @@
<?php
/**
* e107 website system
*
* Copyright (C) 2008-2016 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* @file
* Class for system error pages.
*/
// [e_LANGUAGEDIR]/[e_LANGUAGE]/lan_error.php
e107::lan('core', 'error');
/**
* Class error_page.
*/
class error_page
{
/**
* @var
*/
private $statusCode;
/**
* Constructor.
*
* Use {@link getInstance()}, direct instantiating is not possible for
* signleton objects.
*/
public function __construct()
{
}
/**
* Cloning is not allowed.
*/
private function __clone()
{
}
/**
* @return void
*/
protected function _init()
{
}
/**
* Delivers a "Bad Request" error page to the browser.
*/
public function deliverPageBadRequest()
{
header('HTTP/1.1 400 Bad Request', true, 400);
$title = LAN_ERROR_35; // Error 400 - Bad Request
$caption = LAN_ERROR_45;
$content = LAN_ERROR_36 . '<br/>' . LAN_ERROR_3;
$this->statusCode = 400;
$this->renderPage($title, $caption, $content);
}
/**
* Delivers a "Authentication Failed" error page to the browser.
*/
public function deliverPageUnauthorized()
{
header('HTTP/1.1 401 Unauthorized', true, 401);
$title = LAN_ERROR_1; // Error 401 - Authentication Failed
$caption = LAN_ERROR_45;
$content = LAN_ERROR_2 . '<br/>' . LAN_ERROR_3;
$this->statusCode = 401;
$this->renderPage($title, $caption, $content);
}
/**
* Delivers a "Access forbidden" error page to the browser.
*/
public function deliverPageForbidden()
{
header('HTTP/1.1 403 Forbidden', true, 403);
$title = LAN_ERROR_4; // Error 403 - Access forbidden
$caption = LAN_ERROR_45;
$content = LAN_ERROR_5 . '<br/>' . LAN_ERROR_6 . '<br/><br/>' . LAN_ERROR_2;
$this->statusCode = 403;
$this->renderPage($title, $caption, $content);
}
/**
* Delivers a "Not Found" error page to the browser.
*/
public function deliverPageNotFound()
{
header('HTTP/1.1 404 Not Found', true, 404);
$title = LAN_ERROR_7; // Error 404 - Document Not Found
$caption = LAN_ERROR_45;
$content = LAN_ERROR_21 . '<br/>' . LAN_ERROR_9;
$this->statusCode = 404;
$this->renderPage($title, $caption, $content);
}
/**
* Delivers a "Internal server error" error page to the browser.
*/
public function deliverPageInternalServerError()
{
header('HTTP/1.1 500 Internal Server Error', true, 500);
$title = LAN_ERROR_10; // Error 500 - Internal server error
$caption = LAN_ERROR_14;
$content = LAN_ERROR_11 . '<br/>' . LAN_ERROR_12;
$this->statusCode = 500;
$this->renderPage($title, $caption, $content);
}
/**
* Delivers a "Unknown" error page to the browser.
*/
public function deliverPageUnknown()
{
header('HTTP/1.1 501 Not Implemented', true, 501);
$errorQuery = htmlentities($_SERVER['QUERY_STRING']);
$title = LAN_ERROR_13 . ' (' . $errorQuery . ')'; // Error - Unknown
$caption = LAN_ERROR_14;
$content = LAN_ERROR_15;
$this->statusCode = 'DEFAULT'; // Use default template.
$this->renderPage($title, $caption, $content);
}
/**
* Renders and delivers an error page to the browser.
*
* @param $title
* Page title.
* @param $caption
* Title for info panel.
* @param $content
* Content for info panel.
*/
private function renderPage($title, $caption, $content)
{
$tp = e107::getParser();
$tpl = e107::getCoreTemplate('error', $this->statusCode);
$sc = e107::getScBatch('error');
$sc->setVars(array(
'title' => LAN_ERROR_TITLE, // Oops!
'subtitle' => $title,
'caption' => $caption,
'content' => $content,
));
$body = $tp->parseTemplate($tpl, true, $sc);
e107::getRender()->tablerender('', $body);
}
}

View File

@ -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 . '<br/>' . LAN_ERROR_3;
e107::setErrorPage(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 . '<br/>' . LAN_ERROR_3;
e107::setErrorPage(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 . '<br/>' . LAN_ERROR_6 . '<br/><br/>' . LAN_ERROR_2;
e107::setErrorPage(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 . '<br/>' . LAN_ERROR_9;
$errFrom = isset($_SESSION['e107_http_referer']) ? $_SESSION['e107_http_referer'] : $_SERVER['HTTP_REFERER'];
if(strlen($errFrom))
{
$content .= '<br/>';
$content .= '<br/>';
$content .= LAN_ERROR_23 . ' <a href="' . $errFrom . '" rel="external">' . $errFrom . '</a> ';
$content .= LAN_ERROR_24;
}
e107::setErrorPage(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 . '<br/>' . 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 = '<pre>' . print_r($_SERVER) . print_r($_REQUEST) . '</pre>';
e107::setErrorPage(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::setErrorPage('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);
}
}