Force auth on newsletter unsubscription link
[platal.git] / modules / comletter.php
CommitLineData
26cba39a
NI
1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 Polytechnique.org *
26cba39a
NI
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22Platal::load('newsletter');
2be9fe58 23require_once 'comletter.inc.php';
26cba39a
NI
24
25/**
26 * Newsletter for community
27 */
28class ComLetterModule extends NewsletterModule
29{
30 function handlers()
31 {
32 return array(
33 'comletter' => $this->make_hook('nl', AUTH_COOKIE, 'user'),
2be9fe58 34 'comletter/submit' => $this->make_hook('coml_submit', AUTH_PASSWD, 'user'),
60b19854 35 'comletter/remaining' => $this->make_hook('coml_remaining', AUTH_PASSWD, 'user'),
6d1125df 36 'comletter/out' => $this->make_hook('out', AUTH_COOKIE, 'user'),
26cba39a
NI
37 'comletter/show' => $this->make_hook('nl_show', AUTH_COOKIE, 'user'),
38 'comletter/search' => $this->make_hook('nl_search', AUTH_COOKIE, 'user'),
39 'comletter/admin' => $this->make_hook('admin_nl', AUTH_PASSWD, 'user'),
40 'comletter/admin/edit' => $this->make_hook('admin_nl_edit', AUTH_PASSWD, 'user'),
41 'comletter/admin/edit/valid' => $this->make_hook('admin_nl_valid', AUTH_PASSWD, 'user'),
42 'comletter/admin/edit/cancel' => $this->make_hook('admin_nl_cancel', AUTH_PASSWD, 'user'),
43 'comletter/admin/edit/delete' => $this->make_hook('admin_nl_delete', AUTH_PASSWD, 'user'),
44 'comletter/admin/categories' => $this->make_hook('admin_nl_cat', AUTH_PASSWD, 'user'),
45 'comletter/stat' => $this->make_hook('stat_nl', AUTH_PASSWD, 'user')
46 );
47 }
48
49 protected function getNl()
50 {
51 require_once 'newsletter.inc.php';
52 return NewsLetter::forGroup(NewsLetter::GROUP_COMMUNITY);
53 }
54
2be9fe58
NI
55 function handler_coml_submit($page)
56 {
57 $page->changeTpl('comletter/submit.tpl');
58
59 $nl = $this->getNl();
60 if (!$nl) {
61 return PL_NOT_FOUND;
62 }
63
64 $wp = new PlWikiPage('Xorg.LettreCommunaute');
65 $wp->buildCache();
66
67 if (Post::has('see') || (Post::has('valid') && (!trim(Post::v('title')) || !trim(Post::v('body'))))) {
68 if (!Post::has('see')) {
69 $page->trigError("L'article doit avoir un titre et un contenu");
70 }
71 $art = new ComLArticle(Post::v('title'), Post::v('body'), Post::v('append'));
72 $page->assign('art', $art);
73 } elseif (Post::has('valid')) {
74 $art = new ComLReq(S::user(), Post::v('title'),
75 Post::v('body'), Post::v('append'));
76 $art->submit();
77 $page->assign('submited', true);
78 }
79 $page->addCssLink($nl->cssFile());
80 }
81
60b19854
NI
82 function handler_coml_remaining($page)
83 {
84 pl_content_headers('text/html');
85 $page->changeTpl('newsletter/remaining.tpl', NO_SKIN);
86
87 $article = new ComLArticle('', Post::t('body'), '');
88 $rest = $article->remain();
89
90 $page->assign('too_long', $rest['remaining_lines'] < 0);
91 $page->assign('last_line', ($rest['remaining_lines'] == 0));
92 $page->assign('remaining', ($rest['remaining_lines'] == 0) ? $rest['remaining_characters_for_last_line'] : $rest['remaining_lines']);
93 }
94
26cba39a
NI
95 function handler_out($page, $hash = null, $issue_id = null)
96 {
6d1125df 97 $hash = ($hash == 'nohash') ? null : $hash;
26cba39a
NI
98 if (!$hash) {
99 if (!S::logged()) {
100 return PL_DO_AUTH;
101 }
102 }
103 return $this->handler_nl($page, 'out', $hash, $issue_id);
104 }
105}
106
448c8cdc 107// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
26cba39a 108?>