From fd61fd6e7928c6fd88c6027868f096b35216d9fe Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 6 Jul 2015 23:29:00 +0300 Subject: rewrite relative urls in readability output --- plugins/af_readability/init.php | 20 ++++++++++++++++++++ plugins/af_redditimgur/init.php | 22 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) 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 . "
" . $article["content"]; + //$article["content"] = $r->articleContent->innerHTML . "
" . $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 . "
" . $article["content"]; } } -- cgit v1.2.3