Gravatar mod for sNews 1.7
With this mod you can allow your users to add their email address to their comments and use that email address to fetch their gravatar, if they have one. I've been using it here on my site for quite a while now, as you can see.
So without further ado let's get started. As always BACK-UP your snews.php file and work off a copy.
1. find the function comment and add the following highlighted code;
$url = (strlen($url) > 8 && strpos($url, '?') === false) ? clean(cleanXSS($url)) : null;
$email = trim($_POST['email']);
$email = (strlen($email) > 5 && preg_match( '/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i' , $email)) ? clean(cleanXSS($email)) : null;
2. still within the function comment find and make the following highlighted changes;
$query = 'INSERT INTO '._PRE.'comments'.'(articleid, name, url, comment, time, approved, email) VALUES'."('$post_article_id', '$name', '$url', '$comment', '$time', '$approved', '$email')";
3. still within the function comment find and add the following highlighted code
'name'=>$name,
'email'=>$email,
'comment'=>$comment,
4. still within the function comment find and add the following highlighted code, make sure you adjust the rating if you like, and the gravatar size, etc;
case ($tag == 'comment'):
$email = retrieve('email', 'comments', 'id', $r['id']);
$name = $r['name'];
$default = _SITE."/images/gravatar.png";
$size = "48";
$rating = "pg";
$gravatar = "http://www.gravatar.com/avatar.php?gravatar_id=".md5($email)."&rating=".$rating."&default=".urlencode($default)."&size=".$size;
echo '<img class="gravatar" src="'.$gravatar.'" width="'.$size.'" height="'.$size.'" alt="'.$name.'" /> ';
echo $r['comment'];
break;
5. still within the function comment find and add the following highlighted code;
echo html_input('text', 'url', 'url', $url, l('url'), 'text', '', '', '', '', '', '', '', '', '')."\r\n";
echo html_input('text', 'email', 'email', '', l('cemail'), 'text', '', '', '', '', '', '', '', '', '');
echo html_input('textarea', 'text', 'text', stripslashes($comment), '* '.l('comment'), '', '', '', '', '', '5', '5', '', '', '')."\r\n";
echo mathCaptcha()."\r\n";
6. find the function edit_comment and make the following highlighted changes;
$query = mysql_query('SELECT id,articleid,name,url,email,comment,approved FROM '._PRE.'comments'.' WHERE id='.$commentid);
7. still within the function edit_comment find and add the following highlighted code;
echo html_input('text', 'url', 'url', $r['url'], l('url'), '', '', '', '', '', '', '', '', '', '');
echo html_input('text', 'email', 'email', $r['email'], l('email'), '', '', '', '', '', '', '', '', '', '');
8. find the function processing and add the following highlighted code;
$url = cleanXSS($_POST['url']);
$email = cleanXSS($_POST['email']);
$comment = $_POST['editedcomment'];
9. still within the function processing find and add the following highlighted code;
if (isset($_POST['submit_text'])) {
mysql_query("UPDATE "._PRE.'comments'." SET
name = '$name',
url = '$url',
email = '$email',
comment = '$comment',
approved = '$approved'
WHERE id = $commentid");
} else if (isset($_POST['delete_text'])) {
10. Let's add the email field to the database now.
ALTER TABLE comments ADD email varchar(255) NOT NULL;
11. Now add the gravatar class to your stylesheet.
.gravatar {
float: right;
padding: 6px;
}
12. And finally, you need to add the form text to your language file (EN.php in the lang folder most likely)
$l['cemail'] = 'Email (will not be published, for <a rel="nofollow" href="http://www.gravatar.com">gravatar</a> only)';
That should be it, you should now have gravatars available. If you don't have a default gravatar to use, here's the one I use,
![]()
As always, if I forgot a step or things didn't turn out quite right, please let me know so I can look into it and fix it if needed.
Comments
RSS Comments Feed
Patric
Matt
Looks like I have a comma in the ALTER TABLE syntax that shouldn't be there, right before the closing semi-colon.
I'll update that and get you on email/IM.
Patric
Matt
asundrus
So I tried adding the email via edit, and then it worked, what could I have missed? i'm certain that I did everything 100% correct, I tripple checked.
asundrus
$query = "INSERT INTO "._PRE."comments(articleid, name, url, comment, time, approved, email) VALUES('$post_article_id', '$name', '$url', '$comment', '$time', '$approved', '$email')";
But now I did and ofcourse it's working now.
/me feels a bit embarrassed
Matt
asundrus
Matt
Asundrus, shoot me a message via the contact form and I'll follow up with you on email later tonight or tomorrow morning.
asundrus
Matt
Deyn
thx matt
Adhi
It doesn't appear just like yours, in this blog, that the gravatar images stay still inside the comment area, no matter how long it is.
Can you help me? Maybe I just need to fix the style.css, but I don't know how to be fix it.
Thanks a lot.
Matt
Do you have a link, or can you take a screen shot and post it? It definitely sounds like a styling issue.
From the sound of it, is it over-lapping the admin links or other content? If that's the case, perhaps adding a clearer break after the comment would fix it?
i.e. add the break in step four
echo $r['comment'];
<span class="highlight">echo '<br class="clearer" />';</span>
break;
Kreatur
Matt
Make sure the break clears the floats, hence the class "clearer". The css would be
.clearer {
clear: both
}
Kreatur
Matt
BTW, Nice looking site!
Sven - Philippe
I would be candidate for testing. -D
Matt
Maybe I could do it as separate mod, but I know my "infoline" is hacked up, so it may not be as easy for the average user.
jesth
I mean, the way you have it is cool, left to the date, I tried a few things, but gave up, maybe I'm too tired, don't know.
So if you get the time, and want to share, please do.
Matt
jesth
Matt
If you have an idea of what you want and enough PHP & CSS under your belt, it shouldn't be too difficult with some trial and error.
jesth
38 comments, page 1 of 2 [ 1 2 » ]