| 1 | <?php |
| 2 | /******************************************************************************** |
| 3 | * * banana/message.func.inc.php : function to display messages |
| 4 | * * ------------------------ |
| 5 | * * |
| 6 | * * This file is part of the banana distribution |
| 7 | * * Copyright: See COPYING files that comes with this distribution |
| 8 | * ********************************************************************************/ |
| 9 | |
| 10 | require_once dirname(__FILE__) . '/mimepart.inc.php'; |
| 11 | require_once dirname(__FILE__) . '/banana.inc.php'; |
| 12 | |
| 13 | // {{{ Plain Text Functions |
| 14 | |
| 15 | function banana_isFlowed($line) |
| 16 | { |
| 17 | return ctype_space(substr($line, -1)) && $line != '-- '; |
| 18 | } |
| 19 | |
| 20 | function banana_removeQuotes($line, &$quote_level, $strict = true) |
| 21 | { |
| 22 | $quote_level = 0; |
| 23 | if (empty($line)) { |
| 24 | return ''; |
| 25 | } |
| 26 | while ($line{0} == '>') { |
| 27 | $line = substr($line, 1); |
| 28 | if (!$strict && ctype_space($line{0})) { |
| 29 | $line = substr($line, 1); |
| 30 | } |
| 31 | $quote_level++; |
| 32 | } |
| 33 | if (ctype_space($line{0})) { |
| 34 | $line = substr($line, 1); |
| 35 | } |
| 36 | return $line; |
| 37 | } |
| 38 | |
| 39 | function banana_quote($line, $level, $mark = '>') |
| 40 | { |
| 41 | $lines = explode("\n", $line); |
| 42 | $quote = str_repeat($mark, $level); |
| 43 | foreach ($lines as &$line) { |
| 44 | $line = $quote . $line; |
| 45 | } |
| 46 | return implode("\n", $lines); |
| 47 | } |
| 48 | |
| 49 | function banana_unflowed($text) |
| 50 | { |
| 51 | $lines = explode("\n", $text); |
| 52 | $text = ''; |
| 53 | while (!is_null($line = array_shift($lines))) { |
| 54 | $level = 0; |
| 55 | $line = banana_removeQuotes($line, $level); |
| 56 | while (banana_isFlowed($line)) { |
| 57 | $lvl = 0; |
| 58 | if (empty($lines)) { |
| 59 | break; |
| 60 | } |
| 61 | $nl = $lines[0]; |
| 62 | $nl = banana_removeQuotes($nl, $lvl); |
| 63 | if ($lvl == $level) { |
| 64 | $line .= $nl; |
| 65 | array_shift($lines); |
| 66 | } else { |
| 67 | break; |
| 68 | } |
| 69 | } |
| 70 | $text .= banana_quote($line, $level) . "\n"; |
| 71 | } |
| 72 | return $text; |
| 73 | } |
| 74 | |
| 75 | function banana_wordwrap($text, $quote_level = 0) |
| 76 | { |
| 77 | if ($quote_level > 0) { |
| 78 | $length = Banana::$msgshow_wrap - $quote_level - 1; |
| 79 | return banana_quote(wordwrap($text, $length), $quote_level); |
| 80 | } |
| 81 | return wordwrap($text, Banana::$msgshow_wrap); |
| 82 | } |
| 83 | |
| 84 | function banana_catchFormats($text) |
| 85 | { |
| 86 | $formatting = Array('em' => array('\B\/\b', '\b\/\B'), |
| 87 | 'u' => array('\b_', '_\b'), |
| 88 | 'strong' => array('\B\*\b', '\b\*\B')); |
| 89 | $url = Banana::$msgshow_url; |
| 90 | preg_match_all("/$url/ui", $text, $urls); |
| 91 | $text = str_replace($urls[0], "&&&urls&&&", $text); |
| 92 | foreach ($formatting as $mark=>$limit) { |
| 93 | list($ll, $lr) = $limit; |
| 94 | $text = preg_replace('/' . $ll . '(\w+?)' . $lr . '/us', |
| 95 | "<$mark>\\1</$mark>", $text); |
| 96 | } |
| 97 | return preg_replace('/&&&urls&&&/e', 'array_shift($urls[0])', $text); |
| 98 | } |
| 99 | |
| 100 | /** Build a flowed text from plain text |
| 101 | */ |
| 102 | function banana_flow($text) |
| 103 | { |
| 104 | $lines = explode("\n", $text); |
| 105 | $text = ''; |
| 106 | while (!is_null($line = array_shift($lines))) { |
| 107 | if ($line != '-- ') { |
| 108 | $level = 0; |
| 109 | $line = banana_removeQuotes($line, $level); |
| 110 | $text .= rtrim(str_replace("\n", " \n", banana_wordwrap($line, $level))) . "\n"; |
| 111 | } else { |
| 112 | $text .= $line . "\n"; |
| 113 | } |
| 114 | } |
| 115 | return $text; |
| 116 | } |
| 117 | |
| 118 | // {{{ URL Catcher tools |
| 119 | |
| 120 | function banana__cutlink($link) |
| 121 | { |
| 122 | $link = banana_html_entity_decode($link, ENT_QUOTES); |
| 123 | if (strlen($link) > Banana::$msgshow_wrap) { |
| 124 | $link = substr($link, 0, Banana::$msgshow_wrap - 3) . "..."; |
| 125 | } |
| 126 | return banana_htmlentities($link, ENT_QUOTES); |
| 127 | } |
| 128 | |
| 129 | function banana__cleanURL($url) |
| 130 | { |
| 131 | $url = str_replace('@', '%40', $url); |
| 132 | if (strpos($url, '://') === false) { |
| 133 | $url = 'http://' . $url; |
| 134 | } |
| 135 | return '<a href="'.$url.'" title="'.$url.'">' . banana__cutlink($url) . '</a>'; |
| 136 | } |
| 137 | |
| 138 | function banana__catchMailLink($email) |
| 139 | { |
| 140 | $mid = '<' . $email . '>'; |
| 141 | if (isset(Banana::$spool->ids[$mid])) { |
| 142 | return Banana::$page->makeLink(Array('group' => Banana::$group, |
| 143 | 'artid' => Banana::$spool->ids[$mid]->id, |
| 144 | 'text' => $email)); |
| 145 | } elseif (strpos($email, '$') !== false) { |
| 146 | return $email; |
| 147 | } |
| 148 | return '<a href="mailto:' . $email . '">' . $email . '</a>'; |
| 149 | } |
| 150 | |
| 151 | // }}} |
| 152 | |
| 153 | function banana_catchURLs($text) |
| 154 | { |
| 155 | $url = Banana::$msgshow_url; |
| 156 | |
| 157 | $res = preg_replace("/&(lt|gt|quot);/", " &\\1; ", $text); |
| 158 | $res = preg_replace("/$url/uie", "'\\1'.banana__cleanurl('\\2').'\\3'", $res); |
| 159 | $res = preg_replace('/(["\[])?(?:mailto:|news:)?([a-z0-9.\-+_\$]+@([\-.+_]?[a-z0-9])+)(["\]])?/ie', |
| 160 | "'\\1' . banana__catchMailLink('\\2') . '\\4'", |
| 161 | $res); |
| 162 | $res = preg_replace("/ &(lt|gt|quot); /", "&\\1;", $res); |
| 163 | return $res; |
| 164 | } |
| 165 | |
| 166 | // {{{ Quotes catcher functions |
| 167 | |
| 168 | function banana__replaceQuotes($text, $regexp) |
| 169 | { |
| 170 | return stripslashes(preg_replace("@(^|<pre>|\n)$regexp@i", '\1', $text)); |
| 171 | } |
| 172 | |
| 173 | // }}} |
| 174 | |
| 175 | function banana_catchQuotes($res, $strict = true) |
| 176 | { |
| 177 | if ($strict) { |
| 178 | $regexp = ">"; |
| 179 | } else { |
| 180 | $regexp = "> *"; |
| 181 | } |
| 182 | while (preg_match("/(^|<pre>|\n)$regexp/i", $res)) { |
| 183 | $res = preg_replace("/(^|<pre>|\n)(($regexp.*(?:\n|$))+)/ie", |
| 184 | "'\\1</pre><blockquote><pre>'" |
| 185 | ." . banana__replaceQuotes('\\2', '$regexp')" |
| 186 | ." . '</pre></blockquote><pre>'", |
| 187 | $res); |
| 188 | } |
| 189 | return $res; |
| 190 | } |
| 191 | |
| 192 | function banana_catchSignature($res) |
| 193 | { |
| 194 | $res = preg_replace("@<pre>-- ?\n@", "<pre>\n-- \n", $res); |
| 195 | $parts = preg_split("/\n-- ?\n/", $res); |
| 196 | $sign = '</pre><hr style="width: 100%; margin: 1em 0em; " /><pre>'; |
| 197 | return join($sign, $parts); |
| 198 | } |
| 199 | |
| 200 | function banana_plainTextToHtml($text, $strict = true) |
| 201 | { |
| 202 | $text = banana_htmlentities($text); |
| 203 | $text = banana_catchFormats($text); |
| 204 | $text = banana_catchURLs($text); |
| 205 | $text = banana_catchQuotes($text, $strict); |
| 206 | $text = banana_catchSignature($text); |
| 207 | return '<pre>' . $text . '</pre>'; |
| 208 | } |
| 209 | |
| 210 | function banana_wrap($text, $base_level = 0, $strict = true) |
| 211 | { |
| 212 | $lines = explode("\n", $text); |
| 213 | $text = ''; |
| 214 | $buffer = array(); |
| 215 | $level = 0; |
| 216 | while (!is_null($line = array_shift($lines))) { |
| 217 | $lvl = 0; |
| 218 | $line = banana_removeQuotes($line, $lvl, $strict); |
| 219 | if($lvl != $level) { |
| 220 | if (!empty($buffer)) { |
| 221 | $text .= banana_wordwrap(implode("\n", $buffer), $level + $base_level) . "\n"; |
| 222 | $buffer = array(); |
| 223 | } |
| 224 | $level = $lvl; |
| 225 | } |
| 226 | $buffer[] = $line; |
| 227 | } |
| 228 | if (!empty($buffer)) { |
| 229 | $text .= banana_wordwrap(implode("\n", $buffer), $level + $base_level); |
| 230 | } |
| 231 | return $text; |
| 232 | } |
| 233 | |
| 234 | function banana_formatPlainText(BananaMimePart &$part, $base_level = 0) |
| 235 | { |
| 236 | $text = $part->getText(); |
| 237 | if ($part->isFlowed()) { |
| 238 | $text = banana_unflowed($text); |
| 239 | } |
| 240 | $text = banana_wrap($text, $base_level, $part->isFlowed()); |
| 241 | return banana_plainTextToHtml($text, $part->isFlowed()); |
| 242 | } |
| 243 | |
| 244 | function banana_quotePlainText(BananaMimePart &$part) |
| 245 | { |
| 246 | $text = $part->getText(); |
| 247 | if ($part->isFlowed()) { |
| 248 | $text = banana_unflowed($text); |
| 249 | } |
| 250 | return banana_quote($text, 1); |
| 251 | } |
| 252 | |
| 253 | // }}} |
| 254 | // {{{ HTML Functions |
| 255 | |
| 256 | function banana_htmlentities($text, $quote = ENT_COMPAT) |
| 257 | { |
| 258 | return htmlentities($text, $quote, 'UTF-8'); |
| 259 | } |
| 260 | |
| 261 | function banana_html_entity_decode($text, $quote = ENT_COMPAT) |
| 262 | { |
| 263 | return html_entity_decode($text, $quote, 'UTF-8'); |
| 264 | } |
| 265 | |
| 266 | function banana_removeEvilAttributes($tagSource) |
| 267 | { |
| 268 | $stripAttrib = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|'. |
| 269 | 'onmousemove|onmouseout|onkeypress|onkeydown|onkeyup'; |
| 270 | return stripslashes(preg_replace("/$stripAttrib/i", '', $tagSource)); |
| 271 | } |
| 272 | |
| 273 | function banana_cleanStyles($tag, $attributes) |
| 274 | { |
| 275 | static $td_style, $conv, $size_conv; |
| 276 | if (!isset($td_style)) { |
| 277 | $conv = array('style' => 'style', 'width' => 'width', 'height' => 'height', 'border' => 'border-size', |
| 278 | 'size' => 'font-size', 'align' => 'text-align', 'valign' => 'vertical-align', 'face' => 'font', |
| 279 | 'bgcolor' => 'background-color', 'color' => 'color', 'style' => 'style', |
| 280 | 'cellpadding' => 'padding', 'cellspacing' => 'border-spacing'); |
| 281 | $size_conv = array(1 => 'xx-small', 2 => 'x-small', 3 => 'small', 4 => 'medium', 5 => 'large', |
| 282 | 6 => 'x-large', 7 => 'xx-large', |
| 283 | '-2' => 'xx-small', '-1' => 'x-small', '+1' => 'medium', '+2' => 'large', |
| 284 | '+3' => 'x-large', '+4' => 'xx-large'); |
| 285 | $td_style = array(); |
| 286 | } |
| 287 | if ($tag == 'table') { |
| 288 | array_unshift($td_style, ''); |
| 289 | } |
| 290 | if ($tag == '/table') { |
| 291 | array_shift($td_style); |
| 292 | } |
| 293 | if ($tag{0} == '/') { |
| 294 | return ''; |
| 295 | } |
| 296 | if ($tag == 'td') { |
| 297 | $style = $td_style[0]; |
| 298 | } else { |
| 299 | $style = ''; |
| 300 | } |
| 301 | $attributes = str_replace(array("\n", "\r"), ' ', stripslashes($attributes)); |
| 302 | $attributes = str_replace(array('= "', '= \''), array('="', '=\''), $attributes); |
| 303 | foreach ($conv as $att=>$stl) { |
| 304 | $pattern = '/\b' . preg_quote($att, '/') . '=([\'"])?(.+?)(?(1)\1|(?:$| ))/i'; |
| 305 | if (preg_match($pattern, $attributes, $matches)) { |
| 306 | $attributes = preg_replace($pattern, '', $attributes); |
| 307 | $val = $matches[2]; |
| 308 | if ($att == 'cellspacing' && strpos($style, 'border-collapse') === false) { |
| 309 | $style = "border-collapse: separate; border-spacing: $val $val; " . $style; |
| 310 | } elseif ($att == 'cellpadding' && $tag == 'table') { |
| 311 | $td_style[0] = "$stl: {$val}px; "; |
| 312 | } elseif ($att == 'style') { |
| 313 | $val = rtrim($val, ' ;'); |
| 314 | $style .= "$val; "; |
| 315 | } elseif ($att == 'size') { |
| 316 | $val = $size_conv[$val]; |
| 317 | $style = "$stl: $val; " . $style; |
| 318 | } elseif (is_numeric($val)) { |
| 319 | $style = "$stl: {$val}px; " . $style; |
| 320 | } else { |
| 321 | $style = "$stl: $val; " . $style; |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | if (!empty($style)) { |
| 326 | $style = 'style="' . $style . '" '; |
| 327 | } |
| 328 | return ' ' . $style . trim($attributes); |
| 329 | } |
| 330 | |
| 331 | function banana__filterCss($text) |
| 332 | { |
| 333 | $text = preg_replace("/(,[\s\n\r]*)/s", '\1 .banana .message .body .html ', $text); |
| 334 | return '.banana .message .body .html ' . $text; |
| 335 | } |
| 336 | |
| 337 | function banana_filterCss($css) |
| 338 | { |
| 339 | preg_match_all("/(^|\n|,\s*)\s*([\#\.@\w][^;\{\}\<]*?[\{])/s", $css, $matches); |
| 340 | $css = preg_replace("/(^|\n)\s*([\#\.@\w][^;\{\}\<]*?)([\{])/se", '"\1" . banana__filterCss("\2") . "\3"', $css); |
| 341 | $css = preg_replace('/ body\b/i', '', $css); |
| 342 | if (!Banana::$msgshow_externalimages) { |
| 343 | if (preg_match('!url\([^:\)]+:(//|\\\).*?\)!i', $css)) { |
| 344 | $css = preg_replace('!url\([^:\)]+:(//|\\\).*?\)!i', 'url(invalid-image.png)', $css); |
| 345 | Banana::$msgshow_hasextimages = true; |
| 346 | } |
| 347 | } |
| 348 | return $css; |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * @return string |
| 353 | * @param string |
| 354 | * @desc Strip forbidden tags and delegate tag-source check to removeEvilAttributes() |
| 355 | */ |
| 356 | function banana_cleanHtml($source, $to_xhtml = false) |
| 357 | { |
| 358 | if (function_exists('tidy_repair_string')) { |
| 359 | $tidy_config = array('drop-empty-paras' => true, |
| 360 | 'drop-proprietary-attributes' => true, |
| 361 | 'hide-comments' => true, |
| 362 | 'logical-emphasis' => true, |
| 363 | 'output-xhtml' => true, |
| 364 | 'replace-color' => true, |
| 365 | 'join-classes' => false, |
| 366 | 'clean' => false, |
| 367 | 'show-body-only' => false, |
| 368 | 'alt-text' => '[ inserted by TIDY ]', |
| 369 | 'wrap' => 120); |
| 370 | if (function_exists('tidy_setopt')) { // Tidy 1.0 |
| 371 | foreach ($tidy_config as $field=>$value) { |
| 372 | tidy_setopt($field, $value); |
| 373 | } |
| 374 | tidy_set_encoding('utf8'); |
| 375 | $source = tidy_repair_string($source); |
| 376 | |
| 377 | } else { // Tidy 2.0 |
| 378 | $source = tidy_repair_string($source, $tidy_config, 'utf8'); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | // To XHTML |
| 383 | if ($to_xhtml) { |
| 384 | // catch inline CSS |
| 385 | $css = null; |
| 386 | if (preg_match('/<head.*?>(.*?)<\/head>/is', $source, $matches)) { |
| 387 | $source = preg_replace('/<head.*?>.*?<\/head>/is', '', $source); |
| 388 | preg_match_all('/<style(?:.*?type="text\/css".*?)?>(.*?)<\/style>/is', $matches[1], $matches); |
| 389 | foreach ($matches[1] as &$match) { |
| 390 | $css .= $match; |
| 391 | } |
| 392 | $css = banana_filterCss($css); |
| 393 | Banana::$page->addCssInline($css); |
| 394 | } |
| 395 | |
| 396 | // clean DTD |
| 397 | $source = str_replace('<font', '<span', $source); |
| 398 | $source = preg_replace('/<u\b/', '<span style="text-decoration: underline"', $source); |
| 399 | $source = preg_replace('/<\/(font|u)>/', '</span>', $source); |
| 400 | $source = str_replace('<body', $css ? '<div class="html"' : '<div class="html default"', $source); |
| 401 | $source = str_replace('</body>', '</div>', $source); |
| 402 | } |
| 403 | $allowedTags = '<h1><h2><h3><b><i><a><ul><li><pre><hr><blockquote><img><br><div><span>' |
| 404 | . '<p><small><big><sup><sub><code><em><strong><table><tr><td><th>'; |
| 405 | $source = strip_tags($source, $allowedTags); |
| 406 | |
| 407 | // Use inlined style instead of old html attributes |
| 408 | if ($to_xhtml) { |
| 409 | $source = preg_replace('/<(\/?\w+)(.*?)(\/?>)/muise', "'<\\1' . banana_cleanStyles('\\1', '\\2') . '\\3'", $source); |
| 410 | } |
| 411 | return preg_replace('/<(.*?)>/ie', "'<'.banana_removeEvilAttributes('\\1').'>'", $source); |
| 412 | } |
| 413 | |
| 414 | function banana_catchHtmlSignature($res) |
| 415 | { |
| 416 | $res = preg_replace("@(</p>)\n?-- ?\n?(<p[^>]*>|<br[^>]*>)@", "\\1<br/>-- \\2", $res); |
| 417 | $res = preg_replace("@<br[^>]*>\n?-- ?\n?(<p[^>]*>)@", "<br/>-- <br/>\\2", $res); |
| 418 | $res = preg_replace("@(<pre[^>]*>)\n?-- ?\n@", "<br/>-- <br/>\\1", $res); |
| 419 | $parts = preg_split("@(:?<p[^>]*>\n?-- ?\n?</p>|<br[^>]*>\n?-- ?\n?<br[^>]*>)@", $res); |
| 420 | $sign = '<hr style="width: 100%; margin: 1em 0em; " />'; |
| 421 | return join($sign, $parts); |
| 422 | } |
| 423 | |
| 424 | // {{{ Link to part catcher tools |
| 425 | |
| 426 | function banana__linkAttachment($cid) |
| 427 | { |
| 428 | return banana_htmlentities( |
| 429 | Banana::$page->makeUrl(Array('group' => Banana::$group, |
| 430 | 'artid' => Banana::$artid, |
| 431 | 'part' => $cid))); |
| 432 | } |
| 433 | |
| 434 | // }}} |
| 435 | |
| 436 | function banana_hideExternalImages($text) |
| 437 | { |
| 438 | if (preg_match("/<img([^>]*?)src=['\"](?!cid).*?['\"](.*?)>/i", $text)) { |
| 439 | Banana::$msgshow_hasextimages = true; |
| 440 | return preg_replace("/<img([^>]*?)src=['\"](?!cid).*?['\"](.*?)>/i", |
| 441 | '<img\1src="invalid"\2>', |
| 442 | $text); |
| 443 | } |
| 444 | return $text; |
| 445 | } |
| 446 | |
| 447 | function banana_catchPartLinks($text) |
| 448 | { |
| 449 | $article = Banana::$page->makeURL(array('group' => Banana::$group, 'artid' => Banana::$artid, 'part' => Banana::$part)); |
| 450 | $article = banana_htmlentities($article); |
| 451 | $text = preg_replace('/cid:([^\'" ]+)/e', "banana__linkAttachment('\\1')", $text); |
| 452 | $text = preg_replace('/href="(#.*?)"/i', 'href="' . $article . '\1"', $text); |
| 453 | return $text; |
| 454 | } |
| 455 | |
| 456 | // {{{ HTML to Plain Text tools |
| 457 | |
| 458 | function banana__convertFormats($res) |
| 459 | { |
| 460 | $table = array('em|i' => '/', |
| 461 | 'strong|b' => '*', |
| 462 | 'u' => '_'); |
| 463 | foreach ($table as $tags=>$format) { |
| 464 | $res = preg_replace("!</?($tags)( .*?)?>!is", $format, $res); |
| 465 | } |
| 466 | return $res; |
| 467 | } |
| 468 | |
| 469 | function banana__convertQuotes($res) |
| 470 | { |
| 471 | return preg_replace('!<blockquote.*?>([^<]*)</blockquote>!ies', |
| 472 | "\"\n\" . banana_quote(banana__convertQuotes('\\1' . \"\n\"), 1, '>')", |
| 473 | $res); |
| 474 | } |
| 475 | |
| 476 | // }}} |
| 477 | |
| 478 | function banana_htmlToPlainText($res) |
| 479 | { |
| 480 | $res = str_replace("\n", '', $res); |
| 481 | $res = banana__convertFormats($res); |
| 482 | $res = trim(strip_tags($res, '<div><br><p><blockquote>')); |
| 483 | $res = preg_replace("@</?(br|p|div).*?>@si", "\n", $res); |
| 484 | $res = banana__convertQuotes($res); |
| 485 | return banana_html_entity_decode($res); |
| 486 | } |
| 487 | |
| 488 | function banana_formatHtml(BananaMimePart &$part) |
| 489 | { |
| 490 | $text = $part->getText(); |
| 491 | $text = banana_catchHtmlSignature($text); |
| 492 | if (!Banana::$msgshow_externalimages) { |
| 493 | $text = banana_hideExternalImages($text); |
| 494 | } |
| 495 | $text = banana_catchPartLinks($text); |
| 496 | return banana_cleanHtml($text, true); |
| 497 | } |
| 498 | |
| 499 | function banana_quoteHtml(BananaMimePart &$part) |
| 500 | { |
| 501 | $text = $part->getText(); |
| 502 | $text = banana_htmlToPlainText($text); |
| 503 | return banana_quote($text, 1); |
| 504 | } |
| 505 | |
| 506 | // }}} |
| 507 | // {{{ Richtext Functions |
| 508 | |
| 509 | /** Convert richtext to html |
| 510 | */ |
| 511 | function banana_richtextToHtml($source) |
| 512 | { |
| 513 | $tags = Array('bold' => 'b', |
| 514 | 'italic' => 'i', |
| 515 | 'smaller' => 'small', |
| 516 | 'bigger' => 'big', |
| 517 | 'underline' => 'u', |
| 518 | 'subscript' => 'sub', |
| 519 | 'superscript' => 'sup', |
| 520 | 'excerpt' => 'blockquote', |
| 521 | 'paragraph' => 'p', |
| 522 | 'nl' => 'br' |
| 523 | ); |
| 524 | |
| 525 | // clean unsupported tags |
| 526 | $protectedTags = '<signature><lt><comment><'.join('><', array_keys($tags)).'>'; |
| 527 | $source = strip_tags($source, $protectedTags); |
| 528 | |
| 529 | // convert richtext tags to html |
| 530 | foreach (array_keys($tags) as $tag) { |
| 531 | $source = preg_replace('@(</?)'.$tag.'([^>]*>)@i', '\1'.$tags[$tag].'\2', $source); |
| 532 | } |
| 533 | |
| 534 | // some special cases |
| 535 | $source = preg_replace('@<signature>@i', '<br>-- <br>', $source); |
| 536 | $source = preg_replace('@</signature>@i', '', $source); |
| 537 | $source = preg_replace('@<lt>@i', '<', $source); |
| 538 | $source = preg_replace('@<comment[^>]*>((?:[^<]|<(?!/comment>))*)</comment>@i', '<!-- \1 -->', $source); |
| 539 | return banana_cleanHtml($source); |
| 540 | } |
| 541 | |
| 542 | function banana_formatRichText(BananaMimePart &$part) |
| 543 | { |
| 544 | $text = $part->getText(); |
| 545 | $text = banana_richtextToHtml($text); |
| 546 | $text = banana_catchHtmlSignature($text); |
| 547 | return banana_cleanHtml($text); |
| 548 | } |
| 549 | |
| 550 | function banana_quoteRichtText(BananaMimePart &$part) |
| 551 | { |
| 552 | $text = $part->getText(); |
| 553 | $text = banana_richtextToHtml($text); |
| 554 | $text = banana_htmlToPlainText($text); |
| 555 | return banana_quote($text, 1); |
| 556 | } |
| 557 | |
| 558 | // }}} |
| 559 | |
| 560 | // vim:set et sw=4 sts=4 ts=4 enc=utf-8: |
| 561 | ?> |