Do not render images or social icons if image src is not defined
This commit is contained in:
@@ -6,6 +6,10 @@ use MailPoet\Newsletter\Renderer\StylesHelper;
|
|||||||
|
|
||||||
class Image {
|
class Image {
|
||||||
static function render($element, $column_count) {
|
static function render($element, $column_count) {
|
||||||
|
if(empty($element['src'])) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
$element['width'] = (int)$element['width'];
|
$element['width'] = (int)$element['width'];
|
||||||
$element['height'] = (int)$element['height'];
|
$element['height'] = (int)$element['height'];
|
||||||
$element = self::adjustImageDimensions($element, $column_count);
|
$element = self::adjustImageDimensions($element, $column_count);
|
||||||
|
@@ -6,11 +6,17 @@ class Social {
|
|||||||
$icons_block = '';
|
$icons_block = '';
|
||||||
if(is_array($element['icons'])) {
|
if(is_array($element['icons'])) {
|
||||||
foreach($element['icons'] as $index => $icon) {
|
foreach($element['icons'] as $index => $icon) {
|
||||||
|
if(empty($icon['image'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$icons_block .= '
|
$icons_block .= '
|
||||||
<a href="' . $icon['link'] . '" style="text-decoration:none!important;">
|
<a href="' . $icon['link'] . '" style="text-decoration:none!important;">
|
||||||
<img src="' . $icon['image'] . '" width="' . (int)$icon['width'] . '" height="' . (int)$icon['height'] . '" style="width:' . $icon['width'] . ';height:' . $icon['width'] . ';-ms-interpolation-mode:bicubic;border:0;display:inline;outline:none;" alt="' . $icon['iconType'] . '">
|
<img src="' . $icon['image'] . '" width="' . (int)$icon['width'] . '" height="' . (int)$icon['height'] . '" style="width:' . $icon['width'] . ';height:' . $icon['width'] . ';-ms-interpolation-mode:bicubic;border:0;display:inline;outline:none;" alt="' . $icon['iconType'] . '">
|
||||||
</a>';
|
</a>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if(!empty($icons_block)) {
|
||||||
$template = '
|
$template = '
|
||||||
<tr>
|
<tr>
|
||||||
<td class="mailpoet_padded_side mailpoet_padded_bottom" valign="top" align="center">
|
<td class="mailpoet_padded_side mailpoet_padded_bottom" valign="top" align="center">
|
||||||
|
@@ -150,6 +150,18 @@ class NewsletterRendererTest extends MailPoetTest {
|
|||||||
expect($DOM('tr > td > img', 0)->attr('style'))->notEmpty();
|
expect($DOM('tr > td > img', 0)->attr('style'))->notEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItDoesNotRenderImageWithoutSrc() {
|
||||||
|
$image = array(
|
||||||
|
'src' => '',
|
||||||
|
'width' => '100',
|
||||||
|
'height' => '200',
|
||||||
|
'link' => '',
|
||||||
|
'alt' => 'some test alt text'
|
||||||
|
);
|
||||||
|
$rendered_image = Image::render($image, $columnCount = 1);
|
||||||
|
expect($rendered_image)->equals('');
|
||||||
|
}
|
||||||
|
|
||||||
function testItRendersImageWithLink() {
|
function testItRendersImageWithLink() {
|
||||||
$newsletter = $this->newsletter['body'];
|
$newsletter = $this->newsletter['body'];
|
||||||
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1];
|
$template = $newsletter['content']['blocks'][0]['blocks'][0]['blocks'][1];
|
||||||
@@ -306,6 +318,20 @@ class NewsletterRendererTest extends MailPoetTest {
|
|||||||
expect(count($DOM('a > img')))->equals(10);
|
expect(count($DOM('a > img')))->equals(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItDoesNotRenderSocialIconsWithoutImageSrc() {
|
||||||
|
$block = array(
|
||||||
|
'icons' => array(
|
||||||
|
'image' => '',
|
||||||
|
'width' => '100',
|
||||||
|
'height' => '100',
|
||||||
|
'link' => '',
|
||||||
|
'iconType' => 'custom',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$rendered_block = Social::render($block, $columnCount = 1);
|
||||||
|
expect($rendered_block)->equals('');
|
||||||
|
}
|
||||||
|
|
||||||
function testItRendersFooter() {
|
function testItRendersFooter() {
|
||||||
$newsletter = $this->newsletter['body'];
|
$newsletter = $this->newsletter['body'];
|
||||||
$template = $newsletter['content']['blocks'][3]['blocks'][0]['blocks'][0];
|
$template = $newsletter['content']['blocks'][3]['blocks'][0]['blocks'][0];
|
||||||
|
Reference in New Issue
Block a user