1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 21:57:51 +02:00

Error 403/404 templates;

Not Found redirect - set 404 error code;
404/403 actions - send proper HTTP status code;
Front controller now sets render mode to
module-controller-action by default (override from within individual
actions via setRenderMod() still possible)
This commit is contained in:
SecretR
2013-10-23 17:39:44 +03:00
parent c3f9d98898
commit f60b8f6e81
3 changed files with 110 additions and 20 deletions

View File

@@ -18,34 +18,62 @@ class core_system_error_controller extends eController
e107::coreLan('error'); e107::coreLan('error');
} }
/**
* Alias
*/
public function action404()
{
$this->_forward('notfound');
}
public function actionNotfound() public function actionNotfound()
{ {
$this->getResponse()
->setRenderMod('error404')
->addHeader('HTTP/1.0 404 Not Found');
$this->addTitle(LAN_ERROR_7); $this->addTitle(LAN_ERROR_7);
//var_dump($this->getRequest()->getRouteHistory()); $template = e107::getCoreTemplate('error', 404);
$errorText = "<img src='".e_IMAGE_ABS."generic/warning.png' alt='".LAN_ERROR_37."' /> ".LAN_ERROR_21.'<br />'.LAN_ERROR_9."<br /><br />";
if (strlen(vartrue($errFrom))) $errorText .= LAN_ERROR_23." <a href='{$errFrom}' rel='external'>{$errFrom}</a> ".LAN_ERROR_24." -- ".LAN_ERROR_19."<br /><br />";
$vars = new e_vars(array(
'siteUrl' => SITEURL,
'searchUrl' => e107::getUrl()->create('search'),
));
$errorText .= "<h3>".LAN_ERROR_45."</h3>"; $body = e107::getParser()->parseTemplate($template['start'].$template['body'].$template['end'], true, null, $vars);
if(vartrue($errReturnTo))
{ $this->addBody($body);
foreach ($errReturnTo as $url => $label)
{
$errorText .= "<a href='{$url}'>".$label."</a><br />";
} }
$errorText .= '<br />';
/**
* Alias
*/
public function action403()
{
$this->_forward('forbidden');
} }
$url = e107::getUrl();
$errorText .= "<a href='".SITEURL."'>".LAN_ERROR_20."</a><br />"; public function actionForbidden()
$errorText .= "<a href='".$url->create('search')."'>".LAN_ERROR_22."</a>"; {
$this->getResponse()
->setRenderMod('error403')
->addHeader('HTTP/1.0 403 Forbidden');
$this->addBody($errorText); $this->addTitle(LAN_ERROR_7);
$template = e107::getCoreTemplate('error', 403);
$vars = new e_vars(array(
'siteUrl' => SITEURL,
));
$body = e107::getParser()->parseTemplate($template['start'].$template['body'].$template['end'], true, null, $vars);
$this->addBody($body);
} }
function actionHelloWorld() function actionHelloWorld()
{ {
$this->addTitle('Hello!'); //$this->addTitle('Hello!');
echo 'Hello World'; //echo 'Hello World';
} }
} }

View File

@@ -0,0 +1,47 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2013 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Error Templates
*
* $Id: $
*/
/**
*
* @package e107
* @subpackage e107_templates
* @version $Id$;
*
*/
if (!defined('e107_INIT')) { exit; }
$ERROR_TEMPLATE = array();
$ERROR_TEMPLATE['404']['start'] = '<div class="error-404">';
$ERROR_TEMPLATE['404']['body'] = '
<h3><i class="icon-exclamation-sign alert-danger" title="'.LAN_ERROR_45.'"></i> '.LAN_ERROR_45.'</h3>
<p>
'.LAN_ERROR_21.'<br />'.LAN_ERROR_9.'
</p>
<a href="{siteUrl}">'.LAN_ERROR_20.'</a><br />
<a href="{searchUrl}">'.LAN_ERROR_22.'</a>
';
$ERROR_TEMPLATE['404']['end'] = '</div>';
$ERROR_TEMPLATE['403']['start'] = '<div class="error-403">';
$ERROR_TEMPLATE['403']['body'] = '
<h3><i class="icon-exclamation-sign alert-danger" title="'.LAN_ERROR_4.'"></i> '.LAN_ERROR_4.'</h3>
<p>
'.LAN_ERROR_5.'<br />'.LAN_ERROR_6.'<br /><br />'.LAN_ERROR_2.'
</p>
<a href="{siteUrl}">'.LAN_ERROR_20.'</a><br />
';
$ERROR_TEMPLATE['403']['end'] = '</div>';

View File

@@ -808,7 +808,7 @@ class eRouter
* TODO - user friendly URL ('/system/404') when system config is ready ('/system/404') * TODO - user friendly URL ('/system/404') when system config is ready ('/system/404')
* @var string * @var string
*/ */
public $notFoundUrl = 'system/error/notfound?type=routeError'; public $notFoundUrl = 'system/error/404?type=routeError';
public function __construct() public function __construct()
{ {
@@ -1723,7 +1723,7 @@ class eRouter
{ {
$redirect = $this->assemble($this->notFoundUrl, '', 'encode=0&full=1'); $redirect = $this->assemble($this->notFoundUrl, '', 'encode=0&full=1');
//echo $redirect; exit; //echo $redirect; exit;
e107::getRedirect()->redirect($redirect); e107::getRedirect()->redirect($redirect, true, 404);
} }
} }
} }
@@ -2972,6 +2972,9 @@ class eControllerFront extends eController
// _GET input validation // _GET input validation
$this->validateInput(); $this->validateInput();
// Set Render mode to module-controller-action, override possible within the action
$this->getResponse()->setRenderMod(str_replace('/', '-', $this->getRequest()->getRoute()));
} }
/** /**
@@ -3706,6 +3709,9 @@ class eResponse
$this->_content_type = $typeName; $this->_content_type = $typeName;
} }
/**
* @return eResponse
*/
public function sendContentType() public function sendContentType()
{ {
$ctypeStr = $this->getContentMediaType($this->getContentType()); $ctypeStr = $this->getContentMediaType($this->getContentType());
@@ -3716,6 +3722,15 @@ class eResponse
return $this; return $this;
} }
/**
* @return eResponse
*/
public function addHeader($header, $override = false, $responseCode = null)
{
header($header, $override, $responseCode);
return $this;
}
/** /**
* Append content * Append content
* @param str $body * @param str $body