3 |
// $Id$ |
// $Id$ |
4 |
// ------------------------------------------------------------------------------- |
// ------------------------------------------------------------------------------- |
5 |
// $Log$ |
// $Log$ |
6 |
|
// Revision 1.8 2005/01/21 16:51:57 jonen |
7 |
|
// + changed lang-key for turkish |
8 |
|
// |
9 |
|
// Revision 1.7 2004/11/15 17:24:50 jonen |
10 |
|
// + updated 'setlocale' for FreeBSD |
11 |
|
// |
12 |
|
// Revision 1.6 2003/02/09 17:29:02 joko |
13 |
|
// - refactored code to org.netfrag.glib/ |
14 |
|
// + added startup code here (Site/Boot.php got purged) |
15 |
|
// |
16 |
|
// Revision 1.5 2002/12/23 11:33:58 jonen |
17 |
|
// + minor changes |
18 |
|
// |
19 |
|
// Revision 1.4 2002/12/19 16:25:29 joko |
20 |
|
// + function loadCmsPage($template, $data_merge = array()) |
21 |
|
// |
22 |
|
// Revision 1.3 2002/12/19 06:17:32 joko |
23 |
|
// + database, smarty, and langtext (lt) now gets initialized here (on Site startup) |
24 |
|
// |
25 |
// Revision 1.2 2002/12/13 09:17:41 joko |
// Revision 1.2 2002/12/13 09:17:41 joko |
26 |
// + function getLastRequest |
// + function getLastRequest |
27 |
// + function cacheRequest |
// + function cacheRequest |
42 |
// ------------------------------------------------------------------------------- |
// ------------------------------------------------------------------------------- |
43 |
|
|
44 |
|
|
45 |
require_once 'Site/Boot.php'; |
require_once 'Site/DebugBox.php'; |
46 |
|
require_once 'Site/ExtHttp.php'; |
47 |
|
require_once 'Site/Misc.php'; |
48 |
|
require_once 'Site/Template.php'; |
49 |
|
|
50 |
class Site extends Site_Boot { |
class Site extends Application_AbstractBase { |
51 |
//class Site extends PEAR_Autoloader { |
//class Site extends PEAR_Autoloader { |
52 |
|
|
53 |
|
//$this->_mkEmbeddedObjects( array( parent_name => get_class($this), run => 'start', class_names => $class_names, ref_names => $ref_names ) ); |
54 |
|
|
55 |
|
var $children = array( |
56 |
|
'_block1' => array( |
57 |
|
'Site_DebugBox', 'Site_Handler', 'Site_Request', 'Site_Loader', 'Site_Http', 'Site_Template' |
58 |
|
), |
59 |
|
'_block2' => array( |
60 |
|
'User', 'Session', |
61 |
|
), |
62 |
|
'_block3' => array( |
63 |
|
'LocaleText' => array( ref_names => array('lt'), run => '_'), |
64 |
|
), |
65 |
|
); |
66 |
|
|
67 |
// this collects all/some stuff (object variables and methods) |
// this collects all/some stuff (object variables and methods) |
68 |
// from other (helper)-objects and acts as a dispatcher to them... |
// from other (helper)-objects and acts as a dispatcher to them... |
69 |
// ...is this a bridge then? |
// ...is this a bridge then? |
74 |
// - implement autoloading mechanism via php's overload |
// - implement autoloading mechanism via php's overload |
75 |
|
|
76 |
// essentials (more or less) |
// essentials (more or less) |
77 |
|
var $configuration; // new - the configuration object (a Application::Config one....) |
78 |
var $config; // config ...is very essential (especially preboot stuff) |
var $config; // config ...is very essential (especially preboot stuff) |
79 |
var $logger; // logging? yea |
var $logger; // logging? yea |
80 |
var $db; // the database handle (actually a PEAR::DB) |
var $db; // the database handle (actually a PEAR::DB) |
90 |
var $session; |
var $session; |
91 |
var $user; |
var $user; |
92 |
|
|
93 |
function Site(&$config) { |
function Site(&$configObject) { |
94 |
|
//print "Site<br>"; |
95 |
|
//print Dumper($configObject); |
96 |
|
parent::constructor(); |
97 |
// this will not work, logger is initialized two lines below |
// this will not work, logger is initialized two lines below |
98 |
$this->log( get_class($this) . "->Site( config $config )", LOG_DEBUG ); |
$this->log( get_class($this) . "->new", PEAR_LOG_DEBUG ); |
99 |
$this->config = $config; |
$this->configuration = &$configObject; |
100 |
$this->_init_logger(); |
$this->config = $this->configuration->get(); |
101 |
$this->_init_helpers(); |
//$this->_init_logger(); |
102 |
$this->_init_application(); |
$this->_init_session(); |
103 |
//$this->_init_database(); |
$this->_init_database(); |
104 |
|
$this->_init_smarty(); |
105 |
|
$this->_init_locales(); |
106 |
|
} |
107 |
|
|
108 |
|
// ------------------------------------------------------------------------- |
109 |
|
// Initializers for various things |
110 |
|
// called on object instantiation by constructor |
111 |
|
// |
112 |
|
|
113 |
|
function _init_session() { |
114 |
|
global $site_state; |
115 |
|
session_register_safe('site_state'); |
116 |
|
if (!is_array($site_state)) { $site_state = array(); } |
117 |
|
} |
118 |
|
|
119 |
|
function _init_smarty() { |
120 |
|
$this->log( get_class($this) . "->_init_smarty()", PEAR_LOG_DEBUG ); |
121 |
|
|
122 |
|
// smarty (template engine) |
123 |
|
$smarty = new Smarty; |
124 |
|
$smarty->template_dir = $this->config[path][templates]; |
125 |
|
$smarty->compile_dir = $this->config[path]["var"] . "smarty/templates_c/"; |
126 |
|
$smarty->config_dir = $this->config[path]["var"] . "smarty/configs/"; |
127 |
|
$smarty->cache_dir = $this->config[path]["var"] . "smarty/cache/"; |
128 |
|
$smarty->compile_check = true; |
129 |
|
|
130 |
|
// trace |
131 |
|
//print Dumper($smarty); |
132 |
|
|
133 |
|
//$smarty->caching = false; |
134 |
|
//$smarty->caching = true; |
135 |
|
// TODO: inherit global debugging option(s) here? |
136 |
|
//$smarty->debugging = true; |
137 |
|
// we declare "volatile" as a special namespace/cache key which is clean on each script-startup/reuse |
138 |
|
$smarty->clear_cache(null, "volatile"); |
139 |
|
//$site->smarty = &$smarty; |
140 |
|
$this->smarty = &$smarty; |
141 |
|
//$site->log( "init_site: smarty ready", PEAR_LOG_DEBUG); |
142 |
|
} |
143 |
|
|
144 |
|
// LocaleText-class for language |
145 |
|
function _init_locales() { |
146 |
|
$this->log( get_class($this) . "->_init_lt: LocaleText starting", PEAR_LOG_DEBUG); |
147 |
|
|
148 |
|
$this->lt->start(); |
149 |
|
|
150 |
|
// Set locale according to chosen language (needed for date/time functions) |
151 |
|
// TODO: set this according to user's profile |
152 |
|
// TODO: make an flib/Application/l10n/Locale.php from this (available by doing e.g. an '$locale_key = $app->l10n->getLocaleKey()') |
153 |
|
// TODO: don't wire this to the locale-text setting |
154 |
|
// ---> actually wire the locale-text setting to $app->l10n->getLocaleKey() (the other way round....) |
155 |
|
$langkey = $this->localetext->getCurrentLanguage(); |
156 |
|
if($langkey == "de") { |
157 |
|
if(!setlocale (LC_ALL, 'de_DE')) { |
158 |
|
// needed at e.g. FreeBSD |
159 |
|
setlocale (LC_ALL, 'de_DE.ISO_8859-1'); |
160 |
|
} |
161 |
|
} |
162 |
|
elseif($langkey == "en") { |
163 |
|
if(!setlocale (LC_ALL, 'en_US')) { |
164 |
|
// needed at e.g. FreeBSD |
165 |
|
setlocale (LC_ALL, 'en_US.ISO_8859-1'); |
166 |
|
} |
167 |
|
} |
168 |
|
elseif($langkey == "tr") { |
169 |
|
if(!setlocale (LC_ALL, 'tr_TR')) { |
170 |
|
// needed at e.g. FreeBSD |
171 |
|
setlocale (LC_ALL, 'tr_TR.ISO_8859-1'); |
172 |
|
} |
173 |
|
} |
174 |
|
|
175 |
} |
} |
176 |
|
|
177 |
|
// ------------------------------------------------------------------------- |
178 |
// Dispatchers for all subobjects |
// Dispatchers for all subobjects |
179 |
// TODO: |
// TODO: |
180 |
// - make this much more generic |
// - make this much more generic |
216 |
function &loadHandler($a) { |
function &loadHandler($a) { |
217 |
return $this->loader->loadHandler($a); |
return $this->loader->loadHandler($a); |
218 |
} |
} |
219 |
function &loadPage($a) { |
function &loadPage($a, $b = array()) { |
220 |
return $this->loader->loadPage($a); |
return $this->loader->loadPage($a, $b); |
221 |
|
} |
222 |
|
function &loadTemplate($a, $b = array(), $c = "") { |
223 |
|
return $this->loader->loadTemplate($a, $b, $c); |
224 |
} |
} |
225 |
|
|
226 |
// dispatchers for Http |
// dispatchers for Http |
251 |
return $site->user->isLoggedOn(); |
return $site->user->isLoggedOn(); |
252 |
} |
} |
253 |
|
|
254 |
function log($msg, $level) { |
function loadCmsPage($template, $data_merge = array()) { |
255 |
if ($this->logger) { |
|
256 |
$this->logger->log($msg, $level); |
//print Dumper($this->getRequest()); |
257 |
} else { |
|
258 |
// TODO: how are these type of errors handled? |
// default data to provide to scope of cms |
259 |
//print "error-message: $msg<br>"; |
// TODO/REVIEW: should we be more strict here? |
260 |
|
// e.g. just pass in '$site->config->url' or s.th.l.th. |
261 |
|
$data = array( |
262 |
|
'config' => $this->config, |
263 |
|
'request' => $this->getRequest(), |
264 |
|
); |
265 |
|
|
266 |
|
// merge in additional data |
267 |
|
foreach ($data_merge as $key => $val) { |
268 |
|
$data[$key] = $val; |
269 |
} |
} |
270 |
|
|
271 |
|
// load template |
272 |
|
$this->loadTemplate($template, $data); |
273 |
|
|
274 |
} |
} |
275 |
|
|
276 |
} |
} |