From 2be9fe585f8e410d6918ad04d5ebcd0e6b74f109 Mon Sep 17 00:00:00 2001 From: Nicolas Iooss Date: Sun, 29 Dec 2013 17:39:33 +0100 Subject: [PATCH] Add article submission system for community letter --- include/comletter.inc.php | 113 +++++++++++++++++++++++++++++ include/newsletter.inc.php | 7 +- include/validations/comletter.inc.php | 67 ++++++++++++++++++ modules/comletter.php | 29 ++++++++ templates/comletter/submit.tpl | 129 ++++++++++++++++++++++++++++++++++ upgrade/1.1.11/02_validate.sql | 3 + 6 files changed, 346 insertions(+), 2 deletions(-) create mode 100644 include/comletter.inc.php create mode 100644 include/validations/comletter.inc.php create mode 100644 templates/comletter/submit.tpl create mode 100644 upgrade/1.1.11/02_validate.sql diff --git a/include/comletter.inc.php b/include/comletter.inc.php new file mode 100644 index 0000000..713101a --- /dev/null +++ b/include/comletter.inc.php @@ -0,0 +1,113 @@ +body = $body; + $this->title = $title; + $this->append = $append; + $this->aid = $aid; + $this->cid = $cid; + $this->pos = $pos; + } + + // }}} + // {{{ function title() + + public function title() + { return trim($this->title); } + + // }}} + // {{{ function body() + + public function body() + { return trim($this->body); } + + // }}} + // {{{ function append() + + public function append() + { return trim($this->append); } + + // }}} + // {{{ function toText() + + public function toText($hash = null, $login = null) + { + $title = '*'.$this->title().'*'; + $body = MiniWiki::WikiToText($this->body, true); + $app = MiniWiki::WikiToText($this->append, false, 4); + $text = trim("$title\n\n$body\n\n$app")."\n"; + if (!is_null($hash) && !is_null($login)) { + $text = str_replace('%HASH%', "$hash/$login", $text); + } else { + $text = str_replace('%HASH%', '', $text); + } + return $text; + } + + // }}} + // {{{ function toHtml() + + public function toHtml($hash = null, $login = null) + { + $title = "

".pl_entities($this->title()).'

'; + $body = MiniWiki::WikiToHTML($this->body); + $app = MiniWiki::WikiToHTML($this->append); + + $art = "$title\n"; + $art .= "
\n$body\n"; + if ($app) { + $art .= "
$app
"; + } + $art .= "
\n"; + if (!is_null($hash) && !is_null($login)) { + $art = str_replace('%HASH%', "$hash/$login", $art); + } else { + $art = str_replace('%HASH%', '', $art); + } + + return $art; + } + + // }}} +} + +// }}} + +// vim:set et sw=4 sts=4 sws=4 enc=utf-8: +?> diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index fc08040..5cfe34d 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -503,8 +503,11 @@ class NewsLetter */ public function maySubmit($user = null) { - // Submission of new articles is only enabled for the X.org NL (and forbidden when viewing issues on X.net) - return ($this->group == self::GROUP_XORG && !isset($GLOBALS['IS_XNET_SITE'])); + // Submission of new articles is only enabled for the X.org NL and the + // community letter (and forbidden when viewing issues on X.net) + return ( + ($this->group == self::GROUP_XORG || $this->group == self::GROUP_COMMUNITY) + && !isset($GLOBALS['IS_XNET_SITE'])); } // }}} diff --git a/include/validations/comletter.inc.php b/include/validations/comletter.inc.php new file mode 100644 index 0000000..530d7bc --- /dev/null +++ b/include/validations/comletter.inc.php @@ -0,0 +1,67 @@ +art = new ComLArticle($_title, $_body, $_append); + } + + // }}} + // {{{ function _mail_subj + + protected function _mail_subj() + { + return "[Polytechnique.org/LettreCommunauté] Proposition d'article dans la Lettre de la communauté"; + } + + // }}} + // {{{ function commit() + + public function commit() + { + $nl = NewsLetter::forGroup(NewsLetter::GROUP_COMMUNITY)->getPendingIssue(true); + $nl->saveArticle($this->art); + return true; + } + + // }}} +} + +// }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/modules/comletter.php b/modules/comletter.php index 103adef..959b62a 100644 --- a/modules/comletter.php +++ b/modules/comletter.php @@ -20,6 +20,7 @@ ***************************************************************************/ Platal::load('newsletter'); +require_once 'comletter.inc.php'; /** * Newsletter for community @@ -30,6 +31,7 @@ class ComLetterModule extends NewsletterModule { return array( 'comletter' => $this->make_hook('nl', AUTH_COOKIE, 'user'), + 'comletter/submit' => $this->make_hook('coml_submit', AUTH_PASSWD, 'user'), 'comletter/out' => $this->make_hook('out', AUTH_PUBLIC), 'comletter/show' => $this->make_hook('nl_show', AUTH_COOKIE, 'user'), 'comletter/search' => $this->make_hook('nl_search', AUTH_COOKIE, 'user'), @@ -49,6 +51,33 @@ 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_out($page, $hash = null, $issue_id = null) { if (!$hash) { diff --git a/templates/comletter/submit.tpl b/templates/comletter/submit.tpl new file mode 100644 index 0000000..c2aa702 --- /dev/null +++ b/templates/comletter/submit.tpl @@ -0,0 +1,129 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2013 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + +

Proposer un article pour la prochaine Lettre de la communauté

+ +{if t($submited)} + +

+Ton article a bien été pris en compte. +

+ +

+Nous te recontacterons éventuellement si nous avons des renseignements à te demander à son sujet ! +

+ +{else} + + +{if t($art)} +
+ + + + + + + + + + + + + + + + + + +
Version texte
{$art->toText()}
Version html
+
+ {$art->toHtml()|smarty:nodefaults} +
+
Soumettre
+ Si tu es content de ton article, tu peux le soumettre. + Sinon, tu peux continuer à l'éditer en dessous. +
+ + + + +
+
+ +
+ +{/if} + +

Proposer un article

+ +

+Tu peux lire les conseils de rédaction avant de proposer ton article. +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Proposer un article
Sujet + +
Contenu + +
Ajouts (emails, contacts, tarifs, site web…) + +
+ + {icon name=information title="Syntaxe wiki"} Voir les marqueurs de mise en forme autorisés + +
+ +
+
+ + +{include wiki=Xorg.LettreCommunaute} + +{/if} + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/upgrade/1.1.11/02_validate.sql b/upgrade/1.1.11/02_validate.sql new file mode 100644 index 0000000..03536c6 --- /dev/null +++ b/upgrade/1.1.11/02_validate.sql @@ -0,0 +1,3 @@ +ALTER TABLE requests_answers MODIFY COLUMN category ENUM('alias','liste','usage','photo','evts','gapps-unsuspend','marketing','orange','homonyme','nl','paiements','medal','broken','surveys', 'entreprise','account','address','bulkaccounts', 'community-letter') NOT NULL DEFAULT 'alias'; + +-- vim:set syntax=mysql: -- 2.1.4