]> git.wh0rd.org Git - tt-rss.git/commitdiff
af_redditimgur: implement a hack to deal with reddit rss feed being currently broken
authorAndrew Dolgov <noreply@fakecake.org>
Sat, 23 Jan 2016 08:51:17 +0000 (11:51 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Sat, 23 Jan 2016 08:51:17 +0000 (11:51 +0300)
plugins/af_redditimgur/init.php

index 3ff9607293a2a6b863a048f67fa00dcc02fdbbdf..1ab696ce3ff955bd183471f7e077feb0b8ce7933 100755 (executable)
@@ -244,6 +244,32 @@ class Af_RedditImgur extends Plugin {
 
                        $found = $this->inline_stuff($article, $doc, $xpath);
 
+                       // reddit decided to break its rss because of thunderbird so let's implement a temporary hack
+                       // see also: https://www.reddit.com/r/changelog/comments/428vdq/upcoming_reddit_change_switching_from_rss_20_to/
+
+                       $textnode = $xpath->query("//*[text()[contains(.,'!-- SC_OFF')]]/text()")->item(0);
+
+                       if ($textnode) {
+
+                               $badhtml = htmlspecialchars_decode($textnode->textContent);
+                               $textnode->textContent = "";
+
+                               if ($badhtml) {
+                                       $body = $doc->getElementsByTagName("body")->item(0);
+
+                                       $tmp = new DOMDocument;
+
+                                       if (@$tmp->loadHTML($badhtml)) {
+                                               $newnode = $doc->importNode($tmp->documentElement, TRUE);
+
+                                               if ($newnode) {
+                                                       $body->insertBefore($newnode, $body->firstChild);
+                                                       $found = 1;
+                                               }
+                                       }
+                               }
+                       }
+
                        if (!defined('NO_CURL') && function_exists("curl_init") && !$found && $this->host->get($this, "enable_readability") &&
                                mb_strlen(strip_tags($article["content"])) <= 150) {