From 2aaefbfa54447c37a74aaf126f864fac629e9bd5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Jun 2018 14:58:09 +0300 Subject: update autoloader to consider namespaces for third party libraries: placed and loaded from vendor/namespace/classpath.php update readability to a newer implementation based on Readability.js (https://github.com/andreskrey/readability.php) add vendor/Psr/Log interface required for the above --- plugins/af_readability/init.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'plugins') diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index 2d08a621c..807231390 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -1,4 +1,7 @@ saveHTML(); } - $r = new Readability($tmp, $fetch_effective_url); + $r = new Readability(new Configuration()); - if ($r->init()) { - $tmpxpath = new DOMXPath($r->dom); + try { + if ($r->parse($tmp)) { - $entries = $tmpxpath->query('(//a[@href]|//img[@src])'); + $tmpxpath = new DOMXPath($r->getDOMDOcument()); + $entries = $tmpxpath->query('(//a[@href]|//img[@src])'); - foreach ($entries as $entry) { - if ($entry->hasAttribute("href")) { - $entry->setAttribute("href", - rewrite_relative_url($fetch_effective_url, $entry->getAttribute("href"))); + foreach ($entries as $entry) { + if ($entry->hasAttribute("href")) { + $entry->setAttribute("href", + rewrite_relative_url($fetch_effective_url, $entry->getAttribute("href"))); - } + } - if ($entry->hasAttribute("src")) { - $entry->setAttribute("src", - rewrite_relative_url($fetch_effective_url, $entry->getAttribute("src"))); + if ($entry->hasAttribute("src")) { + $entry->setAttribute("src", + rewrite_relative_url($fetch_effective_url, $entry->getAttribute("src"))); + } } + return $r->getContent(); } - return $r->articleContent->innerHTML; + } catch (ParseException $e) { + return false; } + } return false; -- cgit v1.2.3