From 6995a9b92e68cffcf7a8375080f9e5a210acf0af Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Sun, 1 Oct 2006 11:54:56 +0000 Subject: [PATCH] use delayed error reporting, to avoid screwing the page when an error occur. fix most of the php5-related issues with static calls e.g. git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@935 839d8a87-29fc-0310-9880-83ba4fa771e5 --- classes/env.php | 96 ++++++++++++++++++++++---------------------- classes/platalpage.php | 9 +++-- classes/plmodule.php | 2 +- classes/s.php | 3 +- classes/session.php | 20 +++++---- classes/xdb.php | 42 +++++++++---------- classes/xnet.php | 2 - htdocs/css/openweb.css | 9 +++++ include/platal.inc.php | 40 +++++++++++++++++- include/xnet/session.inc.php | 14 +++---- include/xorg/session.inc.php | 16 ++++---- modules/payment.php | 4 +- 12 files changed, 151 insertions(+), 106 deletions(-) diff --git a/classes/env.php b/classes/env.php index 23ebd50..7e5212a 100644 --- a/classes/env.php +++ b/classes/env.php @@ -21,49 +21,49 @@ class Env { - // {{{ function _get + // {{{ public static function _get - function _get($key, $default) + public static function _get($key, $default) { return isset($_REQUEST[$key]) ? $_REQUEST[$key] : $default; } // }}} - // {{{ function has + // {{{ public static function has - function has($key) + public static function has($key) { return isset($_REQUEST[$key]); } // }}} - // {{{ function kill + // {{{ public static function kill - function kill($key) + public static function kill($key) { unset($_REQUEST[$key]); } // }}} - // {{{ function v + // {{{ public static function v - function v($key, $default = null) + public static function v($key, $default = null) { return Env::_get($key, $default); } // }}} - // {{{ function b + // {{{ public static function b - function b($key, $default = false) + public static function b($key, $default = false) { return (bool)Env::_get($key, $default); } // }}} - // {{{ function i + // {{{ public static function i - function i($key, $default = 0) + public static function i($key, $default = 0) { $i = Env::_get($key, $default); return is_numeric($i) ? intval($i) : $default; @@ -75,49 +75,49 @@ class Env class Post { - // {{{ function _get + // {{{ public static function _get - function _get($key, $default) + public static function _get($key, $default) { return isset($_POST[$key]) ? $_POST[$key] : $default; } // }}} - // {{{ function has + // {{{ public static function has - function has($key) + public static function has($key) { return isset($_POST[$key]); } // }}} - // {{{ function kill + // {{{ public static function kill - function kill($key) + public static function kill($key) { unset($_POST[$key]); } // }}} - // {{{ function v + // {{{ public static function v - function v($key, $default = null) + public static function v($key, $default = null) { return Post::_get($key, $default); } // }}} - // {{{ function b + // {{{ public static function b - function b($key, $default = false) + public static function b($key, $default = false) { return (bool)Post::_get($key, $default); } // }}} - // {{{ function i + // {{{ public static function i - function i($key, $default = 0) + public static function i($key, $default = 0) { $i = Post::_get($key, $default); return is_numeric($i) ? intval($i) : $default; @@ -128,49 +128,49 @@ class Post class Get { - // {{{ function _get + // {{{ public static function _get - function _get($key, $default) + public static function _get($key, $default) { return isset($_GET[$key]) ? $_GET[$key] : $default; } // }}} - // {{{ function has + // {{{ public static function has - function has($key) + public static function has($key) { return isset($_GET[$key]); } // }}} - // {{{ function kill + // {{{ public static function kill - function kill($key) + public static function kill($key) { unset($_GET[$key]); } // }}} - // {{{ function v + // {{{ public static function v - function v($key, $default = null) + public static function v($key, $default = null) { return Get::_get($key, $default); } // }}} - // {{{ function b + // {{{ public static function b - function b($key, $default = false) + public static function b($key, $default = false) { return (bool)Get::_get($key, $default); } // }}} - // {{{ function i + // {{{ public static function i - function i($key, $default = 0) + public static function i($key, $default = 0) { $i = Get::_get($key, $default); return is_numeric($i) ? intval($i) : $default; @@ -181,49 +181,49 @@ class Get class Cookie { - // {{{ function _get + // {{{ public static function _get - function _get($key, $default) + public static function _get($key, $default) { return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default; } // }}} - // {{{ function has + // {{{ public static function has - function has($key) + public static function has($key) { return isset($_COOKIE[$key]); } // }}} - // {{{ function kill + // {{{ public static function kill - function kill($key) + public static function kill($key) { unset($_COOKIE[$key]); } // }}} - // {{{ function v + // {{{ public static function v - function v($key, $default = null) + public static function v($key, $default = null) { return Cookie::_get($key, $default); } // }}} - // {{{ function b + // {{{ public static function b - function b($key, $default = false) + public static function b($key, $default = false) { return (bool)Cookie::_get($key, $default); } // }}} - // {{{ function i + // {{{ public static function i - function i($key, $default = 0) + public static function i($key, $default = 0) { $i = Cookie::_get($key, $default); return is_numeric($i) ? intval($i) : $default; diff --git a/classes/platalpage.php b/classes/platalpage.php index 63add7e..1f20ad6 100644 --- a/classes/platalpage.php +++ b/classes/platalpage.php @@ -77,12 +77,13 @@ class PlatalPage extends Smarty session_write_close(); - $this->assign("xorg_errors", $this->_errors); - $this->assign("xorg_failure", $this->_failure); + $this->assign('xorg_errors', $this->_errors); + $this->assign('xorg_failure', $this->_failure); $this->assign('globals', $globals); switch ($this->_page_type) { case NO_SKIN: + error_reporting(0); $this->display($this->_tpl); exit; @@ -94,6 +95,7 @@ class PlatalPage extends Smarty } if (!$globals->debug) { + error_reporting(0); $this->display($skin); exit; } @@ -103,8 +105,9 @@ class PlatalPage extends Smarty } $this->assign('validate', true); + error_reporting(0); $result = $this->fetch($skin); - $ttime .= sprintf('Temps total: %.02fs
', microtime_float() - $TIME_BEGIN); + $ttime = sprintf('Temps total: %.02fs
', microtime_float() - $TIME_BEGIN); $replc = "VALIDATION HTML INACTIVE
"; if ($globals->debug & 2) { diff --git a/classes/plmodule.php b/classes/plmodule.php index af4de8f..ed4b07f 100644 --- a/classes/plmodule.php +++ b/classes/plmodule.php @@ -33,7 +33,7 @@ class PLModule /* static functions */ - function factory($modname) + public static function factory($modname) { $mod_path = dirname(__FILE__).'/../modules/'.strtolower($modname).'.php'; $class = ucfirst($modname).'Module'; diff --git a/classes/s.php b/classes/s.php index 8ad9826..c2a10e8 100644 --- a/classes/s.php +++ b/classes/s.php @@ -19,6 +19,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -class S extends Session { } +class S extends Session { +} ?> diff --git a/classes/session.php b/classes/session.php index 6052ec6..d42c8eb 100644 --- a/classes/session.php +++ b/classes/session.php @@ -23,7 +23,7 @@ require_once 'diogenes/diogenes.misc.inc.php'; class Session { - function init() + public static function init() { @session_start(); if (empty($_SESSION['challenge'])) { @@ -31,46 +31,44 @@ class Session } } - function destroy() + public static function destroy() { @session_destroy(); unset($_SESSION); } - - - function has($key) + public static function has($key) { return isset($_SESSION[$key]); } - function kill($key) + public static function kill($key) { unset($_SESSION[$key]); } - function v($key, $default = null) + public static function v($key, $default = null) { return isset($_SESSION[$key]) ? $_SESSION[$key] : $default; } - function i($key, $default = 0) + public static function i($key, $default = 0) { $i = Session::v($key, $default); return is_numeric($i) ? intval($i) : $default; } - function has_perms() + public static function has_perms() { return Session::logged() && Session::v('perms') == PERMS_ADMIN; } - function logged() + public static function logged() { return Session::v('auth', AUTH_PUBLIC) >= AUTH_COOKIE; } - function identified() + public static function identified() { return Session::v('auth', AUTH_PUBLIC) >= AUTH_MDP; } diff --git a/classes/xdb.php b/classes/xdb.php index 70b1f24..958b3e2 100644 --- a/classes/xdb.php +++ b/classes/xdb.php @@ -23,18 +23,18 @@ class XDB { var $_trace_data = array(); - // {{{ function _prepare + // {{{ public static function _prepare - function _prepare($args) { + public static function _prepare($args) { $query = array_map(Array('XDB', '_db_escape'), $args); $query[0] = str_replace('{?}', '%s', str_replace('%', '%%', $args[0])); return call_user_func_array('sprintf', $query); } // }}} - // {{{ function _reformatQuery + // {{{ public static function _reformatQuery - function _reformatQuery($query) + public static function _reformatQuery($query) { $query = preg_split("/\n\\s*/", $query); $length = 0; @@ -59,9 +59,9 @@ class XDB } // }}} - // {{{ function _query + // {{{ public static function _query - function _query($query) { + public static function _query($query) { global $globals; if ($globals->debug & 1) { @@ -88,49 +88,49 @@ class XDB } // }}} - // {{{ function query + // {{{ public static function query - function &query() + public static function query() { return new XOrgDBResult(XDB::_prepare(func_get_args())); } // }}} - // {{{ function execute() + // {{{ public static function execute() - function execute() + public static function execute() { return XDB::_query(XDB::_prepare(func_get_args())); } // }}} - // {{{ function iterator() + // {{{ public static function iterator() - function &iterator() + public static function iterator() { return new XOrgDBIterator(XDB::_prepare(func_get_args())); } // }}} - // {{{ function iterRow() + // {{{ public static function iterRow() - function &iterRow() + public static function iterRow() { return new XOrgDBIterator(XDB::_prepare(func_get_args()), MYSQL_NUM); } // }}} - // {{{ function insertId() + // {{{ public static function insertId() - function insertId() + public static function insertId() { return mysql_insert_id(); } // }}} - // {{{ function _db_escape + // {{{ public static function _db_escape - function _db_escape($var) + public static function _db_escape($var) { switch (gettype($var)) { case 'boolean': @@ -158,9 +158,9 @@ class XDB // }}} - function trace_format(&$page, $template = 'database-debug.tpl') { - $page->assign('trace_data', $GLOBALS['XDB::trace_data']); - $page->assign('db_error', $GLOBALS['XDB::error']); + public static function trace_format(&$page, $template = 'database-debug.tpl') { + $page->assign('trace_data', @$GLOBALS['XDB::trace_data']); + $page->assign('db_error', @$GLOBALS['XDB::error']); return $page->fetch($template); } } diff --git a/classes/xnet.php b/classes/xnet.php index 3d5dbb1..c29ec14 100644 --- a/classes/xnet.php +++ b/classes/xnet.php @@ -19,8 +19,6 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -require_once dirname(__FILE__).'/Platal.php'; - class Xnet extends Platal { function Xnet() diff --git a/htdocs/css/openweb.css b/htdocs/css/openweb.css index b1fb751..f0b689b 100644 --- a/htdocs/css/openweb.css +++ b/htdocs/css/openweb.css @@ -447,6 +447,15 @@ div.adresse div.titre { color: purple; } [ choix de classes faites par le skinneur *******************************************************************************/ +.phperror { + color: red; + background: white; + margin: 2px auto; + padding: 4px 2px; + border: 1px solid black; + width: 80%; +} + #dev { width: auto; text-align: center; diff --git a/include/platal.inc.php b/include/platal.inc.php index 6a8ae61..bc09f8e 100644 --- a/include/platal.inc.php +++ b/include/platal.inc.php @@ -38,12 +38,48 @@ define('SKINNED', 0); define('SIMPLE', 1); define('NO_SKIN', 2); -require dirname(dirname(__FILE__)).'/classes/env.php'; - function __autoload($cls) { @include dirname(dirname(__FILE__)).'/classes/'.strtolower($cls).'.php'; } +__autoload('Env'); + +function pl_error_handler($errno, $errstr, $errfile, $errline) +{ + if (!error_reporting()) + return; + + $errortype = array ( + E_ERROR => "Error", + E_WARNING => "Warning", + E_PARSE => "Parsing Error", + E_NOTICE => "Notice", + E_CORE_ERROR => "Core Error", + E_CORE_WARNING => "Core Warning", + E_COMPILE_ERROR => "Compile Error", + E_COMPILE_WARNING => "Compile Warning", + E_USER_ERROR => "User Error", + E_USER_WARNING => "User Warning", + E_USER_NOTICE => "User Notice", + E_STRICT => "Runtime Notice" + ); + + $errstr = htmlentities($errstr); + $GLOBALS['pl_errors'][] = + "
". + "{$errortype[$errno]} $errstr
". + "$errfile : $errline". + "
"; +} + +function pl_print_errors() +{ + print join("\n", $GLOBALS['pl_errors']); +} + +set_error_handler('pl_error_handler', E_ALL | E_STRICT); +register_shutdown_function('pl_print_errors'); + function pl_url($path, $query = null, $fragment = null) { diff --git a/include/xnet/session.inc.php b/include/xnet/session.inc.php index ffcd6fd..7fcb613 100644 --- a/include/xnet/session.inc.php +++ b/include/xnet/session.inc.php @@ -23,7 +23,7 @@ class XnetSession { // {{{ function init - function init() { + public static function init() { global $globals; S::init(); @@ -44,21 +44,21 @@ class XnetSession } // }}} - // {{{ function destroy() + // {{{ public static function destroy() - function destroy() { + public static function destroy() { S::destroy(); XnetSession::init(); } // }}} - // {{{ function doAuth() + // {{{ public static function doAuth() /** Try to do an authentication. * * @param page the calling page (by reference) */ - function doAuth() + public static function doAuth() { if (S::identified()) { // ok, c'est bon, on n'a rien à faire return true; @@ -74,14 +74,14 @@ class XnetSession // }}} // {{{ doAuthCookie - function doAuthCookie() { + public static function doAuthCookie() { return XnetSession::doAuth(); } // }}} // {{{ doAuthX - function doAuthX() { + public static function doAuthX() { global $globals, $page; if (md5('1'.S::v('challenge').$globals->xnet->secret.Get::i('uid').'1') != Get::v('auth')) { diff --git a/include/xorg/session.inc.php b/include/xorg/session.inc.php index c121ba2..8d73093 100644 --- a/include/xorg/session.inc.php +++ b/include/xorg/session.inc.php @@ -21,9 +21,9 @@ class XorgSession { - // {{{ function init + // {{{ public static function init - function init() { + public static function init() { S::init(); if (!S::has('uid')) { try_cookie(); @@ -31,17 +31,17 @@ class XorgSession } // }}} - // {{{ function destroy() + // {{{ public static function destroy() - function destroy() { + public static function destroy() { S::destroy(); XorgSession::init(); } // }}} - // {{{ function doAuth() + // {{{ public static function doAuth() - function doAuth($new_name = false) + public static function doAuth($new_name = false) { global $globals; if (S::identified()) { // ok, c'est bon, on n'a rien à faire @@ -135,13 +135,13 @@ class XorgSession } // }}} - // {{{ function doAuthCookie() + // {{{ public static function doAuthCookie() /** Try to do a cookie-based authentication. * * @param page the calling page (by reference) */ - function doAuthCookie() + public static function doAuthCookie() { if (S::logged()) { return true; diff --git a/modules/payment.php b/modules/payment.php index 137bbec..03fc95d 100644 --- a/modules/payment.php +++ b/modules/payment.php @@ -77,8 +77,8 @@ class PaymentModule extends PLModule { return array( 'payment' => $this->make_hook('payment', AUTH_MDP), - 'payment/cyber_return' => $this->make_hook('cyber_return', AUTH_PUB), - 'payment/paypal_return' => $this->make_hook('paypal_return', AUTH_PUB), + 'payment/cyber_return' => $this->make_hook('cyber_return', AUTH_PUBLIC), + 'payment/paypal_return' => $this->make_hook('paypal_return', AUTH_PUBLIC), 'admin/payments' => $this->make_hook('admin', AUTH_MDP, 'admin'), ); } -- 2.1.4