Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [MOD - AddOn] - grAvatar, identity comments  (Read 8405 times)

henrich

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 381
  • Passion for quality and excellence!
    • My personal blog and portofolio
[MOD - AddOn] - grAvatar, identity comments
« on: January 24, 2008, 05:19:51 am »

FINISHED 1st version: 24 january 2008

Hi friends :)

I created this MOD - Addon for all those sNews sites users who wants to identify their comments posts at the comments section. All this funny stuff will look like this:

http://farm3.static.flickr.com/2164/2215225791_e0df1a9cdc_o.jpg

So, backup your files and let's begin together to install this MOD:



Step 1. Create an account at www.gravatar.com

Read more about gravatar here http://en.wikipedia.org/wiki/Avatar_(computing)

!!! Register with the email address that you want to use for commenting on your blog or other blogs where this feature is added. Anyway you can add into your account also more addresses and more avatars associated to them.

Step 2. After we read the things on gravatar http://site.gravatar.com/site/implement#section_3_1 we realise that we need a new cell in the comments table. In your MySql database do the next Sql query:

Code: [Select]
ALTER TABLE `comments` ADD `email` varchar(100) NOT NULL;
Don't forget to use prefixes if needed!

Step 3. In the tags($tag) function change the whole comments tag line  into this:

Code: [Select]
$tags['comments'] = '<div class="comment">,<p class="date">,name, '.l('on').' ,date,edit,</p>,<p>,comment,</p>,</div>';

Step 4. In the function comment find the next lines:

Code: [Select]
$url = trim($_POST['url']);
$url = (strlen($url) > 8 && strpos($url, '?') === false) ? clean(cleanXSS($url)) : null;

after this add the next lines:

Code: [Select]
$email = trim($_POST['email']);
$email = (strlen($email) > 7 && 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;


Step 5. Same function, find the next line:

Code: [Select]
$query = "INSERT INTO ".db('prefix')."comments(articleid, name, url, comment, time, approved) VALUES('$post_article_id', '$name', '$url', '$comment', '$time', '$approved')";
replace with:

Quote
$query = "INSERT INTO ".db('prefix')."comments(articleid, name, email, url, comment, time, approved) VALUES('$post_article_id', '$name', '$email', '$url', '$comment', '$time', '$approved')";

Step 6. Same function, find the next line:

Code: [Select]
$commentCount = s('comment_limit');
BEFORE this add this line:

Code: [Select]
echo '<ol class="commentlist">';
Step 7. Same function, find next line:

Code: [Select]
$tag = explode(',', tags('comments'));
The upcoming cicle must be replaced, until the $ordinal++; (this not included, can remain the same), so will look like this:

UPDATED: 21th february 2008 See red code.

Quote
foreach ($tag as $tag) {
   switch (true) {
   case ($tag == 'date'): echo $date; break;
   case ($tag == 'name'): $name = $r['name']; echo !empty($r['url']) ? '<a href="'.$r['url'].'" title="'.$r['url'].'" rel="nofollow">'.$name.'</a> ' : $name; break;
   case ($tag == 'comment'): echo bb_smilies($r['comment']);break;
   //GRAVATAR
   case ($tag == 'gravatar'):
   $email = retrieve('email', 'comments', 'id', $r['id']);
   $name = $r['name'];
   $default = "http://www.yourdomain.com/images/avatar.jpg";
   $size = 50;
   $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id=".md5($email)."&amp;default=".urlencode($default)."&amp;size=".$size;
   echo '<img class="imgr gravatars" src="'.$grav_url.'" width="'.$size.'" height="'.$size.'" alt="'.$name.'" /> ';
   break;
   //GRAVATAR
   case ($tag == 'edit' && $_SESSION[db('website').'Logged_In'] == token()):
   echo $edit_link.'editcomment&amp;commentid='.$r['id'].'" title="'.l('edit').' '.l('comment').'">'.l('edit').'</a> ';
   echo $edit_link.'process&amp;task=deletecomment&amp;articleid='.$r['articleid'].'&amp;commentid='.$r['id'].'" title="'.l('delete').' '.l('comment').'" onclick="return pop()">'.l('delete').'</a>';
   break; case ($tag == 'edit'): ; break; default: echo $tag;
}
}

$default = "http://www.yourdomain.com/images/avatar.jpg"; this line will have the url code where you will place your default avatar, this avatar will be used when a comment poster on your site does not have yet a gravatar account. Just create a default face in 80x80 pixels, as you see in my example.

$size = 50; this can be a value between 40 and 80.

Step 8. Now find this line:

Code: [Select]
if ($maxPage > 1) {paginator($categorySEF, $pageNum, $maxPage, $articleSEF, '');}
after this add:

Code: [Select]
echo '</ol>';
Step 9. Still the same function, find the next line:

Code: [Select]
echo html_input('text', 'url', 'url', '', l('url'), 'text', '', '', '', '', '', '', '', '', '');
after this add this line:

Code: [Select]
echo html_input('text', 'email', 'email', '', l('email'), 'text', '', '', '', '', '', '', '', '', '');
Step 10. In function edit_comment() , find the next line:

Code: [Select]
echo html_input('text', 'url', 'url', $r['url'], l('url'), '', '', '', '', '', '', '', '', '', '');
after this add the following line:

Code: [Select]
echo html_input('text', 'email', 'email', $r['email'], l('email'), '', '', '', '', '', '', '', '', '', '');
Step 11. We are in the function processing(), find next line:

Code: [Select]
$url = cleanXSS($_POST['url']);
after that add this:

Code: [Select]
$email = cleanXSS($_POST['email']);
Step 12. Same function, find the next line:

Code: [Select]
mysql_query("UPDATE ".db('prefix')."comments SET name = '$name', url = '$url', comment = '$comment', approved = '$approved' WHERE id = '$commentid' LIMIT 1;");
replace with:

Quote
mysql_query("UPDATE ".db('prefix')."comments SET name = '$name', email = '$email', url = '$url', comment = '$comment', approved = '$approved' WHERE id = '$commentid' LIMIT 1;");

Code: [Select]
Step 13.  CSS rules (you can make your own also:

Code: [Select]
#articles .commentlist {
margin-bottom: 20px;
margin-left: 10px;
clear : both;
width: 95%
}

#articles .commentlist li {
background: #f7f7f7;
color: #707070;
padding: 5px 10px 3px 10px;
margin : 10px auto 5px auto;
border-top: 3px solid #e0e0e0;
width : 95%;
}

