From 1547b0f6051a721ef80013d99f997dac1f819f84 Mon Sep 17 00:00:00 2001 From: Vincent Zanotti Date: Mon, 3 Jan 2011 17:51:31 +0100 Subject: [PATCH] Creates a new plat/al error code for invalid request. This is intended to be used for requests where the URL format, or the input is invalid (for instance non JSON-encoded input for the API). Signed-off-by: Vincent Zanotti --- classes/platal.php | 17 ++++++++++++----- modules/core.php | 17 ++++++++++++----- templates/{403.tpl => 40x.tpl} | 0 3 files changed, 24 insertions(+), 10 deletions(-) rename templates/{403.tpl => 40x.tpl} (100%) diff --git a/classes/platal.php b/classes/platal.php index 755cf67..cbd9870 100644 --- a/classes/platal.php +++ b/classes/platal.php @@ -19,11 +19,14 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -define('PL_DO_AUTH', 300); -define('PL_FORBIDDEN', 403); -define('PL_NOT_FOUND', 404); -define('PL_WIKI', 500); -define('PL_JSON', 501); +// Return values for handlers and hooks. This defines the behavior of both the +// plat/al engine, and the invidivual hooks. +define('PL_DO_AUTH', 300); // User should be redirected to the login page. +define('PL_BAD_REQUEST', 400); // Request is not valid, and could not be interpreted. +define('PL_FORBIDDEN', 403); // User is not allowed to view page (auth or permission error). +define('PL_NOT_FOUND', 404); // Page doesn't not exist. Engine will try to offer suggestions. +define('PL_WIKI', 500); // Page is a wiki page, plat/al engine should yield to the wiki engine. +define('PL_JSON', 501); // Page is valid, but result should be JSON-encoded, not HTML-encoded. abstract class PlHook { @@ -421,6 +424,10 @@ abstract class Platal $page->assign('platal', $this); $res = $this->call_hook($page); switch ($res) { + case PL_BAD_REQUEST: + $this->mods['core']->handler_400($page); + break; + case PL_FORBIDDEN: $this->mods['core']->handler_403($page); break; diff --git a/modules/core.php b/modules/core.php index 6557ca4..a109a4c 100644 --- a/modules/core.php +++ b/modules/core.php @@ -24,6 +24,7 @@ class CoreModule extends PLModule function handlers() { return array( + '400' => $this->make_hook('400', AUTH_PUBLIC), '403' => $this->make_hook('403', AUTH_PUBLIC), '404' => $this->make_hook('404', AUTH_PUBLIC), 'login' => $this->make_hook('login', AUTH_COOKIE), @@ -51,17 +52,23 @@ class CoreModule extends PLModule exit; } - function handler_403($page) + function handler_400(PlPage& $page) + { + header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request'); + $page->coreTpl('40x.tpl'); + $page->trigError('Ta requête est invalide.'); + } + + function handler_403(PlPage& $page) { - global $globals; header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); + $page->coreTpl('40x.tpl'); $page->trigError('Tu n\'as pas les permissions nécessaires pour accéder à cette page.'); - $page->coreTpl('403.tpl'); } - function handler_404($page) + function handler_404(PlPage& $page) { - global $globals, $platal; + global $platal; header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); $page->coreTpl('404.tpl'); $page->assign('near', $platal->near_hook()); diff --git a/templates/403.tpl b/templates/40x.tpl similarity index 100% rename from templates/403.tpl rename to templates/40x.tpl -- 2.1.4