[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package s9e\TextFormatter 5 * @copyright Copyright (c) 2010-2022 The s9e authors 6 * @license http://www.opensource.org/licenses/mit-license.php The MIT License 7 */ 8 namespace s9e\TextFormatter\Plugins\MediaEmbed\Configurator; 9 10 use DOMXPath; 11 use s9e\TextFormatter\Configurator\Helpers\TemplateLoader; 12 use s9e\TextFormatter\Plugins\MediaEmbed\Configurator\TemplateGenerators\Choose; 13 use s9e\TextFormatter\Plugins\MediaEmbed\Configurator\TemplateGenerators\Flash; 14 use s9e\TextFormatter\Plugins\MediaEmbed\Configurator\TemplateGenerators\Iframe; 15 16 class TemplateBuilder 17 { 18 /** 19 * @var array Generator names as keys, generators as values 20 */ 21 protected $templateGenerators = []; 22 23 /** 24 * Constructor 25 */ 26 public function __construct() 27 { 28 $this->templateGenerators['choose'] = new Choose($this); 29 $this->templateGenerators['flash'] = new Flash; 30 $this->templateGenerators['iframe'] = new Iframe; 31 } 32 33 /** 34 * Generate and return a template for given site 35 * 36 * @param string $siteId 37 * @param array $siteConfig 38 * @return string 39 */ 40 public function build($siteId, array $siteConfig) 41 { 42 return $this->addSiteId($siteId, $this->getTemplate($siteConfig)); 43 } 44 45 /** 46 * Generate and return a template based on given config 47 * 48 * @param array $config 49 * @return string 50 */ 51 public function getTemplate(array $config) 52 { 53 foreach ($this->templateGenerators as $type => $generator) 54 { 55 if (isset($config[$type])) 56 { 57 return $generator->getTemplate($config[$type]); 58 } 59 } 60 61 return ''; 62 } 63 64 /** 65 * Added the siteId value to given template in a data-s9e-mediaembed attribute 66 * 67 * @param string $siteId Site ID 68 * @param string $template Original template 69 * @return string Modified template 70 */ 71 protected function addSiteId($siteId, $template) 72 { 73 $dom = TemplateLoader::load($template); 74 $xpath = new DOMXPath($dom); 75 $query = '//*[namespace-uri() != "' . TemplateLoader::XMLNS_XSL . '"]' 76 . '[not(ancestor::*[namespace-uri() != "' . TemplateLoader::XMLNS_XSL . '"])]'; 77 foreach ($xpath->query($query) as $element) 78 { 79 $element->setAttribute('data-s9e-mediaembed', $siteId); 80 } 81 82 return TemplateLoader::save($dom); 83 } 84 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |