function wd_spamScore($body, $author, $words=NULL, $starters=NULL)
{
#
# score >= 1 - The message doesn't look like spam
# score == 0 - The message should be put to moderation
# score < -10 - The message is most certainly spam
#
$score = 0;
#
# put our body in lower case for checking
#
$body = strtolower($body);
#
# how many links are in the body ?
#
$n = max
(
array
(
substr_count($body, 'http://'),
substr_count($body, 'href'),
substr_count($body, 'ftp')
)
);
if ($n > 2)
{
#
# more than 2 : -1 point per link
#
$score -= $n;
}
else
{
#
# less than 3 : +2 points
#
$score += 2;
}
#
# now remove links
#
# html style:
$body = preg_replace('#\#', NULL, $body);
# bb style: [url] [/url]
$body = preg_replace('#\[url.+\/url\]#', NULL, $body);
# remaining addresses: http://
$body = preg_replace('#http://[^\s]+#', NULL, $body);
#
# how long is the body ?
#
$l = strlen($body);
if ($l > 20 && $n = 0)
{
#
# More than 20 characters and there's no links : +2 points
#
$score += 2;
}
else if ($l < 20)
{
#
# Less than 20 characters : -1 point
#
$score--;
}
#
# Keyword search
#
if (empty($words))
{
$words = array();
}
$words += array
(
'levitra', 'viagra', 'casino', 'free sex', 'porn', -online','adipex','advicer','baccarrat','blackjack','bllogspot','booker','byob','car-rental-e-site','car-rentals-e-site','carisoprodol','casino','casinos','chatroom','cialis','coolcoolhu','coolhu','credit-card-debt','credit-report-4u','cwas','cyclen','cyclobenzaprine','dating-e-site','day-trading','debt-consolidation','debt-consolidation-consultant','discreetordering','duty-free','dutyfree','equityloans','fioricet','flowers-leading-site','freenet-shopping','freenet','gambling-','hair-loss','health-insurancedeals-4u','homeequityloans','homefinance','holdem','holdempoker','holdemsoftware','holdemtexasturbowilson','hotel-dealse-site','hotele-site','hotelse-site','incest','insurance-quotesdeals-4u','insurancedeals-4u','jrcreations','levitra','macinstruct','mortgage-4-u','mortgagequotes','online-gambling','onlinegambling-4u','ottawavalleyag','ownsthis','palm-texas-holdem-game','paxil','penis','pharmacy','phentermine','poker-chip','poze','pussy','rental-car-e-site','ringtones','roulette','shemale','slot-machine','texas-holdem','thorcarlson','top-site','top-e-site','tramadol','trim-spa','ultram','valeofglamorganconservatives','viagra','vioxx','xanax','zolus'
);
foreach ($words as $word)
{
$n = substr_count($body, $word);
if (!$n)
{
continue;
}
$score -= $n;
}
#
# Body starts with...
#
if (empty($starters))
{
$starters = array();
}
$starters += array
(
'interesting', 'sorry', 'nice', 'cool', 'hi'
);
foreach ($starters as $word)
{
$pos = strpos($body, $word . ' ');
if ($pos === false)
{
continue;
}
if ($pos > 10)
{
continue;
}
$score -= 10;
break;
}
#
# Author's name has 'http://' in it
#
if (strpos($author, 'http://'))
{
$score -= 2;
}
#
# How many different words are used ?
#
$count = str_word_count($body);
if ($count < 10)
{
$score -= 5;
}
return $score;
}
//
// Creates a new post
//
function add_post($post_info, &$new_pid)
{
global $forum_db, $db_type, $forum_config, $lang_common;
($hook = get_hook('fn_add_post_start')) ? eval($hook) : null;
//Check Spam:
$isSpam = wd_spamScore($forum_db->escape($post_info['message']), $forum_db->escape($post_info['poster']));
if($isSpam >= 0){
// Add the post
$query = array(
'INSERT' => 'poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id',
'INTO' => 'posts',
'VALUES' => '\''.$forum_db->escape($post_info['poster']).'\', '.$post_info['poster_id'].', \''.get_remote_address().'\', \''.$forum_db->escape($post_info['message']).'\', '.$post_info['hide_smilies'].', '.$post_info['posted'].', '.$post_info['topic_id']
);
// If it's a guest post, there might be an e-mail address we need to include
if ($post_info['is_guest'] && $post_info['poster_email'] != null)
{
$query['INSERT'] .= ', poster_email';
$query['VALUES'] .= ', \''.$post_info['poster_email'].'\'';
}
($hook = get_hook('fn_qr_add_post')) ? eval($hook) : null;
$forum_db->query_build($query) or error(__FILE__, __LINE__);
$new_pid = $forum_db->insert_id();
if (!$post_info['is_guest'])
{
// Subscribe or unsubscribe?
if ($post_info['subscr_action'] == 1)
{
$query = array(
'INSERT' => 'user_id, topic_id',
'INTO' => 'subscriptions',
'VALUES' => $post_info['poster_id'].' ,'.$post_info['topic_id']
);
($hook = get_hook('fn_qr_add_subscription2')) ? eval($hook) : null;
$forum_db->query_build($query) or error(__FILE__, __LINE__);
}
else if ($post_info['subscr_action'] == 2)
{
$query = array(
'DELETE' => 'subscriptions',
'WHERE' => 'topic_id='.$post_info['topic_id'].' AND user_id='.$post_info['poster_id']
);
($hook = get_hook('fn_qr_delete_subscription')) ? eval($hook) : null;
$forum_db->query_build($query) or error(__FILE__, __LINE__);
}
}
// Count number of replies in the topic
$query = array(
'SELECT' => 'COUNT(p.id)',
'FROM' => 'posts AS p',
'WHERE' => 'p.topic_id='.$post_info['topic_id']
);
($hook = get_hook('fn_qr_get_topic_reply_count3')) ? eval($hook) : null;
$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
$num_replies = $forum_db->result($result, 0) - 1;
// Update topic
$query = array(
'UPDATE' => 'topics',
'SET' => 'num_replies='.$num_replies.', last_post='.$post_info['posted'].', last_post_id='.$new_pid.', last_poster=\''.$forum_db->escape($post_info['poster']).'\'',
'WHERE' => 'id='.$post_info['topic_id']
);
($hook = get_hook('fn_qr_update_topic4')) ? eval($hook) : null;
$forum_db->query_build($query) or error(__FILE__, __LINE__);
sync_forum($post_info['forum_id']);
require FORUM_ROOT.'include/search_idx.php';
update_search_index('post', $new_pid, $post_info['message']);
send_subscriptions($post_info, $new_pid);
}
else
{
error("Spam!","1");
}
($hook = get_hook('fn_add_post_end')) ? eval($hook) : null;
}