/**
* @param $body
* @return mixed
*/
public static function processHtml($body)
{
$processedPaths = array();
preg_match_all("@\\<link[^>]*(rel=\"stylesheet/less\")[^>]*\\>@msUi", $body, $matches);
if (is_array($matches)) {
foreach ($matches[0] as $tag) {
preg_match("/href=\"([^\"]+)*\"/", $tag, $href);
if (array_key_exists(1, $href) && !empty($href[1])) {
$source = $href[1];
$source = preg_replace("/\\?_dc=[\\d]+/", "", $source);
if (is_file(PIMCORE_ASSET_DIRECTORY . $source)) {
$path = PIMCORE_ASSET_DIRECTORY . $source;
} else {
if (is_file(PIMCORE_DOCUMENT_ROOT . $source)) {
$path = PIMCORE_DOCUMENT_ROOT . $source;
}
}
// add the same file only one time
if (in_array($path, $processedPaths)) {
continue;
}
$newFile = PIMCORE_TEMPORARY_DIRECTORY . "/less___" . File::getValidFilename(str_replace(".less", "", $source)) . "-" . filemtime($path) . ".css";
if (!is_file($newFile)) {
$compiledContent = self::compile($path, $source);
File::put($newFile, $compiledContent);
}
$body = str_replace($tag, str_replace("stylesheet/less", "stylesheet", str_replace($source, str_replace(PIMCORE_DOCUMENT_ROOT, "", $newFile), $tag)), $body);
}
}
}
return $body;
}