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

git-svn-id: http://svn.automattic.com/wordpress/trunk@2258 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2005-02-11 01:52:19 +00:00
parent 74458cebc9
commit 6d15f88945
2 changed files with 45 additions and 43 deletions

View File

@ -4,7 +4,7 @@ require_once('admin.php');
$title = __('Moderate comments');
$parent_file = 'edit.php';
$wpvarstoreset = array('action', 'item_ignored', 'item_deleted', 'item_approved', 'feelinglucky');
$wpvarstoreset = array('action', 'item_ignored', 'item_deleted', 'item_approved', 'item_spam', 'feelinglucky');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$wpvar = $wpvarstoreset[$i];
if (!isset($$wpvar)) {
@ -38,7 +38,8 @@ case 'update':
$item_ignored = 0;
$item_deleted = 0;
$item_approved = 0;
$item_spam = 0;
foreach($comment as $key => $value) {
if ($feelinglucky && 'later' == $value)
$value = 'delete';
@ -48,15 +49,17 @@ case 'update':
// wp_set_comment_status($key, "hold");
++$item_ignored;
break;
case 'delete':
wp_set_comment_status($key, 'delete');
++$item_deleted;
break;
case 'spam':
wp_set_comment_status($key, 'spam');
++$item_spam;
break;
case 'approve':
wp_set_comment_status($key, 'approve');
if (get_settings('comments_notify') == true) {
if ( get_settings('comments_notify') == true ) {
wp_notify_postauthor($key);
}
++$item_approved;
@ -65,7 +68,7 @@ case 'update':
}
$file = basename(__FILE__);
header("Location: $file?ignored=$item_ignored&deleted=$item_deleted&approved=$item_approved");
header("Location: $file?ignored=$item_ignored&deleted=$item_deleted&approved=$item_approved&spam=$item_spam");
exit();
break;
@ -77,8 +80,9 @@ require_once('admin-header.php');
if ( isset($_GET['deleted']) || isset($_GET['approved']) || isset($_GET['ignored']) ) {
echo "<div class='updated'>\n<p>";
$approved = (int) $_GET['approved'];
$deleted = (int) $_GET['deleted'];
$ignored = (int) $_GET['ignored'];
$deleted = (int) $_GET['deleted'];
$ignored = (int) $_GET['ignored'];
$spam = (int) $_GET['spam'];
if ($approved) {
if ('1' == $approved) {
echo __("1 comment approved <br />") . "\n";
@ -93,6 +97,13 @@ if ( isset($_GET['deleted']) || isset($_GET['approved']) || isset($_GET['ignored
echo sprintf(__("%s comments deleted <br />"), $deleted) . "\n";
}
}
if ($spam) {
if ('1' == $spam) {
echo __("1 comment marked as spam <br />") . "\n";
} else {
echo sprintf(__("%s comments marked as spam <br />"), $spam) . "\n";
}
}
if ($ignored) {
if ('1' == $ignored) {
echo __("1 comment unchanged <br />") . "\n";
@ -139,6 +150,7 @@ echo '<a href="post.php?action=editcomment&amp;comment='.$comment->comment_ID.'"
<?php
echo " <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:') ?>
<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>
<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>
<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>
<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>
</p>
@ -173,7 +185,14 @@ function markAllForDefer() {
}
}
}
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>');
function markAllAsSpam() {
for (var i=0; i< document.approval.length; i++) {
if (document.approval[i].value == "spam") {
document.approval[i].checked = true;
}
}
}
document.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>');
// ]]>
</script>

View File

@ -568,17 +568,6 @@ function discover_pingback_server_uri($url, $timeout_bytes = 2048) {
}
/* wp_set_comment_status:
part of otaku42's comment moderation hack
changes the status of a comment according to $comment_status.
allowed values:
hold : set comment_approve field to 0
approve: set comment_approve field to 1
delete : remove comment out of database
returns true if change could be applied
returns false on database error or invalid value for $comment_status
*/
function wp_set_comment_status($comment_id, $comment_status) {
global $wpdb;
@ -589,6 +578,9 @@ function wp_set_comment_status($comment_id, $comment_status) {
case 'approve':
$query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1";
break;
case 'spam':
$query = "UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID='$comment_id' LIMIT 1";
break;
case 'delete':
$query = "DELETE FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1";
break;
@ -605,30 +597,21 @@ function wp_set_comment_status($comment_id, $comment_status) {
}
/* wp_get_comment_status
part of otaku42's comment moderation hack
gets the current status of a comment
returned values:
"approved" : comment has been approved
"unapproved": comment has not been approved
"deleted ": comment not found in database
a (boolean) false signals an error
*/
function wp_get_comment_status($comment_id) {
global $wpdb;
$result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
if ($result == NULL) {
return "deleted";
} else if ($result == "1") {
return "approved";
} else if ($result == "0") {
return "unapproved";
} else {
return false;
}
global $wpdb;
$result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
if ($result == NULL) {
return 'deleted';
} else if ($result == '1') {
return 'approved';
} else if ($result == '0') {
return 'unapproved';
} else if ($result == 'spam') {
return 'spam';
} else {
return false;
}
}
if ( ! function_exists('wp_notify_postauthor') ) {