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