return $text;
}
-function banana_wordwrap($text, $quote_level)
+function banana_wordwrap($text, $quote_level = 0)
{
if ($quote_level > 0) {
$length = Banana::$msgshow_wrap - $quote_level - 1;
return banana_quote(wordwrap($text, $length), $quote_level);
-
}
return wordwrap($text, Banana::$msgshow_wrap);
}
function banana_catchFormats($text)
{
- $formatting = Array('/' => 'em', // match / first in order not to match closing markups </...> <> </>
- '_' => 'u',
- '*' => 'strong');
+ $formatting = Array('em' => array('\B\/\b', '\b\/\B'),
+ 'u' => array('\b_', '_\b'),
+ 'strong' => array('\B\*\b', '\b\*\B'));
$url = Banana::$msgshow_url;
preg_match_all("/$url/ui", $text, $urls);
- $text = str_replace($urls[0], "&&&urls&&&", $text);
- foreach ($formatting as $limit=>$mark) {
- $limit = preg_quote($limit, '/');
- $text = preg_replace('/' . $limit . '(\S+?)' . $limit . '/us',
+ $urls = $urls[0];
+ $replace = $urls;
+ rsort($replace);
+ $text = str_replace($replace, "&&&urls&&&", $text);
+ foreach ($formatting as $mark=>$limit) {
+ list($ll, $lr) = $limit;
+ $text = preg_replace('/' . $ll . '(\w+?)' . $lr . '/us',
"<$mark>\\1</$mark>", $text);
}
- return preg_replace('/&&&urls&&&/e', 'array_shift($urls[0])', $text);
+ return preg_replace('/&&&urls&&&/e', 'array_shift($urls)', $text);
+}
+
+/** Build a flowed text from plain text
+ */
+function banana_flow($text)
+{
+ $lines = explode("\n", $text);
+ $text = '';
+ while (!is_null($line = array_shift($lines))) {
+ if ($line != '-- ') {
+ $level = 0;
+ $line = banana_removeQuotes($line, $level);
+ $text .= rtrim(str_replace("\n", " \n", banana_wordwrap($line, $level))) . "\n";
+ } else {
+ $text .= $line . "\n";
+ }
+ }
+ return $text;
}
// {{{ URL Catcher tools
$mid = '<' . $email . '>';
if (isset(Banana::$spool->ids[$mid])) {
return Banana::$page->makeLink(Array('group' => Banana::$group,
- 'artid' => Banana::$spool->ids[$mid],
+ 'artid' => Banana::$spool->ids[$mid]->id,
'text' => $email));
} elseif (strpos($email, '$') !== false) {
return $email;
$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)
if ($part->isFlowed()) {
$text = banana_unflowed($text);
}
- return banana_wrap($text, 1);
+ return banana_quote($text, 1);
}
// }}}
} 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') {
$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;
}
}
}
return ' ' . $style . trim($attributes);
}
+function banana__filterCss($text)
+{
+ $text = preg_replace("/(,[\s\n\r]*)/s", '\1 .banana .message .body .html ', $text);
+ return '.banana .message .body .html ' . $text;
+}
+
function banana_filterCss($css)
{
- $css = preg_replace("/(^|\n|,)\s*(\w+[^\{\}\<]+\{)/s", '\1.banana .message .body .html \2', $css);
+ preg_match_all("/(^|\n|,\s*)\s*([\#\.@\w][^;\{\}\<]*?[\{])/s", $css, $matches);
+ $css = preg_replace("/(^|\n)\s*([\#\.@\w][^;\{\}\<]*?)([\{])/se", '"\1" . banana__filterCss("\2") . "\3"', $css);
$css = preg_replace('/ body\b/i', '', $css);
if (!Banana::$msgshow_externalimages) {
- if (preg_match("/url\(((ht|f)tps?:.*?)\)/i", $css)) {
- $css = preg_replace("/url\(((ht|f)tps?:.*?)\)/i", 'url(invalid-image.png)', $css);
+ if (preg_match('!url\([^:\)]+:(//|\\\).*?\)!i', $css)) {
+ $css = preg_replace('!url\([^:\)]+:(//|\\\).*?\)!i', 'url(invalid-image.png)', $css);
Banana::$msgshow_hasextimages = true;
}
}
*/
function banana_cleanHtml($source, $to_xhtml = false)
{
- if (!function_exists('tidy_repair_string')) {
+ if (function_exists('tidy_repair_string')) {
$tidy_config = array('drop-empty-paras' => true,
'drop-proprietary-attributes' => true,
'hide-comments' => true,
}
tidy_set_encoding('utf8');
$source = tidy_repair_string($source);
+
} else { // Tidy 2.0
$source = tidy_repair_string($source, $tidy_config, 'utf8');
}
$css = null;
if (preg_match('/<head.*?>(.*?)<\/head>/is', $source, $matches)) {
$source = preg_replace('/<head.*?>.*?<\/head>/is', '', $source);
- preg_match_all('/<style.*?type="text\/css".*?>(.*?)<\/style>/is', $matches[1], $matches);
+ preg_match_all('/<style(?:.*?type="text\/css".*?)?>(.*?)<\/style>/is', $matches[1], $matches);
foreach ($matches[1] as &$match) {
$css .= $match;
}
// 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);
}
{
$text = $part->getText();
$text = banana_htmlToPlainText($text);
- return banana_wrap($text, 1);
+ return banana_quote($text, 1);
}
// }}}
$text = $part->getText();
$text = banana_richtextToHtml($text);
$text = banana_htmlToPlainText($text);
- return banana_wrap($text, 1);
+ return banana_quote($text, 1);
}
// }}}