Use css padding instead of line breaks in body
[banana.git] / banana / misc.inc.php
index 9a8307f..b280c9a 100644 (file)
@@ -99,7 +99,7 @@ function makeHREF($params, $text = null, $popup = null, $class = null)
     if (isset($params['action']) && $params['action'] == 'view') {
         $target = ' target="_blank"';
     }
-    return '<a href="' . htmlentities($link) . $target . '"' . $popup . $class . '>' . $text . '</a>';
+    return '<a href="' . htmlentities($link) .'"' . $target . $popup . $class . '>' . $text . '</a>';
 }
 
 /** Format tree images links
@@ -315,7 +315,9 @@ function formatDisplayHeader($_header,$_text) {
                 $p = $banana->spool->overview[$p]->parent;
             }
             foreach (array_reverse($par_ok) as $p) {
-                $rsl .= makeHREF(Array('group' => $banana->spool->group), $ndx) . ' ';
+                $rsl .= makeHREF(Array('group' => $banana->spool->group,
+                                       'artid' => $p),
+                                 $ndx) . ' ';
                 $ndx++;
             }
             return $rsl;
@@ -414,8 +416,25 @@ function displayShortcuts($first = -1)
                     $res .= sprintf($fmt, $ndx, min($ndx+$banana->tmax-1,sizeof($banana->spool->overview)));
                 }
             }
+            if (!is_null($action)) {
+                if ($action == 'new') {
+                    $res .= ' > Nouveau Message';
+                }
+            }
         } else {
-            $res .= ' > Message';
+            if (!is_null($action)) {
+                $res .= ' > ' . makeHREF(Array('group' => $group,
+                                               'artid' => $artid),
+                                         'Message')
+                     . ' > ';
+                if ($action == 'new') {
+                    $res .= 'RĂ©pondre';
+                } elseif ($action == 'cancel') {
+                    $res .= 'Annuler';
+                }
+            } else {
+                $res .= ' > Message';
+            }
         }
     }
     return $res.'</div>';
@@ -425,12 +444,16 @@ function displayShortcuts($first = -1)
  *  FORMATTING STUFF : BODY
  */
 
-function autoformat($text)
+function autoformat($text, $part = false)
 {
     global $banana;
     $length = $banana->wrap;
-        
-    $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$length, all=>1 };'";
+    $all = null;
+    if (!$part) {
+        $all = ', all=1';
+    }
+    
+    $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$length$all };'";
     exec($cmd, $result, $ret);
     if ($ret != 0) {
         $result = split("\n", $text);
@@ -458,7 +481,8 @@ function wrap($text, $_prefix="", $_force=false)
     $format = false;
     foreach ($splits as $line) {
         if ($_force || strlen($line) > $max) {
-            if (preg_match("!^(.*)($url)(.*)!i", $line, $matches) && strlen($matches[2]) > $length && strlen($matches) < 900) {
+            if (preg_match("!^(.*)($url)(.*)!i", $line, $matches)
+                    && strlen($matches[2]) > $length && strlen($matches) < 900) {
                 if (strlen($matches[1]) != 0) {
                     array_push($next, rtrim($matches[1]));
                     if (strlen($matches[1]) > $max) {
@@ -482,8 +506,12 @@ function wrap($text, $_prefix="", $_force=false)
                     }
                 }
             } else {
-                $format = true;
-                array_push($next, $line);
+                if (strlen($line) > 2 * $max) {
+                    $next = array_merge($next, autoformat($line, true));
+                } else {
+                    $format = true;
+                    array_push($next, $line);
+                }
             }
         } else {
             array_push($next, $line);
@@ -517,11 +545,11 @@ function cleanurl($url)
 function formatbody($_text, $format='plain', $flowed=false)
 {
     if ($format == 'html') {
-        $res = '<br/>'.html_entity_decode(to_entities(removeEvilTags($_text))).'<br/>';
+        $res = html_entity_decode(to_entities(removeEvilTags($_text)));
     } else if ($format == 'richtext') {
-        $res = '<br/>'.html_entity_decode(to_entities(richtextToHtml($_text))).'<br/>';
+        $res = html_entity_decode(to_entities(richtextToHtml($_text)));
     } else {
-        $res  = "\n\n" . to_entities(wrap($_text, "", $flowed))."\n\n";
+        $res  = to_entities(wrap($_text, "", $flowed));
         $res  = formatPlainText($res);
     }
 
@@ -543,6 +571,7 @@ function formatbody($_text, $format='plain', $flowed=false)
         $res = preg_replace("@<br[^>]*>\n?-- ?\n?(<p[^>]*>)@", "<br/>-- <br/>\\2", $res);
         $res = preg_replace("@(<pre[^>]*>)\n?-- ?\n@", "<br/>-- <br/>\\1", $res);
         $parts = preg_split("@(:?<p[^>]*>\n?-- ?\n?</p>|<br[^>]*>\n?-- ?\n?<br[^>]*>)@", $res);
+        $sign  = '<hr style="width: 100%; margin: 1em 0em; " />';
     } else {
         while (preg_match("@(^|<pre>|\n)&gt;@i", $res)) {
             $res  = preg_replace("@(^|<pre>|\n)((&gt;[^\n]*\n)+)@ie",
@@ -553,21 +582,10 @@ function formatbody($_text, $format='plain', $flowed=false)
         }
         $res = preg_replace("@<pre>-- ?\n@", "<pre>\n-- \n", $res);
         $parts = preg_split("/\n-- ?\n/", $res);
+        $sign  = '</pre><hr style="width: 100%; margin: 1em 0em; " /><pre>';
     }
 
-    if (count($parts) > 1) {
-        $sign  = array_pop($parts);
-        if ($format == 'html') {
-            $res  = join('<br/>-- <br/>', $parts);
-            $sign = '<hr style="width: 100%; margin: 1em 0em; " />'.$sign.'<br/>';
-        } else {
-            $res  = join('\n-- \n', $parts);
-            $sign = '</pre><hr style="width: 100%; margin: 1em 0em; " /><pre>'.$sign;
-        }
-        return $res.$sign;
-    } else {
-        return $res;
-    }
+    return join($sign, $parts);
 }
 
 // vim:set et sw=4 sts=4 ts=4