summaryrefslogtreecommitdiffstats
path: root/extensions/Gravatar/Extension.pm
blob: 1be0d4454b0640176dda661b90b9dcda47976a85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::Extension::Gravatar;

use strict;
use warnings;

use base qw(Bugzilla::Extension);

use Bugzilla::User::Setting;
use Digest::MD5 qw(md5_hex);

BEGIN {
    *Bugzilla::User::gravatar = \&_user_gravatar;
}

sub _user_gravatar {
    my ($self) = @_;
    if (!$self->{gravatar}) {
        if ($self->setting('show_my_gravatar') eq 'On') {
            (my $email = $self->email) =~ s/\+(.*?)\@/@/;
            $self->{gravatar} = 'https://secure.gravatar.com/avatar/' . md5_hex(lc($email)) . '?size=32&d=mm';
        } else {
            $self->{gravatar} = 'extensions/Gravatar/web/default.jpg';
        }
    }
    return $self->{gravatar};
}

sub install_before_final_checks {
    my ($self, $args) = @_;
    add_setting('show_gravatars', ['On', 'Off'], 'Off');
    add_setting('show_my_gravatar', ['On', 'Off'], 'On');
}

__PACKAGE__->NAME;