Changeset 3675 in subversion


Ignore:
Timestamp:
May 27, 2010 9:34:58 AM (3 years ago)
Author:
alec
Message:
  • support base URL for inline images
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/lib/washtml.php

    r3651 r3675  
    7575 * - changed $ignore_elements behaviour 
    7676 * - added RFC2397 support 
     77 * - base URL support 
    7778 */ 
    7879 
     
    145146                 ')\s*/i', $str, $match)) { 
    146147          if ($match[2]) { 
    147             if ($src = $this->config['cid_map'][$match[2]]) 
     148            if (($src = $this->config['cid_map'][$match[2]]) 
     149                || ($src = $this->config['cid_map'][$this->config['base_url'].$match[2]])) { 
    148150              $value .= ' url('.htmlspecialchars($src, ENT_QUOTES) . ')'; 
     151            } 
    149152            else if (preg_match('/^(http|https|ftp):.*$/i', $match[2], $url)) { 
    150153              if ($this->config['allow_remote']) 
     
    181184        $t .= ' style="' . $style . '"'; 
    182185      else if ($key == 'background' || ($key == 'src' && strtolower($node->tagName) == 'img')) { //check tagName anyway 
    183         if ($src = $this->config['cid_map'][$value]) { 
     186        if (($src = $this->config['cid_map'][$value]) 
     187            || ($src = $this->config['cid_map'][$this->config['base_url'].$value])) { 
    184188          $t .= ' ' . $key . '="' . htmlspecialchars($src, ENT_QUOTES) . '"'; 
    185189        } 
     
    216220      case XML_ELEMENT_NODE: //Check element 
    217221        $tagName = strtolower($node->tagName); 
    218         if($callback = $this->handlers[$tagName]) { 
     222        if ($callback = $this->handlers[$tagName]) { 
    219223          $dump .= call_user_func($callback, $tagName, $this->wash_attribs($node), $this->dumpHtml($node)); 
    220         } else if(isset($this->_html_elements[$tagName])) { 
     224        } 
     225        else if (isset($this->_html_elements[$tagName])) { 
    221226          $content = $this->dumpHtml($node); 
    222227          $dump .= '<' . $tagName . $this->wash_attribs($node) . 
    223228            ($content != '' || isset($this->_block_elements[$tagName]) ? ">$content</$tagName>" : ' />'); 
    224         } else if(isset($this->_ignore_elements[$tagName])) { 
     229        } 
     230        else if (isset($this->_ignore_elements[$tagName])) { 
    225231          $dump .= '<!-- ' . htmlspecialchars($tagName, ENT_QUOTES) . ' not allowed -->'; 
    226         } else { 
     232        } 
     233        else { 
    227234          $dump .= '<!-- ' . htmlspecialchars($tagName, ENT_QUOTES) . ' ignored -->'; 
    228235          $dump .= $this->dumpHtml($node); // ignore tags not its content 
    229         } 
     236        } 
    230237        break; 
    231238      case XML_CDATA_SECTION_NODE: 
     
    250257  /* Main function, give it untrusted HTML, tell it if you allow loading 
    251258   * remote images and give it a map to convert "cid:" urls. */ 
    252   public function wash($html) { 
    253     //Charset seems to be ignored (probably if defined in the HTML document) 
     259  public function wash($html) 
     260  { 
     261    // Charset seems to be ignored (probably if defined in the HTML document) 
    254262    $node = new DOMDocument('1.0', $this->config['charset']); 
    255263    $this->extlinks = false; 
     264 
     265    // Find base URL for images 
     266    if (preg_match('/<base\s+href=[\'"]*([^\'"]+)/is', $html, $matches)) 
     267      $this->config['base_url'] = $matches[1]; 
     268    else 
     269      $this->config['base_url'] = ''; 
     270 
    256271    @$node->loadHTML($html); 
    257272    return $this->dumpHtml($node); 
Note: See TracChangeset for help on using the changeset viewer.