5 * Copyright 2010 (c) Alain Peyrat <aljeux@free.fr>
7 * This file is part of FusionForge
9 * FusionForge is free software; you can redistribute it
10 * and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
24 class gravatarPlugin extends Plugin {
26 function gravatarPlugin () {
28 $this->name = "gravatar" ;
29 $this->text = _('Gravatar Plugin');
30 $this->hooks[] = 'user_logo';
33 function user_logo (&$params) {
34 $user_id = $params['user_id'];
35 $size = isset($params['size'])? $params['size']: 'm';
36 $code = $this->getHtml($user_id, $size);
37 if (isset($params['content'])) {
38 $params['content'] = $code;
44 private function getEmail($user_id) {
45 $res = db_query_params('SELECT email FROM users WHERE user_id=$1', array($user_id));
47 return db_result($res, 0, 'email');
52 private function getHtml($user_id, $size) {
53 if ($email = $this->getEmail($user_id)) {
54 $hash = md5( strtolower( trim( $email ) ) );
56 $url = 'http://www.gravatar.com/avatar/';
57 if (isset($_SERVER['HTTPS']))
58 $url = 'https://secure.gravatar.com/avatar/';
71 $url .= $hash.'?s='. $usize;
72 $class = 'img-shadow-'.$size;
73 return '<div class="'.$class.'"><img src="'.$url.'" class="gravatar" alt="" /></div>';