make mmlist be a derived class from xlmrpcclient, that's way more pretty,
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 22 Oct 2006 22:34:28 +0000 (22:34 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 22 Oct 2006 22:34:28 +0000 (22:34 +0000)
and uses the autoload code.

lists.inc.php can now be a private include from the list module *YEAH*.

remove ugly includes to that file.

count(GLOBAL_INCLUDES)--

 include/user.func.inc.php          |    9 ++------
 include/validations/listes.inc.php |   12 ++++-------
 modules/auth.php                   |    6 +----
 modules/lists.php                  |   13 ++++--------
 modules/profile.php                |    5 +---
 modules/xnet.php                   |    7 ++----
 modules/xnetgrp.php                |   38 +++++++++++++++----------------------
 modules/xnetlists.php              |    7 ++----
 8 files changed, 39 insertions(+), 58 deletions(-)

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1013 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/mmlist.php [new file with mode: 0644]
include/user.func.inc.php
include/validations/listes.inc.php
modules/auth.php
modules/lists.php
modules/lists/lists.inc.php [moved from include/lists.inc.php with 91% similarity]
modules/profile.php
modules/xnet.php
modules/xnetgrp.php
modules/xnetlists.php

diff --git a/classes/mmlist.php b/classes/mmlist.php
new file mode 100644 (file)
index 0000000..504d8bb
--- /dev/null
@@ -0,0 +1,39 @@
+<?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                *
+ ***************************************************************************/
+
+class MMList extends XmlrpcClient
+{
+    function __construct($uid, $pass, $fqdn = null)
+    {
+        global $globals;
+
+        $dom = is_null($fqdn) ? $globals->mail->domain : $fqdn;
+        $url = "http://$uid:$pass@{$globals->lists->rpchost}:{$globals->lists->rpcport}/$dom";
+        parent::__construct($url);
+    }
+
+    function __call($method, $args)
+    {
+        return parent::__call($method, $args);
+    }
+}
+
+?>
index f5af491..d0fe12e 100644 (file)
@@ -57,12 +57,9 @@ function user_clear_all_subs($user_id, $really_del=true)
     XDB::execute("DELETE FROM requests        WHERE user_id={?}", $uid);
     XDB::execute("DELETE FROM user_changes    WHERE user_id={?}", $uid);
     XDB::execute("DELETE FROM watch_sub       WHERE uid={?}", $uid);
-    
-    include_once('lists.inc.php');
-    if (function_exists(lists_xmlrpc)) {
-        $client =& lists_xmlrpc(S::v('id'), S::v('password'));
-        $client->kill($alias, $really_del);
-    }
+
+    $mmlist = new MMList(S::v('id'), S::v('password'));
+    $mmlist->kill($alias, $really_del);
 }
 
 // }}}
index 956e135..1152185 100644 (file)
@@ -101,15 +101,13 @@ class ListeReq extends Validate
 
     // }}}
     // {{{ function commit()
