move orange.php
[platal.git] / classes / Platal.php
index 06ce1b4..92604db 100644 (file)
@@ -30,27 +30,23 @@ class Platal
     var $__hooks;
 
     var $path;
-    var $menu;
-    var $auth;
+    var $argv;
 
     function Platal()
     {
-        $this->path = Get::_get('p', null);
+        $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;
             $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)
@@ -58,11 +54,6 @@ class Platal
         require_once dirname(__FILE__).'/../classes/'.$cls.'.php';
     }
 
-    function _menu_cmp($a, $b)
-    {
-        return strcasecmp($a['path'], $b['path']);
-    }
-
     function call_hook(&$page)
     {
         $p = $this->path;
@@ -77,10 +68,17 @@ class Platal
             return PL_NOT_FOUND;
         }
 
-        $args = array_merge(array(&$page),
-            explode('/', substr($this->path, strlen($p) + 1)));
-
         $hook = $this->__hooks[$p];
+
+        if (!is_callable($hook['hook'])) {
+            return PL_NOT_FOUND;
+        }
+
+        $args       = explode('/', substr($this->path, strlen($p)));
+        $args[0]    = $p;
+        $this->argv = $args;
+        $args[0]    = &$page;
+
         if ($hook['auth'] > Session::get('auth', AUTH_PUBLIC)) {
             $_SESSION['session']->doAuth($page);
         }
@@ -94,9 +92,8 @@ class Platal
         new_skinned_page('index.tpl', AUTH_PUBLIC);
 
         if (empty($this->path)) {
-            $page->run();
-        }
-
+            $this->__mods['core']->handler_index($page);
+        } else
         switch ($this->call_hook($page)) {
           case PL_FORBIDDEN:
             $this->__mods['core']->handler_403($page);
@@ -106,6 +103,7 @@ class Platal
             $this->__mods['core']->handler_404($page);
             break;
         }
+        $page->assign_by_ref('platal', $this);
         $page->run();
     }
 }