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;
}
// }}}
+ // {{{ 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])
+ );
+ }
+ // }}}
}
// }}}
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'),
$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) {
{if t($art)}
+
+{if !$art->check()}
+<p class='erreur'>
+L'article que tu as proposé est trop long !<br />
+Il te faut te limiter à 4 lignes de 68 caractères.
+</p>
+{/if}
+
<form action="comletter/submit" method='post'>
<table class='bicol'>
<tr><th>Version texte</th></tr>
</div>
</td>
</tr>
+ {if $art->check()}
<tr>
<th>Soumettre</th>
</tr>
<input type='submit' name='valid' value='Soumettre' />
</td>
</tr>
+ {/if}
</table>
</form>
<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('comletter/remaining/', {'body': this.value}, function(data) {$('#remaining').html(data)}){/literal}"
+ onkeyup="{literal}$.post('comletter/remaining/', {'body': this.value}, function(data) {$('#remaining').html(data)}){/literal}"
+ cols="68" rows="4" name="body" >{if t($art)}{$art->body()}{/if}</textarea>
</td>
</tr>
<tr class="pair">