From 8d8f76072d8a363c3b24cfd0f2728bdc5754ec7f Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Sun, 30 Jul 2006 10:23:52 +0000 Subject: [PATCH] purge the nasty hooks \o/ replace it with some cross-module mechanism -> not tested *yet* git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@708 839d8a87-29fc-0310-9880-83ba4fa771e5 --- classes/Platal.php | 10 +++++ hooks/README | 10 ----- hooks/banana.inc.php | 54 --------------------------- hooks/lists.inc.php | 34 ----------------- hooks/newsletter.inc.php | 33 ---------------- hooks/search.inc.php | 30 --------------- hooks/tmp.inc.php | 32 ---------------- include/xnet/globals.inc.php | 2 - include/xorg/globals.inc.php | 2 - include/xorg/hook.inc.php | 89 -------------------------------------------- modules/banana.php | 27 ++++++++++++++ modules/carnet.php | 7 ++++ modules/events.php | 6 +++ modules/lists.php | 6 +++ modules/register.php | 3 +- modules/search.php | 6 +++ 16 files changed, 64 insertions(+), 287 deletions(-) delete mode 100644 hooks/README delete mode 100644 hooks/banana.inc.php delete mode 100644 hooks/lists.inc.php delete mode 100644 hooks/newsletter.inc.php delete mode 100644 hooks/search.inc.php delete mode 100644 hooks/tmp.inc.php delete mode 100644 include/xorg/hook.inc.php diff --git a/classes/Platal.php b/classes/Platal.php index 88e0650..72348a3 100644 --- a/classes/Platal.php +++ b/classes/Platal.php @@ -142,6 +142,16 @@ class Platal $page->assign_by_ref('platal', $this); $page->run(); } + + function on_subscribe($forlife, $uid, $promo, $pass) + { + $args = func_get_args(); + foreach ($this->__mods as $mod) { + if (!is_callable($mod, 'on_subscribe')) + continue; + call_user_func_array(array($mod, 'on_subscribe'), $args); + } + } } ?> diff --git a/hooks/README b/hooks/README deleted file mode 100644 index 5ae46ff..0000000 --- a/hooks/README +++ /dev/null @@ -1,10 +0,0 @@ -config() - function used to create new config entries in $globals. - usually, a module need to create a ....Config class to store the defaults. - -subscribe($forlife, $uid, $promo, $pass) - triggered when a user subscription is sucessfull - -prefs() - function used to add boxes in htdocs/preferences.php - must return a dictionnary : url, title, text, weight. diff --git a/hooks/banana.inc.php b/hooks/banana.inc.php deleted file mode 100644 index 67b9851..0000000 --- a/hooks/banana.inc.php +++ /dev/null @@ -1,54 +0,0 @@ -numRows()) { - $cible[] = $p_for; - } else { // pas de forum promo, il faut le créer - $res = XDB::query("SELECT SUM(perms IN ('admin','user') AND deces=0),COUNT(*) - FROM auth_user_md5 WHERE promo={?}", $promo); - list($effau, $effid) = $res->fetchOneRow(); - if (5*$effau>$effid) { // + de 20% d'inscrits - require_once("xorg.mailer.inc.php"); - $mymail = new XOrgMailer('mails/forums.promo.tpl'); - $mymail->assign('promo', $promo); - $mymail->send(); - } - } - - while (list ($key, $val) = each ($cible)) { - XDB::execute("INSERT INTO forums.abos (fid,uid) - SELECT fid,{?} FROM forums.list WHERE nom={?}", $uid, $val); - } -} - -// }}} - -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: -?> diff --git a/hooks/lists.inc.php b/hooks/lists.inc.php deleted file mode 100644 index 8123402..0000000 --- a/hooks/lists.inc.php +++ /dev/null @@ -1,34 +0,0 @@ -subscribe("promo$promo"); -} - -// }}} - -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: -?> diff --git a/hooks/newsletter.inc.php b/hooks/newsletter.inc.php deleted file mode 100644 index ecd0baa..0000000 --- a/hooks/newsletter.inc.php +++ /dev/null @@ -1,33 +0,0 @@ - diff --git a/hooks/search.inc.php b/hooks/search.inc.php deleted file mode 100644 index aa82b04..0000000 --- a/hooks/search.inc.php +++ /dev/null @@ -1,30 +0,0 @@ - diff --git a/hooks/tmp.inc.php b/hooks/tmp.inc.php deleted file mode 100644 index def0722..0000000 --- a/hooks/tmp.inc.php +++ /dev/null @@ -1,32 +0,0 @@ - diff --git a/include/xnet/globals.inc.php b/include/xnet/globals.inc.php index e1863d1..e661de0 100644 --- a/include/xnet/globals.inc.php +++ b/include/xnet/globals.inc.php @@ -31,11 +31,9 @@ class XnetGlobals extends PlatalGlobals function init() { global $globals; - require_once('xorg/hook.inc.php'); $globals = new XnetGlobals; $globals->core = new CoreConfig; - $globals->hook = new XOrgHook(); $globals->read_config(); diff --git a/include/xorg/globals.inc.php b/include/xorg/globals.inc.php index 2561df2..03ef9c5 100644 --- a/include/xorg/globals.inc.php +++ b/include/xorg/globals.inc.php @@ -31,11 +31,9 @@ class XorgGlobals extends PlatalGlobals function init() { global $globals; - require_once('xorg/hook.inc.php'); $globals = new XorgGlobals; $globals->core = new CoreConfig; - $globals->hook = new XOrgHook(); $globals->read_config(); diff --git a/include/xorg/hook.inc.php b/include/xorg/hook.inc.php deleted file mode 100644 index 69ea5a1..0000000 --- a/include/xorg/hook.inc.php +++ /dev/null @@ -1,89 +0,0 @@ - - * @access public - * @link http://doc.polytechnique.org/XOrgModule/#hook - * @since Classe available since 0.9.3 - */ -class XOrgHook -{ - // {{{ properties - - /** - * list of all the modules names that have implemented some reactions to our triggers - * - * @var array - * @access private - */ - var $_mods = Array(); - - // }}} - // {{{ constructor XOrgHook() - - /** - * Instanciates our Hook. - * - * @param string $name the name of the hook - */ - function XOrgHook() - { - global $globals; - - foreach (glob($globals->spoolroot."/hooks/*.inc.php") as $file) { - require_once("$file"); - $this->_mods[] = basename($file, '.inc.php'); - } - } - - // }}} - // {{{ function subscribe - - function subscribe($forlife, $uid, $promo, $pass) - { - foreach ($this->_mods as $mod) { - if (!function_exists($mod.'_subscribe')) continue; - call_user_func($mod.'_subscribe', $forlife, $uid, $promo, $pass); - } - } - - // }}} -} - -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: -?> diff --git a/modules/banana.php b/modules/banana.php index 63234c2..3441fb5 100644 --- a/modules/banana.php +++ b/modules/banana.php @@ -31,6 +31,33 @@ class BananaModule extends PLModule ); } + function on_subscribe($forlife, $uid, $promo, $password) + { + $cible = array('xorg.general', 'xorg.pa.divers', 'xorg.pa.logements'); + $p_for = "xorg.promo.x$promo"; + + // récupération de l'id du forum promo + $res = XDB::query("SELECT fid FROM forums.list WHERE nom={?}", $p_for); + if ($res->numRows()) { + $cible[] = $p_for; + } else { // pas de forum promo, il faut le créer + $res = XDB::query("SELECT SUM(perms IN ('admin','user') AND deces=0),COUNT(*) + FROM auth_user_md5 WHERE promo={?}", $promo); + list($effau, $effid) = $res->fetchOneRow(); + if (5*$effau>$effid) { // + de 20% d'inscrits + require_once("xorg.mailer.inc.php"); + $mymail = new XOrgMailer('mails/forums.promo.tpl'); + $mymail->assign('promo', $promo); + $mymail->send(); + } + } + + while (list ($key, $val) = each ($cible)) { + XDB::execute("INSERT INTO forums.abos (fid,uid) + SELECT fid,{?} FROM forums.list WHERE nom={?}", $uid, $val); + } + } + function handler_banana(&$page, $group = null, $action = null, $artid = null) { $get = Array(); diff --git a/modules/carnet.php b/modules/carnet.php index 6d79e6d..6a9177a 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -36,6 +36,13 @@ class CarnetModule extends PLModule ); } + function on_subscribe($forlife, $uid, $promo, $password) + { + require_once 'notifs.inc.php'; + register_watch_op($uid, WATCH_INSCR); + inscription_notifs_base($uid); + } + function _add_rss_link(&$page) { if (!S::has('core_rss_hash')) { diff --git a/modules/events.php b/modules/events.php index 8c13572..8fa4f28 100644 --- a/modules/events.php +++ b/modules/events.php @@ -37,6 +37,12 @@ class EventsModule extends PLModule ); } + function on_subscribe($forlife, $uid, $promo, $password) + { + require_once 'newsletter.inc.php'; + subscribe_nl($uid); + } + function handler_ev(&$page) { $page->changeTpl('login.tpl'); diff --git a/modules/lists.php b/modules/lists.php index f8b9aa0..a9c452b 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -44,6 +44,12 @@ class ListsModule extends PLModule ); } + function on_subscribe($forlife, $uid, $promo, $password) + { + $this->prepare_client(null); + $this->client->subscribe("promo$promo"); + } + function prepare_client(&$page) { require_once 'lists.inc.php'; diff --git a/modules/register.php b/modules/register.php index 0c78846..9d32298 100644 --- a/modules/register.php +++ b/modules/register.php @@ -254,7 +254,8 @@ class RegisterModule extends PLModule XDB::execute('UPDATE register_pending SET hash="INSCRIT" WHERE uid={?}', $uid); - $globals->hook->subscribe($forlife, $uid, $promo, $password); + global $platal; + $platal->on_subscribe($forlife, $uid, $promo, $password); require_once('xorg.mailer.inc.php'); $mymail = new XOrgMailer('register/inscription.reussie.tpl'); diff --git a/modules/search.php b/modules/search.php index fb14ea8..eb7c9f1 100644 --- a/modules/search.php +++ b/modules/search.php @@ -29,6 +29,12 @@ class SearchModule extends PLModule ); } + function on_subscribe($forlife, $uid, $promo, $pass) + { + require_once 'user.func.inc.php'; + user_reindex($uid); + } + function get_quick($offset, $limit, $order) { global $globals; -- 2.1.4