function blacklist($commentID) { global $wpbl_options, $wbbl_comment, $tableblacklist, $approved; $wpbl_comment = get_commentdata($commentID, 1, false); // first check the comment status based on WP core moderation $stat = wp_get_comment_status($commentID); if ($stat == 'deleted') { // no need to proceed since there is no comment return; } else { if ($stat == 'unapproved') { $held = True; } else { $held = False; } } // are we supposed to delete comments held by the core? if ($held && in_array('deletecore', $wpbl_options)) { mail_and_del($commentID, "Mail held for moderation outside WPBlacklist"); return; } else { if ($held && !in_array('checkcore', $wpbl_options)) { // comment held for moderation but option to check against blacklist not specified return; } } // IP check $sites = $GLOBALS['wpdb']->get_results("SELECT regex FROM {$tableblacklist} WHERE regex_type='ip'"); if ($sites) { foreach ($sites as $site) { $regex = "/^{$site->regex}/"; if (preg_match($regex, $wpbl_comment['comment_author_IP'])) { $held = True; if (in_array('deleteip', $wpbl_options)) { $approved = 'deleted'; mail_and_del($commentID, "Author IP: {$wpbl_comment['comment_author_IP']} matched {$regex}"); return; } break; } } } // RBL check if (!$held || in_array('deleterbl', $wpbl_options)) { $sites = $GLOBALS['wpdb']->get_results("SELECT regex FROM {$tableblacklist} WHERE regex_type='rbl'"); if ($sites) { foreach ($sites as $site) { $regex = $site->regex; if (preg_match("/([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)/", $wpbl_comment['comment_author_IP'], $matches)) { $rblhost = $matches[4] . "." . $matches[3] . "." . $matches[2] . "." . $matches[1] . "." . $regex; $resolved = gethostbyname($rblhost); if ($resolved != $rblhost) { $held = True; if (in_array('deleterbl', $wpbl_options)) { mail_and_del($commentID, "Author IP: {$wpbl_comment['comment_author_IP']} blacklisted by RBL {$regex}"); return; } break; } } } } } // expression check if (!$held || in_array('deletemail', $wpbl_options) || in_array('deleteurl', $wpbl_options) || in_array('delcommurl', $wpbl_options)) { $sites = $GLOBALS['wpdb']->get_results("SELECT regex FROM {$tableblacklist} WHERE regex_type='url'"); if ($sites) { foreach ($sites as $site) { $regex = "/{$site->regex}/i"; // echo "Regex: $regex <br />"; if (preg_match($regex, $wpbl_comment['comment_author_url'])) { $held = True; if (in_array('deleteurl', $wpbl_options)) { $approved = 'deleted'; mail_and_del($commentID, "Author URL: {$wpbl_comment['comment_author_url']} matched {$regex}"); return; } break; } if (preg_match($regex, $wpbl_comment['comment_author_email'])) { $held = True; if (in_array('deletemail', $wpbl_options)) { mail_and_del($commentID, "Author e-mail: {$wpbl_comment['comment_author_email']} matched {$regex}"); return; } break; } if (preg_match($regex, $wpbl_comment['comment_content'])) { $held = True; if (in_array('delcommurl', $wpbl_options)) { $approved = 'deleted'; mail_and_del($commentID, "Comment text contained {$regex}"); return; } break; } } } } if ($wpbl_comment['comment_type'] == 'trackback' && (!$held || in_array('deltbsp', $wpbl_options))) { // Let's check the remote site require_once XOOPS_ROOT_PATH . '/class/snoopy.php'; $snoopy = new Snoopy(); if ($snoopy->fetch($wpbl_comment['comment_author_url'])) { $orig_contents = $snoopy->results; } if (!strpos($orig_contents, $siteurl)) { $approved = 'deleted'; mail_and_del($commentID, "TrackBack URL does not contain my site URL"); } } if ($held) { $approved = 0; wp_set_comment_status($commentID, 'hold'); } else { $approved = 1; wp_set_comment_status($commentID, 'approve'); } // the following is essential not to break other plugins return $commentID; }
function blacklist($commentID) { global $wpdb, $url, $email, $comment, $user_ip, $wpbl_options, $tablecomments, $tableblacklist; // $row = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_ID='$commentID'"); // echo "Author: $row->comment_author<br />"; // first check the comment status based on WP core moderation $stat = wp_get_comment_status($commentID); if ($stat == 'deleted') { // no need to proceed since there is no comment return; } else { if ($stat == 'unapproved') { $approved = False; } else { $approved = True; } } // are we supposed to delete comments held by the core? if (!$approved && in_array('deletecore', $wpbl_options)) { mail_and_del($commentID, "Mail held for moderation outside WPBlacklist"); return; } // IP check $sites = $wpdb->get_results("SELECT regex FROM {$tableblacklist} WHERE regex_type='ip'"); if ($sites) { foreach ($sites as $site) { $regex = "/^{$site->regex}/"; if (preg_match($regex, $user_ip)) { $approved = False; if (in_array('deleteip', $wpbl_options)) { mail_and_del($commentID, "Author IP: {$user_ip} matched {$regex}"); return; } break; } } } // RBL check if ($approved || in_array('deleterbl', $wpbl_options)) { $sites = $wpdb->get_results("SELECT regex FROM {$tableblacklist} WHERE regex_type='rbl'"); if ($sites) { foreach ($sites as $site) { $regex = $site->regex; if (preg_match("/([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)/", $user_ip, $matches)) { $rblhost = $matches[4] . "." . $matches[3] . "." . $matches[2] . "." . $matches[1] . "." . $regex; $resolved = gethostbyname($rblhost); if ($resolved != $rblhost) { $approved = False; if (in_array('deleterbl', $wpbl_options)) { mail_and_del($commentID, "Author IP: {$user_ip} blacklisted by RBL {$regex}"); return; } break; } } } } } // expression check if ($approved || in_array('deletemail', $wpbl_options) || in_array('deleteurl', $wpbl_options) || in_array('delcommurl', $wpbl_options)) { $sites = $wpdb->get_results("SELECT regex FROM {$tableblacklist} WHERE regex_type='url'"); if ($sites) { foreach ($sites as $site) { $regex = "/{$site->regex}/i"; // echo "Regex: $regex <br />"; if (preg_match($regex, $url)) { $approved = False; if (in_array('deleteurl', $wpbl_options)) { mail_and_del($commentID, "Author URL: {$url} matched {$regex}"); return; } break; } if (preg_match($regex, $email)) { $approved = False; if (in_array('deletemail', $wpbl_options)) { mail_and_del($commentID, "Author e-mail: {$email} matched {$regex}"); return; } break; } if (preg_match($regex, $comment)) { $approved = False; if (in_array('delcommurl', $wpbl_options)) { mail_and_del($commentID, "Comment text contained {$regex}"); return; } break; } } } } if ($approved) { wp_set_comment_status($commentID, 'approve'); } else { wp_set_comment_status($commentID, 'hold'); } }