From 9bb8bf21cfc5b5f47805cd54d64cfeae75ce1de3 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Sun, 22 Oct 2006 22:34:28 +0000 Subject: [PATCH] make mmlist be a derived class from xlmrpcclient, that's way more pretty, 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 | 39 ++++++++++++++++++++++++++++++++ include/user.func.inc.php | 9 +++----- include/validations/listes.inc.php | 12 ++++------ modules/auth.php | 6 ++--- modules/lists.php | 13 ++++------- {include => modules/lists}/lists.inc.php | 14 ------------ modules/profile.php | 5 ++-- modules/xnet.php | 7 +++--- modules/xnetgrp.php | 38 +++++++++++++------------------ modules/xnetlists.php | 7 +++--- 10 files changed, 78 insertions(+), 72 deletions(-) create mode 100644 classes/mmlist.php rename {include => modules/lists}/lists.inc.php (91%) diff --git a/classes/mmlist.php b/classes/mmlist.php new file mode 100644 index 0000000..504d8bb --- /dev/null +++ b/classes/mmlist.php @@ -0,0 +1,39 @@ +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); + } +} + +?> diff --git a/include/user.func.inc.php b/include/user.func.inc.php index f5af491..d0fe12e 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -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); } // }}} diff --git a/include/validations/listes.inc.php b/include/validations/listes.inc.php index 956e135..1152185 100644 --- a/include/validations/listes.inc.php +++ b/include/validations/listes.inc.php @@ -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) { diff --git a/modules/auth.php b/modules/auth.php index 8bd9069..dae0153 100644 --- a/modules/auth.php +++ b/modules/auth.php @@ -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) { diff --git a/modules/lists.php b/modules/lists.php index f31b51b..4fd6b00 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -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); } - } ?> diff --git a/include/lists.inc.php b/modules/lists/lists.inc.php similarity index 91% rename from include/lists.inc.php rename to modules/lists/lists.inc.php index 8e1b5fb..6382e7d 100644 --- a/include/lists.inc.php +++ b/modules/lists/lists.inc.php @@ -19,19 +19,6 @@ * 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: ?> diff --git a/modules/profile.php b/modules/profile.php index d3a5530..cd4bc6b 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -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()) { diff --git a/modules/xnet.php b/modules/xnet.php index c36cf59..5427a27 100644 --- a/modules/xnet.php +++ b/modules/xnet.php @@ -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'); } diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 0b3dc7d..a287dc5 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -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 $ml@ !!!"); } 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( diff --git a/modules/xnetlists.php b/modules/xnetlists.php index 7638917..23b114f 100644 --- a/modules/xnetlists.php +++ b/modules/xnetlists.php @@ -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'), -- 2.1.4