X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2Fplatal.php;h=f766817d9d84497507b9ccec2c12d01b7167d6b6;hb=6c85148b00f7b0b8d4c39393069ddc97b657044a;hp=ee6fcd179ef891c71b8a3aa1c320118235a05c72;hpb=951db8e3a9ab2deb5c45a52201d1a29660502833;p=platal.git diff --git a/classes/platal.php b/classes/platal.php index ee6fcd1..f766817 100644 --- a/classes/platal.php +++ b/classes/platal.php @@ -1,6 +1,6 @@ 24 && $has_end) { + return "#final#"; + } + foreach ($keys as $k) { + if ($k == "#final#") { + continue; + } $lev = levenshtein($key, $k); - if ((is_null($val) || $lev < $val) && $lev < strlen($k)/2) { + if ((!isset($val) || $lev < $val) && $lev <= (strlen($k)*2)/3) { $val = $lev; $best = $k; } } - if (is_null($best) && in_array("#final#", $keys)) { + if (!isset($best) && $has_end) { return "#final#"; } else { return $best; @@ -114,6 +126,9 @@ class Platal { $hooks = array(); foreach ($this->__hooks as $hook=>$handler) { + if (!empty($handler['perms']) && $handler['perms'] != S::v('perms')) { + continue; + } $parts = split('/', $hook); $place =& $hooks; foreach ($parts as $part) { @@ -128,19 +143,18 @@ class Platal $p = split('/', $this->path); $place =& $hooks; $link = ''; - $ended = false; foreach ($p as $k) { - if (!$ended) { + if (!isset($ended)) { $key = $this->find_nearest_key($k, $place); } else { $key = $k; } if ($key == "#final#") { - $key = $k; - $ended = true; if (!array_key_exists($link, $this->__hooks)) { return null; } + $key = $k; + $ended = true; } if (!is_null($key)) { if (!empty($link)) { @@ -152,7 +166,10 @@ class Platal return null; } } - return $link; + if ($link != $this->path) { + return $link; + } + return null; } function call_hook(&$page) @@ -165,10 +182,6 @@ class Platal $args = $this->argv; $args[0] = &$page; - if (strlen($hook['perms']) && $hook['perms'] != Session::v('perms')) { - return PL_FORBIDDEN; - } - if ($hook['auth'] > S::v('auth', AUTH_PUBLIC)) { if ($hook['type'] == DO_AUTH) { global $globals; @@ -181,16 +194,28 @@ class Platal } } - return call_user_func_array($hook['hook'], $args); + if (!empty($hook['perms']) && $hook['perms'] != S::v('perms')) { + return PL_FORBIDDEN; + } + + $val = call_user_func_array($hook['hook'], $args); + if ($val == PL_DO_AUTH) { + // The handler need a better auth with the current args + if (!call_user_func(array($globals->session, 'doAuth'))) { + $this->force_login($page); + } + $val = call_user_func_array($hook['hook'], $args); + } + return $val; } function force_login(&$page) { if (S::logged()) { - $page->changeTpl('password_prompt_logged.tpl'); + $page->changeTpl('core/password_prompt_logged.tpl'); $page->addJsLink('do_challenge_response_logged.js'); } else { - $page->changeTpl('password_prompt.tpl'); + $page->changeTpl('core/password_prompt.tpl'); $page->addJsLink('do_challenge_response.js'); } $page->run(); @@ -200,7 +225,7 @@ class Platal { global $page; - new_skinned_page('index.tpl'); + new_skinned_page('platal/index.tpl'); if (empty($this->path)) { $this->path = 'index';