[MOD] Admin comments in sNews with Matts gravatar mod
Updated tutorial for use with an sNews installation already using Matts gravatar mod. Go get it if you don't have it already and want to continue.
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.
This update is a lot later than I had planned but I've been busy with other projects (might hear more about them soon ;)). This tutorial is pretty much a C&P of the old one with relevant bits changed (yea, I'm lazy). Feel free to spam some comments if I've messed up somewhere.
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, email) VALUES'.
"('$post_article_id', '$name', '$url', '$comment', '$time', '$approved', '$email')";
mysql_query($query);
Replace with:
$approved = s('approve_comments') != 'on'|| _ADMIN ? 'True' : '';
$query = 'INSERT INTO '._PRE.'comments'.'(articleid, name, url, comment, time, approved, email, admin) VALUES'.
"('$post_article_id', '$name', '$url', '$comment', '$time', '$approved', '$email', '$admin')";
mysql_query($query);
Find:
$commentNum = $offset + $ordinal;
$tag = explode(',', tags('comments'));
Replace with:
$commentNum = $offset + $ordinal;
if ($r['admin'] == 'True') {
$commentstyle = 'admin'; //admin style
} else {
$commentstyle = 'visitor'; //visitor style
}
echo '<div class="comment'.$commentstyle.'">'.$commentimg.'<p class="meta'.$commentstyle.'">';
$tag = explode(',', tags('comments'));
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:
$name = $r['name'];
echo !empty($r['url']) ?
'<a href="'.$r['url'].'" title="'.$r['url'].'" rel="nofollow">
'.$name.'</a> ' : $name;
break;
Replace with:
$name = $r['name'];
if ($r['admin'] == 'True') {
$admintitle = '<span class="admintitle">(Admin)</span>'; //admin title next to name
}
echo !empty($r['url']) ?
'<a href="'.$r['url'].'" title="'.$r['url'].'" rel="nofollow">
'.$name.'</a> '.$admintitle.'' : $name.' '.$admintitle;
break;
This bit depends on what settings you used with the gravatar mod. For this tutorial I will be using size 38. You can of course use any size you want but that may also involve changing the CSS to work with it.
Find and edit the highlighted code.
$default = _SITE."/images/gravatar.png";
$size = "38";
$rating = "pg";
Find:
echo '<img class="gravatar" src="'.$gravatar.'" width="'.$size.'" height="'.$size.'" alt="'.$name.'" /> ';
echo $r['comment'];
break;
Replace with:
echo '</p><p class="'.$commentstyle.'comment">'.$r['comment'].'</p><img class="gravatar" src="'.$gravatar.'" width="'.$size.'" height="'.$size.'" alt="'.$name.'" /></div>'; break;
Styling
Now open up your style.css file. This can be found in the "CSS" folder of a default install. If you have modified these or they aren't together you will need to scan through and delete them. Then simply add the "replace with" code.
Find:
.comment {
color:gray;
border-top:1px solid #ccc;
background:#F5F6F6;
margin:0 0 10px;
padding:10px;
}
.gravatar {
float: right;
padding: 6px;
}
Replace with:
/*[MOD] ADMIN COMMENTS*/
.commentadmin { /*admin comment block*/
position:relative;
background:#D1E1FA;
margin:0 0 10px 0;
}
.commentvisitor { /*visitor comment block*/
position:relative;
background:#DFF9E0;
margin:0 0 10px 0;
}
.metaadmin, .metavisitor { /*name and date*/
padding-top:10px;
margin-left:46px;
}
.admintitle { /*styles for (Admin) which appears next to your name*/
font-style:italic;
color:#00234F;
}
.commentadmin img, .commentvisitor img { /*gravatar styling*/
position:absolute;
top:0;
left:0;
padding:4px;
}
.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.
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
Nice work Scott, I will definitely test it out on my sandbox site some time.




