--- nfo/php/libs/org.netfrag.flib/Site.php 2002/11/12 05:42:30 1.1 +++ nfo/php/libs/org.netfrag.flib/Site.php 2003/02/09 17:29:02 1.6 @@ -1,8 +1,25 @@ _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? @@ -34,6 +68,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) @@ -49,16 +84,82 @@ 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->_init_database(); + $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_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") { + setlocale (LC_ALL, 'de_DE'); + } + elseif($langkey == "en") { + setlocale (LC_ALL, 'en_US'); + } + elseif($langkey == "tr") { + setlocale (LC_ALL, 'tr_TR'); + } + + } + + // ------------------------------------------------------------------------- // Dispatchers for all subobjects // TODO: // - make this much more generic @@ -88,12 +189,23 @@ return $this->request->getRequest(); } + function getLastRequest() { + return $this->request->getCached(); + } + + function cacheRequest($request = array()) { + return $this->request->cacheRequest($request); + } + // dispatchers for Loader function &loadHandler($a) { return $this->loader->loadHandler($a); } - function &loadPage($a) { - return $this->loader->loadPage($a); + function &loadPage($a, $b = array()) { + return $this->loader->loadPage($a, $b); + } + function &loadTemplate($a, $b = array(), $c = "") { + return $this->loader->loadTemplate($a, $b, $c); } // dispatchers for Http @@ -124,13 +236,26 @@ 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()); + + // default data to provide to scope of cms + // TODO/REVIEW: should we be more strict here? + // e.g. just pass in '$site->config->url' or s.th.l.th. + $data = array( + 'config' => $this->config, + 'request' => $this->getRequest(), + ); + + // merge in additional data + foreach ($data_merge as $key => $val) { + $data[$key] = $val; } + + // load template + $this->loadTemplate($template, $data); + } }