#articles .commentlist li.alt {
    background: #f7f7f7;
}

#articles p {
font : bold;
width : 440px;
}

.imgr {
border: 0;
float: right;
margin: 5px 5px 5px 5px;
padding: 0px;
border : 1px solid #efefef;
}

img.gravatars { padding-top: 0 !important; }

#articles is the DIV id section where my comments are included, yours may have other name.



So you have a nice comment section with avatars. Please let me know the results of your install. More MOD ideas i have, more MODs i will make, this is the 4th and i think the most important from my part :), stay close  :P

P.S.: Thanks for Bob who explained to me, when only simple queries are made, we can use the retrieve function.
« Last Edit: October 05, 2008, 11:19:00 am by henrich »
Logged
By(e) Henrich :)
------------------------------
IT related blog

henrich

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 381
  • Passion for quality and excellence!
    • My personal blog and portofolio
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #1 on: February 21, 2008, 09:09:32 pm »

Updated STEP 7. See red code. It was necesary to validate the code at w3.org.
Logged
By(e) Henrich :)
------------------------------
IT related blog

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #2 on: March 22, 2008, 05:12:51 am »

I like this. So, karma+. I saw, here are few bloggers. Mainly programmers and web designers :D . I used this on Wordpress  some time ago. Sexy comments was the name of plugin, I think...
Logged

henrich

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 381
  • Passion for quality and excellence!
    • My personal blog and portofolio
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #3 on: March 22, 2008, 01:01:07 pm »

Yeah, i remember also something about that plugin. Please add me on your yahoo messenger list, my id you can see in my profile.
Logged
By(e) Henrich :)
------------------------------
IT related blog

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #4 on: March 24, 2008, 04:30:07 am »

Henrich,

Better use this in step 4.

