Force auth on newsletter unsubscription link
[platal.git] / modules / comletter.php
index 103adef..b5afacb 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2013 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 Platal::load('newsletter');
+require_once 'comletter.inc.php';
 
 /**
  * Newsletter for community
@@ -30,7 +31,9 @@ class ComLetterModule extends NewsletterModule
     {
         return array(
             'comletter'                   => $this->make_hook('nl',              AUTH_COOKIE, 'user'),
-            'comletter/out'               => $this->make_hook('out',             AUTH_PUBLIC),
+            'comletter/submit'            => $this->make_hook('coml_submit',     AUTH_PASSWD, 'user'),
+            'comletter/remaining'         => $this->make_hook('coml_remaining',  AUTH_PASSWD, 'user'),
+            'comletter/out'               => $this->make_hook('out',             AUTH_COOKIE, 'user'),
             'comletter/show'              => $this->make_hook('nl_show',         AUTH_COOKIE, 'user'),
             'comletter/search'            => $this->make_hook('nl_search',       AUTH_COOKIE, 'user'),
             'comletter/admin'             => $this->make_hook('admin_nl',        AUTH_PASSWD, 'user'),
@@ -49,8 +52,49 @@ class ComLetterModule extends NewsletterModule
         return NewsLetter::forGroup(NewsLetter::GROUP_COMMUNITY);
     }
 
+    function handler_coml_submit($page)
+    {
+        $page->changeTpl('comletter/submit.tpl');
+
+        $nl = $this->getNl();
+        if (!$nl) {
+            return PL_NOT_FOUND;
+        }
+
+        $wp = new PlWikiPage('Xorg.LettreCommunaute');
+        $wp->buildCache();
+
+        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 ComLArticle(Post::v('title'), Post::v('body'), Post::v('append'));
+            $page->assign('art', $art);
+        } elseif (Post::has('valid')) {
+            $art = new ComLReq(S::user(), Post::v('title'),
+                               Post::v('body'), Post::v('append'));
+            $art->submit();
+            $page->assign('submited', true);
+        }
+        $page->addCssLink($nl->cssFile());
+    }
+
+    function handler_coml_remaining($page)
+    {
+        pl_content_headers('text/html');
+        $page->changeTpl('newsletter/remaining.tpl', NO_SKIN);
+
+        $article = new ComLArticle('', Post::t('body'), '');
+        $rest = $article->remain();
+
+        $page->assign('too_long', $rest['remaining_lines'] < 0);
+        $page->assign('last_line', ($rest['remaining_lines'] == 0));
+        $page->assign('remaining', ($rest['remaining_lines'] == 0) ? $rest['remaining_characters_for_last_line'] : $rest['remaining_lines']);
+    }
+
     function handler_out($page, $hash = null, $issue_id = null)
     {
+        $hash = ($hash == 'nohash') ? null : $hash;
         if (!$hash) {
             if (!S::logged()) {
                 return PL_DO_AUTH;
@@ -60,5 +104,5 @@ class ComLetterModule extends NewsletterModule
     }
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>