templateGenerators['choose'] = new Choose($this); $this->templateGenerators['flash'] = new Flash; $this->templateGenerators['iframe'] = new Iframe; } public function build($siteId, array $siteConfig) { return $this->addSiteId($siteId, $this->getTemplate($siteConfig)); } public function getTemplate(array $config) { foreach ($this->templateGenerators as $type => $generator) if (isset($config[$type])) return $generator->getTemplate($config[$type]); return ''; } 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); } }