mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
Merge branch 'custom-avatar-provider' of git://github.com/Vinrobot/BookStack into Vinrobot-custom-avatar-provider
This commit is contained in:
@@ -251,7 +251,7 @@ class UserRepo
|
||||
}
|
||||
|
||||
try {
|
||||
$avatar = Images::saveUserGravatar($user);
|
||||
$avatar = Images::saveUserGravatar($user, config('services.gravatar_url'));
|
||||
$user->avatar()->associate($avatar);
|
||||
$user->save();
|
||||
return true;
|
||||
|
@@ -281,16 +281,22 @@ class ImageService extends UploadService
|
||||
/**
|
||||
* Save a gravatar image and set a the profile image for a user.
|
||||
* @param \BookStack\Auth\User $user
|
||||
* @param null|string $gravatarUrl
|
||||
* @param int $size
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function saveUserGravatar(User $user, $size = 500)
|
||||
public function saveUserGravatar(User $user, $gravatarUrl, $size = 500)
|
||||
{
|
||||
$emailHash = md5(strtolower(trim($user->email)));
|
||||
$url = 'https://www.gravatar.com/avatar/' . $emailHash . '?s=' . $size . '&d=identicon';
|
||||
if (!is_string($gravatarUrl) || empty($gravatarUrl)) {
|
||||
$gravatarUrl = 'https://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon';
|
||||
}
|
||||
$email = strtolower(trim($user->email));
|
||||
$gravatarUrl = str_replace('%{hash}', md5($email), $gravatarUrl);
|
||||
$gravatarUrl = str_replace('%{size}', $size, $gravatarUrl);
|
||||
$gravatarUrl = str_replace('%{email}', urlencode($email), $gravatarUrl);
|
||||
$imageName = str_replace(' ', '-', $user->name . '-gravatar.png');
|
||||
$image = $this->saveNewFromUrl($url, 'user', $imageName);
|
||||
$image = $this->saveNewFromUrl($gravatarUrl, 'user', $imageName);
|
||||
$image->created_by = $user->id;
|
||||
$image->updated_by = $user->id;
|
||||
$image->save();
|
||||
|
Reference in New Issue
Block a user