
Smarty-plugin for Gravatar

Briefly about how the URL for Gravatar is built. It has the form:
http://www.gravatar.com/avatar/? s = & r = & d =
The plugin itself looks like this:
/ *
* Smarty plugin
* -------------------------------------------- -----------------
* File: function.gravatar.php
* Type: function
* Name:
gravatar
* Purpose: Build URL for Gravatar * --------- -------------------------------------------------- -
* /
function smarty_function_gravatar ($ params)
{
$ url = 'http://www.gravatar.com/avatar/';
if (empty ($ params ['email'])) {
$ params ['email'] = '';
}
$ url. = md5 (strtolower (trim ($ params ['email'])));
$ firstparam = true;
if (isset ($ params ['size'])) {
$ url. = '? s ='. $ params ['size'];
$ firstparam = false;
}
if (isset ($ params ['rating'])) {
$ url. = ($ firstparam)? '?': '&';
$ url. = 'r ='. $ params ['rating'];
$ firstparam = false;
}
if (isset ($ params ['default'])) {
$ url. = ($ firstparam)? '?': '&';
$ url. = 'd ='. urlencode ($ params ['default']);
}
return $ url;
}
?>
* This source code was highlighted with Source Code Highlighter .
Examples of using:
* This source code was highlighted with Source Code Highlighter .
Useful links:
www.gravatar.com - more about the service on the official website
www.smarty.net/manual/ru/plugins.php - Smarty documentation. Plugin creation