View previous topic :: View next topic |
Author |
Message |
stevem
Joined: 15 Mar 2003 Posts: 365
|
Posted: Sun Oct 31, 2004 5:32 pm Post subject: List of all comments |
|
|
If you want to stop spammers then use Cyberian's Comment Blacklist or How to avert SPAM bots.
It is useful to have a list of all the comments on your blog in case there is some old spam to weed out or you want IP addresses to add to the blacklist. The following code will list all the comments (from new to old) and also allow you to quickly delete them. Put it in a file called something like b2allcomments.php and make a link in b2menutop.txt. It can only be seen by logged-in users at level 8 or above but change that if you wish on line 12
16 Nov: Updated version can be found here This allows you to search for and delete comments with certain words
30 Dec: Another update here which allows you to show only the most recent posts in case you have thousands of them
22 Jan: Update here to search commenter's name and URL as well as the comment itself
Code: | <?php
require("b2config.php");
require("$b2inc/b2template.functions.php");
include("$b2inc/b2vars.php");
include("$b2inc/b2functions.php");
dbconnect();
get_currentuserinfo();
if (!($user_login)) exit;
if ($user_level<8) exit;
if ($action=='deletecomment') {
$standalone = 1;
require_once("./b2header.php");
if ($user_level == 0)
die ("Cheatin' uh ?");
$comment = $HTTP_GET_VARS['comment'];
$p = $HTTP_GET_VARS['p'];
$commentdata=get_commentdata($comment) or die("Oops, no comment with this ID. <a href=\"$PHP_SELF\">Go back</a> !");
$query = "DELETE FROM $tablecomments WHERE comment_ID=$comment";
$result = mysql_query($query) or die("Oops, no comment with this ID. <a href=\"$PHP_SELF\">Go back</a> !");
header ("Location: $PHP_SELF");
}
?>
<html>
<head>
<style type="text/css" media="screen">
@import url( layout2b.css );
</style>
<title>Comments</title>
</head><body>
<h2>Comments</h2>
<div id="contentcomments">
<div class="storyContent">
<div><b><span style="color: #0099CC">::</span> <a href="index.php">return to the blog</a></b> <a href="b2edit.php">:: return to edit</a></div>
<br /><br />
<?php
$queryc = "SELECT * FROM $tablecomments WHERE comment_content NOT LIKE '%<trackback />%' ORDER BY comment_date DESC";
$resultc = mysql_query($queryc);
if ($resultc) {
?>
<?php // these lines are b2's motor, do not delete
while($rowc = mysql_fetch_object($resultc)) {
$commentdata = get_commentdata($rowc->comment_ID);
$posting = $rowc->comment_post_ID;
$commentauthor = $rowc->comment_author;
$postdata = get_postdata($posting);
?>
<p>
<b><?php comment_author() ?></b> ( <?php comment_author_email_link() ?>
<?php if(comment_author_url_link()=="") {$slash="";} else {$slash="/";} echo " $slash"; ?>
<?php comment_author_url_link() ?> ) (IP: <?php comment_author_IP() ?>)
<?php comment_date('D j M Y') ?> @ <?php comment_time('g:i a') ?>
<?php
echo " [ <a href=\"$PHP_SELF?action=deletecomment&p=".$postdata["ID"]."&comment=".$commentdata["comment_ID"]."\" onclick=\"return confirm('You are about to delete this comment by \'".htmlentities($commentauthor)."\'\\n \'Cancel\' to stop, \'OK\' to delete.')\">Delete Comment</a> ]";
?><br />
Comment was made in <b>
<?php the_title() ?> <?php echo $the_date ?> @ <?php the_time('g:i a') ?></b><br /><br />
<?php comment_text() ?>
<br /><br /></p>
<?php //end of the loop, don't delete
}
}
?>
<br /><br />
<div><b><span style="color: #0099CC">::</span> <a href="index.php">return to the blog</a></b> <a href="b2edit.php">:: return to edit</a></div>
</div></div>
</body>
</html> |
Last edited by stevem on Sat Jan 22, 2005 6:41 pm; edited 8 times in total |
|
Back to top |
|
 |
Sigg3
Joined: 03 Jul 2003 Posts: 898 Location: Oslo, Norway
|
|
Back to top |
|
 |
Sigg3
Joined: 03 Jul 2003 Posts: 898 Location: Oslo, Norway
|
|
Back to top |
|
 |
