Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ DISCORD_APP_SECRET=false

# External services such as Gravatar and Draw.IO
DISABLE_EXTERNAL_SERVICES=false
# Default GRAVATAR_URL set to Gravatar service
GRAVATAR_URL=false
# To use a different service to get user's avatar like libravatar
# Possible placeholders: %{hash} %{size} %{email}
#GRAVATAR_URL=https://seccdn.libravatar.org/avatar/%{hash}?s=%{size}&d=identicon

# LDAP Settings
LDAP_SERVER=false
Expand Down
2 changes: 1 addition & 1 deletion app/Auth/UserRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function downloadGravatarToUserAvatar(User $user)
}

try {
$avatar = Images::saveUserGravatar($user);
$avatar = Images::saveUserGravatar($user, config('services.gravatar_url'));
$user->avatar()->associate($avatar);
$user->save();
return true;
Expand Down
14 changes: 10 additions & 4 deletions app/Uploads/ImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,22 @@ protected function destroyImagesFromPath(string $path)
/**
* 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();
Expand Down
1 change: 1 addition & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'gravatar' => env('GRAVATAR', !env('DISABLE_EXTERNAL_SERVICES', false)),
'drawio' => env('DRAWIO', !env('DISABLE_EXTERNAL_SERVICES', false)),

'gravatar_url' => env('GRAVATAR_URL', false),

'callback_url' => env('APP_URL', false),

Expand Down