From: Raphaël Barrois Date: Sun, 4 Nov 2012 19:17:40 +0000 (+0100) Subject: Add new MailingList class X-Git-Tag: xorg/1.1.6~19 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=a2f6904201cf0bddea8dd1e9a74c3dff297f242d;p=platal.git Add new MailingList class Signed-off-by: Raphaël Barrois --- 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: +?>