From c976326cfd1ee61836b14cfdfc223cea86053683 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 30 Jun 2010 16:20:48 -0600 Subject: [PATCH] All IMP HTML viewer tests now pass --- imp/lib/Mime/Viewer/Html.php | 38 +++++++++++++++++++++----------- imp/lib/tests/mime_viewer_html.phpt | 44 +++++++++++++++---------------------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/imp/lib/Mime/Viewer/Html.php b/imp/lib/Mime/Viewer/Html.php index 78f3ff974..f88599f1e 100644 --- a/imp/lib/Mime/Viewer/Html.php +++ b/imp/lib/Mime/Viewer/Html.php @@ -18,6 +18,13 @@ 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('&', '&', trim($matches[5], '\'" '))) . '"' - : $matches[1] . "'" . $this->_blockimg . '\')' . $matches[6] . '" htmlimgblocked="' . rawurlencode(str_replace('&', '&', trim($matches[5], '\'" '))) . '"'; + ? $matches[1] . '"' . $this->blockimg . '" htmlimgblocked="' . rawurlencode(str_replace('&', '&', trim($matches[5], '\'" '))) . '"' + : trim($matches[1] . "'" . $this->blockimg . '\')' . $matches[6], '\'" ') . '" htmlimgblocked="' . rawurlencode(str_replace('&', '&', trim($matches[5], '\'" '))) . '"'; } /** diff --git a/imp/lib/tests/mime_viewer_html.phpt b/imp/lib/tests/mime_viewer_html.phpt index 560b0b8f6..2ce1c7c96 100644 --- a/imp/lib/tests/mime_viewer_html.phpt +++ b/imp/lib/tests/mime_viewer_html.phpt @@ -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 Example Email echo $v->openLinksInNewWindow('') . "\n"; echo $v->openLinksInNewWindow('') . "\n"; echo "\n"; -exit; // Test regex for hiding images. -echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'), - '') . "\n"; -echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'), - '') . "\n"; -echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'), - '') . "\n"; -echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'), - "Best flight deals") . "\n"; -echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'), - '') . "\n"; -echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'), - '') . "\n"; -echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'), - '') . "\n"; -echo preg_replace_callback($v->_img_regex, array($v, '_blockImages'), - ' +echo $v->blockImages('') . "\n"; +echo $v->blockImages('') . "\n"; +echo $v->blockImages('') . "\n"; +echo $v->blockImages("Best flight deals") . "\n"; +echo $v->blockImages('') . "\n"; +echo $v->blockImages('') . "\n"; +echo $v->blockImages('') . "\n"; +echo $v->blockImages(' ') . "\n"; ?> @@ -59,12 +51,12 @@ foo Example Email - - - -Best flight deals - - - - - + + + +Best flight deals + + + + + -- 2.11.0