function antispam_api_cmd_comment_check in AntiSpam 7
Same name and namespace in other branches
- 6 antispam.module \antispam_api_cmd_comment_check()
AntiSpam API: Comment Check.
Parameters
string $content_type: Content type; it can be 'node' or 'comment' .
object $content: Content object.
Return value
array result[0] - return status (int) See constants ANTISPAM_API_RESULT_xxx. result[1] - signature (string) - DEFENSIO only (obsolete) result[2] - spaminess (float) value between 0 to 1 - DEFENSIO only (obsolete)
3 calls to antispam_api_cmd_comment_check()
- antispam_api_cmd_spam_check in ./
antispam.module - AntiSpam API: Generic Data Check.
- _antispam_comment_save in ./
antispam.module - Called from hook_comment_insert() and hook_comment_update().
- _antispam_node_save in ./
antispam.module - Called from hook_node_insert() and hook_node_update()
File
- ./
antispam.module, line 2157 - Primary hook implementations for the Antispam module.
Code
function antispam_api_cmd_comment_check($content_type, $content) {
if (!variable_get('antispam_connection_enabled', 1)) {
return array(
ANTISPAM_API_RESULT_ERROR,
);
}
$provider = antispam_get_service_provider();
$comment_data = antispam_prepare_comment_data($content_type, $content, $provider);
$api_host = antispam_get_api_host($provider);
$api_key = antispam_get_api_key($provider);
if (empty($api_key)) {
return array(
ANTISPAM_API_RESULT_ERROR,
);
}
$comment_data = array_merge(_antispam_api_prepare_request_data(), $comment_data);
$query_string = _antispam_api_build_query_string($comment_data);
$host = $api_key . '.' . $api_host;
$response = _antispam_api_http_post($query_string, $host, '/' . ANTISPAM_AKISMET_API_VERSION . '/comment-check');
if (!isset($response[1])) {
watchdog('antispam', "cheking a content failed: can not get a response back from the service provider " . antispam_get_provider_name($provider, FALSE));
return array(
ANTISPAM_API_RESULT_ERROR,
);
}
$result[0] = 'true' == $response[1] ? ANTISPAM_API_RESULT_IS_SPAM : ANTISPAM_API_RESULT_IS_HAM;
if (ANTISPAM_API_RESULT_IS_SPAM === $result[0]) {
if ($content_type == 'node') {
global $user;
$content_id = $content->nid;
$user_mail = isset($user->mail) ? $user->mail : '';
}
else {
// Comment.
$content_id = $content->cid;
$user_mail = $content->mail;
}
$hostname = !empty($content->hostname) ? $content->hostname : ip_address();
db_insert('antispam_spam_marks')
->fields(array(
'content_type' => $content_type,
'content_id' => $content_id,
'spam_created' => mktime(0, 0, 0, date("m"), date("d"), date("Y")),
'hostname' => $hostname,
'mail' => $user_mail,
))
->execute();
}
// Signature.
$result[1] = '';
// Spaminess.
$result[2] = 0.0;
return $result;
}