Skip to content

Instantly share code, notes, and snippets.

@ManiruzzamanAkash
Created July 1, 2018 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ManiruzzamanAkash/fcc837652af00522d1727bce686cf8bf to your computer and use it in GitHub Desktop.
Save ManiruzzamanAkash/fcc837652af00522d1727bce686cf8bf to your computer and use it in GitHub Desktop.
GravatarHelper -> 1) Check if your file has any gravatar image or not | 2) return the gravatar image for email
<?php
namespace App\Helpers;
class GravatarHelper
{
/**
* validate_gravatar
*
* Check if the email has any gravatar image or not
*
* @param string $email Email of the User
* @return boolean true, if there is an image. false otherwise
*/
public static function validate_gravatar($email) {
$hash = md5($email);
$uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404';
$headers = @get_headers($uri);
if (!preg_match("|200|", $headers[0])) {
$has_valid_avatar = FALSE;
} else {
$has_valid_avatar = TRUE;
}
return $has_valid_avatar;
}
/**
* gravatar_image
*
* Get the Gravatar Image From An Email address
*
* @param string $email User Email
* @param integer $size size of image
* @param string $d type of image if not gravatar image
* @return string gravatar image URL
*/
public static function gravatar_image($email, $size=0, $d="") {
$hash = md5($email);
$image_url = 'http://www.gravatar.com/avatar/' . $hash. '?s='.$size.'&d='.$d;
return $image_url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment