Gravatar has a description of its php implementation on the following page:
https://en.gravatar.com/site/implement/images/php/
I'm trying to use this code to implement it in Drupal's user profiles and user pictures.
I have created a preprocess function to enable printing e-mail addresses in user-profile.tpl.php
function THEMENAME_preprocess_user_profile(&$variables) {
$account = $variables['elements']['#account'];
foreach (element_children($variables['elements']) as $key) {
$variables['user_profile'][$key] = $variables['elements'][$key];
}
$variables['user_profile']['mail'] = $account->mail;
field_attach_preprocess('user', $account, $variables['elements'], $variables);
}
Added the code to user-profile.tpl.php
print render($user_profile['mail']);
This code works what it's supposed to do - it displays mail address in the user profile. Now I need to use that address to create gravatars in profiles and in user pictures later.
I have somehow tried to connect the tutorial on Gravatar's site and this code, but without success. Here is the code (I have tried at least 20 different combinations):
$email = "['user_profile']['mail']";
$default = "http://www.somewhere.com/homestar.jpg";
$size = 40;
function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
$url = 'http://www.gravatar.com/avatar/';
$url .= md5( strtolower( trim( $email ) ) );
$url .= "?s=$s&d=$d&r=$r";
if ( $img ) {
$url = '<img src="' . $url . '"';
foreach ( $atts as $key => $val )
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
return $url;
}
As far as I understand, the problem is in this row:
$email = "['user_profile']['mail']";
What am I doing wrong and what is the right expression to put between quotes in this row?