From 692425342317277090f4c03f36d114eab3742340 Mon Sep 17 00:00:00 2001 From: Maryana Rozhankivska Date: Wed, 25 Jun 2014 20:00:00 +0300 Subject: fix of issue #677: When downloading images, wallabag doesnt respect html "base" tag, tnx to @fivefilters --- inc/3rdparty/makefulltextfeed.php | 6 +++++- inc/3rdparty/makefulltextfeedHelpers.php | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/inc/3rdparty/makefulltextfeed.php b/inc/3rdparty/makefulltextfeed.php index 62c050ec..a081f88b 100755 --- a/inc/3rdparty/makefulltextfeed.php +++ b/inc/3rdparty/makefulltextfeed.php @@ -671,7 +671,11 @@ foreach ($items as $key => $item) { $html .= $item->get_description(); } else { $readability->clean($content_block, 'select'); - if ($options->rewrite_relative_urls) makeAbsolute($effective_url, $content_block); + // get base URL + $base_url = get_base_url($readability->dom); + if (!$base_url) $base_url = $effective_url; + // rewrite URLs + if ($options->rewrite_relative_urls) makeAbsolute($base_url, $content_block); // footnotes if (($links == 'footnotes') && (strpos($effective_url, 'wikipedia.org') === false)) { $readability->addFootnotes($content_block); diff --git a/inc/3rdparty/makefulltextfeedHelpers.php b/inc/3rdparty/makefulltextfeedHelpers.php index 4e985372..ac872ab8 100755 --- a/inc/3rdparty/makefulltextfeedHelpers.php +++ b/inc/3rdparty/makefulltextfeedHelpers.php @@ -377,3 +377,13 @@ function debug($msg) { flush(); } } + +function get_base_url($dom) { + $xpath = new DOMXPath($dom); + $base_url = @$xpath->evaluate('string(//head/base/@href)', $dom); + if ($base_url !== '') { + return $base_url; + } else { + return false; + } +} -- cgit v1.2.3