/** * Generate and return document template * @return string */ protected function generateTemplate(IsotopeProductCollection $objCollection, array $arrTokens) { $objTemplate = new \Isotope\Template($this->documentTpl); $objTemplate->setData($this->arrData); $objTemplate->title = \String::parseSimpleTokens($this->documentTitle, $arrTokens); $objTemplate->collection = $objCollection; // Render the collection $objCollectionTemplate = new \Isotope\Template($this->collectionTpl); $objCollection->addToTemplate($objCollectionTemplate, array('gallery' => $this->gallery, 'sorting' => $objCollection->getItemsSortingCallable($this->orderCollectionBy))); $objTemplate->products = $objCollectionTemplate->parse(); // Generate template and fix PDF issues, see Contao's ModuleArticle $strBuffer = Haste::getInstance()->call('replaceInsertTags', array($objTemplate->parse(), false)); $strBuffer = html_entity_decode($strBuffer, ENT_QUOTES, $GLOBALS['TL_CONFIG']['characterSet']); $strBuffer = \Controller::convertRelativeUrls($strBuffer, '', true); // Remove form elements and JavaScript links $arrSearch = array('@<form.*</form>@Us', '@<a [^>]*href="[^"]*javascript:[^>]+>.*</a>@Us'); $strBuffer = preg_replace($arrSearch, '', $strBuffer); // URL decode image paths (see contao/core#6411) // Make image paths absolute $strBuffer = preg_replace_callback('@(src=")([^"]+)(")@', function ($args) { if (preg_match('@^(http://|https://)@', $args[2])) { return $args[2]; } return $args[1] . TL_ROOT . '/' . rawurldecode($args[2]) . $args[3]; }, $strBuffer); // Handle line breaks in preformatted text $strBuffer = preg_replace_callback('@(<pre.*</pre>)@Us', 'nl2br_callback', $strBuffer); // Default PDF export using TCPDF $arrSearch = array('@<span style="text-decoration: ?underline;?">(.*)</span>@Us', '@(<img[^>]+>)@', '@(<div[^>]+block[^>]+>)@', '@[\\n\\r\\t]+@', '@<br( /)?><div class="mod_article@', '@href="([^"]+)(pdf=[0-9]*(&|&)?)([^"]*)"@'); $arrReplace = array('<u>$1</u>', '<br>$1', '<br>$1', ' ', '<div class="mod_article', 'href="$1$4"'); $strBuffer = preg_replace($arrSearch, $arrReplace, $strBuffer); return $strBuffer; }