]> BookStack Code Mirror - bookstack/commitdiff
Added config to change Gravatar URL 1111/head
authorVinrobot <redacted>
Thu, 8 Nov 2018 08:14:11 +0000 (09:14 +0100)
committerVinrobot <redacted>
Sat, 10 Nov 2018 15:11:11 +0000 (16:11 +0100)
.env.example
app/Auth/UserRepo.php
app/Uploads/ImageService.php
config/services.php

index eda20ea261bb9147a17dd451877fc42b5896311f..06394f54fe01c0e17067bac13ce3b073c66917fd 100644 (file)
@@ -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
index 7c88badb843297a37901a70883179c9a20757447..abff7c6416c5a43177a7e2ddc51a71a10365551b 100644 (file)
@@ -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;
index f109db60068f5b919509a450df371bc8bd50eeee..b65a476f44beed5ac7290410656030d4c150b076 100644 (file)
@@ -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();
index 711040386a9ac17c954ad694ac3aece8b11a06de..b8f152124ae4dc93fddd10ab2d3fbd96e2e56be8 100644 (file)
@@ -19,6 +19,7 @@ return [
     '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),