From abde67b15ea173b2fd8f5a194eb6e0f72d332661 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sat, 21 Jun 2008 18:23:23 +0200 Subject: [PATCH] Globals, Session and Page object are now built by the Platal:: object. Signed-off-by: Florent Bruneau --- classes/platal.php | 30 ++++++++++++++++++++++++------ classes/plpage.php | 3 +-- htdocs/xorg.php | 3 --- include/globals.inc.php.in | 3 ++- include/xorg.inc.php | 31 +++++++++++-------------------- include/xorg/session.inc.php | 4 ++++ 6 files changed, 42 insertions(+), 32 deletions(-) diff --git a/classes/platal.php b/classes/platal.php index cbcca66..60c7902 100644 --- a/classes/platal.php +++ b/classes/platal.php @@ -34,8 +34,17 @@ class Platal public $path; public $argv; + static private $_page = null; + public function __construct() { + global $platal, $globals, $session; + $platal =& $this; + $globalclass = PL_GLOBALS_CLASS; + $globals = new $globalclass(); + $sessionclass = PL_SESSION_CLASS; + $session = new $sessionclass(); + $modules = func_get_args(); if (is_array($modules[0])) { $modules = $modules[0]; @@ -237,7 +246,7 @@ class Platal if (empty($hook)) { return PL_NOT_FOUND; } - global $globals; + global $globals, $session; if ($this->https && !$_SERVER['HTTPS'] && $globals->core->secure_domain) { http_redirect('https://' . $globals->core->secure_domain . $_SERVER['REQUEST_URI']); } @@ -247,7 +256,7 @@ class Platal if ($hook['auth'] > S::v('auth', AUTH_PUBLIC)) { if ($hook['type'] & DO_AUTH) { - if (!call_user_func(array($globals->session, 'doAuth'))) { + if (!$session->doAuth()) { $this->force_login($page); } } else { @@ -261,7 +270,7 @@ class Platal $val = call_user_func_array($hook['hook'], $args); if ($val == PL_DO_AUTH) { // The handler need a better auth with the current args - if (!call_user_func(array($globals->session, 'doAuth'))) { + if (!$session->doAuth()) { $this->force_login($page); } $val = call_user_func_array($hook['hook'], $args); @@ -285,9 +294,7 @@ class Platal public function run() { - global $page; - - new_skinned_page('platal/index.tpl'); + $page =& self::page(); if (empty($this->path)) { $this->path = 'index'; @@ -317,6 +324,17 @@ class Platal call_user_func_array(array($mod, 'on_subscribe'), $args); } } + + static public function &page() + { + global $platal, $page; + if (is_null(self::$_page)) { + $pageclass = PL_PAGE_CLASS; + $page = new $pageclass(); + self::$_page =& $page; + } + return self::$_page; + } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/classes/plpage.php b/classes/plpage.php index da24f3d..30a29b3 100644 --- a/classes/plpage.php +++ b/classes/plpage.php @@ -31,7 +31,7 @@ abstract class PlPage extends Smarty // {{{ function PlPage() - public function __construct($tpl, $type = SKINNED) + public function __construct() { parent::Smarty(); @@ -47,7 +47,6 @@ abstract class PlPage extends Smarty $this->compile_check = !empty($globals->debug); - $this->changeTpl($tpl, $type); $this->_errors = array('errors' => array()); $this->_jsonVars = array(); $this->_failure = false; diff --git a/htdocs/xorg.php b/htdocs/xorg.php index 93226b9..3dc92b2 100644 --- a/htdocs/xorg.php +++ b/htdocs/xorg.php @@ -20,17 +20,14 @@ ***************************************************************************/ require_once dirname(__FILE__).'/../include/xorg.inc.php'; -global $globals, $platal, $page; if (!($path = Env::v('n')) || ($path{0} < 'A' || $path{0} > 'Z')) { - $platal = new Platal('auth', 'carnet', 'email', 'events', 'forums', 'geoloc', 'lists', 'marketing', 'payment', 'platal', 'profile', 'register', 'search', 'stats', 'admin', 'newsletter', 'axletter', 'bandeau', 'survey', 'gadgets', 'googleapps'); $platal->run(); - exit; } diff --git a/include/globals.inc.php.in b/include/globals.inc.php.in index 2ddbcc1..23b6374 100644 --- a/include/globals.inc.php.in +++ b/include/globals.inc.php.in @@ -43,8 +43,9 @@ class PlatalGlobals extends PlGlobals public function __construct($sess) { - $this->session = $sess; /* XXX Remove references to session from $globals */ parent::__construct(array('platal.ini', 'platal.conf')); + $globals->bootstrap(array('NbIns'), 'update_NbIns');i + $globals->bootstrap(array('NbValid'), 'update_NbValid'); } public function asso($key=null) diff --git a/include/xorg.inc.php b/include/xorg.inc.php index ca92d7c..0be0ddd 100644 --- a/include/xorg.inc.php +++ b/include/xorg.inc.php @@ -19,26 +19,31 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ +define('PL_GLOBALS_CLASS', 'PlatalGlobals'); +define('PL_SESSION_CLASS', 'XorgSession'); +define('PL_PAGE_CLASS', 'XorgPage'); + require_once('platal.inc.php'); require_once('globals.inc.php'); require_once('xorg/session.inc.php'); -$globals = new PlatalGlobals('XorgSession'); -$globals->bootstrap(array('NbIns'), 'update_NbIns'); -$globals->bootstrap(array('NbValid'), 'update_NbValid'); +$globals = new PlatalGlobals(); // {{{ class XorgPage class XorgPage extends PlPage { - public function __construct($tpl, $type = SKINNED) + public function __construct() { - parent::__construct($tpl, $type); + parent::__construct(); + + // Set the default page + $this->changeTpl('platal/index.tpl'); } public function run() { global $globals, $platal; - $this->assign('globals', $globals); + $this->assign_by_ref('globals', $globals); if (isset($platal) && $platal->path == 'register') { $skin = $globals->register_skin . ".tpl"; } else { @@ -48,19 +53,5 @@ class XorgPage extends PlPage } } -// {{{ function new_skinned_page() - -function new_skinned_page($tpl_name) -{ - global $page; - if (!$page instanceof XorgPage) { - $page = new XorgPage($tpl_name); - } else { - $page->changeTpl($tpl_name); - } -} - -XorgSession::init(); - // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/include/xorg/session.inc.php b/include/xorg/session.inc.php index b3f66bf..8d86e93 100644 --- a/include/xorg/session.inc.php +++ b/include/xorg/session.inc.php @@ -23,6 +23,10 @@ require_once 'xorg.misc.inc.php'; class XorgSession { + public function __construct() { + XorgSession::init(); + } + // {{{ public static function init public static function init() -- 2.1.4