288 static $tagsWithoutClose = array(
'INPUT'=>1,
'IMG'=>1,
'BR'=>1,
'HR'=>1,
'META'=>1,
'AREA'=>1,
'BASE'=>1,
'COL'=>1,
'EMBED'=>1,
'KEYGEN'=>1,
'LINK'=>1,
'PARAM'=>1,
'SOURCE'=>1,
'TRACK'=>1,
'WBR'=>1);
289 $tagsCantHaveNestedTags = array();
295 $commentClosePosition = mb_strpos($tag,
'-->');
296 if($commentClosePosition !==
false)
298 $clean = mb_substr($tag, 0, $commentClosePosition);
299 $parentNode->setNodeValue($parentNode->
getNodeValue() . $clean);
300 $parentNode->bxNodeFoundCloseTag =
true;
302 $tag = mb_substr($tag, $commentClosePosition + 3);
314 $parentNode->setNodeValue($parentNode->
getNodeValue() . $tag);
318 elseif(in_array($parentNode->
getNodeName(), $this->tagsMustBeClosed))
320 if(mb_strtoupper(mb_substr($tag, -9)) ==
'</'.$parentNode->
getNodeName().
'>')
322 $parentNode->bxNodeFoundCloseTag =
true;
330 $parentNode->
appendChild($document->createTextNode($tag));
334 $firstChild->setNodeValue($firstChild->getNodeValue() . $tag);
337 $parentNode->bxNodeFoundCloseTag =
false;
342 if(mb_substr($tag, 0, 2) ===
'</')
346 $cleaned = mb_strtoupper(mb_substr($tag, 2, -mb_strlen(
'>')));
347 $searchableNode = $parentNode;
348 $isSearchableNodeFound =
false;
350 $unclosedNodes = array();
353 if(!$searchableNode->bxNodeFoundCloseTag)
355 $unclosedNodes[] = $searchableNode;
358 if($searchableNode->getNodeName() === $cleaned)
360 $isSearchableNodeFound =
true;
363 }
while($searchableNode = $searchableNode->getParentNode());
365 if($isSearchableNodeFound)
367 foreach($unclosedNodes as $unclosedNode)
370 if(in_array($unclosedNode->getNodeName(), $tagsCantHaveNestedTags))
372 if($unclosedNode->hasChildNodes())
374 foreach ($unclosedNode->getChildNodesArray() as $childNode)
376 $unclosedNode->getParentNode()->appendChild($unclosedNode->removeChild($childNode));
381 $unclosedNode->bxNodeFoundCloseTag =
true;
384 return $searchableNode->getParentNode();
390 throw new DomException(
'Parser error. Find close tag, but can not find open tag ' . $cleaned);
402 elseif(mb_substr($tag, 0, 4) ===
'<!--')
405 $cleaned = mb_substr($tag, 4);
406 if(mb_substr($tag, -3) ==
'-->')
408 $cleaned = mb_substr($cleaned, 0, -3);
409 $parentNode->bxNodeFoundCloseTag =
true;
413 $isSingleTag =
false;
418 $node = $document->createComment($cleaned);
420 elseif(mb_substr($tag, 0, 1) ===
'<')
424 if(mb_substr($tag, -2) ===
'/>')
427 $cleaned = mb_substr($tag, 1, -2);
428 $bxNodeWithCloseTag =
false;
432 $cleaned = mb_substr($tag, 1, -1);
433 $isSingleTag =
false;
434 $bxNodeWithCloseTag =
true;
439 $isDocType = mb_substr($list[
'NAME'], 0, mb_strlen(
'!DOCTYPE')) ===
'!DOCTYPE';
441 if(isset($tagsWithoutClose[$list[
'NAME']]) || $isDocType)
443 $bxNodeWithCloseTag =
false;
454 $node = $document->createElement($list[
'NAME']);
455 foreach($list[
'ATTRIBUTES'] as $attrName => $attrValue)
457 $nodeAttr = $document->createAttribute($attrName, $attrValue);
458 $node->setAttributeNode($nodeAttr);
460 $node->bxNodeWithCloseTag = $bxNodeWithCloseTag;
466 $cleaned = html_entity_decode($tag, ENT_QUOTES, (defined(
"BX_UTF") ?
"UTF-8" :
"ISO-8859-1"));
467 $node = $document->createTextNode($cleaned);
470 if($node && $parentNode)
498 if(preg_match_all(
'/(<\?[\W\w\n]*?\?>)/i', $html, $matches, PREG_SET_ORDER) && is_array($matches))
500 $prefix =
'BX_DOM_DOCUMENT_PHP_SLICE_PLACEHOLDER_' . $this->currentObjectNumber .
'_';
501 foreach($matches as $key => $value)
503 $this->storedItemCounter++;
504 $this->storedPHP[
'<!--' . $prefix . $this->storedItemCounter .
'-->'] = $value[0];
507 $replaceFrom = array_values($this->storedPHP);
508 $replaceTo = array_keys($this->storedPHP);
510 $html = str_replace($replaceFrom, $replaceTo, $html);