Follow us on Facebook and Twitter!

Improved Manage Comments Addon
#1
I found it was taking way too much time to delete un-wanted comments / spam.

So what I have done was add a checkbox feature so you are able to "mass delete" comments.

[Image: 332aqnr.png]

When you hit the "Delete Selected" button, a confirm dialog box will appear. As you can see in the screenshot, I've also added "Check All / Clear All" links.

The delete feature works exactly the same as if you were to delete the comment the old way - All replies attached to the comment will also be deleted.

I have extensively tested this and it works great, but with that said : ** Use at your own risk! **

Requirements
Commentics v2.3

Installation Instructions
1) Download the attached file at the bottom of this post
2) Backup your /comments/admin/includes/pages/manage_comments.php file
3) Copy the new manage_comments.php (overwriting the old file)

Feel free to let me know here if you run in to any bugs. Enjoy!


Attached Files
.php   manage_comments.php (Size: 11.16 KB / Downloads: 19)
Reply
#2
Hi MuffinMan,

Really excellent work! I've been meaning to add this feature for a long time but there was one issue which was holding me back, and you seem to have overcome it, (whether it was on purpose or not I'm not sure). It's with the search feature. Let's say if you search and it filters the results down to a few, I was expecting that when I then clicked the 'Check All' link and hit delete it would delete all of the comments instead of just the ones that I had searched for. However it only deleted the ones that I had searched for and all of the rest were still there, which is great! Did you mean to code it like that?

There are a few suggestions that I want to make:

1. It only shows comments that are not approved. I had to change "WHERE is_approved = 0" to "WHERE is_approved = 0 OR 1" to show all of them. (The comments that I wanted to delete were approved).

2. The approve and delete buttons link to a 'moderate_comments' page which doesn't exist. I have a feeling this is linked to (1) - maybe you had created a 'moderate_comments' page which only shows comments that need approval.

3. I think the '<?=' will only work if the server has PHP short tags enabled, so it may be better to use '<?php echo' instead.

4. You can add class="button" to the button to make it look like the other ones.

5. I didn't test what happens with the 'Check All' if there are multiple pages, so not sure what would happen there?

6. Is it possible to convert the $_POST to a $_GET, so it's like the existing delete feature, or do you think $_POST is best in this case?
Have you completed the interview?
Reply
#3
Thanks for the feedback!

Quote:Really excellent work! I've been meaning to add this feature for a long time but there was one issue which was holding me back, and you seem to have overcome it, (whether it was on purpose or not I'm not sure). It's with the search feature. Let's say if you search and it filters the results down to a few, I was expecting that when I then clicked the 'Check All' link and hit delete it would delete all of the comments instead of just the ones that I had searched for. However it only deleted the ones that I had searched for and all of the rest were still there, which is great! Did you mean to code it like that?

Yes, I made it so the Check All / Clear All works for only what is currently showing on the screen. I've used that javascript code in another project and it worked great - so I decided to use it in here.

Quote:It only shows comments that are not approved. I had to change "WHERE is_approved = 0" to "WHERE is_approved = 0 OR 1" to show all of them. (The comments that I wanted to delete were approved).

Sorry about that .. I was excited to release this and forgot about that feature. What happened is I created a new admin page just for moderating comments and did not revert that setting.

Quote:The approve and delete buttons link to a 'moderate_comments' page which doesn't exist. I have a feeling this is linked to (1) - maybe you had created a 'moderate_comments' page which only shows comments that need approval.

I thought I changed that ... I guess not. Yikes.

Quote:I think the '<?=' will only work if the server has PHP short tags enabled, so it may be better to use '<?php echo' instead.

You're absolutely right - I will get that fixed.

Quote:You can add class="button" to the button to make it look like the other ones.

Ok great, I will add that to the code.

Quote:I didn't test what happens with the 'Check All' if there are multiple pages, so not sure what would happen there?

It should still work as intended, but I will double check on that.

Quote:Is it possible to convert the $_POST to a $_GET, so it's like the existing delete feature, or do you think $_POST is best in this case?

Why I tried using $_GET, it wasn't working for me. I'll look at that again today and see if I can figure out where I went wrong.
Reply
#4
I was able to get the bug fixes resolved (minus changing the $_POST to $_GET feature).

I'm not able to modify my original post, could you grab the attached file and modify my original post with this new one?

I'll try and get the last change you requested done tonight.

P.S. - I tested the "Check All " with multiple pages and it worked as intended.

Thanks.


