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.
*
);
/**
- * Cached block image.
- *
- * @var string
- */
- protected $_blockimg = null;
-
- /**
* The regular expression to catch any tags and attributes that load
* external images.
*
# closing parenthesis
\s*\)
# remainder of the "style" attribute; match 6
- ((?(3)[^"\'>]*|[^\s>]*))
+ ((?(3)[^"\'>]*|[^\s>]*)(?(3)\\3))
)
/isx';
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'),
}
/**
+ * 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
*/
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], '\'" '))) . '"';
}
/**
$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.
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";
?>
<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">