Changeset 2252 in subversion for trunk/roundcubemail/program/include/main.inc
- Timestamp:
- Jan 22, 2009 9:47:23 AM (4 years ago)
- File:
-
- 1 edited
-
trunk/roundcubemail/program/include/main.inc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/include/main.inc
r2237 r2252 588 588 * @return string Modified CSS source 589 589 */ 590 function rcmail_mod_css_styles($source, $container_id, $base_url = '') 591 { 592 $a_css_values = array(); 590 function rcmail_mod_css_styles($source, $container_id) 591 { 593 592 $last_pos = 0; 593 $replacements = new rcube_string_replacer; 594 594 595 595 // ignore the whole block if evil styles are detected 596 596 $stripped = preg_replace('/[^a-z\(:]/', '', rcmail_xss_entitiy_decode($source)); 597 597 if (preg_match('/expression|behavior|url\(|import/', $stripped)) 598 return ' ';598 return '/* evil! */'; 599 599 600 600 // cut out all contents between { and } 601 601 while (($pos = strpos($source, '{', $last_pos)) && ($pos2 = strpos($source, '}', $pos))) 602 602 { 603 $key = sizeof($a_css_values); 604 $a_css_values[$key] = substr($source, $pos+1, $pos2-($pos+1)); 605 $source = substr($source, 0, $pos+1) . "<<str_replacement[$key]>>" . substr($source, $pos2, strlen($source)-$pos2); 603 $key = $replacements->add(substr($source, $pos+1, $pos2-($pos+1))); 604 $source = substr($source, 0, $pos+1) . $replacements->get_replacement($key) . substr($source, $pos2, strlen($source)-$pos2); 606 605 $last_pos = $pos+2; 607 606 } 608 607 609 608 // remove html comments and add #container to each tag selector. 610 609 // also replace body definition because we also stripped off the <body> tag … … 622 621 $source); 623 622 624 // replace all @import statements to modify the imported CSS sources too625 $styles = preg_replace_callback(626 '/@import\s+(url\()?[\'"]?([^\)\'"]+)[\'"]?(\))?/im',627 create_function('$matches', "return sprintf(\"@import url('./bin/modcss.php?u=%s&c=%s')\", urlencode(make_absolute_url(\$matches[2],'$base_url')), urlencode('$container_id'));"),628 $styles);629 630 623 // put block contents back in 631 $styles = preg_replace_callback( 632 '/<<str_replacement\[([0-9]+)\]>>/', 633 create_function('$matches', "\$values = ".var_export($a_css_values, true)."; return \$values[\$matches[1]];"), 634 $styles); 624 $styles = $replacements->resolve($styles); 635 625 636 626 return $styles; … … 648 638 { 649 639 $out = html_entity_decode(html_entity_decode($content)); 650 $out = preg_replace_callback('/\\\([0-9a-f]{4})/i', create_function('$matches', 'return chr(hexdec($matches[1]));'), $out);640 $out = preg_replace_callback('/\\\([0-9a-f]{4})/i', 'rcmail_xss_entitiy_decode_callback', $out); 651 641 $out = preg_replace('#/\*.*\*/#Um', '', $out); 652 642 return $out; 653 643 } 654 644 645 646 /** 647 * preg_replace_callback callback for rcmail_xss_entitiy_decode_callback 648 * 649 * @param array matches result from preg_replace_callback 650 * @return string decoded entity 651 */ 652 function rcmail_xss_entitiy_decode_callback($matches) 653 { 654 return chr(hexdec($matches[1])); 655 } 655 656 656 657 /** … … 1210 1211 } 1211 1212 1213 1214 1215 /** 1216 * Helper class to turn relative urls into absolute ones 1217 * using a predefined base 1218 */ 1219 class rcube_base_replacer 1220 { 1221 private $base_url; 1222 1223 public function __construct($base) 1224 { 1225 $this->base_url = $base; 1226 } 1227 1228 public function callback($matches) 1229 { 1230 return $matches[1] . '="' . make_absolute_url($matches[3], $this->base_url) . '"'; 1231 } 1232 } 1233 1234 1212 1235 ?>
Note: See TracChangeset
for help on using the changeset viewer.
