From d0a9aeaf80510cdbbf4f4e461798ae9c36ace420 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Apr 2019 08:51:17 +0300 Subject: move readability library to af_readability/vendor out of global vendor directory af_redditimgur: use HOOK_GET_FULL_TEXT instead of invoking readability directly --- plugins/af_redditimgur/init.php | 44 +++++------------------------------------ 1 file changed, 5 insertions(+), 39 deletions(-) (limited to 'plugins/af_redditimgur/init.php') diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 9ab2e7968..403db888a 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -1,7 +1,4 @@ get_content_type($url, $useragent_compat); if ($content_type && strpos($content_type, "text/html") !== FALSE) { - $tmp = fetch_file_contents(["url" => $url, - "useragent" => $useragent_compat, - "http_accept" => "text/html"]); - - Debug::log("tmplen: " . mb_strlen($tmp), Debug::$LOG_VERBOSE); - - if ($tmp && mb_strlen($tmp) < 1024 * 500) { - - $r = new Readability(new Configuration()); - - try { - if ($r->parse($tmp)) { - - $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($url, $entry->getAttribute("href"))); + foreach ($this->host->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) { + $extracted_content = $p->hook_get_full_text($url); - } - - if ($entry->hasAttribute("src")) { - $entry->setAttribute("src", - rewrite_relative_url($url, $entry->getAttribute("src"))); - - } - - } - - $article["content"] = $r->getContent() . "
" . $article["content"]; - } - } catch (Exception $e) { - // + if ($extracted_content) { + $article["content"] = $extracted_content; + break; } } } -- cgit v1.2.3-54-g00ecf