2c31e9c3d83b10128ffe154dfcd13caef5fc32c9
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 /********************************************************************************
15 function _b_($str) { return utf8_decode(dgettext('banana', utf8_encode($str))); }
17 /********************************************************************************
21 function _headerdecode($charset, $c, $str) {
22 $s = ($c == 'Q') ?
quoted_printable_decode($str) : base64_decode($str);
23 $s = iconv($charset, 'iso-8859-15', $s);
24 return str_replace('_', ' ', $s);
27 function headerDecode($value) {
28 $val = preg_replace('/(=\?[^?]*\?[BQ]\?[^?]*\?=) (=\?[^?]*\?[BQ]\?[^?]*\?=)/', '\1\2', $value);
29 return preg_replace('/=\?([^?]*)\?([BQ])\?([^?]*)\?=/e', '_headerdecode("\1", "\2", "\3")', $val);
32 function header_translate($hdr) {
34 case 'from': return _b_('De');
35 case 'subject': return _b_('Sujet');
36 case 'newsgroups': return _b_('Forums');
37 case 'followup-to': return _b_('Suivi-à');
38 case 'date': return _b_('Date');
39 case 'organization': return _b_('Organisation');
40 case 'references': return _b_('Références');
41 case 'x-face': return _b_('Image');
47 /********************************************************************************
51 function formatDate($_text) {
52 return strftime("%A %d %B %Y, %H:%M (fuseau serveur)", strtotime($_text));
55 function fancyDate($stamp) {
56 $today = intval(time() / (24*3600));
57 $dday = intval($stamp / (24*3600));
59 if ($today == $dday) {
61 } elseif ($today == 1 +
$dday) {
62 $format = _b_('hier')." %H:%M";
63 } elseif ($today < 7 +
$dday) {
68 return strftime($format, $stamp);
71 function formatFrom($text) {
72 # From: mark@cbosgd.ATT.COM
73 # From: mark@cbosgd.ATT.COM (Mark Horton)
74 # From: Mark Horton <mark@cbosgd.ATT.COM>
75 $mailto = '<a href="mailto:';
77 $result = htmlentities($text);
78 if (preg_match("/^([^ ]+)@([^ ]+)$/",$text,$regs)) {
79 $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[1]."@".$regs[2])."</a>";
81 if (preg_match("/^([^ ]+)@([^ ]+) \((.*)\)$/",$text,$regs)) {
82 $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[3])."</a>";
84 if (preg_match("/^\"?([^<>\"]+)\"? +<(.+)@(.+)>$/",$text,$regs)) {
85 $result="$mailto{$regs[2]}@{$regs[3]}\">".htmlentities($regs[1])."</a>";
87 return preg_replace("/\\\(\(|\))/","\\1",$result);
90 function wrap($text, $_prefix="", $_length=72)
92 $parts = preg_split("/\n-- ?\n/", $text);
93 if (count($parts) >1) {
94 $sign = "\n-- \n" . array_pop($parts);
95 $text = join("\n-- \n", $parts);
101 $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$_length, all=>1 };'";
104 return $_prefix.join("\n$_prefix", $result).($_prefix ?
'' : $sign);
107 function formatbody($_text) {
109 $res = "\n\n" . htmlentities(wrap($_text, "", $news['wrap']))."\n\n";
110 $res = preg_replace("/(<|>|")/", " \\1 ", $res);
111 $res = preg_replace('/(["\[])?((https?|ftp|news):\/\/[a-z@0-9.~%$£µ&i#\-+=_\/\?]*)(["\]])?/i', "\\1<a href=\"\\2\">\\2</a>\\4", $res);
112 $res = preg_replace("/ (<|>|") /", "\\1", $res);
114 $parts = preg_split("/\n-- ?\n/", $res);
116 if (count($parts) > 1) {
117 $sign = "</pre><hr style='width: 100%; margin: 1em 0em; ' /><pre>" . array_pop($parts);
118 return join("\n-- \n", $parts).$sign;