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:
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:
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.
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:
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:
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:
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.
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.
The Following 2 Users Say Thank You to Wildhoney For This Useful Post: