# 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
/**
* 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();
'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),