From 9a92931e9be0bacdcc8a026c79dbf1f4185266a5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 9 Jun 2023 18:28:37 +0300 Subject: enable readability --- init.php | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'init.php') diff --git a/init.php b/init.php index 6af66cd..3cfde14 100644 --- a/init.php +++ b/init.php @@ -380,30 +380,24 @@ class Af_Lemmy extends Plugin { */ private function readability(array $article, string $url, DOMDocument $doc, DOMXpath $xpath, bool $debug = false) : array { - if (function_exists("curl_init") && $this->host->get($this, "enable_readability") && - mb_strlen(strip_tags($article["content"])) <= 150) { + if (function_exists("curl_init") && mb_strlen(strip_tags($article["content"])) <= 150) { - // do not try to embed posts linking back to other reddit posts - // readability.php requires PHP 5.6 - if ($url && strpos($url, "reddit.com") === false) { + /* link may lead to a huge video file or whatever, we need to check content type before trying to + parse it which p much requires curl */ - /* link may lead to a huge video file or whatever, we need to check content type before trying to - parse it which p much requires curl */ + $useragent_compat = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"; + $content_type = $this->get_content_type($url, $useragent_compat); - $useragent_compat = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"; - $content_type = $this->get_content_type($url, $useragent_compat); + if ($content_type && strpos($content_type, "text/html") !== false) { - if ($content_type && strpos($content_type, "text/html") !== false) { - - $this->host->run_hooks_callback(PluginHost::HOOK_GET_FULL_TEXT, - function ($result) use (&$article) { - if ($result) { - $article["content"] = $result; - return true; - } - }, - $url); - } + $this->host->run_hooks_callback(PluginHost::HOOK_GET_FULL_TEXT, + function ($result) use (&$article) { + if ($result) { + $article["content"] = $result; + return true; + } + }, + $url); } } -- cgit v1.2.3