Thu 22nd Dec 2005
Gravatar Smarty Modifier
Posted lunch time, filed under Blogsome , PHP , Smarty Templates.I wrote a Gravatar modifier for Smarty:
{$comment->comment_author_email|gravatar:"default":
size:"rating":border}
For example, to use no default image, and limit the size to 40×40 pixels, you’d use:
{$comment->comment_author_email|gravatar:"":"40":"":""}
Notice the double quotes where the argument is missing, and that (in this version) you actually need to include all of the arguments.
(I’ve updated this, but haven’t tested it fully yet).
Anyway, here’s the code:
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty gravatar plugin
*
* Type: modifier<br>
* Name: gravatar<br>
* Author: Matt Schinckel<br>
* mailto:matt@schinckel.net<br>
* aim:mschinckel<br>
* http://schinckel.net<br>
* Purpose: convert email address to gravatar
* @param string
* @return string
*/
function smarty_modifier_gravatar($email, $default=false, $size=false, $rating=false, $border=false)
{
$gravurl = "<img src='http://www.gravatar.com/avatar.php?gravatar_id=".md5($email);
if ($default)
{
$gravurl = $gravurl."&default=".urlencode($default);
}
if ($size)
{
$gravurl = $gravurl."&size=".$size;
}
if ($rating)
{
$gravurl = $gravurl."&rating=".$rating;
}
if ($border)
{
$gravurl = $gravurl."&border=".$border;
}
return $gravurl."' alt='Gravatar Image' />";
}
?>
Did you have any look getting this installed a blogsome?
I tried to follow your instructions for getting gravatars working in your other post but it didnt seem to work. I didnt find the instructions very clear.
Any help appreciated.
2 months after the fact.
Very cool.
1 year, 3 months after the fact.
Very useful! Thanks!!!
2 years, 2 months after the fact.
If someone wants to use a function instead of a modifier, take a look at:
http://www.kevinpapst.de/blog/gravatar-smarty-tag.html
Long live OpenSource
2 years, 3 months after the fact.
Can I use this script in my blog at blogsome?
How to do that..?
Thanks a lot..
Regards,
Ari
2 years, 3 months after the fact.
IIRC, they put this up as a modifier as blogsome.
Try putting the following in your template:
{$comment->comment_author_email|gravatar:"":"40":"":""}
2 years, 3 months after the fact.
Oh, and I don’t use Blogsome any longer, so I can’t help you any further than that.
2 years, 3 months after the fact.