2 /* Generic Site Classes
3 * 2007/04/09 Joe Presbrey <presbrey@mit.edu>
8 function __construct($uri) {
10 $this->argv = array_merge(
11 array_prepend_keys($_COOKIE,'c_'),
12 array_prepend_keys($_FILES,'f_'),
13 array_prepend_keys($_GET,'g_'),
14 array_prepend_keys($_POST,'p_'));
17 if (isset($_SESSION)) {
18 $this->argv = array_merge(
20 array_prepend_keys($_SESSION,'s_'));
23 function Run($MODULE, $METHOD) {
25 if (file_exists(strtolower('site/'.$MODULE.'.php'))) {
26 require_once strtolower('site/'.$MODULE.'.php');
27 if (class_exists($MODULE)) {
28 $page = new $MODULE($this, $METHOD);
30 $handlers = $page->get_handlers($METHOD);
31 foreach($this->argv as $argk=>$argv) {
32 if (in_array($argk, $handlers) &&
33 false !== $page->Run($argk)) {
37 if ($nCalls == 0 && is_callable(array($page, '_default'))) {
38 $page->Run('_default');
54 function __construct($site, $method) {
55 $this->argv = $site->argv;
56 foreach($this->argv as $k=>$v)
59 $this->uri = $site->uri;
60 $this->method = $method;
62 function get_handlers() {
63 $handlers = isset($this->handlers[$this->method]) ?
64 $this->handlers[$this->method] : array();
67 function has_handler($handler) {
68 return isset($this->handlers[$this->method]) ?
69 in_array($handler, $this->handlers[$this->method]) : false;
73 function Run($handler) {
74 if (is_callable(array($this, $handler))) {
75 return array(0, call_user_func(array($this, $handler)));