function spam_content_insert in Spam 6
Same name and namespace in other branches
- 5.3 spam.module \spam_content_insert()
This function is called when new content is first posted to your website.
Parameters
$content: An array holding the complete content.
$type: A string naming the type of content being inserted.
5 calls to spam_content_insert()
- contact_spamapi in content/
spam_content_contact.inc - Spam module _spamapi() hook.
- spam_comment in content/
spam_content_comment.inc - Drupal _comment() hook.
- spam_content_update in ./
spam.module - This function is called when content on your website is updated.
- spam_nodeapi in content/
spam_content_node.inc - Drupal _nodeapi() hook.
- spam_user in content/
spam_content_user.inc
File
- ./
spam.module, line 225 - Spam module, v3 Copyright(c) 2006-2008 Jeremy Andrews <jeremy@tag1consulting.com>. All rights reserved.
Code
function spam_content_insert($content, $type, $extra = array()) {
if (!spam_filter_content_type($content, $type, $extra)) {
return;
}
$id = spam_invoke_module($type, 'content_id', $content, $extra);
if (spam_bypass_filters() || user_access('bypass filters')) {
spam_log(SPAM_DEBUG, 'spam_content_insert', t('bypassing filters'), $type, $id);
return;
}
spam_log(SPAM_VERBOSE, 'spam_content_insert', t('inserting'), $type, $id);
$score = 0;
$error = FALSE;
if ($id) {
$spam = spam_content_is_spam($content, $type, $extra);
$score = $spam['score'];
// this is neccessary in case that some content types have potentially identical IDs, such as hashes.
$sid = db_result(db_query("SELECT sid FROM {spam_tracker} WHERE content_type = '%s' AND content_id = '%s'", $type, $id));
if (!$sid) {
db_query("INSERT INTO {spam_tracker} (content_type, content_id, score, hostname, timestamp) VALUES('%s', '%s', %d, '%s', %d)", $type, $id, $score, ip_address(), time());
$sid = db_result(db_query("SELECT sid FROM {spam_tracker} WHERE content_type = '%s' AND content_id = '%s'", $type, $id));
}
if ($sid) {
watchdog('spam', 'Inserted %type with id %id into spam tracker table.', array(
'%type' => $type,
'%id' => $id,
), WATCHDOG_NOTICE);
$extra['sid'] = $sid;
if (!isset($extra['host'])) {
// Content type modules can set this value, should REMOTE_ADDR not be
// the correct IP for their content type.
$extra['host'] = ip_address();
}
$fields = spam_invoke_module($type, 'filter_fields', $content, $extra);
if (!empty($fields) && is_array($fields['main'])) {
$filters = db_query('SELECT name, module, gain FROM {spam_filters} WHERE status = %d ORDER BY weight', SPAM_FILTER_ENABLED);
while ($filter = db_fetch_object($filters)) {
// Let filters act on insert action.
spam_invoke_module($filter->module, 'insert', $type, $content, $fields, $extra);
}
}
else {
watchdog('spam', 'Function spam_content_insert failed, no fields are defined for %type content type.', array(
'%type' => $type,
), WATCHDOG_ERROR);
$error = -3;
}
}
else {
watchdog('spam', 'Function spam_content_insert failed, unable to insert %type with id %id into spam_tracker table.', array(
'%type' => $type,
'%id' => $id,
), WATCHDOG_ERROR);
$error = -2;
}
}
else {
watchdog('spam', 'Function spam_content_insert failed, unable to insert %type into spam_tracker table, no id found in the content array.', array(
'%type' => $type,
), WATCHDOG_ERROR);
$error = -1;
}
// This content became spam during an insert, mark it as such.
if ($score >= variable_get('spam_threshold', SPAM_DEFAULT_THRESHOLD)) {
spam_mark_as_spam($type, $id, $extra);
$_SESSION['spam_content'] = serialize((array) $content);
$_SESSION['spam_type'] = $type;
if (!in_array(variable_get('spam_visitor_action', SPAM_ACTION_PREVENT), array(
SPAM_ACTION_HOLD,
))) {
_spam_update_statistics(t('prevented spam @type', array(
'@type' => $type,
)));
spam_log(SPAM_DEBUG, 'spam_content_insert', t('redirecting to spam/denied'), $type, $id);
drupal_goto('spam/denied');
}
}
return $error;
}