stevem
Joined: 15 Mar 2003 Posts: 365
|
Posted: Wed Nov 03, 2004 6:18 pm Post subject: |
|
|
Whoops sorry ! I called mine comments.php and so hard-coded it into the file. Either call the file comments.php or change the lines so that comments.php become b2allcomments.php:
Code: | header ("Location: comments.php"); | to Code: | header ("Location: $PHP_SELF"); |
and Code: | echo " [ <a href=\"comments.php?action=deletecomment&p=".$postdata["ID"]."&comment=".$commentdata["comment_ID"]."\" onclick=\"return confirm('You are about to delete this comment by \'".htmlentities($commentauthor)."\'\\n \'Cancel\' to stop, \'OK\' to delete.')\">Delete Comment</a> ]"; | to Code: | echo " [ <a href=\"$PHP_SELF?action=deletecomment&p=".$postdata["ID"]."&comment=".$commentdata["comment_ID"]."\" onclick=\"return confirm('You are about to delete this comment by \'".htmlentities($commentauthor)."\'\\n \'Cancel\' to stop, \'OK\' to delete.')\">Delete Comment</a> ]"; |
I'll change it in the original posting. Thanks 
Last edited by stevem on Thu Nov 04, 2004 8:48 pm; edited 1 time in total |
|
Back to top |
|
 |
Sigg3
Joined: 03 Jul 2003 Posts: 898 Location: Oslo, Norway
|
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1283 Location: Oregon
|
Posted: Thu Nov 04, 2004 8:24 pm Post subject: |
|
|
Code: | header ("Location: comments.php"); | to Code: | header ("Location: $PHP_SELF"); |
_________________ Michael P.
 |
|
Back to top |
|
 |
stevem
Joined: 15 Mar 2003 Posts: 365
|
Posted: Thu Nov 04, 2004 8:48 pm Post subject: |
|
|
 |
|
Back to top |
|
 |
DruidX
Joined: 22 Jul 2004 Posts: 6 Location: UK
|
Posted: Fri Nov 05, 2004 8:25 pm Post subject: |
|
|
Umm, Maybe I'm insane or something, but I don't seem to be able to delete comments using this. I cut-n-pasted the code as shown and made the appropriate link, but I when I click 'delete comment' and then refresh the page it doesn't show the comment as being deleted. I was wondering if it doesn't acctually delete the comments or if one has to do somthing extra to make them go away.
I've recently been attacked by 5 spam bots, and need this feature! |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1283 Location: Oregon
|
Posted: Fri Nov 05, 2004 8:56 pm Post subject: |
|
|
All the necessary codes seem to be in place, though. _________________ Michael P.
 |
|
Back to top |
|
 |
stevem
Joined: 15 Mar 2003 Posts: 365
|
Posted: Fri Nov 05, 2004 9:33 pm Post subject: |
|
|
Yes it does delete the comments. The code is the same as that which is already supplied to delete a comment. Have you checked by looking at the post with the comment that the comment has been deleted? Can you delete a comment in the ordinary way in the Post/Edit window? |
|
Back to top |
|
 |
Sigg3
Joined: 03 Jul 2003 Posts: 898 Location: Oslo, Norway
|
|
Back to top |
|
 |
stevem
Joined: 15 Mar 2003 Posts: 365
|
Posted: Tue Nov 09, 2004 3:27 pm Post subject: |
|
|
It should be possible to implement both of those though it may be the end of the week before I get the free time to do it. |
|
Back to top |
|
 |
DruidX
Joined: 22 Jul 2004 Posts: 6 Location: UK
|
Posted: Wed Nov 10, 2004 12:21 am Post subject: |
|
|
Humm, it seems to have worked now, how very odd. Maybe for some reason it wasn't refreshing properly and I was looking at the cach or... Oh I don't know. I'm just happy that it has worked. Yay, no more evil spam  |
|
Back to top |
|
 |
Sigg3
Joined: 03 Jul 2003 Posts: 898 Location: Oslo, Norway
|
|
Back to top |
|
 |
DruidX
Joined: 22 Jul 2004 Posts: 6 Location: UK
|
Posted: Wed Nov 10, 2004 6:59 pm Post subject: |
|
|
I suppose, but there will also always be nice people like you to help the rest of us protect ourselves  |
|
Back to top |
|
 |
|