Part of the EllisLab Network
   
 
Helper: Gravatar (Revised)
Posted: 08 July 2007 12:04 PM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  18
Joined  06-26-2007

Introduction

The purpose of the gravatar helper is to help you quickly and easily implement gravatars on your own website by constructing the 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.

Installation

1. Unpack the contents of the archive to an easily accessible directory, leaving the path names intact.

2. Copy the contents of the upload directory to your web server where CodeIgniter is installed, taking special care to preserve the directory structure.

Usage

Using the gravatar helper in your applications is very simple and straightforward. To begin using it, add the following code to your controller:

$this->load->helper( 'gravatar' );

Next, add the following bit of code to your view where you would like to display the gravatar:

<?php echo gravatar( "you@domain.com" ); ?>

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.

Rating

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.

Size

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 down-sampled using bicubic resampling before output.

Default

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.

<?php echo gravatar( "you@domain.com", "PG", "40", "http://www.domain.com/default.gif" ); ?>

In turn, the results would be:

http://gravatar.com/avatar.php?gravatar_id=0ee5f81c11737062773c780c611ab0d5&rating=PG&size=40&default=http://www.domain.com/default.gif

Typically, you should use the examples above to construct an <IMG> element to display a user’s gravatar like so:

<img src="<?php echo gravatar( "you@domain.com" ); ?>" alt="Gravatar">

Changelog

Version 1.0
Release Date: Wednesday, August 08, 2007

  * Reformulated code to generate URLs only, omitting the markup.
  * Created user documentation.

Version 1.0 Beta
Release Date: Sunday, July 08, 2007

Download

Unix/Linux Users:
ci_helper_gravatar-1.0.tar.gz

Windows Users:
ci_helper_gravatar-1.0.zip

Profile
 
 
Posted: 08 July 2007 02:36 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  755
Joined  06-11-2007

Good stuff, even though the code is simple it is well packaged and well documented. Will be using it, thanks.

 Signature 

PhilSturgeon.co.uk - Personal blog site using my new CMS.
StyleDNA Ltd - CodeIgnitor Web Development, Hosting and Design.
_________________

Helpers: Asset Helper, BBCode Helper
Libraries: Layout Lib
_________________

Theres no place like 127.0.0.1

Profile
 
 
Posted: 08 July 2007 11:48 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  18
Joined  06-26-2007
thepyromaniac - 08 July 2007 02:36 PM
Good stuff, even though the code is simple it is well packaged and well documented. Will be using it, thanks.

Thanks!

Anywhere there is the need for an avatar, I prefer to use gravatars. This way I can encourage the use of their services to ensure they’ll be around for awhile through use and advertisement. But this aside, it’s also much easier to fetch their gravatar than it is to create an avatar storage system and maintain the users’ avatars locally (not that it is hard). Gravatar is a great service.

Profile
 
 
Posted: 17 July 2007 08:14 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  08-22-2006

I’ve written my own but it’s too messy to be posted, so just on suggestion, you should provide a method (or public member) to return just the image url, so that way you can be more flexible when using it, background image for example.

 Signature 

Don’t argue with an idiot, people watching may not be able to tell the difference.


marcoss
http://defmay.com
http://fenix.st

Profile
 
 
Posted: 17 July 2007 11:25 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Avatar
Total Posts:  18
Joined  06-26-2007

It would probably just be best to omit all of the markup. I’ve noticed a few issues myself. Issues like the fact that this assumes you are using XHTML instead of HTML. I’ve already gone the route of stripping out the markup myself.

Updated the code above in the initial post. Thanks for all your suggestions.

Profile
 
 
Posted: 30 August 2007 10:38 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Avatar
Total Posts:  18
Joined  06-26-2007

The above documentation and the source is now also available on the CodeIgniter wiki: http://codeigniter.com/wiki/Gravatars/

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 62653 Total Logged-in Users: 35
Total Topics: 77188 Total Anonymous Users: 0
Total Replies: 416683 Total Guests: 215
Total Posts: 493871    
Members ( View Memberlist )