diff options
Diffstat (limited to 'plugins/af_readability/init.php')
-rwxr-xr-x | plugins/af_readability/init.php | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index a39cc278e..7027db4a7 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -6,7 +6,7 @@ use \andreskrey\Readability\Configuration; class Af_Readability extends Plugin { - /* @var PluginHost $host */ + /** @var PluginHost $host */ private $host; function about() { @@ -19,6 +19,7 @@ class Af_Readability extends Plugin { return array("needs_curl" => true); } + /** @return void */ function save() { $enable_share_anything = checkbox_to_sql_bool($_POST["enable_share_anything"] ?? ""); @@ -51,7 +52,7 @@ class Af_Readability extends Plugin { function hook_article_button($line) { return "<i class='material-icons' onclick=\"Plugins.Af_Readability.embed(".$line["id"].")\" - style='cursor : pointer' title='".__('Toggle full article text')."'>description</i>"; + style='cursor : pointer' title=\"".__('Toggle full article text')."\">description</i>"; } function hook_prefs_tab($args) { @@ -186,9 +187,14 @@ class Af_Readability extends Plugin { case "action_append": return $this->process_article($article, true); } + return $article; } - public function extract_content($url) { + /** + * @param string $url + * @return string|false + */ + public function extract_content(string $url) { $tmp = UrlHelper::fetch([ "url" => $url, @@ -212,7 +218,11 @@ class Af_Readability extends Plugin { } try { - $r = new Readability(new Configuration()); + + $r = new Readability(new Configuration([ + 'fixRelativeURLs' => true, + 'originalURL' => $url, + ])); if ($r->parse($tmp)) { @@ -222,13 +232,18 @@ class Af_Readability extends Plugin { foreach ($entries as $entry) { if ($entry->hasAttribute("href")) { $entry->setAttribute("href", - rewrite_relative_url(UrlHelper::$fetch_effective_url, $entry->getAttribute("href"))); + UrlHelper::rewrite_relative(UrlHelper::$fetch_effective_url, $entry->getAttribute("href"))); } if ($entry->hasAttribute("src")) { + if ($entry->hasAttribute("data-src")) { + $src = $entry->getAttribute("data-src"); + } else { + $src = $entry->getAttribute("src"); + } $entry->setAttribute("src", - rewrite_relative_url(UrlHelper::$fetch_effective_url, $entry->getAttribute("src"))); + UrlHelper::rewrite_relative(UrlHelper::$fetch_effective_url, $src)); } } @@ -244,7 +259,13 @@ class Af_Readability extends Plugin { return false; } - function process_article($article, $append_mode) { + /** + * @param array<string, mixed> $article + * @param bool $append_mode + * @return array<string,mixed> + * @throws PDOException + */ + function process_article(array $article, bool $append_mode) : array { $extracted_content = $this->extract_content($article["link"]); @@ -261,12 +282,14 @@ class Af_Readability extends Plugin { return $article; } - private function get_stored_array($name) { - $tmp = $this->host->get($this, $name); - - if (!is_array($tmp)) $tmp = []; - - return $tmp; + /** + * @param string $name + * @return array<int|string, mixed> + * @throws PDOException + * @deprecated + */ + private function get_stored_array(string $name) : array { + return $this->host->get_array($this, $name); } function hook_article_filter($article) { @@ -304,7 +327,12 @@ class Af_Readability extends Plugin { return 2; } - private function filter_unknown_feeds($enabled_feeds) { + /** + * @param array<int> $enabled_feeds + * @return array<int> + * @throws PDOException + */ + private function filter_unknown_feeds(array $enabled_feeds) : array { $tmp = array(); foreach ($enabled_feeds as $feed) { @@ -320,7 +348,7 @@ class Af_Readability extends Plugin { return $tmp; } - function embed() { + function embed() : void { $article_id = (int) $_REQUEST["id"]; $sth = $this->pdo->prepare("SELECT link FROM ttrss_entries WHERE id = ?"); |