Skip to content

Commit

Permalink
Merge pull request #13854 from owncloud/avatar-exists
Browse files Browse the repository at this point in the history
Add a better way to check if an avatar exists for the user
  • Loading branch information
Vincent Petry committed Feb 9, 2015
2 parents dc475ab + c644ed8 commit 5d8f1a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
9 changes: 9 additions & 0 deletions lib/private/avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public function get ($size = 64) {
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
Expand Down
7 changes: 1 addition & 6 deletions lib/private/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,7 @@ public static function publicPreviewIcon( $path, $token ) {
**/
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();
}

/**
Expand Down
7 changes: 7 additions & 0 deletions lib/public/iavatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5d8f1a1

Please sign in to comment.