mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-06-24 06:08:41 +02:00
fix: Call to a member function find() on bool (#3146)
* fix: Call to a member function find() on bool Happens when defaultLinkTo() is passed the empty string. * fix: prevent exception in defaultLinkTo() when passed the empty string * refactor
This commit is contained in:
parent
001427243c
commit
dbab225fd2
2 changed files with 27 additions and 14 deletions
28
lib/html.php
28
lib/html.php
|
@ -169,31 +169,35 @@ function backgroundToImg($htmlContent)
|
|||
*
|
||||
* @link https://github.com/plaidfluff/php-urljoin php-urljoin
|
||||
*
|
||||
* @param string|object $content The HTML content. Supports HTML objects or string objects
|
||||
* @param string $server Fully qualified URL to the page containing relative links
|
||||
* @return object Content with fixed URLs.
|
||||
* @param string|object $dom The HTML content. Supports HTML objects or string objects
|
||||
* @param string $url Fully qualified URL to the page containing relative links
|
||||
* @return string|object Content with fixed URLs.
|
||||
*/
|
||||
function defaultLinkTo($content, $server)
|
||||
function defaultLinkTo($dom, $url)
|
||||
{
|
||||
if ($dom === '') {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$string_convert = false;
|
||||
if (is_string($content)) {
|
||||
if (is_string($dom)) {
|
||||
$string_convert = true;
|
||||
$content = str_get_html($content);
|
||||
$dom = str_get_html($dom);
|
||||
}
|
||||
|
||||
foreach ($content->find('img') as $image) {
|
||||
$image->src = urljoin($server, $image->src);
|
||||
foreach ($dom->find('img') as $image) {
|
||||
$image->src = urljoin($url, $image->src);
|
||||
}
|
||||
|
||||
foreach ($content->find('a') as $anchor) {
|
||||
$anchor->href = urljoin($server, $anchor->href);
|
||||
foreach ($dom->find('a') as $anchor) {
|
||||
$anchor->href = urljoin($url, $anchor->href);
|
||||
}
|
||||
|
||||
if ($string_convert) {
|
||||
$content = $content->outertext;
|
||||
$dom = $dom->outertext;
|
||||
}
|
||||
|
||||
return $content;
|
||||
return $dom;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue