X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContact%2FAvatar.php;h=e039a52799fc524e98f605cbb00ad51e198307a1;hb=f609e38600f54fe8465d1194008d823103f41baa;hp=f43ed7b8c7931b2351113174f267f4a99be6fac3;hpb=8b7cb5d9efeab580c2592e0fbe301f7142b73a3d;p=friendica.git diff --git a/src/Contact/Avatar.php b/src/Contact/Avatar.php index f43ed7b8c7..e039a52799 100644 --- a/src/Contact/Avatar.php +++ b/src/Contact/Avatar.php @@ -1,6 +1,6 @@ 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); @@ -125,7 +127,7 @@ class Avatar private static function getFilename(string $url): string { - $guid = Item::guidFromUri($url, parse_url($url, PHP_URL_HOST)); + $guid = Item::guidFromUri($url); 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,15 +163,15 @@ 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)) { - Logger::notice('Directory permissions could not be changed', ['directory' => $dirpath, 'old' => $old_perm, 'new' => $dir_perm]); + Logger::warning('Directory permissions could not be changed', ['directory' => $dirpath, 'old' => $old_perm, 'new' => $dir_perm]); } if ((($old_group = filegroup($dirpath)) != $group) && !chgrp($dirpath, $group)) { - Logger::notice('Directory group could not be changed', ['directory' => $dirpath, 'old' => $old_group, 'new' => $group]); + Logger::warning('Directory group could not be changed', ['directory' => $dirpath, 'old' => $old_group, 'new' => $group]); } } @@ -181,11 +183,11 @@ class Avatar $old_group = filegroup($filepath); if (($old_perm != $file_perm) && !chmod($filepath, $file_perm)) { - Logger::notice('File permissions could not be changed', ['file' => $filepath, 'old' => $old_perm, 'new' => $file_perm]); + Logger::warning('File permissions could not be changed', ['file' => $filepath, 'old' => $old_perm, 'new' => $file_perm]); } if (($old_group != $group) && !chgrp($filepath, $group)) { - Logger::notice('File group could not be changed', ['file' => $filepath, 'old' => $old_group, 'new' => $group]); + Logger::warning('File group could not be changed', ['file' => $filepath, 'old' => $old_group, 'new' => $group]); } DI::profiler()->stopRecording(); @@ -244,13 +246,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; } /** @@ -263,7 +268,7 @@ class Avatar { $localFile = self::getCacheFile($avatar); if (!empty($localFile)) { - unlink($localFile); + @unlink($localFile); Logger::debug('Unlink avatar', ['avatar' => $avatar]); } }