+}
+
+function banana_cleanStyles($tag, $attributes)
+{
+ static $td_style, $conv, $size_conv;
+ if (!isset($td_style)) {
+ $conv = array('style' => 'style', 'width' => 'width', 'height' => 'height', 'border' => 'border-size',
+ 'size' => 'font-size', 'align' => 'text-align', 'valign' => 'vertical-align', 'face' => 'font',
+ 'bgcolor' => 'background-color', 'color' => 'color', 'style' => 'style',
+ 'cellpadding' => 'padding', 'cellspacing' => 'border-spacing');
+ $size_conv = array(1 => 'xx-small', 2 => 'x-small', 3 => 'small', 4 => 'medium', 5 => 'large',
+ 6 => 'x-large', 7 => 'xx-large',
+ '-2' => 'xx-small', '-1' => 'x-small', '+1' => 'medium', '+2' => 'large',
+ '+3' => 'x-large', '+4' => 'xx-large');
+ $td_style = array();
+ }
+ if ($tag == 'table') {
+ array_unshift($td_style, '');
+ }
+ if ($tag == '/table') {
+ array_shift($td_style);
+ }
+ if ($tag{0} == '/') {
+ return '';
+ }
+ if ($tag == 'td') {
+ $style = $td_style[0];
+ } else {
+ $style = '';
+ }
+ $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;
+ } elseif ($att == 'cellpadding' && $tag == 'table') {
+ $td_style[0] = "$stl: {$val}px; ";
+ } elseif ($att == 'style') {
+ $val = rtrim($val, ' ;');
+ $style .= "$val; ";
+ } elseif ($att == 'size') {
+ $val = $size_conv[$val];
+ $style = "$stl: $val; " . $style;
+ } elseif (is_numeric($val)) {
+ $style = "$stl: {$val}px; " . $style;
+ } else {
+ $style = "$stl: $val; " . $style;
+ }
+ }
+ }
+ if (!empty($style)) {
+ $style = 'style="' . $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)
+{
+ 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\([^:\)]+:(//|\\\).*?\)!i', $css)) {
+ $css = preg_replace('!url\([^:\)]+:(//|\\\).*?\)!i', 'url(invalid-image.png)', $css);
+ Banana::$msgshow_hasextimages = true;
+ }
+ }
+ return $css;
+}