3 |
// $Id$ |
// $Id$ |
4 |
// ------------------------------------------------------------------------------- |
// ------------------------------------------------------------------------------- |
5 |
// $Log$ |
// $Log$ |
6 |
|
// Revision 1.6 2003/02/09 17:29:02 joko |
7 |
|
// - refactored code to org.netfrag.glib/ |
8 |
|
// + added startup code here (Site/Boot.php got purged) |
9 |
|
// |
10 |
|
// Revision 1.5 2002/12/23 11:33:58 jonen |
11 |
|
// + minor changes |
12 |
|
// |
13 |
|
// Revision 1.4 2002/12/19 16:25:29 joko |
14 |
|
// + function loadCmsPage($template, $data_merge = array()) |
15 |
|
// |
16 |
|
// Revision 1.3 2002/12/19 06:17:32 joko |
17 |
|
// + database, smarty, and langtext (lt) now gets initialized here (on Site startup) |
18 |
|
// |
19 |
|
// Revision 1.2 2002/12/13 09:17:41 joko |
20 |
|
// + function getLastRequest |
21 |
|
// + function cacheRequest |
22 |
|
// |
23 |
// Revision 1.1 2002/11/12 05:42:30 joko |
// Revision 1.1 2002/11/12 05:42:30 joko |
24 |
// + initial checkin |
// + initial checkin |
25 |
// |
// |
36 |
// ------------------------------------------------------------------------------- |
// ------------------------------------------------------------------------------- |
37 |
|
|
38 |
|
|
39 |
require_once 'Site/Boot.php'; |
require_once 'Site/DebugBox.php'; |
40 |
|
require_once 'Site/ExtHttp.php'; |
41 |
|
require_once 'Site/Misc.php'; |
42 |
|
require_once 'Site/Template.php'; |
43 |
|
|
44 |
class Site extends Site_Boot { |
class Site extends Application_AbstractBase { |
45 |
//class Site extends PEAR_Autoloader { |
//class Site extends PEAR_Autoloader { |
46 |
|
|
47 |
|
//$this->_mkEmbeddedObjects( array( parent_name => get_class($this), run => 'start', class_names => $class_names, ref_names => $ref_names ) ); |
48 |
|
|
49 |
|
var $children = array( |
50 |
|
'_block1' => array( |
51 |
|
'Site_DebugBox', 'Site_Handler', 'Site_Request', 'Site_Loader', 'Site_Http', 'Site_Template' |
52 |
|
), |
53 |
|
'_block2' => array( |
54 |
|
'User', 'Session', |
55 |
|
), |
56 |
|
'_block3' => array( |
57 |
|
'LocaleText' => array( ref_names => array('lt'), run => '_'), |
58 |
|
), |
59 |
|
); |
60 |
|
|
61 |
// this collects all/some stuff (object variables and methods) |
// this collects all/some stuff (object variables and methods) |
62 |
// from other (helper)-objects and acts as a dispatcher to them... |
// from other (helper)-objects and acts as a dispatcher to them... |
63 |
// ...is this a bridge then? |
// ...is this a bridge then? |
68 |
// - implement autoloading mechanism via php's overload |
// - implement autoloading mechanism via php's overload |
69 |
|
|
70 |
// essentials (more or less) |
// essentials (more or less) |
71 |
|
var $configuration; // new - the configuration object (a Application::Config one....) |
72 |
var $config; // config ...is very essential (especially preboot stuff) |
var $config; // config ...is very essential (especially preboot stuff) |
73 |
var $logger; // logging? yea |
var $logger; // logging? yea |
74 |
var $db; // the database handle (actually a PEAR::DB) |
var $db; // the database handle (actually a PEAR::DB) |
84 |
var $session; |
var $session; |
85 |
var $user; |
var $user; |
86 |
|
|
87 |
function Site(&$config) { |
function Site(&$configObject) { |
88 |
|
//print "Site<br>"; |
89 |
|
//print Dumper($configObject); |
90 |
|
parent::constructor(); |
91 |
// this will not work, logger is initialized two lines below |
// this will not work, logger is initialized two lines below |
92 |
$this->log( get_class($this) . "->Site( config $config )", LOG_DEBUG ); |
$this->log( get_class($this) . "->new", PEAR_LOG_DEBUG ); |
93 |
$this->config = $config; |
$this->configuration = &$configObject; |
94 |
$this->_init_logger(); |
$this->config = $this->configuration->get(); |
95 |
$this->_init_helpers(); |
//$this->_init_logger(); |
96 |
$this->_init_application(); |
$this->_init_session(); |
97 |
//$this->_init_database(); |
$this->_init_database(); |
98 |
|
$this->_init_smarty(); |
99 |
|
$this->_init_locales(); |
100 |
|
} |
101 |
|
|
102 |
|
// ------------------------------------------------------------------------- |
103 |
|
// Initializers for various things |
104 |
|
// called on object instantiation by constructor |
105 |
|
// |
106 |
|
|
107 |
|
function _init_session() { |
108 |
|
global $site_state; |
109 |
|
session_register_safe('site_state'); |
110 |
|
if (!is_array($site_state)) { $site_state = array(); } |
111 |
} |
} |
112 |
|
|
113 |
|
function _init_smarty() { |
114 |
|
$this->log( get_class($this) . "->_init_smarty()", PEAR_LOG_DEBUG ); |
115 |
|
|
116 |
|
// smarty (template engine) |
117 |
|
$smarty = new Smarty; |
118 |
|
$smarty->template_dir = $this->config[path][templates]; |
119 |
|
$smarty->compile_dir = $this->config[path]["var"] . "smarty/templates_c/"; |
120 |
|
$smarty->config_dir = $this->config[path]["var"] . "smarty/configs/"; |
121 |
|
$smarty->cache_dir = $this->config[path]["var"] . "smarty/cache/"; |
122 |
|
$smarty->compile_check = true; |
123 |
|
|
124 |
|
// trace |
125 |
|
//print Dumper($smarty); |
126 |
|
|
127 |
|
//$smarty->caching = false; |
128 |
|
//$smarty->caching = true; |
129 |
|
// TODO: inherit global debugging option(s) here? |
130 |
|
//$smarty->debugging = true; |
131 |
|
// we declare "volatile" as a special namespace/cache key which is clean on each script-startup/reuse |
132 |
|
$smarty->clear_cache(null, "volatile"); |
133 |
|
//$site->smarty = &$smarty; |
134 |
|
$this->smarty = &$smarty; |
135 |
|
//$site->log( "init_site: smarty ready", PEAR_LOG_DEBUG); |
136 |
|
} |
137 |
|
|
138 |
|
// LocaleText-class for language |
139 |
|
function _init_locales() { |
140 |
|
$this->log( get_class($this) . "->_init_lt: LocaleText starting", PEAR_LOG_DEBUG); |
141 |
|
|
142 |
|
$this->lt->start(); |
143 |
|
|
144 |
|
// Set locale according to chosen language (needed for date/time functions) |
145 |
|
// TODO: set this according to user's profile |
146 |
|
// TODO: make an flib/Application/l10n/Locale.php from this (available by doing e.g. an '$locale_key = $app->l10n->getLocaleKey()') |
147 |
|
// TODO: don't wire this to the locale-text setting |
148 |
|
// ---> actually wire the locale-text setting to $app->l10n->getLocaleKey() (the other way round....) |
149 |
|
$langkey = $this->localetext->getCurrentLanguage(); |
150 |
|
if($langkey == "de") { |
151 |
|
setlocale (LC_ALL, 'de_DE'); |
152 |
|
} |
153 |
|
elseif($langkey == "en") { |
154 |
|
setlocale (LC_ALL, 'en_US'); |
155 |
|
} |
156 |
|
elseif($langkey == "tr") { |
157 |
|
setlocale (LC_ALL, 'tr_TR'); |
158 |
|
} |
159 |
|
|
160 |
|
} |
161 |
|
|
162 |
|
// ------------------------------------------------------------------------- |
163 |
// Dispatchers for all subobjects |
// Dispatchers for all subobjects |
164 |
// TODO: |
// TODO: |
165 |
// - make this much more generic |
// - make this much more generic |
189 |
return $this->request->getRequest(); |
return $this->request->getRequest(); |
190 |
} |
} |
191 |
|
|
192 |
|
function getLastRequest() { |
193 |
|
return $this->request->getCached(); |
194 |
|
} |
195 |
|
|
196 |
|
function cacheRequest($request = array()) { |
197 |
|
return $this->request->cacheRequest($request); |
198 |
|
} |
199 |
|
|
200 |
// dispatchers for Loader |
// dispatchers for Loader |
201 |
function &loadHandler($a) { |
function &loadHandler($a) { |
202 |
return $this->loader->loadHandler($a); |
return $this->loader->loadHandler($a); |
203 |
} |
} |
204 |
function &loadPage($a) { |
function &loadPage($a, $b = array()) { |
205 |
return $this->loader->loadPage($a); |
return $this->loader->loadPage($a, $b); |
206 |
|
} |
207 |
|
function &loadTemplate($a, $b = array(), $c = "") { |
208 |
|
return $this->loader->loadTemplate($a, $b, $c); |
209 |
} |
} |
210 |
|
|
211 |
// dispatchers for Http |
// dispatchers for Http |
236 |
return $site->user->isLoggedOn(); |
return $site->user->isLoggedOn(); |
237 |
} |
} |
238 |
|
|
239 |
function log($msg, $level) { |
function loadCmsPage($template, $data_merge = array()) { |
240 |
if ($this->logger) { |
|
241 |
$this->logger->log($msg, $level); |
//print Dumper($this->getRequest()); |
242 |
} else { |
|
243 |
// TODO: how are these type of errors handled? |
// default data to provide to scope of cms |
244 |
//print "error-message: $msg<br>"; |
// TODO/REVIEW: should we be more strict here? |
245 |
|
// e.g. just pass in '$site->config->url' or s.th.l.th. |
246 |
|
$data = array( |
247 |
|
'config' => $this->config, |
248 |
|
'request' => $this->getRequest(), |
249 |
|
); |
250 |
|
|
251 |
|
// merge in additional data |
252 |
|
foreach ($data_merge as $key => $val) { |
253 |
|
$data[$key] = $val; |
254 |
} |
} |
255 |
|
|
256 |
|
// load template |
257 |
|
$this->loadTemplate($template, $data); |
258 |
|
|
259 |
} |
} |
260 |
|
|
261 |
} |
} |