| 3 |
// $Id$ |
// $Id$ |
| 4 |
// ------------------------------------------------------------------------------- |
// ------------------------------------------------------------------------------- |
| 5 |
// $Log$ |
// $Log$ |
| 6 |
|
// Revision 1.9 2005/08/11 14:07:45 jonen |
| 7 |
|
// + added workaround for locale_number problem relating to generate Postscript files |
| 8 |
|
// |
| 9 |
|
// Revision 1.8 2005/01/21 16:51:57 jonen |
| 10 |
|
// + changed lang-key for turkish |
| 11 |
|
// |
| 12 |
|
// Revision 1.7 2004/11/15 17:24:50 jonen |
| 13 |
|
// + updated 'setlocale' for FreeBSD |
| 14 |
|
// |
| 15 |
|
// Revision 1.6 2003/02/09 17:29:02 joko |
| 16 |
|
// - refactored code to org.netfrag.glib/ |
| 17 |
|
// + added startup code here (Site/Boot.php got purged) |
| 18 |
|
// |
| 19 |
|
// Revision 1.5 2002/12/23 11:33:58 jonen |
| 20 |
|
// + minor changes |
| 21 |
|
// |
| 22 |
|
// Revision 1.4 2002/12/19 16:25:29 joko |
| 23 |
|
// + function loadCmsPage($template, $data_merge = array()) |
| 24 |
|
// |
| 25 |
|
// Revision 1.3 2002/12/19 06:17:32 joko |
| 26 |
|
// + database, smarty, and langtext (lt) now gets initialized here (on Site startup) |
| 27 |
|
// |
| 28 |
|
// Revision 1.2 2002/12/13 09:17:41 joko |
| 29 |
|
// + function getLastRequest |
| 30 |
|
// + function cacheRequest |
| 31 |
|
// |
| 32 |
// Revision 1.1 2002/11/12 05:42:30 joko |
// Revision 1.1 2002/11/12 05:42:30 joko |
| 33 |
// + initial checkin |
// + initial checkin |
| 34 |
// |
// |
| 45 |
// ------------------------------------------------------------------------------- |
// ------------------------------------------------------------------------------- |
| 46 |
|
|
| 47 |
|
|
| 48 |
require_once 'Site/Boot.php'; |
require_once 'Site/DebugBox.php'; |
| 49 |
|
require_once 'Site/ExtHttp.php'; |
| 50 |
|
require_once 'Site/Misc.php'; |
| 51 |
|
require_once 'Site/Template.php'; |
| 52 |
|
|
| 53 |
class Site extends Site_Boot { |
class Site extends Application_AbstractBase { |
| 54 |
//class Site extends PEAR_Autoloader { |
//class Site extends PEAR_Autoloader { |
| 55 |
|
|
| 56 |
|
//$this->_mkEmbeddedObjects( array( parent_name => get_class($this), run => 'start', class_names => $class_names, ref_names => $ref_names ) ); |
| 57 |
|
|
| 58 |
|
var $children = array( |
| 59 |
|
'_block1' => array( |
| 60 |
|
'Site_DebugBox', 'Site_Handler', 'Site_Request', 'Site_Loader', 'Site_Http', 'Site_Template' |
| 61 |
|
), |
| 62 |
|
'_block2' => array( |
| 63 |
|
'User', 'Session', |
| 64 |
|
), |
| 65 |
|
'_block3' => array( |
| 66 |
|
'LocaleText' => array( ref_names => array('lt'), run => '_'), |
| 67 |
|
), |
| 68 |
|
); |
| 69 |
|
|
| 70 |
// this collects all/some stuff (object variables and methods) |
// this collects all/some stuff (object variables and methods) |
| 71 |
// from other (helper)-objects and acts as a dispatcher to them... |
// from other (helper)-objects and acts as a dispatcher to them... |
| 72 |
// ...is this a bridge then? |
// ...is this a bridge then? |
| 77 |
// - implement autoloading mechanism via php's overload |
// - implement autoloading mechanism via php's overload |
| 78 |
|
|
| 79 |
// essentials (more or less) |
// essentials (more or less) |
| 80 |
|
var $configuration; // new - the configuration object (a Application::Config one....) |
| 81 |
var $config; // config ...is very essential (especially preboot stuff) |
var $config; // config ...is very essential (especially preboot stuff) |
| 82 |
var $logger; // logging? yea |
var $logger; // logging? yea |
| 83 |
var $db; // the database handle (actually a PEAR::DB) |
var $db; // the database handle (actually a PEAR::DB) |
| 93 |
var $session; |
var $session; |
| 94 |
var $user; |
var $user; |
| 95 |
|
|
| 96 |
function Site(&$config) { |
function Site(&$configObject) { |
| 97 |
|
//print "Site<br>"; |
| 98 |
|
//print Dumper($configObject); |
| 99 |
|
parent::constructor(); |
| 100 |
// this will not work, logger is initialized two lines below |
// this will not work, logger is initialized two lines below |
| 101 |
$this->log( get_class($this) . "->Site( config $config )", LOG_DEBUG ); |
$this->log( get_class($this) . "->new", PEAR_LOG_DEBUG ); |
| 102 |
$this->config = $config; |
$this->configuration = &$configObject; |
| 103 |
$this->_init_logger(); |
$this->config = $this->configuration->get(); |
| 104 |
$this->_init_helpers(); |
//$this->_init_logger(); |
| 105 |
$this->_init_application(); |
$this->_init_session(); |
| 106 |
//$this->_init_database(); |
$this->_init_database(); |
| 107 |
|
$this->_init_smarty(); |
| 108 |
|
$this->_init_locales(); |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
// ------------------------------------------------------------------------- |
| 112 |
|
// Initializers for various things |
| 113 |
|
// called on object instantiation by constructor |
| 114 |
|
// |
| 115 |
|
|
| 116 |
|
function _init_session() { |
| 117 |
|
global $site_state; |
| 118 |
|
session_register_safe('site_state'); |
| 119 |
|
if (!is_array($site_state)) { $site_state = array(); } |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
function _init_smarty() { |
| 123 |
|
$this->log( get_class($this) . "->_init_smarty()", PEAR_LOG_DEBUG ); |
| 124 |
|
|
| 125 |
|
// smarty (template engine) |
| 126 |
|
$smarty = new Smarty; |
| 127 |
|
$smarty->template_dir = $this->config[path][templates]; |
| 128 |
|
$smarty->compile_dir = $this->config[path]["var"] . "smarty/templates_c/"; |
| 129 |
|
$smarty->config_dir = $this->config[path]["var"] . "smarty/configs/"; |
| 130 |
|
$smarty->cache_dir = $this->config[path]["var"] . "smarty/cache/"; |
| 131 |
|
$smarty->compile_check = true; |
| 132 |
|
|
| 133 |
|
// trace |
| 134 |
|
//print Dumper($smarty); |
| 135 |
|
|
| 136 |
|
//$smarty->caching = false; |
| 137 |
|
//$smarty->caching = true; |
| 138 |
|
// TODO: inherit global debugging option(s) here? |
| 139 |
|
//$smarty->debugging = true; |
| 140 |
|
// we declare "volatile" as a special namespace/cache key which is clean on each script-startup/reuse |
| 141 |
|
$smarty->clear_cache(null, "volatile"); |
| 142 |
|
//$site->smarty = &$smarty; |
| 143 |
|
$this->smarty = &$smarty; |
| 144 |
|
//$site->log( "init_site: smarty ready", PEAR_LOG_DEBUG); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
// LocaleText-class for language |
| 148 |
|
function _init_locales() { |
| 149 |
|
$this->log( get_class($this) . "->_init_lt: LocaleText starting", PEAR_LOG_DEBUG); |
| 150 |
|
|
| 151 |
|
$this->lt->start(); |
| 152 |
|
|
| 153 |
|
// Set locale according to chosen language (needed for date/time functions) |
| 154 |
|
// TODO: set this according to user's profile |
| 155 |
|
// TODO: make an flib/Application/l10n/Locale.php from this (available by doing e.g. an '$locale_key = $app->l10n->getLocaleKey()') |
| 156 |
|
// TODO: don't wire this to the locale-text setting |
| 157 |
|
// ---> actually wire the locale-text setting to $app->l10n->getLocaleKey() (the other way round....) |
| 158 |
|
$langkey = $this->localetext->getCurrentLanguage(); |
| 159 |
|
|
| 160 |
|
$ident = $_GET[x]; |
| 161 |
|
// fallback to post |
| 162 |
|
if (!$ident) { $ident = $_POST[x]; } |
| 163 |
|
|
| 164 |
|
if($langkey == "de") { |
| 165 |
|
if(($ident == '/terminal/deposit/' || $ident == '/terminal/ss_success/') && $this->session->get('validTerminal')) { |
| 166 |
|
if(!setlocale (LC_ALL, 'en_US')) { |
| 167 |
|
// needed at e.g. FreeBSD |
| 168 |
|
setlocale (LC_ALL, 'en_US.ISO_8859-1'); |
| 169 |
|
} |
| 170 |
|
} else { |
| 171 |
|
if(!setlocale (LC_ALL, 'de_DE')) { |
| 172 |
|
// needed at e.g. FreeBSD |
| 173 |
|
setlocale (LC_ALL, 'de_DE.ISO_8859-1'); |
| 174 |
|
} |
| 175 |
|
} |
| 176 |
|
} |
| 177 |
|
elseif($langkey == "en") { |
| 178 |
|
if(!setlocale (LC_ALL, 'en_US')) { |
| 179 |
|
// needed at e.g. FreeBSD |
| 180 |
|
setlocale (LC_ALL, 'en_US.ISO_8859-1'); |
| 181 |
|
} |
| 182 |
|
} |
| 183 |
|
elseif($langkey == "tr") { |
| 184 |
|
if(($ident == '/terminal/deposit/' || $ident == '/terminal/ss_success/') && $this->session->get('validTerminal')) { |
| 185 |
|
//if($_POST[xsend] && $this->session->get('validTerminal')) { |
| 186 |
|
if(!setlocale (LC_ALL, 'en_US')) { |
| 187 |
|
// needed at e.g. FreeBSD |
| 188 |
|
setlocale (LC_ALL, 'en_US.ISO_8859-1'); |
| 189 |
|
} |
| 190 |
|
} else { |
| 191 |
|
if(!setlocale (LC_ALL, 'tr_TR')) { |
| 192 |
|
// needed at e.g. FreeBSD |
| 193 |
|
setlocale (LC_ALL, 'tr_TR.ISO_8859-1'); |
| 194 |
|
} |
| 195 |
|
} |
| 196 |
|
} |
| 197 |
|
|
| 198 |
} |
} |
| 199 |
|
|
| 200 |
|
// ------------------------------------------------------------------------- |
| 201 |
// Dispatchers for all subobjects |
// Dispatchers for all subobjects |
| 202 |
// TODO: |
// TODO: |
| 203 |
// - make this much more generic |
// - make this much more generic |
| 227 |
return $this->request->getRequest(); |
return $this->request->getRequest(); |
| 228 |
} |
} |
| 229 |
|
|
| 230 |
|
function getLastRequest() { |
| 231 |
|
return $this->request->getCached(); |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
function cacheRequest($request = array()) { |
| 235 |
|
return $this->request->cacheRequest($request); |
| 236 |
|
} |
| 237 |
|
|
| 238 |
// dispatchers for Loader |
// dispatchers for Loader |
| 239 |
function &loadHandler($a) { |
function &loadHandler($a) { |
| 240 |
return $this->loader->loadHandler($a); |
return $this->loader->loadHandler($a); |
| 241 |
} |
} |
| 242 |
function &loadPage($a) { |
function &loadPage($a, $b = array()) { |
| 243 |
return $this->loader->loadPage($a); |
return $this->loader->loadPage($a, $b); |
| 244 |
|
} |
| 245 |
|
function &loadTemplate($a, $b = array(), $c = "") { |
| 246 |
|
return $this->loader->loadTemplate($a, $b, $c); |
| 247 |
} |
} |
| 248 |
|
|
| 249 |
// dispatchers for Http |
// dispatchers for Http |
| 274 |
return $site->user->isLoggedOn(); |
return $site->user->isLoggedOn(); |
| 275 |
} |
} |
| 276 |
|
|
| 277 |
function log($msg, $level) { |
function loadCmsPage($template, $data_merge = array()) { |
| 278 |
if ($this->logger) { |
|
| 279 |
$this->logger->log($msg, $level); |
//print Dumper($this->getRequest()); |
| 280 |
} else { |
|
| 281 |
// TODO: how are these type of errors handled? |
// default data to provide to scope of cms |
| 282 |
//print "error-message: $msg<br>"; |
// TODO/REVIEW: should we be more strict here? |
| 283 |
|
// e.g. just pass in '$site->config->url' or s.th.l.th. |
| 284 |
|
$data = array( |
| 285 |
|
'config' => $this->config, |
| 286 |
|
'request' => $this->getRequest(), |
| 287 |
|
); |
| 288 |
|
|
| 289 |
|
// merge in additional data |
| 290 |
|
foreach ($data_merge as $key => $val) { |
| 291 |
|
$data[$key] = $val; |
| 292 |
} |
} |
| 293 |
|
|
| 294 |
|
// load template |
| 295 |
|
$this->loadTemplate($template, $data); |
| 296 |
|
|
| 297 |
} |
} |
| 298 |
|
|
| 299 |
} |
} |