Add article submission system for community letter
[platal.git] / modules / comletter.php
CommitLineData
26cba39a
NI
1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2013 Polytechnique.org *
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'),
26cba39a
NI
35 'comletter/out' => $this->make_hook('out', AUTH_PUBLIC),
36 'comletter/show' => $this->make_hook('nl_show', AUTH_COOKIE, 'user'),
37 'comletter/search' => $this->make_hook('nl_search', AUTH_COOKIE, 'user'),
38 'comletter/admin' => $this->make_hook('admin_nl', AUTH_PASSWD, 'user'),
39 'comletter/admin/edit' => $this->make_hook('admin_nl_edit', AUTH_PASSWD, 'user'),
40 'comletter/admin/edit/valid' => $this->make_hook('admin_nl_valid', AUTH_PASSWD, 'user'),
41 'comletter/admin/edit/cancel' => $this->make_hook('admin_nl_cancel', AUTH_PASSWD, 'user'),
42 'comletter/admin/edit/delete' => $this->make_hook('admin_nl_delete', AUTH_PASSWD, 'user'),
43 'comletter/admin/categories' => $this->make_hook('admin_nl_cat', AUTH_PASSWD, 'user'),
44 'comletter/stat' => $this->make_hook('stat_nl', AUTH_PASSWD, 'user')
45 );
46 }
47
48 protected function getNl()
49 {
50 require_once 'newsletter.inc.php';
51 return NewsLetter::forGroup(NewsLetter::GROUP_COMMUNITY);
52 }
53
2be9fe58
NI
54 function handler_coml_submit($page)
55 {
56 $page->changeTpl('comletter/submit.tpl');
57
58 $nl = $this->getNl();
59 if (!$nl) {
60 return PL_NOT_FOUND;
61 }
62
63 $wp = new PlWikiPage('Xorg.LettreCommunaute');
64 $wp->buildCache();
65
66 if (Post::has('see') || (Post::has('valid') && (!trim(Post::v('title')) || !trim(Post::v('body'))))) {
67 if (!Post::has('see')) {
68 $page->trigError("L'article doit avoir un titre et un contenu");
69 }
70 $art = new ComLArticle(Post::v('title'), Post::v('body'), Post::v('append'));
71 $page->assign('art', $art);
72 } elseif (Post::has('valid')) {
73 $art = new ComLReq(S::user(), Post::v('title'),
74 Post::v('body'), Post::v('append'));
75 $art->submit();
76 $page->assign('submited', true);
77 }
78 $page->addCssLink($nl->cssFile());
79 }
80
26cba39a
NI
81 function handler_out($page, $hash = null, $issue_id = null)
82 {
83 if (!$hash) {
84 if (!S::logged()) {
85 return PL_DO_AUTH;
86 }
87 }
88 return $this->handler_nl($page, 'out', $hash, $issue_id);
89 }
90}
91
92// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
93?>