X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Flists.php;h=8375dbc536cd662cf8abe850ccc9ffac4348734e;hb=1515e65adcb5f6cee7d5327f28ebb85f48377791;hp=f8b9aa05e4635999b06de276b1238028b375cfe0;hpb=c85297061a317f47d8293e079badd998ecab9b4e;p=platal.git diff --git a/modules/lists.php b/modules/lists.php index f8b9aa0..8375dbc 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -1,6 +1,6 @@ $this->make_hook('lists', AUTH_MDP), + 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP, '', NO_AUTH), 'lists/create' => $this->make_hook('create', AUTH_MDP), 'lists/members' => $this->make_hook('members', AUTH_COOKIE), @@ -44,18 +45,38 @@ class ListsModule extends PLModule ); } + function on_subscribe($forlife, $uid, $promo, $password) + { + $this->prepare_client(null); + $this->client->subscribe("promo$promo"); + } + function prepare_client(&$page) { - require_once 'lists.inc.php'; + global $globals; + + 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; } function handler_lists(&$page) { + function filter_owner($list) + { + return $list['own']; + } + + function filter_member($list) + { + return $list['sub']; + } + $this->prepare_client($page); - $page->changeTpl('listes/index.tpl'); + $page->changeTpl('lists/index.tpl'); + $page->addJsLink('ajax.js'); $page->assign('xorg_title','Polytechnique.org - Listes de diffusion'); @@ -76,12 +97,52 @@ class ListsModule extends PLModule } } $listes = $this->client->get_lists(); - $page->assign_by_ref('listes', $listes); + $owner = array_filter($listes, 'filter_owner'); + $listes = array_diff_key($listes, $owner); + $member = array_filter($listes, 'filter_member'); + $listes = array_diff_key($listes, $member); + foreach ($owner as $key=>$liste) { + list($subs,$mails) = $this->client->get_pending_ops($liste['list']); + $owner[$key]['subscriptions'] = $subs; + $owner[$key]['mails'] = $mails; + } + $page->register_modifier('hdc', 'list_header_decode'); + $page->assign_by_ref('owner', $owner); + $page->assign_by_ref('member', $member); + $page->assign_by_ref('public', $listes); + } + + function handler_ajax(&$page, $list = null) + { + header('Content-Type: text/html; charset="iso-8859-15"'); + $domain = $this->prepare_client($page); + $page->changeTpl('lists/liste.inc.tpl', NO_SKIN); + if (Get::has('unsubscribe')) { + $this->client->unsubscribe($list); + } + if (Get::has('subscribe')) { + $this->client->subscribe($list); + } + if (Get::has('sadd')) { /* 4 = SUBSCRIBE */ + $this->client->handle_request($list, Get::v('sadd'), 4, ''); + } + if (Get::has('mid')) { + $this->moderate_mail($domain, $list, Get::i('mid')); + } + + list($liste, $members, $owners) = $this->client->get_members($list); + if ($liste['own']) { + list($subs,$mails) = $this->client->get_pending_ops($list); + $liste['subscriptions'] = $subs; + $liste['mails'] = $mails; + } + $page->register_modifier('hdc', 'list_header_decode'); + $page->assign_by_ref('liste', $liste); } function handler_create(&$page) { - $page->changeTpl('listes/create.tpl'); + $page->changeTpl('lists/create.tpl'); $owners = preg_split("/[\s]+/", Post::v('owners'), -1, PREG_SPLIT_NO_EMPTY); $members = preg_split("/[\s]+/", Post::v('members'), -1, PREG_SPLIT_NO_EMPTY); @@ -91,29 +152,31 @@ class ListsModule extends PLModule require_once('user.func.inc.php'); // if we want to add an owner and then type , then both // add_owner_sub and add_owner are filled. - if (Post::v('add_owner') != "") { - if (($forlife = get_user_forlife(Post::v('add_owner'))) !== false) { - $owners [] = $forlife; - } - // if we want to add a member and then type , then - // add_owner_sub is filled, whereas add_owner is empty. - } else if (Post::has('add_member')) { - if (($forlife = get_user_forlife(Post::v('add_member'))) !== false) { - $members[] = $forlife; - } + $oforlifes = get_users_forlife_list(Post::v('add_owner'), true); + $mforlifes = get_users_forlife_list(Post::v('add_member'), true); + if (!is_null($oforlifes)) { + $owners = array_merge($owners, $oforlifes); + } + // if we want to add a member and then type , then + // add_owner_sub is filled, whereas add_owner is empty. + if (!is_null($mforlifes)) { + $members = array_merge($members, $mforlifes); } } // click on validate button 'add_member_sub' if (Post::has('add_member_sub') && Post::has('add_member')) { require_once('user.func.inc.php'); - if (($forlife = get_user_forlife(Post::v('add_member'))) !== false) { - $members[] = $forlife; + $forlifes = get_users_forlife_list(Post::v('add_member'), true); + if (!is_null($forlifes)) { + $members = array_merge($members, $forlifes); } } - ksort($owners); array_unique($owners); - ksort($members); array_unique($members); + ksort($owners); + $owners = array_unique($owners); + ksort($members); + $members = array_unique($members); $page->assign('owners', join(' ', $owners)); $page->assign('members', join(' ', $members)); @@ -169,7 +232,7 @@ class ListsModule extends PLModule $this->prepare_client($page); - $page->changeTpl('listes/members.tpl'); + $page->changeTpl('lists/members.tpl'); if (Get::has('del')) { $this->client->unsubscribe($liste); @@ -228,7 +291,7 @@ class ListsModule extends PLModule $this->prepare_client($page); - $page->changeTpl('listes/trombi.tpl'); + $page->changeTpl('lists/trombi.tpl'); if (Get::has('del')) { $this->client->unsubscribe($liste); @@ -242,7 +305,6 @@ class ListsModule extends PLModule $owners = $this->client->get_owners($liste); if (is_array($owners)) { - require_once 'trombi.inc.php'; $moderos = list_sort_owners($owners[1]); $page->assign_by_ref('details', $owners[0]); @@ -255,7 +317,7 @@ class ListsModule extends PLModule } } - function handler_archives(&$page, $liste = null) + function handler_archives(&$page, $liste = null, $action = null, $artid = null) { global $globals; @@ -263,126 +325,149 @@ class ListsModule extends PLModule return PL_NOT_FOUND; } - $this->prepare_client($page); + $domain = $this->prepare_client($page); - $page->changeTpl('listes/archives.tpl'); + $page->changeTpl('lists/archives.tpl'); - $page->addCssLink('css/lists.archives.css'); if (list($det) = $this->client->get_members($liste)) { if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv']) - && !$det['own'] && ($det['sub'] < 2)) - { + && !$det['own'] && ($det['sub'] < 2)) { $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter"); - } elseif (Get::has('file')) { - $file = Get::v('file'); - $rep = Get::v('rep'); - if (strstr('/', $file)!==false || !preg_match(',^\d+/\d+$,', $rep)) { - $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter"); - } else { - $page->assign('archives', $globals->lists->spool - ."/{$domain}{$globals->lists->vhost_sep}$liste/$rep/$file"); - } - } else { - $archs = Array(); - foreach (glob($globals->lists->spool - ."/{$domain}{$globals->lists->vhost_sep}$liste/*/*") as $rep) - { - if (preg_match(",/(\d*)/(\d*)$,", $rep, $matches)) { - $archs[intval($matches[1])][intval($matches[2])] = true; + } + $get = Array('listname' => $liste, 'domain' => $domain); + if (Post::has('updateall')) { + $get['updateall'] = Post::v('updateall'); + } + if (!is_null($action)) { + if ($action == 'new') { + $get['action'] = 'new'; + } elseif (!is_null($artid)) { + $get['artid'] = $artid; + if ($action == 'reply') { + $get['action'] = 'new'; + } elseif ($action == 'cancel') { + $get['action'] = $action; + } elseif ($action == 'from') { + $get['first'] = $artid; + unset($get['artid']); + } elseif ($action == 'read') { + $get['part'] = @$_GET['part']; + } elseif ($action == 'source') { + $get['part'] = 'source'; + } elseif ($action == 'xface') { + $get['part'] = 'xface'; + } elseif ($action) { + $get['part'] = str_replace('.', '/', $action); } } - $page->assign('archs', $archs); - $page->assign('range', range(1,12)); } + require_once('banana/ml.inc.php'); + $banana = new MLBanana($get); + $page->assign('banana', $banana->run()); + $page->addCssInline($banana->css()); + $page->addCssLink('banana.css'); } else { $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter"); } } + function moderate_mail($domain, $liste, $mid) + { + $mail = $this->client->get_pending_mail($liste, $mid); + $reason = ''; + + $prenom = S::v('prenom'); + $nom = S::v('nom'); + + if (Env::has('mok')) { + $action = 1; /** 2 = ACCEPT **/ + $subject = "Message accepté"; + $append .= "a été accepté par $prenom $nom.\n"; + } elseif (Env::has('mno')) { + $action = 2; /** 2 = REJECT **/ + $subject = "Message refusé"; + $reason = Post::v('reason'); + $append = "a été refusé par $prenom $nom avec la raison :\n\n" + . $reason; + } elseif (Env::has('mdel')) { + $action = 3; /** 3 = DISCARD **/ + $subject = "Message supprimé"; + $append = "a été supprimé par $prenom $nom.\n\n" + . "Rappel: il ne faut utiliser cette opération " + . "que dans le cas de spams ou de virus !\n"; + } + + if (isset($action) && $this->client->handle_request($liste, $mid, $action, $reason)) { + $texte = "le message suivant :\n\n" + ." Auteur: {$mail['sender']}\n" + ." Sujet : « {$mail['subj']} »\n" + ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n" + .$append; + $mailer = new PlMailer(); + $mailer->addTo("$liste-owner@{$domain}"); + $mailer->setFrom("$liste-bounces@{$domain}"); + $mailer->addHeader('Reply-To', "$liste-owner@{$domain}"); + $mailer->setSubject($subject); + $mailer->setTxtBody(wordwrap($texte,72)); + $mailer->send(); + Get::kill('mid'); + } + + return $mail; + } + function handler_moderate(&$page, $liste = null) { if (is_null($liste)) { return PL_NOT_FOUND; } - $this->prepare_client($page); + $domain = $this->prepare_client($page); - $page->changeTpl('listes/moderate.tpl'); + $page->changeTpl('lists/moderate.tpl'); - $page->register_modifier('qpd', 'quoted_printable_decode'); $page->register_modifier('hdc', 'list_header_decode'); if (Env::has('sadd')) { /* 4 = SUBSCRIBE */ $this->client->handle_request($liste,Env::v('sadd'),4,''); pl_redirect('lists/moderate/'.$liste); } - if (Post::has('sdel')) { /* 2 = REJECT */ $this->client->handle_request($liste,Post::v('sdel'),2,Post::v('reason')); } - if (Env::has('mid')) { - $mid = Env::v('mid'); - $mail = $this->client->get_pending_mail($liste, $mid); - $reason = ''; - - $prenom = S::v('prenom'); - $nom = S::v('nom'); - - if (Env::has('mok')) { - $action = 1; /** 2 = ACCEPT **/ - $subject = "Message accepté"; - $append .= "a été accepté par $prenom $nom.\n"; - } elseif (Env::has('mno')) { - $action = 2; /** 2 = REJECT **/ - $subject = "Message refusé"; - $reason = Post::v('reason'); - $append = "a été refusé par $prenom $nom avec la raison :\n\n" - . $reason; - } elseif (Env::has('mdel')) { - $action = 3; /** 3 = DISCARD **/ - $subject = "Message supprimé"; - $append = "a été supprimé par $prenom $nom.\n\n" - . "Rappel: il ne faut utiliser cette opération " - . "que dans le cas de spams ou de virus !\n"; + if (Post::has('moderate_mails') && Post::has('select_mails')) { + $mails = array_keys(Post::v('select_mails')); + foreach($mails as $mail) { + $this->moderate_mail($domain, $liste, $mail); } + } elseif (Env::has('mid')) { + if (Get::has('mid')) { + require_once('banana/moderate.inc.php'); + $params = array('listname' => $liste, 'domain' => $domain, 'artid' => Get::i('mid'), 'part' => Get::v('part')); + $banana = new ModerationBanana($params, $this->client); + $res = $banana->run(); + $page->addCssInline($banana->css()); - if (isset($action) && $this->client->handle_request($liste, $mid, $action, $reason)) { - $texte = "le message suivant :\n\n" - ." Auteur: {$mail['sender']}\n" - ." Sujet : « {$mail['subj']} »\n" - ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n" - .$append; - require_once 'diogenes/diogenes.hermes.inc.php'; - $mailer = new HermesMailer(); - $mailer->addTo("$liste-owner@{$domain}"); - $mailer->setFrom("$liste-bounces@{$domain}"); - $mailer->addHeader('Reply-To', "$liste-owner@{$domain}"); - $mailer->setSubject($subject); - $mailer->setTxtBody(wordwrap($texte,72)); - $mailer->send(); - Get::kill('mid'); - } - - if (Get::has('mid') && is_array($mail)) { $msg = file_get_contents('/etc/mailman/fr/refuse.txt'); $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg); $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg); $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg); $msg = str_replace("%(listname)s", $liste, $msg); - $page->assign('msg', $msg); + $page->assign('msg', $msg); - $page->changeTpl('listes/moderate_mail.tpl'); - $page->assign_by_ref('mail', $mail); + $page->addCssLink('banana.css'); + $page->changeTpl('lists/moderate_mail.tpl'); + $page->assign_by_ref('mail', $res); return; } + $mail = $this->moderate_mail($domain, $liste, Env::i('mid')); } elseif (Env::has('sid')) { - if (list($subs,$mails) = $this->client->get_pending_ops($liste)) { foreach($subs as $user) { if ($user['id'] == Env::v('sid')) { - $page->changeTpl('listes/moderate_sub.tpl'); + $page->changeTpl('lists/moderate_sub.tpl'); $page->assign('del_user', $user); return; } @@ -392,6 +477,9 @@ class ListsModule extends PLModule } if (list($subs,$mails) = $this->client->get_pending_ops($liste)) { + foreach ($mails as $key=>$mail) { + $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']); + } $page->assign_by_ref('subs', $subs); $page->assign_by_ref('mails', $mails); } else { @@ -409,18 +497,11 @@ class ListsModule extends PLModule $this->prepare_client($page); - $page->changeTpl('listes/admin.tpl'); + $page->changeTpl('lists/admin.tpl'); if (Env::has('add_member')) { - require_once('user.func.inc.php'); - $members = explode(' ', Env::v('add_member')); - if ($members) foreach ($members as $i => $alias) { - if (($login = get_user_forlife($alias)) !== false) {; - $members[$i] = $login; - } - } - + $members = get_users_forlife_list(Env::v('add_member')); $arr = $this->client->mass_subscribe($liste, $members); if (is_array($arr)) { foreach($arr as $addr) { @@ -441,16 +522,12 @@ class ListsModule extends PLModule if (Env::has('add_owner')) { require_once('user.func.inc.php'); - - $owners = explode(' ', Env::v('add_owner')); - - if ($owners) foreach ($owners as $alias) { - if (($login = get_user_forlife($alias)) === false) {; - $login = $alias; - } - - if ($this->client->add_owner($liste, $login)) { - $page->trig($alias." ajouté aux modérateurs."); + $owners = get_users_forlife_list(Env::v('add_owner')); + if ($owners) { + foreach ($owners as $login) { + if ($this->client->add_owner($liste, $login)) { + $page->trig($alias." ajouté aux modérateurs."); + } } } } @@ -465,9 +542,8 @@ 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); + $membres = list_sort_members($mem, @$tri_promo); + $moderos = list_sort_owners($own, @$tri_promo); $page->assign_by_ref('details', $det); $page->assign_by_ref('members', $membres); @@ -475,7 +551,9 @@ class ListsModule extends PLModule $page->assign('np_m', count($mem)); } else { - $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer"); + $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.
" + ." Si tu penses qu'il s'agit d'une erreur, " + ."contact le support"); } } @@ -487,7 +565,7 @@ class ListsModule extends PLModule $this->prepare_client($page); - $page->changeTpl('listes/options.tpl'); + $page->changeTpl('lists/options.tpl'); if (Post::has('submit')) { $values = $_POST; @@ -532,23 +610,36 @@ class ListsModule extends PLModule function handler_delete(&$page, $liste = null) { + global $globals; if (is_null($liste)) { return PL_NOT_FOUND; } - $this->prepare_client($page); - - $page->changeTpl('listes/delete.tpl'); - - if (Post::v('valid') == 'OUI' - && $this->client->delete_list($liste, Post::b('del_archive'))) - { - foreach (array('', '-owner', '-admin', '-bounces') as $app) { - XDB::execute("DELETE FROM aliases - WHERE type='liste' AND alias='{?}'", - $liste.$app); + $domain = $this->prepare_client($page); + if ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) { + $domain = ''; + $table = 'aliases'; + $type = 'liste'; + } else { + $domain = '@' . $domain; + $table = 'virtual'; + $type = 'list'; + } + + $page->changeTpl('lists/delete.tpl'); + if (Post::v('valid') == 'OUI') { + if ($this->client->delete_list($liste, Post::b('del_archive'))) { + foreach (array('', '-owner', '-admin', '-bounces') as $app) { + XDB::execute("DELETE FROM $table + WHERE type={?} AND alias={?}", + $type, $liste.$app.$domain); + } + $page->assign('deleted', true); + } else { + $page->kill('Une erreur est survenue lors de la suppression de la liste.
' + . 'Contact les administrateurs du site pour régler le problème : ' + . 'support@polytechnique.org'); } - $page->assign('deleted', true); } elseif (list($details,$options) = $this->client->get_owner_options($liste)) { $page->assign_by_ref('details', $details); $page->assign_by_ref('options', $options); @@ -566,7 +657,7 @@ class ListsModule extends PLModule $this->prepare_client($page); - $page->changeTpl('listes/soptions.tpl'); + $page->changeTpl('lists/soptions.tpl'); if (Post::has('submit')) { $values = $_POST; @@ -592,7 +683,7 @@ class ListsModule extends PLModule $this->prepare_client($page); - $page->changeTpl('listes/check.tpl'); + $page->changeTpl('lists/check.tpl'); if (Post::has('correct')) { $this->client->check_options($liste, true); @@ -607,15 +698,13 @@ class ListsModule extends PLModule } function handler_admin_all(&$page) { - $page->changeTpl('listes/admin_all.tpl'); + $page->changeTpl('lists/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); } - } ?>