/[cvs]/nfo/php/libs/org.netfrag.flib/Site.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.flib/Site.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by jonen, Mon Dec 23 11:33:58 2002 UTC revision 1.8 by jonen, Fri Jan 21 16:51:57 2005 UTC
# Line 3  Line 3 
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  //    Revision 1.5  2002/12/23 11:33:58  jonen
17  //    + minor changes  //    + minor changes
18  //  //
# Line 32  Line 42 
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?
# Line 47  class Site extends Site_Boot { Line 74  class Site extends Site_Boot {
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)
# Line 62  class Site extends Site_Boot { Line 90  class Site extends Site_Boot {
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();      $this->_init_smarty();
105      $this->_init_lt();      $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
# Line 150  class Site extends Site_Boot { Line 251  class Site extends Site_Boot {
251      return $site->user->isLoggedOn();      return $site->user->isLoggedOn();
252    }    }
253        
   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<br>";  
     }  
   }  
     
254    function loadCmsPage($template, $data_merge = array()) {    function loadCmsPage($template, $data_merge = array()) {
255            
256  //print Dumper($this->getRequest());  //print Dumper($this->getRequest());

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.8

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed