[XPathAbstract] Fix relative links in fetched HTML (#3401)

* [core] Make defaultLinkTo compatible with DOMDocument

* [XPathAbstract] Fix relative links in fetched HTML
This commit is contained in:
mrnoname1000 2023-05-18 06:50:50 -05:00 committed by GitHub
parent ecd717cf58
commit 096c3bca73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -387,6 +387,9 @@ abstract class XPathAbstract extends BridgeAbstract
libxml_clear_errors(); libxml_clear_errors();
libxml_use_internal_errors(false); libxml_use_internal_errors(false);
// fix relative links
defaultLinkTo($webPageHtml, $this->feedUri);
$xpath = new \DOMXPath($webPageHtml); $xpath = new \DOMXPath($webPageHtml);
$this->feedName = $this->provideFeedTitle($xpath); $this->feedName = $this->provideFeedTitle($xpath);

View File

@ -185,14 +185,17 @@ function defaultLinkTo($dom, $url)
$dom = str_get_html($dom); $dom = str_get_html($dom);
} }
foreach ($dom->find('img') as $image) { // Use long method names for compatibility with simple_html_dom and DOMDocument
$image->src = urljoin($url, $image->src);
foreach ($dom->getElementsByTagName('img') as $image) {
$image->setAttribute('src', urljoin($url, $image->getAttribute('src')));
} }
foreach ($dom->find('a') as $anchor) { foreach ($dom->getElementsByTagName('a') as $anchor) {
$anchor->href = urljoin($url, $anchor->href); $anchor->setAttribute('href', urljoin($url, $anchor->getAttribute('href')));
} }
// Will never be true for DOMDocument
if ($string_convert) { if ($string_convert) {
$dom = $dom->outertext; $dom = $dom->outertext;
} }