<html><head /><body>
<?php 
require_once '../../../../../wp-config.php';
global $sk2_log;
include_once dirname(__FILE__) . "/sk2_core_class.php";
$comment_ID = (int) @$_REQUEST['c_id'];
$author_email = @$_REQUEST['c_author'];
//DEBUG:
$sk2_log->live_output = false;
$sk2_log->log_msg(__("Second Chance. Comment ID:", 'sk2') . $comment_ID, 4, $comment_ID, "2nd_chance");
$sk2_core = new sk2_core(0, true, false);
if ($sk2_core->load_comment($comment_ID)) {
    //echo "<pre>"; 	print_r($sk2_core->cur_comment);
    if ($sk2_core->cur_comment->author_email != $author_email) {
        die(__("Email not matching comment ID", 'sk2'));
    }
    $sk2_core->load_plugin_files();
    $sk2_core->second_chance();
} else {
    die(__("Invalid comment", 'sk2'));
}
?>
</body></html>
function sk2_filter_comment($comment_ID)
{
    include_once dirname(__FILE__) . "/sk2_core_class.php";
    if (!$comment_ID) {
        $sk2_log->log_msg(__("Structural failure: no comment ID sent to comment hook", 'sk2'), 10, 0, "web_UI", true, false);
        die(__("Aborting Spam Karma", 'sk2'));
    }
    $sk2_core = new sk2_core($comment_ID, false);
    $sk2_core->process_comment();
    $approved = $sk2_core->cur_comment->approved;
    $sk2_settings->save_settings();
    // should also save/display logs here...
    // doing notification ourselves (since we killed WP's)
    if ($approved == 'spam') {
        // your adventure stops here, cowboy...
        header("HTTP/1.1 403 Forbidden");
        header("Status: 403 Forbidden");
        _e("Sorry, but your comment has been flagged by the spam filter running on this blog: this might be an error, in which case all apologies. Your comment will be presented to the blog admin who will be able to restore it immediately.<br/>You may want to contact the blog admin via e-mail to notify him.", 'sk2');
        //		echo "<!-- ";
        //		$sk2_log->dump_logs();
        //		echo "-->";
        die;
    } else {
        if ('0' == $approved) {
            if ($sk2_core->cur_comment->can_unlock()) {
                // redirect to Second Chance page
                header('Expires: Mon, 26 Aug 1980 09:00:00 GMT');
                header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
                header('Cache-Control: no-cache, must-revalidate');
                header('Pragma: no-cache');
                $location = get_bloginfo('wpurl') . "/" . strstr(str_replace("\\", "/", dirname(__FILE__)), "wp-content/") . "/" . sk2_second_chance_file . "?c_id={$comment_ID}&c_author=" . urlencode($sk2_core->cur_comment->author_email);
                //$location = str_replace($_SERVER['DOCUMENT_ROOT'], "/", dirname(__FILE__)) . "/" . sk2_second_chance_file ."?c_id=$comment_ID&c_author=" . urlencode($sk2_core->cur_comment->author_email);
                $can_use_location = @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ? false : true;
                if (!$can_use_location && $phpver >= '4.0.1' && @preg_match('/Microsoft/', getenv('SERVER_SOFTWARE')) && php_sapi_name() == 'isapi') {
                    $can_use_location = true;
                }
                if ($can_use_location) {
                    header("Location: {$location}");
                } else {
                    header("Refresh: 0;url={$location}");
                }
                exit;
            } else {
                wp_notify_moderator($comment_ID);
            }
        } elseif (get_settings('comments_notify')) {
            wp_notify_postauthor($comment_ID, $sk2_core->cur_comment->type);
        }
    }
}
 function snowball_by(&$cmt_object, $criterion, $query_where, $coef_hit, $coef_raise)
 {
     $coef = $this->get_option_value("coef");
     $good_karma = $this->get_option_value("good_karma");
     $karma_diff = 0;
     if (($old = $this->get_granularity($query_where, "<", $cmt_object->cmt_date)) && ($recent = $this->get_granularity($query_where, ">", $cmt_object->cmt_date))) {
         $threshold = $this->get_option_value("threshold");
         if ($recent->cmt_count > $threshold) {
             if (!$old->cmt_count) {
                 if ($recent->karma_avg < 0) {
                     $karma_diff = -($coef_hit * pow($recent->cmt_count - $threshold, 2));
                     global $wpdb;
                     //$now_gmt = gmstrftime("'%Y-%m-%d %H:%M:%S'");
                     if (!$this->retro_spanked && ($retro_cmts = $wpdb->get_results("SELECT `comment_ID` FROM `{$wpdb->comments}` WHERE `comment_ID` != {$this->ID} AND `comment_author_IP` = '" . $cmt_object->author_ip . "' AND `comment_date_gmt` > DATE_SUB('" . $cmt_object->cmt_date . "', INTERVAL " . $this->get_option_value("old_enough") . " DAY)"))) {
                         // Unleash all minions of Hell on that bad boy's company...
                         $log = sprintf(__ngettext("Retro-spanked one comment. ID: ", "Retro-spanked %d comments. IDs: ", count($retro_cmts), 'sk2'), count($retro_cmts));
                         $this->retro_spanked = true;
                         $retro_spanking_core = new sk2_core(0, true, true);
                         //$retro_spanking_core->load_plugin_files($);
                         foreach ($retro_cmts as $retro_cmt) {
                             $retro_spanking_core->load_comment($retro_cmt->comment_ID);
                             $retro_spanking_core->cur_comment->modify_karma($karma_diff, get_class($this), __("Retro-spanking triggered by comment ID: ", 'sk2') . $this->ID);
                             $retro_spanking_core->treat_comment();
                             $retro_spanking_core->set_comment_sk_info();
                             $log .= $retro_cmt->comment_ID . ", ";
                         }
                         $log = substr($log, 0, -2) . ". " . __("Karma hit: ", 'sk2') . $karma_diff;
                         $this->log_msg($log, 5);
                     }
                     if (mysql_error()) {
                         $this->log_msg_mysql(__("Retro-spanking sql query failed.", 'sk2'), 7, $this->ID);
                     }
                 } elseif ($recent->karma_avg < $recent->cmt_count) {
                     // decent average: small penalty
                     $karma_diff = -0.5 * $coef_hit * ($recent->cmt_count - $recent->karma_avg + $threshold);
                 }
                 //DdV TODO: check if this is a flood and retro-moderate other comments
             } elseif ($coef * $old->cmt_count < $recent->cmt_count) {
                 if ($old->karma_avg < $good_karma) {
                     // bad average in the past: spank hard
                     $karma_diff = -($coef_hit * pow($recent->cmt_count - $old->cmt_count * 3, 2));
                 } else {
                     $karma_diff = $coef_hit * (-$recent->cmt_count - $old->cmt_count * 3);
                 }
                 // otherwise, spank soft
             } elseif ($old->karma_avg > $good_karma) {
                 if ($recent->karma_avg > $good_karma) {
                     $karma_diff = min($coef_raise * $recent->karma_avg * $old->karma_avg / pow($coef * $good_karma, 2) * $old->cmt_count, 1000);
                 } elseif ($recent->karma_avg > 0) {
                     $karma_diff = min($coef_raise * $recent->karma_avg * $old->karma_avg / pow($coef * $good_karma, 2) * $old->cmt_count, 1000);
                 }
                 // smaller push
             }
         } elseif ($old->cmt_count > $threshold) {
             $karma_diff = min($coef_raise * $old->karma_avg * $old->cmt_count / ($coef * $good_karma), 1000);
             // the better the average, the more comments: the nicer the gift...
             //$this->log_msg($coef_raise . " # " . $old->karma_avg . " # " . $old->cmt_count  . " # " . $coef . " # " . $good_karma . " ## " . $karma_diff, 8);
         }
     }
     $this->log_msg("Snowball karma_diff : {$karma_diff}", 3);
     if ($karma_diff) {
         $log = sprintf(__("Commenter granularity (based on %s): %d old comment(s) (karma avg: %f), %d recent comment(s) (karma avg: %f).", 'sk2'), $criterion, $old->cmt_count, round($old->karma_avg, 2), $recent->cmt_count, round($recent->karma_avg, 2));
         $this->modify_karma($cmt_object, $karma_diff, $log);
         $this->log_msg($log, 3);
     }
 }