function antispam_nodeapi in AntiSpam 6
Implementation of hook_nodeapi().
File
- ./
antispam.module, line 745
Code
function antispam_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'insert':
case 'update':
// If anti-spam servie connections are not enabled, we have nothing else to do here.
if (!variable_get('antispam_connection_enabled', 1)) {
antispam_notify_moderators('node', $node, $node->status ? TRUE : FALSE, FALSE);
break;
}
// Also quit asap, if current user has administration permission
// or permission to post without spam checking.
if (antispam_is_spam_moderator($node->type) || user_access('post with no antispam checking')) {
antispam_notify_moderators('node', $node, $node->status ? TRUE : FALSE, FALSE);
break;
}
// Now, check if it's about a node type that we have not been explicitly requested to check.
$check_nodetypes = variable_get('antispam_check_nodetypes', array());
if (!is_array($check_nodetypes) || !isset($check_nodetypes[$node->type]) || !$check_nodetypes[$node->type]) {
antispam_notify_moderators('node', $node, $node->status ? TRUE : FALSE, FALSE);
break;
}
// Ok, let's send a query to anti-spam service.
$api_result = antispam_api_cmd_comment_check('node', $node);
if ($api_result[0] == ANTISPAM_API_RESULT_IS_HAM) {
antispam_notify_moderators('node', $node, $node->status ? TRUE : FALSE, FALSE);
antispam_increase_counter(ANTISPAM_COUNT_HAM_DETECTED);
}
else {
if ($api_result[0] == ANTISPAM_API_RESULT_IS_SPAM) {
$node->signature = $api_result[1];
$node->spaminess = $api_result[2];
// Oops! We got spammed, let's mark the comment as such.
antispam_content_spam_operation('node', $node, 'submit-spam', FALSE);
antispam_increase_counter(ANTISPAM_COUNT_SPAM_DETECTED);
antispam_notify_moderators('node', $node, FALSE, TRUE);
}
else {
antispam_notify_moderators('node', $node, FALSE, FALSE);
}
// Unpublish the node, if necessary.
if ($node->status) {
antispam_content_publish_operation('node', $node, 'unpublish', FALSE);
}
// Since users won't see their content published, show them a polite explanation on why.
$content_type_name = node_get_types('name', $node);
drupal_set_message(t('Your %content-type-name has been queued for moderation by site administrators and will be published after approval.', array(
'%content-type-name' => $content_type_name,
)));
// Record the event to watchdog.
if ($api_result[0] == ANTISPAM_API_RESULT_ERROR) {
watchdog('content', 'AntiSpam service seems to be down, %content-type-name queued for manual approval: %title', array(
'%content-type-name' => $content_type_name,
'%title' => $node->title,
), WATCHDOG_WARNING, l(t('view'), 'node/' . $node->nid));
}
else {
watchdog('content', 'Spam detected by AntiSpam in %content-type-name: %title', array(
'%content-type-name' => $content_type_name,
'%title' => $node->title,
), WATCHDOG_WARNING, l(t('view'), 'node/' . $node->nid));
// If requested to, generate a delay so the spammer has to wait for a while.
if (($seconds = variable_get('antispam_antispambot_delay', 60)) > 0) {
sleep($seconds);
}
}
}
break;
case 'delete':
db_query('DELETE FROM {antispam_spam_marks} WHERE content_type = \'node\' AND content_id = %d', $node->nid);
break;
case 'load':
$rec = db_fetch_object(db_query('SELECT signature, spaminess FROM {antispam_spam_marks} WHERE content_type = \'node\' AND content_id = %d', $node->nid));
if ($rec) {
return $rec;
}
else {
return array(
'signature' => '',
'spaminess' => 1,
);
}
break;
}
}