X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fmisc.inc.php;h=bdac4fac3913bf0a605954c5674d8716e12d2f07;hb=abb21748aff438a931f7064bd8ef4d45490d7a37;hp=9731d160be67e10a9bc8791c4ec803d869b4bf05;hpb=cced14b680fba9d9b84e06fda822a7b7daf3fad6;p=banana.git diff --git a/include/misc.inc.php b/include/misc.inc.php index 9731d16..bdac4fa 100644 --- a/include/misc.inc.php +++ b/include/misc.inc.php @@ -1,38 +1,219 @@ $g, "; + } + 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 .= "spool->group}&artid=$p\">$ndx "; + $ndx++; + } + return $rsl; + + case "x-face": + return '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)); +} + +function fancyDate($stamp) { + $today = intval(time() / (24*3600)); + $dday = intval($stamp / (24*3600)); + + if ($today == $dday) { + $format = "%H:%M"; + } elseif ($today == 1 + $dday) { + $format = _b_('hier')." %H:%M"; + } elseif ($today < 7 + $dday) { + $format = '%a %H:%M'; + } else { + $format = '%a %e %b'; + } + return strftime($format, $stamp); +} + +function formatFrom($text) { +# From: mark@cbosgd.ATT.COM +# From: mark@cbosgd.ATT.COM (Mark Horton) +# From: Mark Horton + $mailto = '".htmlentities($regs[1]."@".$regs[2]).""; + } + if (preg_match("/^([^ ]+)@([^ ]+) \((.*)\)$/",$text,$regs)) { + $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[3]).""; + } + if (preg_match("/^\"?([^<>\"]+)\"? +<(.+)@(.+)>$/",$text,$regs)) { + $result="$mailto{$regs[2]}@{$regs[3]}\">".htmlentities($regs[1]).""; + } + return preg_replace("/\\\(\(|\))/","\\1",$result); +} + +function displayshortcuts($first = -1) { + global $banana; + extract($banana->state); + + $res = '
'; + $res .= '['._b_('Liste des forums').'] '; + if (is_null($group)) { + return $res.'
'; + } + + $res .= "[$group] "; + + if (is_null($artid)) { + $res .= "["._b_('Nouveau message')."] "; + if (sizeof($banana->spool->overview)>$banana->tmax) { + $res .= '
'; + $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 = "[%0{$n}u-%0{$n}u] "; + } + $res .= sprintf($fmt, $ndx, min($ndx+$banana->tmax-1,sizeof($banana->spool->overview))); + } + } + } else { + $res .= "[" + ._b_('Répondre')."] "; + if ($banana->post->checkcancel()) { + $res .= "[" + ._b_('Annuler ce message')."] "; + } + } + return $res.''; +} + +/******************************************************************************** + * FORMATTING STUFF : BODY + */ + +function wrap($text, $_prefix="") { - $parts = preg_split("/\n-- ?\n/", $_text); + $parts = preg_split("/\n-- ?\n/", $text); if (count($parts) >1) { $sign = "\n-- \n" . array_pop($parts); $text = join("\n-- \n", $parts); } else { $sign = ''; - $text = $_text; + $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 _headerdecode($charset, $c, $str) { - $s = ($c == 'Q') ? quoted_printable_decode($str) : base64_decode($str); - $s = iconv($charset, 'iso-8859-15', $s); - return str_replace('_', ' ', $s); -} - -function headerDecode($value) { - $val = preg_replace('/(=\?[^?]*\?[BQ]\?[^?]*\?=) (=\?[^?]*\?[BQ]\?[^?]*\?=)/', '\1\2', $value); - return preg_replace('/=\?([^?]*)\?([BQ])\?([^?]*)\?=/e', '_headerdecode("\1", "\2", "\3")', $val); +function formatbody($_text) { + $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\\2\\4", $res); + $res = preg_replace("/ (<|>|") /", "\\1", $res); + + $parts = preg_split("/\n-- ?\n/", $res); + + if (count($parts) > 1) { + $sign = "
" . array_pop($parts);
+        return join("\n-- \n", $parts).$sign;
+    } else {
+        return $res;
+    }
 }
 
 ?>