[MOD] Badges and styles for admin comments in sNews
This mod for sNews will style admin comments differently from normal visitors to allow easier identification of the author and to prevent fraudulent comments. You will need to be logged in while commenting for the admin effects to be applied to your comment. Click the image to the right for a preview of how it will look on a default install.
Backup first!
Be sure to backup all files and your database before proceeding. The following modification is performed at your own risk.
MySQL Database
This first step involving your database depends upon your own setup, so please check which applies to you.
sNews database with no prefix
Go to your MySQL admin page and insert the following into your sNews table:
ALTER TABLE comments ADD admin varchar(5) NOT NULL;
sNews database with table prefix
If you are using a table prefix you need to enter it in place of the highlighted text and insert the following code to your database:
ALTER TABLE PREFIX_comments ADD admin varchar(5) NOT NULL;
Thats the entry added to the database, lets move on to editing the files.
Inserting the code
Find and replace the following blocks of code in snews.php
Find:
// INFO LINE TAGS (readmore, comments, date)
$tags = array(
'infoline' => '<p class="date">,readmore,comments,date,edit,</p>',
'comments' => '<p class="meta">,name, '.l('on').' ,date,edit,</p>,<p class="comment">,comment,</p>'
);
Replace with:
// INFO LINE TAGS (readmore, comments, date)
$tags = array(
'infoline' => '<p class="date">,readmore,comments,date,edit,</p>',
'comments' => 'name, '.l('on').' ,date,edit,comment'
);
The rest of the edits in this file are within the comments function.
Find:
$ident=1;
} else {
Replace with:
$ident = 1;
$admin = 'True';
} else {
Find:
$approved = s('approve_comments') != 'on'|| _ADMIN ? 'True' : '';
$query = 'INSERT INTO '._PRE.'comments'.'(articleid, name, url, comment, time, approved) VALUES'.
"('$post_article_id', '$name', '$url', '$comment', '$time', '$approved')";
mysql_query($query);
Replace with:
$approved = s('approve_comments') != 'on'|| _ADMIN ? 'True' : '';
$query = 'INSERT INTO '._PRE.'comments'.'(articleid, name, url, comment, time, approved, admin) VALUES'.
"('$post_article_id', '$name', '$url', '$comment', '$time', '$approved', '$admin')";
mysql_query($query);
Find:
$query = 'SELECT id,articleid,name,url,comment,time,approved FROM '._PRE.'comments'.'
Replace with:
$query = 'SELECT id,articleid,name,url,comment,time,approved,admin FROM '._PRE.'comments'.'
Find:
case ($tag == 'comment'): echo $r['comment']; break;
Replace with:
case ($tag == 'comment'): echo '</p><p class="'.$commentstyle.'comment">'.$r['comment'].'</p></div>'; break;
Find:
$commentNum = $offset + $ordinal;
$tag = explode(',', tags('comments'));
This next part can be edited if needed. For example you may want to use a different image format, in which case you need to change the src='' urls. You could also remove the image altogether by commenting out the lines like this "//$admin = "img....", you will probably want to do this if you are using mdj's gravatar mod.
Replace with:
$commentNum = $offset + $ordinal;
if ($r['admin'] == 'True') {
$commentimg = "<img src='images/admin.png' alt='(Admin)' />"; //admin badge next to name
$commentstyle = 'admin'; //admin style
} else {
$commentimg = "<img src='images/visitor.png' alt='(Visitor)' />"; //visitor badge next to name
$commentstyle = 'visitor'; //visitor style
}
echo '<div class="comment'.$commentstyle.'">'.$commentimg.'<p class="meta'.$commentstyle.'">';
$tag = explode(',', tags('comments'));
Styling
Now open up your style.css file. This can be found in the "css" folder of a defualt install.
Find:
.comment {
color:gray;
border-top:1px solid #ccc;
background:#F5F6F6;
margin:0 0 10px;
padding:10px;
}
Replace with:
/*[MOD] ADMIN COMMENTS*/
.commentadmin { /*admin comment block*/
background:#D1E1FA;
margin:0 0 10px 0;
}
.commentvisitor { /*visitor comment block*/
background:#DFF9E0;
margin:0 0 10px 0;
}
.metaadmin, .metavisitor { /*name and date*/
padding:5px 0 5px 0;
margin:0;
}
.commentadmin img, .commentvisitor img { /*badge styling*/
float:left;
padding:8px;
}
.admincomment, .visitorcomment { /*comment text area*/
color:gray;
border-top:1px solid #ccc;
background:#F5F6F6;
margin:0;
padding:10px;
}
I have added different classes for each part to give you the extra freedom if you decide to have it all different. The CSS is commented so hopefully you can see how to style the comments the way you need, you can always leave a comment if not.
Feel free to use these images for badges if you don't have your own. Put them in your images folder.
Your comments should now look like the example above. Leave a comment if you have any problems. Let me know if you use it, would be nice to see how others have styled it. Look below to see how I have done mine. :)
Comments
You would never guess i'm the admin.
Looking good, I noticed you're using gravatar on your site, wouldn't it be cool adding that to this mod?
Thanks for the feedback Pete.
Gravatar works fine with this mod but it needs a lil tweaking. You need to comment out the image code as mentioned in one of the steps. You may also have problems finding the right places to insert this code if you already have gravatar installed.
Just a quick tip: Try searching for individual lines instead of the entire block of code. Then add this code after any different code found.
Some might have problems with that so I could do another guide that works on the basis of gravatar mod already being installed and using (Admin) after the name instead of the badges. Let me know if this is something anyone is interested in or if anyone has any specific ideas.
If you could make a guide with this mod and include how to implement gravatar, that would be awsome, I just made a fresh install of sNews, and will wait for you to make a guide.
Hi Scott, nice site.
I like this mod, it's a proper way to "adminify" comments. People always ask me how I do mine, and I never published any how-to because I totally hacked mine in, based on whether or not the comment email matches the site admin.
It works fine for me, if I ever change email, I'll do a global replace in the mySQL field for the comments, but it's too sloppy to release as mod.
Nice work.
Hey Matt, thanks for the comment.
I've added all of your mods that I felt fit my needs. It has to be said that your work has really improved sNews and made it a much more refined yet still basic and mod-able script.
Just a quick update on the plans for a gravatar based tutorial...
I've been busy with other things lately and haven't had chance, but I'm looking over it now. Should have something up soon if it goes smoothly.
*Update* linky
Hi.
Just added this mod, and it works great, I was just thinking, let's say you only want to change to color of the name, and nothing else, how would this be done, if possible?
Hey Jesth,
you could try adding the following to your css file:
.metaadmin {
color:DFF;
}
Replacing "DFF" with the colour you want. If thats not exactly how you want it, then it will probably mean editing the script as well.
Pas mal le plugin, reste à savoir si tout cela est facilement adaptable sur une version ISO et pas sur du UFT-8
Hi yule,
Thanks for the comment however if possible please use English in future.
Translation: "Not bad plugin, the question remains whether all this is easily adaptable to an ISO version and not on the UFT-8"
In response: I do not see how character sets have anything to do with the above. Feel free to explain your concerns further.




