You are here

function _gravatar_get_gravatar in Gravatar integration 5

Generate a gravatar URL.

Parameters

$options: An associative array of additional options, with the following keys:

  • 'mail' A string with an e-mail address. Defaults to a random number.
  • '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'.

Return value

An URL-encoded string with the gravatar image.

2 calls to _gravatar_get_gravatar()
gravatar_admin_settings in ./gravatar.module
Administration settings form.
gravatar_comment in ./gravatar.module
Implementation of hook_comment().

File

./gravatar.module, line 186
Integrates gravatar service for comment user pictures.

Code

function _gravatar_get_gravatar($options = array()) {

  // Merge default options.
  $options += array(
    'mail' => mt_rand(),
    'default' => _gravatar_get_default_image(gravatar_var('default')),
    'size' => _gravatar_get_size(),
    'rating' => gravatar_var('rating'),
  );
  $hash = md5(drupal_strtolower($options['mail']));
  $gravatar = gravatar_var('url') . $hash;
  $gravatar .= '?d=' . urlencode($options['default']);
  $gravatar .= '&s=' . $options['size'];
  $gravatar .= '&r=' . $options['rating'];
  return $gravatar;
}