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 = array_intersect(
31 $page->get_handlers($METHOD),
32 array_keys($this->ARGV));
33 foreach($handlers as $handler) {
34 if (false !== $page->Run($handler)) {
38 if ($nCalls == 0 && is_callable(array($page, '_default'))) {
39 $page->Run('_default');
51 var $SITE, $METHOD, $URI;
52 function __construct($site, $method) {
54 $this->METHOD = $method;
55 foreach($site->ARGV as $k=>$v)
57 $this->URI = $site->URI;
59 function get_handlers() {
60 $handlers = isset($this->handlers[$this->METHOD]) ?
61 $this->handlers[$this->METHOD] : array();
64 function has_handler($handler) {
65 return isset($this->handlers[$this->METHOD]) ?
66 in_array($handler, $this->handlers[$this->METHOD]) : false;
70 function Run($handler) {
71 if (is_callable(array($this, $handler))) {
72 return array(0, call_user_func(array($this, $handler)));