Merge commit 'origin/master' into account
[platal.git] / modules / newsletter.php
index 75ab2e9..3ed81bc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -41,13 +41,13 @@ class NewsletterModule extends PLModule
         $page->setTitle('Lettres mensuelles');
 
         switch ($action) {
-          case 'out': Newsletter::unsubscribe(); break;
-          case 'in':  Newsletter::subscribe(); break;
+          case 'out': NewsLetter::unsubscribe(); break;
+          case 'in':  NewsLetter::subscribe(); break;
           default: ;
         }
 
-        $page->assign('nls', Newsletter::subscriptionState());
-        $page->assign('nl_list', Newsletter::listSent());
+        $page->assign('nls', NewsLetter::subscriptionState());
+        $page->assign('nl_list', NewsLetter::listSent());
     }
 
     function handler_nl_show(&$page, $nid = 'last')
@@ -58,20 +58,14 @@ class NewsletterModule extends PLModule
 
         try {
             $nl = new NewsLetter($nid);
+            $user =& S::user();
             if (Get::has('text')) {
-                $nl->toText($page, S::v('prenom'), S::v('nom'), S::v('femme'));
+                $nl->toText($page, $user);
             } else {
-                $nl->toHtml($page, S::v('prenom'), S::v('nom'), S::v('femme'));
+                $nl->toHtml($page, $user);
             }
             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());
+                $nl->sendTo($user);
             }
         } catch (MailNotFound $e) {
             return PL_NOT_FOUND;
@@ -108,11 +102,11 @@ class NewsletterModule extends PLModule
         require_once("newsletter.inc.php");
 
         if($new) {
-            Newsletter::create();
+            NewsLetter::create();
             pl_redirect("admin/newsletter");
         }
 
-        $page->assign('nl_list', Newsletter::listAll());
+        $page->assign('nl_list', NewsLetter::listAll());
     }
 
     function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') {
@@ -151,22 +145,26 @@ class NewsletterModule extends PLModule
 
         if ($action == 'edit' && $aid != 'update') {
             $eaid = $aid;
-            if(Post::has('title')) {
+            if (Post::has('title')) {
                 $art  = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'),
                                       $eaid, Post::v('cid'), Post::v('pos'));
             } else {
                 $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid);
             }
+            if ($art && !$art->check()) {
+                $page->trigError("Cet article est trop long.");
+            }
             $page->assign('art', $art);
         }
 
         if ($aid == 'blacklist_check') {
+            global $globals;
             $ips_to_check = array();
-            $gethostbyname_count = 0;
+            $blacklist_host_resolution_count = 0;
 
             foreach ($nl->_arts as $key => $articles) {
                 foreach ($articles as $article) {
-                    $article_ips = $article->getLinkIps($gethostbyname_count);
+                    $article_ips = $article->getLinkIps($blacklist_host_resolution_count);
                     if (!empty($article_ips)) {
                         $ips_to_check[$article->title()] = $article_ips;
                     }
@@ -174,8 +172,8 @@ class NewsletterModule extends PLModule
             }
 
             $page->assign('ips_to_check', $ips_to_check);
-            if ($gethostbyname_count >= $globals->mail->blacklist_host_resolution_limit) {
-                $page-trigError("Toutes les url et adresses emails de la lettre"
+            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.");