Attached Files
.php   manage_comments.php (Size: 11.12 KB / Downloads: 12)
Reply
#5
Keep it as $_POST, it's okay. It's probably more suitable if there can be many comments to be deleted. The URL might struggle with it.

I'll add this for the next version. I could also do a bulk Approve and Send as well.
Have you completed the interview?
Reply
#6
(21-Apr-2013, 08:17 PM)Steven Wrote: Keep it as $_POST, it's okay. It's probably more suitable if there can be many comments to be deleted. The URL might struggle with it.

I'll add this for the next version. I could also do a bulk Approve and Send as well.

Yeah, I was thinking about that as well. The URL would get quite lengthy if the user has to do 100 delete's at once.

I've already went ahead and added an bulk approve feature to my personal version. All you need to do is change :

PHP Code:
<input type="checkbox" name="bulk_delete[]" value="<?php echo $id; ?>"> <?php echo $comment["name"]; ?></td> 

To like :

PHP Code:
<input type="checkbox" name="id_Array[]" value="<?php echo $id; ?>"> <?php echo $comment["name"]; ?></td> 

and then just add the buttons :

PHP Code:
<input type="button" class="button" value="Approve" onclick="return OnApprove();">&nbsp;&nbsp;<input type="button" class="button" value="Delete" onclick="return OnDelete();"

And then a little javascript magic ...

Code:
function OnApprove()
{
    if (confirm("Are you sure you want to APPROVE the selected comments?"))
    {
        document.getElementById('myform').action = "index.php?page=moderate_comments&action=bulkApprove&key=<?php echo $_SESSION['cmtx_csrf_key']; ?>";
        document.getElementById('myform').submit();
        return true;
    }
}
function OnDelete()
{
    if (confirm("Are you sure you want to DELETE the selected comments?"))
    {
        document.getElementById('myform').action = "index.php?page=moderate_comments&action=bulkDelete&key=<?php echo $_SESSION['cmtx_csrf_key']; ?>";
        document.getElementById('myform').submit();
        return true;
    }
}

Then finally the php code to handle the business :

PHP Code:
<?php
if ($_GET['action'] == "bulkApprove") {

    
$approve_messages $_POST['id_array'];
    
$N count($approve_messages);

    for(
$i=0$i $N$i++) {
        
$id $approve_messages[$i];
        if (!
cmtx_is_approved($id)) {
            
$id cmtx_sanitize($id);
            
mysql_query("UPDATE `" $cmtx_mysql_table_prefix "comments` SET `is_approved` = '1' WHERE `id` = '$id'");
        }
    }
    
?>
    <div class="success"><?php echo "Comments Approved" ?></div>
    <div style="clear: left;"></div>
    <?php
}

if (
$_GET['action'] == "bulkDelete") {

    
$delete_messages $_POST['id_array'];
    
$N count($delete_messages);

    for(
$i=0$i $N$i++) {
        
$id $delete_messages[$i];
        
$id cmtx_sanitize($id);
        
mysql_query("DELETE FROM `" $cmtx_mysql_table_prefix "comments` WHERE `id` = '$id'");
        
cmtx_delete_replies($id);
        
mysql_query("DELETE FROM `" $cmtx_mysql_table_prefix "voters` WHERE `comment_id` = '$id'");
        
mysql_query("DELETE FROM `" $cmtx_mysql_table_prefix "reporters` WHERE `comment_id` = '$id'");
    }
    
?>
    <div class="success"><?php echo "Comments Deleted" ?></div>
    <div style="clear: left;"></div>
    <?php
}
?>

That's how I am currently doing it - not sure if there is a better way to handle it, but it's working great here.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Sad Recent Comments..again noblues 2 1,931 26-Sep-2013, 06:44 PM
Last Post: noblues
  Recent Comments resp. Pages kooler 2 2,021 02-Aug-2013, 06:29 PM
Last Post: kooler
  Recent Comments CommiC 6 4,674 23-Jun-2013, 12:09 AM
Last Post: CommiC
  using permalinks on recent comments module otuzel 2 2,313 12-Mar-2013, 11:11 PM
Last Post: otuzel
  Recent Comments Add On Help brande 3 2,990 27-Jan-2013, 10:31 PM
Last Post: Steven
  Add-ons Recent Comments not working ! besric 4 3,704 07-Nov-2012, 05:16 PM
Last Post: besric
  Auto populate your comments table corculator 0 1,873 25-Feb-2012, 01:25 PM
Last Post: corculator
  Cannot get recent comments add on to work stevylake 1 2,184 04-Sep-2011, 01:25 PM
Last Post: Steven

Forum Jump:


Users browsing this thread: 1 Guest(s)