2009-12-10 03:32:57 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
2011-04-14 16:47:20 +01:00
|
|
|
* Copyright (C) 2009,2011 StatusNet, Inc.
|
2009-12-10 03:32:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package GravatarPlugin
|
|
|
|
* @maintainer Eric Helgeson <erichelgeson@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
|
|
|
// This check helps protect against security problems;
|
|
|
|
// your code file can't be executed directly from the web.
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
class GravatarPlugin extends Plugin
|
|
|
|
{
|
2011-04-14 16:38:41 +01:00
|
|
|
function onEndProfileGetAvatar($profile, $size, &$avatar)
|
|
|
|
{
|
2011-04-14 18:06:23 +01:00
|
|
|
if (empty($avatar)) {
|
2013-09-09 20:35:16 +01:00
|
|
|
try {
|
|
|
|
$user = $profile->getUser();
|
|
|
|
if (!empty($user->email)) {
|
|
|
|
// Fake one!
|
|
|
|
$avatar = new Avatar();
|
|
|
|
$avatar->width = $avatar->height = $size;
|
|
|
|
$avatar->url = $this->gravatar_url($user->email, $size);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (NoSuchUserException $e) {
|
|
|
|
return true;
|
2011-04-14 16:38:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-07 04:48:00 +01:00
|
|
|
function gravatar_url($email, $size)
|
|
|
|
{
|
2010-10-27 04:56:59 +01:00
|
|
|
$url = "https://secure.gravatar.com/avatar.php?gravatar_id=".
|
2009-12-10 03:32:57 +00:00
|
|
|
md5(strtolower($email)).
|
|
|
|
"&default=".urlencode(Avatar::defaultImage($size)).
|
|
|
|
"&size=".$size;
|
|
|
|
return $url;
|
|
|
|
}
|
2010-01-09 23:58:40 +00:00
|
|
|
|
|
|
|
function onPluginVersion(&$versions)
|
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'Gravatar',
|
|
|
|
'version' => STATUSNET_VERSION,
|
2011-04-14 16:38:41 +01:00
|
|
|
'author' => 'Eric Helgeson, Evan Prodromou',
|
2010-01-09 23:58:40 +00:00
|
|
|
'homepage' => 'http://status.net/wiki/Plugin:Gravatar',
|
|
|
|
'rawdescription' =>
|
2011-04-08 17:46:41 +01:00
|
|
|
// TRANS: Plugin decsription.
|
2010-01-09 23:58:40 +00:00
|
|
|
_m('The Gravatar plugin allows users to use their <a href="http://www.gravatar.com/">Gravatar</a> with StatusNet.'));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-18 16:14:00 +01:00
|
|
|
}
|