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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations)
Fri Jan 21 16:51:57 2005 UTC (19 years, 5 months ago) by jonen
Branch: MAIN
Changes since 1.7: +5 -2 lines
+ changed lang-key for turkish

1 <?
2 // -------------------------------------------------------------------------------
3 // $Id: Site.php,v 1.7 2004/11/15 17:24:50 jonen Exp $
4 // -------------------------------------------------------------------------------
5 // $Log: Site.php,v $
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
27 // + initial checkin
28 //
29 // Revision 1.3 2002/10/25 15:14:50 cvsjoko
30 // + generic logging mechanism via PEAR::Log
31 //
32 // Revision 1.2 2002/10/20 21:52:00 cvsmax
33 // + add new
34 // + function cacheThisRequest($request) # save current request in session
35 // + function getCachedRequest() # get cached request from session
36 //
37 // Revision 1.1 2002/10/09 00:42:50 cvsjoko
38 // + much code from "lib/menu/libnav.php.inc"
39 // -------------------------------------------------------------------------------
40
41
42 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 Application_AbstractBase {
48 //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)
65 // from other (helper)-objects and acts as a dispatcher to them...
66 // ...is this a bridge then?
67
68 // TODO:
69 // - "Request" depends on "Handler" for now ;(
70 // - application should croak if preboot doesn't exist inside config
71 // - implement autoloading mechanism via php's overload
72
73 // 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)
76 var $logger; // logging? yea
77 var $db; // the database handle (actually a PEAR::DB)
78 var $smarty; // a reference to a new smarty object, do templating stuff with that
79
80 // some helper objects
81 var $handler; // keeps track of handlers and identifiers
82 var $request; // takes care about the requests
83 var $loader; // loads various components (lib, page, file, etc.)
84 var $misc; // not needed yet, just wastes space
85
86 // some application objects
87 var $session;
88 var $user;
89
90 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
95 $this->log( get_class($this) . "->new", PEAR_LOG_DEBUG );
96 $this->configuration = &$configObject;
97 $this->config = $this->configuration->get();
98 //$this->_init_logger();
99 $this->_init_session();
100 $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 == "tr") {
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
176 // TODO:
177 // - make this much more generic
178 // - maybe use "aggregate" if it becomes available
179 // - there is some function to get given args to a function from inside it, use this perhaps
180 // - patch php to support multiple inheritance ;)
181
182 // dispatchers for Handler
183 function &encodeIdentifier($a) {
184 return $this->handler->encodeIdentifier($a);
185 }
186 function &decodeIdentifier($a) {
187 return $this->handler->decodeIdentifier($a);
188 }
189 function &getPageIdentifier() {
190 return $this->handler->getPageIdentifier();
191 }
192 function &setHandler($a, $b) {
193 return $this->handler->setHandler($a, $b);
194 }
195 function getHandler($a) {
196 return $this->handler->getHandler($a);
197 }
198
199 // dispatchers for Request
200 function getRequest() {
201 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
213 function &loadHandler($a) {
214 return $this->loader->loadHandler($a);
215 }
216 function &loadPage($a, $b = array()) {
217 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
224 function &redirect($a) {
225 return $this->http->redirect($a);
226 }
227
228
229
230 // TODO: throw these out!
231
232 function getLink($key, $attribs = array()) {
233 //dprint("getlink: " . dumpvar($attribs));
234 $ident = $this->encodeIdentifier($key);
235 // base url with ident
236 $url = $_SERVER[PHP_SELF] . '?' . 'x=' . $ident;
237 // additional arguments?
238 foreach ($attribs as $key => $value) {
239 $url .= '&' . $key . '=' . $value;
240 }
241 return $url;
242 }
243
244 function isAuthenticated() {
245 //global $uservars_db;
246 //return isset($uservars_db[status]);
247 global $site;
248 return $site->user->isLoggedOn();
249 }
250
251 function loadCmsPage($template, $data_merge = array()) {
252
253 //print Dumper($this->getRequest());
254
255 // default data to provide to scope of cms
256 // 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 }
274
275 ?>

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