From c644ed89a77387b7430e192b45fd5226703b8b3c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 3 Feb 2015 14:54:06 +0100 Subject: [PATCH] Add a better way to check if an avatar exists for the user --- lib/private/avatar.php | 9 +++++++++ lib/private/helper.php | 7 +------ lib/public/iavatar.php | 7 +++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/private/avatar.php b/lib/private/avatar.php index a9d9346d50..5e234d77bb 100644 --- a/lib/private/avatar.php +++ b/lib/private/avatar.php @@ -42,6 +42,15 @@ class OC_Avatar implements \OCP\IAvatar { return $avatar; } + /** + * Check if an avatar exists for the user + * + * @return bool + */ + public function exists() { + return $this->view->file_exists('avatar.jpg') || $this->view->file_exists('avatar.png'); + } + /** * sets the users avatar * @param \OC_Image|resource|string $data OC_Image, imagedata or path to set a new avatar diff --git a/lib/private/helper.php b/lib/private/helper.php index 6268bd3d42..238eab502a 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -288,12 +288,7 @@ class OC_Helper { **/ public static function userAvatarSet($user) { $avatar = new \OC_Avatar($user); - $image = $avatar->get(1); - if ($image instanceof \OC_Image) { - return true; - } else { - return false; - } + return $avatar->exists(); } /** diff --git a/lib/public/iavatar.php b/lib/public/iavatar.php index 213d2e6cef..fdb044f9e5 100644 --- a/lib/public/iavatar.php +++ b/lib/public/iavatar.php @@ -20,6 +20,13 @@ interface IAvatar { */ function get($size = 64); + /** + * Check if an avatar exists for the user + * + * @return bool + */ + public function exists(); + /** * sets the users avatar * @param Image $data mixed imagedata or path to set a new avatar