Created
October 1, 2013 05:46
-
-
Save sisodiakaran/6774343 to your computer and use it in GitHub Desktop.
CakePHP-GravatarHelper
This file contains hidden or 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
<?php | |
class GravatarHelper extends AppHelper { | |
/** | |
* Get either a Gravatar URL or complete image tag for a specified email address. | |
* | |
* @param string $email The email address | |
* @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ] | |
* @param boole $img True to return a complete IMG tag False for just the URL | |
* @param array $atts Optional, additional key/value attributes to include in the IMG tag | |
* @return String containing either just a URL or a complete image tag | |
* @source http://gravatar.com/site/implement/images/php/ | |
*/ | |
public function image( $email, $s = 80, $img = false, $atts = array() ) { | |
$d = 'mm'; //Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] | |
$r = 'g'; //Maximum rating (inclusive) [ g | pg | r | x ] | |
$url = 'http://www.gravatar.com/avatar/'; | |
$url .= md5( strtolower( trim( $email ) ) ); | |
$url .= "?s=$s&d=$d&r=$r"; | |
if ( $img ) { | |
$url = '<img src="' . $url . '"'; | |
foreach ( $atts as $key => $val ) | |
$url .= ' ' . $key . '="' . $val . '"'; | |
$url .= ' />'; | |
} | |
return $url; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Just put
GravatarHelper.php
file in yourapp/View/Helper
folder, and add below code in your view.echo $this->Gravatar->image($email = '[email protected]', $size=200, $image_tag = TRUE, array('alt' => '...', 'title' => '...', 'class' => 'some-image-class' ));