You are here

function _gravatar_get_default_image in Gravatar integration 5

Same name and namespace in other branches
  1. 6 gravatar.module \_gravatar_get_default_image()
  2. 7 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_admin_settings in ./gravatar.module
Administration settings form.
_gravatar_get_gravatar in ./gravatar.module
Generate a gravatar URL.

File

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

Code

function _gravatar_get_default_image($index) {
  global $base_url;
  static $defaults = array();
  if (!isset($defaults[$index])) {
    $default = NULL;
    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 = $base_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';
        break;
    }
    $defaults[$index] = $default;
  }

  // @todo Remove when stable.
  if (!isset($defaults[$index])) {
    watchdog('gravatar', t('Hit unwanted condition in _gravatar_get_default_image.'));
    return NULL;
  }
  return $defaults[$index];
}