Make WordPress Core

Changeset 2258


Ignore:
Timestamp:
02/11/2005 01:52:19 AM (20 years ago)
Author:
saxmatt
Message:

Excellent spam moderation patch from CarLBanks - http://mosquito.wordpress.org/view.php?id=835

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/moderation.php

    r2233 r2258  
    55$parent_file = 'edit.php';
    66
    7 $wpvarstoreset = array('action', 'item_ignored', 'item_deleted', 'item_approved', 'feelinglucky');
     7$wpvarstoreset = array('action', 'item_ignored', 'item_deleted', 'item_approved', 'item_spam', 'feelinglucky');
    88for ($i=0; $i<count($wpvarstoreset); $i += 1) {
    99    $wpvar = $wpvarstoreset[$i];
     
    3939    $item_deleted = 0;
    4040    $item_approved = 0;
    41    
     41    $item_spam = 0;
     42
    4243    foreach($comment as $key => $value) {
    4344    if ($feelinglucky && 'later' == $value)
     
    4950                ++$item_ignored;
    5051                break;
    51            
    5252            case 'delete':
    5353                wp_set_comment_status($key, 'delete');
    5454                ++$item_deleted;
    5555                break;
    56            
     56            case 'spam':
     57                wp_set_comment_status($key, 'spam');
     58                ++$item_spam;
     59                break;
    5760            case 'approve':
    5861                wp_set_comment_status($key, 'approve');
    59                 if (get_settings('comments_notify') == true) {
     62                if ( get_settings('comments_notify') == true ) {
    6063                    wp_notify_postauthor($key);
    6164                }
     
    6669
    6770    $file = basename(__FILE__);
    68     header("Location: $file?ignored=$item_ignored&deleted=$item_deleted&approved=$item_approved");
     71    header("Location: $file?ignored=$item_ignored&deleted=$item_deleted&approved=$item_approved&spam=$item_spam");
    6972    exit();
    7073
     
    7881    echo "<div class='updated'>\n<p>";
    7982    $approved = (int) $_GET['approved'];
    80     $deleted = (int) $_GET['deleted'];
    81     $ignored = (int) $_GET['ignored'];
     83    $deleted  = (int) $_GET['deleted'];
     84    $ignored  = (int) $_GET['ignored'];
     85    $spam     = (int) $_GET['spam'];
    8286    if ($approved) {
    8387        if ('1' == $approved) {
     
    9498        }
    9599    }
     100    if ($spam) {
     101        if ('1' == $spam) {
     102        echo __("1 comment marked as spam <br />") . "\n";
     103        } else {
     104        echo sprintf(__("%s comments marked as spam <br />"), $spam) . "\n";
     105        }
     106    }
    96107    if ($ignored) {
    97108        if ('1' == $ignored) {
     
    140151echo " <a href=\"post.php?action=deletecomment&amp;p=".$comment->comment_post_ID."&amp;comment=".$comment->comment_ID."\" onclick=\"return confirm('" . sprintf(__("You are about to delete this comment by \'%s\'\\n  \'Cancel\' to stop, \'OK\' to delete."), $comment->comment_author) . "')\">" . __('Delete just this comment') . "</a> | "; ?>  <?php _e('Bulk action:') ?>
    141152    <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-approve" value="approve" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-approve"><?php _e('Approve') ?></label>
     153    <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-spam" value="spam" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-spam"><?php _e('Spam') ?></label>
    142154    <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-delete" value="delete" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-delete"><?php _e('Delete') ?></label>
    143155    <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-nothing" value="later" checked="checked" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-nothing"><?php _e('Defer until later') ?></label>
     
    174186    }
    175187}
    176 document.write('<ul><li><a href="javascript:markAllForApprove()"><?php _e('Mark all for approval'); ?></a></li><li><a href="javascript:markAllForDelete()"><?php _e('Mark all for deletion'); ?></a></li><li><a href="javascript:markAllForDefer()"><?php _e('Mark all for later'); ?></a></li></ul>');
     188function markAllAsSpam() {
     189    for (var i=0; i< document.approval.length; i++) {
     190        if (document.approval[i].value == "spam") {
     191            document.approval[i].checked = true;
     192        }
     193    }
     194}
     195document.write('<ul><li><a href="javascript:markAllForApprove()"><?php _e('Mark all for approval'); ?></a></li><li><a href="javascript:markAllAsSpam()"><?php _e('Mark all as spam'); ?></a></li><li><a href="javascript:markAllForDelete()"><?php _e('Mark all for deletion'); ?></a></li><li><a href="javascript:markAllForDefer()"><?php _e('Mark all for later'); ?></a></li></ul>');
    177196// ]]>
    178197</script>
  • trunk/wp-includes/comment-functions.php

    r2239 r2258  
    569569
    570570
    571 /* wp_set_comment_status:
    572    part of otaku42's comment moderation hack
    573    changes the status of a comment according to $comment_status.
    574    allowed values:
    575    hold   : set comment_approve field to 0
    576    approve: set comment_approve field to 1
    577    delete : remove comment out of database
    578    
    579    returns true if change could be applied
    580    returns false on database error or invalid value for $comment_status
    581  */
    582571function wp_set_comment_status($comment_id, $comment_status) {
    583572    global $wpdb;
     
    590579            $query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1";
    591580        break;
     581        case 'spam':
     582            $query = "UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID='$comment_id' LIMIT 1";
     583        break;
    592584        case 'delete':
    593585            $query = "DELETE FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1";
     
    606598
    607599
    608 /* wp_get_comment_status
    609    part of otaku42's comment moderation hack
    610    gets the current status of a comment
    611 
    612    returned values:
    613    "approved"  : comment has been approved
    614    "unapproved": comment has not been approved
    615    "deleted   ": comment not found in database
    616 
    617    a (boolean) false signals an error
    618  */
    619600function wp_get_comment_status($comment_id) {
    620     global $wpdb;
    621    
    622     $result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
    623     if ($result == NULL) {
    624         return "deleted";
    625     } else if ($result == "1") {
    626         return "approved";
    627     } else if ($result == "0") {
    628         return "unapproved";
    629     } else {
    630         return false;
    631     }
     601    global $wpdb;
     602   
     603    $result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
     604    if ($result == NULL) {
     605        return 'deleted';
     606    } else if ($result == '1') {
     607        return 'approved';
     608    } else if ($result == '0') {
     609        return 'unapproved';
     610    } else if ($result == 'spam') {
     611        return 'spam';
     612    } else {
     613        return false;
     614    }
    632615}
    633616
Note: See TracChangeset for help on using the changeset viewer.