| 1 |
<? |
| 2 |
// ------------------------------------------------------------------------------- |
| 3 |
// $Id: Site.php,v 1.4 2002/12/19 16:25:29 joko Exp $ |
| 4 |
// ------------------------------------------------------------------------------- |
| 5 |
// $Log: Site.php,v $ |
| 6 |
// Revision 1.4 2002/12/19 16:25:29 joko |
| 7 |
// + function loadCmsPage($template, $data_merge = array()) |
| 8 |
// |
| 9 |
// Revision 1.3 2002/12/19 06:17:32 joko |
| 10 |
// + database, smarty, and langtext (lt) now gets initialized here (on Site startup) |
| 11 |
// |
| 12 |
// Revision 1.2 2002/12/13 09:17:41 joko |
| 13 |
// + function getLastRequest |
| 14 |
// + function cacheRequest |
| 15 |
// |
| 16 |
// Revision 1.1 2002/11/12 05:42:30 joko |
| 17 |
// + initial checkin |
| 18 |
// |
| 19 |
// Revision 1.3 2002/10/25 15:14:50 cvsjoko |
| 20 |
// + generic logging mechanism via PEAR::Log |
| 21 |
// |
| 22 |
// Revision 1.2 2002/10/20 21:52:00 cvsmax |
| 23 |
// + add new |
| 24 |
// + function cacheThisRequest($request) # save current request in session |
| 25 |
// + function getCachedRequest() # get cached request from session |
| 26 |
// |
| 27 |
// Revision 1.1 2002/10/09 00:42:50 cvsjoko |
| 28 |
// + much code from "lib/menu/libnav.php.inc" |
| 29 |
// ------------------------------------------------------------------------------- |
| 30 |
|
| 31 |
|
| 32 |
require_once 'Site/Boot.php'; |
| 33 |
|
| 34 |
class Site extends Site_Boot { |
| 35 |
//class Site extends PEAR_Autoloader { |
| 36 |
|
| 37 |
// this collects all/some stuff (object variables and methods) |
| 38 |
// from other (helper)-objects and acts as a dispatcher to them... |
| 39 |
// ...is this a bridge then? |
| 40 |
|
| 41 |
// TODO: |
| 42 |
// - "Request" depends on "Handler" for now ;( |
| 43 |
// - application should croak if preboot doesn't exist inside config |
| 44 |
// - implement autoloading mechanism via php's overload |
| 45 |
|
| 46 |
// essentials (more or less) |
| 47 |
var $config; // config ...is very essential (especially preboot stuff) |
| 48 |
var $logger; // logging? yea |
| 49 |
var $db; // the database handle (actually a PEAR::DB) |
| 50 |
var $smarty; // a reference to a new smarty object, do templating stuff with that |
| 51 |
|
| 52 |
// some helper objects |
| 53 |
var $handler; // keeps track of handlers and identifiers |
| 54 |
var $request; // takes care about the requests |
| 55 |
var $loader; // loads various components (lib, page, file, etc.) |
| 56 |
var $misc; // not needed yet, just wastes space |
| 57 |
|
| 58 |
// some application objects |
| 59 |
var $session; |
| 60 |
var $user; |
| 61 |
|
| 62 |
function Site(&$config) { |
| 63 |
// this will not work, logger is initialized two lines below |
| 64 |
$this->log( get_class($this) . "->Site( config $config )", LOG_DEBUG ); |
| 65 |
$this->config = $config; |
| 66 |
$this->_init_logger(); |
| 67 |
$this->_init_helpers(); |
| 68 |
$this->_init_application(); |
| 69 |
$this->_init_database(); |
| 70 |
$this->_init_smarty(); |
| 71 |
$this->_init_lt(); |
| 72 |
} |
| 73 |
|
| 74 |
// Dispatchers for all subobjects |
| 75 |
// TODO: |
| 76 |
// - make this much more generic |
| 77 |
// - maybe use "aggregate" if it becomes available |
| 78 |
// - there is some function to get given args to a function from inside it, use this perhaps |
| 79 |
// - patch php to support multiple inheritance ;) |
| 80 |
|
| 81 |
// dispatchers for Handler |
| 82 |
function &encodeIdentifier($a) { |
| 83 |
return $this->handler->encodeIdentifier($a); |
| 84 |
} |
| 85 |
function &decodeIdentifier($a) { |
| 86 |
return $this->handler->decodeIdentifier($a); |
| 87 |
} |
| 88 |
function &getPageIdentifier() { |
| 89 |
return $this->handler->getPageIdentifier(); |
| 90 |
} |
| 91 |
function &setHandler($a, $b) { |
| 92 |
return $this->handler->setHandler($a, $b); |
| 93 |
} |
| 94 |
function getHandler($a) { |
| 95 |
return $this->handler->getHandler($a); |
| 96 |
} |
| 97 |
|
| 98 |
// dispatchers for Request |
| 99 |
function getRequest() { |
| 100 |
return $this->request->getRequest(); |
| 101 |
} |
| 102 |
|
| 103 |
function getLastRequest() { |
| 104 |
return $this->request->getCached(); |
| 105 |
} |
| 106 |
|
| 107 |
function cacheRequest($request = array()) { |
| 108 |
return $this->request->cacheRequest($request); |
| 109 |
} |
| 110 |
|
| 111 |
// dispatchers for Loader |
| 112 |
function &loadHandler($a) { |
| 113 |
return $this->loader->loadHandler($a); |
| 114 |
} |
| 115 |
function &loadPage($a, $b = array()) { |
| 116 |
return $this->loader->loadPage($a, $b); |
| 117 |
} |
| 118 |
function &loadTemplate($a, $b = array(), $c = "") { |
| 119 |
return $this->loader->loadTemplate($a, $b, $c); |
| 120 |
} |
| 121 |
|
| 122 |
// dispatchers for Http |
| 123 |
function &redirect($a) { |
| 124 |
return $this->http->redirect($a); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
// TODO: throw these out! |
| 130 |
|
| 131 |
function getLink($key, $attribs = array()) { |
| 132 |
//dprint("getlink: " . dumpvar($attribs)); |
| 133 |
$ident = $this->encodeIdentifier($key); |
| 134 |
// base url with ident |
| 135 |
$url = $_SERVER[PHP_SELF] . '?' . 'x=' . $ident; |
| 136 |
// additional arguments? |
| 137 |
foreach ($attribs as $key => $value) { |
| 138 |
$url .= '&' . $key . '=' . $value; |
| 139 |
} |
| 140 |
return $url; |
| 141 |
} |
| 142 |
|
| 143 |
function isAuthenticated() { |
| 144 |
//global $uservars_db; |
| 145 |
//return isset($uservars_db[status]); |
| 146 |
global $site; |
| 147 |
return $site->user->isLoggedOn(); |
| 148 |
} |
| 149 |
|
| 150 |
function log($msg, $level) { |
| 151 |
if ($this->logger) { |
| 152 |
$this->logger->log($msg, $level); |
| 153 |
} else { |
| 154 |
// TODO: how are these type of errors handled? |
| 155 |
//print "error-message: $msg<br>"; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
function loadCmsPage($template, $data_merge = array()) { |
| 160 |
|
| 161 |
//print Dumper($this->getRequest()); |
| 162 |
|
| 163 |
// default data to provide to scope of cms |
| 164 |
// TODO/REVIEW: should we be more strict here? |
| 165 |
// e.g. just pass in '$site->config->url' or s.th.l.th. |
| 166 |
$data = array( |
| 167 |
'config' => $this->config, |
| 168 |
'request' => $this->getRequest(), |
| 169 |
); |
| 170 |
|
| 171 |
// merge in additional data |
| 172 |
foreach ($data_merge as $key => $val) { |
| 173 |
$data[$key] = $val; |
| 174 |
} |
| 175 |
|
| 176 |
// load template |
| 177 |
$this->loadTemplate($template, $data); |
| 178 |
|
| 179 |
} |
| 180 |
|
| 181 |
} |
| 182 |
|
| 183 |
?> |