--- nfo/php/libs/org.netfrag.flib/Site.php 2002/12/23 11:33:58 1.5
+++ nfo/php/libs/org.netfrag.flib/Site.php 2004/11/15 17:24:50 1.7
@@ -1,8 +1,15 @@
// -------------------------------------------------------------------------------
-// $Id: Site.php,v 1.5 2002/12/23 11:33:58 jonen Exp $
+// $Id: Site.php,v 1.7 2004/11/15 17:24:50 jonen Exp $
// -------------------------------------------------------------------------------
// $Log: Site.php,v $
+// Revision 1.7 2004/11/15 17:24:50 jonen
+// + updated 'setlocale' for FreeBSD
+//
+// Revision 1.6 2003/02/09 17:29:02 joko
+// - refactored code to org.netfrag.glib/
+// + added startup code here (Site/Boot.php got purged)
+//
// Revision 1.5 2002/12/23 11:33:58 jonen
// + minor changes
//
@@ -32,11 +39,28 @@
// -------------------------------------------------------------------------------
-require_once 'Site/Boot.php';
+require_once 'Site/DebugBox.php';
+require_once 'Site/ExtHttp.php';
+require_once 'Site/Misc.php';
+require_once 'Site/Template.php';
-class Site extends Site_Boot {
+class Site extends Application_AbstractBase {
//class Site extends PEAR_Autoloader {
+ //$this->_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 +71,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 +87,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 == "tur") {
+ 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 +248,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());