5 * Copyright 2010 (c) Alain Peyrat <aljeux@free.fr>
6 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
8 * This file is part of FusionForge
10 * FusionForge is free software; you can redistribute it
11 * and/or modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY; without even the implied
17 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 * See the GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 class gravatarPlugin extends Plugin {
27 function __construct() {
29 $this->name = "gravatar" ;
30 $this->text = _('Gravatar Plugin');
31 $this->hooks[] = 'user_logo';
34 function user_logo (&$params) {
35 $user_id = $params['user_id'];
36 $size = isset($params['size'])? $params['size']: 'm';
37 $code = $this->getHtml($user_id, $size);
38 if (isset($params['content'])) {
39 $params['content'] = $code;
45 private function getEmail($user_id) {
46 $res = db_query_params('SELECT email FROM users WHERE user_id=$1', array($user_id));
48 return db_result($res, 0, 'email');
53 private function getHtml($user_id, $size) {
54 if ($email = $this->getEmail($user_id)) {
55 $hash = md5( strtolower( trim( $email ) ) );
57 $url = 'http://www.gravatar.com/avatar/';
58 if (isset($_SERVER['HTTPS']))
59 $url = 'https://secure.gravatar.com/avatar/';
72 $url .= $hash.'?s='. $usize;
73 $class = 'img-shadow-'.$size;
74 $code = '<div class="'.$class.'"><img src="'.$url.'" class="gravatar" alt="" /></div>';
76 $code .= '<div class="align-center"><i><a href="http://www.gravatar.com/">'._('Change face').'</a></i></div>';