1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-16 19:44:09 +02:00

Error page improvement: template support.

This commit is contained in:
lonalore
2016-12-14 15:01:51 +01:00
parent d5f9b9ac5e
commit fb3946ae0a
8 changed files with 498 additions and 216 deletions

View File

@@ -1,102 +1,104 @@
<?php
/*
/**
* e107 website system
*
* Copyright (C) 2008-2011 e107 Inc (e107.org)
* 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)
*
* System error controller
*
* $URL$
* $Id$
*/
* @file
* System error controller.
*/
/**
* Class core_system_error_controller.
*/
class core_system_error_controller extends eController
{
function preAction()
/**
* Pre-action callback, fired only if dispatch status is still true
* and action method is found.
*/
public function preAction()
{
e107::coreLan('error');
}
/**
* Alias
*/
public function action404()
{
$this->_forward('notfound');
}
public function actionNotfound()
{
$this->getResponse()
->setRenderMod('error404')
->addHeader('HTTP/1.0 404 Not Found');
$this->addTitle(LAN_ERROR_7);
$template = e107::getCoreTemplate('error', 404);
$vars = new e_vars(array(
'SITEURL' => SITEURL,
'SEARCHURL' => e107::getUrl()->create('search'),
));
$body = e107::getParser()->parseTemplate(
$this->updateTemplate($template['start']).
$this->updateTemplate($template['body']).
$this->updateTemplate($template['end'])
, true, null, $vars);
$this->addBody($body);
}
/**
* Update template to v2.x spec. ALL CAPS shortcodes only.
* @param $template
* @return mixed
*/
private function updateTemplate($template)
{
$srch = array('{siteUrl}','{searchUrl}');
$repl = array('{SITEURL}','{SEARCHURL}');
return str_replace($srch,$repl,$template);
}
/**
* Alias
* Alias for "Error 403".
*/
public function action403()
{
$this->_forward('forbidden');
}
/**
* Alias for "Error 404".
*/
public function action404()
{
$this->_forward('notfound');
}
/**
* Error 403.
*/
public function actionForbidden()
{
$this->getResponse()
->setRenderMod('error403')
->addHeader('HTTP/1.0 403 Forbidden');
$this->addTitle(LAN_ERROR_7);
$template = e107::getCoreTemplate('error', 403);
$vars = new e_vars(array(
'SITEURL' => SITEURL,
$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 = e107::getParser()->parseTemplate(
$this->updateTemplate($template['start']).
$this->updateTemplate($template['body']).
$this->updateTemplate($template['end'])
, true, null, $vars);
$body = $tp->parseTemplate($tpl, true, $sc);
$this->addBody($body);
}
function actionHelloWorld()
/**
* Error 404.
*/
public function actionNotfound()
{
//$this->addTitle('Hello!');
//echo 'Hello World';
$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);
}
}

View File

@@ -0,0 +1,81 @@
<?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
* Error shortcodes.
*/
if(!defined('e107_INIT'))
{
exit;
}
/**
* Class error_shortcodes.
*/
class error_shortcodes extends e_shortcode
{
/**
* @return mixed
*/
public function sc_error_title()
{
return varset($this->var['title'], '');
}
/**
* @return mixed
*/
public function sc_error_subtitle()
{
return varset($this->var['subtitle'], '');
}
/**
* @return mixed
*/
public function sc_error_caption()
{
return varset($this->var['caption'], '');
}
/**
* @return mixed
*/
public function sc_error_content()
{
return varset($this->var['content'], '');
}
/**
* @return string
*/
public function sc_error_link_home()
{
$icon = e107::getParser()->toGlyph('fa-home');
$url = SITEURL;
return '<a href="' . $url . '" class="btn btn-primary">' . $icon . ' ' . LAN_ERROR_20 . '</a>';
}
/**
* @return string
*/
public function sc_error_link_search()
{
$icon = e107::getParser()->toGlyph('fa-search');
$url = e107::getUrl()->create('search');
return '<a href="' . $url . '" class="btn btn-default">' . $icon . ' ' . LAN_ERROR_22 . '</a>';
}
}

View File

@@ -1,47 +1,187 @@
<?php
/*
/**
* e107 website system
*
* Copyright (C) 2008-2013 e107 Inc (e107.org)
* 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)
*
* Error Templates
*
* $Id: $
* @file
* Error templates.
*/
/**
*
* @package e107
* @subpackage e107_templates
* @version $Id$;
*
*/
if (!defined('e107_INIT')) { exit; }
if(!defined('e107_INIT'))
{
exit;
}
$ERROR_TEMPLATE = array();
$ERROR_TEMPLATE['404']['start'] = '<div class="error-404 alert-danger">';
$ERROR_TEMPLATE['404']['body'] = '
<h3><i class="icon-exclamation-sign" 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>
/**
* 400 Bad Request.
*/
$ERROR_TEMPLATE['400'] = '
<h1 class="text-center">
<strong>{ERROR_TITLE}</strong>
</h1>
<h2 class="text-center">
{ERROR_SUBTITLE}
</h2>
<br/>
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
{ERROR_CAPTION}
</div>
<div class="panel-body">
{ERROR_CONTENT}
</div>
</div>
</div>
<br/>
<div class="error-actions text-center">
{ERROR_LINK_HOME}
</div>
<br/>
';
$ERROR_TEMPLATE['404']['end'] = '</div>';
$ERROR_TEMPLATE['403']['start'] = '<div class="error-403 alert-danger">';
$ERROR_TEMPLATE['403']['body'] = '
<h3><i class="icon-exclamation-sign" 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 />
/**
* 401 Unauthorized.
*/
$ERROR_TEMPLATE['401'] = '
<h1 class="text-center">
<strong>{ERROR_TITLE}</strong>
</h1>
<h2 class="text-center">
{ERROR_SUBTITLE}
</h2>
<br/>
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
{ERROR_CAPTION}
</div>
<div class="panel-body">
{ERROR_CONTENT}
</div>
</div>
</div>
<br/>
<div class="error-actions text-center">
{ERROR_LINK_HOME}
</div>
<br/>
';
$ERROR_TEMPLATE['403']['end'] = '</div>';
/**
* 403 Forbidden.
*/
$ERROR_TEMPLATE['403'] = '
<h1 class="text-center">
<strong>{ERROR_TITLE}</strong>
</h1>
<h2 class="text-center">
{ERROR_SUBTITLE}
</h2>
<br/>
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
{ERROR_CAPTION}
</div>
<div class="panel-body">
{ERROR_CONTENT}
</div>
</div>
</div>
<br/>
<div class="error-actions text-center">
{ERROR_LINK_HOME}
</div>
<br/>
';
/**
* 404 Not Found.
*/
$ERROR_TEMPLATE['404'] = '
<h1 class="text-center">
<strong>{ERROR_TITLE}</strong>
</h1>
<h2 class="text-center">
{ERROR_SUBTITLE}
</h2>
<br/>
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
{ERROR_CAPTION}
</div>
<div class="panel-body">
{ERROR_CONTENT}
</div>
</div>
</div>
<br/>
<div class="error-actions text-center">
{ERROR_LINK_HOME} {ERROR_LINK_SEARCH}
</div>
<br/>
';
/**
* 500 Internal server error.
*/
$ERROR_TEMPLATE['500'] = '
<h1 class="text-center">
<strong>{ERROR_TITLE}</strong>
</h1>
<h2 class="text-center">
{ERROR_SUBTITLE}
</h2>
<br/>
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
{ERROR_CAPTION}
</div>
<div class="panel-body">
{ERROR_CONTENT}
</div>
</div>
</div>
<br/>
<div class="error-actions text-center">
{ERROR_LINK_HOME}
</div>
<br/>
';
/**
* Default error page.
*/
$ERROR_TEMPLATE['DEFAULT'] = '
<h1 class="text-center">
<strong>{ERROR_TITLE}</strong>
</h1>
<h2 class="text-center">
{ERROR_SUBTITLE}
</h2>
<br/>
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
{ERROR_CAPTION}
</div>
<div class="panel-body">
{ERROR_CONTENT}
</div>
</div>
</div>
<br/>
<div class="error-actions text-center">
{ERROR_LINK_HOME}
</div>
<br/>
';

View File

@@ -42,7 +42,7 @@ class core_system_rewrite_url extends eUrlConfig
'name' => LAN_EURL_CORE_SYSTEM, // Module name
'label' => LAN_EURL_SYSTEM_REWRITE_LABEL, // Current profile name
'description' => LAN_EURL_SYSTEM_REWRITE_DESCR, //
'examples' => array("{SITEURL}system/error404")
'examples' => array("{SITEURL}system/error/404")
),
'form' => array(), // Under construction - additional configuration options
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity