// This class allows us to do JavaScript like assignements to innerHTML
require_once(dirname(__FILE__).'/JSLikeHTMLElement.php');
+libxml_use_internal_errors(true);
// Alternative usage (for testing only!)
// uncomment the lines below and call Readability.php in your browser
} else {
$topCandidate->innerHTML = $page->documentElement->innerHTML;
$page->documentElement->innerHTML = '';
+ $this->reinitBody();
$page->documentElement->appendChild($topCandidate);
}
} else {
$articleContent = $this->dom->createElement('div');
$articleContent->setAttribute('id', 'readability-content');
$siblingScoreThreshold = max(10, ((int)$topCandidate->getAttribute('readability')) * 0.2);
- $siblingNodes = $topCandidate->parentNode->childNodes;
+ $siblingNodes = @$topCandidate->parentNode->childNodes;
if (!isset($siblingNodes)) {
$siblingNodes = new stdClass;
$siblingNodes->length = 0;
{
// 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.
- if (!isset($this->body->childNodes)) $this->body = $this->dom->createElement('body');
- $this->body->innerHTML = $this->bodyCache;
+ $this->reinitBody();
if ($this->flagIsActive(self::FLAG_STRIP_UNLIKELYS)) {
$this->removeFlag(self::FLAG_STRIP_UNLIKELYS);
public function removeFlag($flag) {
$this->flags = $this->flags & ~$flag;
}
+
+ /**\r
+ * Will recreate previously deleted body property\r
+ *\r
+ * @return void\r
+ */\r
+ protected function reinitBody() {\r
+ if (!isset($this->body->childNodes)) {\r
+ $this->body = $this->dom->createElement('body');
+ $this->body->innerHTML = $this->bodyCache;\r
+ }\r
+ }
+
}
-?>
\ No newline at end of file
+?>