Commit | Line | Data |
---|---|---|
a2f69042 RB |
1 | <?php |
2 | /*************************************************************************** | |
3 | * Copyright (C) 2003-2011 Polytechnique.org * | |
4 | * http://opensource.polytechnique.org/ * | |
5 | * * | |
6 | * This program is free software; you can redistribute it and/or modify * | |
7 | * it under the terms of the GNU General Public License as published by * | |
8 | * the Free Software Foundation; either version 2 of the License, or * | |
9 | * (at your option) any later version. * | |
10 | * * | |
11 | * This program is distributed in the hope that it will be useful, * | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 | * GNU General Public License for more details. * | |
15 | * * | |
16 | * You should have received a copy of the GNU General Public License * | |
17 | * along with this program; if not, write to the Free Software * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
22 | // {{{ class MailingList | |
23 | ||
24 | class MailingList | |
25 | { | |
26 | public $address; // Fully qualified address of the list | |
27 | public $mbox; // mailbox for the list | |
28 | public $domain; // domain for the list | |
29 | protected $mmclient; // The XML-RPC client for Mailman requests | |
30 | ||
31 | public function __construct($mbox, $domain, $user, $pass='') | |
32 | { | |
33 | $this->mbox = $mbox; | |
34 | $this->domain = $domain; | |
35 | $this->address = "$mbox@$domain"; | |
36 | ||
37 | if ($user instanceof PlUser) { | |
38 | $this->mmclient = new MMList($user, $this->domain); | |
39 | } else { | |
40 | $this->mmclient = new MMList($user, $pass, $this->domain); | |
41 | } | |
42 | } | |
43 | ||
44 | /** Instantiate a MailingList from its address. | |
45 | * | |
46 | * $user and $pass are connection parameters for MailMan. | |
47 | */ | |
48 | public static function fromAddress($address, $user, $pass='') | |
49 | { | |
50 | if (strstr($address, '@') !== false) { | |
51 | list($mbox, $domain) = explode('@', $address); | |
52 | } else { | |
53 | global $globals; | |
54 | $mbox = $address; | |
55 | $domain = $globals->mail->domain; | |
56 | } | |
57 | return new MailingList($mbox, $domain, $user, $pass); | |
58 | } | |
59 | ||
60 | /** Retrieve the MailingList associated with a given promo. | |
61 | * | |
62 | * $user and $pass are connection parameters for MailMan. | |
63 | */ | |
64 | public static function promo($promo, $user, $pass='') | |
65 | { | |
66 | global $globals; | |
67 | $mail_domain = $globals->mail->domain; | |
68 | return new MailingList('promo', "$promo.$mail_domain", $user, $pass); | |
69 | } | |
70 | ||
71 | /** Subscribe the current user to the list | |
72 | */ | |
73 | public function subscribe() | |
74 | { | |
75 | return $this->mmclient->subscribe($this->mbox); | |
76 | } | |
77 | ||
78 | /** Unsubscribe the current user from the list | |
79 | */ | |
80 | public function unsubscribe() | |
81 | { | |
82 | return $this->mmclient->unsubscribe($this->mbox); | |
83 | } | |
84 | ||
85 | /** Retrieve owners for the list. | |
86 | * | |
87 | * TODO: document the return type | |
88 | */ | |
89 | public function getOwners() | |
90 | { | |
91 | return $this->mmclient->get_owners($this->mbox); | |
92 | } | |
93 | ||
94 | /** Retrieve members of the list. | |
95 | * | |
96 | * TODO: document the return type | |
97 | */ | |
98 | public function getMembers() | |
99 | { | |
100 | return $this->mmclient->get_members($this->mbox); | |
101 | } | |
102 | ||
103 | /** Retrieve a subset of list members. | |
104 | * | |
105 | * TODO: document the return type | |
106 | */ | |
107 | public function getMembersLimit($page, $number_per_page) | |
108 | { | |
109 | return $this->mmclient->get_members_limit($this->mbox, $page, $number_per_page); | |
110 | } | |
111 | ||
112 | /** Create a list | |
113 | */ | |
114 | public function create($description, $advertise, | |
115 | $moderation_level, $subscription_level, $owners, $members) | |
116 | { | |
117 | return $this->mmclient->create_list($this->mbox, utf8_decode($description), | |
118 | $advertise, $moderation_level, $subscription_level, | |
119 | $owners, $members); | |
120 | } | |
121 | } | |
122 | ||
123 | // }}} | |
124 | ||
125 | // vim:set et sw=4 sts=4 sws=4 enc=utf-8: | |
126 | ?> |