/[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.7 - (show annotations)
Mon Nov 15 17:24:50 2004 UTC (19 years, 7 months ago) by jonen
Branch: MAIN
Changes since 1.6: +18 -5 lines
+ updated 'setlocale' for FreeBSD

1 <?
2 // -------------------------------------------------------------------------------
3 // $Id: Site.php,v 1.6 2003/02/09 17:29:02 joko Exp $
4 // -------------------------------------------------------------------------------
5 // $Log: Site.php,v $
6 // Revision 1.6 2003/02/09 17:29:02 joko
7 // - refactored code to org.netfrag.glib/
8 // + added startup code here (Site/Boot.php got purged)
9 //
10 // Revision 1.5 2002/12/23 11:33:58 jonen
11 // + minor changes
12 //
13 // Revision 1.4 2002/12/19 16:25:29 joko
14 // + function loadCmsPage($template, $data_merge = array())
15 //
16 // Revision 1.3 2002/12/19 06:17:32 joko
17 // + database, smarty, and langtext (lt) now gets initialized here (on Site startup)
18 //
19 // Revision 1.2 2002/12/13 09:17:41 joko
20 // + function getLastRequest
21 // + function cacheRequest
22 //
23 // Revision 1.1 2002/11/12 05:42:30 joko
24 // + initial checkin
25 //
26 // Revision 1.3 2002/10/25 15:14:50 cvsjoko
27 // + generic logging mechanism via PEAR::Log
28 //
29 // Revision 1.2 2002/10/20 21:52:00 cvsmax
30 // + add new
31 // + function cacheThisRequest($request) # save current request in session
32 // + function getCachedRequest() # get cached request from session
33 //
34 // Revision 1.1 2002/10/09 00:42:50 cvsjoko
35 // + much code from "lib/menu/libnav.php.inc"
36 // -------------------------------------------------------------------------------
37
38
39 require_once 'Site/DebugBox.php';
40 require_once 'Site/ExtHttp.php';
41 require_once 'Site/Misc.php';
42 require_once 'Site/Template.php';
43
44 class Site extends Application_AbstractBase {
45 //class Site extends PEAR_Autoloader {
46
47 //$this->_mkEmbeddedObjects( array( parent_name => get_class($this), run => 'start', class_names => $class_names, ref_names => $ref_names ) );
48
49 var $children = array(
50 '_block1' => array(
51 'Site_DebugBox', 'Site_Handler', 'Site_Request', 'Site_Loader', 'Site_Http', 'Site_Template'
52 ),
53 '_block2' => array(
54 'User', 'Session',
55 ),
56 '_block3' => array(
57 'LocaleText' => array( ref_names => array('lt'), run => '_'),
58 ),
59 );
60
61 // this collects all/some stuff (object variables and methods)
62 // from other (helper)-objects and acts as a dispatcher to them...
63 // ...is this a bridge then?
64
65 // TODO:
66 // - "Request" depends on "Handler" for now ;(
67 // - application should croak if preboot doesn't exist inside config
68 // - implement autoloading mechanism via php's overload
69
70 // essentials (more or less)
71 var $configuration; // new - the configuration object (a Application::Config one....)
72 var $config; // config ...is very essential (especially preboot stuff)
73 var $logger; // logging? yea
74 var $db; // the database handle (actually a PEAR::DB)
75 var $smarty; // a reference to a new smarty object, do templating stuff with that
76
77 // some helper objects
78 var $handler; // keeps track of handlers and identifiers
79 var $request; // takes care about the requests
80 var $loader; // loads various components (lib, page, file, etc.)
81 var $misc; // not needed yet, just wastes space
82
83 // some application objects
84 var $session;
85 var $user;
86
87 function Site(&$configObject) {
88 //print "Site<br>";
89 //print Dumper($configObject);
90 parent::constructor();
91 // this will not work, logger is initialized two lines below
92 $this->log( get_class($this) . "->new", PEAR_LOG_DEBUG );
93 $this->configuration = &$configObject;
94 $this->config = $this->configuration->get();
95 //$this->_init_logger();
96 $this->_init_session();
97 $this->_init_database();
98 $this->_init_smarty();
99 $this->_init_locales();
100 }
101
102 // -------------------------------------------------------------------------
103 // Initializers for various things
104 // called on object instantiation by constructor
105 //
106
107 function _init_session() {
108 global $site_state;
109 session_register_safe('site_state');
110 if (!is_array($site_state)) { $site_state = array(); }
111 }
112
113 function _init_smarty() {
114 $this->log( get_class($this) . "->_init_smarty()", PEAR_LOG_DEBUG );
115
116 // smarty (template engine)
117 $smarty = new Smarty;
118 $smarty->template_dir = $this->config[path][templates];
119 $smarty->compile_dir = $this->config[path]["var"] . "smarty/templates_c/";
120 $smarty->config_dir = $this->config[path]["var"] . "smarty/configs/";
121 $smarty->cache_dir = $this->config[path]["var"] . "smarty/cache/";
122 $smarty->compile_check = true;
123
124 // trace
125 //print Dumper($smarty);
126
127 //$smarty->caching = false;
128 //$smarty->caching = true;
129 // TODO: inherit global debugging option(s) here?
130 //$smarty->debugging = true;
131 // we declare "volatile" as a special namespace/cache key which is clean on each script-startup/reuse
132 $smarty->clear_cache(null, "volatile");
133 //$site->smarty = &$smarty;
134 $this->smarty = &$smarty;
135 //$site->log( "init_site: smarty ready", PEAR_LOG_DEBUG);
136 }
137
138 // LocaleText-class for language
139 function _init_locales() {
140 $this->log( get_class($this) . "->_init_lt: LocaleText starting", PEAR_LOG_DEBUG);
141
142 $this->lt->start();
143
144 // Set locale according to chosen language (needed for date/time functions)
145 // TODO: set this according to user's profile
146 // TODO: make an flib/Application/l10n/Locale.php from this (available by doing e.g. an '$locale_key = $app->l10n->getLocaleKey()')
147 // TODO: don't wire this to the locale-text setting
148 // ---> actually wire the locale-text setting to $app->l10n->getLocaleKey() (the other way round....)
149 $langkey = $this->localetext->getCurrentLanguage();
150 if($langkey == "de") {
151 if(!setlocale (LC_ALL, 'de_DE')) {
152 // needed at e.g. FreeBSD
153 setlocale (LC_ALL, 'de_DE.ISO_8859-1');
154 }
155 }
156 elseif($langkey == "en") {
157 if(!setlocale (LC_ALL, 'en_US')) {
158 // needed at e.g. FreeBSD
159 setlocale (LC_ALL, 'en_US.ISO_8859-1');
160 }
161 }
162 elseif($langkey == "tur") {
163 if(!setlocale (LC_ALL, 'tr_TR')) {
164 // needed at e.g. FreeBSD
165 setlocale (LC_ALL, 'tr_TR.ISO_8859-1');
166 }
167 }
168
169 }
170
171 // -------------------------------------------------------------------------
172 // Dispatchers for all subobjects
173 // TODO:
174 // - make this much more generic
175 // - maybe use "aggregate" if it becomes available
176 // - there is some function to get given args to a function from inside it, use this perhaps
177 // - patch php to support multiple inheritance ;)
178
179 // dispatchers for Handler
180 function &encodeIdentifier($a) {
181 return $this->handler->encodeIdentifier($a);
182 }
183 function &decodeIdentifier($a) {
184 return $this->handler->decodeIdentifier($a);
185 }
186 function &getPageIdentifier() {
187 return $this->handler->getPageIdentifier();
188 }
189 function &setHandler($a, $b) {
190 return $this->handler->setHandler($a, $b);
191 }
192 function getHandler($a) {
193 return $this->handler->getHandler($a);
194 }
195
196 // dispatchers for Request
197 function getRequest() {
198 return $this->request->getRequest();
199 }
200
201 function getLastRequest() {
202 return $this->request->getCached();
203 }
204
205 function cacheRequest($request = array()) {
206 return $this->request->cacheRequest($request);
207 }
208
209 // dispatchers for Loader
210 function &loadHandler($a) {
211 return $this->loader->loadHandler($a);
212 }
213 function &loadPage($a, $b = array()) {
214 return $this->loader->loadPage($a, $b);
215 }
216 function &loadTemplate($a, $b = array(), $c = "") {
217 return $this->loader->loadTemplate($a, $b, $c);
218 }
219
220 // dispatchers for Http
221 function &redirect($a) {
222 return $this->http->redirect($a);
223 }
224
225
226
227 // TODO: throw these out!
228
229 function getLink($key, $attribs = array()) {
230 //dprint("getlink: " . dumpvar($attribs));
231 $ident = $this->encodeIdentifier($key);
232 // base url with ident
233 $url = $_SERVER[PHP_SELF] . '?' . 'x=' . $ident;
234 // additional arguments?
235 foreach ($attribs as $key => $value) {
236 $url .= '&' . $key . '=' . $value;
237 }
238 return $url;
239 }
240
241 function isAuthenticated() {
242 //global $uservars_db;
243 //return isset($uservars_db[status]);
244 global $site;
245 return $site->user->isLoggedOn();
246 }
247
248 function loadCmsPage($template, $data_merge = array()) {
249
250 //print Dumper($this->getRequest());
251
252 // default data to provide to scope of cms
253 // TODO/REVIEW: should we be more strict here?
254 // e.g. just pass in '$site->config->url' or s.th.l.th.
255 $data = array(
256 'config' => $this->config,
257 'request' => $this->getRequest(),
258 );
259
260 // merge in additional data
261 foreach ($data_merge as $key => $val) {
262 $data[$key] = $val;
263 }
264
265 // load template
266 $this->loadTemplate($template, $data);
267
268 }
269
270 }
271
272 ?>

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