function _antispam_node_save in AntiSpam 7
Called from hook_node_insert() and hook_node_update()
2 calls to _antispam_node_save()
- antispam_node_insert in ./
antispam.module - Implements hook_node_insert().
- antispam_node_update in ./
antispam.module - Implements hook_node_update().
File
- ./
antispam.module, line 762 - Primary hook implementations for the Antispam module.
Code
function _antispam_node_save(&$node) {
// 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);
return;
}
// 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);
return;
}
// 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);
return;
}
// 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];
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_type_get_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);
}
}
}
}