Skip to content

Commit

Permalink
New image default set and handle forcing default avatars
Browse files Browse the repository at this point in the history
The new image default set is "retro", recently added by the gravatar team.  It generates a unique 8-bit pixel art image based on the email hash.
To force default avatars, just specify an empty string for the email parameter of get/buildGravatarURL
  • Loading branch information
katanacrimson committed Oct 7, 2011
1 parent 7ba6734 commit e9117c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions Gravatar.php
Expand Up @@ -134,7 +134,7 @@ public function setDefaultImage($image)

// Check $image against recognized gravatar "defaults", and if it doesn't match any of those we need to see if it is a valid URL.
$_image = strtolower($image);
$valid_defaults = array('404' => 1, 'mm' => 1, 'identicon' => 1, 'monsterid' => 1, 'wavatar' => 1);
$valid_defaults = array('404' => 1, 'mm' => 1, 'identicon' => 1, 'monsterid' => 1, 'wavatar' => 1, 'retro' => 1);
if(!isset($valid_defaults[$_image]))
{
if(!filter_var($image, FILTER_VALIDATE_URL))
Expand Down Expand Up @@ -237,14 +237,18 @@ public function buildGravatarURL($email, $hash_email = true)
}

// Tack the email hash onto the end.
if($hash_email == true)
if($hash_email == true && !empty($email))
{
$url .= $this->getEmailHash($email);
}
else
elseif(!empty($email))
{
$url .= $email;
}
else
{
$url .= str_repeat('0', 32);
}

// Check to see if the param_cache property has been populated yet
if($this->param_cache === NULL)
Expand All @@ -262,8 +266,15 @@ public function buildGravatarURL($email, $hash_email = true)
$this->params_cache = (!empty($params)) ? '?' . implode('&', $params) : '';
}

// Handle "null" gravatar requests.
$tail = '';
if(empty($email))
{
$tail = !empty($this->params_cache) ? '&f=y' : '?f=y';
}

// And we're done.
return $url . $this->params_cache;
return $url . $this->params_cache . $tail;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion README.markdown
Expand Up @@ -36,7 +36,7 @@ We'll assume you're using this git repository as a git submodule, and have it lo
### setting the default image

Gravatar provides several pre-fabricated default images for use when the email address provided does not have a gravatar or when the gravatar specified exceeds your maximum allowed content rating.
The provided images are 'mm', 'identicon', 'monsterid', and 'wavatar'. To set the default iamge to use on your site, use the method `\emberlabs\GravatarLib\Gravatar->setDefaultImage()`
The provided images are 'mm', 'identicon', 'monsterid', 'retro', and 'wavatar'. To set the default iamge to use on your site, use the method `\emberlabs\GravatarLib\Gravatar->setDefaultImage()`
In addition, you can also set your own default image to be used by providing a valid URL to the image you wish to use.

Here are a couple of examples...
Expand Down

2 comments on commit e9117c5

@Cgood007
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cgood007
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to open this

Please sign in to comment.