X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FPhoto.php;h=30e666898777c5b4a9c245d5a31b611b9373b932;hb=71a0c52dc338213f81a17e95ef166d56f2d6bc40;hp=7de0084e2443dcdd490f8cdafdc2f82122378a1c;hpb=a1a584f444ef9552a59d05cd337351ca375fc3d5;p=friendica.git diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 7de0084e24..30e6668987 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -245,13 +245,17 @@ class Photo * Construct a photo array for a system resource image * * @param string $filename Image file name relative to code root - * @param string $mimetype Image mime type. Defaults to "image/jpeg" + * @param string $mimetype Image mime type. Is guessed by file name when empty. * * @return array * @throws \Exception */ - public static function createPhotoForSystemResource($filename, $mimetype = "image/jpeg") + public static function createPhotoForSystemResource($filename, $mimetype = '') { + if (empty($mimetype)) { + $mimetype = Images::guessTypeByExtension($filename); + } + $fields = self::getFields(); $values = array_fill(0, count($fields), ""); @@ -269,13 +273,17 @@ class Photo * * @param string $url Image URL * @param int $uid User ID of the requesting person - * @param string $mimetype Image mime type. Defaults to "image/jpeg" + * @param string $mimetype Image mime type. Is guessed by file name when empty. * * @return array * @throws \Exception */ - public static function createPhotoForExternalResource($url, $uid, $mimetype = "image/jpeg") + public static function createPhotoForExternalResource($url, $uid = 0, $mimetype = '') { + if (empty($mimetype)) { + $mimetype = Images::guessTypeByExtension($url); + } + $fields = self::getFields(); $values = array_fill(0, count($fields), ""); @@ -796,30 +804,33 @@ class Photo } /** - * Returns the GUID from picture links + * Fetch the guid and scale from picture links * * @param string $name Picture link - * @return string GUID - * @throws \Exception + * @return array */ - public static function getGUID($name) + public static function getResourceData(string $name):array { $base = DI::baseUrl()->get(); $guid = str_replace([Strings::normaliseLink($base), '/photo/'], '', Strings::normaliseLink($name)); + if (parse_url($guid, PHP_URL_SCHEME)) { + return []; + } + $guid = self::stripExtension($guid); if (substr($guid, -2, 1) != "-") { - return ''; + return []; } $scale = intval(substr($guid, -1, 1)); if (!is_numeric($scale)) { - return ''; + return []; } $guid = substr($guid, 0, -2); - return $guid; + return ['guid' => $guid, 'scale' => $scale]; } /** @@ -831,13 +842,12 @@ class Photo */ public static function isLocal($name) { - $guid = self::getGUID($name); - - if (empty($guid)) { + $data = self::getResourceData($name); + if (empty($data)) { return false; } - return DBA::exists('photo', ['resource-id' => $guid]); + return DBA::exists('photo', ['resource-id' => $data['guid'], 'scale' => $data['scale']]); } /**