Skip to content

Commit

Permalink
Validate Gravatars; Return NULL when none is set.
Browse files Browse the repository at this point in the history
  • Loading branch information
evansims committed Mar 31, 2013
1 parent ed73d1f commit 25cb281
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
2 changes: 0 additions & 2 deletions lib/api.2-0.php
Expand Up @@ -302,7 +302,6 @@
if(HTTP_METHOD == 'GET') {

$avatar = $User->Avatar();
if(!$avatar) $avatar = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($User->Email()))) . '?r=PG&s=200&d=404';

Response::Send(200, RESP_OK, array(
'avatar' => $avatar
Expand Down Expand Up @@ -639,7 +638,6 @@
if(HTTP_METHOD == 'GET') {

$avatar = $User->Avatar();
if(!$avatar) $avatar = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($User->Email()))) . '?r=PG&s=200&d=404';

if(isSessionCleared($User->Hash())) {
// Get information about user.
Expand Down
38 changes: 37 additions & 1 deletion lib/class.users.php
Expand Up @@ -382,7 +382,43 @@ public function PhoneConfirmed($update = null)

public function Avatar($update = null)
{
return $this->__Property('avatar', $update);
$avatar = $this->__Property('avatar', $update);

if(!$avatar) {
$avatar = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($this->Email()))) . '?r=PG&s=200&d=404';

$gravatar = curl_init();
curl_setopt_array($gravatar, array(
CURLOPT_URL => $avatar,
CURLOPT_HEADER => TRUE,
CURLOPT_NOBODY => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_MAXREDIRS => 10,
CURLOPT_AUTOREFERER => TRUE,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 5
));

$r = array();
$r['body'] = curl_exec($gravatar);
$r['header'] = curl_getinfo($gravatar);
$r['error'] = curl_errno($gravatar);
curl_close($gravatar);

if(!$r['error']) {
if(isset($r['header']['http_code']) && isset($r['header']['content_type'])) {
if($r['header']['http_code'] == 200 && substr($r['header']['content_type'], 0, 6) == "image/") {
return $avatar;
}
}
}

return NULL;
}

return $avatar;
}

public function Question($update = null)
Expand Down

0 comments on commit 25cb281

Please sign in to comment.