X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=banana%2Fmisc.inc.php;h=ccc309b58164728bfb3da0215ae356b434c50ba9;hb=f0d8d46d2ace65fa202a31fd756463352c3bf560;hp=09cd285ec2474b7a63f771ae160ade8656edca45;hpb=92f5ea62fd125ff4be9deb8df205a036a47e1484;p=banana.git diff --git a/banana/misc.inc.php b/banana/misc.inc.php index 09cd285..ccc309b 100644 --- a/banana/misc.inc.php +++ b/banana/misc.inc.php @@ -300,7 +300,7 @@ function formatDisplayHeader($_header,$_text) { case "from": return formatFrom($_text); - + case "references": $rsl = ""; $ndx = 1; @@ -380,52 +380,56 @@ function formatFrom($text) { return preg_replace("/\\\(\(|\))/","\\1",$result); } +function makeTab($link, $text) +{ + return Array(makeHREF($link, $text), + $text); +} + function displayTabs() { global $banana; extract($banana->state); - - $res = Array(); if (function_exists('hook_shortcuts') && $cstm = hook_shortcuts()) { $res = $cstm; } - array_push($res, - makeHREF(Array('subscribe' => 1), _b_('Abonnements')), - is_null($group) ? Array(_b_('Les forums'), true) : makeHREF(Array(), _b_('Les forums'))); + $res['subscribe'] = makeTab(Array('subscribe' => 1), _b_('Abonnements')); + $res['forums'] = makeTab(Array(), _b_('Les forums')); if (!is_null($group)) { - $grplink = makeHREF(Array('group' => $group), $group); - $grpcur = Array($group, true); + $res['group'] = makeTab(Array('group' => $group), $group); if (is_null($artid)) { if (@$action == 'new') { - array_push($res, $grplink, Array(_b_('Nouveau Message'), true)); - } else { - array_push($res, $grpcur); + $res['action'] = makeTab(Array('group' => $group, + 'action' => 'new'), + _b_('Nouveau Message')); } } else { + $res['message'] = makeTab(Array('group' => $group, + 'artid' => $artid), + _b_('Message')); if (!is_null($action)) { - array_push($res, - $grplink, - makeHREF(Array('group' => $group, - 'artid' => $artid), - _b_('Message'))); if ($action == 'new') { - array_push($res, Array(_b_('RĂ©pondre'), true)); + $res['action'] = makeTab(Array('group' => $group, + 'artid' => $artid, + 'action' => 'new'), + _b_('RĂ©ponse')); } elseif ($action == 'cancel') { - array_push($res, Array(_b_('Annuler'), true)); + $res['action'] = makeTab(Array('group' => $group, + 'artid' => $artid, + 'action' => 'cancel'), + _b_('Annuler')); } - } else { - array_push($res, $grplink, Array(_b_('Message'), true)); } } } $ret = ''; @@ -461,7 +465,7 @@ function displayPages($first = -1) function makeTable($text) { - return '' + return '
' . '' @@ -475,16 +479,14 @@ function makeTable($text) * FORMATTING STUFF : BODY */ -function autoformat($text, $part = false) +function autoformat($text) { global $banana; $length = $banana->wrap; - $all = null; - if (!$part) { - $all = ', all=1'; - } - $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$length$all };'"; + $cmd = 'echo ' . escapeshellarg($text) + . ' | perl -MText::Autoformat -e \'autoformat {left=>1, right=>' . $length . ', all=>1 };\''; + exec($cmd, $result, $ret); if ($ret != 0) { $result = split("\n", $text); @@ -501,7 +503,7 @@ function wrap($text, $_prefix="", $_force=false) } else { $sign = ''; } - + global $banana; $url = $banana->url_regexp; $length = $banana->wrap; @@ -537,12 +539,8 @@ function wrap($text, $_prefix="", $_force=false) } } } else { - if (strlen($line) > 2 * $max) { - $next = array_merge($next, autoformat($line, true)); - } else { - $format = true; - array_push($next, $line); - } + array_push($next, $line); + $format = true; } } else { array_push($next, $line); @@ -573,6 +571,27 @@ function cleanurl($url) return ''.cutlink($url).''; } +function catchMailLink($email) +{ + global $banana; + $mid = '<' . $email . '>'; + if (isset($banana->spool->ids[$mid])) { + return makeHREF(Array('group' => $banana->state['group'], + 'artid' => $banana->spool->ids[$mid]), + $email); + } elseif (strpos($email, '$') !== false) { + return $email; + } + return '' . $email . ''; +} + +/** Remove quotation marks + */ +function replaceQuotes($text) +{ + return stripslashes(preg_replace("@(^|
|\n)>[ \t\r]*@i", '\1', $text));
+}
+
 function formatbody($_text, $format='plain', $flowed=false)
 {
     if ($format == 'html') {
@@ -589,7 +608,9 @@ function formatbody($_text, $format='plain', $flowed=false)
         $url  = $banana->url_regexp;
         $res  = preg_replace("/(<|>|")/", " \\1 ", $res);
         $res  = preg_replace("!$url!ie", "'\\1'.cleanurl('\\2').'\\3'", $res);
-        $res  = preg_replace('/(["\[])?(?:mailto:)?([a-z0-9.\-+_]+@[a-z0-9.\-+_]+)(["\]])?/i', '\1\2\3', $res);
+        $res  = preg_replace('/(["\[])?(?:mailto:|news:)?([a-z0-9.\-+_\$]+@([\-.+_]?[a-z0-9])+)(["\]])?/ie',
+                             "'\\1' . catchMailLink('\\2') . '\\4'",
+                             $res);
         $res  = preg_replace("/ (<|>|") /", "\\1", $res);
 
         if ($format == 'richtext') {
@@ -605,10 +626,10 @@ function formatbody($_text, $format='plain', $flowed=false)
         $sign  = '
'; } else { while (preg_match("@(^|
|\n)>@i", $res)) {
-            $res  = preg_replace("@(^|
|\n)((>[^\n]*\n)+)@ie",
+            $res  = preg_replace("@(^|
|\n)((>[^\n]*(?:\n|$))+)@ie",
                 "'\\1
'"
-                .".stripslashes(preg_replace('@(^|
|\n)>[ \\t\\r]*@i', '\\1', '\\2'))"
-                .".'
'",
+                ." . replaceQuotes('\\2')"
+                ." . '
'",
                 $res);
         }
         $res = preg_replace("@
-- ?\n@", "
\n-- \n", $res);
' . displayTabs() . '