function comment_spamapi in Spam 5.3
Same name and namespace in other branches
- 6 content/spam_content_comment.inc \comment_spamapi()
Spam module _spamapi() hook.
File
- modules/
spam_comment.inc, line 48
Code
function comment_spamapi($op, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL) {
switch ($op) {
case 'content_module':
// Register with the spam api as a content type module.
return 'comment';
case 'content_id':
// Tell the spam module the id of a given comment.
if (is_object($arg1)) {
// The delete hook uses an object instead of an array.
$arg1 = (array) $arg1;
}
return _spam_comment_cid($arg1['cid']);
case 'content_types':
// Register the "comment" content type with the spam module.
return array(
array(
'name' => t('comments'),
'module' => t('comment'),
'title' => t('Comments'),
'description' => t('Check this box to filter comments for spam.'),
'default_value' => 1,
),
);
case 'filter_content_type':
return variable_get('spam_filter_comments', 1);
case 'filter_fields':
// Tell spam module which fields it should scan for spam.
$fields['main'] = array(
'subject',
'comment',
);
if (is_object($arg1)) {
// The delete hook uses an object instead of an array.
$arg1 = (array) $arg1;
}
if (isset($arg1['author'])) {
$fields['other'][] = 'author';
}
if (isset($arg1['name'])) {
$fields['other'][] = 'name';
}
if (isset($arg1['mail'])) {
$fields['other'][] = 'mail';
}
if (isset($arg1['homepage'])) {
$fields['other'][] = 'homepage';
}
return $fields;
case 'feedback_form':
$form = array();
if (is_numeric($form['cid'])) {
$form['cid'] = array(
'#type' => 'textfield',
'#title' => t('Comment ID'),
'#value' => $arg1['cid'],
'#disabled' => TRUE,
);
}
// fall through...
case 'error_form':
if (!is_array($form)) {
$form = array();
}
$form['comment'] = array(
'#type' => 'fieldset',
'#title' => 'Comment',
);
$form['comment']['title'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#value' => $arg1['subject'],
'#disabled' => TRUE,
);
$form['comment']['body'] = array(
'#type' => 'textarea',
'#title' => t('Comment'),
'#value' => $arg1['comment'],
'#disabled' => TRUE,
);
return $form;
case 'load':
return db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $arg1));
case 'title':
return db_result(db_query('SELECT subject FROM {comments} WHERE cid = %d', $arg1));
case 'edit_link':
return "comment/edit/{$arg1}";
case 'status':
$status = db_result(db_query('SELECT status FROM {comments} WHERE cid = %d', $arg1));
if ($status == COMMENT_PUBLISHED) {
return SPAM_PUBLISHED;
}
else {
return SPAM_NOT_PUBLISHED;
}
case 'hostname':
return db_result(db_query('SELECT hostname FROM {comments} WHERE cid = %d', $arg1));
case 'link':
if (is_object($arg1) && isset($arg1->cid)) {
return spam_links('comment', $arg1->cid, $arg1);
}
break;
case 'redirect':
$nid = db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', $arg1));
return drupal_goto("/node/{$nid}", NULL, "comment-{$arg1}");
case 'overview_filter_join':
return 'INNER JOIN {comments} c ON t.content_id = c.cid';
case 'overview_filter_where':
switch ($arg1) {
case 'title':
return "c.subject LIKE '%%%s%%'";
case 'status':
return 'c.status = %d';
}
case 'menu':
// Create page for listing all spam comments in comment admin section.
$items = array();
if ($arg1) {
$items[] = array(
'path' => 'admin/content/comment/list/spam',
'title' => t('Spam'),
'callback' => 'spam_comment_admin',
'callback arguments' => array(
'spam',
),
'access' => user_access('administer spam'),
'type' => MENU_LOCAL_TASK,
);
}
return $items;
case 'publish':
// Only update comments that exist and need to be published.
$nid = db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d AND status = %d OR status = %d', $arg1, COMMENT_NOT_PUBLISHED, SPAM_COMMENT));
if ($nid) {
db_query('UPDATE {comments} SET status = %d WHERE cid = %d', COMMENT_PUBLISHED, $arg1);
_comment_update_node_statistics($nid);
}
break;
case 'unpublish':
// Only update comments that exist and need to be unpublished.
// When 'unpublishing' comments, we actually mark them as spam.
$nid = db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d AND status = %d', $arg1, COMMENT_PUBLISHED));
if ($nid) {
db_query('UPDATE {comments} SET status = %d WHERE cid = %d', SPAM_COMMENT, $arg1);
_comment_update_node_statistics($nid);
}
break;
}
}