purge the nasty hooks \o/
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 30 Jul 2006 10:23:52 +0000 (10:23 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 30 Jul 2006 10:23:52 +0000 (10:23 +0000)
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

16 files changed:
classes/Platal.php
hooks/README [deleted file]
hooks/banana.inc.php [deleted file]
hooks/lists.inc.php [deleted file]
hooks/newsletter.inc.php [deleted file]
hooks/search.inc.php [deleted file]
hooks/tmp.inc.php [deleted file]
include/xnet/globals.inc.php
include/xorg/globals.inc.php
include/xorg/hook.inc.php [deleted file]
modules/banana.php
modules/carnet.php
modules/events.php
modules/lists.php
modules/register.php
modules/search.php

index 88e0650..72348a3 100644 (file)
@@ -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 (file)
index 5ae46ff..0000000
+++ /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 (file)
index 67b9851..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 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                *
- ***************************************************************************/
-
-// {{{ subscribe HOOK
-
-function banana_subscribe($forlife, $uid, $promo, $password)
-{
-    $cible = array('xorg.general','xorg.pa.emploi','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);
-    }
-}
-
-// }}}
-// 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 (file)
index 8123402..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 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                *
- ***************************************************************************/
-
-// {{{ subscribe HOOK
-
-function lists_subscribe($forlife, $uid, $promo, $password)
-{
-    require_once('lists.inc.php');
-    $client =& lists_xmlrpc($uid, $password);
-    $client->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 (file)
index ecd0baa..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 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                *
- ***************************************************************************/
-
-// {{{ subscribe HOOK
-
-function newsletter_subscribe($forlife, $uid, $promo, $password)
-{
-    require_once('newsletter.inc.php');
-    subscribe_nl($uid);
-}
-
-// }}}
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
-?>
diff --git a/hooks/search.inc.php b/hooks/search.inc.php
deleted file mode 100644 (file)
index aa82b04..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 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                *
- ***************************************************************************/
-
-// {{{ subscribe HOOK
-function search_subscribe($forlife, $uid, $promo, $pass)
-{
-    require_once('user.func.inc.php');
-    user_reindex($uid);
-}
-// }}}
-
-?>
diff --git a/hooks/tmp.inc.php b/hooks/tmp.inc.php
deleted file mode 100644 (file)
index def0722..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 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                *
- ***************************************************************************/
-
-// {{{ subscribe HOOK
-
-function tmp_subscribe($forlife, $uid, $promo, $password)
-{
-    require_once('notifs.inc.php');
-    register_watch_op($uid, WATCH_INSCR);
-    inscription_notifs_base($uid);
-}
-
-// }}}
-?>
index e1863d1..e661de0 100644 (file)
@@ -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();
 
index 2561df2..03ef9c5 100644 (file)
@@ -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 (file)
index 69ea5a1..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2006 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                *
- **************************************************************************/
-
-/**
- * XOrg's Hooks API
- *
- * Hooks are used in modules to allow modules that depends upon us to hook
- * themselves in our core functionnalities.
- *
- * Every module will use some hools, and define their names.
- * Pretend « myhook » is one of those names, then :
- *  - hooks/myhook/API has to exists, and will explain the API of the hook
- *  - every module "mod" may have a file hooks/myhook/mod.inc.php that implements
- *    fully or partially the API of the hook.
- *
- * If the hook's API has to change, the functions that change MUST change their
- * name to avoid any compatibility problem.
- *
- * @category XOrgCore
- * @package  XOrgCore
- * @author   Pierre Habouzit <pierre.habouzit@polytechnique.org>
- * @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:
-?>
index 63234c2..3441fb5 100644 (file)
@@ -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();
index 6d79e6d..6a9177a 100644 (file)
@@ -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')) {
index 8c13572..8fa4f28 100644 (file)
@@ -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');
index f8b9aa0..a9c452b 100644 (file)
@@ -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';
index 0c78846..9d32298 100644 (file)
@@ -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');
index fb14ea8..eb7c9f1 100644 (file)
@@ -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;