TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack (13) Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 01-08-2008, 08:54 PM   13 links from elsewhere to this Post. Click to view. #1 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Box Gravatar Wrapper Class

Newest Version: 1.2

I made some changes to the way this class works. Although there are some comments below that say Gravatar changed their API somewhat. Though I don't really see where. The changes I made are as follows:

I added 4 functions instead of the global constants which were being used instead. I removed setRating($szArg) and added 4 separate functions:
  • setRatingAsG
  • setRatingAsPG
  • setRatingAsR
  • setRatingAsX

These all work in the same fashion as setRating() described below. I also added 3 functions for changing the default image if no image is available, and no custom image was supplied:
  • setDefaultImageAsIdentIcon
  • setDefaultImageAsMonsterId
  • setDefaultImageAsWavatar

Last of all, I update the example index.php so that it provides a working example.

Download version 1.2 below!

Version 1.0 (Other versions below)

This class is merely a wrapper class for Gravatar. It's dead simple to use, as is Gravatar itself.

Implementing

Each class member returns $this and so you may chain the methods. The following is an example of how to use the Gravatar wrapper class:

php Code:
$pAvatar = new TalkPHP_Gravatar();
   
echo $pAvatar   -> setEmail('example@example.com')
                ->  setSize(80)
                ->  setRating(GRAVATAR_RATING_PG)
                ->  getAvatar();

The above code will simply return you the URL to the avatar on Gravatar. For it to output an image you need to put it in an <img> node like the following:

html4strict Code:
<img src="<?php echo $pAvatar->getAvatar(); ?>" alt="Gravatar" />

Parameters

There is a function for each parameter that you may set in order to modify the returned image resource. These are as follows:
  • setImage: Sets the default image for if the email addresses specified does not have a Gravatar image. This must be supplied as a FQDN link to an image resource.
  • setEmail: This is the email address which you are attempting to acquire the Gravatar for. This should be a properly formatted email address.
  • setSize: You may set the return size for the Gravatar. The Gravatar documentation recommends anywhere from 1 to 80 pixels square. This function accepts only 1 parameter as all avatars are square.
  • setRating: This function allows you to control the maximum rating of Gravatar that is acquired. There are numerous constants that can be passed into this function. For example, if I set a maximum of PG, then only G and PG images will be returned.

The following is a list of the 4 constants that can be passed into the setRating function:
  • GRAVATAR_RATING_G
  • GRAVATAR_RATING_PG
  • GRAVATAR_RATING_R
  • GRAVATAR_RATING_X

Installation

This is a simple one file script and therefore is lightweight and fast. Your web host must support PHP 5. To get the script working you will need to include the script into your project like so:

php Code:
include_once('./TalkPHP_Gravatar.php');

You're then good to go! If you have any issues or general queries or feature suggestions, please respond in this thread and I shall do my utmost.
Attached Files
File Type: zip TalkPHP.com_Gravatar.version.1_0.zip (789 Bytes, 501 views)
File Type: rar TalkPHP.com_Gravatar.version-1.2.rar (801 Bytes, 231 views)
File Type: zip TalkPHP.com_Gravatar.version-1.2.zip (861 Bytes, 1123 views)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.

Last edited by Wildhoney : 12-05-2008 at 04:35 PM.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following 2 Users Say Thank You to Wildhoney For This Useful Post:
ciprianmp (06-17-2008), iflashlord (05-23-2009)
 


LinkBacks (?)
LinkBack to this Thread: http://www.talkphp.com/script-giveaway/1905-gravatar-wrapper-class.html
Posted By For Type Date
Untitled document This thread Refback 01-13-2008 10:01 PM
Gravatar 3.0, Powered by Automattic | SYP This thread Refback 01-13-2008 05:14 AM
ShadowReality This thread Refback 01-10-2008 03:06 PM
GRavatar plugin for WordPress and WordPress-MU | Ring Of Blogs This thread Refback 01-09-2008 10:31 PM
Automattic Acquires Gravatar | CenterNetworks - Web 2.0 News, Opinions and Insights from New York This thread Refback 01-09-2008 09:00 PM
Untitled document This thread Refback 01-09-2008 03:43 PM
Support WordPress by Displaying Gravatars On Your Blog This thread Refback 01-09-2008 01:35 PM
Now Gravatar Powered. | Act of War: Warfare Re-defined This thread Refback 01-09-2008 07:08 AM
Untitled document This thread Refback 01-09-2008 07:05 AM
Untitled document This thread Refback 01-09-2008 06:22 AM
Do you have your gravatar yet ? This thread Refback 01-09-2008 05:12 AM
Untitled document This thread Refback 01-09-2008 04:31 AM
Untitled document This thread Refback 01-09-2008 04:12 AM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:28 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design