X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FUtil%2FImages.php;h=c268916cc9b1e25f65e72d215b013c1377111fa3;hb=036b565a7846916f763ce1dcbcaade0844ff1589;hp=f39b0db00dc235a643475159e562724bc4c0c0b6;hpb=aa0b485f3dca72c5448076e913fa54d948cd7731;p=friendica.git diff --git a/src/Util/Images.php b/src/Util/Images.php index f39b0db00d..c268916cc9 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -1,6 +1,6 @@ get($url); + $cacheKey = 'getInfoFromURL:' . sha1($url); + + $data = DI::cache()->get($cacheKey); if (empty($data) || !is_array($data)) { $data = self::getInfoFromURL($url); - DI::cache()->set($url, $data); + DI::cache()->set($cacheKey, $data); } return $data; @@ -184,7 +211,17 @@ class Images return $data; } - $img_str = DI::httpRequest()->fetch($url, true, 4); + if (Network::isLocalLink($url) && ($data = Photo::getResourceData($url))) { + $photo = Photo::selectFirst([], ['resource-id' => $data['guid'], 'scale' => $data['scale']]); + if (!empty($photo)) { + $img_str = Photo::getImageDataForPhoto($photo); + } + // @todo Possibly add a check for locally stored files + } + + if (empty($img_str)) { + $img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4); + } if (!$img_str) { return []; @@ -193,18 +230,7 @@ class Images $filesize = strlen($img_str); try { - if (function_exists("getimagesizefromstring")) { - $data = @getimagesizefromstring($img_str); - } else { - $tempfile = tempnam(get_temppath(), "cache"); - - $stamp1 = microtime(true); - file_put_contents($tempfile, $img_str); - DI::profiler()->saveTimestamp($stamp1, "file"); - - $data = getimagesize($tempfile); - unlink($tempfile); - } + $data = @getimagesizefromstring($img_str); } catch (\Exception $e) { return []; }