Somes improvements in the html style parser
[banana.git] / banana / message.func.inc.php
index 70b45f9..3b00c9c 100644 (file)
@@ -105,7 +105,9 @@ function banana_flow($text)
     $text  = '';
     while (!is_null($line = array_shift($lines))) {
         if ($line != '-- ') {
-            $text .= rtrim(str_replace("\n", " \n", banana_wordwrap($line))) . "\n";
+            $level = 0;
+            $line  = banana_removeQuotes($line, $level);
+            $text .= rtrim(str_replace("\n", " \n", banana_wordwrap($line, $level))) . "\n";
         } else {
             $text .= $line . "\n";
         }
@@ -202,7 +204,7 @@ function banana_plainTextToHtml($text, $strict = true)
     $text = banana_catchURLs($text);
     $text = banana_catchQuotes($text, $strict);
     $text = banana_catchSignature($text);
-    return banana_cleanHtml('<pre>' . $text . '</pre>');
+    return '<pre>' . $text . '</pre>';
 }
 
 function banana_wrap($text, $base_level = 0, $strict = true)
@@ -245,7 +247,7 @@ function banana_quotePlainText(BananaMimePart &$part)
     if ($part->isFlowed()) {
         $text = banana_unflowed($text);
     }
-    return banana_wrap($text, 1);
+    return banana_quote($text, 1);
 }
 
 // }}}
@@ -296,15 +298,15 @@ function banana_cleanStyles($tag, $attributes)
     } else {
         $style = '';
     }
-    $attributes = str_replace("\n", ' ', stripslashes($attributes));
-    $attributes = str_replace('= "', '="', $attributes);
+    $attributes = str_replace(array("\n", "\r"), ' ', stripslashes($attributes));
+    $attributes = str_replace(array('= "', '= \''), array('="', '=\''), $attributes);
     foreach ($conv as $att=>$stl) {
         $pattern = '/\b' . preg_quote($att, '/') . '=([\'"])?(.+?)(?(1)\1|(?:$| ))/i';
         if (preg_match($pattern, $attributes, $matches)) {
             $attributes = preg_replace($pattern, '', $attributes);
             $val = $matches[2];
             if ($att == 'cellspacing' && strpos($style, 'border-collapse') === false) {
-                $style .= "border-collapse: separate; border-spacing: $val $val; ";
+                $style = "border-collapse: separate; border-spacing: $val $val; " . $style;
             } elseif ($att == 'cellpadding' && $tag == 'table') {
                 $td_style[0] = "$stl: {$val}px; ";
             } elseif ($att == 'style') {
@@ -312,11 +314,11 @@ function banana_cleanStyles($tag, $attributes)
                 $style .= "$val; ";
             } elseif ($att == 'size') {
                 $val = $size_conv[$val];
-                $style .= "$stl: $val; ";
+                $style = "$stl: $val; " . $style;
             } elseif (is_numeric($val)) {
-                $style .= "$stl: {$val}px; ";
+                $style = "$stl: {$val}px; " . $style;
             } else {
-                $style .= "$stl: $val; ";
+                $style = "$stl: $val; " . $style;
             }
         }
     }
@@ -371,6 +373,7 @@ function banana_cleanHtml($source, $to_xhtml = false)
             }
             tidy_set_encoding('utf8');
             $source = tidy_repair_string($source);
+
         } else { // Tidy 2.0
             $source = tidy_repair_string($source, $tidy_config, 'utf8');
         }
@@ -403,7 +406,7 @@ function banana_cleanHtml($source, $to_xhtml = false)
 
     // Use inlined style instead of old html attributes
     if ($to_xhtml) {
-        $source = preg_replace('/<(\/?\w+)(.*?)(\/?>)/uise', "'<\\1' . banana_cleanStyles('\\1', '\\2') . '\\3'", $source);
+        $source = preg_replace('/<(\/?\w+)(.*?)(\/?>)/muise', "'<\\1' . banana_cleanStyles('\\1', '\\2') . '\\3'", $source);
     }    
     return preg_replace('/<(.*?)>/ie', "'<'.banana_removeEvilAttributes('\\1').'>'", $source);
 }
@@ -497,7 +500,7 @@ function banana_quoteHtml(BananaMimePart &$part)
 {
     $text = $part->getText();
     $text = banana_htmlToPlainText($text);
-    return banana_wrap($text, 1);
+    return banana_quote($text, 1);
 }
 
 // }}}
@@ -549,7 +552,7 @@ function banana_quoteRichtText(BananaMimePart &$part)
     $text = $part->getText();
     $text = banana_richtextToHtml($text);
     $text = banana_htmlToPlainText($text);
-    return banana_wrap($text, 1);
+    return banana_quote($text, 1);
 }
 
 // }}}