From: x2003bruneau Date: Tue, 16 Jan 2007 21:47:20 +0000 (+0000) Subject: Oops, do not break plain text rendering X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;ds=inline;h=7caf3c1489ed09a402f34e275e4858e2c9dfd2f4;p=banana.git Oops, do not break plain text rendering git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@176 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- diff --git a/banana/message.func.inc.php b/banana/message.func.inc.php index 7dfb6a4..f86e731 100644 --- a/banana/message.func.inc.php +++ b/banana/message.func.inc.php @@ -316,7 +316,7 @@ function banana_cleanStyles($tag, $attributes) * @param string * @desc Strip forbidden tags and delegate tag-source check to removeEvilAttributes() */ -function banana_cleanHtml($source) +function banana_cleanHtml($source, $to_xhtml = false) { if (function_exists('tidy_repair_string')) { $tidy_on = Array( @@ -339,32 +339,35 @@ function banana_cleanHtml($source) } // To XHTML - // catch inline CSS - $css = null; - if (preg_match('/(.*?)<\/head>/is', $source, $matches)) { - $source = preg_replace('/.*?<\/head>/is', '', $source); - preg_match_all('/(.*?)<\/style>/is', $matches[1], $matches); - foreach ($matches[1] as &$match) { - $css .= $match; + if ($to_xhtml) { + // catch inline CSS + $css = null; + if (preg_match('/(.*?)<\/head>/is', $source, $matches)) { + $source = preg_replace('/.*?<\/head>/is', '', $source); + preg_match_all('/(.*?)<\/style>/is', $matches[1], $matches); + foreach ($matches[1] as &$match) { + $css .= $match; + } + $css = preg_replace("/(^|\n|,)\s*(\w+[^\{\}\<]+\{)/s", '\1.banana .message .body .html \2', $css); + $css = preg_replace('/ body\b/i', '', $css); + Banana::$page->addCssInline($css); } - $css = preg_replace("/(^|\n|,)\s*(\w+[^\{\}\<]+\{)/s", '\1.banana .message .body .html \2', $css); - $css = preg_replace('/ body\b/i', '', $css); - Banana::$page->addCssInline($css); - } - - // clean DTD - $source = str_replace('/', '', $source); - $source = str_replace('', '', $source); + // clean DTD + $source = str_replace('/', '', $source); + $source = str_replace('', '', $source); + } $allowedTags = '



  • ' . '

    '; $source = strip_tags($source, $allowedTags); // Use inlined style instead of old html attributes - $source = preg_replace('/<(\/?\w+)(.*?)(\/?>)/ise', "'<\\1' . banana_cleanStyles('\\1', '\\2') . '\\3'", $source); + if ($to_xhtml) { + $source = preg_replace('/<(\/?\w+)(.*?)(\/?>)/ise', "'<\\1' . banana_cleanStyles('\\1', '\\2') . '\\3'", $source); + } return preg_replace('/<(.*?)>/ie', "'<'.banana_removeEvilAttributes('\\1').'>'", $source); } @@ -446,7 +449,7 @@ function banana_formatHtml(BananaMimePart &$part) $text = banana_hideExternalImages($text); } $text = banana_catchPartLinks($text); - return banana_cleanHtml($text); + return banana_cleanHtml($text, true); } function banana_quoteHtml(BananaMimePart &$part)