Move and factorize code:
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 22 Jun 2008 21:18:37 +0000 (23:18 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 22 Jun 2008 21:18:37 +0000 (23:18 +0200)
* autoload => common.inc.php
* update_{DynamicConf} ==> PlatalGlobals
* update_NbNotifs ==> XorgSession

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
12 files changed:
classes/platalglobals.php.in
classes/xorgsession.php
include/common.inc.php [new file with mode: 0644]
include/notifs.inc.php
include/validations.inc.php
include/xnet.inc.php
include/xorg.inc.php
modules/admin.php
modules/carnet.php
modules/profile.php
modules/register.php
modules/xnetevents.php

index 1e15c81..409b68c 100644 (file)
@@ -38,8 +38,8 @@ class PlatalGlobals extends PlGlobals
     public function __construct()
     {
         parent::__construct(array('platal.ini', 'platal.conf'));
-        $this->bootstrap(array('NbIns'), 'update_NbIns');
-        $this->bootstrap(array('NbValid'), 'update_NbValid');
+        $this->bootstrap(array('NbIns'), array($this, 'updateNbIns'));
+        $this->bootstrap(array('NbValid'), array($this, 'updateNbValid'));
     }
 
     public function asso($key=null)
@@ -74,7 +74,29 @@ class PlatalGlobals extends PlGlobals
             return null;
         }
     }
+
+
+    public function updateNbIns()
+    {
+        $res = XDB::query("SELECT  COUNT(*)
+                             FROM  auth_user_md5
+                            WHERE  perms IN ('admin','user') AND deces=0");
+        $cnt = $res->fetchOneCell();
+        $this->changeDynamicConfig(array('NbIns' => $cnt));
+    }
+
+    public function updateNbValid()
+    {
+        $res = XDB::query("SELECT  COUNT(*)
+                             FROM  requests");
+        $this->changeDynamicConfig(array('NbValid' => $res->fetchOneCell()));
+    }
 }
 
+
+/******************************************************************************
+ * Dynamic configuration update/edition stuff
+ *****************************************************************************/
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
index 97e9a24..7cbaec4 100644 (file)
@@ -233,7 +233,7 @@ class XorgSession extends PlSession
         $this->makePerms($perms);
         $this->securityChecks();
         $this->setSkin();
-        update_NbNotifs();
+        $this->updateNbNotifs();
         check_redirect();
         return true;
     }
@@ -293,6 +293,14 @@ class XorgSession extends PlSession
     {
         return AUTH_MDP;
     }
+
+
+    public function updateNbNotifs()
+    {
+        require_once 'notifs.inc.php';
+        $n = select_notifs(false, S::i('uid'), S::v('watch_last'), false);
+        S::set('notifs', $n->numRows());
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
diff --git a/include/common.inc.php b/include/common.inc.php
new file mode 100644 (file)
index 0000000..35296b4
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+function __autoload($cls)
+{
+    if (!pl_autoload($cls)) {
+        $cls = strtolower($cls);
+        if (substr($cls, -3, 3) == 'req') {
+            @include 'validations.inc.php';
+            return;
+        } else if (substr($cls, 0, 6) == 'banana') {
+            require_once 'banana/banana.inc.php';
+            Banana::load(substr($cls, 6));
+            return;
+        }
+        @include "$cls.inc.php";
+    }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
index 33ae8eb..d48f010 100644 (file)
@@ -54,7 +54,7 @@ function register_watch_op($uid, $cid, $date='', $info='')
                              WHERE  ni_id={?}', $uid);
         XDB::execute('DELETE FROM watch_nonins WHERE ni_id={?}', $uid);
     }
-    update_NbNotifs();
+    Platal::session()->updateNbNotifs();
 }
 
 // }}}
index cf2f77c..12ec281 100644 (file)
@@ -117,7 +117,7 @@ abstract class Validate
                 $this->uid, $this->type, $this, $this->stamp);
 
         global $globals;
-        update_NbValid();
+        $globals->updateNbValid();
         return true;
     }
 
@@ -147,7 +147,7 @@ abstract class Validate
             $success =  XDB::execute('DELETE FROM requests WHERE user_id={?} AND type={?} AND stamp={?}',
                                       $this->uid, $this->type, $this->stamp);
         }
-        update_NbValid();
+        $globals->updateNbValid();
         return $success;
     }
 
index f3fc1a8..a8431e3 100644 (file)
@@ -24,22 +24,7 @@ define('PL_SESSION_CLASS', 'XnetSession');
 define('PL_PAGE_CLASS', 'XnetPage');
 
 require_once dirname(dirname(__FILE__)) . '/core/include/platal.inc.php';
-
-function __autoload($cls)
-{
-    $cls = strtolower($cls);
-    if (!pl_autoload($cls)) {
-        if (substr($cls, -3, 3) == 'req') {
-            @include 'validations.inc.php';
-            return;
-        } else if (substr($cls, 0, 6) == 'banana') {
-            require_once 'banana/banana.inc.php';
-            Banana::load(substr($cls, 6));
-            return;
-        }
-        @include "$cls.inc.php";
-    }
-}
+require_once 'common.inc.php';
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
index 8927aba..b67126b 100644 (file)
@@ -25,51 +25,7 @@ define('PL_PAGE_CLASS', 'XorgPage');
 
 require_once dirname(dirname(__FILE__)) . '/core/include/platal.inc.php';
 require_once 'security.inc.php';
