diff options
author | Andrew Dolgov <[email protected]> | 2021-02-28 00:06:06 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-28 00:06:06 +0300 |
commit | 96aec41484554074189bd13607e689d946835d95 (patch) | |
tree | 0f15c462be53f9b07a5dc3ed3c1e5358c769ff4a | |
parent | 1abb8eaf818b64133b91a4fc27a81ce42803296c (diff) |
remove posts which fail to return reddit json
-rwxr-xr-x | init.php | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -50,18 +50,28 @@ class Reddit_Delay extends Plugin { $target = $xpath->query("//atom:feed")->item(0); while ($row = $sth->fetch()) { - Debug::log(sprintf("[delay] pulling from cache: %s [%s]", - $row["link"], $row["orig_ts"]), Debug::$LOG_VERBOSE); + $reddit_json = UrlHelper::fetch(["url" => $row["link"] . "/.json"]); - $tmpdoc = new DOMDocument(); + if ($reddit_json) { + Debug::log(sprintf("[delay] pulling from cache: %s [%s]", + $row["link"], $row["orig_ts"]), Debug::$LOG_VERBOSE); - if ($tmpdoc->loadXML($row["item"])) { - $tmpxpath = new DOMXPath($tmpdoc); + $tmpdoc = new DOMDocument(); - $imported_entry = $doc->importNode($tmpxpath->query("//entry")->item(0), true); + if ($tmpdoc->loadXML($row["item"])) { + $tmpxpath = new DOMXPath($tmpdoc); + + $imported_entry = $doc->importNode($tmpxpath->query("//entry")->item(0), true); + + $dsth->execute([$row["id"]]); + } + } else { + Debug::log(sprintf("[delay] json fetch failed, post deleted? removing: %s [%s]", + $row["link"], $row["orig_ts"]), Debug::$LOG_VERBOSE); $dsth->execute([$row["id"]]); } + } } |