]> andersk Git - sql-web.git/blob - lib/joe/site.lib.php
c2a2e3a62b030b19413e8b07cf60e1eb526e7645
[sql-web.git] / lib / joe / site.lib.php
1 <?php
2 /* Generic Site Classes
3  * 2007/04/09 Joe Presbrey <presbrey@mit.edu>
4  */
5
6 class Site {
7         function Start() {}
8         function Call($MODULE, $METHOD, $ARGP=array()) {
9                 $nCalls = 0;
10                 if (file_exists(strtolower('site/'.$MODULE.'.php'))) {
11                         require_once strtolower('site/'.$MODULE.'.php');
12                         if (class_exists($MODULE)) {
13                                 $page = new $MODULE($this, $METHOD, $ARGP);
14                                 $page->Start();
15                                 $handlers = $page->get_handlers($METHOD);
16                                 switch ($METHOD) {
17                                         case 'GET':
18                                         case 'get':
19                                                 $argv = array_merge($_COOKIE, $_FILES, $_POST, $_GET, isset($_SESSION)?$_SESSION:array()); break;
20                                         case 'POST':
21                                         case 'post':
22                                         default:
23                                                 $argv = array_merge($_COOKIE, $_FILES, $_GET, $_POST, isset($_SESSION)?$_SESSION:array()); break;
24                                 }
25                                 foreach($handlers as $handler) {
26                                         if (isset($argv[$handler]) &&
27                                                 false !== $page->Call($handler, $argv)) {
28                                                 $nCalls++;
29                                         }
30                                 }
31                                 if ($nCalls == 0 && is_callable(array($page, '_default'))) {
32                                         $page->Call('_default', $argv);
33                                         $nCalls++;
34                                 }
35                                 $page->Finish();
36                         }
37                 }
38                 return $nCalls;
39         }
40         function Finish() {}
41 }
42
43 class Page {
44         var $site, $method, $argp;
45         function __construct($site, $method, $argp) {
46                 $this->site = $site;
47                 $this->method = $method;
48                 $this->argp = $argp;
49         }
50         function get_handlers() {
51                 $handlers = isset($this->handlers[$this->method]) ?
52                                         $this->handlers[$this->method] : array();
53                 return $handlers;
54         }
55         function has_handler($handler) {
56                 return isset($this->handlers[$this->method]) ? in_array($handler, $this->handlers[$this->method]) : false;
57         }
58
59         function Start() {}
60         function Call($handler, $argv) {
61                 if (is_callable(array($this, $handler))) {
62                         return array(0, call_user_func(array($this, $handler), $argv));
63                 } else {
64                         return false;
65                 }
66         }
67         function Finish() {}
68 }
This page took 0.02974 seconds and 3 git commands to generate.