-
-function __autoload($cls)
-{
-    $cls = strtolower($cls);
-    if (!pl_autoload($cls)) {
-        if (substr($cls, -3, 3) == 'req') {
-            @include 'validations.inc.php';
-            return;
-        } else if (substr($cls, 0, 6) == 'banana') {
-            require_once 'banana/banana.inc.php';
-            Banana::load(substr($cls, 6));
-            return;
-        }
-        @include "$cls.inc.php";
-    }
-}
-
-/******************************************************************************
- * Dynamic configuration update/edition stuff
- *****************************************************************************/
-
-function update_NbIns()
-{
-    global $globals;
-    $res = XDB::query("SELECT  COUNT(*)
-                         FROM  auth_user_md5
-                        WHERE  perms IN ('admin','user') AND deces=0");
-    $cnt = $res->fetchOneCell();
-    $globals->changeDynamicConfig(array('NbIns' => $cnt));
-}
-
-function update_NbValid()
-{
-    global $globals;
-    $res = XDB::query("SELECT  COUNT(*)
-                         FROM  requests");
-    $globals->changeDynamicConfig(array('NbValid' => $res->fetchOneCell()));
-}
-
-function update_NbNotifs()
-{
-    require_once 'notifs.inc.php';
-    $n = select_notifs(false, S::i('uid'), S::v('watch_last'), false);
-    $_SESSION['notifs'] = $n->numRows();
-}
+require_once 'common.inc.php';
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
index b4c8137..5ad1c2f 100644 (file)
@@ -578,7 +578,7 @@ class AdminModule extends PLModule
                             $mailer->send();
 
                             // update number of subscribers (perms or deceased may have changed)
-                            update_NbIns();
+                            $globals->updateNbIns();
 
                             $page->trigSuccess("updaté correctement.");
                         }
@@ -621,7 +621,7 @@ class AdminModule extends PLModule
                     case "u_kill":
                         user_clear_all_subs($mr['user_id']);
                         // update number of subscribers (perms or deceased may have changed)
-                        update_NbIns();
+                        $globals->updateNbIns();
                         $page->trigSuccess("'{$mr['user_id']}' a été désinscrit !");
                         $mailer = new PlMailer("admin/useredit.mail.tpl");
                         $mailer->assign("admin", S::v('forlife'));
@@ -968,7 +968,8 @@ class AdminModule extends PLModule
 
         // Update the count of item to validate here... useful in development configuration
         // where several copies of the site use the same DB, but not the same "dynamic configuration"
-        update_NbValid();
+        global $globals;
+        $globals->updateNbValid();
         $page->assign('vit', new ValidateIterator());
     }
 
index 345d56d..44a9336 100644 (file)
@@ -65,8 +65,8 @@ class CarnetModule extends PLModule
         $page->changeTpl('carnet/panel.tpl');
 
         if (Get::has('read')) {
-            $_SESSION['watch_last'] = Get::v('read');
-            update_NbNotifs();
+            S::set('watch_last', Get::v('read'));
+            Platal::session()->updateNbNotifs();
             pl_redirect('carnet/panel');
         }
 
index b6cd695..031493b 100644 (file)
@@ -125,6 +125,7 @@ class ProfileModule extends PLModule
 
     function handler_photo_change(&$page)
     {
+        global $globals;
         $page->changeTpl('profile/trombino.tpl');
 
         require_once('validations.inc.php');
@@ -158,12 +159,12 @@ class ProfileModule extends PLModule
             XDB::execute('DELETE FROM  requests
                                 WHERE  user_id = {?} AND type="photo"',
                          S::v('uid'));
-            update_NbValid();
+            $globals->updateNbValid();
         } elseif (Env::v('cancel')) {
             $sql = XDB::query('DELETE FROM  requests
                                      WHERE  user_id={?} AND type="photo"',
                               S::v('uid'));
-            update_NbValid();
+            $globals->updateNbValid();
         }
 
         $sql = XDB::query('SELECT  COUNT(*)
index a0d27dc..1276540 100644 (file)
@@ -317,7 +317,7 @@ class RegisterModule extends PLModule
         user_reindex($uid);
 
         // update number of subscribers (perms has changed)
-        update_NbIns();
+        $globals->updateNbIns();
 
         if (!start_connexion($uid, false)) {
             return PL_FORBIDDEN;
index 417fb3f..136e5b4 100644 (file)
@@ -97,7 +97,7 @@ class XnetEventsModule extends PLModule
             XDB::execute("DELETE FROM requests
                                     WHERE type = 'paiements' AND data LIKE {?}",
                                    PayReq::same_event($eid, $globals->asso('id')));
-            update_NbValid();
+            $globals->updateNbValid();
         }
 
         if ($action == 'archive') {