-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Gravatars
[size=4]Introduction[/size]
The purpose of the gravatar helper is to help you quickly and easily implement gravatars on your own website by constructing the Uniform Resource Identifier (URI) that is necessary to display the user's gravatar.
This simple guide will assist you in installing the gravatar helper as well as illustrate its use.
[size=4]Source[/size]
[pre][code] <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
- CodeIgniter
- An open source application development framework for PHP 4.3.2 or newer
- @package CodeIgniter
- @author Rick Ellis
- @copyright Copyright (c) 2006, EllisLab, Inc.
- @license http://www.codeigniter.com/user_guide/license.html
- @link http://www.codeigniter.com
- @since Version 1.0
- @filesource */
/**
- CodeIgniter Gravatar Helper
- @package CodeIgniter
- @subpackage Helpers
- @category Helpers
- @author David Cassidy */
/**
-
Gravatar
-
Fetches a gravatar from the Gravatar website using the specified params
-
@access public
-
@param string
-
@param string
-
@param integer
-
@param string
-
@return string */ function gravatar( $email, $rating = 'X', $size = '80', $default = 'http://gravatar.com/avatar.php' ) {
$email = md5( $email );
return "http://gravatar.com/avatar.php?gravatar_id=" .$email."&rating=" .$rating."&size=" .$size."&default=" .$default; }
?> [/code][/pre]
[size=4]Usage[/size]
Using the gravatar helper in your applications is very simple and straightforward. To begin using it, add the following code to your controller:
[code]$this->load->helper( 'gravatar' );[/code]
Next, add the following bit of code to your view where you would like to display the gravatar:
[code]<?php echo gravatar( "you@domain.com" ); ?>[/code]
The above, will load the gravatar for the specified email address. Optionally, you may want to specify some additional parameters to impose limitations on the gravatar image.
[b]Rating[/b] Defines a maximum rating for the image's content. If the owner has flagged the image with a rating higher than that specified, the default image will instead be used. Acceptable values are G, PG, R, or X.
[b]Size[/b] Defines the desired height and width of the image in pixels, with acceptable values being between 1 and 80. Specifying a size smaller than 80 will result in the original gravatar image to be downsampled using bicubic resampling before output.
[b]Default[/b] The default parameter allows you to specify the URL to an image that will be used as the default if the query fails to locate a gravatar for the given email address. Additionally, if a user's gravatar exceeds the rating limit defined by the "rating" parameter, this is the image that will instead be shown.
Below is an example illustrating the use of these optional parameters.
[code]<?php echo gravatar( "you@domain.com", "PG", "40", "http://www.domain.com/default.gif" ); ?>[/code]
In turn, the results would be:
Typically, you should use the examples above to construct an element to display a user's gravatar like so:
[code]<img src="<?php echo gravatar( "you@domain.com" ); ?>" alt="Gravatar">[/code]