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)) {
$this->callback = $callback;
}
- protected function run(PlPage &$page, array $args)
+ protected function run(PlPage $page, array $args)
{
global $session, $platal;
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);
$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.
parent::__construct($auth, $perms, $type);
}
- protected function run(PlPage &$page, array $args)
+ protected function run(PlPage $page, array $args)
{
return PL_WIKI;
}
public $aliased = null;
public $children = array();
- public function addChild(array $path, PlHook $hook)
+ public function addChildren(array $hooks)
{
global $platal;
- $next = array_shift($path);
- $alias = null;
- if ($next && $next{0} == '%') {
- $alias = $next;
- $next = $platal->hook_map(substr($next, 1));
- }
- if (!$next) {
- return;
- }
- @$child =& $this->children[$next];
- if (!$child) {
- $child = new PlHookTree();
- $this->children[$next] =& $child;
- $child->aliased = $alias;
- }
- if (empty($path)) {
- $child->hook = $hook;
- } else {
- $child->addChild($path, $hook);
- }
- }
-
- private function findChildAux(array $remain, array $matched, array $aliased)
- {
- $next = @$remain[0];
- if ($this->aliased) {
- $aliased = $matched;
- }
- if (!empty($next)) {
- $child = @$this->children[$next];
- if ($child) {
- array_shift($remain);
- $matched[] = $next;
- return $child->findChildAux($remain, $matched, $aliased);
+ foreach ($hooks as $path=>$hook) {
+ $path = explode('/', $path);
+ $element = $this;
+ foreach ($path as $next) {
+ $alias = null;
+ if ($next{0} == '%') {
+ $alias = $next;
+ $next = $platal->hook_map(substr($next, 1));
+ }
+ if (!isset($element->children[$next])) {
+ $child = new PlHookTree();
+ $child->aliased = $alias;
+ $element->children[$next] = $child;
+ } else {
+ $child = $element->children[$next];
+ }
+ $element = $child;
}
+ $element->hook = $hook;
}
- return array($this->hook, $matched, $remain, $aliased);
}
public function findChild(array $path)
{
- return $this->findChildAux($path, array(), array());
+ $remain = $path;
+ $matched = array();
+ $aliased = array();
+ $element = $this;
+ while (true)
+ {
+ $next = @$remain[0];
+ if ($element->aliased) {
+ $aliased = $matched;
+ }
+ if (empty($next) || !isset($element->children[$next])) {
+ break;
+ }
+ $element = $element->children[$next];
+ array_shift($remain);
+ $matched[] = $next;
+ }
+ return array($element->hook, $matched, $remain, $aliased);
}
private function findNearestChildAux(array $remain, array $matched, array $aliased)
$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;
+ }
}
}
}
foreach ($modules as $module) {
$module = strtolower($module);
$this->mods[$module] = $m = PLModule::factory($module);
- $hooks = $m->handlers();
- foreach ($hooks as $path=>$hook) {
- $this->hooks->addChild(explode('/', $path), $hook);
- }
+ $this->hooks->addChildren($m->handlers());
}
if ($globals->mode == '') {
return $url;
}
- private function call_hook(PlPage &$page)
+ private function call_hook(PlPage $page)
{
$hook = $this->find_hook();
if (empty($hook)) {
/** Show the authentication form.
*/
- abstract public function force_login(PlPage& $page);
+ abstract public function force_login(PlPage $page);
+
+ protected function report_error($error)
+ {
+ PlErrorReport::report($error);
+ }
public function run()
{
}
} catch (Exception $e) {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
- PlErrorReport::report($e);
+ $this->report_error($e);
if (self::globals()->debug) {
$page->kill(pl_entities($e->getMessage())
. '<pre>' . pl_entities("" . $e) . '</pre>');