X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=modules%2Flists.php;h=c6fb9dca2200d0c739b97c4c49b540ec7a502e61;hb=c15afc4e9844238cab4173022b3ef40d0dc9585d;hp=24a63a3bb80131fae473452362a4a71858a1ede6;hpb=d3f26be98b879dc9df9be60fffe2f1e152b3b218;p=platal.git diff --git a/modules/lists.php b/modules/lists.php index 24a63a3..c6fb9dc 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -21,18 +21,19 @@ class ListsModule extends PLModule { - var $client; + protected $client; function handlers() { return array( 'lists' => $this->make_hook('lists', AUTH_MDP), - 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP, '', NO_AUTH), + 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP, 'user', NO_AUTH), 'lists/create' => $this->make_hook('create', AUTH_MDP), 'lists/members' => $this->make_hook('members', AUTH_COOKIE), 'lists/trombi' => $this->make_hook('trombi', AUTH_COOKIE), 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE), + 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC), 'lists/moderate' => $this->make_hook('moderate', AUTH_MDP), 'lists/admin' => $this->make_hook('admin', AUTH_MDP), @@ -41,7 +42,7 @@ class ListsModule extends PLModule 'lists/soptions' => $this->make_hook('soptions', AUTH_MDP), 'lists/check' => $this->make_hook('check', AUTH_MDP), - 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP, 'admin'), + 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP, 'admin'), ); } @@ -191,7 +192,7 @@ class ListsModule extends PLModule $page->trig('champs «addresse souhaitée» vide'); } if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) { - $page->trig('le nom de la liste ne doit contenir que des lettres, chiffres et tirets'); + $page->trig('le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets'); } $res = XDB::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste); @@ -271,6 +272,17 @@ class ListsModule extends PLModule } } + function compare($a, $b) + { + if ($a['promo'] == $b['promo']) { + if ($a['nom'] == $b['nom']) { + return strcmp($a['prenom'], $b['prenom']); + } + return strcmp($a['nom'], $b['nom']); + } + return $a['promo'] - $b['promo']; + } + function _get_list($offset, $limit) { global $platal; @@ -291,9 +303,7 @@ class ListsModule extends PLModule $total--; } } - uasort($membres, create_function('$a,$b', 'return $a["promo"] > $b["promo"] || ' - . '($a["promo"] == $b["promo"] && (strcmp($a["nom"], $b["nom"]) > 0 || ' - . '($a["nom"] == $b["nom"] && strcmp($a["prenom"], $b["prenom"]) > 0)));')); + uasort($membres, array($this, 'compare')); return array($total, $membres); } @@ -352,43 +362,42 @@ class ListsModule extends PLModule 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); - } - if (Get::v('action') == 'showext') { - $get['action'] = 'showext'; - } - } - } - require_once('banana/ml.inc.php'); - $banana = new MLBanana($get); - $page->assign('banana', $banana->run()); - $page->addCssInline($banana->css()); - $page->addCssLink('banana.css'); - new PlBacktrace('MBox', $banana->backtrace(), 'response', 'time'); + require_once 'banana/ml.inc.php'; + get_banana_params($get, null, $action, $artid); + run_banana($page, 'MLBanana', $get); } else { $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter"); } } + function handler_rss(&$page, $liste = null, $alias = null, $hash = null) + { + require_once('rss.inc.php'); + $uid = init_rss(null, $alias, $hash); + if (!$uid || !$liste) { + exit; + } + + $res = XDB::query("SELECT user_id AS uid, password, alias AS forlife + FROM auth_user_md5 AS u + INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie') + WHERE u.user_id = {?}", $uid); + $row = $res->fetchOneAssoc(); + $_SESSION = array_merge($row, $_SESSION); + + $domain = $this->prepare_client($page); + if (list($det) = $this->client->get_members($liste)) { + if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv']) + && !$det['own'] && ($det['sub'] < 2)) { + exit; + } + require_once('banana/ml.inc.php'); + $banana = new MLBanana(S::v('forlife'), Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2')); + $banana->run(); + } + exit; + } + function moderate_mail($domain, $liste, $mid) { $mail = $this->client->get_pending_mail($liste, $mid); @@ -437,7 +446,7 @@ class ListsModule extends PLModule function handler_moderate(&$page, $liste = null) { if (is_null($liste)) { - return PL_NOT_FOUND; + return PL_NOT_FOUND; } $domain = $this->prepare_client($page); @@ -446,12 +455,34 @@ class ListsModule extends PLModule $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('sadd') || Env::has('sdel')) { + if (Env::has('sadd')) { /* 4 = SUBSCRIBE */ + $sub = $this->client->get_pending_sub($liste, Env::v('sadd')); + $this->client->handle_request($liste,Env::v('sadd'),4,''); + $info = "validée"; + } + if (Post::has('sdel')) { /* 2 = REJECT */ + $sub = $this->client->get_pending_sub($liste, Env::v('sdel')); + $this->client->handle_request($liste, Post::v('sdel'), 2, Post::v('reason')); + $info = "refusée"; + } + if ($sub) { + $mailer = new PlMailer(); + $mailer->setFrom("$liste-bounces@{$domain}"); + $mailer->addTo("$liste-owner@{$domain}"); + $mailer->addHeader('Reply-To', "$liste-owner@{$domain}"); + $mailer->setSubject("L'inscription de {$sub['name']} a été $info"); + $text = "L'inscription de {$sub['name']} à la liste $liste@{$domain} a été $info par " . S::v('prenom') . ' ' + . S::v('nom') . '(' . S::v('promo') . ")\n"; + if (trim(Post::v('reason'))) { + $text .= "\nLa raison invoquée est :\n" . Post::v('reason'); + } + $mailer->setTxtBody(wordwrap($text, 72)); + $mailer->send(); + } + if (Env::has('sadd')) { + pl_redirect('lists/moderate/'.$liste); + } } if (Post::has('moderate_mails') && Post::has('select_mails')) { @@ -461,12 +492,12 @@ class ListsModule extends PLModule } } elseif (Env::has('mid')) { if (Get::has('mid') && !Env::has('mok') && !Env::has('mdel')) { + $page->changeTpl('lists/moderate_mail.tpl'); require_once('banana/moderate.inc.php'); $params = array('listname' => $liste, 'domain' => $domain, 'artid' => Get::i('mid'), 'part' => Get::v('part'), 'action' => Get::v('action')); - $banana = new ModerationBanana($params, $this->client); - $res = $banana->run(); - $page->addCssInline($banana->css()); + $params['client'] = $this->client; + run_banana($page, 'ModerationBanana', $params); $msg = file_get_contents('/etc/mailman/fr/refuse.txt'); $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg); @@ -474,10 +505,6 @@ class ListsModule extends PLModule $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg); $msg = str_replace("%(listname)s", $liste, $msg); $page->assign('msg', $msg); - - $page->addCssLink('banana.css'); - $this->changeTpl('lists/moderate_mail.tpl'); - $page->assign_by_ref('mail', $res); return; } @@ -506,6 +533,22 @@ class ListsModule extends PLModule } } + static public function no_login_callback($login) + { + require_once 'user.func.inc.php'; + global $list_unregistered; + + $users = get_not_registered_user($login, true); + if ($users->total()) { + if (!isset($list_unregistered)) { + $list_unregistered = array(); + } + $list_unregistered[$login] = $users; + } else { + _default_user_callback($login); + } + } + function handler_admin(&$page, $liste = null) { global $globals; @@ -514,13 +557,43 @@ class ListsModule extends PLModule return PL_NOT_FOUND; } - $this->prepare_client($page); + $domain = $this->prepare_client($page); $this->changeTpl('lists/admin.tpl'); + if (Env::has('send_mark')) { + $actions = Env::v('mk_action'); + $uids = Env::v('mk_uid'); + $mails = Env::v('mk_email'); + foreach ($actions as $key=>$action) { + switch ($action) { + case 'none': + break; + + case 'marketu': case 'markets': + require_once 'emails.inc.php'; + $mail = valide_email($mails[$key]); + if (isvalid_email_redirection($mail)) { + $from = ($action == 'marketu') ? 'user' : 'staff'; + $market = Marketing::get($uids[$key], $mail); + if (!$market) { + $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S::v('uid')); + $market->add(); + break; + } + } + + default: + XDB::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain) + VALUES ({?}, \'list\', {?}, {?})', + $uids[$key], $liste, $domain); + } + } + } + if (Env::has('add_member')) { require_once('user.func.inc.php'); - $members = get_users_forlife_list(Env::v('add_member')); + $members = get_users_forlife_list(Env::v('add_member'), false, array('ListsModule', 'no_login_callback')); $arr = $this->client->mass_subscribe($liste, $members); if (is_array($arr)) { foreach($arr as $addr) { @@ -541,7 +614,7 @@ class ListsModule extends PLModule if (Env::has('add_owner')) { require_once('user.func.inc.php'); - $owners = get_users_forlife_list(Env::v('add_owner')); + $owners = get_users_forlife_list(Env::v('add_owner'), false, array('ListsModule', 'no_login_callback')); if ($owners) { foreach ($owners as $login) { if ($this->client->add_owner($liste, $login)) { @@ -561,6 +634,10 @@ class ListsModule extends PLModule } if (list($det,$mem,$own) = $this->client->get_members($liste)) { + global $list_unregistered; + if ($list_unregistered) { + $page->assign_by_ref('unregistered', $list_unregistered); + } $membres = list_sort_members($mem, @$tri_promo); $moderos = list_sort_owners($own, @$tri_promo);