function comment_spamapi_form_alter in Spam 6
Same name and namespace in other branches
- 5.3 modules/spam_comment.inc \comment_spamapi_form_alter()
Form alter gets its own function so we can reference &$form without causing errors in PHP4 installations. (If we use spamapi, we have to set a default, which PHP4 doesn't support.)
File
- content/
spam_content_comment.inc, line 250 - Include file for integration with comments.
Code
function comment_spamapi_form_alter(&$form, &$form_state, $form_id) {
// Scan comments before they are inserted into the database
if ($form_id == 'comment_form' && is_array($form) && in_array(variable_get('spam_visitor_action', SPAM_ACTION_PREVENT), array(
SPAM_ACTION_PREVENT_SILENT,
SPAM_ACTION_PREVENT,
))) {
$form['#validate'][] = 'comment_spam_scan';
}
else {
if ($form_id == 'comment_admin_overview' || $form_id == 'spam_content_comment_admin_overview') {
$form['#spam_submit_valuetype'] = 'comments';
$form['#spam_submit_itemtype'] = 'comment';
$form['#submit'] = array_merge(array(
'spam_admin_overview_submit',
), $form['#submit']);
$parameters = $form['#parameters'];
if (is_array($parameters)) {
if (!in_array('new', $parameters)) {
$form['options']['operation']['#options']['markasnotspam'] = t('Mark the selected comments as not spam');
}
if (!in_array('spam', $parameters)) {
$form['options']['operation']['#options']['markasspam'] = t('Mark the selected comments as spam');
}
if (in_array('new', $parameters)) {
$form['options']['operation']['#options']['teachnotspam'] = t('Teach filters selected comments are not spam');
}
}
if (isset($form_state['post']['comments']) && is_array($form_state['post']['comments'])) {
foreach ($form_state['post']['comments'] as $cid) {
switch ($form_state['post']['operation']) {
case 'markasspam':
$score = _spam_content_comment_score($cid);
if (!spam_score_is_spam($score)) {
spam_mark_as_spam('comment', $cid);
}
break;
case 'markasnotspam':
$score = _spam_content_comment_score($cid);
if (spam_score_is_spam($score)) {
spam_mark_as_not_spam('comment', $cid);
}
break;
case 'teachnotspam':
spam_mark_as_not_spam('comment', $cid);
break;
}
}
}
}
}
}