Add a comment preview and delete link in the Admin section of sNews

Add a comment preview and delete link in the Admin section of sNews

I got a recent request to do a simple mod to put a "delete" link beside the comment edit link in the Admin section of sNews, so one can easily delete an obvious spam comment without clicking edit, then deleting. Seemed like a good idea, so I've added a few extra bits and have it running on my site as well, so I might as well offer it up to the community too. Here's a preview;

sNews comment delete

Within snews.php, find the function administration(), and add the following highlighted code in the comment SQL query;

$query_comm = 'SELECT id,articleid,name,comment FROM '._PRE.'comments'.' WHERE approved != \'True\'';

Now find the code that outputs the unapproved comments;

echo '<p>'.$r['name'].' (<strong>'.$articleTITLE.'</strong>) '.l('divider').'
<a href="'._SITE.'?action=editcomment&amp;commentid='.$r['id'].'">'.l('edit').'</a></p>';

Now replace that code with this block;

if (strlen($r['comment']) > '60') {
    $preview = substr($r['comment'],0,60).'...';
} else {
    $preview = $r['comment'];
echo '<p>'.$r['name'].' (<strong>'.$articleTITLE.'</strong>) '.l('divider').' <a href="'._SITE.'?action=editcomment&amp;commentid='.$r['id'].'">'.l('edit').'</a> <a href="'._SITE.'?action=process&amp;task=deletecomment&amp;commentid='.$r['id'].'" title="'.l('delete').' '.l('comment').'" onclick="return pop()">'.l('delete').'</a><br />&nbsp;-&nbsp;<span class="comment_preview">"'.$preview.'"</span></p>';

And the style for the comment preview;

.comment_preview {
font-size: .9em;
font-style: italic;
color: #555;

That's it. Very basic. It still redirects you to the article related to the comment, but to change that would require quite a bit more hacking on other functions.



You might like


hey matt
very nice mod,
it is a must for snews comment system.

thank you and
awesome day

Mhm, now where the feck can I find and being able to change "Comment preview:" ?? Have styled that label, but I can't get rid of the semicolon...

I'm not sure I follow you Patric, where do you see "Comment preview:" at?

Are you thinking about this;

If that's the case, it's in the javascript, just remove the semi-colon from that code... that colon should have been in the label actually;

$('#text').parent().after('<div><label for="comment-preview">Comment Preview</label>:</div><div id="comment-preview"></div>');

YES, I'm such an dumba**, thanks Matt.

Thanks for this one Matt. Only wish I'd seen it earlier - it really is a necessity for sNews.

Thanks! <3

Using your gravatar mod as well so I added 'email' to the $query_comm list and then output $r['email'] in the echo... maybe someone else will find it useful.

Hi there just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Opera.
I'm not sure if this is a formatting issue or something to do with internet browser compatibility but I
figured I'd post to let you know. The layout look great though!

Hope you get the problem resolved soon. Cheers

Comments are closed. No new comments allowed.

Copyleft 2002 - 2017 Matt Jones
Hand crafted with HTML5 & CSS3
↑ Back to top