2 /********************************************************************************
3 * include/misc.inc.php : Misc functions
4 * -------------------------
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
10 function _b_($str) { return utf8_decode(dgettext('banana', utf8_encode($str))); }
12 function _headerdecode($charset, $c, $str) {
13 $s = ($c == 'Q') ?
quoted_printable_decode($str) : base64_decode($str);
14 $s = iconv($charset, 'iso-8859-15', $s);
15 return str_replace('_', ' ', $s);
18 function headerDecode($value) {
19 $val = preg_replace('/(=\?[^?]*\?[BQ]\?[^?]*\?=) (=\?[^?]*\?[BQ]\?[^?]*\?=)/', '\1\2', $value);
20 return preg_replace('/=\?([^?]*)\?([BQ])\?([^?]*)\?=/e', '_headerdecode("\1", "\2", "\3")', $val);
23 function header_translate($hdr) {
25 case 'from': return _b_('De');
26 case 'subject': return _b_('Sujet');
27 case 'newsgroups': return _b_('Forums');
28 case 'followup-to': return _b_('Suivi-à');
29 case 'date': return _b_('Date');
30 case 'organization': return _b_('Organisation');
31 case 'references': return _b_('Références');
32 case 'x-face': return _b_('Image');
38 function formatDate($_text) {
39 return strftime("%A %d %B %Y, %H:%M (fuseau serveur)", strtotime($_text));
42 function fancyDate($stamp) {
43 $today = intval(time() / (24*3600));
44 $dday = intval($stamp / (24*3600));
46 if ($today == $dday) {
48 } elseif ($today == 1 +
$dday) {
49 $format = _b_('hier')." %H:%M";
50 } elseif ($today < 7 +
$dday) {
55 return strftime($format, $stamp);
58 function formatFrom($text) {
59 # From: mark@cbosgd.ATT.COM
60 # From: mark@cbosgd.ATT.COM (Mark Horton)
61 # From: Mark Horton <mark@cbosgd.ATT.COM>
62 $mailto = '<a href="mailto:';
64 $result = htmlentities($text);
65 if (preg_match("/^([^ ]+)@([^ ]+)$/",$text,$regs)) {
66 $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[1]."@".$regs[2])."</a>";
68 if (preg_match("/^([^ ]+)@([^ ]+) \((.*)\)$/",$text,$regs)) {
69 $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[3])."</a>";
71 if (preg_match("/^\"?([^<>\"]+)\"? +<(.+)@(.+)>$/",$text,$regs)) {
72 $result="$mailto{$regs[2]}@{$regs[3]}\">".htmlentities($regs[1])."</a>";
74 return preg_replace("/\\\(\(|\))/","\\1",$result);
77 function wrap($text, $_prefix="", $_length=72)
79 $parts = preg_split("/\n-- ?\n/", $text);
80 if (count($parts) >1) {
81 $sign = "\n-- \n" . array_pop($parts);
82 $text = join("\n-- \n", $parts);
88 $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$_length, all=>1 };'";
91 return $_prefix.join("\n$_prefix", $result).($_prefix ?
'' : $sign);
94 function formatbody($_text) {
96 $res = "\n\n" . htmlentities(wrap($_text, "", $news['wrap']))."\n\n";
97 $res = preg_replace("/(<|>|")/", " \\1 ", $res);
98 $res = preg_replace('/(["\[])?((https?|ftp|news):\/\/[a-z@0-9.~%$£µ&i#\-+=_\/\?]*)(["\]])?/i', "\\1<a href=\"\\2\">\\2</a>\\4", $res);
99 $res = preg_replace("/ (<|>|") /", "\\1", $res);
101 $parts = preg_split("/\n-- ?\n/", $res);
103 if (count($parts) > 1) {
104 $sign = "</pre><hr style='width: 100%; margin: 1em 0em; ' /><pre>" . array_pop($parts);
105 return join("\n-- \n", $parts).$sign;