X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FPhoto.php;h=d9e6f7cadebb8c54688cce3f531d15d5e025da54;hb=624e4c192c7f837ac0587a50da6e1409081eb519;hp=8ba01e33655d280ede203d5f774e3c6b51465a42;hpb=53f06b512280dcb5964e91083206d003e8616ce7;p=friendica.git diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 8ba01e3365..d9e6f7cade 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -32,6 +32,7 @@ use Friendica\Core\Storage\Exception\InvalidClassStorageException; use Friendica\Core\Storage\Exception\ReferenceStorageException; use Friendica\Core\Storage\Exception\StorageException; use Friendica\Core\Storage\Type\SystemResource; +use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Object\Image; use Friendica\Util\DateTimeFormat; use Friendica\Util\Images; @@ -497,7 +498,8 @@ class Photo $filename = basename($image_url); if (!empty($image_url)) { - $ret = DI::httpClient()->get($image_url); + $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE); + Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]); $img_str = $ret->getBody(); $type = $ret->getContentType(); } else { @@ -702,10 +704,19 @@ class Photo } $image_uri = substr($image_uri, strrpos($image_uri, '/') + 1); $image_uri = substr($image_uri, 0, strpos($image_uri, '-')); - if (!strlen($image_uri)) { - return ''; - } - return $image_uri; + return trim($image_uri); + } + + /** + * Checks if the given URL is a local photo. + * Since it is meant for time critical occasions, the check is done without any database requests. + * + * @param string $url + * @return boolean + */ + public static function isPhotoURI(string $url): bool + { + return !empty(self::ridFromURI($url)); } /** @@ -912,7 +923,8 @@ class Photo { $filename = basename($image_url); if (!empty($image_url)) { - $ret = DI::httpClient()->get($image_url); + $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE); + Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]); $img_str = $ret->getBody(); $type = $ret->getContentType(); } else {