Made plat/al php5.3 compliant
authorRiton <henri.jouhaud@polytechnique.org>
Thu, 9 Sep 2010 12:54:30 +0000 (14:54 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 9 Sep 2010 13:01:01 +0000 (15:01 +0200)
- split => preg_split or explode
- handler(&$page) => handler($page)
- abstract static => interface

Signed-off-by: Riton <henri.jouhaud@polytechnique.org>
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/platal.php
classes/pluser.php
include/misc.inc.php
modules/core.php
ut/enginetest.php

index b911828..06be26d 100644 (file)
@@ -267,7 +267,7 @@ abstract class Platal
             $this->mods[$module] = $m = PLModule::factory($module);
             $hooks = $m->handlers();
             foreach ($hooks as $path=>$hook) {
-                $this->hooks->addChild(split('/', $path), $hook);
+                $this->hooks->addChild(explode('/', $path), $hook);
             }
         }
 
@@ -302,7 +302,7 @@ abstract class Platal
 
     protected function find_hook()
     {
-        $p = split('/', $this->path);
+        $p = explode('/', $this->path);
         list($hook, $matched, $remain, $aliased) = $this->hooks->findChild($p);
         if (empty($hook)) {
             return null;
@@ -318,7 +318,7 @@ abstract class Platal
 
     public function near_hook()
     {
-        $p = split('/', $this->path);
+        $p = explode('/', $this->path);
         list($hook, $matched, $remain, $aliased) = $this->hooks->findNearestChild($p);
         if (empty($hook)) {
             return null;
index 3e4418a..187f131 100644 (file)
@@ -32,6 +32,17 @@ class UserNotFoundException extends Exception
     }
 }
 
+interface PlUserInterface
+{
+    public static function _default_user_callback($login, $results);
+
+    /**
+     * Determines if the @p login is an email address, and an email address not
+     * served locally by plat/al.
+     */
+    public static function isForeignEmailAddress($email);
+}
+
 /**
  * Represents an user of plat/al (without any further assumption), with a
  * special focus on always-used properties (identification fields, display name,
@@ -39,7 +50,7 @@ class UserNotFoundException extends Exception
  * NOTE: each implementation of plat/al-code MUST subclass PlUser, and name it
  * 'User'.
  */
-abstract class PlUser
+abstract class PlUser implements PlUserInterface
 {
     /**
      * User data enumerations.
@@ -328,7 +339,7 @@ abstract class PlUser
             if (strlen(trim($logins)) == 0) {
                 return null;
             }
-            $logins = split("[; ,\r\n\|]+", $logins);
+            $logins = preg_split("/[; ,\r\n\|]+/", $logins);
         }
 
         if ($logins) {
@@ -379,14 +390,6 @@ abstract class PlUser
         return;
     }
 
-    abstract public static function _default_user_callback($login, $results);
-
-    /**
-     * Determines if the @p login is an email address, and an email address not
-     * served locally by plat/al.
-     */
-    abstract public static function isForeignEmailAddress($email);
-
     private static function stripBadChars($text)
     {
         return str_replace(array(' ', "'"), array('-', ''),
index c1b8c67..3615bcb 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-function quoted_printable_encode($input, $line_max = 76)
-{
-    $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
-    $eol = "\n";
-    $linebreak = "=0D=0A=\n    ";
-    $escape = "=";
-    $output = "";
+// Use native function if it's available (>= PHP5.3)
+if (!function_exists('quoted_printable_encode')) {
+    function quoted_printable_encode($input, $line_max = 76)
+    {
+        $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
+        $eol = "\n";
+        $linebreak = "=0D=0A=\n    ";
+        $escape = "=";
+        $output = "";
 
-    foreach ($lines as $j => $line) {
-        $linlen = strlen($line);
-        $newline = "";
-        for($i = 0; $i < $linlen; $i++) {
-            $c = $line{$i};
-            $dec = ord($c);
-            if ( ($dec == 32) && ($i == ($linlen - 1)) ) {
-                // convert space at eol only
-                $c = "=20";
-            } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) {
-                // always encode "\t", which is *not* required
-                $c = $escape.strtoupper(sprintf("%02x",$dec));
-            }
-            if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
-                $output .= $newline.$escape.$eol;
-                $newline = "    ";
-            }
-            $newline .= $c;
-        } // end of for
-        $output .= $newline;
-        if ($j<count($lines)-1) $output .= $linebreak;
+        foreach ($lines as $j => $line) {
+            $linlen = strlen($line);
+            $newline = "";
+            for($i = 0; $i < $linlen; $i++) {
+                $c = $line{$i};
+                $dec = ord($c);
+                if ( ($dec == 32) && ($i == ($linlen - 1)) ) {
+                    // convert space at eol only
+                    $c = "=20";
+                } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) {
+                    // always encode "\t", which is *not* required
+                    $c = $escape.strtoupper(sprintf("%02x",$dec));
+                }
+                if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
+                    $output .= $newline.$escape.$eol;
+                    $newline = "    ";
+                }
+                $newline .= $c;
+            } // end of for
+            $output .= $newline;
+            if ($j<count($lines)-1) $output .= $linebreak;
+        }
+        return trim($output);
     }
-    return trim($output);
 }
 
 /** genere une chaine aleatoire de 22 caracteres ou moins
index 6d43027..1d2dcc4 100644 (file)
@@ -43,13 +43,13 @@ class CoreModule extends PLModule
         );
     }
 
-    function handler_valid(&$page)
+    function handler_valid($page)
     {
         readfile($page->compile_dir.'/valid.html');
         exit;
     }
 
-    function handler_403(&$page)
+    function handler_403($page)
     {
         global $globals;
         header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
@@ -57,7 +57,7 @@ class CoreModule extends PLModule
         $page->coreTpl('403.tpl');
     }
 
-    function handler_404(&$page)
+    function handler_404($page)
     {
         global $globals, $platal;
         header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
@@ -66,7 +66,7 @@ class CoreModule extends PLModule
         $page->trigError('Cette page n\'existe pas !!!');
     }
 
-    function handler_login(&$page)
+    function handler_login($page)
     {
         $allkeys = func_get_args();
         unset($allkeys[0]);
@@ -74,7 +74,7 @@ class CoreModule extends PLModule
         pl_redirect($url);
     }
 
-    function handler_favicon(&$page)
+    function handler_favicon($page)
     {
         global $globals;
         pl_cached_content_headers("image/x-icon");
@@ -82,7 +82,7 @@ class CoreModule extends PLModule
         exit;
     }
 
-    function handler_robotstxt(&$page)
+    function handler_robotstxt($page)
     {
         global $globals;
 
@@ -106,7 +106,7 @@ class CoreModule extends PLModule
         return PL_NOT_FOUND;
     }
 
-    function handler_purge_cache(&$page)
+    function handler_purge_cache($page)
     {
         S::assert_xsrf_token();
 
@@ -116,12 +116,12 @@ class CoreModule extends PLModule
         http_redirect(empty($_SERVER['HTTP_REFERER']) ? './' : $_SERVER['HTTP_REFERER']);
     }
 
-    function handler_kill_sessions(&$page)
+    function handler_kill_sessions($page)
     {
         kill_sessions();
     }
 
-    function handler_bug(&$page)
+    function handler_bug($page)
     {
         global $globals;
 
@@ -163,14 +163,14 @@ class CoreModule extends PLModule
         }
     }
 
-    function handler_wiki_help(&$page, $action = 'title')
+    function handler_wiki_help($page, $action = 'title')
     {
         $page->coreTpl('wiki.help.tpl', SIMPLE);
         $page->assign('wiki_help', MiniWiki::help($action == 'title'));
     }
 
     /// Shared handler for wiki syntax result preview
-    function handler_wiki_preview(&$page, $action = 'title')
+    function handler_wiki_preview($page, $action = 'title')
     {
         pl_content_headers("text/html");
         $text = Env::v('text');
@@ -178,7 +178,7 @@ class CoreModule extends PLModule
         exit;
     }
 
-    function handler_siteerror(&$page) {
+    function handler_siteerror($page) {
         global $globals;
         $page->coreTpl('site_errors.tpl');
         $file = @file_get_contents($globals->spoolroot . '/spool/tmp/site_errors');
index 414588b..d6dd75e 100644 (file)
@@ -127,7 +127,7 @@ class EngineTest extends PlTestCase
         $tree->addChild(array('test', 'hook'), new PlStdHook(array('EngineTest', 'barCallback')));
 
         $page = new TestPage();
-        $p = split('/', $path);
+        $p = explode('/', $path);
         list($hook, $matched, $remain, $aliased) = $tree->findChild($p);
         $matched = join('/', $matched);
         $this->assertEquals($expmatched, $matched);