-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import Gravatar from BNETDocs/bnetdocs-web@0a93306
- Loading branch information
1 parent
8df7989
commit 8b7dd82
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |