Skip to content

Commit

Permalink
Fix deferred images in HTML emails
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Aug 30, 2019
1 parent 558582e commit 7e750d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core-bundle/src/Resources/contao/library/Contao/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public function sendTo()
$src = rawurldecode($src); // see #3713

// Embed the image if the URL is now relative
if (!preg_match('@^https?://@', $src) && file_exists($this->strImageDir . $src))
if (!preg_match('@^https?://@', $src) && ($objFile = new File(StringUtil::stripRootDir($this->strImageDir . $src))) && ($objFile->exists() || $objFile->generateIfDeferredImage()))
{
if (!isset($arrCid[$src]))
{
Expand Down
20 changes: 17 additions & 3 deletions core-bundle/src/Resources/contao/library/Contao/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,11 @@ public function getModel()
}

/**
* Return the file content as string
* Generate the image if the current file is a deferred image and does not exist yet
*
* @return string The file content without BOM
* @return bool True if a deferred image was resized otherwise false
*/
public function getContent()
public function generateIfDeferredImage()
{
if (!$this->exists())
{
Expand All @@ -614,6 +614,8 @@ public function getContent()
if ($image instanceof DeferredImageInterface)
{
System::getContainer()->get('contao.image.resizer')->resizeDeferredImage($image);

return true;
}
}
catch (\Throwable $e)
Expand All @@ -622,6 +624,18 @@ public function getContent()
}
}

return false;
}

/**
* Return the file content as string
*
* @return string The file content without BOM
*/
public function getContent()
{
$this->generateIfDeferredImage();

$strContent = file_get_contents($this->strRootDir . '/' . ($this->strTmp ?: $this->strFile));

// Remove BOMs (see #4469)
Expand Down

0 comments on commit 7e750d8

Please sign in to comment.