You are here

function _gravatar_get_default_image in Gravatar integration 7

Same name and namespace in other branches
  1. 5 gravatar.module \_gravatar_get_default_image()
  2. 6 gravatar.module \_gravatar_get_default_image()

Get the default gravatar image.

Parameters

$index: An integer index for selection.

Return value

The default image for use in a Gravatar avatar URL.

2 calls to _gravatar_get_default_image()
gravatar_get_gravatar in ./gravatar.module
Generate a gravatar URL.
gravatar_process_default_setting in ./gravatar.admin.inc
Add previews for each default picture option.

File

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

Code

function _gravatar_get_default_image($index) {
  global $base_url;
  static $defaults = array();
  if (!isset($defaults[$index])) {
    switch ($index) {
      case GRAVATAR_DEFAULT_GLOBAL:
        $default = variable_get('user_picture_default', '');
        if ($default && !valid_url($default, TRUE)) {

          // Convert a relative global default picture URL to an absolute URL.
          $default = file_create_url($default);
        }
        break;
      case GRAVATAR_DEFAULT_MODULE:
        $default = $base_url . '/' . drupal_get_path('module', 'gravatar') . '/avatar.png';
        break;
      case GRAVATAR_DEFAULT_MODULE_CLEAR:
        $default = $base_url . '/' . drupal_get_path('module', 'gravatar') . '/avatar-clear.png';
        break;
      case GRAVATAR_DEFAULT_IDENTICON:
        $default = 'identicon';
        break;
      case GRAVATAR_DEFAULT_WAVATAR:
        $default = 'wavatar';
        break;
      case GRAVATAR_DEFAULT_MONSTERID:
        $default = 'monsterid';
        break;
      case GRAVATAR_DEFAULT_LOGO:
        $default = '';

        //$default = $base_url . '/' . drupal_get_path('module', 'gravatar') . '/gravatar.jpg';
        break;
      case GRAVATAR_DEFAULT_MYSTERY_MAN:
      case GRAVATAR_DEFAULT_RETRO:
      case 404:
        $default = $index;
        break;
      default:

        // @todo Remove when stable.
        $default = '';
        trigger_error('Unwanted condition ' . check_plain(var_export($index, TRUE)) . ' in _gravatar_get_default_image().');
    }
    $defaults[$index] = $default;
  }
  return $defaults[$index];
}