From a2f6904201cf0bddea8dd1e9a74c3dff297f242d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Sun, 4 Nov 2012 20:17:40 +0100 Subject: [PATCH] Add new MailingList class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- include/mailinglist.inc.php | 126 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 include/mailinglist.inc.php diff --git a/include/mailinglist.inc.php b/include/mailinglist.inc.php new file mode 100644 index 0000000..c78b751 --- /dev/null +++ b/include/mailinglist.inc.php @@ -0,0 +1,126 @@ +mbox = $mbox; + $this->domain = $domain; + $this->address = "$mbox@$domain"; + + if ($user instanceof PlUser) { + $this->mmclient = new MMList($user, $this->domain); + } else { + $this->mmclient = new MMList($user, $pass, $this->domain); + } + } + + /** Instantiate a MailingList from its address. + * + * $user and $pass are connection parameters for MailMan. + */ + public static function fromAddress($address, $user, $pass='') + { + if (strstr($address, '@') !== false) { + list($mbox, $domain) = explode('@', $address); + } else { + global $globals; + $mbox = $address; + $domain = $globals->mail->domain; + } + return new MailingList($mbox, $domain, $user, $pass); + } + + /** Retrieve the MailingList associated with a given promo. + * + * $user and $pass are connection parameters for MailMan. + */ + public static function promo($promo, $user, $pass='') + { + global $globals; + $mail_domain = $globals->mail->domain; + return new MailingList('promo', "$promo.$mail_domain", $user, $pass); + } + + /** Subscribe the current user to the list + */ + public function subscribe() + { + return $this->mmclient->subscribe($this->mbox); + } + + /** Unsubscribe the current user from the list + */ + public function unsubscribe() + { + return $this->mmclient->unsubscribe($this->mbox); + } + + /** Retrieve owners for the list. + * + * TODO: document the return type + */ + public function getOwners() + { + return $this->mmclient->get_owners($this->mbox); + } + + /** Retrieve members of the list. + * + * TODO: document the return type + */ + public function getMembers() + { + return $this->mmclient->get_members($this->mbox); + } + + /** Retrieve a subset of list members. + * + * TODO: document the return type + */ + public function getMembersLimit($page, $number_per_page) + { + return $this->mmclient->get_members_limit($this->mbox, $page, $number_per_page); + } + + /** Create a list + */ + public function create($description, $advertise, + $moderation_level, $subscription_level, $owners, $members) + { + return $this->mmclient->create_list($this->mbox, utf8_decode($description), + $advertise, $moderation_level, $subscription_level, + $owners, $members); + } +} + +// }}} + +// vim:set et sw=4 sts=4 sws=4 enc=utf-8: +?> -- 2.1.4