--- nfo/php/libs/org.netfrag.flib/Site.php 2002/11/12 05:42:30 1.1
+++ nfo/php/libs/org.netfrag.flib/Site.php 2005/08/11 14:07:45 1.9
@@ -1,8 +1,34 @@
// -------------------------------------------------------------------------------
-// $Id: Site.php,v 1.1 2002/11/12 05:42:30 joko Exp $
+// $Id: Site.php,v 1.9 2005/08/11 14:07:45 jonen Exp $
// -------------------------------------------------------------------------------
// $Log: Site.php,v $
+// Revision 1.9 2005/08/11 14:07:45 jonen
+// + added workaround for locale_number problem relating to generate Postscript files
+//
+// Revision 1.8 2005/01/21 16:51:57 jonen
+// + changed lang-key for turkish
+//
+// Revision 1.7 2004/11/15 17:24:50 jonen
+// + updated 'setlocale' for FreeBSD
+//
+// Revision 1.6 2003/02/09 17:29:02 joko
+// - refactored code to org.netfrag.glib/
+// + added startup code here (Site/Boot.php got purged)
+//
+// Revision 1.5 2002/12/23 11:33:58 jonen
+// + minor changes
+//
+// Revision 1.4 2002/12/19 16:25:29 joko
+// + function loadCmsPage($template, $data_merge = array())
+//
+// Revision 1.3 2002/12/19 06:17:32 joko
+// + database, smarty, and langtext (lt) now gets initialized here (on Site startup)
+//
+// Revision 1.2 2002/12/13 09:17:41 joko
+// + function getLastRequest
+// + function cacheRequest
+//
// Revision 1.1 2002/11/12 05:42:30 joko
// + initial checkin
//
@@ -19,11 +45,28 @@
// -------------------------------------------------------------------------------
-require_once 'Site/Boot.php';
+require_once 'Site/DebugBox.php';
+require_once 'Site/ExtHttp.php';
+require_once 'Site/Misc.php';
+require_once 'Site/Template.php';
-class Site extends Site_Boot {
+class Site extends Application_AbstractBase {
//class Site extends PEAR_Autoloader {
+ //$this->_mkEmbeddedObjects( array( parent_name => get_class($this), run => 'start', class_names => $class_names, ref_names => $ref_names ) );
+
+ var $children = array(
+ '_block1' => array(
+ 'Site_DebugBox', 'Site_Handler', 'Site_Request', 'Site_Loader', 'Site_Http', 'Site_Template'
+ ),
+ '_block2' => array(
+ 'User', 'Session',
+ ),
+ '_block3' => array(
+ 'LocaleText' => array( ref_names => array('lt'), run => '_'),
+ ),
+ );
+
// this collects all/some stuff (object variables and methods)
// from other (helper)-objects and acts as a dispatcher to them...
// ...is this a bridge then?
@@ -34,6 +77,7 @@
// - implement autoloading mechanism via php's overload
// essentials (more or less)
+ var $configuration; // new - the configuration object (a Application::Config one....)
var $config; // config ...is very essential (especially preboot stuff)
var $logger; // logging? yea
var $db; // the database handle (actually a PEAR::DB)
@@ -49,16 +93,111 @@
var $session;
var $user;
- function Site(&$config) {
+ function Site(&$configObject) {
+ //print "Site
";
+ //print Dumper($configObject);
+ parent::constructor();
// this will not work, logger is initialized two lines below
- $this->log( get_class($this) . "->Site( config $config )", LOG_DEBUG );
- $this->config = $config;
- $this->_init_logger();
- $this->_init_helpers();
- $this->_init_application();
- //$this->_init_database();
+ $this->log( get_class($this) . "->new", PEAR_LOG_DEBUG );
+ $this->configuration = &$configObject;
+ $this->config = $this->configuration->get();
+ //$this->_init_logger();
+ $this->_init_session();
+ $this->_init_database();
+ $this->_init_smarty();
+ $this->_init_locales();
+ }
+
+ // -------------------------------------------------------------------------
+ // Initializers for various things
+ // called on object instantiation by constructor
+ //
+
+ function _init_session() {
+ global $site_state;
+ session_register_safe('site_state');
+ if (!is_array($site_state)) { $site_state = array(); }
+ }
+
+ function _init_smarty() {
+ $this->log( get_class($this) . "->_init_smarty()", PEAR_LOG_DEBUG );
+
+ // smarty (template engine)
+ $smarty = new Smarty;
+ $smarty->template_dir = $this->config[path][templates];
+ $smarty->compile_dir = $this->config[path]["var"] . "smarty/templates_c/";
+ $smarty->config_dir = $this->config[path]["var"] . "smarty/configs/";
+ $smarty->cache_dir = $this->config[path]["var"] . "smarty/cache/";
+ $smarty->compile_check = true;
+
+ // trace
+ //print Dumper($smarty);
+
+ //$smarty->caching = false;
+ //$smarty->caching = true;
+ // TODO: inherit global debugging option(s) here?
+ //$smarty->debugging = true;
+ // we declare "volatile" as a special namespace/cache key which is clean on each script-startup/reuse
+ $smarty->clear_cache(null, "volatile");
+ //$site->smarty = &$smarty;
+ $this->smarty = &$smarty;
+ //$site->log( "init_site: smarty ready", PEAR_LOG_DEBUG);
+ }
+
+ // LocaleText-class for language
+ function _init_locales() {
+ $this->log( get_class($this) . "->_init_lt: LocaleText starting", PEAR_LOG_DEBUG);
+
+ $this->lt->start();
+
+ // Set locale according to chosen language (needed for date/time functions)
+ // TODO: set this according to user's profile
+ // TODO: make an flib/Application/l10n/Locale.php from this (available by doing e.g. an '$locale_key = $app->l10n->getLocaleKey()')
+ // TODO: don't wire this to the locale-text setting
+ // ---> actually wire the locale-text setting to $app->l10n->getLocaleKey() (the other way round....)
+ $langkey = $this->localetext->getCurrentLanguage();
+
+ $ident = $_GET[x];
+ // fallback to post
+ if (!$ident) { $ident = $_POST[x]; }
+
+ if($langkey == "de") {
+ if(($ident == '/terminal/deposit/' || $ident == '/terminal/ss_success/') && $this->session->get('validTerminal')) {
+ if(!setlocale (LC_ALL, 'en_US')) {
+ // needed at e.g. FreeBSD
+ setlocale (LC_ALL, 'en_US.ISO_8859-1');
+ }
+ } else {
+ if(!setlocale (LC_ALL, 'de_DE')) {
+ // needed at e.g. FreeBSD
+ setlocale (LC_ALL, 'de_DE.ISO_8859-1');
+ }
+ }
+ }
+ elseif($langkey == "en") {
+ if(!setlocale (LC_ALL, 'en_US')) {
+ // needed at e.g. FreeBSD
+ setlocale (LC_ALL, 'en_US.ISO_8859-1');
+ }
+ }
+ elseif($langkey == "tr") {
+ if(($ident == '/terminal/deposit/' || $ident == '/terminal/ss_success/') && $this->session->get('validTerminal')) {
+ //if($_POST[xsend] && $this->session->get('validTerminal')) {
+ if(!setlocale (LC_ALL, 'en_US')) {
+ // needed at e.g. FreeBSD
+ setlocale (LC_ALL, 'en_US.ISO_8859-1');
+ }
+ } else {
+ if(!setlocale (LC_ALL, 'tr_TR')) {
+ // needed at e.g. FreeBSD
+ setlocale (LC_ALL, 'tr_TR.ISO_8859-1');
+ }
+ }
+ }
+
}
+ // -------------------------------------------------------------------------
// Dispatchers for all subobjects
// TODO:
// - make this much more generic
@@ -88,12 +227,23 @@
return $this->request->getRequest();
}
+ function getLastRequest() {
+ return $this->request->getCached();
+ }
+
+ function cacheRequest($request = array()) {
+ return $this->request->cacheRequest($request);
+ }
+
// dispatchers for Loader
function &loadHandler($a) {
return $this->loader->loadHandler($a);
}
- function &loadPage($a) {
- return $this->loader->loadPage($a);
+ function &loadPage($a, $b = array()) {
+ return $this->loader->loadPage($a, $b);
+ }
+ function &loadTemplate($a, $b = array(), $c = "") {
+ return $this->loader->loadTemplate($a, $b, $c);
}
// dispatchers for Http
@@ -124,13 +274,26 @@
return $site->user->isLoggedOn();
}
- function log($msg, $level) {
- if ($this->logger) {
- $this->logger->log($msg, $level);
- } else {
- // TODO: how are these type of errors handled?
- //print "error-message: $msg
";
+ function loadCmsPage($template, $data_merge = array()) {
+
+//print Dumper($this->getRequest());
+
+ // default data to provide to scope of cms
+ // TODO/REVIEW: should we be more strict here?
+ // e.g. just pass in '$site->config->url' or s.th.l.th.
+ $data = array(
+ 'config' => $this->config,
+ 'request' => $this->getRequest(),
+ );
+
+ // merge in additional data
+ foreach ($data_merge as $key => $val) {
+ $data[$key] = $val;
}
+
+ // load template
+ $this->loadTemplate($template, $data);
+
}
}