From 9e3943236a995c98e518d56a5ab8df5f494d116e Mon Sep 17 00:00:00 2001 From: Riton Date: Thu, 9 Sep 2010 14:54:30 +0200 Subject: [PATCH 1/1] Made plat/al php5.3 compliant - split => preg_split or explode - handler(&$page) => handler($page) - abstract static => interface Signed-off-by: Riton Signed-off-by: Florent Bruneau --- classes/platal.php | 6 +++--- classes/pluser.php | 23 +++++++++++--------- include/misc.inc.php | 61 +++++++++++++++++++++++++++------------------------- modules/core.php | 24 ++++++++++----------- ut/enginetest.php | 2 +- 5 files changed, 61 insertions(+), 55 deletions(-) diff --git a/classes/platal.php b/classes/platal.php index b911828..06be26d 100644 --- a/classes/platal.php +++ b/classes/platal.php @@ -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; diff --git a/classes/pluser.php b/classes/pluser.php index 3e4418a..187f131 100644 --- a/classes/pluser.php +++ b/classes/pluser.php @@ -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('-', ''), diff --git a/include/misc.inc.php b/include/misc.inc.php index c1b8c67..3615bcb 100644 --- a/include/misc.inc.php +++ b/include/misc.inc.php @@ -19,37 +19,40 @@ * 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 $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 ($jcompile_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'); diff --git a/ut/enginetest.php b/ut/enginetest.php index 414588b..d6dd75e 100644 --- a/ut/enginetest.php +++ b/ut/enginetest.php @@ -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); -- 2.1.4