X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=banana%2Fmessage.func.inc.php;h=1628f374f4f7e6691da036fa27e3e3eeec1146ad;hb=1c71a12868e08c6050fa4c283665f82a67e50c10;hp=07d52f78caefebeccce19c277ac766669683d96a;hpb=d759a2ba63588128669bb1ea255fd940b0340dd1;p=banana.git diff --git a/banana/message.func.inc.php b/banana/message.func.inc.php index 07d52f7..1628f37 100644 --- a/banana/message.func.inc.php +++ b/banana/message.func.inc.php @@ -251,40 +251,146 @@ function banana_removeEvilAttributes($tagSource) $stripAttrib = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|'. 'onmousemove|onmouseout|onkeypress|onkeydown|onkeyup'; return stripslashes(preg_replace("/$stripAttrib/i", '', $tagSource)); -} +} + +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("\n", ' ', stripslashes($attributes)); + $attributes = str_replace('= "', '="', $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; "; + } 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; "; + } elseif (is_numeric($val)) { + $style .= "$stl: {$val}px; "; + } else { + $style .= "$stl: $val; "; + } + } + } + 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; +} /** * @return string * @param string * @desc Strip forbidden tags and delegate tag-source check to removeEvilAttributes() */ -function banana_cleanHtml($source) +function banana_cleanHtml($source, $to_xhtml = false) { - $allowedTags = '