]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Gravatar/GravatarPlugin.php
Merge commit 'refs/merge-requests/157' of git://gitorious.org/statusnet/mainline...
[quix0rs-gnu-social.git] / plugins / Gravatar / GravatarPlugin.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2009,2011 StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /**
21  * @package GravatarPlugin
22  * @maintainer Eric Helgeson <erichelgeson@gmail.com>
23  */
24
25 if (!defined('STATUSNET') && !defined('LACONICA')) {
26     // This check helps protect against security problems;
27     // your code file can't be executed directly from the web.
28     exit(1);
29 }
30
31 class GravatarPlugin extends Plugin
32 {
33     function onEndProfileGetAvatar($profile, $size, &$avatar)
34     {
35         if (empty($avatar)) {
36             $user = $profile->getUser();
37             if (!empty($user) && !empty($user->email)) {
38                 // Fake one!
39                 $avatar = new Avatar();
40                 $avatar->width = $avatar->height = $size;
41                 $avatar->url = $this->gravatar_url($user->email, $size);
42                 return false;
43             }
44         }
45
46         return true;
47     }
48
49     function gravatar_url($email, $size)
50     {
51         $url = "https://secure.gravatar.com/avatar.php?gravatar_id=".
52                 md5(strtolower($email)).
53                 "&default=".urlencode(Avatar::defaultImage($size)).
54                 "&size=".$size;
55             return $url;
56     }
57
58     function onPluginVersion(&$versions)
59     {
60         $versions[] = array('name' => 'Gravatar',
61                             'version' => STATUSNET_VERSION,
62                             'author' => 'Eric Helgeson, Evan Prodromou',
63                             'homepage' => 'http://status.net/wiki/Plugin:Gravatar',
64                             'rawdescription' =>
65                             // TRANS: Plugin decsription.
66                             _m('The Gravatar plugin allows users to use their <a href="http://www.gravatar.com/">Gravatar</a> with StatusNet.'));
67
68         return true;
69     }
70 }