1C-Bitrix 25.700.0
node.php
См. документацию.
1<?php
2namespace Bitrix\Main\Web\DOM;
3
4abstract class Node
5{
6 const ELEMENT_NODE = 1;
7 const ATTRIBUTE_NODE = 2;
8 const TEXT_NODE = 3;
11 const ENTITY_NODE = 6;
13 const COMMENT_NODE = 8;
15 const DOCUMENT_NODE = 9;
17 const NOTATION_NODE = 12;
18
19 public static $isNodeListAsArray = true;
20
21 /* @var Document $ownerDocument */
22 protected $ownerDocument = null;
23
24 /* @var string $nodeType*/
25 protected $nodeType = null;
26
27 /* @var string $nodeName*/
28 protected $nodeName = null;
29
30 /* @var string $nodeValue*/
31 protected $nodeValue = null;
32
33 /* @var NodeList $childNodes*/
34 protected $childNodes = null;
35
36 /* @var Node $parentNode*/
37 protected $parentNode = null;
38
39 /* @var null|NamedNodeMap $attributes*/
40 protected $attributes = null;
41
42 /* @var string $textContent*/
43 protected $textContent = null;
44
45 /* @var bool $bxIsAlreadyClosed*/
46 public $bxIsAlreadyClosed = false;
47
48 /* @var bool $bxClosable*/
49 public $bxClosable = true;
50
51 public $bxNodeFoundCloseTag = false;
52
53 public function __construct()
54 {
55 $this->init();
56 }
57
58 protected function init()
59 {
60 if(self::$isNodeListAsArray)
61 {
62 $this->childNodes = array();
63 }
64 else
65 {
66 $this->childNodes = new NodeList;
67 }
68 }
69
70 public function getNodeType()
71 {
72 return $this->nodeType;
73 }
74
75 public function getParentNode()
76 {
77 return $this->parentNode;
78 }
79
80 public function setParentNode(Node $node = null)
81 {
82 $this->parentNode = $node;
83 }
84
85 public function hasAttributes()
86 {
87 if(!$this->attributes)
88 {
89 return false;
90 }
91
92 if(self::$isNodeListAsArray)
93 {
94 return !empty($this->attributes);
95 }
96 else
97 {
98 return $this->attributes->getLength() > 0;
99 }
100 }
101
102 public function getAttributes()
103 {
104 return $this->attributes;
105 }
106
107 public function getNodeName()
108 {
109 return $this->nodeName;
110 }
111
112 public function setNodeName($a)
113 {
114 $this->nodeName = $a;
115 }
116
117 public function getNodeValue()
118 {
119 return $this->nodeValue;
120 }
121
122 public function getTextContent()
123 {
124 return $this->nodeValue;
125 }
126
127 public function getOwnerDocument()
128 {
130 }
131
132 public function setOwnerDocument(Document $owner)
133 {
134 $this->ownerDocument = $owner;
135 }
136
137 public function getFirstChild()
138 {
139 $child = null;
140 foreach($this->getChildNodesArray() as $child)
141 {
142 break;
143 }
144
145 return $child;
146 }
147
148 public function getLastChild()
149 {
150 $child = null;
151 foreach($this->getChildNodesArray() as $child)
152 {
153
154 }
155
156 return $child;
157 }
158
159 public function getPreviousSibling()
160 {
161 $searchableSibling = null;
162 if($this->parentNode)
163 {
164 $previousSibling = null;
165 foreach($this->parentNode->getChildNodesArray() as $sibling)
166 {
167 if($this->isEqual($sibling))
168 {
169 $searchableSibling = $previousSibling;
170 break;
171 }
172
173 $previousSibling = $sibling;
174 }
175 }
176
177 return $searchableSibling;
178 }
179
180 public function getNextSibling()
181 {
182 $searchableSibling = null;
183 if($this->parentNode)
184 {
185 $previousSibling = null;
186 foreach($this->parentNode->getChildNodesArray() as $sibling)
187 {
188 if($this->isEqual($previousSibling))
189 {
190 $searchableSibling = $sibling;
191 break;
192 }
193
194 $previousSibling = $sibling;
195 }
196 }
197
198 return $searchableSibling;
199 }
200
201 /*
202 * @return NodeList|Node[]
203 */
204 public function getChildNodes()
205 {
206 return $this->childNodes;
207 }
208
209 /*
210 * @return Node[]
211 */
212 public function getChildNodesArray()
213 {
214 if(self::$isNodeListAsArray)
215 {
216 return $this->childNodes;
217 }
218 else
219 {
220 return $this->childNodes->get();
221 }
222 }
223
224 public function setChildNodesArray($childList)
225 {
226 if(self::$isNodeListAsArray)
227 {
228 $this->childNodes = $childList;
229 }
230 else
231 {
232 $this->childNodes->set($childList);
233 }
234 }
235
236 public function hasChildNodes()
237 {
238 if(self::$isNodeListAsArray)
239 {
240 return (!empty($this->getChildNodes()));
241 }
242 else
243 {
244 return ($this->getChildNodes()->getLength() > 0);
245 }
246 }
247
248 protected function haveChild($checkingChild)
249 {
250 foreach($this->childNodes as $child)
251 {
252 if($child === $checkingChild)
253 {
254 return true;
255 }
256 }
257
258 return false;
259 }
260
265 public function appendChild(Node $newChild)
266 {
267 $this->insertBefore($newChild);
268 }
269
270 public function insertBefore(Node $newChild, Node $refChild = null, $removeExist = true)
271 {
272 if($newChild->getOwnerDocument() !== $this->getOwnerDocument())
273 {
274 throw new DomException('Node newChild was created from a different document than the one that created this node', DomException::WRONG_DOCUMENT_ERR);
275 }
276
277 if($refChild && !$this->haveChild($refChild))
278 {
279 throw new DomException('Node refChild not found in childList', DomException::NOT_FOUND_ERR);
280 }
281
282 if ($removeExist && $this->haveChild($newChild))
283 {
284 $this->removeChild($newChild);
285 }
286
287
288
289 $childList = $this->getChildNodesArray();
290 if($refChild)
291 {
292 $childListNew = array();
293 foreach($childList as $child)
294 {
295 if($refChild === $child)
296 {
297 $childListNew[] = $newChild;
298 }
299 $childListNew[] = $child;
300 }
301 $childList = $childListNew;
302 }
303 else
304 {
305 $childList[] = $newChild;
306 }
307
308 $this->setChildNodesArray($childList);
309 $newChild->setParentNode($this);
310
311 return $newChild;
312 }
313
314 public function removeChild(Node $oldChild)
315 {
316 $childList = $this->getChildNodesArray();
317 $childListNew = array();
318 $isFound = false;
319 foreach($childList as $child)
320 {
321 if($oldChild !== $child)
322 {
323 $childListNew[] = $child;
324 }
325 else
326 {
327 $isFound = true;
328 }
329 }
330
331 if($isFound)
332 {
333 $this->setChildNodesArray($childListNew);
334 $oldChild->setParentNode(null);
335 }
336 else
337 {
338 throw new DomException('Node not found in childList', DomException::NOT_FOUND_ERR);
339 }
340
341 return $oldChild;
342 }
343
344 public function replaceChild(Node $newChild, Node $oldChild)
345 {
346 throw new DomException('Not implemented');
347 }
348
349 public function isEqual(Node $node = null)
350 {
351 if($node && $node === $this)
352 {
353 return true;
354 }
355
356 return false;
357 }
358
359 public function getOuterHTML()
360 {
361 return $this->getOwnerDocument()->getParser()->getSource($this);
362 }
363
364 public function getInnerHTML()
365 {
366 $html = '';
367 if(!$this->hasChildNodes())
368 {
369 return $html;
370 }
371
372 $parser = $this->getOwnerDocument()->getParser();
373 foreach($this->getChildNodesArray() as $child)
374 {
375 $html .= $parser->getSource($child);
376 }
377
378 return $html;
379 }
380
381 public function setInnerHTML($html)
382 {
383 foreach($this->getChildNodesArray() as $child)
384 {
385 $this->removeChild($child);
386 }
387 $this->getOwnerDocument()->getParser()->parse($html, $this);
388 }
389
394
395 public function querySelectorAll($queryString)
396 {
397 return QueryEngine::getQuerySelectorEngine()->query($queryString, $this);
398 }
399
404 public function querySelector($queryString)
405 {
406 $list = QueryEngine::getQuerySelectorEngine()->query($queryString, $this, 1);
407 return current($list);
408 }
409
410 public function closest($queryString)
411 {
412 $list = $this->getOwnerDocument()->getQueryEngine()->query($queryString, $this, 1, QueryEngine::DIR_UP);
413 return current($list);
414 }
415
416 public function toString()
417 {
418 throw new DomException('Not implemented');
419 }
420
421 public function toArray()
422 {
423 $childNodes = array();
424 if($this->hasChildNodes())
425 {
426 foreach($this->getChildNodesArray() as $child)
427 {
428 /* @var $child Node*/
429 $childNodes[] = $child->toArray();
430 }
431 }
432
433 $attributes = array();
434 if($this->hasAttributes())
435 {
436 foreach($this->getAttributes() as $attr)
437 {
438 /* @var $attr Attr*/
439 $attributes = array_merge($attributes, $attr->toArray());
440 }
441 }
442
443 return array(
444 'nodeType' => $this->nodeType,
445 'nodeName' => $this->nodeName,
446 'textContent' => $this->getTextContent(),
447 'attributesCount' => count($attributes),
448 'attributes' => $attributes,
449 'childNodesCount' => count($childNodes),
450 'childNodes' => $childNodes,
451 );
452 }
453}
const WRONG_DOCUMENT_ERR
Определения domexception.php:9
Определения node.php:5
getNodeValue()
Определения node.php:117
removeChild(Node $oldChild)
Определения node.php:314
__construct()
Определения node.php:53
const DOCUMENT_TYPE_NODE
Определения node.php:16
setChildNodesArray($childList)
Определения node.php:224
closest($queryString)
Определения node.php:410
const ENTITY_NODE
Определения node.php:11
hasAttributes()
Определения node.php:85
setNodeName($a)
Определения node.php:112
const NOTATION_NODE
Определения node.php:17
isEqual(Node $node=null)
Определения node.php:349
const ELEMENT_NODE
Определения node.php:6
getNextSibling()
Определения node.php:180
init()
Определения node.php:58
getLastChild()
Определения node.php:148
querySelector($queryString)
Определения node.php:404
setOwnerDocument(Document $owner)
Определения node.php:132
toString()
Определения node.php:416
getPreviousSibling()
Определения node.php:159
insertBefore(Node $newChild, Node $refChild=null, $removeExist=true)
Определения node.php:270
setParentNode(Node $node=null)
Определения node.php:80
$bxIsAlreadyClosed
Определения node.php:46
toArray()
Определения node.php:421
const DOCUMENT_NODE
Определения node.php:15
$bxClosable
Определения node.php:49
const ENTITY_REFERENCE_NODE
Определения node.php:10
$nodeName
Определения node.php:28
const CDATA_SECTION_NODE
Определения node.php:9
$parentNode
Определения node.php:37
getChildNodesArray()
Определения node.php:212
$bxNodeFoundCloseTag
Определения node.php:51
$childNodes
Определения node.php:34
const ATTRIBUTE_NODE
Определения node.php:7
$nodeType
Определения node.php:25
getParentNode()
Определения node.php:75
const TEXT_NODE
Определения node.php:8
querySelectorAll($queryString)
Определения node.php:395
getInnerHTML()
Определения node.php:364
haveChild($checkingChild)
Определения node.php:248
$nodeValue
Определения node.php:31
getOwnerDocument()
Определения node.php:127
static $isNodeListAsArray
Определения node.php:19
const PROCESSING_INSTRUCTION_NODE
Определения node.php:12
$ownerDocument
Определения node.php:22
const DOCUMENT_FRAGMENT_NODE
Определения node.php:14
appendChild(Node $newChild)
Определения node.php:265
$attributes
Определения node.php:40
replaceChild(Node $newChild, Node $oldChild)
Определения node.php:344
getFirstChild()
Определения node.php:137
$textContent
Определения node.php:43
setInnerHTML($html)
Определения node.php:381
getNodeName()
Определения node.php:107
getTextContent()
Определения node.php:122
hasChildNodes()
Определения node.php:236
getOuterHTML()
Определения node.php:359
getNodeType()
Определения node.php:70
getChildNodes()
Определения node.php:204
getAttributes()
Определения node.php:102
const COMMENT_NODE
Определения node.php:13
static getQuerySelectorEngine()
Определения queryengine.php:27
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
else $a
Определения template.php:137