Skip to content

Commit

Permalink
Import Gravatar from BNETDocs/bnetdocs-web@0a93306
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Aug 21, 2016
1 parent 8df7989 commit 8b7dd82
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/libraries/Gravatar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace CarlBennett\MVC\Libraries;

class Gravatar {

const GRAVATAR_BASE_URL = "//www.gravatar.com/avatar/";

protected $email;

public function __construct($email) {
$this->email = $email;
}

public function getEmail() {
return $this->email;
}

public function getHash() {
return hash("md5", strtolower(trim($this->email)));
}

public function getUrl(
$size = null, $default = null, $forcedefault = null, $rating = null
) {
$url = self::GRAVATAR_BASE_URL . $this->getHash();
$args = [];
if (!is_null($size)) $args["s"] = $size;
if (!is_null($default)) $args["d"] = $default;
if (!is_null($forcedefault)) $args["f"] = $forcedefault;
if (!is_null($rating)) $args["r"] = $rating;
$query = http_build_query($args);
if ($query) $url .= "?" . $query;
return $url;
}
}

0 comments on commit 8b7dd82

Please sign in to comment.