Catch ** // __ also in subject
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Wed, 12 Jul 2006 16:44:38 +0000 (16:44 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:34:55 +0000 (00:34 +0100)
Allow custom formatting of all headers by applying hook

git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@88 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/banana.inc.php.in
banana/misc.inc.php
banana/post.inc.php
banana/spool.inc.php

index 50eb0a9..a93c11e 100644 (file)
@@ -14,7 +14,7 @@ class Banana
     var $hdecode     = array('from','name','organization','subject');
     var $parse_hdr   = array('content-disposition', 'content-transfer-encoding', 'content-type', 'date', 'followup-to', 'from',
             'message-id', 'newsgroups', 'organization', 'references', 'subject', 'x-face');
-    var $show_hdr    = array('from', 'subject', 'newsgroups', 'followup', 'date', 'organization', 'references', 'x-face');
+    var $show_hdr    = array('from', 'newsgroups', 'followup', 'date', 'organization', 'references', 'x-face');
 
     /** Favorites MIMEtypes to use, by order for reading multipart messages
      */
index 25a9246..8991d58 100644 (file)
@@ -170,6 +170,21 @@ function htmlToPlainText($res)
     return $res;
 }
 
+/** Match **, // and __ to format plain text
+ */
+function formatPlainText($text)
+{
+    $formatting = Array('\*' => 'strong',
+                        '_' => 'u',
+                        '/' => 'em');
+    foreach ($formatting as $limit=>$mark) {
+        $text = preg_replace('@(^|\W)' . $limit . '(\w+)' . $limit . '(\W|$)@'
+                            ,'\1<' . $mark . '>\2</' . $mark . '>\3'
+                            , $text);
+    }
+    return $text;
+} 
+
 /********************************************************************************
  * RICHTEXT STUFF
  */
@@ -252,6 +267,11 @@ function header_translate($hdr) {
 
 function formatDisplayHeader($_header,$_text) {
     global $banana;
+    if (function_exists('hook_formatDisplayHeader')
+            && $res = hook_formatDisplayHeader($_header, $_text)) {
+        return $res;
+    }
+
     switch ($_header) {
         case "date": 
             return formatDate($_text);
@@ -289,13 +309,11 @@ function formatDisplayHeader($_header,$_text) {
 
         case "x-face":
             return '<img src="' . makeLink(Array('xface' => urlencode(base64_encode($_text)))) .'"  alt="x-face" />';
-        
+    
+        case "subject":
+            return formatPlainText($_text);
+
         default:
-            if (function_exists('hook_formatDisplayHeader')
-                    && $res = hook_formatDisplayHeader($_header, $_text))
-            {
-                return $res;
-            }
             return htmlentities($_text);
     }
 }
@@ -496,14 +514,7 @@ function formatbody($_text, $format='plain', $flowed=false)
         $res = '<br/>'.html_entity_decode(to_entities(richtextToHtml($_text))).'<br/>';
     } else {
         $res  = "\n\n" . to_entities(wrap($_text, "", $flowed))."\n\n";
-        $formatting = Array('\*' => 'strong',
-                            '_' => 'u',
-                            '/' => 'em');
-        foreach ($formatting as $limit=>$mark) {
-            $res = preg_replace('@(\W)' . $limit . '(\w+)' . $limit . '(\W)@'
-                                ,'\1<' . $mark . '>\2</' . $mark . '>\3'
-                                , $res);
-        }
+        $res  = formatPlainText($res);
     }
 
     if ($format != 'html') {
index e699e7f..b1aed1c 100644 (file)
@@ -351,7 +351,7 @@ class BananaPost
         }
 
         $res  = '<table class="bicol banana_msg" cellpadding="0" cellspacing="0">';
-        $res .= '<tr><th colspan="2">'._b_('En-tĂȘtes').'</th></tr>';
+        $res .= '<tr><th colspan="2">' . formatdisplayheader('subject', $this->headers['subject']) . '</th></tr>';
         $res .= '<tr><td class="headers"><table cellpadding="0" cellspacing="0">';
 
         foreach ($banana->show_hdr as $hdr) {
index e9e81f8..705f4b0 100644 (file)
@@ -350,7 +350,7 @@ class BananaSpool
             if (function_exists('hook_getSubject')) {
                 $link = hook_getSubject($subject);
             }
-            $subject = htmlentities($subject);
+            $subject = formatPlainText(htmlentities($subject));
             if ($_index == $_ref) {
                 $res .= '<span class="cur">' . $subject . $link . '</span>';
             } else {