From 45b1ca51dea8645aae1f9e4ef38231f3ce5c207c Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Thu, 14 Oct 2004 22:16:01 +0000 Subject: [PATCH] new mailing list interface --- htdocs/listes/index.php | 10 +++---- include/inscription_listes_base.inc.php | 5 ++-- include/newsletter.inc.php | 46 +++++++++++++++++++++++++++++++ scripts/mailman/mailman-rpc.py | 48 ++------------------------------- 4 files changed, 56 insertions(+), 53 deletions(-) create mode 100644 include/newsletter.inc.php diff --git a/htdocs/listes/index.php b/htdocs/listes/index.php index fc2a678..7d55a4e 100644 --- a/htdocs/listes/index.php +++ b/htdocs/listes/index.php @@ -18,12 +18,13 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: index.php,v 1.7 2004-10-10 13:51:15 x2000habouzit Exp $ + $Id: index.php,v 1.8 2004-10-14 22:16:01 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); new_skinned_page('listes/index.tpl', AUTH_MDP); include('xml-rpc-client.inc.php'); +include('newsletter.inc.php'); $res = $globals->db->query("SELECT password FROM auth_user_md5 WHERE user_id={$_SESSION['uid']}"); list($pass) = mysql_fetch_row($res); @@ -44,12 +45,11 @@ if(isset($_POST['promo_add'])) { $client->subscribe('polytechnique.org',"promo$promo"); } } -if(!empty($_GET['nl_unsub'])) $client->unsubscribe_nl(); -if(!empty($_GET['nl_sub'])) $client->subscribe_nl(); +if(!empty($_GET['nl_unsub'])) unsubscribe_nl(); +if(!empty($_GET['nl_sub'])) subscribe_nl(); $listes = $client->get_lists('polytechnique.org'); -$nl = $client->get_nl_state(); $page->assign_by_ref('listes',$listes); -$page->assign('nl',$nl); +$page->assign('nl',get_nl_state()); $page->run(); ?> diff --git a/include/inscription_listes_base.inc.php b/include/inscription_listes_base.inc.php index e90b556..e6a9f92 100644 --- a/include/inscription_listes_base.inc.php +++ b/include/inscription_listes_base.inc.php @@ -18,10 +18,11 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: inscription_listes_base.inc.php,v 1.3 2004-10-10 13:51:17 x2000habouzit Exp $ + $Id: inscription_listes_base.inc.php,v 1.4 2004-10-14 22:16:01 x2000habouzit Exp $ ***************************************************************************/ include('xml-rpc-client.inc.php'); +include('newsletter.inc.php'); /** inscrit l'uid donnée à la promo * @param $uid UID @@ -35,7 +36,7 @@ function inscription_listes_base($uid,$pass,$promo) { // récupération de l'id de la liste promo $client = new xmlrpc_client("http://$uid:$pass@localhost:4949"); $client->subscribe('polytechnique.org',"promo$promo"); - $client->subscribe_nl(); + subscribe_nl(); } ?> diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php new file mode 100644 index 0000000..432e8c3 --- /dev/null +++ b/include/newsletter.inc.php @@ -0,0 +1,46 @@ +db->query("SELECT COUNT(*)>0 FROM newsletter_ins WHERE user_id={$_SESSION['uid']}"); + list($b) = mysql_fetch_row($res); + mysql_free_result($res); + return $b; +} + +function unsubscribe_nl() { + global $globals; + $globals->db->query("DELETE FROM newsletter_ins WHERE user_id={$_SESSION['uid']}"); +} + +function subscribe_nl() { + global $globals; + $globals->db->query("INSERT INTO newsletter_ins (user_id) VALUES ({$_SESSION['uid']})"); +} + +?> diff --git a/scripts/mailman/mailman-rpc.py b/scripts/mailman/mailman-rpc.py index e0b6e17..cb59edf 100755 --- a/scripts/mailman/mailman-rpc.py +++ b/scripts/mailman/mailman-rpc.py @@ -18,7 +18,7 @@ #* Foundation, Inc., * #* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * #*************************************************************************** -# $Id: mailman-rpc.py,v 1.58 2004-10-13 10:05:00 x2000habouzit Exp $ +# $Id: mailman-rpc.py,v 1.59 2004-10-14 22:16:01 x2000habouzit Exp $ #*************************************************************************** import base64, MySQLdb, os, getopt, sys, MySQLdb.converters, sha @@ -215,7 +215,7 @@ def get_lists((userdesc,perms),vhost): names.sort() result = [] for name in names: - if not name.startswith(prefix) or name == mm_cfg.MAIN_NEWSLETTER: + if not name.startswith(prefix): continue try: mlist = MailList.MailList(name,lock=0) @@ -265,47 +265,6 @@ def unsubscribe((userdesc,perms),vhost,listname): mlist.Unlock() return 0 -def subscribe_nl((userdesc,perms)): - try: - mlist = MailList.MailList(mm_cfg.MAIN_NEWSLETTER,lock=0) - except: - return 0 - try: - mlist.Lock() - mlist.ApprovedAddMember(userdesc,0,0) - mlist.Save() - mlist.Unlock() - return 1 - except: - mlist.Unlock() - return 0 - -def unsubscribe_nl((userdesc,perms)): - try: - mlist = MailList.MailList(mm_cfg.MAIN_NEWSLETTER,lock=0) - except: - return 0 - try: - mlist.Lock() - mlist.ApprovedDeleteMember(userdesc.address,0,0) - mlist.Save() - mlist.Unlock() - return 1 - except: - mlist.Unlock() - return 0 - -def get_nl_state((userdesc,perms)): - try: - mlist = MailList.MailList(mm_cfg.MAIN_NEWSLETTER,lock=0) - except: - return 0 - try: - return ( userdesc.address in mlist.getRegularMemberKeys() ) - except: - return 0 - - #------------------------------------------------------------------------------- # users procedures for [ index.php ] # @@ -776,9 +735,6 @@ server = FastXMLRPCServer(("localhost", 4949), BasicAuthXMLRPCRequestHandler) server.register_function(get_lists) server.register_function(subscribe) server.register_function(unsubscribe) -server.register_function(subscribe_nl) -server.register_function(unsubscribe_nl) -server.register_function(get_nl_state) # members.php server.register_function(get_members) # trombi.php -- 2.1.4