]> git.wh0rd.org Git - tt-rss.git/commitdiff
rewrite relative urls in readability output
authorAndrew Dolgov <noreply@fakecake.org>
Mon, 6 Jul 2015 20:29:00 +0000 (23:29 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Mon, 6 Jul 2015 20:29:00 +0000 (23:29 +0300)
plugins/af_readability/init.php
plugins/af_redditimgur/init.php

index 161458c79b1d16a79dd6767efabd75d86d9786cb..8e47d7640729286ec3def39d7246106a8b379f16 100644 (file)
@@ -104,6 +104,26 @@ class Af_Readability extends Plugin {
                        $r = new Readability($tmp, $article["link"]);
 
                        if ($r->init()) {
+
+                               $tmpxpath = new DOMXPath($r->dom);
+
+                               $entries = $tmpxpath->query('(//a[@href]|//img[@src])');
+
+                               foreach ($entries as $entry) {
+                                       if ($entry->hasAttribute("href")) {
+                                               $entry->setAttribute("href",
+                                                       rewrite_relative_url($entry->getAttribute("href"), $article["link"]));
+
+                                       }
+
+                                       if ($entry->hasAttribute("src")) {
+                                               $entry->setAttribute("src",
+                                                       rewrite_relative_url($entry->getAttribute("src"), $article["link"]));
+
+                                       }
+
+                               }
+
                                $article["content"] = $r->articleContent->innerHTML;
                        }
                }
index 0dfd3f0c2841a9abb35fdb64eaed4f0436cd0924..ca451bfcdb653a83417167f79cdfe1832bcb32ec 100644 (file)
@@ -266,8 +266,28 @@ class Af_RedditImgur extends Plugin {
                                                                $r = new Readability($tmp, $content_link->getAttribute("href"));
 
                                                                if ($r->init()) {
-                                                                       $article["content"] = $r->articleContent->innerHTML . "<hr/>" . $article["content"];
+                                                                       //$article["content"] = $r->articleContent->innerHTML . "<hr/>" . $article["content"];
+
+                                                                       $tmpxpath = new DOMXPath($r->dom);
+
+                                                                       $entries = $tmpxpath->query('(//a[@href]|//img[@src])');
+
+                                                                       foreach ($entries as $entry) {
+                                                                               if ($entry->hasAttribute("href")) {
+                                                                                       $entry->setAttribute("href",
+                                                                                               rewrite_relative_url($entry->getAttribute("href"), $content_link));
+
+                                                                               }
 
+                                                                               if ($entry->hasAttribute("src")) {
+                                                                                       $entry->setAttribute("src",
+                                                                                               rewrite_relative_url($entry->getAttribute("src"), $content_link));
+
+                                                                               }
+
+                                                                       }
+
+                                                                       $article["content"] = $r->articleContent->innerHTML . "<hr/>" . $article["content"];
                                                                }
                                                        }