You are here

function _gravatar_get_account_user_picture in Gravatar integration 6

Same name and namespace in other branches
  1. 7 gravatar.module \_gravatar_get_account_user_picture()

Decide which user picture should be displayed for a user account.

Parameters

$account: A user object.

Return value

A string with the path to the user's picture.

1 call to _gravatar_get_account_user_picture()
gravatar_preprocess_user_picture in ./gravatar.module
Override template_preprocess_user_picture() to display user pictures with Gravatar integration.

File

./gravatar.module, line 164
Integrates gravatar service for user pictures.

Code

function _gravatar_get_account_user_picture($account) {
  if (!empty($account->picture) && file_exists($account->picture)) {

    // If the user has an uploaded picture, use it first.
    return file_create_url($account->picture);
  }
  elseif (!user_access('use gravatar', $account) || user_access('disable own gravatar', $account) && isset($account->gravatar) && !$account->gravatar) {

    // If the user does not have access to use gravatars or has gravatars
    // disabled for their account, use the global default image.
    return variable_get('user_picture_default', '');
  }
  else {

    // Otherwise, show a gravatar with the appropraite default picture.
    $mail = $account->mail;
    $options = array();
    if (empty($mail)) {
      $options['force default'] = TRUE;

      // Use various fallbacks to provide a unique default gravatar.
      if (!empty($account->hostname)) {
        $mail = $account->hostname;
      }
      elseif (!empty($account->homepage)) {
        $mail = $account->homepage;
      }
      else {
        $mail = serialize($account);
      }
    }
    return gravatar_get_gravatar($mail, $options);
  }
}