private function HtmlAssetInliner::embedLocalCss in TMGMT Translator Smartling 8
1 call to HtmlAssetInliner::embedLocalCss()
- HtmlAssetInliner::getCompletePage in src/Context/HtmlAssetInliner.php
- Gets complete page data and returns generated string
File
- src/Context/HtmlAssetInliner.php, line 416
Class
- HtmlAssetInliner
Namespace
Drupal\tmgmt_smartling\Context
Code
private function embedLocalCss() {
$css = [];
preg_match_all('/<link rel="stylesheet" href="([^"]+)\\?.*" media="([a-zA-Z0-9]*)" \\/>/iU', $this->html, $css);
foreach ($css[1] as $id => $filename) {
if (strpos($filename, '?') !== FALSE) {
$fil_splt = explode('?', $filename);
$filename = reset($fil_splt);
}
$path = DRUPAL_ROOT . $filename;
if (!file_exists($path)) {
continue;
}
$file_content = file_get_contents($path);
$file_content = $this
->embedCssImages($file_content, $path);
$this->html = str_replace($css[0][$id], "<style media='{$css[2][$id]}'>\n {$file_content} \n</style>", $this->html);
}
$css = [];
preg_match_all('/@import url\\("([^"]+)"\\);/iU', $this->html, $css);
foreach ($css[1] as $id => $filename) {
if (strpos($filename, '?') !== FALSE) {
$fil_splt = explode('?', $filename);
$filename = reset($fil_splt);
}
$path = DRUPAL_ROOT . $filename;
if (!file_exists($path)) {
continue;
}
$file_content = file_get_contents($path);
$file_content = $this
->embedCssImages($file_content, $path);
$this->html = str_replace($css[0][$id], "\n\n {$file_content} \n\n", $this->html);
}
}