]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - inc/3rdparty/libraries/readability/Readability.php
phpepub via composer
[github/wallabag/wallabag.git] / inc / 3rdparty / libraries / readability / Readability.php
old mode 100644 (file)
new mode 100755 (executable)
index d0f09d7..a30012c
@@ -46,6 +46,7 @@
 
 // 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 
@@ -679,6 +680,7 @@ class Readability
                                } else {
                                        $topCandidate->innerHTML = $page->documentElement->innerHTML;
                                        $page->documentElement->innerHTML = '';
+                                       $this->reinitBody();
                                        $page->documentElement->appendChild($topCandidate);
                                }
                        } else {
@@ -696,7 +698,7 @@ class Readability
                $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;
@@ -794,8 +796,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
                        // 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);
@@ -1134,5 +1135,18 @@ class Readability
        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
+?>