function antispam_content_spam_operation in AntiSpam 7
Same name and namespace in other branches
- 6 antispam.module \antispam_content_spam_operation()
Mark content as spam or remove the mark.
Parameters
string $content_type: Content type; can be either 'node' or 'comment'.
object $content: Content object.
string $op: Operation; it can be 'submit-spam' or 'submit-ham'.
boolean $log_action: TRUE to log action (default), otherwise the caller logs the action.
2 calls to antispam_content_spam_operation()
- antispam_callback_set_spam_status in ./
antispam.module - Menu callback; mark/unmark content as spam.
- antispam_confirm_multiple_operation_submit in ./
antispam.admin.inc - confirm_form callback; perform the actual operation against selected content.
File
- ./
antispam.module, line 1878 - Primary hook implementations for the Antispam module.
Code
function antispam_content_spam_operation($content_type, $content, $op, $log_action = TRUE) {
watchdog('antispam', 'antispam_content_spam_operation: type=' . $content_type . ' . op=' . $op);
if ($content_type == 'node') {
global $user;
$content_id = $content->nid;
$content_title = $content->title;
$content_link = l(t('view'), 'node/' . $content->nid);
$user_mail = isset($user->mail) ? $user->mail : '';
}
else {
$content_id = $content->cid;
$content_title = $content->subject;
$content_link = l(t('view'), 'node/' . $content->nid, array(
'fragment' => 'comment-' . $content->cid,
));
$user_mail = $content->mail;
}
watchdog('antispam', 'antispam_content_spam_operation: content_id=' . $content_id);
if (!isset($content->signature)) {
$content->signature = '';
}
if (!isset($content->spaminess)) {
$content->spaminess = 0.0;
}
if ($op == 'submit-spam') {
if (variable_get('antispam_connection_enabled', 1)) {
antispam_api_cmd_submit_spam($content_type, $content);
$action = $content_type == 'node' ? t('Content submitted as spam') : t('Comment submitted as spam');
}
else {
$action = $content_type == 'node' ? t('Content marked as spam') : t('Comment marked as spam');
}
$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,
'signature' => $content->signature,
'spaminess' => $content->spaminess,
))
->execute();
}
else {
if (variable_get('antispam_connection_enabled', 1)) {
antispam_api_cmd_submit_ham($content_type, $content);
$action = $content_type == 'node' ? t('Content submitted as ham') : t('Comment submitted as ham');
}
else {
$action = $content_type == 'node' ? t('Content marked as ham') : t('Comment marked as ham');
}
db_delete('antispam_spam_marks')
->condition('content_type', $content_type)
->condition('content_id', $content_id)
->execute();
}
if ($log_action) {
watchdog('content', '@action: @title', array(
'@action' => $action,
'@title' => $content_title,
), WATCHDOG_NOTICE, $content_link);
}
antispam_clear_cache();
}