templateGenerators['choose'] = new Choose($this); $this->templateGenerators['flash'] = new Flash; $this->templateGenerators['iframe'] = new Iframe; } /** * Generate and return a template for given site * * @param string $siteId * @param array $siteConfig * @return string */ public function build($siteId, array $siteConfig) { return $this->addSiteId($siteId, $this->getTemplate($siteConfig)); } /** * Generate and return a template based on given config * * @param array $config * @return string */ public function getTemplate(array $config) { foreach ($this->templateGenerators as $type => $generator) { if (isset($config[$type])) { return $generator->getTemplate($config[$type]); } } return ''; } /** * Added the siteId value to given template in a data-s9e-mediaembed attribute * * @param string $siteId Site ID * @param string $template Original template * @return string Modified template */ protected function addSiteId($siteId, $template) { $dom = TemplateLoader::load($template); $xpath = new DOMXPath($dom); $query = '//*[namespace-uri() != "' . TemplateLoader::XMLNS_XSL . '"]' . '[not(ancestor::*[namespace-uri() != "' . TemplateLoader::XMLNS_XSL . '"])]'; foreach ($xpath->query($query) as $element) { $element->setAttribute('data-s9e-mediaembed', $siteId); } return TemplateLoader::save($dom); } }