All IMP HTML viewer tests now pass
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 30 Jun 2010 22:20:48 +0000 (16:20 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 30 Jun 2010 22:20:48 +0000 (16:20 -0600)
imp/lib/Mime/Viewer/Html.php
imp/lib/tests/mime_viewer_html.phpt

index 78f3ff9..f88599f 100644 (file)
 class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html
 {
     /**
+     * Cached block image.
+     *
+     * @var string
+     */
+    public $blockimg = null;
+
+    /**
      * The window target to use for links.
      * Needed for testing purposes.
      *
@@ -38,13 +45,6 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html
     );
 
     /**
-     * Cached block image.
-     *
-     * @var string
-     */
-    protected $_blockimg = null;
-
-    /**
      * The regular expression to catch any tags and attributes that load
      * external images.
      *
@@ -80,7 +80,7 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html
             # closing parenthesis
             \s*\)
             # remainder of the "style" attribute; match 6
-            ((?(3)[^"\'>]*|[^\s>]*))
+            ((?(3)[^"\'>]*|[^\s>]*)(?(3)\\3))
         )
         /isx';
 
@@ -243,7 +243,7 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html
             preg_match($this->_img_regex, $this->_mimepart->getContents()) &&
             (!$GLOBALS['prefs']->getValue('html_image_addrbook') ||
              !$this->_inAddressBook())) {
-            $data = preg_replace_callback($this->_img_regex, array($this, '_blockImages'), $data);
+            $data = $this->blockImages($data);
 
             $status[] = array(
                 'icon' => Horde::img('mime/image.png'),
@@ -308,6 +308,18 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html
     }
 
     /**
+     * Block images in HTML data.
+     *
+     * @param string $data  Data in.
+     *
+     * @return string  Altered data.
+     */
+    public function blockImages($data)
+    {
+        return preg_replace_callback($this->_img_regex, array($this, '_blockImages'), $data);
+    }
+
+    /**
      * Called from the image-blocking regexp to construct the new image tags.
      *
      * @param array $matches
@@ -316,13 +328,13 @@ class IMP_Horde_Mime_Viewer_Html extends Horde_Mime_Viewer_Html
      */
     protected function _blockImages($matches)
     {
-        if (is_null($this->_blockimg)) {
-            $this->_blockimg = Horde::url(Horde_Themes::img('spacer_red.png'), true, -1);
+        if (is_null($this->blockimg)) {
+            $this->blockimg = Horde::url(Horde_Themes::img('spacer_red.png'), true, -1);
         }
 
         return empty($matches[2])
-            ? $matches[1] . '"' . $this->_blockimg . '" htmlimgblocked="' . rawurlencode(str_replace('&amp;', '&', trim($matches[5], '\'" '))) . '"'
-            : $matches[1] . "'" . $this->_blockimg . '\')' . $matches[6] . '" htmlimgblocked="' . rawurlencode(str_replace('&amp;', '&', trim($matches[5], '\'" '))) . '"';
+            ? $matches[1] . '"' . $this->blockimg . '" htmlimgblocked="' . rawurlencode(str_replace('&amp;', '&', trim($matches[5], '\'" '))) . '"'
+            : trim($matches[1] . "'" . $this->blockimg . '\')' . $matches[6], '\'" ') . '" htmlimgblocked="' . rawurlencode(str_replace('&amp;', '&', trim($matches[5], '\'" '))) . '"';
     }
 
     /**
index 560b0b8..2ce1c7c 100644 (file)
@@ -13,6 +13,7 @@ $mock_part = new Horde_Mime_Part();
 $mock_part->setType('text/html');
 
 $v = Horde_Mime_Viewer::factory($mock_part);
+$v->blockimg = 'imgblock.png';
 $v->newwinTarget = '_blank';
 
 // Test regex for converting links to open in a new window.
@@ -26,25 +27,16 @@ echo $v->openLinksInNewWindow('foo <a mailto="example@example.com">Example Email
 echo $v->openLinksInNewWindow('<map name="Map"><area shape="rect" coords="32,-2,293,29" href="http://www.example.com/"></map>') . "\n";
 echo $v->openLinksInNewWindow('<map name="Map"><area shape="rect" coords="32,-2,293,29" href="http://www.example.com/" target="foo"></map>') . "\n";
 echo "\n";
-exit;
 
 // Test regex for hiding images.
-echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'),
-                           '<img src="http://example.com/image.png">') . "\n";
-echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'),
-                           '<img src="http://example.com/image.png" />') . "\n";
-echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'),
-                           '<td  background=http://example.com/image.png>') . "\n";
-echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'),
-                           "<img src= http://example.com/image.png alt='Best flight deals'  border=0>") . "\n";
-echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'),
-                           '<foo style="background:url(http://example.com/image.png)">') . "\n";
-echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'),
-                           '<foo style="background: transparent url(http://example.com/image.png) repeat">') . "\n";
-echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'),
-                           '<foo style="background-image:url(http://example.com/image.png)">') . "\n";
-echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'),
-                           '<foo style="background: transparent url(http://example.com/image.png) repeat">
+echo $v->blockImages('<img src="http://example.com/image.png">') . "\n";
+echo $v->blockImages('<img src="http://example.com/image.png" />') . "\n";
+echo $v->blockImages('<td  background=http://example.com/image.png>') . "\n";
+echo $v->blockImages("<img src= http://example.com/image.png alt='Best flight deals'  border=0>") . "\n";
+echo $v->blockImages('<foo style="background:url(http://example.com/image.png)">') . "\n";
+echo $v->blockImages('<foo style="background: transparent url(http://example.com/image.png) repeat">') . "\n";
+echo $v->blockImages('<foo style="background-image:url(http://example.com/image.png)">') . "\n";
+echo $v->blockImages('<foo style="background: transparent url(http://example.com/image.png) repeat">
 <foo style="background-image:url(http://example.com/image.png)">') . "\n";
 
 ?>
@@ -59,12 +51,12 @@ foo <a target="_blank" mailto="example@example.com">Example Email</a>
 <map name="Map"><area target="_blank" shape="rect" coords="32,-2,293,29" href="http://www.example.com/"></map>
 <map name="Map"><area shape="rect" coords="32,-2,293,29" href="http://www.example.com/" target="_blank"></map>
 
-<img src="/spacer_red.png" blocked="http%3A%2F%2Fexample.com%2Fimage.png">
-<img src="/spacer_red.png" blocked="http%3A%2F%2Fexample.com%2Fimage.png" />
-<td  background="/spacer_red.png" blocked="http%3A%2F%2Fexample.com%2Fimage.png">
-<img src="/spacer_red.png" blocked="http%3A%2F%2Fexample.com%2Fimage.png" alt='Best flight deals'  border=0>
-<foo style="background:url('/spacer_red.png')" blocked="http%3A%2F%2Fexample.com%2Fimage.png">
-<foo style="background: transparent url('/spacer_red.png') repeat" blocked="http%3A%2F%2Fexample.com%2Fimage.png">
-<foo style="background-image:url('/spacer_red.png')" blocked="http%3A%2F%2Fexample.com%2Fimage.png">
-<foo style="background: transparent url('/spacer_red.png') repeat" blocked="http%3A%2F%2Fexample.com%2Fimage.png">
-<foo style="background-image:url('/spacer_red.png')" blocked="http%3A%2F%2Fexample.com%2Fimage.png">
+<img src="imgblock.png" htmlimgblocked="http%3A%2F%2Fexample.com%2Fimage.png">
+<img src="imgblock.png" htmlimgblocked="http%3A%2F%2Fexample.com%2Fimage.png" />
+<td  background="imgblock.png" htmlimgblocked="http%3A%2F%2Fexample.com%2Fimage.png">
+<img src="imgblock.png" htmlimgblocked="http%3A%2F%2Fexample.com%2Fimage.png" alt='Best flight deals'  border=0>
+<foo style="background:url('imgblock.png')" htmlimgblocked="http%3A%2F%2Fexample.com%2Fimage.png">
+<foo style="background: transparent url('imgblock.png') repeat" htmlimgblocked="http%3A%2F%2Fexample.com%2Fimage.png">
+<foo style="background-image:url('imgblock.png')" htmlimgblocked="http%3A%2F%2Fexample.com%2Fimage.png">
+<foo style="background: transparent url('imgblock.png') repeat" htmlimgblocked="http%3A%2F%2Fexample.com%2Fimage.png">
+<foo style="background-image:url('imgblock.png')" htmlimgblocked="http%3A%2F%2Fexample.com%2Fimage.png">