-    
+
     function commit()
     {
-        require_once 'lists.inc.php';
-
-        $client =& lists_xmlrpc(S::v('uid'), S::v('password'));
-        $ret = $client->create_list($this->liste, $this->desc,
-            $this->advertise, $this->modlevel, $this->inslevel,
-            $this->owners, $this->members);
+        $list = new List(S::v('uid'), S::v('password'));
+        $ret = $list->create_list($this->liste, $this->desc, $this->advertise,
+                                  $this->modlevel, $this->inslevel,
+                                  $this->owners, $this->members);
         $liste = strtolower($this->liste);
         if ($ret) {
             foreach(Array($liste, $liste."-owner", $liste."-admin", $liste."-bounces") as $l) {
index 8bd9069..dae0153 100644 (file)
@@ -49,8 +49,6 @@ class AuthModule extends PLModule
     {
         global $globals;
 
-        require_once 'lists.inc.php';
-
         $cle = $globals->core->econfiance;
 
         if (S::v('chall') && $_GET['PASS'] == md5(S::v('chall').$cle)) {
@@ -58,8 +56,8 @@ class AuthModule extends PLModule
             $res  = XDB::query("SELECT password FROM auth_user_md5 WHERE user_id=10154");
             $pass = $res->fetchOneCell();
 
-            $client =& lists_xmlrpc(10154, $pass, "x-econfiance.polytechnique.org");
-            $members = $client->get_members('membres');
+            $list = new MMList(10154, $pass, "x-econfiance.polytechnique.org");
+            $members = $list->get_members('membres');
             if (is_array($members)) {
                 $membres = Array();
                 foreach($members[1] as $member) {
index f31b51b..4fd6b00 100644 (file)
@@ -54,9 +54,9 @@ class ListsModule extends PLModule
     {
         global $globals;
 
-        require_once 'lists.inc.php';
+        require_once dirname(__FILE__).'/lists/lists.inc.php';
 
-        $this->client =& lists_xmlrpc(S::v('uid'), S::v('password'));
+        $this->client = new MMList(S::v('uid'), S::v('password'));
         return $globals->mail->domain;
     }
 
@@ -465,7 +465,6 @@ class ListsModule extends PLModule
         }
 
         if (list($det,$mem,$own) = $this->client->get_members($liste)) {
-
             $membres = list_sort_members($mem, $tri_promo);
             $moderos = list_sort_owners($own, $tri_promo);
 
@@ -609,13 +608,11 @@ class ListsModule extends PLModule
     function handler_admin_all(&$page) {
         $page->changeTpl('listes/admin_all.tpl');
         $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
-        require_once 'lists.inc.php';
-        
-        $client =& lists_xmlrpc(S::v('uid'), S::v('password'));
+
+        $client = new MMList(S::v('uid'), S::v('password'));
         $listes = $client->get_all_lists();
-        $page->assign_by_ref('listes',$listes);
+        $page->assign_by_ref('listes', $listes);
     }
-    
 }
 
 ?>
similarity index 91%
rename from include/lists.inc.php
rename to modules/lists/lists.inc.php
index 8e1b5fb..6382e7d 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-// {{{ function lists_xmlrpc
-
-function &lists_xmlrpc($uid, $pass, $fqdn=null)
-{
-    global $globals;
-
-    $dom = is_null($fqdn) ? $globals->mail->domain : $fqdn;
-    $url = "http://$uid:$pass@{$globals->lists->rpchost}:{$globals->lists->rpcport}/$dom";
-    $client = new XmlrpcClient($url);
-    return $client;
-}
-
-// }}}
 // {{{ function list_sort_owners
 
 function list_sort_owners(&$members, $tri_promo = true) {
@@ -91,5 +78,4 @@ function list_header_decode($value) {
 }
 
 // }}}
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index d3a5530..cd4bc6b 100644 (file)
@@ -271,9 +271,8 @@ class ProfileModule extends PLModule
             XDB::execute('REPLACE INTO groupex.membres (uid,asso_id)
                                      VALUES ({?}, {?})',
                                  S::v('uid'), $asso_id);
-            require_once 'lists.inc.php';
-            $client =& lists_xmlrpc(S::v('uid'), S::v('password'));
-            $client->subscribe("promo".S::v('promo'));
+            $mmlist = new MMList(S::v('uid'), S::v('password'));
+            $mmlist->subscribe("promo".S::v('promo'));
         }
 
         if (is_ax_key_missing()) {
index c36cf59..5427a27 100644 (file)
@@ -74,11 +74,10 @@ class XnetModule extends PLModule
                                                 WHERE  alias LIKE {?}', '%@'.$domain);
                     $page->trig('suppression des alias mails');
 
-                    require_once('lists.inc.php');
-                    $client =& lists_xmlrpc(S::v('uid'), S::v('password'), $domain);
-                    if ($listes = $client->get_lists()) {
+                    $mmlist = new MMList(S::v('uid'), S::v('password'), $domain);
+                    if ($listes = $mmlist->get_lists()) {
                         foreach ($listes as $l) {
-                            $client->delete_list($l['list'], true);
+                            $mmlist->delete_list($l['list'], true);
                         }
                         $page->trig('mail lists surpprimées');
                     }
index 0b3dc7d..a287dc5 100644 (file)
@@ -199,13 +199,10 @@ class XnetGrpModule extends PLModule
     {
         global $globals;
 
-        require_once 'lists.inc.php';
-
         new_groupadmin_page('xnet/groupe/mail.tpl');
-        $client =& lists_xmlrpc(S::v('uid'),
-                                S::v('password'),
-                                $globals->asso('mail_domain'));
-        $page->assign('listes', $client->get_lists());
+        $mmlist = new MMList(S::v('uid'), S::v('password'),
+                           $globals->asso('mail_domain'));
+        $page->assign('listes', $mmlist->get_lists());
 
         if (Post::has('send')) {
             $from  = Post::v('from');
@@ -215,7 +212,7 @@ class XnetGrpModule extends PLModule
             $mls = array_keys(Env::v('ml', array()));
 
             require_once 'xnet/mail.inc.php';
-            $tos = get_all_redirects(Post::has('membres'), $mls, $client);
+            $tos = get_all_redirects(Post::has('membres'), $mls, $mmlist);
             send_xnet_mails($from, $sujet, $body, $tos, Post::v('replyto'));
             $page->kill("Mail envoyé !");
             $page->assign('sent', true);
@@ -545,20 +542,19 @@ class XnetGrpModule extends PLModule
     {
         global $globals;
 
-        require_once 'lists.inc.php';
         require_once 'xnet/mail.inc.php';
 
         new_groupadmin_page('xnet/groupe/annuaire-admin.tpl');
-        $client =& lists_xmlrpc(S::v('uid'), S::v('password'),
-                                $globals->asso('mail_domain'));
-        $lists  = $client->get_lists();
+        $mmlist = new MMList(S::v('uid'), S::v('password'),
+                             $globals->asso('mail_domain'));
+        $lists  = $mmlist->get_lists();
         if (!$lists) $lists = array();
         $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists);
 
         $subscribers = array();
 
         foreach ($listes as $list) {
-            list(,$members) = $client->get_members($list);
+            list(,$members) = $mmlist->get_members($list);
             $mails = array_map(create_function('$arr', 'return $arr[1];'), $members);
             $subscribers = array_unique(array_merge($subscribers, $mails));
         }
@@ -655,13 +651,12 @@ class XnetGrpModule extends PLModule
 
         if (($domain = $globals->asso('mail_domain')) && empty($user_same_email)) {
 
-            require 'lists.inc.php';
-            $client =& lists_xmlrpc(S::v('uid'), S::v('password'), $domain);
-            $listes = $client->get_lists($user['email2']);
+            $mmlist = new MMList(S::v('uid'), S::v('password'), $domain);
+            $listes = $mmlist->get_lists($user['email2']);
 
             foreach ($listes as $liste) {
                 if ($liste['sub'] == 2) {
-                    $client->mass_unsubscribe($liste['list'], Array($user['email2']));
+                    $mmlist->mass_unsubscribe($liste['list'], Array($user['email2']));
                     $page->trig("{$user['prenom']} {$user['nom']} a été"
                                 ." désinscrit de {$liste['list']}");
                 } elseif ($liste['sub']) {
@@ -695,9 +690,8 @@ class XnetGrpModule extends PLModule
             return PL_NOT_FOUND;
         }
 
-        require 'lists.inc.php';
-        $client =& lists_xmlrpc(S::v('uid'), S::v('password'),
-                                $globals->asso('mail_domain'));
+        $mmlist = new MMList(S::v('uid'), S::v('password'),
+                             $globals->asso('mail_domain'));
 
         if (Post::has('change')) {
             if ($user['origine'] != 'X') {
@@ -732,10 +726,10 @@ class XnetGrpModule extends PLModule
                                ."actuellement une demande d'inscription en "
                                ."cours sur <strong>$ml@</strong> !!!");
                 } elseif ($ask) {
-                    $client->mass_subscribe($ml, Array($user['email2']));
+                    $mmlist->mass_subscribe($ml, Array($user['email2']));
                     $page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml@");
                 } else {
-                    $client->mass_unsubscribe($ml, Array($user['email2']));
+                    $mmlist->mass_unsubscribe($ml, Array($user['email2']));
                     $page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml@");
                 }
             }
@@ -760,7 +754,7 @@ class XnetGrpModule extends PLModule
         }
 
         $page->assign('user', $user);
-        $listes = $client->get_lists($user['email2']);
+        $listes = $mmlist->get_lists($user['email2']);
         $page->assign('listes', $listes);
 
         $res = XDB::query(
index 7638917..23b114f 100644 (file)
@@ -55,10 +55,10 @@ class XnetListsModule extends ListsModule
     {
         global $globals;
 
-        require_once 'lists.inc.php';
+        require_once dirname(__FILE__).'/lists/lists.inc.php';
 
-        $this->client =& lists_xmlrpc(S::v('uid'), S::v('password'),
-                                      $globals->asso('mail_domain'));
+        $this->client = new MMList(S::v('uid'), S::v('password'),
+                                   $globals->asso('mail_domain'));
 
         $page->useMenu();
         $page->assign('asso', $globals->asso());
@@ -148,7 +148,6 @@ class XnetListsModule extends ListsModule
             return;
         }
 
-        require_once 'lists.inc.php';
         $ret = $this->client->create_list(
                     $liste, Post::v('desc'), Post::v('advertise'),
                     Post::v('modlevel'), Post::v('inslevel'),