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 _headerdecode($charset, $c, $str) {
11 $s = ($c == 'Q') ?
quoted_printable_decode($str) : base64_decode($str);
12 $s = iconv($charset, 'iso-8859-15', $s);
13 return str_replace('_', ' ', $s);
16 function headerDecode($value) {
17 $val = preg_replace('/(=\?[^?]*\?[BQ]\?[^?]*\?=) (=\?[^?]*\?[BQ]\?[^?]*\?=)/', '\1\2', $value);
18 return preg_replace('/=\?([^?]*)\?([BQ])\?([^?]*)\?=/e', '_headerdecode("\1", "\2", "\3")', $val);
21 function header_translate($hdr) {
22 switch (strtolower($hdr)) {
23 case 'from': return _('De');
24 case 'subject': return _('Sujet');
25 case 'newsgroups': return _('Forums');
26 case 'followup': return _('Suivi-à');
27 case 'date': return _('Date');
28 case 'organization': return _('Organisation');
29 case 'references': return _('Références');
30 case 'xface': return _('Image');
36 function formatDate($_text) {
37 return strftime("%A %d %B %Y, %H:%M (fuseau serveur)", strtotime($_text));
40 function fancyDate($stamp) {
41 $today = intval(time() / (24*3600));
42 $dday = intval($stamp / (24*3600));
44 if ($today == $dday) {
46 } elseif ($today == 1 +
$dday) {
47 $format = _('hier')." %H:%M";
48 } elseif ($today < 7 +
$dday) {
53 return strftime($format, $stamp);
56 function formatFrom($text) {
57 # From: mark@cbosgd.ATT.COM
58 # From: mark@cbosgd.ATT.COM (Mark Horton)
59 # From: Mark Horton <mark@cbosgd.ATT.COM>
60 $mailto = '<a href="mailto:';
62 $result = htmlentities($text);
63 if (preg_match("/^([^ ]+)@([^ ]+)$/",$text,$regs)) {
64 $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[1]."@".$regs[2])."</a>";
66 if (preg_match("/^([^ ]+)@([^ ]+) \((.*)\)$/",$text,$regs)) {
67 $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[3])."</a>";
69 if (preg_match("/^\"?([^<>\"]+)\"? +<(.+)@(.+)>$/",$text,$regs)) {
70 $result="$mailto{$regs[2]}@{$regs[3]}\">".htmlentities($regs[1])."</a>";
72 return preg_replace("/\\\(\(|\))/","\\1",$result);
75 function wrap($text, $_prefix="", $_length=72)
77 $parts = preg_split("/\n-- ?\n/", $text);
78 if (count($parts) >1) {
79 $sign = "\n-- \n" . array_pop($parts);
80 $text = join("\n-- \n", $parts);
86 $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$_length, all=>1 };'";
89 return $_prefix.join("\n$_prefix", $result).($_prefix ?
'' : $sign);
92 function formatbody($_text) {
94 $res = "\n\n" . htmlentities(wrap($_text, "", $news['wrap']))."\n\n";
95 $res = preg_replace("/(<|>|")/", " \\1 ", $res);
96 $res = preg_replace('/(["\[])?((https?|ftp|news):\/\/[a-z@0-9.~%$£µ&i#\-+=_\/\?]*)(["\]])?/i', "\\1<a href=\"\\2\">\\2</a>\\4", $res);
97 $res = preg_replace("/ (<|>|") /", "\\1", $res);
99 $parts = preg_split("/\n-- ?\n/", $res);
101 if (count($parts) > 1) {
102 $sign = "</pre><hr style='width: 100%; margin: 1em 0em; ' /><pre>" . array_pop($parts);
103 return join("\n-- \n", $parts).$sign;