Code: [Select]
$email = (strlen($email) > 7 && 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;
Is from contact code, and is good verification of email string format.
Logged

Karaviro

  • Newbie
  • *
  • Karma: 0
  • Posts: 3
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #5 on: October 18, 2008, 01:00:09 am »

Hello Henrich

Im not a Jack in such things, but i just tried to do this in
sNews 1.6 MU

but as supposed it didnt work.

there are differences - and i thought so - that you cant just overlook the fact, that the snewsMU.php has a different behavior

while doing the Mod step by step
there was diffrences in:

Step 5

Code: [Select]
  $query = "INSERT INTO ".db('prefix')."comments(articleid, name, email, url, comment, time, approved) VALUES('$post_article_id', '$name', '$email', '$url', '$comment', '$time', '$approved'".$author_id.")";       

here you find at the end .$author_id.

and

Step 9

Code: [Select]
  if ($maxPage > 1) {paginator($categorySEF, $pageNum, $maxPage, $articleSEF, '');}
echo '</ol>';
}
if ($freeze_status != 'freezed') {
## MULTI_USER
if (s('comments_reg') != 'on' || $_SESSION[db('website').'Logged_In'] == token() ) {
## END MULTI_USER
echo '<div class="commentsbox"><h2>'.l('addcomment').'</h2>';
echo '<p>'.l('required').'</p>';
echo html_input('form', '', 'post', '', '', '', '', '', '', '', '', '', 'post', db('website'), '');
$type = $_SESSION[db('website').'Logged_In'] == token() ? 'hidden' : 'text';
echo html_input($type, 'name', 'name', $_SESSION['username'], '* '.l('name'), 'text', '', '', '', '', '', '', '', '', '');
echo html_input($type, 'url', 'url', get_identity($_SESSION['id'], 'website'), l('url'), 'text', '', '', '', '', '', '', '', '', '');

there is no

Code: [Select]
echo html_input('text', 'url', 'url', '', l('url'), 'text', '', '', '', '', '', '', '', '', '');

the other steps could be applied

dont get me wrong, im not blaming

i just have no idea how that work, and maybe this info is helping getin gavatar for the MU version to work

i would be happy about any suggestion how i could inplement Avatars.

Thank you for your work

greetings
Logged

henrich

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 381
  • Passion for quality and excellence!
    • My personal blog and portofolio
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #6 on: October 18, 2008, 10:07:03 am »

This MOD is for sNews 1.6 and i am not using sNews MU and i have no idea about the structure of that platform. Sorry. For MU version you better wrote a new similar MOD as i see from your report, there is not enough only to update the current MOD, well this is not sure beacuase i have just waked up now :) If i will have time, maybe i will do a MOD also for the MU version, but not in the near future. Thanks.
Logged
By(e) Henrich :)
------------------------------
IT related blog

Karaviro

  • Newbie
  • *
  • Karma: 0
  • Posts: 3
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #7 on: October 18, 2008, 11:17:53 pm »

Hm as i supposed :)

thank you for sharing your first minutes of the day with me

My web develobment knowledge is just rudimental and i didnt learn php ...
... so i supose it would be too complex, that i could do the job with some hint of you
what should i track

or maybe you can tell me what to read
about gavatar
or php
i dont have the possibility to learn php by scratch at the moment

what do you think?
Logged

alexxfender

  • Newbie
  • *
  • Karma: 0
  • Posts: 10
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #8 on: December 22, 2008, 10:31:09 pm »

nice!!
Logged

henrich

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 381
  • Passion for quality and excellence!
    • My personal blog and portofolio
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #9 on: December 22, 2008, 11:11:38 pm »

@Karaviro, you should read again the initial post. Read the info on that gravatar site/address. I can't explain better then them.

@alexxfender, thanks.
Logged
By(e) Henrich :)
------------------------------
IT related blog

kreatur

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 73
    • RoManga
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #10 on: October 03, 2009, 02:38:42 pm »

I have a really simple site and don't want to complicate it, but some users asked for this and i'd like to make them happy, any chance this can be modified to work with 1.7?
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #11 on: October 03, 2009, 04:09:46 pm »

Mhm... Kreatur, if you'd performed a search you'd found that it does exist... Matt over at mdj.us have made gravatar mod for 1.7: http://mdj.us/snews-cms/hacks-mods/gravatar-mod-for-snews-17/

In use elsewhere ? Well, I have it on my site
Logged
"It's only dead fish that goes with the flow... "
Updated

kreatur

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 73
    • RoManga
Re: [MOD - AddOn] - grAvatar, identity comments
« Reply #12 on: October 03, 2009, 06:53:27 pm »

You're right, i don't know how i didn't manage to find, tx for the reply.
Logged