X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FPhoto.php;h=96c82b0c17d84c0cc095e8872b919cafee805be3;hb=07862b8a8840e2e7f833cd7ef670fb442d865860;hp=f9940f51e36ef60ab6614e973e8f4690b3c7f152;hpb=552a30e1f31f1a6f2ffb3f0abec6925a01d05d3a;p=friendica.git diff --git a/src/Model/Photo.php b/src/Model/Photo.php index f9940f51e3..96c82b0c17 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -1,6 +1,6 @@ $resourceid]); if (!DBA::isResult($r)) { @@ -164,7 +166,11 @@ class Photo $accessible = $uid ? (bool)DI::pConfig()->get($uid, 'system', 'accessible-photos', false) : false; - $sql_acl = Security::getPermissionsSQLByUserId($uid, $accessible); + if (!empty($visitor_uid) && ($uid == $visitor_uid)) { + $sql_acl = ''; + } else { + $sql_acl = Security::getPermissionsSQLByUserId($uid, $accessible); + } $conditions = ["`resource-id` = ? AND `scale` <= ? " . $sql_acl, $resourceid, $scale]; $params = ['order' => ['scale' => true]]; @@ -225,7 +231,7 @@ class Photo DBA::p( "SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`, min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created` - FROM `photo` WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) $sqlExtra + FROM `photo` WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) $sqlExtra GROUP BY `resource-id` $sqlExtra2", $values )); @@ -313,6 +319,28 @@ class Photo return $fields; } + /** + * Construct a photo array for a given image data string + * + * @param string $image_data Image data + * @param string $mimetype Image mime type. Is guessed by file name when empty. + * + * @return array + * @throws \Exception + */ + public static function createPhotoForImageData(string $image_data, string $mimetype = ''): array + { + $fields = self::getFields(); + $values = array_fill(0, count($fields), ''); + + $photo = array_combine($fields, $values); + $photo['data'] = $image_data; + $photo['type'] = $mimetype ?: Images::getMimeTypeByData($image_data); + $photo['cacheable'] = false; + + return $photo; + } + /** * Construct a photo array for a system resource image * @@ -560,6 +588,11 @@ class Photo $photo_failure = false; + if (!Network::isValidHttpUrl($image_url)) { + Logger::warning('Invalid image url', ['image_url' => $image_url, 'uid' => $uid, 'cid' => $cid, 'callstack' => System::callstack(20)]); + return false; + } + $filename = basename($image_url); if (!empty($image_url)) { $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE); @@ -647,7 +680,11 @@ class Photo $micro = Contact::getDefaultAvatar($contact, Proxy::SIZE_MICRO); } - return [$image_url, $thumb, $micro]; + $photo = DBA::selectFirst( + 'photo', ['blurhash'], ['uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'photo-type' => self::CONTACT_AVATAR] + ); + + return [$image_url, $thumb, $micro, $photo['blurhash']]; } /** @@ -881,7 +918,7 @@ class Photo */ public static function getResourceData(string $name): array { - $base = DI::baseUrl()->get(); + $base = DI::baseUrl(); $guid = str_replace([Strings::normaliseLink($base), '/photo/'], '', Strings::normaliseLink($name)); @@ -945,7 +982,7 @@ class Photo */ public static function isLocalPage(string $name): bool { - $base = DI::baseUrl()->get(); + $base = DI::baseUrl(); $guid = str_replace(Strings::normaliseLink($base), '', Strings::normaliseLink($name)); $guid = preg_replace("=/photos/.*/image/(.*)=ism", '$1', $guid); @@ -1325,7 +1362,7 @@ class Photo logger::warning('profile banner upload with scale 3 (960) failed'); } - logger::info('new profile banner upload ended'); + logger::info('new profile banner upload ended', ['uid' => $uid, 'resource_id' => $resource_id, 'filename' => $filename]); $condition = ["`photo-type` = ? AND `resource-id` != ? AND `uid` = ?", self::USER_BANNER, $resource_id, $uid]; self::update(['photo-type' => self::DEFAULT], $condition);