function DEFNENSIO_FILTER($type, $name, $title, $url, $content, $openid = false) { global $hostURL, $blogURL, $database, $configVal, $defensio_conf; //if ( doesHaveOwnership() ) return true; // owner DEFENSIO_Init(); $defensio_meta = array(); $comment = array(); $comment['referrer'] = $_SERVER['HTTP_REFERER']; $comment['user-ip'] = preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']); $comment['user-ip'] = '168.126.63.1'; $comment['owner-url'] = $defensio_conf['blog']; $comment['comment_type'] = $type == 2 ? 'trackback' : 'comment'; $comment['comment-author'] = $name; $comment['article-date'] = strftime("%Y/%m/%d", time()); // $comment['permalink'] = $comment_perma_link; // Make sure it we don't send an SQL escaped string to the server $comment['comment-content'] = defensio_unescape_string($content); $comment['comment-author-url'] = $url; //$comment['comment-author-email'] = $email; // optional field $next_id = $type == 2 ? getTrackBacksNextId() : getCommentsNextId(); $comment_TYPE = $type == 2 ? 'T' : 'C'; // to using openid if ($openid) { $comment['openid'] = Acl::getIdentity('openid'); $comment['user-logged-in'] = 'true'; } // to testing // $comment['test-force'] = 'spam,x.xxxx'; // | 'ham,x.xxxx' ( 0 ~ 1) if ($r = defensio_post('audit-comment', $comment)) { $ar = Spyc::YAMLLoad($r); if (isset($ar['defensio-result'])) { if ($ar['defensio-result']['status'] == DF_SUCCESS) { // Set metadata about the comment $defensio_meta['spaminess'] = $ar['defensio-result']['spaminess']; $defensio_meta['signature'] = $ar['defensio-result']['signature']; error_log(print_r($ar, true)); if ($ar['defensio-result']['spam']) { $defensio_meta['spam'] = true; defensio_save_meta_data($comment_TYPE, $next_id, $defensio_meta); return false; } else { // not spam $defensio_meta['spaminess'] = 0; // if do you want check with Thief-cat algorithm, comment out the following two lines. if (!$defensio_conf['force_with_tca']) { defensio_save_meta_data($comment_TYPE, $next_id, $defensio_meta); return true; } } } } /* else { // Succesful http request, but Defensio failed. } */ } /* else { // Unsuccesful POST to the server. Defensio might be down. } */ //defensio_save_meta_data($comment_TYPE, $next_id, $defensio_meta); // there is problem in defensio. /////////////////////// // call fail // Do Local spam check with "Thief-cat algorithm" $count = 0; $tableName = $database['prefix'] . 'Trackbacks'; if ($type == 2) { $sql = 'SELECT COUNT(id) as cc FROM ' . $database['prefix'] . 'Trackbacks WHERE'; $sql .= ' url = \'' . POD::escapeString($url) . '\''; $sql .= ' AND isFiltered > 0'; if ($row = POD::queryRow($sql)) { $count += @$row[0]; } } else { // Comment Case $tableName = $database['prefix'] . 'Comments'; $sql = 'SELECT COUNT(id) as cc FROM ' . $database['prefix'] . 'Comments WHERE'; $sql .= ' comment = \'' . POD::escapeString($content) . '\''; $sql .= ' AND homepage = \'' . POD::escapeString($url) . '\''; $sql .= ' AND name = \'' . POD::escapeString($name) . '\''; $sql .= ' AND isFiltered > 0'; if ($row = POD::queryRow($sql)) { $count += @$row[0]; } } // Check IP $sql = 'SELECT COUNT(id) as cc FROM ' . $tableName . ' WHERE'; $sql .= ' ip = \'' . POD::escapeString($_SERVER['REMOTE_ADDR']) . '\''; $sql .= ' AND isFiltered > 0'; if ($row = POD::queryRow($sql)) { $count += @$row[0]; } $is_spam = $count >= 10 ? 1 : 0; if (isset($defensio_meta['spaminess']) and isset($defensio_meta['signature']) && $is_spam) { defensio_submit_spam($defensio_meta['signature']); } $defensio_meta['spam'] = $defensio_meta['spaminess'] = $is_spam; defensio_save_meta_data($comment_TYPE, $next_id, $defensio_meta); return !$is_spam; }
function defensio_submit_spam_comment($defensio_conf) { //Function to report the comment as spam which Defensio marked as not spam //Loop thru the $_POST['moderate_commnts_boxes'] and keep marking each comment as spam to Defensio global $pixelpost_db_prefix; if (is_array($_POST['moderate_commnts_boxes'])) { $number_of_images = count($_POST['moderate_commnts_boxes']); $counter = 0; $counter_no_signature = 0; $signatures = null; foreach ($_POST['moderate_commnts_boxes'] as $cid) { $query = "SELECT `signature` FROM {$pixelpost_db_prefix}comments WHERE id = '" . (int) $cid . "'"; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); if ($row['signature'] != null) { $counter = $counter + 1; if ($counter != $number_of_images) { $signatures .= $row['signature'] . ","; } else { $signatures .= $row['signature']; } //Since comment is spam, let's mark it as marked by defensio $query = "UPDATE {$pixelpost_db_prefix}comments SET publish = 'dfn' WHERE id = '" . (int) $cid . "'"; mysql_query($query); } else { // no signature was found $counter_no_signature = $counter_no_signature + 1; } } } // construct the error message $GLOBALS['defensio_result_message'] = '<div class="jcaption confirm">'; if ($signatures != null) { // we obviously have some signatures so submit them $r = defensio_submit_spam($defensio_conf, $signatures); $GLOBALS['defensio_result_message'] .= 'Reported ' . $counter . ' comments as SPAM to Defensio.'; if ($counter_no_signature > 0) { $GLOBALS['defensio_result_message'] .= 'However, ' . $counter_no_signature . 'comments could not be reported.'; } } else { $GLOBALS['defensio_result_message'] .= 'Could not report ' . $counter_no_signature . ' comments as SPAM to Defensio.'; } $GLOBALS['defensio_result_message'] .= '</div>'; } else { $GLOBALS['defensio_result_message'] = '<div class="jcaption confirm">You must select at least one comment.</div>'; } }