diff options
Diffstat (limited to 'plugins/af_redditimgur')
-rwxr-xr-x | plugins/af_redditimgur/init.php | 100 |
1 files changed, 53 insertions, 47 deletions
diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 6eb530e27..a1da0ca37 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -101,15 +101,17 @@ class Af_RedditImgur extends Plugin { private function process_post_media($data, $doc, $xpath, $anchor) { $found = 0; - if (is_array($data["media_metadata"])) { + if (isset($data["media_metadata"])) { foreach ($data["media_metadata"] as $media) { - $media_url = htmlspecialchars_decode($media["s"]["u"]); + if (!empty($media["s"]["u"])) { + $media_url = htmlspecialchars_decode($media["s"]["u"]); - Debug::log("found media_metadata (gallery): $media_url", Debug::$LOG_VERBOSE); + Debug::log("found media_metadata (gallery): $media_url", Debug::$LOG_VERBOSE); - if ($media_url) { - $this->handle_as_image($doc, $anchor, $media_url); - $found = 1; + if ($media_url) { + $this->handle_as_image($doc, $anchor, $media_url); + $found = 1; + } } } } @@ -134,7 +136,9 @@ class Af_RedditImgur extends Plugin { } } */ - if (!$found && $data["post_hint"] == "hosted:video") { + $post_hint = $data["post_hint"] ?? false; + + if (!$found && $post_hint == "hosted:video") { $media_url = $data["url"]; if (isset($data["preview"]["images"][0]["source"])) @@ -154,7 +158,7 @@ class Af_RedditImgur extends Plugin { } } - if (!$found && $data["post_hint"] == "video") { + if (!$found && $post_hint == "video") { $media_url = $data["url"]; if (isset($data["preview"]["images"][0]["source"])) @@ -168,7 +172,7 @@ class Af_RedditImgur extends Plugin { $found = 1; } - if (!$found && $data["post_hint"] == "image") { + if (!$found && $post_hint == "image") { $media_url = $data["url"]; Debug::log("found image url: $media_url", Debug::$LOG_VERBOSE); @@ -177,14 +181,14 @@ class Af_RedditImgur extends Plugin { $found = 1; } - if (!$found && is_array($data["preview"]["images"])) { + if (!$found && isset($data["preview"]["images"])) { foreach ($data["preview"]["images"] as $img) { if (isset($img["source"]["url"])) { $media_url = htmlspecialchars_decode($img["source"]["url"]); $target_url = $data["url"]; if ($media_url) { - if ($data["post_hint"] == "self") { + if ($post_hint == "self") { Debug::log("found preview image url: $media_url (link: $target_url)", Debug::$LOG_VERBOSE); $this->handle_as_image($doc, $anchor, $media_url, $target_url); @@ -229,7 +233,7 @@ class Af_RedditImgur extends Plugin { $data = $child["data"]; - if (is_array($data["crosspost_parent_list"])) { + if (isset($data["crosspost_parent_list"])) { Debug::log("JSON: processing child crosspost_parent_list", Debug::$LOG_EXTENDED); foreach ($data["crosspost_parent_list"] as $parent) { @@ -511,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"]; - $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 ?"); + 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->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); + } } } |