use delayed error reporting, to avoid screwing the page when an error
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 1 Oct 2006 11:54:56 +0000 (11:54 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 1 Oct 2006 11:54:56 +0000 (11:54 +0000)
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

12 files changed:
classes/env.php
classes/platalpage.php
classes/plmodule.php
classes/s.php
classes/session.php
classes/xdb.php
classes/xnet.php
htdocs/css/openweb.css
include/platal.inc.php
include/xnet/session.inc.php
include/xorg/session.inc.php
modules/payment.php

index 23ebd50..7e5212a 100644 (file)
 
 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;
index 63add7e..1f20ad6 100644 (file)
@@ -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<br />', microtime_float() - $TIME_BEGIN);
+        $ttime  = sprintf('Temps total: %.02fs<br />', microtime_float() - $TIME_BEGIN);
         $replc  = "<span class='erreur'>VALIDATION HTML INACTIVE</span><br />";
 
         if ($globals->debug & 2) {
index af4de8f..ed4b07f 100644 (file)
@@ -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';
index 8ad9826..c2a10e8 100644 (file)
@@ -19,6 +19,7 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-class S extends Session { }
+class S extends Session {
+}
 
 ?>
index 6052ec6..d42c8eb 100644 (file)
@@ -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;
     }
index 70b1f24..958b3e2 100644 (file)
@@ -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);
     }
 }
index 3d5dbb1..c29ec14 100644 (file)
@@ -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()
index b1fb751..f0b689b 100644 (file)
@@ -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;
index 6a8ae61..bc09f8e 100644 (file)
@@ -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'][] =
+        "<div class='phperror'>".
+        "<strong>{$errortype[$errno]}</strong> <em>$errstr</em><br />".
+        "<tt>$errfile : $errline</tt>".
+        "</div>";
+}
+
+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)
 {
index ffcd6fd..7fcb613 100644 (file)
@@ -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')) {
index c121ba2..8d73093 100644 (file)
@@ -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;
index 137bbec..03fc95d 100644 (file)
@@ -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'),
         );
     }