private function HtmlAssetInliner::removeUseless in TMGMT Translator Smartling 8
Removes <link>, <meta> and <script> tags from generated page
File
- src/
Context/ HtmlAssetInliner.php, line 226
Class
Namespace
Drupal\tmgmt_smartling\ContextCode
private function removeUseless($keepjs = TRUE) {
# fix showing up of garbage characters
$this->html = mb_convert_encoding($this->html, 'HTML-ENTITIES', 'UTF-8');
$tags = $this
->getTags('//meta | //link | //script');
$tagsLength = $tags->length;
# get all <link>, <meta> and <script> tags and remove them
for ($i = 0; $i < $tagsLength; $i++) {
$tag = $tags
->item($i);
# delete only external scripts
if (strtolower($tag->nodeName) === 'script') {
if ($keepjs) {
if ($tag
->getAttribute('src') !== '') {
$tag->parentNode
->removeChild($tag);
}
}
else {
$tag->parentNode
->removeChild($tag);
}
}
elseif (strtolower($tag->nodeName) === 'meta') {
# keep the charset meta
if (stripos($tag
->getAttribute('content'), 'charset') === FALSE) {
$tag->parentNode
->removeChild($tag);
}
}
else {
$tag->parentNode
->removeChild($tag);
}
}
$this->html = $this->dom
->saveHTML();
}