X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplatal.php;h=7e4476d81d633a28f0f1801264b63a0e31062aa4;hb=084e071cccd36d44ba9a0f02e8aacddebc0223b8;hp=eeafbb91b64991ffb58d7a186ee7c38cfed1c143;hpb=5f6b3a28efe41c038f349fb0b281d9637f7078de;p=platal.git diff --git a/classes/platal.php b/classes/platal.php index eeafbb9..7e4476d 100644 --- a/classes/platal.php +++ b/classes/platal.php @@ -54,9 +54,9 @@ abstract class PlHook return ($this->type & $type) == $type; } - abstract protected function run(PlPage &$page, array $args); + abstract protected function run(PlPage $page, array $args); - public function call(PlPage &$page, array $args) + public function call(PlPage $page, array $args) { global $globals, $session, $platal; if (!$session->checkAuth($this->auth)) { @@ -92,7 +92,7 @@ class PlStdHook extends PlHook $this->callback = $callback; } - protected function run(PlPage &$page, array $args) + protected function run(PlPage $page, array $args) { global $session, $platal; @@ -152,7 +152,7 @@ class PlApiHook extends PlHook return empty($encodedPayload) ? array() : json_decode($encodedPayload, true); } - protected function run(PlPage &$page, array $args) + protected function run(PlPage $page, array $args) { $method = $_SERVER['REQUEST_METHOD']; $encodedPayload = $this->getEncodedPayload($method); @@ -215,7 +215,7 @@ class PlTokenHook extends PlHook $this->callback = $callback; } - protected function run(PlPage &$page, array $args) + protected function run(PlPage $page, array $args) { // Retrieve the user, either from the session (less expensive, as it is // already there), or from the in-path (user, token) pair. @@ -250,7 +250,7 @@ class PlWikiHook extends PlHook parent::__construct($auth, $perms, $type); } - protected function run(PlPage &$page, array $args) + protected function run(PlPage $page, array $args) { return PL_WIKI; } @@ -322,16 +322,18 @@ class PlHookTree $nearest_sdx = 50; $match = null; foreach ($this->children as $path=>$hook) { - $lev = levenshtein($next, $path); - if ($lev <= $nearest_lev - && ($lev < strlen($next) / 2 || strpos($next, $path) !== false - || strpos($path, $next) !== false)) { - $sdx = levenshtein(soundex($next), soundex($path)); - if ($lev == $nearest_lev || $sdx < $nearest_sdx) { - $child = $hook; - $nearest_lev = $lev; - $nearest_sdx = $sdx; - $match = $path; + if ($path) { + $lev = levenshtein($next, $path); + if ($lev <= $nearest_lev + && ($lev < strlen($next) / 2 || strpos($next, $path) !== false + || strpos($path, $next) !== false)) { + $sdx = levenshtein(soundex($next), soundex($path)); + if ($lev == $nearest_lev || $sdx < $nearest_sdx) { + $child = $hook; + $nearest_lev = $lev; + $nearest_sdx = $sdx; + $match = $path; + } } } } @@ -467,7 +469,7 @@ abstract class Platal return $url; } - private function call_hook(PlPage &$page) + private function call_hook(PlPage $page) { $hook = $this->find_hook(); if (empty($hook)) { @@ -483,7 +485,7 @@ abstract class Platal /** Show the authentication form. */ - abstract public function force_login(PlPage& $page); + abstract public function force_login(PlPage $page); public function run() {