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 |
UninlineAttributes.php
001 <?php
002
003 /**
004 * @package s9e\TextFormatter
005 * @copyright Copyright (c) 2010-2022 The s9e authors
006 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
007 */
008 namespace s9e\TextFormatter\Configurator\TemplateNormalizations;
009
010 use DOMAttr;
011 use DOMElement;
012 use s9e\TextFormatter\Configurator\Helpers\AVTHelper;
013
014 /**
015 * Uninline element attributes
016 *
017 * Will replace
018 * <a href="{@url}">...</a>
019 * with
020 * <a><xsl:attribute name="href"><xsl:value-of select="@url"/></xsl:attribute>...</a>
021 */
022 class UninlineAttributes extends AbstractNormalization
023 {
024 /**
025 * {@inheritdoc}
026 */
027 protected $queries = ['//*[namespace-uri() != $XSL][@*]'];
028
029 /**
030 * {@inheritdoc}
031 */
032 protected function normalizeElement(DOMElement $element)
033 {
034 // Using a document fragment improves performance with multiple attributes
035 $fragment = $element->ownerDocument->createDocumentFragment();
036 while ($element->attributes->length > 0)
037 {
038 $fragment->appendChild($this->uninlineAttribute($element->attributes->item(0)));
039 }
040 $element->insertBefore($fragment, $element->firstChild);
041 }
042
043 /**
044 * Remove an attribute from its parent element and return its content as an xsl:attribute
045 *
046 * @param DOMAttr $attribute Attribute node
047 * @return DOMElement xsl:attribute element
048 */
049 protected function uninlineAttribute(DOMAttr $attribute)
050 {
051 $xslAttribute = (strpos($attribute->value, '{') === false)
052 ? $this->uninlineStaticAttribute($attribute)
053 : $this->uninlineDynamicAttribute($attribute);
054
055 // Set the xsl:attribute element's name
056 $xslAttribute->setAttribute('name', $attribute->nodeName);
057
058 // Remove the attribute from its parent element
059 $attribute->parentNode->removeAttributeNode($attribute);
060
061 return $xslAttribute;
062 }
063
064 /**
065 * Uninline an AVT-style attribute
066 *
067 * @param DOMAttr $attribute Attribute node
068 * @return DOMElement xsl:attribute element
069 */
070 protected function uninlineDynamicAttribute(DOMAttr $attribute)
071 {
072 $xslAttribute = $this->createElement('xsl:attribute');
073
074 // Build the content of the xsl:attribute element
075 foreach (AVTHelper::parse($attribute->value) as list($type, $content))
076 {
077 if ($type === 'expression')
078 {
079 $childNode = $this->createElement('xsl:value-of');
080 $childNode->setAttribute('select', $content);
081 }
082 else
083 {
084 $childNode = $this->createText($content);
085 }
086
087 $xslAttribute->appendChild($childNode);
088 }
089
090 return $xslAttribute;
091 }
092
093 /**
094 * Uninline an attribute with a static value
095 *
096 * @param DOMAttr $attribute Attribute node
097 * @return DOMElement xsl:attribute element
098 */
099 protected function uninlineStaticAttribute(DOMAttr $attribute)
100 {
101 return $this->createElement('xsl:attribute', str_replace('}}', '}', $attribute->value));
102 }
103 }