Is there anyway to add gravatar images to recent comments, i was messing with the template funcions.php file, but i can only get the default gravatar too print out and not individual ones?
This is my implementation, i can get it to show the default image, but not the user with a gravatar? the original pieces of code can be found at the bottom
`
function printLatestComments($number, $shorten='123') {
if(getOption('mod_rewrite')) {
$albumpath = "/"; $imagepath = "/"; $modrewritesuffix = getOption('mod_rewrite_image_suffix');
} else {
$albumpath = "/index.php?album="; $imagepath = "&image="; $modrewritesuffix = "";
}
$email = getCommentAuthorEmail();
$comments = getLatestComments($number,$shorten);
echo "\n";
echo "[list]\n";
foreach ($comments as $comment) {
if($comment['anon'] === "0") {
$author = " ".$comment['name'] .gettext(" said: ")." ";
} else {
$author = "";
}
$album = $comment['folder'];
if($comment['type'] === "images") {
$imagetag = $imagepath.$comment['filename'].$modrewritesuffix;
} else {
$imagetag = "";
}
$date = $comment['date'];
$albumtitle = $comment['albumtitle'];
if ($comment['title'] == "") $title = $image; else $title = get_language_string($comment['title']);
$website = $comment['website'];
$shortcomment = truncate_string($comment['comment'], $shorten);
if(!empty($title)) {
$title = ": ".$title;
}
$default = "http://www.thehilln10.com/images/defaultGrav.gif";
$size = 20;
$grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5($email)."&default=".urlencode($default)."&size=".$size;
echo "[*]".$author."
\n";
echo "".$shortcomment."";
echo '[img]'.$grav_url.'[/img]';
}
echo "[/list]\n";
echo "\n";
}
`
The original gravatar hack:
`
[img][/img]
`
The original print latest comments code:
`
function printLatestComments($number, $shorten='123') {
if(getOption('mod_rewrite')) {
$albumpath = "/"; $imagepath = "/"; $modrewritesuffix = getOption('mod_rewrite_image_suffix');
} else {
$albumpath = "/index.php?album="; $imagepath = "&image="; $modrewritesuffix = "";
}
$comments = getLatestComments($number,$shorten);
echo "\n";
echo "[list]\n";
foreach ($comments as $comment) {
if($comment['anon'] === "0") {
$author = " ".$comment['name'] .gettext(" said: ")." ";
} else {
$author = "";
}
$album = $comment['folder'];
if($comment['type'] === "images") {
$imagetag = $imagepath.$comment['filename'].$modrewritesuffix;
} else {
$imagetag = "";
}
$date = $comment['date'];
$albumtitle = $comment['albumtitle'];
if ($comment['title'] == "") $title = $image; else $title = get_language_string($comment['title']);
$website = $comment['website'];
$shortcomment = truncate_string($comment['comment'], $shorten);
if(!empty($title)) {
$title = ": ".$title;
}
echo "[*]".$author."
\n";
echo "".$shortcomment."";
}
echo "[/list]\n";
echo "\n";
}
`
Gravatar is indeed a neat feature to hook up to ZenPhoto comment system.
I have used Gravatar in BBpress with great results.
here is some info about code.
http://en.gravatar.com/site/implement
This is how they state to do it on their web page.
PHP
Implementing gravatars with PHP is quite simple. PHP provides strtolower(), md5(), and urlencode() functions, allowing us to create the gravatar URL with ease. Assume the following data:
$email = "someone@somewhere.com"; $default = "http://www.somewhere.com/homestar.jpg"; $size = 40;
You can construct your gravatar url with the following php code:
$grav_url = "http://www.gravatar.com/avatar.php? gravatar_id=".md5( strtolower($email) ). "&default=".urlencode($default). "&size=".$size;
Once the gravatar URL is created, you can output it whenever you please:
Based on what Olihar posted, I made a simple function that puts together the Gravatar url. All you have to pass it is the e-mail address.
`
function gravatar($email) {
$default = "http://www.somewhere.com/homestar.jpg";
$size = 60;
$grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5( strtolower($email) )."&default=".urlencode($default)."&size=".$size;
echo $grav_url;
}
I put this in a file called customfunctions.php within my theme folder and you would call it like this
[img][/img]
`