Member
Member
developing   2009-01-01, 22:17
#1

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?

Member
Member
sbillard   2009-01-01, 22:53
#2

Comments (and other fields) are filtered for "valid" HTML tags. See the allowed tags option. Any tags not permitted in this list are stripped.

Member
Member
developing   2009-01-02, 20:22
#3

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";

}
`

Member
Member
sbillard   2009-01-03, 00:43
#4

I know nothing of gravatar, however I can tell you from your code that if it is only displaying the default image then there is some problem with the gravatar_id bit. Maybe passing the md5 of the email address is not sufficient or not correct.

Member
Member
olihar   2009-01-03, 23:07
#5

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:

Member
Member
kingkool68   2009-01-04, 07:36
#6

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]
`

Member
Member
olihar   2009-01-11, 11:26
#7

@kingkool68

I don't follow, I don't seem to get this to work that way....

After a long try the only thing I get is empty photo.

  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.