/[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.1 by joko, Tue Nov 12 05:42:30 2002 UTC revision 1.7 by jonen, Mon Nov 15 17:24:50 2004 UTC
# Line 3  Line 3 
3  //    $Id$  //    $Id$
4  //    -------------------------------------------------------------------------------  //    -------------------------------------------------------------------------------
5  //    $Log$  //    $Log$
6    //    Revision 1.7  2004/11/15 17:24:50  jonen
7    //    + updated 'setlocale' for FreeBSD
8    //
9    //    Revision 1.6  2003/02/09 17:29:02  joko
10    //    - refactored code to org.netfrag.glib/
11    //    + added startup code here (Site/Boot.php got purged)
12    //
13    //    Revision 1.5  2002/12/23 11:33:58  jonen
14    //    + minor changes
15    //
16    //    Revision 1.4  2002/12/19 16:25:29  joko
17    //    + function loadCmsPage($template, $data_merge = array())
18    //
19    //    Revision 1.3  2002/12/19 06:17:32  joko
20    //    + database, smarty, and langtext (lt) now gets initialized here (on Site startup)
21    //
22    //    Revision 1.2  2002/12/13 09:17:41  joko
23    //    + function getLastRequest
24    //    + function cacheRequest
25    //
26  //    Revision 1.1  2002/11/12 05:42:30  joko  //    Revision 1.1  2002/11/12 05:42:30  joko
27  //    + initial checkin  //    + initial checkin
28  //  //
# Line 19  Line 39 
39  //    -------------------------------------------------------------------------------  //    -------------------------------------------------------------------------------
40    
41    
42  require_once 'Site/Boot.php';  require_once 'Site/DebugBox.php';
43    require_once 'Site/ExtHttp.php';
44    require_once 'Site/Misc.php';
45    require_once 'Site/Template.php';
46    
47  class Site extends Site_Boot {  class Site extends Application_AbstractBase {
48  //class Site extends PEAR_Autoloader {  //class Site extends PEAR_Autoloader {
49    
50      //$this->_mkEmbeddedObjects( array( parent_name => get_class($this), run => 'start', class_names => $class_names, ref_names => $ref_names ) );
51    
52      var $children = array(
53        '_block1' => array(
54          'Site_DebugBox', 'Site_Handler', 'Site_Request', 'Site_Loader', 'Site_Http', 'Site_Template'
55        ),
56        '_block2' => array(
57          'User', 'Session',
58        ),
59        '_block3' => array(
60          'LocaleText' => array( ref_names => array('lt'), run => '_'),
61        ),
62      );
63    
64    // this collects all/some stuff (object variables and methods)    // this collects all/some stuff (object variables and methods)
65    // from other (helper)-objects and acts as a dispatcher to them...    // from other (helper)-objects and acts as a dispatcher to them...
66    // ...is this a bridge then?    // ...is this a bridge then?
# Line 34  class Site extends Site_Boot { Line 71  class Site extends Site_Boot {
71    // - implement autoloading mechanism via php's overload    // - implement autoloading mechanism via php's overload
72    
73    // essentials (more or less)    // essentials (more or less)
74      var $configuration;  // new - the configuration object (a Application::Config one....)
75    var $config;      // config  ...is very essential (especially preboot stuff)    var $config;      // config  ...is very essential (especially preboot stuff)
76    var $logger;     // logging? yea    var $logger;     // logging? yea
77    var $db;          // the database handle (actually a PEAR::DB)    var $db;          // the database handle (actually a PEAR::DB)
# Line 49  class Site extends Site_Boot { Line 87  class Site extends Site_Boot {
87    var $session;    var $session;
88    var $user;    var $user;
89    
90    function Site(&$config) {    function Site(&$configObject) {
91        //print "Site<br>";
92        //print Dumper($configObject);
93        parent::constructor();
94      // this will not work, logger is initialized two lines below      // this will not work, logger is initialized two lines below
95      $this->log( get_class($this) . "->Site( config $config )", LOG_DEBUG );      $this->log( get_class($this) . "->new", PEAR_LOG_DEBUG );
96      $this->config = $config;      $this->configuration = &$configObject;
97      $this->_init_logger();      $this->config = $this->configuration->get();
98      $this->_init_helpers();      //$this->_init_logger();
99      $this->_init_application();      $this->_init_session();
100      //$this->_init_database();      $this->_init_database();
101        $this->_init_smarty();
102        $this->_init_locales();
103      }
104    
105      // -------------------------------------------------------------------------
106      // Initializers for various things
107      //    called on object instantiation by constructor
108      //
109    
110      function _init_session() {
111        global $site_state;
112        session_register_safe('site_state');
113        if (!is_array($site_state)) { $site_state = array(); }
114      }
115      
116      function _init_smarty() {
117        $this->log( get_class($this) . "->_init_smarty()", PEAR_LOG_DEBUG );
118    
119        // smarty (template engine)
120          $smarty = new Smarty;
121          $smarty->template_dir = $this->config[path][templates];
122          $smarty->compile_dir = $this->config[path]["var"] . "smarty/templates_c/";
123          $smarty->config_dir = $this->config[path]["var"] . "smarty/configs/";
124          $smarty->cache_dir = $this->config[path]["var"] . "smarty/cache/";
125          $smarty->compile_check = true;
126    
127          // trace
128          //print Dumper($smarty);
129    
130          //$smarty->caching = false;
131          //$smarty->caching = true;
132          // TODO: inherit global debugging option(s) here?
133          //$smarty->debugging = true;
134          // we declare "volatile" as a special namespace/cache key which is clean on each script-startup/reuse
135          $smarty->clear_cache(null, "volatile");
136          //$site->smarty = &$smarty;
137          $this->smarty = &$smarty;
138          //$site->log( "init_site: smarty ready", PEAR_LOG_DEBUG);
139      }
140    
141      // LocaleText-class for language
142      function _init_locales() {
143         $this->log( get_class($this) . "->_init_lt: LocaleText starting", PEAR_LOG_DEBUG);
144        
145        $this->lt->start();
146    
147        // Set locale according to chosen language (needed for date/time functions)
148        // TODO: set this according to user's profile
149        // TODO: make an flib/Application/l10n/Locale.php from this (available by doing e.g. an '$locale_key = $app->l10n->getLocaleKey()')
150        // TODO: don't wire this to the locale-text setting
151        //             ---> actually wire the locale-text setting to $app->l10n->getLocaleKey()      (the other way round....)
152        $langkey = $this->localetext->getCurrentLanguage();
153        if($langkey == "de") {
154            if(!setlocale (LC_ALL, 'de_DE')) {
155              // needed at e.g. FreeBSD
156              setlocale (LC_ALL, 'de_DE.ISO_8859-1');
157            }
158        }
159        elseif($langkey == "en") {
160            if(!setlocale (LC_ALL, 'en_US')) {
161              // needed at e.g. FreeBSD
162              setlocale (LC_ALL, 'en_US.ISO_8859-1');
163            }
164        }
165        elseif($langkey == "tur") {
166            if(!setlocale (LC_ALL, 'tr_TR')) {
167              // needed at e.g. FreeBSD
168              setlocale (LC_ALL, 'tr_TR.ISO_8859-1');
169            }
170        }
171    
172    }    }
173    
174      // -------------------------------------------------------------------------
175    // Dispatchers for all subobjects    // Dispatchers for all subobjects
176      // TODO:      // TODO:
177      //    - make this much more generic      //    - make this much more generic
# Line 88  class Site extends Site_Boot { Line 201  class Site extends Site_Boot {
201      return $this->request->getRequest();      return $this->request->getRequest();
202    }    }
203    
204      function getLastRequest() {
205        return $this->request->getCached();
206      }
207    
208      function cacheRequest($request = array()) {
209        return $this->request->cacheRequest($request);
210      }
211    
212    // dispatchers for Loader    // dispatchers for Loader
213    function &loadHandler($a) {    function &loadHandler($a) {
214      return $this->loader->loadHandler($a);      return $this->loader->loadHandler($a);
215    }    }
216    function &loadPage($a) {    function &loadPage($a, $b = array()) {
217      return $this->loader->loadPage($a);      return $this->loader->loadPage($a, $b);
218      }
219      function &loadTemplate($a, $b = array(), $c = "") {
220        return $this->loader->loadTemplate($a, $b, $c);
221    }    }
222    
223    // dispatchers for Http    // dispatchers for Http
# Line 124  class Site extends Site_Boot { Line 248  class Site extends Site_Boot {
248      return $site->user->isLoggedOn();      return $site->user->isLoggedOn();
249    }    }
250        
251    function log($msg, $level) {    function loadCmsPage($template, $data_merge = array()) {
252      if ($this->logger) {      
253        $this->logger->log($msg, $level);  //print Dumper($this->getRequest());
254      } else {      
255        // TODO: how are these type of errors handled?      // default data to provide to scope of cms
256        //print "error-message: $msg<br>";      // TODO/REVIEW: should we be more strict here?
257        // e.g. just pass in '$site->config->url' or s.th.l.th.
258        $data = array(
259          'config' => $this->config,
260          'request' => $this->getRequest(),
261        );
262        
263        // merge in additional data
264        foreach ($data_merge as $key => $val) {
265          $data[$key] = $val;
266      }      }
267        
268        // load template
269        $this->loadTemplate($template, $data);
270        
271    }    }
272        
273  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.7

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