X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fnewsletter.php;h=4f65bf9236c95b2df62e1f873e16322b960333f4;hb=e97df22eacc433a9982aad507f980b303d5fa2c1;hp=4eae2c05c310bd26869927e90a58e1bf116bd8eb;hpb=bc0903c71a064931efd8677b246e7f31c194fb82;p=platal.git diff --git a/modules/newsletter.php b/modules/newsletter.php index 4eae2c0..4f65bf9 100644 --- a/modules/newsletter.php +++ b/modules/newsletter.php @@ -1,6 +1,6 @@ $this->make_hook('nl', AUTH_COOKIE), - 'nl/show' => $this->make_hook('nl_show', AUTH_COOKIE), - 'nl/submit' => $this->make_hook('nl_submit', AUTH_MDP), - 'admin/newsletter' => $this->make_hook('admin_nl', AUTH_MDP, 'admin'), - 'admin/newsletter/categories' => $this->make_hook('admin_nl_cat', AUTH_MDP, 'admin'), + 'nl' => $this->make_hook('nl', AUTH_COOKIE), + 'nl/show' => $this->make_hook('nl_show', AUTH_COOKIE), + 'nl/submit' => $this->make_hook('nl_submit', AUTH_MDP), + 'admin/newsletter' => $this->make_hook('admin_nl', AUTH_MDP, 'admin'), + 'admin/newsletter/categories' => $this->make_hook('admin_nl_cat', AUTH_MDP, 'admin'), 'admin/newsletter/edit' => $this->make_hook('admin_nl_edit', AUTH_MDP, 'admin'), - - 'ax' => $this->make_hook('ax', AUTH_COOKIE), - 'ax/show' => $this->make_hook('ax_show', AUTH_COOKIE), - 'ax/submit' => $this->make_hook('ax_submit', AUTH_MDP), - 'ax/edit' => $this->make_hook('ax_submit', AUTH_MDP), - 'admin/axletter/rights' => $this->make_hook('admin_ax_rights', AUTH_MDP, 'admin'), ); } @@ -44,7 +38,7 @@ class NewsletterModule extends PLModule require_once 'newsletter.inc.php'; $page->changeTpl('newsletter/index.tpl'); - $page->assign('xorg_title','Polytechnique.org - Lettres mensuelles'); + $page->setTitle('Lettres mensuelles'); switch ($action) { case 'out': Newsletter::unsubscribe(); break; @@ -62,16 +56,25 @@ class NewsletterModule extends PLModule require_once 'newsletter.inc.php'; - $nl = new NewsLetter($nid); - if (Get::has('text')) { - $nl->toText($page, S::v('prenom'), S::v('nom'), S::v('femme')); - } else { - $nl->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme')); - } - if (Post::has('send')) { - $nl->sendTo(S::v('prenom'), S::v('nom'), - S::v('bestalias'), S::v('femme'), - S::v('mail_fmt') != 'texte'); + try { + $nl = new NewsLetter($nid); + if (Get::has('text')) { + $nl->toText($page, S::v('prenom'), S::v('nom'), S::v('femme')); + } else { + $nl->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme')); + } + if (Post::has('send')) { + $res = XDB::query("SELECT hash + FROM newsletter_ins + WHERE user_id = {?}", + S::i('uid')); + $nl->sendTo(S::user()->login(), S::user()->bestEmail(), + S::v('prenom'), S::v('nom'), + S::v('femme'), S::v('mail_fmt') != 'texte', + $res->fetchOneCell()); + } + } catch (MailNotFound $e) { + return PL_NOT_FOUND; } } @@ -80,121 +83,118 @@ class NewsletterModule extends PLModule $page->changeTpl('newsletter/submit.tpl'); require_once 'newsletter.inc.php'; + $wp = new PlWikiPage('Xorg.LettreMensuelle'); + $wp->buildCache(); - if (Post::has('see')) { + if (Post::has('see') || (Post::has('valid') && (!trim(Post::v('title')) || !trim(Post::v('body'))))) { + if (!Post::has('see')) { + $page->trigError("L'article doit avoir un titre et un contenu"); + } $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append')); $page->assign('art', $art); } elseif (Post::has('valid')) { require_once('validations.inc.php'); - $art = new NLReq(S::v('uid'), Post::v('title'), + $art = new NLReq(S::user(), Post::v('title'), Post::v('body'), Post::v('append')); $art->submit(); $page->assign('submited', true); } + $page->addCssLink('nl.css'); } function handler_admin_nl(&$page, $new = false) { $page->changeTpl('newsletter/admin.tpl'); - $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : liste'); + $page->setTitle('Administration - Newsletter : liste'); require_once("newsletter.inc.php"); - + if($new) { Newsletter::create(); pl_redirect("admin/newsletter"); } - + $page->assign('nl_list', Newsletter::listAll()); } - + function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') { $page->changeTpl('newsletter/edit.tpl'); - $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Edition'); - require_once("newsletter.inc.php"); - - $nl = new NewsLetter($nid); - + $page->addCssLink('nl.css'); + $page->setTitle('Administration - Newsletter : Édition'); + require_once 'newsletter.inc.php'; + + $nl = new NewsLetter($nid); + if($action == 'delete') { $nl->delArticle($aid); pl_redirect("admin/newsletter/edit/$nid"); } - + if($aid == 'update') { - $nl->_title = Post::v('title'); - $nl->_title_mail= Post::v('title_mail'); - $nl->_date = Post::v('date'); - $nl->_head = Post::v('head'); - $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null; + $nl->_title = Post::v('title'); + $nl->_title_mail = Post::v('title_mail'); + $nl->_date = Post::v('date'); + $nl->_head = Post::v('head'); + $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null; if (preg_match('/^[-a-z0-9]*$/i', $nl->_shortname) && !is_numeric($nl->_shortname)) { $nl->save(); } else { - $page->trig('Le nom de la NL n\'est pas valide'); + $page->trigError("Le nom de la NL n'est pas valide."); pl_redirect('admin/newsletter/edit/' . $nl->_id); } } - + if(Post::v('save')) { $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), - $aid, Post::v('cid'), Post::v('pos')); + $aid, Post::v('cid'), Post::v('pos')); $nl->saveArticle($art); pl_redirect("admin/newsletter/edit/$nid"); } - - if($action == 'edit' && $aid != 'update') { + + if ($action == 'edit' && $aid != 'update') { $eaid = $aid; if(Post::has('title')) { $art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'), - $eaid, Post::v('cid'), Post::v('pos')); + $eaid, Post::v('cid'), Post::v('pos')); } else { - $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid); + $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid); } $page->assign('art', $art); } - - $page->assign_by_ref('nl',$nl); - } - - function handler_admin_nl_cat(&$page, $action = 'list', $id = null) { - $page->assign('xorg_title','Polytechnique.org - Administration - Newsletter : Catégories'); - $page->assign('title', 'Gestion des catégories de la newsletter'); - $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid'); - $table_editor->describe('titre','intitulé',true); - $table_editor->describe('pos','position',true); - $table_editor->apply($page, $action, $id); - } - - function handler_ax(&$page, $action = null) - { - require_once 'newsletter.inc.php'; - - $page->changeTpl('newsletter/ax.tpl'); - $page->assign('xorg_title','Polytechnique.org - Envois de l\'AX'); - switch ($action) { - case 'out': AXLetter::unsubscribe(); break; - case 'in': AXLetter::subscribe(); break; - default: ; - } + if ($aid == 'blacklist_check') { + global $globals; + $ips_to_check = array(); + $blacklist_host_resolution_count = 0; + + foreach ($nl->_arts as $key => $articles) { + foreach ($articles as $article) { + $article_ips = $article->getLinkIps($blacklist_host_resolution_count); + if (!empty($article_ips)) { + $ips_to_check[$article->title()] = $article_ips; + } + } + } - $perm = AXLetter::hasPerms(); - if ($perm) { - $waiting = AXLetter::awaiting(); - if ($waiting) { - $new = new AXLetter($waiting); - $page->assign('new', $new); + $page->assign('ips_to_check', $ips_to_check); + if ($blacklist_host_resolution_count >= $globals->mail->blacklist_host_resolution_limit) { + $page->trigError("Toutes les url et adresses emails de la lettre" + . " n'ont pas été prises en compte car la" + . " limite du nombre de résolutions DNS" + . " autorisée a été atteinte."); } } - $page->assign('axs', AXLetter::subscriptionState()); - $page->assign('ax_list', AXLetter::listSent()); - $page->assign('ax_rights', AXLetter::hasPerms()); + + $page->assign_by_ref('nl', $nl); } - function handler_ax_submit(&$page) - { - require_once('newsletter.inc.php'); - if (!AXLetter::hasPerms()) { - return PL_FORBIDDEN; - } + function handler_admin_nl_cat(&$page, $action = 'list', $id = null) { + $page->setTitle('Administration - Newsletter : Catégories'); + $page->assign('title', 'Gestion des catégories de la newsletter'); + $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid'); + $table_editor->describe('titre','intitulé',true); + $table_editor->describe('pos','position',true); + $table_editor->apply($page, $action, $id); } } +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>