function spam_content_update in Spam 5.3
Same name and namespace in other branches
- 6 spam.module \spam_content_update()
This function is called when content on your website is updated.
Parameters
$content: An array holding the complete content.
$type: A string naming the type of content being updated.
3 calls to spam_content_update()
- comment_comment in modules/
spam_comment.inc - Drupal _comment() hook.
- node_nodeapi in modules/
spam_node.inc - Drupal _nodeapi() hook.
- spam_user in modules/
spam_user.inc
File
- ./
spam.module, line 275
Code
function spam_content_update($content, $type, $extra = array()) {
if (!spam_filter_content_type($content, $type, $extra)) {
return;
}
$id = spam_invoke_module($type, 'content_id', $content, $extra);
spam_log(SPAM_VERBOSE, 'spam_content_update', t('updating'), $type, $id);
$error = FALSE;
$score = 0;
if ($id) {
$score = spam_content_filter($content, $type, $extra);
db_query("UPDATE {spam_tracker} SET score = %d, hostname = %d, timestamp = %d WHERE content_type = '%s' AND content_id = '%s'", $score, time(), $type, $id);
$sid = db_result(db_query("SELECT sid FROM {spam_tracker} WHERE content_type = '%s' AND content_id = %d", $type, $id));
if ($sid) {
watchdog('spam', t('Updated %type with id %id in 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'] = $_SERVER['REMOTE_ADDR'];
}
$fields = spam_invoke_module($type, 'filter_fields', $content, $extra);
if (!empty($fields) && is_array($fields['main'])) {
$gid = 0;
$filters = db_query('SELECT name, module, gain FROM {spam_filters} WHERE gid = %d AND status = %d ORDER BY weight', $gid, SPAM_FILTER_ENABLED);
while ($filter = db_fetch_object($filters)) {
// Let filters act on insert action.
spam_invoke_module($filter->module, 'update', $type, $content, $fields, $extra);
}
}
else {
watchdog('spam', t('Function spam_content_update failed, no fields are defined for %type content type.', array(
'%type' => $type,
)), WATCHDOG_ERROR);
$error = -3;
}
}
else {
watchdog('spam', t('Update to %type with id %id not filtered before, inserting.', array(
'%type' => $type,
'%id' => $id,
)), WATCHDOG_NOTICE);
// It seems that the content hasn't ever been scanned before, let's try
// inserting it.
$error = spam_content_insert($content, $type, $extra);
}
}
else {
watchdog('spam', t('Function spam_content_update failed, unable to update %type in spam_tracker table, no id found in the content array.', array(
'%type' => $type,
)), WATCHDOG_ERROR);
$error = -1;
}
// This content became spam during an update, mark it as such.
if ($score >= variable_get('spam_threshold', SPAM_DEFAULT_THRESHOLD)) {
spam_mark_as_spam($type, $id, $extra);
$_SESSION['content'] = serialize((array) $content);
$_SESSION['type'] = $type;
spam_update_statistics(t('prevented spam @type', array(
'@type' => $type,
)));
spam_log(SPAM_DEBUG, 'spam_content_update', t('redirecting to spam/denied'), $type, $id);
drupal_goto('spam/denied');
}
return $error;
}