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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations)
Thu Aug 11 14:07:45 2005 UTC (18 years, 11 months ago) by jonen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +24 -1 lines
+ added workaround for locale_number problem relating to generate Postscript files

1 joko 1.1 <?
2     // -------------------------------------------------------------------------------
3 jonen 1.9 // $Id: Site.php,v 1.8 2005/01/21 16:51:57 jonen Exp $
4 joko 1.1 // -------------------------------------------------------------------------------
5 joko 1.2 // $Log: Site.php,v $
6 jonen 1.9 // Revision 1.8 2005/01/21 16:51:57 jonen
7     // + changed lang-key for turkish
8     //
9 jonen 1.8 // Revision 1.7 2004/11/15 17:24:50 jonen
10     // + updated 'setlocale' for FreeBSD
11     //
12 jonen 1.7 // 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 joko 1.6 // Revision 1.5 2002/12/23 11:33:58 jonen
17     // + minor changes
18     //
19 jonen 1.5 // Revision 1.4 2002/12/19 16:25:29 joko
20     // + function loadCmsPage($template, $data_merge = array())
21     //
22 joko 1.4 // Revision 1.3 2002/12/19 06:17:32 joko
23     // + database, smarty, and langtext (lt) now gets initialized here (on Site startup)
24     //
25 joko 1.3 // Revision 1.2 2002/12/13 09:17:41 joko
26     // + function getLastRequest
27     // + function cacheRequest
28     //
29 joko 1.2 // Revision 1.1 2002/11/12 05:42:30 joko
30     // + initial checkin
31     //
32 joko 1.1 // Revision 1.3 2002/10/25 15:14:50 cvsjoko
33     // + generic logging mechanism via PEAR::Log
34     //
35     // Revision 1.2 2002/10/20 21:52:00 cvsmax
36     // + add new
37     // + function cacheThisRequest($request) # save current request in session
38     // + function getCachedRequest() # get cached request from session
39     //
40     // Revision 1.1 2002/10/09 00:42:50 cvsjoko
41     // + much code from "lib/menu/libnav.php.inc"
42     // -------------------------------------------------------------------------------
43    
44    
45 joko 1.6 require_once 'Site/DebugBox.php';
46     require_once 'Site/ExtHttp.php';
47     require_once 'Site/Misc.php';
48     require_once 'Site/Template.php';
49 joko 1.1
50 joko 1.6 class Site extends Application_AbstractBase {
51 joko 1.1 //class Site extends PEAR_Autoloader {
52    
53 joko 1.6 //$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 joko 1.1 // this collects all/some stuff (object variables and methods)
68     // from other (helper)-objects and acts as a dispatcher to them...
69     // ...is this a bridge then?
70    
71     // TODO:
72     // - "Request" depends on "Handler" for now ;(
73     // - application should croak if preboot doesn't exist inside config
74     // - implement autoloading mechanism via php's overload
75    
76     // essentials (more or less)
77 joko 1.6 var $configuration; // new - the configuration object (a Application::Config one....)
78 joko 1.1 var $config; // config ...is very essential (especially preboot stuff)
79     var $logger; // logging? yea
80     var $db; // the database handle (actually a PEAR::DB)
81     var $smarty; // a reference to a new smarty object, do templating stuff with that
82    
83     // some helper objects
84     var $handler; // keeps track of handlers and identifiers
85     var $request; // takes care about the requests
86     var $loader; // loads various components (lib, page, file, etc.)
87     var $misc; // not needed yet, just wastes space
88    
89     // some application objects
90     var $session;
91     var $user;
92    
93 joko 1.6 function Site(&$configObject) {
94     //print "Site<br>";
95     //print Dumper($configObject);
96     parent::constructor();
97 joko 1.1 // this will not work, logger is initialized two lines below
98 joko 1.6 $this->log( get_class($this) . "->new", PEAR_LOG_DEBUG );
99     $this->configuration = &$configObject;
100     $this->config = $this->configuration->get();
101     //$this->_init_logger();
102     $this->_init_session();
103 joko 1.3 $this->_init_database();
104     $this->_init_smarty();
105 joko 1.6 $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 jonen 1.9
157     $ident = $_GET[x];
158     // fallback to post
159     if (!$ident) { $ident = $_POST[x]; }
160    
161 joko 1.6 if($langkey == "de") {
162 jonen 1.9 if(($ident == '/terminal/deposit/' || $ident == '/terminal/ss_success/') && $this->session->get('validTerminal')) {
163     if(!setlocale (LC_ALL, 'en_US')) {
164     // needed at e.g. FreeBSD
165     setlocale (LC_ALL, 'en_US.ISO_8859-1');
166     }
167     } else {
168 jonen 1.7 if(!setlocale (LC_ALL, 'de_DE')) {
169     // needed at e.g. FreeBSD
170     setlocale (LC_ALL, 'de_DE.ISO_8859-1');
171     }
172 jonen 1.9 }
173 joko 1.6 }
174     elseif($langkey == "en") {
175 jonen 1.7 if(!setlocale (LC_ALL, 'en_US')) {
176     // needed at e.g. FreeBSD
177     setlocale (LC_ALL, 'en_US.ISO_8859-1');
178     }
179 joko 1.6 }
180 jonen 1.8 elseif($langkey == "tr") {
181 jonen 1.9 if(($ident == '/terminal/deposit/' || $ident == '/terminal/ss_success/') && $this->session->get('validTerminal')) {
182     //if($_POST[xsend] && $this->session->get('validTerminal')) {
183     if(!setlocale (LC_ALL, 'en_US')) {
184     // needed at e.g. FreeBSD
185     setlocale (LC_ALL, 'en_US.ISO_8859-1');
186     }
187     } else {
188 jonen 1.7 if(!setlocale (LC_ALL, 'tr_TR')) {
189     // needed at e.g. FreeBSD
190     setlocale (LC_ALL, 'tr_TR.ISO_8859-1');
191     }
192 jonen 1.9 }
193 joko 1.6 }
194    
195 joko 1.1 }
196    
197 joko 1.6 // -------------------------------------------------------------------------
198 joko 1.1 // Dispatchers for all subobjects
199     // TODO:
200     // - make this much more generic
201     // - maybe use "aggregate" if it becomes available
202     // - there is some function to get given args to a function from inside it, use this perhaps
203     // - patch php to support multiple inheritance ;)
204    
205     // dispatchers for Handler
206     function &encodeIdentifier($a) {
207     return $this->handler->encodeIdentifier($a);
208     }
209     function &decodeIdentifier($a) {
210     return $this->handler->decodeIdentifier($a);
211     }
212     function &getPageIdentifier() {
213     return $this->handler->getPageIdentifier();
214     }
215     function &setHandler($a, $b) {
216     return $this->handler->setHandler($a, $b);
217     }
218     function getHandler($a) {
219     return $this->handler->getHandler($a);
220     }
221    
222     // dispatchers for Request
223     function getRequest() {
224     return $this->request->getRequest();
225 joko 1.2 }
226    
227     function getLastRequest() {
228     return $this->request->getCached();
229     }
230    
231     function cacheRequest($request = array()) {
232     return $this->request->cacheRequest($request);
233 joko 1.1 }
234    
235     // dispatchers for Loader
236     function &loadHandler($a) {
237     return $this->loader->loadHandler($a);
238     }
239 jonen 1.5 function &loadPage($a, $b = array()) {
240     return $this->loader->loadPage($a, $b);
241 joko 1.3 }
242     function &loadTemplate($a, $b = array(), $c = "") {
243     return $this->loader->loadTemplate($a, $b, $c);
244 joko 1.1 }
245    
246     // dispatchers for Http
247     function &redirect($a) {
248     return $this->http->redirect($a);
249     }
250    
251    
252    
253     // TODO: throw these out!
254    
255     function getLink($key, $attribs = array()) {
256     //dprint("getlink: " . dumpvar($attribs));
257     $ident = $this->encodeIdentifier($key);
258     // base url with ident
259     $url = $_SERVER[PHP_SELF] . '?' . 'x=' . $ident;
260     // additional arguments?
261     foreach ($attribs as $key => $value) {
262     $url .= '&' . $key . '=' . $value;
263     }
264     return $url;
265     }
266    
267     function isAuthenticated() {
268     //global $uservars_db;
269     //return isset($uservars_db[status]);
270     global $site;
271     return $site->user->isLoggedOn();
272 joko 1.4 }
273    
274     function loadCmsPage($template, $data_merge = array()) {
275    
276     //print Dumper($this->getRequest());
277    
278     // default data to provide to scope of cms
279     // TODO/REVIEW: should we be more strict here?
280     // e.g. just pass in '$site->config->url' or s.th.l.th.
281     $data = array(
282     'config' => $this->config,
283     'request' => $this->getRequest(),
284     );
285    
286     // merge in additional data
287     foreach ($data_merge as $key => $val) {
288     $data[$key] = $val;
289     }
290    
291     // load template
292     $this->loadTemplate($template, $data);
293    
294 joko 1.1 }
295    
296     }
297    
298     ?>

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