private function HtmlAssetInliner::embedLocalJs in TMGMT Translator Smartling 8
1 call to HtmlAssetInliner::embedLocalJs()
- HtmlAssetInliner::getCompletePage in src/
Context/ HtmlAssetInliner.php - Gets complete page data and returns generated string
File
- src/
Context/ HtmlAssetInliner.php, line 489
Class
Namespace
Drupal\tmgmt_smartling\ContextCode
private function embedLocalJs() {
//<script src="/sites/default/files/js/js_BKcMdIbOMdbTdLn9dkUq3KCJfIKKo2SvKoQ1AnB8D-g.js"></script>
//<script src="/core/assets/vendor/modernizr/modernizr.min.js?v=3.3.1"></script>
$js = [];
preg_match_all('/<script src="([^"]+)"><\\/script>/iU', $this->html, $js);
foreach ($js[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);
$this->html = str_replace($js[0][$id], "<script>\n {$file_content} \n</script>", $this->html);
}
}