Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Allow avatar path customization #890

Merged
merged 2 commits into from May 11, 2020
Merged

[3.x] Allow avatar path customization #890

merged 2 commits into from May 11, 2020

Conversation

derekmd
Copy link
Contributor

@derekmd derekmd commented May 10, 2020

Covers: #742

Features

✔️ Apps can disable Gravatar and stop telling its parent Automattic about user activity on /telescope requests.
✔️ Existing apps still use Gravatar.
✔️ Apps can now show local avatars taken from your own image hosting rather than using a remote service.

Configuration

namespace App\Providers;

// ...

class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
    public function register()
    {
        // ...

        Telescope::avatar(function ($id) {
            $user = User::find($id);

            return url("/assets/images/users/{$user->avatar_path}");
        });
    }

    // ...
}

Remote Service Example

To switch from Gravatar to Libravatar:

Telescope::avatar(function ($id, $email) {
    $hash = md5(Str::lower($email));

    return vsprintf('https://seccdn.libravatar.org/avatar/%s?s=200&d=%s', [
        $hash,
        urlencode(url('/assets/image/avatar-placeholder.png')),
    ]);
});

Implementation

The avatar URL is generated in PHP, only for JSON routes GET /telescope/telescope-api/{type}/{telescopeEntryId} for a preview of a single entry. i.e., this will not generate N+1 database queries when viewing a list of Telescope entries.

Add config('telescope.avatar_driver')
to control where to fetch user avatars
shown in the Telescope UI.

1. 'gravatar' looks up the avatar just-in-time
   using the email address (current default)
2. 'custom' can use a URL from your local
   application. Call IncomingEntry::avatar()
   to register a callback that returns a URL
   string for logged in $user.
3. '' empty string will disable the avatar and
   hide it from the UI. This will prevent calls
   from being made to Gravatar servers on each
   Telescope request.
Gravatar md5() calls are now done
in PHP rather than within Vue
component <preview-screen>.
@taylorotwell taylorotwell merged commit f967dd8 into laravel:3.x May 11, 2020
@taylorotwell
Copy link
Member

Changed this so that just registering a callback with Telescope::avatar(fn) will enable custom driver. No need for configuration option.

@derekmd derekmd deleted the custom-avatar branch May 11, 2020 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants