--- nfo/php/libs/org.netfrag.flib/Site.php 2002/12/23 11:33:58 1.5 +++ nfo/php/libs/org.netfrag.flib/Site.php 2005/01/21 16:51:57 1.8 @@ -1,8 +1,18 @@ _mkEmbeddedObjects( array( parent_name => get_class($this), run => 'start', class_names => $class_names, ref_names => $ref_names ) ); + + var $children = array( + '_block1' => array( + 'Site_DebugBox', 'Site_Handler', 'Site_Request', 'Site_Loader', 'Site_Http', 'Site_Template' + ), + '_block2' => array( + 'User', 'Session', + ), + '_block3' => array( + 'LocaleText' => array( ref_names => array('lt'), run => '_'), + ), + ); + // this collects all/some stuff (object variables and methods) // from other (helper)-objects and acts as a dispatcher to them... // ...is this a bridge then? @@ -47,6 +74,7 @@ // - implement autoloading mechanism via php's overload // essentials (more or less) + var $configuration; // new - the configuration object (a Application::Config one....) var $config; // config ...is very essential (especially preboot stuff) var $logger; // logging? yea var $db; // the database handle (actually a PEAR::DB) @@ -62,18 +90,91 @@ var $session; var $user; - function Site(&$config) { + function Site(&$configObject) { + //print "Site
"; + //print Dumper($configObject); + parent::constructor(); // this will not work, logger is initialized two lines below - $this->log( get_class($this) . "->Site( config $config )", LOG_DEBUG ); - $this->config = $config; - $this->_init_logger(); - $this->_init_helpers(); - $this->_init_application(); + $this->log( get_class($this) . "->new", PEAR_LOG_DEBUG ); + $this->configuration = &$configObject; + $this->config = $this->configuration->get(); + //$this->_init_logger(); + $this->_init_session(); $this->_init_database(); $this->_init_smarty(); - $this->_init_lt(); + $this->_init_locales(); + } + + // ------------------------------------------------------------------------- + // Initializers for various things + // called on object instantiation by constructor + // + + function _init_session() { + global $site_state; + session_register_safe('site_state'); + if (!is_array($site_state)) { $site_state = array(); } + } + + function _init_smarty() { + $this->log( get_class($this) . "->_init_smarty()", PEAR_LOG_DEBUG ); + + // smarty (template engine) + $smarty = new Smarty; + $smarty->template_dir = $this->config[path][templates]; + $smarty->compile_dir = $this->config[path]["var"] . "smarty/templates_c/"; + $smarty->config_dir = $this->config[path]["var"] . "smarty/configs/"; + $smarty->cache_dir = $this->config[path]["var"] . "smarty/cache/"; + $smarty->compile_check = true; + + // trace + //print Dumper($smarty); + + //$smarty->caching = false; + //$smarty->caching = true; + // TODO: inherit global debugging option(s) here? + //$smarty->debugging = true; + // we declare "volatile" as a special namespace/cache key which is clean on each script-startup/reuse + $smarty->clear_cache(null, "volatile"); + //$site->smarty = &$smarty; + $this->smarty = &$smarty; + //$site->log( "init_site: smarty ready", PEAR_LOG_DEBUG); + } + + // LocaleText-class for language + function _init_locales() { + $this->log( get_class($this) . "->_init_lt: LocaleText starting", PEAR_LOG_DEBUG); + + $this->lt->start(); + + // Set locale according to chosen language (needed for date/time functions) + // TODO: set this according to user's profile + // TODO: make an flib/Application/l10n/Locale.php from this (available by doing e.g. an '$locale_key = $app->l10n->getLocaleKey()') + // TODO: don't wire this to the locale-text setting + // ---> actually wire the locale-text setting to $app->l10n->getLocaleKey() (the other way round....) + $langkey = $this->localetext->getCurrentLanguage(); + if($langkey == "de") { + if(!setlocale (LC_ALL, 'de_DE')) { + // needed at e.g. FreeBSD + setlocale (LC_ALL, 'de_DE.ISO_8859-1'); + } + } + elseif($langkey == "en") { + if(!setlocale (LC_ALL, 'en_US')) { + // needed at e.g. FreeBSD + setlocale (LC_ALL, 'en_US.ISO_8859-1'); + } + } + elseif($langkey == "tr") { + if(!setlocale (LC_ALL, 'tr_TR')) { + // needed at e.g. FreeBSD + setlocale (LC_ALL, 'tr_TR.ISO_8859-1'); + } + } + } + // ------------------------------------------------------------------------- // Dispatchers for all subobjects // TODO: // - make this much more generic @@ -150,15 +251,6 @@ return $site->user->isLoggedOn(); } - function log($msg, $level) { - if ($this->logger) { - $this->logger->log($msg, $level); - } else { - // TODO: how are these type of errors handled? - //print "error-message: $msg
"; - } - } - function loadCmsPage($template, $data_merge = array()) { //print Dumper($this->getRequest());