Avoid HTML parsing of an empty body

This commit is contained in:
Michael 2021-04-10 05:46:19 +00:00
parent 3e2fa7867c
commit 5a00902e11
7 changed files with 26 additions and 9 deletions

View file

@ -1178,7 +1178,11 @@ class BBCode
// if its not a picture then look if its a page that contains a picture link
$body = DI::httpRequest()->fetch($match[1]);
if (empty($body)) {
DI::cache()->set($cache_key, $text);
return $text;
}
$doc = new DOMDocument();
@$doc->loadHTML($body);
$xpath = new DOMXPath($doc);
@ -1214,8 +1218,6 @@ class BBCode
private static function cleanPictureLinksCallback($match)
{
$a = DI::app();
// When the picture link is the own photo path then we can avoid fetching the link
$own_photo_url = preg_quote(Strings::normaliseLink(DI::baseUrl()->get()) . '/photos/');
if (preg_match('|' . $own_photo_url . '.*?/image/|', Strings::normaliseLink($match[1]))) {
@ -1257,6 +1259,10 @@ class BBCode
// if its not a picture then look if its a page that contains a picture link
$body = DI::httpRequest()->fetch($match[1]);
if (empty($body)) {
DI::cache()->set($cache_key, $text);
return $text;
}
$doc = new DOMDocument();
@$doc->loadHTML($body);