From 1fb1100011a3c3600fb9195eb526475ccf94e4cc Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Wed, 12 Jul 2006 16:44:38 +0000 Subject: [PATCH] Catch ** // __ also in subject 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 | 2 +- banana/misc.inc.php | 39 +++++++++++++++++++++++++-------------- banana/post.inc.php | 2 +- banana/spool.inc.php | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in index 50eb0a9..a93c11e 100644 --- a/banana/banana.inc.php.in +++ b/banana/banana.inc.php.in @@ -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 */ diff --git a/banana/misc.inc.php b/banana/misc.inc.php index 25a9246..8991d58 100644 --- a/banana/misc.inc.php +++ b/banana/misc.inc.php @@ -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\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 '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 = '
'.html_entity_decode(to_entities(richtextToHtml($_text))).'
'; } 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\3' - , $res); - } + $res = formatPlainText($res); } if ($format != 'html') { diff --git a/banana/post.inc.php b/banana/post.inc.php index e699e7f..b1aed1c 100644 --- a/banana/post.inc.php +++ b/banana/post.inc.php @@ -351,7 +351,7 @@ class BananaPost } $res = ''; - $res .= ''; + $res .= ''; $res .= '
'._b_('En-tĂȘtes').'
' . formatdisplayheader('subject', $this->headers['subject']) . '
'; foreach ($banana->show_hdr as $hdr) { diff --git a/banana/spool.inc.php b/banana/spool.inc.php index e9e81f8..705f4b0 100644 --- a/banana/spool.inc.php +++ b/banana/spool.inc.php @@ -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 .= '' . $subject . $link . ''; } else { -- 2.1.4