/** * Embeds the css stylesheets to the html email and normalizes the url() css tag * In addition .less files are compiled, modified and embedded to html email * * @static * @param $string - the content to modify * @param null | Document $document * @return string * @throws Exception - if something else than a document is passed */ public static function embedAndModifyCss($string, $document = null) { if ($document && $document instanceof Document == false) { throw new Exception('$document has to be an instance of Document'); } //matches all <link> Tags preg_match_all("@<link.*?href\\s*=\\s*[\"']([^http].*?)[\"'].*?(/?>|</\\s*link>)@is", $string, $matches); if (!empty($matches[0])) { foreach ($matches[0] as $key => $value) { $fullMatch = $matches[0][$key]; $path = $matches[1][$key]; $fileInfo = self::getNormalizedFileInfo($path, $document); if (in_array($fileInfo['fileExtension'], array('css', 'less'))) { if (is_readable($fileInfo['filePathNormalized'])) { if ($fileInfo['fileExtension'] == 'css') { $fileContent = file_get_contents($fileInfo['filePathNormalized']); } else { $fileContent = Pimcore_Tool_Less::compile($fileInfo['filePathNormalized']); $fileContent = str_replace('/**** compiled with lessphp ****/', '', $fileContent); } if ($fileContent) { $fileContent = self::normalizeCssContent($fileContent, $fileInfo); $string = str_replace($fullMatch, '<style type="text/css">' . $fileContent . '</style>', $string); } } } } } return $string; }
protected function frontend() { $body = $this->getResponse()->getBody(); $body = Pimcore_Tool_Less::processHtml($body); $this->getResponse()->setBody($body); }