Updated gravatars to use identicon when email address is redacted

This commit is contained in:
Nelson LaQuet 2015-05-20 04:14:06 -05:00
parent a57d081fec
commit 35af7bb681
2 changed files with 14 additions and 16 deletions

View file

@ -4,26 +4,18 @@
use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\URL;
class Gravatar { class Gravatar {
/** public static function getUrl($email, $size = 80, $default = null, $rating = 'g') {
 * Returns a Gravatar URL
 *
 * @param string $email The email address
 * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
 * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
 * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
 * @return Gravatar URL
 * @source http://gravatar.com/site/implement/images/php/
 */
public static function getUrl( $email, $s = 80, $d = 'mm', $r = 'g') {
$url = 'https://www.gravatar.com/avatar/'; $url = 'https://www.gravatar.com/avatar/';
$url .= md5( strtolower( trim( $email ) ) ); $url .= md5( strtolower( trim( $email ) ) );
$url .= "?s=$s&r=$r"; $url .= "?s=$size&r=$rating";
if (!Config::get('app.debug')) { if ($default != null)
$url .= "&d=" . $default;
else {
$size = 'normal'; $size = 'normal';
if ($s == 50) if ($size == 50)
$size = 'thumbnail'; $size = 'thumbnail';
else if ($s == 100) else if ($size == 100)
$size = 'small'; $size = 'small';
$url .= "&d=" . urlencode(URL::to('/images/icons/profile_' . $size . '.png')); $url .= "&d=" . urlencode(URL::to('/images/icons/profile_' . $size . '.png'));

View file

@ -66,9 +66,15 @@
if (!$this->uses_gravatar) if (!$this->uses_gravatar)
return $this->avatar->getUrl($type); return $this->avatar->getUrl($type);
if ($this->email == "redacted@example.net") {
return Gravatar::getUrl($this->id . "", Image::$ImageTypes[$type]['width'], "identicon");
}
$email = $this->gravatar; $email = $this->gravatar;
if (!strlen($email))
if (!strlen($email)) {
$email = $this->email; $email = $this->email;
}
return Gravatar::getUrl($email, Image::$ImageTypes[$type]['width']); return Gravatar::getUrl($email, Image::$ImageTypes[$type]['width']);
} }