Changeset 97bd2c0 in github
- Timestamp:
- Sep 29, 2007 2:15:05 PM (6 years ago)
- Branches:
- master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
- Children:
- ee18f5f
- Parents:
- ca2b4dd
- Files:
-
- 1 added
- 4 edited
-
CHANGELOG (modified) (1 diff)
-
bin/modcss.php (added)
-
program/include/main.inc (modified) (2 diffs)
-
program/include/rcube_shared.inc (modified) (1 diff)
-
program/steps/mail/func.inc (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
CHANGELOG
re2f3738f r97bd2c0 1 1 CHANGELOG RoundCube Webmail 2 2 --------------------------- 3 4 2007/09/29 (thomasb) 5 ---------- 6 - Filter linked/imported CSS files (closes #1484056) 7 3 8 4 9 2007/09/27 (tomekp) -
program/include/main.inc
r5e80457 r97bd2c0 30 30 require_once('lib/utf7.inc'); 31 31 require_once('lib/utf8.class.php'); 32 require_once('include/rcube_shared.inc'); 32 33 require_once('include/rcmail_template.inc'); 33 34 … … 1447 1448 1448 1449 return $domain; 1450 } 1451 1452 1453 /** 1454 * Replace all css definitions with #container [def] 1455 * 1456 * @param string CSS source code 1457 * @param string Container ID to use as prefix 1458 * @return string Modified CSS source 1459 */ 1460 function rcmail_mod_css_styles($source, $container_id, $base_url = '') 1461 { 1462 $a_css_values = array(); 1463 $last_pos = 0; 1464 1465 // cut out all contents between { and } 1466 while (($pos = strpos($source, '{', $last_pos)) && ($pos2 = strpos($source, '}', $pos))) 1467 { 1468 $key = sizeof($a_css_values); 1469 $a_css_values[$key] = substr($source, $pos+1, $pos2-($pos+1)); 1470 $source = substr($source, 0, $pos+1) . "<<str_replacement[$key]>>" . substr($source, $pos2, strlen($source)-$pos2); 1471 $last_pos = $pos+2; 1472 } 1473 1474 // remove html commends and add #container to each tag selector. 1475 // also replace body definition because we also stripped off the <body> tag 1476 $styles = preg_replace( 1477 array( 1478 '/(^\s*<!--)|(-->\s*$)/', 1479 '/(^\s*|,\s*|\}\s*)([a-z0-9\._#][a-z0-9\.\-_]*)/im', 1480 '/@import\s+(url\()?[\'"]?([^\)\'"]+)[\'"]?(\))?/ime', 1481 '/<<str_replacement\[([0-9]+)\]>>/e', 1482 "/$container_id\s+body/i" 1483 ), 1484 array( 1485 '', 1486 "\\1#$container_id \\2", 1487 "sprintf(\"@import url('./bin/modcss.php?u=%s&c=%s')\", urlencode(make_absolute_url('\\2','$base_url')), urlencode($container_id))", 1488 "\$a_css_values[\\1]", 1489 "$container_id div.rcmBody" 1490 ), 1491 $source); 1492 1493 return $styles; 1449 1494 } 1450 1495 -
program/include/rcube_shared.inc
r5a6efff r97bd2c0 435 435 $host_url = $base_url; 436 436 $abs_path = $path; 437 438 // check if path is an absolute URL 439 if (preg_match('/^[fhtps]+:\/\//', $path)) 440 return $path; 437 441 438 442 // cut base_url to the last directory -
program/steps/mail/func.inc
r5eee009 r97bd2c0 947 947 $body = preg_replace('/\x00/', '', $body); 948 948 949 $base_url = ""; 949 950 $last_style_pos = 0; 950 951 $body_lc = strtolower($body); 951 952 953 // check for <base href> 954 if (preg_match(($base_reg = '/(<base.*href=["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)([^<]*>)/i'), $body, $base_regs)) 955 $base_url = $base_regs[2]; 956 952 957 // find STYLE tags 953 958 while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos))) … … 956 961 957 962 // replace all css definitions with #container [def] 958 $styles = rcmail_mod_css_styles(substr($body, $pos, $pos2-$pos), $container_id );963 $styles = rcmail_mod_css_styles(substr($body, $pos, $pos2-$pos), $container_id, $base_url); 959 964 960 965 $body = substr($body, 0, $pos) . $styles . substr($body, $pos2); … … 984 989 985 990 // resolve <base href> 986 $base_reg = '/(<base.*href=["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)([^<]*>)/i'; 987 if (preg_match($base_reg, $body, $regs)) 988 { 989 $base_url = $regs[2]; 991 if ($base_url) 992 { 990 993 $body = preg_replace('/(src|background|href)=(["\']?)([\.\/]+[^"\'\s]+)(\2|\s|>)/Uie', "'\\1=\"'.make_absolute_url('\\3', '$base_url').'\"'", $body); 991 994 $body = preg_replace('/(url\s*\()(["\']?)([\.\/]+[^"\'\)\s]+)(\2)\)/Uie', "'\\1\''.make_absolute_url('\\3', '$base_url').'\')'", $body); … … 994 997 995 998 // modify HTML links to open a new window if clicked 996 $body = preg_replace('/< a\s+([^>]+)>/Uie', "rcmail_alter_html_link('\\1');", $body);999 $body = preg_replace('/<(a|link)\s+([^>]+)>/Uie', "rcmail_alter_html_link('\\1','\\2', '$container_id');", $body); 997 1000 998 1001 // add comments arround html and other tags … … 1006 1009 $body); 1007 1010 1008 $out = preg_replace(array('/<body([^>]*)>/i', 1009 '/<\/body>/i'), 1010 array('<div class="rcmBody"\\1>', 1011 '</div>'), 1012 $out); 1011 $out = preg_replace( 1012 array( 1013 '/<body([^>]*)>/i', 1014 '/<\/body>/i', 1015 ), 1016 array( 1017 '<div class="rcmBody"\\1>', 1018 '</div>', 1019 ), 1020 $out); 1013 1021 1014 1022 // quote <? of php and xml files that are specified as text/html … … 1020 1028 1021 1029 // parse link attributes and set correct target 1022 function rcmail_alter_html_link($ in)1030 function rcmail_alter_html_link($tag, $attrs, $container_id) 1023 1031 { 1024 1032 $in = preg_replace('/=([^("|\'|\s)]+)(\s|$)/', '="\1"', $in); 1025 $attrib = parse_attrib_string($in); 1026 1027 if (stristr((string)$attrib['href'], 'mailto:')) 1028 $attrib['onclick'] = sprintf("return %s.command('compose','%s',this)", 1029 JS_OBJECT_NAME, 1030 JQ(substr($attrib['href'], 7))); 1033 $attrib = parse_attrib_string($attrs); 1034 1035 if ($tag == 'link' && preg_match('/^https?:\/\//i', $attrib['href'])) 1036 $attrib['href'] = "./bin/modcss.php?u=" . urlencode($attrib['href']) . "&c=" . urlencode($container_id); 1037 1038 else if (stristr((string)$attrib['href'], 'mailto:')) 1039 $attrib['onclick'] = sprintf( 1040 "return %s.command('compose','%s',this)", 1041 JS_OBJECT_NAME, 1042 JQ(substr($attrib['href'], 7))); 1043 1031 1044 else if (!empty($attrib['href']) && $attrib['href']{0}!='#') 1032 1045 $attrib['target'] = '_blank'; 1033 1034 return '<a' . create_attrib_string($attrib, array('href', 'name', 'target', 'onclick', 'id', 'class', 'style', 'title')) . '>'; 1035 } 1036 1037 1038 // replace all css definitions with #container [def] 1039 function rcmail_mod_css_styles($source, $container_id) 1040 { 1041 $a_css_values = array(); 1042 $last_pos = 0; 1043 1044 // cut out all contents between { and } 1045 while (($pos = strpos($source, '{', $last_pos)) && ($pos2 = strpos($source, '}', $pos))) 1046 { 1047 $key = sizeof($a_css_values); 1048 $a_css_values[$key] = substr($source, $pos+1, $pos2-($pos+1)); 1049 $source = substr($source, 0, $pos+1) . "<<str_replacement[$key]>>" . substr($source, $pos2, strlen($source)-$pos2); 1050 $last_pos = $pos+2; 1051 } 1052 1053 // remove html commends and add #container to each tag selector. 1054 // also replace body definition because we also stripped off the <body> tag 1055 $styles = preg_replace(array('/(^\s*<!--)|(-->\s*$)/', '/(^\s*|,\s*|\}\s*)([a-z0-9\._][a-z0-9\.\-_]*)/im', '/<<str_replacement\[([0-9]+)\]>>/e', "/$container_id\s+body/i"), 1056 array('', "\\1#$container_id \\2", "\$a_css_values[\\1]", "$container_id div.rcmBody"), 1057 $source); 1058 1059 return $styles; 1046 1047 return "<$tag" . create_attrib_string($attrib, array('href','name','target','onclick','id','class','style','title','rel','type','media')) . ' />'; 1060 1048 } 1061 1049
Note: See TracChangeset
for help on using the changeset viewer.
