Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
TemplateBuilder.php
01 <?php
02
03 /**
04 * @package s9e\TextFormatter
05 * @copyright Copyright (c) 2010-2022 The s9e authors
06 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
07 */
08 namespace s9e\TextFormatter\Plugins\MediaEmbed\Configurator;
09
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 }