$html .= $item->get_description();\r
} else {\r
$readability->clean($content_block, 'select');\r
- if ($options->rewrite_relative_urls) makeAbsolute($effective_url, $content_block);\r
+ // get base URL\r
+ $base_url = get_base_url($readability->dom);\r
+ if (!$base_url) $base_url = $effective_url;\r
+ // rewrite URLs\r
+ if ($options->rewrite_relative_urls) makeAbsolute($base_url, $content_block);\r
// footnotes\r
if (($links == 'footnotes') && (strpos($effective_url, 'wikipedia.org') === false)) {\r
$readability->addFootnotes($content_block);\r
flush();
}
}
+
+function get_base_url($dom) {\r
+ $xpath = new DOMXPath($dom);\r
+ $base_url = @$xpath->evaluate('string(//head/base/@href)', $dom);\r
+ if ($base_url !== '') {\r
+ return $base_url;\r
+ } else {\r
+ return false;\r
+ }\r
+}