- #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
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
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()
'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'),
$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');
--- /dev/null
+{**************************************************************************}
+{* *}
+{* 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 *}
+{* *}
+{**************************************************************************}
+
+<small>
+ {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}
+</small>
+
+{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
<tr class="pair">
<td class='titre'>Contenu</td>
<td>
- <textarea cols="68" rows="8" name='body'>{if t($art)}{$art->body()}{/if}</textarea>
+ <textarea onchange="{literal}$.post('nl/remaining/', {'body': this.value}, function(data) {$('#remaining').html(data)}){/literal}"
+ onkeyup="{literal}$.post('nl/remaining/', {'body': this.value}, function(data) {$('#remaining').html(data)}){/literal}"
+ cols="68" rows="8" name="body" >{if t($art)}{$art->body()}{/if}</textarea>
</td>
</tr>
+ <tr class="pair">
+ <td id="remaining" class="center" colspan="2"></td>
+ </tr>
<tr class="impair">
<td class='titre'>Ajouts (emails, contacts, tarifs, site web…)</td>
<td>