From: Nicolas Iooss Date: Sat, 28 Dec 2013 21:55:53 +0000 (+0100) Subject: Community letter: add article submission limitations X-Git-Tag: xorg/1.1.11~4 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=60b19854568852e2a89d80f3456876ac4ff2cc9a;p=platal.git Community letter: add article submission limitations --- diff --git a/include/comletter.inc.php b/include/comletter.inc.php index 713101a..25efeea 100644 --- a/include/comletter.inc.php +++ b/include/comletter.inc.php @@ -23,6 +23,10 @@ class ComLArticle { + // Maximum number of lines per article, as wanted by the NL master + const MAX_LINES_PER_ARTICLE = 4; + const MAX_CHARACTERS_PER_LINE = 68; + // {{{ properties public $aid; @@ -105,6 +109,35 @@ class ComLArticle } // }}} + // {{{ function check() + + public function check() + { + $rest = $this->remain(); + + return $rest['remaining_lines'] >= 0; + } + + // }}} + // {{{ function remain() + + public function remain() + { + $text = MiniWiki::WikiToText($this->body); + $array = explode("\n", wordwrap($text, self::MAX_CHARACTERS_PER_LINE)); + $lines_count = 0; + foreach ($array as $line) { + if (trim($line) != '') { + ++$lines_count; + } + } + + return array( + 'remaining_lines' => self::MAX_LINES_PER_ARTICLE - $lines_count, + 'remaining_characters_for_last_line' => self::MAX_CHARACTERS_PER_LINE - strlen($array[count($array) - 1]) + ); + } + // }}} } // }}} diff --git a/modules/comletter.php b/modules/comletter.php index 959b62a..b6e7194 100644 --- a/modules/comletter.php +++ b/modules/comletter.php @@ -32,6 +32,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/remaining' => $this->make_hook('coml_remaining', 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'), @@ -78,6 +79,19 @@ class ComLetterModule extends NewsletterModule $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) { if (!$hash) { diff --git a/templates/comletter/submit.tpl b/templates/comletter/submit.tpl index c2aa702..f086bb9 100644 --- a/templates/comletter/submit.tpl +++ b/templates/comletter/submit.tpl @@ -36,6 +36,14 @@ Nous te recontacterons éventuellement si nous avons des renseignements à te de {if t($art)} + +{if !$art->check()} +

+L'article que tu as proposé est trop long !
+Il te faut te limiter à 4 lignes de 68 caractères. +

+{/if} +
@@ -50,6 +58,7 @@ Nous te recontacterons éventuellement si nous avons des renseignements à te de + {if $art->check()} @@ -67,6 +76,7 @@ Nous te recontacterons éventuellement si nous avons des renseignements à te de + {/if}
Version texte
Soumettre
@@ -93,7 +103,9 @@ Tu peux lire les conseils de rédaction Contenu - +