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 |
NodeLocator.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\Helpers;
009
010 use DOMDocument;
011 use DOMXPath;
012
013 abstract class NodeLocator
014 {
015 /**
016 * Return all attributes (literal or generated) that match given regexp
017 *
018 * @param DOMDocument $dom Document
019 * @param string $regexp Regexp
020 * @return DOMNode[] List of DOMNode instances
021 */
022 public static function getAttributesByRegexp(DOMDocument $dom, $regexp)
023 {
024 return self::getNodesByRegexp($dom, $regexp, 'attribute');
025 }
026
027 /**
028 * Return all DOMNodes whose content is CSS
029 *
030 * @param DOMDocument $dom Document
031 * @return DOMNode[] List of DOMNode instances
032 */
033 public static function getCSSNodes(DOMDocument $dom)
034 {
035 $regexp = '/^(?:color|style)$/i';
036 $nodes = array_merge(
037 self::getAttributesByRegexp($dom, $regexp),
038 self::getElementsByRegexp($dom, '/^style$/i')
039 );
040
041 return $nodes;
042 }
043
044 /**
045 * Return all elements (literal or generated) that match given regexp
046 *
047 * @param DOMDocument $dom Document
048 * @param string $regexp Regexp
049 * @return DOMNode[] List of DOMNode instances
050 */
051 public static function getElementsByRegexp(DOMDocument $dom, $regexp)
052 {
053 return self::getNodesByRegexp($dom, $regexp, 'element');
054 }
055
056 /**
057 * Return all DOMNodes whose content is JavaScript
058 *
059 * @param DOMDocument $dom Document
060 * @return DOMNode[] List of DOMNode instances
061 */
062 public static function getJSNodes(DOMDocument $dom)
063 {
064 $regexp = '/^(?:data-s9e-livepreview-)?on/i';
065 $nodes = array_merge(
066 self::getAttributesByRegexp($dom, $regexp),
067 self::getElementsByRegexp($dom, '/^script$/i')
068 );
069
070 return $nodes;
071 }
072
073 /**
074 * Return all elements (literal or generated) that match given regexp
075 *
076 * Will return all <param/> descendants of <object/> and all attributes of <embed/> whose name
077 * matches given regexp. This method will NOT catch <param/> elements whose 'name' attribute is
078 * set via an <xsl:attribute/>
079 *
080 * @param DOMDocument $dom Document
081 * @param string $regexp
082 * @return DOMNode[] List of DOMNode instances
083 */
084 public static function getObjectParamsByRegexp(DOMDocument $dom, $regexp)
085 {
086 $xpath = new DOMXPath($dom);
087 $nodes = [];
088
089 // Collect attributes from <embed/> elements
090 foreach (self::getAttributesByRegexp($dom, $regexp) as $attribute)
091 {
092 if ($attribute->nodeType === XML_ATTRIBUTE_NODE)
093 {
094 if (strtolower($attribute->parentNode->localName) === 'embed')
095 {
096 $nodes[] = $attribute;
097 }
098 }
099 elseif ($xpath->evaluate('count(ancestor::embed)', $attribute))
100 {
101 // Assuming <xsl:attribute/> or <xsl:copy-of/>
102 $nodes[] = $attribute;
103 }
104 }
105
106 // Collect <param/> descendants of <object/> elements
107 foreach ($xpath->query('//object//param') as $param)
108 {
109 if (preg_match($regexp, $param->getAttribute('name')))
110 {
111 $nodes[] = $param;
112 }
113 }
114
115 return $nodes;
116 }
117
118 /**
119 * Return all DOMNodes whose content is an URL
120 *
121 * NOTE: it will also return HTML4 nodes whose content is an URI
122 *
123 * @param DOMDocument $dom Document
124 * @return DOMNode[] List of DOMNode instances
125 */
126 public static function getURLNodes(DOMDocument $dom)
127 {
128 $regexp = '/(?:^(?:action|background|c(?:ite|lassid|odebase)|data|formaction|href|i(?:con|tem(?:id|prop|type))|longdesc|manifest|p(?:ing|luginspage|oster|rofile)|usemap)|src)$/i';
129 $nodes = self::getAttributesByRegexp($dom, $regexp);
130
131 /**
132 * @link http://helpx.adobe.com/flash/kb/object-tag-syntax-flash-professional.html
133 * @link http://www.sitepoint.com/control-internet-explorer/
134 */
135 foreach (self::getObjectParamsByRegexp($dom, '/^(?:dataurl|movie)$/i') as $param)
136 {
137 $node = $param->getAttributeNode('value');
138 if ($node)
139 {
140 $nodes[] = $node;
141 }
142 }
143
144 return $nodes;
145 }
146
147 /**
148 * Return all nodes of given type
149 *
150 * @param DOMDocument $dom Owner document
151 * @param string $type Node type ('element' or 'attribute')
152 * @return DOMNode[] List of DOMNode instances
153 */
154 protected static function getNodes(DOMDocument $dom, $type)
155 {
156 $nodes = [];
157 $prefix = ($type === 'attribute') ? '@' : '';
158 $xpath = new DOMXPath($dom);
159
160 // Get natural nodes
161 foreach ($xpath->query('//' . $prefix . '*') as $node)
162 {
163 $nodes[] = [$node, $node->nodeName];
164 }
165
166 // Get XSL-generated nodes
167 foreach ($xpath->query('//xsl:' . $type) as $node)
168 {
169 $nodes[] = [$node, $node->getAttribute('name')];
170 }
171
172 // Get xsl:copy-of nodes
173 foreach ($xpath->query('//xsl:copy-of') as $node)
174 {
175 if (preg_match('/^' . $prefix . '(\\w+)$/', $node->getAttribute('select'), $m))
176 {
177 $nodes[] = [$node, $m[1]];
178 }
179 }
180
181 return $nodes;
182 }
183
184 /**
185 * Return all nodes (literal or generated) that match given regexp
186 *
187 * @param DOMDocument $dom Owner document
188 * @param string $regexp Regexp
189 * @param string $type Node type ('element' or 'attribute')
190 * @return DOMNode[] List of DOMNode instances
191 */
192 protected static function getNodesByRegexp(DOMDocument $dom, $regexp, $type)
193 {
194 $nodes = [];
195 foreach (self::getNodes($dom, $type) as list($node, $name))
196 {
197 if (preg_match($regexp, $name))
198 {
199 $nodes[] = $node;
200 }
201 }
202
203 return $nodes;
204 }
205 }