From: Stéphane Jacob Date: Sun, 13 Mar 2011 20:52:45 +0000 (+0100) Subject: Displays remaining lines and characters in nl article submission (Closes #908). X-Git-Tag: xorg/1.1.0~32 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;ds=sidebyside;h=0fd5be9929ec59aefa4f2d0ec7ed66e29a5daf3b;p=platal.git Displays remaining lines and characters in nl article submission (Closes #908). Signed-off-by: Stéphane Jacob --- diff --git a/ChangeLog b/ChangeLog index 26e5f8e..8d90d6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,9 @@ Bug/Wish: - #1035: Bases emails on users types (eg educationnal types) -JAC - #1404: Implements best_domain -JAC + * Newsletter: + - #908: Displays remaining lines and characters in submission -JAC + * Payments: - #1398: Creates csv for payments -JAC diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 667099c..0ee1423 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -1124,7 +1124,8 @@ class NLIssue class NLArticle { // Maximum number of lines per article - const MAX_LINES_PER_ARTICLE = 9; + const MAX_LINES_PER_ARTICLE = 8; + const MAX_CHARACTERS_PER_LINE = 68; // {{{ properties @@ -1212,17 +1213,30 @@ class NLArticle public function check() { - $text = MiniWiki::WikiToText($this->body); - $arr = explode("\n",wordwrap($text,68)); - $c = 0; - foreach ($arr as $line) { - if (trim($line)) { - $c++; + $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 $c < self::MAX_LINES_PER_ARTICLE; - } + 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]) + ); + } // }}} // {{{ function parseUrlsFromArticle() diff --git a/modules/newsletter.php b/modules/newsletter.php index 6d18e7e..632f375 100644 --- a/modules/newsletter.php +++ b/modules/newsletter.php @@ -27,6 +27,7 @@ class NewsletterModule extends PLModule 'nl' => $this->make_hook('nl', AUTH_COOKIE), 'nl/show' => $this->make_hook('nl_show', AUTH_COOKIE), 'nl/submit' => $this->make_hook('nl_submit', AUTH_MDP), + 'nl/remaining' => $this->make_hook('nl_remaining', AUTH_MDP), 'admin/nls' => $this->make_hook('admin_nl_groups', AUTH_MDP, 'admin'), 'admin/newsletter' => $this->make_hook('admin_nl', AUTH_MDP, 'admin'), 'admin/newsletter/categories' => $this->make_hook('admin_nl_cat', AUTH_MDP, 'admin'), @@ -118,6 +119,21 @@ class NewsletterModule extends PLModule $page->addCssLink($nl->cssFile()); } + function handler_nl_remaining($page) + { + require_once 'newsletter.inc.php'; + + pl_content_headers('text/html'); + $page->changeTpl('newsletter/remaining.tpl', NO_SKIN); + + $article = new NLArticle('', 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_admin_nl($page, $new = false) { $page->changeTpl('newsletter/admin.tpl'); $page->setTitle('Administration - Newsletter : liste'); diff --git a/templates/newsletter/remaining.tpl b/templates/newsletter/remaining.tpl new file mode 100644 index 0000000..9de482a --- /dev/null +++ b/templates/newsletter/remaining.tpl @@ -0,0 +1,31 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2011 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 *} +{* *} +{**************************************************************************} + + + {if t($too_long)} + L'article est trop long. + {else} + Il reste encore {$remaining} {if t($last_line)}caractères{else}lignes{/if}, une fois l'article formatté. + {/if} + + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/newsletter/submit.tpl b/templates/newsletter/submit.tpl index 9e3758f..eb7030d 100644 --- a/templates/newsletter/submit.tpl +++ b/templates/newsletter/submit.tpl @@ -104,9 +104,14 @@ Tu peux lire les conseils de rédaction avant d Contenu - + + + + Ajouts (emails, contacts, tarifs, site web…)