|
|
|
@ -45,19 +45,31 @@ class JSLikeHTMLElement extends \DOMElement |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function __set($name, $value) |
|
|
|
public function __set($name, $value) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($name === 'innerHTML') { |
|
|
|
if ($name !== 'innerHTML') { |
|
|
|
|
|
|
|
$trace = debug_backtrace(); |
|
|
|
|
|
|
|
trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// first, empty the element |
|
|
|
// first, empty the element |
|
|
|
for ($x = $this->childNodes->length - 1; $x >= 0; --$x) { |
|
|
|
for ($x = $this->childNodes->length - 1; $x >= 0; --$x) { |
|
|
|
$this->removeChild($this->childNodes->item($x)); |
|
|
|
$this->removeChild($this->childNodes->item($x)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// $value holds our new inner HTML |
|
|
|
// $value holds our new inner HTML |
|
|
|
if ($value !== '') { |
|
|
|
$value = trim($value); |
|
|
|
|
|
|
|
if (empty($value)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ensure bad entity won't generate warning |
|
|
|
|
|
|
|
$previousError = libxml_use_internal_errors(true); |
|
|
|
|
|
|
|
|
|
|
|
$f = $this->ownerDocument->createDocumentFragment(); |
|
|
|
$f = $this->ownerDocument->createDocumentFragment(); |
|
|
|
|
|
|
|
|
|
|
|
// appendXML() expects well-formed markup (XHTML) |
|
|
|
// appendXML() expects well-formed markup (XHTML) |
|
|
|
// @ to suppress PHP warnings |
|
|
|
$result = $f->appendXML($value); |
|
|
|
$result = @$f->appendXML($value); |
|
|
|
|
|
|
|
if ($result) { |
|
|
|
if ($result) { |
|
|
|
if ($f->hasChildNodes()) { |
|
|
|
if ($f->hasChildNodes()) { |
|
|
|
$this->appendChild($f); |
|
|
|
$this->appendChild($f); |
|
|
|
@ -72,7 +84,7 @@ class JSLikeHTMLElement extends \DOMElement |
|
|
|
// We use it (and suppress the warning) because an HTML fragment will |
|
|
|
// We use it (and suppress the warning) because an HTML fragment will |
|
|
|
// be wrapped around <html><body> tags which we don't really want to keep. |
|
|
|
// be wrapped around <html><body> tags which we don't really want to keep. |
|
|
|
// Note: despite the warning, if loadHTML succeeds it will return true. |
|
|
|
// Note: despite the warning, if loadHTML succeeds it will return true. |
|
|
|
$result = @$f->loadHTML('<htmlfragment>' . $value . '</htmlfragment>'); |
|
|
|
$result = $f->loadHTML('<htmlfragment>' . $value . '</htmlfragment>'); |
|
|
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
if ($result) { |
|
|
|
$import = $f->getElementsByTagName('htmlfragment')->item(0); |
|
|
|
$import = $f->getElementsByTagName('htmlfragment')->item(0); |
|
|
|
@ -81,16 +93,11 @@ class JSLikeHTMLElement extends \DOMElement |
|
|
|
$importedNode = $this->ownerDocument->importNode($child, true); |
|
|
|
$importedNode = $this->ownerDocument->importNode($child, true); |
|
|
|
$this->appendChild($importedNode); |
|
|
|
$this->appendChild($importedNode); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
// oh well, we tried, we really did. :( |
|
|
|
|
|
|
|
// this element is now empty |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
libxml_clear_errors(); |
|
|
|
$trace = debug_backtrace(); |
|
|
|
libxml_use_internal_errors($previousError); |
|
|
|
trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|