* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
-define('PL_OK', 0);
-define('PL_NEEDLOGIN', 1);
define('PL_FORBIDDEN', 403);
define('PL_NOT_FOUND', 404);
var $__mods;
var $__hooks;
+ var $ns;
var $path;
- var $menu;
- var $auth;
+ var $argv;
function Platal()
{
- $this->path = Get::_get('p', null);
+ $modules = func_get_args();
+ $this->path = trim(Get::_get('p', null), '/');
$this->__mods = array();
$this->__hooks = array();
- $this->menu = array();
- foreach (glob(dirname(__FILE__).'/../modules/*.php') as $module) {
- $module = basename($module, '.php');
- $m =& PLModule::factory($this, $module);
- $this->__mods[$module] =& $m;
+ array_unshift($modules, 'core');
+ foreach ($modules as $module) {
+ $this->__mods[$module] = $m = PLModule::factory($this, $module);
$this->__hooks += $m->handlers();
- $this->menu = array_merge($this->menu, $m->menu_entries());
}
-
- krsort($this->__hooks);
- usort($this->menu, array($this, '_menu_cmp'));
- }
-
- function load_class($cls)
- {
- require_once dirname(__FILE__).'/../classes/'.$cls.'.php';
- }
-
- function _menu_cmp($a, $b)
- {
- return strcasecmp($a['path'], $b['path']);
}
- function call_hook(&$page)
+ function find_hook()
{
$p = $this->path;
$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 = array_merge(array(&$page),
- explode('/', substr($this->path, strlen($p) + 1)));
+ $args = $this->argv;
+ $args[0] = &$page;
- $hook = $this->__hooks[$p];
if ($hook['auth'] > Session::get('auth', AUTH_PUBLIC)) {
$_SESSION['session']->doAuth($page);
}
+
return call_user_func_array($hook['hook'], $args);
}
new_skinned_page('index.tpl', AUTH_PUBLIC);
if (empty($this->path)) {
- $page->run();
+ $this->path = 'index';
}
switch ($this->call_hook($page)) {
$this->__mods['core']->handler_404($page);
break;
}
+ $page->assign_by_ref('platal', $this);
$page->run();
}
}