X-Git-Url: http://andersk.mit.edu/gitweb/sql-web.git/blobdiff_plain/9d568c7bac02a2382ee5bd541421bcf0c26f6298..f185cadba1740cbc0840fcd0a6fb343b573f2705:/lib/joe/site.lib.php diff --git a/lib/joe/site.lib.php b/lib/joe/site.lib.php index c28c231..e780e8d 100755 --- a/lib/joe/site.lib.php +++ b/lib/joe/site.lib.php @@ -4,8 +4,23 @@ */ class Site { - function Start() {} - function Call($MODULE, $METHOD) { + var $uri, $argv; + function __construct($uri) { + $this->uri = $uri; + $this->argv = array_merge( + array_prepend_keys($_COOKIE,'c_'), + array_prepend_keys($_FILES,'f_'), + array_prepend_keys($_GET,'g_'), + array_prepend_keys($_POST,'p_')); + } + function Start() { + if (isset($_SESSION)) { + $this->argv = array_merge( + $this->argv, + array_prepend_keys($_SESSION,'s_')); + } + } + function Run($MODULE, $METHOD) { $nCalls = 0; if (file_exists(strtolower('site/'.$MODULE.'.php'))) { require_once strtolower('site/'.$MODULE.'.php'); @@ -13,23 +28,14 @@ class Site { $page = new $MODULE($this, $METHOD); $page->Start(); $handlers = $page->get_handlers($METHOD); - switch ($METHOD) { - case 'GET': - case 'get': - $argv = array_merge($_COOKIE, $_FILES, $_POST, $_GET, isset($_SESSION)?$_SESSION:array()); break; - case 'POST': - case 'post': - default: - $argv = array_merge($_COOKIE, $_FILES, $_GET, $_POST, isset($_SESSION)?$_SESSION:array()); break; - } - foreach($handlers as $handler) { - if (isset($argv[$handler]) && - false !== $page->Call($handler, $argv)) { + foreach($this->argv as $argk=>$argv) { + if (in_array($argk, $handlers) && + false !== $page->Run($argk)) { $nCalls++; } } if ($nCalls == 0 && is_callable(array($page, '_default'))) { - $page->Call('_default', $argv); + $page->Run('_default'); $nCalls++; } $page->Finish(); @@ -41,9 +47,16 @@ class Site { } class Page { - var $site, $method; + var $site; + var $method; + var $uri; + var $argv; function __construct($site, $method) { + $this->argv = $site->argv; + foreach($this->argv as $k=>$v) + $this->$k = $v; $this->site = $site; + $this->uri = $site->uri; $this->method = $method; } function get_handlers() { @@ -52,14 +65,17 @@ class Page { return $handlers; } function has_handler($handler) { - return isset($this->handlers[$this->method]) ? in_array($handler, $this->handlers[$this->method]) : false; + return isset($this->handlers[$this->method]) ? + in_array($handler, $this->handlers[$this->method]) : false; } function Start() {} - function Call($handler, $argv) { - if (is_callable(array($this, $handler))) - return array(0, call_user_func_array(array($this, $handler), $argv)); - else return false; + function Run($handler) { + if (is_callable(array($this, $handler))) { + return array(0, call_user_func(array($this, $handler))); + } else { + return false; + } } function Finish() {} }