function filterDOM(PHPTAL_Dom_Element $element) { $defs = PHPTAL_Dom_Defs::getInstance(); foreach ($element->childNodes as $node) { if ($node instanceof PHPTAL_Dom_Comment) { if ($defs->isCDATAElementInHTML($element->getNamespaceURI(), $element->getLocalName())) { $textNode = new PHPTAL_Dom_CDATASection($node->getValueEscaped(), $node->getEncoding()); $node->parentNode->replaceChild($textNode, $node); } else { $node->parentNode->removeChild($node); } } else { if ($node instanceof PHPTAL_Dom_Element) { $this->filterDOM($node); } } } }
protected function isSpaceSensitiveInXHTML(PHPTAL_Dom_Element $element) { $ln = $element->getLocalName(); return ($ln === 'script' || $ln === 'pre' || $ln === 'textarea') && ($element->getNamespaceURI() === 'http://www.w3.org/1999/xhtml' || $element->getNamespaceURI() === ''); }
/** * Allows <script> to be normalize. Love your semicolons! (or use CDATA) */ private function isSpaceSensitiveInXHTML(PHPTAL_Dom_Element $element) { return ($element->getLocalName() === 'pre' || $element->getLocalName() === 'textarea') && ($element->getNamespaceURI() === 'http://www.w3.org/1999/xhtml' || $element->getNamespaceURI() === ''); }
/** * HTML5 doesn't care about boilerplate */ private function elementSpecificOptimizations(PHPTAL_Dom_Element $element) { if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml' && $element->getNamespaceURI() !== '') { return; } if ($this->getPHPTAL()->getOutputMode() !== PHPTAL::HTML5) { return; } // <meta charset> if ('meta' === $element->getLocalName() && $element->getAttributeNS('', 'http-equiv') === 'Content-Type') { $element->removeAttributeNS('', 'http-equiv'); $element->removeAttributeNS('', 'content'); $element->setAttributeNS('', 'charset', strtolower($this->getPHPTAL()->getEncoding())); } elseif ('link' === $element->getLocalName() && $element->getAttributeNS('', 'rel') === 'stylesheet' || 'style' === $element->getLocalName()) { // There's only one type of stylesheets that works. $element->removeAttributeNS('', 'type'); } elseif ('script' === $element->getLocalName()) { $element->removeAttributeNS('', 'language'); // Only remove type that matches default. E4X, vbscript, coffeescript, etc. must be preserved $type = $element->getAttributeNS('', 'type'); $is_std = preg_match('/^(?:text|application)\\/(?:ecma|java)script(\\s*;\\s*charset\\s*=\\s*[^;]*)?$/', $type); // Remote scripts should have type specified in HTTP headers. if ($is_std || $element->getAttributeNS('', 'src')) { $element->removeAttributeNS('', 'type'); } } }