<?php
/********************************************************************************
-* include/misc.inc.php : Misc functions
-* -------------------------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
+ * include/misc.inc.php : Misc functions
+ * -------------------------
+ *
+ * This file is part of the banana distribution
+ * Copyright: See COPYING files that comes with this distribution
+ ********************************************************************************/
+
+/********************************************************************************
+ * MISC
+ */
+
+function _b_($str) { return utf8_decode(dgettext('banana', utf8_encode($str))); }
+
+/********************************************************************************
+ * HEADER STUFF
+ */
function _headerdecode($charset, $c, $str) {
$s = ($c == 'Q') ? quoted_printable_decode($str) : base64_decode($str);
}
function header_translate($hdr) {
- switch (strtolower($hdr)) {
- case 'from': return _('De');
- case 'subject': return _('Sujet');
- case 'newsgroups': return _('Forums');
- case 'followup': return _('Suivi-à');
- case 'date': return _('Date');
- case 'organization': return _('Organisation');
- case 'references': return _('Références');
- case 'xface': return _('Image');
+ switch ($hdr) {
+ case 'from': return _b_('De');
+ case 'subject': return _b_('Sujet');
+ case 'newsgroups': return _b_('Forums');
+ case 'followup-to': return _b_('Suivi-à');
+ case 'date': return _b_('Date');
+ case 'organization': return _b_('Organisation');
+ case 'references': return _b_('Références');
+ case 'x-face': return _b_('Image');
default:
+ if (function_exists('hook_headerTranslate')
+ && $res = hook_headerTranslate($hdr)) {
+ return $res;
+ }
return $hdr;
}
}
+function formatDisplayHeader($_header,$_text) {
+ global $banana;
+ switch ($_header) {
+ case "date":
+ return formatDate($_text);
+
+ case "followup-to":
+ case "newsgroups":
+ $res = "";
+ $groups = preg_split("/[\t ]*,[\t ]*/",$_text);
+ foreach ($groups as $g) {
+ $res.="<a href='?group=$g'>$g</a>, ";
+ }
+ return substr($res,0, -2);
+
+ case "from":
+ return formatFrom($_text);
+
+ case "references":
+ $rsl = "";
+ $ndx = 1;
+ $text = str_replace("><","> <",$_text);
+ $text = preg_split("/[ \t]/",strtr($text,$banana->spool->ids));
+ $parents = preg_grep("/^\d+$/",$text);
+ $p = array_pop($parents);
+ $par_ok = Array();
+
+ while ($p) {
+ $par_ok[]=$p;
+ $p = $banana->spool->overview[$p]->parent;
+ }
+ foreach (array_reverse($par_ok) as $p) {
+ $rsl .= "<a href=\"?group={$banana->spool->group}&artid=$p\">$ndx</a> ";
+ $ndx++;
+ }
+ return $rsl;
+
+ case "x-face":
+ return '<img src="xface.php?face='.base64_encode($_text).'" alt="x-face" />';
+
+ default:
+ if (function_exists('hook_formatDisplayHeader')
+ && $res = hook_formatDisplayHeader($_header, $_text))
+ {
+ return $res;
+ }
+ return htmlentities($_text);
+ }
+}
+
+/********************************************************************************
+ * FORMATTING STUFF
+ */
+
function formatDate($_text) {
return strftime("%A %d %B %Y, %H:%M (fuseau serveur)", strtotime($_text));
}
if ($today == $dday) {
$format = "%H:%M";
} elseif ($today == 1 + $dday) {
- $format = _('hier')." %H:%M";
+ $format = _b_('hier')." %H:%M";
} elseif ($today < 7 + $dday) {
- $format = '%A %H:%M';
+ $format = '%a %H:%M';
} else {
$format = '%a %e %b';
}
return preg_replace("/\\\(\(|\))/","\\1",$result);
}
-function wrap($text, $_prefix="", $_length=72)
+function displayshortcuts($first = -1) {
+ global $banana;
+ extract($banana->state);
+
+ $res = '<div class="banana_scuts">';
+ $res .= '[<a href="?">'._b_('Liste des forums').'</a>] ';
+ if (is_null($group)) {
+ return $res.'</div>';
+ }
+
+ $res .= "[<a href=\"?group=$group\">$group</a>] ";
+
+ if (is_null($artid)) {
+ $res .= "[<a href=\"?group=$group&action=new\">"._b_('Nouveau message')."</a>] ";
+ if (sizeof($banana->spool->overview)>$banana->tmax) {
+ $res .= '<br />';
+ $n = intval(log(count($banana->spool->overview), 10))+1;
+ for ($ndx=1; $ndx <= sizeof($banana->spool->overview); $ndx += $banana->tmax) {
+ if ($first==$ndx) {
+ $fmt = "[%0{$n}u-%0{$n}u] ";
+ } else {
+ $fmt = "[<a href=\"?group=$group&first=$ndx\">%0{$n}u-%0{$n}u</a>] ";
+ }
+ $res .= sprintf($fmt, $ndx, min($ndx+$banana->tmax-1,sizeof($banana->spool->overview)));
+ }
+ }
+ } else {
+ $res .= "[<a href=\"?group=$group&artid=$artid&action=new\">"
+ ._b_('Répondre')."</a>] ";
+ if ($banana->post->checkcancel()) {
+ $res .= "[<a href=\"?group=$group&artid=$artid&action=cancel\">"
+ ._b_('Annuler ce message')."</a>] ";
+ }
+ }
+ return $res.'</div>';
+}
+
+/********************************************************************************
+ * FORMATTING STUFF : BODY
+ */
+
+function wrap($text, $_prefix="")
{
$parts = preg_split("/\n-- ?\n/", $text);
if (count($parts) >1) {
$sign = '';
$text = $text;
}
-
- $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$_length, all=>1 };'";
+
+ global $banana;
+ $length = $banana->wrap;
+ $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$length, all=>1 };'";
exec($cmd, $result);
return $_prefix.join("\n$_prefix", $result).($_prefix ? '' : $sign);
}
function formatbody($_text) {
- global $news;
- $res = "\n\n" . htmlentities(wrap($_text, "", $news['wrap']))."\n\n";
+ $res = "\n\n" . htmlentities(wrap($_text, ""))."\n\n";
$res = preg_replace("/(<|>|")/", " \\1 ", $res);
$res = preg_replace('/(["\[])?((https?|ftp|news):\/\/[a-z@0-9.~%$£µ&i#\-+=_\/\?]*)(["\]])?/i', "\\1<a href=\"\\2\">\\2</a>\\4", $res);
$res = preg_replace("/ (<|>|") /", "\\1", $res);