X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContact%2FAvatar.php;h=fc4b7e38cba62279c37d05ca04877e5fa71f5163;hb=15eb8407928c24a96c17528304e23b0558c37bba;hp=d4368df22baac8771656342f495c83e7cddc5add;hpb=08ead524339a43f29c809ca63514e40cd24dee9c;p=friendica.git diff --git a/src/Contact/Avatar.php b/src/Contact/Avatar.php index d4368df22b..fc4b7e38cb 100644 --- a/src/Contact/Avatar.php +++ b/src/Contact/Avatar.php @@ -1,6 +1,6 @@ [HttpClientAccept::IMAGE]]); + try { + $fetchResult = HTTPSignature::fetchRaw($avatar, 0, [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE]]); + } catch (\Exception $exception) { + Logger::notice('Avatar is invalid', ['avatar' => $avatar, 'exception' => $exception]); + return $fields; + } $img_str = $fetchResult->getBody(); if (empty($img_str)) { @@ -87,9 +92,11 @@ class Avatar return $fields; } - $filename = self::getFilename($contact['url']); + $filename = self::getFilename($contact['url'], $avatar); $timestamp = time(); + $fields['blurhash'] = $image->getBlurHash(); + $fields['photo'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_SMALL, $timestamp); $fields['thumb'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_THUMB, $timestamp); $fields['micro'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_MICRO, $timestamp); @@ -113,7 +120,7 @@ class Avatar return $fields; } - $filename = self::getFilename($contact['url']); + $filename = self::getFilename($contact['url'], $contact['avatar']); $timestamp = time(); $fields['photo'] = self::storeAvatarCache($image, $filename, Proxy::PIXEL_SMALL, $timestamp); @@ -123,9 +130,9 @@ class Avatar return $fields; } - private static function getFilename(string $url): string + private static function getFilename(string $url, string $host): string { - $guid = Item::guidFromUri($url, parse_url($url, PHP_URL_HOST)); + $guid = Item::guidFromUri($url, $host); return substr($guid, 0, 2) . '/' . substr($guid, 3, 2) . '/' . substr($guid, 5, 3) . '/' . substr($guid, 9, 2) .'/' . substr($guid, 11, 2) . '/' . substr($guid, 13, 4). '/' . substr($guid, 18) . '-'; @@ -161,7 +168,7 @@ class Avatar $dirpath .= $part . '/'; if (!file_exists($dirpath)) { - if (!@mkdir($dirpath, $dir_perm)) { + if (!@mkdir($dirpath, $dir_perm) && !file_exists($dirpath)) { Logger::warning('Directory could not be created', ['directory' => $dirpath]); } } elseif ((($old_perm = fileperms($dirpath) & 0777) != $dir_perm) && !chmod($dirpath, $dir_perm)) { @@ -244,13 +251,16 @@ class Avatar * Delete locally cached avatar pictures of a contact * * @param string $avatar - * @return void + * @return bool */ - public static function deleteCache(array $contact) + public static function deleteCache(array $contact): bool { + $existed = (self::isCacheFile($contact['photo']) || self::isCacheFile($contact['thumb']) || self::isCacheFile($contact['micro'])); self::deleteCacheFile($contact['photo']); self::deleteCacheFile($contact['thumb']); self::deleteCacheFile($contact['micro']); + + return $existed; } /**