Version 1.1
I actually decided to work on version 1.1 which contains a cache built in. It recognises the avatar sizes, and will download a fresh copy from the Gravatar server when the current avatar expires. This can easily be changed by opening up the
TalkPHP_Gravatar_Cache.php file and modifying the class constant at the top. It is currently set at 5 days.
There are only a couple of additions to the above code that you need to concern yourself with - one of which is you now have to include 2 files. I've separated the classes into 2 classes to make them more manageable. The
index.php file shows you how to include the second file, but it's nothing complicated in the least:
php Code:
include_once('./TalkPHP_Gravatar.php');
include_once('./TalkPHP_Gravatar_Cache.php');
The functionality still performs exactly the same as version 1.0 above. There is a directory called
/cache/ which should be writeable, so don't forget to set the correct permissions on that. Typically 777.
Last but not least, for the more technically minded, I have added an exception for if the cache class is not
TalkPHP_Gravatar_Cache. An exception will be thrown if it isn't to save on any problems. As you shouldn't see this error unless you drastically modify the script, there's really no need to put the class instantiation and method calls in a
try and catch block, but it's entirely up to you.