function gravatar_get_gravatar in Gravatar integration 7
Same name and namespace in other branches
- 6 gravatar.module \gravatar_get_gravatar()
Generate a gravatar URL.
Parameters
$mail: A string with an e-mail address.
$options: An associative array of additional options, with the following keys:
- 'default' A string with the default gravatar image parameter. Defaults to the result of _gravatar_get_default_image() with the current value of the gravatar_default variable.
- 'size' An integer of the desired size of the image. Defaults to smallest size of the user_picture_dimensions variable.
- 'rating' A string with a MPAA rating limit for the image. Can be 'G', 'PG', 'R', or 'X'. Defaults to 'G'.
- 'cache' A boolean if TRUE, the resulting image will be cached. Defaults to FALSE. This feature is not yet implemented.
Return value
An URL-encoded string with the gravatar image.
3 calls to gravatar_get_gravatar()
- gravatar_process_default_setting in ./
gravatar.admin.inc - Add previews for each default picture option.
- _gravatar_get_account_user_picture in ./
gravatar.module - Decide which user picture should be displayed for a user account.
- _gravatar_get_gravatar_image in ./
gravatar.module - Fetch a gravatar image.
File
- ./
gravatar.module, line 309 - Integrates gravatar service for user pictures.
Code
function gravatar_get_gravatar($mail, $options = array()) {
global $is_https;
// Merge default options.
$options += array(
'default' => _gravatar_get_default_image(gravatar_var('default')),
'size' => min(max(0, variable_get('gravatar_size', 100)), GRAVATAR_SIZE_MAX),
'rating' => variable_get('gravatar_rating', 'G'),
'cache' => FALSE,
'force default' => FALSE,
);
$hash = md5(drupal_strtolower($mail));
// @todo Implement cache fetching.
//if ($options['cache'] && gravatar_var('cache') && valid_email_address($mail)) {
// if ($cached = cache_get($hash, 'gravatar')) {
// return $cached;
// }
// elseif ($data = _gravatar_get_gravatar_image($mail)) {
// cache_set($hash, $data, 'gravatar');
// return $data;
// }
//}
$gravatar = $is_https ? variable_get('gravatar_url_ssl', GRAVATAR_URL_SSL) : variable_get('gravatar_url', GRAVATAR_URL);
$gravatar .= $hash . '.jpg';
$query = array(
'd' => $options['default'],
's' => $options['size'],
'r' => $options['rating'],
'f' => $options['force default'] ? 'y' : '',
);
$query = array_filter($query);
return url($gravatar, array(
'query' => $query,
));
}