fix of issue #619 and other similar, error in JSLikeHTMLElement: node no longer exists.

This commit is contained in:
Maryana Rozhankivska 2014-07-09 16:50:52 +03:00
parent 4247b37551
commit cc1ec61b85

17
inc/3rdparty/libraries/readability/Readability.php vendored Normal file → Executable file
View file

@ -679,6 +679,7 @@ class Readability
} else { } else {
$topCandidate->innerHTML = $page->documentElement->innerHTML; $topCandidate->innerHTML = $page->documentElement->innerHTML;
$page->documentElement->innerHTML = ''; $page->documentElement->innerHTML = '';
$this->reinitBody();
$page->documentElement->appendChild($topCandidate); $page->documentElement->appendChild($topCandidate);
} }
} else { } else {
@ -794,8 +795,7 @@ class Readability
{ {
// TODO: find out why element disappears sometimes, e.g. for this URL http://www.businessinsider.com/6-hedge-fund-etfs-for-average-investors-2011-7 // TODO: find out why element disappears sometimes, e.g. for this URL http://www.businessinsider.com/6-hedge-fund-etfs-for-average-investors-2011-7
// in the meantime, we check and create an empty element if it's not there. // in the meantime, we check and create an empty element if it's not there.
if (!isset($this->body->childNodes)) $this->body = $this->dom->createElement('body'); $this->reinitBody();
$this->body->innerHTML = $this->bodyCache;
if ($this->flagIsActive(self::FLAG_STRIP_UNLIKELYS)) { if ($this->flagIsActive(self::FLAG_STRIP_UNLIKELYS)) {
$this->removeFlag(self::FLAG_STRIP_UNLIKELYS); $this->removeFlag(self::FLAG_STRIP_UNLIKELYS);
@ -1134,5 +1134,18 @@ class Readability
public function removeFlag($flag) { public function removeFlag($flag) {
$this->flags = $this->flags & ~$flag; $this->flags = $this->flags & ~$flag;
} }
/**
* Will recreate previously deleted body property
*
* @return void
*/
protected function reinitBody() {
if (!isset($this->body->childNodes)) {
$this->body = $this->dom->createElement('body');
}
$this->body->innerHTML = $this->bodyCache;
}
} }
?> ?>