From ebfdf077d5789f9dae13e913d5cc23937ce2a9d2 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 22 Jun 2008 23:18:37 +0200 Subject: [PATCH] =?utf8?q?Move=20and=20factorize=20code:=20*=20autoload=20?= =?utf8?q?=3D>=20common.inc.php=20*=20update=5F{DynamicConf}=C2=A0=3D=3D>?= =?utf8?q?=20PlatalGlobals=20*=20update=5FNbNotifs=20=3D=3D>=20XorgSession?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Florent Bruneau --- classes/platalglobals.php.in | 26 +++++++++++++++++++++++-- classes/xorgsession.php | 10 +++++++++- include/common.inc.php | 39 +++++++++++++++++++++++++++++++++++++ include/notifs.inc.php | 2 +- include/validations.inc.php | 4 ++-- include/xnet.inc.php | 17 +--------------- include/xorg.inc.php | 46 +------------------------------------------- modules/admin.php | 7 ++++--- modules/carnet.php | 4 ++-- modules/profile.php | 5 +++-- modules/register.php | 2 +- modules/xnetevents.php | 2 +- 12 files changed, 88 insertions(+), 76 deletions(-) create mode 100644 include/common.inc.php diff --git a/classes/platalglobals.php.in b/classes/platalglobals.php.in index 1e15c81..409b68c 100644 --- a/classes/platalglobals.php.in +++ b/classes/platalglobals.php.in @@ -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: ?> diff --git a/classes/xorgsession.php b/classes/xorgsession.php index 97e9a24..7cbaec4 100644 --- a/classes/xorgsession.php +++ b/classes/xorgsession.php @@ -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 index 0000000..35296b4 --- /dev/null +++ b/include/common.inc.php @@ -0,0 +1,39 @@ + diff --git a/include/notifs.inc.php b/include/notifs.inc.php index 33ae8eb..d48f010 100644 --- a/include/notifs.inc.php +++ b/include/notifs.inc.php @@ -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(); } // }}} diff --git a/include/validations.inc.php b/include/validations.inc.php index cf2f77c..12ec281 100644 --- a/include/validations.inc.php +++ b/include/validations.inc.php @@ -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; } diff --git a/include/xnet.inc.php b/include/xnet.inc.php index f3fc1a8..a8431e3 100644 --- a/include/xnet.inc.php +++ b/include/xnet.inc.php @@ -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: ?> diff --git a/include/xorg.inc.php b/include/xorg.inc.php index 8927aba..b67126b 100644 --- a/include/xorg.inc.php +++ b/include/xorg.inc.php @@ -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: ?> diff --git a/modules/admin.php b/modules/admin.php index b4c8137..5ad1c2f 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -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()); } diff --git a/modules/carnet.php b/modules/carnet.php index 345d56d..44a9336 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -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'); } diff --git a/modules/profile.php b/modules/profile.php index b6cd695..031493b 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -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(*) diff --git a/modules/register.php b/modules/register.php index a0d27dc..1276540 100644 --- a/modules/register.php +++ b/modules/register.php @@ -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; diff --git a/modules/xnetevents.php b/modules/xnetevents.php index 417fb3f..136e5b4 100644 --- a/modules/xnetevents.php +++ b/modules/xnetevents.php @@ -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') { -- 2.1.4