Globals, Session and Page object are now built by the Platal:: object.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 21 Jun 2008 16:23:23 +0000 (18:23 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 21 Jun 2008 16:23:23 +0000 (18:23 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/platal.php
classes/plpage.php
htdocs/xorg.php
include/globals.inc.php.in
include/xorg.inc.php
include/xorg/session.inc.php

index cbcca66..60c7902 100644 (file)
@@ -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:
index da24f3d..30a29b3 100644 (file)
@@ -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;
index 93226b9..3dc92b2 100644 (file)
  ***************************************************************************/
 
 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;
 }
 
index 2ddbcc1..23b6374 100644 (file)
@@ -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)
index ca92d7c..0be0ddd 100644 (file)
  *  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:
 ?>
index b3f66bf..8d86e93 100644 (file)
@@ -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()