/[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.6 - (show annotations)
Sun Feb 9 17:29:02 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
Changes since 1.5: +95 -19 lines
- refactored code to org.netfrag.glib/
+ added startup code here (Site/Boot.php got purged)

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

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