Changeset 3960 in subversion


Ignore:
Timestamp:
Sep 11, 2010 9:21:34 AM (3 years ago)
Author:
alec
Message:
  • Fix messages background image handling in some cases (#1486990)
Location:
trunk/roundcubemail
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r3951 r3960  
    2121- Re-added 'Close' button in upload form (#1486930, #1486823) 
    2222- Fix handling of charsets with LATIN-* label 
     23- Fix messages background image handling in some cases (#1486990) 
    2324 
    2425RELEASE 0.4 
  • trunk/roundcubemail/program/include/main.inc

    r3952 r3960  
    846846  $last_pos = 0; 
    847847  $replacements = new rcube_string_replacer; 
    848    
     848 
    849849  // ignore the whole block if evil styles are detected 
    850850  $stripped = preg_replace('/[^a-z\(:]/', '', rcmail_xss_entity_decode($source)); 
     
    869869      '/(^\s*<!--)|(-->\s*$)/', 
    870870      '/(^\s*|,\s*|\}\s*)([a-z0-9\._#\*][a-z0-9\.\-_]*)/im', 
    871       "/$container_id\s+body/i", 
     871      '/'.preg_quote($container_id, '/').'\s+body/i', 
    872872    ), 
    873873    array( 
    874874      '', 
    875875      "\\1#$container_id \\2", 
    876       "$container_id div.rcmBody", 
     876      $container_id, 
    877877    ), 
    878878    $source); 
    879    
     879 
    880880  // put block contents back in 
    881881  $styles = $replacements->resolve($styles); 
  • trunk/roundcubemail/program/steps/mail/func.inc

    r3923 r3960  
    995995          $style = array(); 
    996996 
    997           if (!empty($attrs['color'])) 
    998             $style[] = 'background-color: '.$attrs['color']; 
    999           if (!empty($attrs['image'])) 
    1000             $style[] = 'background-image: url('.$attrs['image'].')'; 
    1001           if (!empty($style)) 
    1002             $div_attr['style'] = implode('; ', $style); 
     997          if (!empty($attrs)) { 
     998            foreach ($attrs as $a_idx => $a_val) 
     999              $style[] = $a_idx . ': ' . $a_val; 
     1000            if (!empty($style)) 
     1001              $div_attr['style'] = implode('; ', $style); 
     1002          } 
    10031003 
    10041004          $out .= html::div($div_attr, $plugin['prefix'] . $body); 
     
    10721072 */ 
    10731073function rcmail_html4inline($body, $container_id, $body_id='', &$attributes=null) 
    1074   { 
     1074{ 
    10751075  $last_style_pos = 0; 
    10761076  $body_lc = strtolower($body); 
     1077  $cont_id = $container_id.($body_id ? ' div.'.$body_id : ''); 
    10771078 
    10781079  // find STYLE tags 
    10791080  while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos))) 
    1080     { 
     1081  { 
    10811082    $pos = strpos($body_lc, '>', $pos)+1; 
    10821083 
    10831084    // replace all css definitions with #container [def] 
    1084     $styles = rcmail_mod_css_styles(substr($body, $pos, $pos2-$pos), 
    1085       $container_id.($body_id ? ' div.'.$body_id : '')); 
     1085    $styles = rcmail_mod_css_styles( 
     1086      substr($body, $pos, $pos2-$pos), $cont_id); 
    10861087 
    10871088    $body = substr($body, 0, $pos) . $styles . substr($body, $pos2); 
    10881089    $body_lc = strtolower($body); 
    10891090    $last_style_pos = $pos2; 
    1090     } 
     1091  } 
    10911092 
    10921093  // modify HTML links to open a new window if clicked 
     
    10951096  unset($GLOBALS['rcmail_html_container_id']); 
    10961097 
    1097   $out = preg_replace(array( 
     1098  $body = preg_replace(array( 
    10981099      // add comments arround html and other tags 
    10991100      '/(<!DOCTYPE[^>]*>)/i', 
     
    11271128 
    11281129  // Handle body attributes that doesn't play nicely with div elements 
    1129   if (preg_match('/<div class="' . preg_quote($body_id, '/') . '" ([^>]+)/', $out, $m)) { 
     1130  if (preg_match('/<div class="' . preg_quote($body_id, '/') . '" ([^>]+)/', $body, $m)) { 
    11301131    $attrs = $m[0]; 
    11311132    // Get bgcolor, we'll set it as background-color of the message container 
    11321133    if (preg_match('/bgcolor=["\']*([a-z0-9#]+)["\']*/', $attrs, $mb)) { 
    1133       $attributes['color'] = $mb[1]; 
     1134      $attributes['background-color'] = $mb[1]; 
    11341135      $attrs = preg_replace('/bgcolor=["\']*([a-z0-9#]+)["\']*/', '', $attrs); 
    11351136    } 
    11361137    // Get background, we'll set it as background-image of the message container 
    11371138    if (preg_match('/background=["\']*([^"\'>\s]+)["\']*/', $attrs, $mb)) { 
    1138       $attributes['image'] = $mb[1]; 
     1139      $attributes['background-image'] = 'url('.$mb[1].')'; 
    11391140      $attrs = preg_replace('/background=["\']*([^"\'>\s]+)["\']*/', '', $attrs); 
    11401141    } 
    11411142    if (!empty($attributes)) 
    1142       $out = preg_replace('/<div class="' . preg_quote($body_id, '/') . '" [^>]+/', rtrim($attrs), $out, 1); 
     1143      $body = preg_replace('/<div class="' . preg_quote($body_id, '/') . '" [^>]+/', rtrim($attrs), $body, 1); 
     1144 
     1145    // handle body styles related to background image 
     1146    if ($attributes['background-image']) { 
     1147      // get body style 
     1148      if (preg_match('/#'.preg_quote($cont_id, '/').'\s+\{([^}]+)}/i', $body, $m)) { 
     1149        // get background related style 
     1150        if (preg_match_all('/(background-position|background-repeat)\s*:\s*([^;]+);/i', $m[1], $ma, PREG_SET_ORDER)) { 
     1151          foreach ($ma as $style) 
     1152            $attributes[$style[1]] = $style[2]; 
     1153        } 
     1154      } 
     1155    } 
    11431156  } 
    11441157  // make sure there's 'rcmBody' div, we need it for proper css modification 
    11451158  // its name is hardcoded in rcmail_message_body() also 
    11461159  else 
    1147     $out = '<div class="' . $body_id . '">' . $out . '</div>'; 
    1148  
    1149   return $out; 
    1150   } 
     1160    $body = '<div class="' . $body_id . '">' . $body . '</div>'; 
     1161 
     1162  return $body; 
     1163} 
    11511164 
    11521165 
Note: See TracChangeset for help on using the changeset viewer.