protected function addSiteId($siteId, $template) { $dom = TemplateHelper::loadTemplate($template); $xpath = new DOMXPath($dom); $query = '//*[namespace-uri() != "' . TemplateHelper::XMLNS_XSL . '"][not(ancestor::*[namespace-uri() != "' . TemplateHelper::XMLNS_XSL . '"])]'; foreach ($xpath->query($query) as $element) { $element->setAttribute('data-s9e-mediaembed', $siteId); } return TemplateHelper::saveTemplate($dom); }
/** * @testdox Works * @dataProvider getData */ public function test($template, $expected, $preserveWhiteSpace = null) { if ($expected instanceof Exception) { $this->setExpectedException(get_class($expected), $expected->getMessage()); } $xml = '<xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' . $template . '</xsl:template>'; $dom = new DOMDocument(); $dom->loadXML($xml); $className = preg_replace('/.*\\\\(.*?)Test$/', 's9e\\TextFormatter\\Configurator\\TemplateNormalizations\\\\$1', get_class($this)); $normalizer = new $className(); $normalizer->normalize($dom->documentElement); $this->assertSame($expected, TemplateHelper::saveTemplate($dom)); }
public function saveChanges() { $this->template->setContent(TemplateHelper::saveTemplate($this)); }
public function normalizeValue($value) { return TemplateHelper::saveTemplate(TemplateHelper::loadTemplate($value)); }
/** * @testdox saveTemplate() correctly handles '<ul><li>one<li>two</ul>' */ public function testSaveHTML() { $html = '<ul><li>one<li>two</ul>'; $xml = '<ul><li>one</li><li>two</li></ul>'; $this->assertSame($xml, TemplateHelper::saveTemplate(TemplateHelper::loadTemplate($html))); }
/** * Normalize a template * * @param string $template Original template * @return string Normalized template */ public function normalizeTemplate($template) { $dom = TemplateHelper::loadTemplate($template); // We'll keep track of what normalizations have been applied $applied = []; // Apply all the normalizations until no more change is made or we've reached the maximum // number of loops $loops = 5; do { $old = $template; foreach ($this->collection as $k => $normalization) { if (isset($applied[$k]) && !empty($normalization->onlyOnce)) { continue; } $normalization->normalize($dom->documentElement); $applied[$k] = 1; } $template = TemplateHelper::saveTemplate($dom); } while (--$loops && $template !== $old); return $template; }