Skip to content

Commit

Permalink
Override document root to fix images in PDFs in Contao 4 (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Oct 9, 2018
1 parent 0233211 commit 383f41e
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,20 @@ protected function generateTemplate(IsotopeProductCollection $objCollection, arr

// URL decode image paths (see contao/core#6411)
// Make image paths absolute
$strBuffer = preg_replace_callback('@(src=")([^"]+)(")@', function ($args) {
$blnOverrideRoot = false;
$strBuffer = preg_replace_callback('@(src=")([^"]+)(")@', function ($args) use (&$blnOverrideRoot) {
if (preg_match('@^(http://|https://)@', $args[2])) {
return $args[1] . $args[2] . $args[3];
}

$blnOverrideRoot = true;
return $args[1] . TL_ROOT . '/' . rawurldecode($args[2]) . $args[3];
}, $strBuffer);

if ($blnOverrideRoot) {
$_SERVER['DOCUMENT_ROOT'] = TL_ROOT;
}

// Handle line breaks in preformatted text
$strBuffer = preg_replace_callback('@(<pre.*</pre>)@Us', 'nl2br_callback', $strBuffer);

Expand Down

0 comments on commit 383f41e

Please sign in to comment.