From 5849a398206dad2d2d492a25d4bbe2232fa388fa Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 6 Feb 2021 10:31:06 +0300 Subject: [PATCH] af_redditimgur: don't try to load empty html; fix a warning in update debugger --- classes/feeds.php | 2 +- plugins/af_redditimgur/init.php | 72 +++++++++++++++++---------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index 1b87fe6c7..6a4bd5fcd 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -772,7 +772,7 @@ class Feeds extends Handler_Protected { Debug::set_loglevel($xdebug); $feed_id = (int)$_REQUEST["feed_id"]; - @$do_update = $_REQUEST["action"] == "do_update"; + $do_update = ($_REQUEST["action"] ?? "") == "do_update"; $csrf_token = $_POST["csrf_token"]; $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 60e00c74c..a1da0ca37 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -515,56 +515,58 @@ class Af_RedditImgur extends Plugin { function hook_article_filter($article) { - if (strpos($article["link"], "reddit.com/r/") !== false) { + if (strpos($article["link"], "reddit.com/r/") !== false && !empty($article["content"])) { $doc = new DOMDocument(); - @$doc->loadHTML($article["content"]); - $xpath = new DOMXPath($doc); - $content_link = $xpath->query("(//a[contains(., '[link]')])")->item(0); + if (@$doc->loadHTML($article["content"])) { + $xpath = new DOMXPath($doc); - if ($this->host->get($this, "enable_content_dupcheck")) { + $content_link = $xpath->query("(//a[contains(., '[link]')])")->item(0); - if ($content_link) { - $content_href = $content_link->getAttribute("href"); - $entry_guid = $article["guid_hashed"]; - $owner_uid = $article["owner_uid"]; + if ($this->host->get($this, "enable_content_dupcheck")) { - if (DB_TYPE == "pgsql") { - $interval_qpart = "date_entered < NOW() - INTERVAL '1 day'"; - } else { - $interval_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY)"; - } + if ($content_link) { + $content_href = $content_link->getAttribute("href"); + $entry_guid = $article["guid_hashed"]; + $owner_uid = $article["owner_uid"]; + + if (DB_TYPE == "pgsql") { + $interval_qpart = "date_entered < NOW() - INTERVAL '1 day'"; + } else { + $interval_qpart = "date_entered < DATE_SUB(NOW(), INTERVAL 1 DAY)"; + } - $sth = $this->pdo->prepare("SELECT COUNT(id) AS cid - FROM ttrss_entries, ttrss_user_entries WHERE - ref_id = id AND - $interval_qpart AND - guid != ? AND - owner_uid = ? AND - content LIKE ?"); + $sth = $this->pdo->prepare("SELECT COUNT(id) AS cid + FROM ttrss_entries, ttrss_user_entries WHERE + ref_id = id AND + $interval_qpart AND + guid != ? AND + owner_uid = ? AND + content LIKE ?"); - $sth->execute([$entry_guid, $owner_uid, "%href=\"$content_href\">[link]%"]); + $sth->execute([$entry_guid, $owner_uid, "%href=\"$content_href\">[link]%"]); - if ($row = $sth->fetch()) { - $num_found = $row['cid']; + if ($row = $sth->fetch()) { + $num_found = $row['cid']; - if ($num_found > 0) $article["force_catchup"] = true; + if ($num_found > 0) $article["force_catchup"] = true; + } } } - } - if ($content_link && $this->is_blacklisted($content_link->getAttribute("href"))) - return $article; + if ($content_link && $this->is_blacklisted($content_link->getAttribute("href"))) + return $article; - $found = $this->inline_stuff($article, $doc, $xpath); + $found = $this->inline_stuff($article, $doc, $xpath); - $node = $doc->getElementsByTagName('body')->item(0); + $node = $doc->getElementsByTagName('body')->item(0); - if ($node && $found) { - $article["content"] = $doc->saveHTML($node); - $article["enclosures"] = []; - } else if ($content_link) { - $article = $this->readability($article, $content_link->getAttribute("href"), $doc, $xpath); + if ($node && $found) { + $article["content"] = $doc->saveHTML($node); + $article["enclosures"] = []; + } else if ($content_link) { + $article = $this->readability($article, $content_link->getAttribute("href"), $doc, $xpath); + } } }