path = trim(Get::_get('n', null), '/'); $this->__mods = array(); $this->__hooks = array(); array_unshift($modules, 'core'); foreach ($modules as $module) { $this->__mods[$module] = $m = PLModule::factory($module); $this->__hooks += $m->handlers(); } } function pl_self($n = null) { if (is_null($n)) return $this->path; if ($n >= 0) return join('/', array_slice($this->argv, 0, $n + 1)); if ($n <= -count($this->argv)) return $this->argv[0]; return join('/', array_slice($this->argv, 0, $n)); } function find_hook() { $p = $this->path; while ($p) { if (array_key_exists($p, $this->__hooks)) break; $p = substr($p, 0, strrpos($p, '/')); } if (empty($this->__hooks[$p])) { return null; } $hook = $this->__hooks[$p]; if (!is_callable($hook['hook'])) { return null; } $this->argv = explode('/', substr($this->path, strlen($p))); $this->argv[0] = $p; return $hook; } function call_hook(&$page) { $hook = $this->find_hook(); if (is_null($hook)) { return PL_NOT_FOUND; } $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; if (!call_user_func(array($globals->session, 'doAuth'))) { $this->force_login($page); } } else { return PL_FORBIDDEN; } } return call_user_func_array($hook['hook'], $args); } function force_login(&$page) { if (S::logged()) { $page->changeTpl('password_prompt_logged.tpl'); $page->addJsLink('do_challenge_response_logged.js'); } else { $page->changeTpl('password_prompt.tpl'); $page->addJsLink('do_challenge_response.js'); } $page->run(); } function run() { global $page; new_skinned_page('index.tpl'); if (empty($this->path)) { $this->path = 'index'; } $page->assign('platal', $this); switch ($this->call_hook($page)) { case PL_FORBIDDEN: $this->__mods['core']->handler_403($page); break; case PL_NOT_FOUND: $this->__mods['core']->handler_404($page); break; } $page->assign('platal', $this); $page->run(); } function on_subscribe($forlife, $uid, $promo, $pass) { $args = func_get_args(); foreach ($this->__mods as $mod) { if (!is_callable($mod, 'on_subscribe')) continue; call_user_func_array(array($mod, 'on_subscribe'), $args); } } } ?>