summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2015-07-06 23:29:00 +0300
committerAndrew Dolgov <[email protected]>2015-07-06 23:29:00 +0300
commitfd61fd6e7928c6fd88c6027868f096b35216d9fe (patch)
treef73528700f7b5176af27dff19cdf8dceb75a587f /plugins
parente2a3689a1889c5df124b8d44131f3337d59d8ebd (diff)
rewrite relative urls in readability output
Diffstat (limited to 'plugins')
-rw-r--r--plugins/af_readability/init.php20
-rw-r--r--plugins/af_redditimgur/init.php22
2 files changed, 41 insertions, 1 deletions
diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php
index 161458c79..8e47d7640 100644
--- a/plugins/af_readability/init.php
+++ b/plugins/af_readability/init.php
@@ -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;
}
}
diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php
index 0dfd3f0c2..ca451bfcd 100644
--- a/plugins/af_redditimgur/init.php
+++ b/plugins/af_redditimgur/init.php
@@ -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"];
}
}