function antispam_moderation_form in AntiSpam 7
Same name and namespace in other branches
- 6 antispam.admin.inc \antispam_moderation_form()
1 string reference to 'antispam_moderation_form'
- antispam_callback_queue in ./
antispam.admin.inc - Menu callback; Moderation queue.
File
- ./
antispam.admin.inc, line 672 - The antispam admin theme.
Code
function antispam_moderation_form($form, &$form_state, $mode = '', $submode = '') {
drupal_add_js('misc/tableselect.js');
// Build the moderation queue form.
$form = array();
$submode_menu = antispam_get_submode_menu($mode, $submode);
$form['submode_menu'] = array(
'#type' => 'item',
'#markup' => $submode_menu,
);
$form['options'] = array(
'#type' => 'fieldset',
'#title' => t('Moderator actions'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
);
$options = array(
'' => t('- select operation -'),
);
foreach (antispam_moderator_operations($mode, $submode) as $key => $operation_info) {
$options[$key] = $operation_info['title'];
}
$form['options']['operation'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => '',
);
$form['options']['submit'] = array(
'#type' => 'submit',
'#value' => t('Moderate'),
);
// Nodes.
if ($mode == 'nodes') {
$allowed_nodes = variable_get('antispam_check_nodetypes', array());
$sql_nodetypes = array();
foreach ($allowed_nodes as $type => $value) {
if (!empty($value)) {
$sql_nodetypes[] = $type;
}
}
$query = db_select('node', 'n');
$query
->join('users', 'u', 'u.uid = n.uid');
$query
->leftJoin('antispam_spam_marks', 's', 's.content_id = n.nid AND s.content_type = :type', array(
':type' => 'node',
));
$query
->fields('n');
$query
->addField('u', 'name', 'registered_name');
$query
->addField('s', 'spaminess');
$query
->addField('s', 'content_id', 'spam_mark');
$query
->condition('n.type', $sql_nodetypes, 'IN');
if ($submode == 'spam') {
$query
->isNotNull('s.content_id');
}
elseif ($submode == 'unpublished') {
$query
->condition('n.status', 0);
}
elseif ($submode == 'published') {
$query
->condition('n.status', 1);
}
$form['header'] = array(
'#type' => 'value',
'#value' => array(
// theme('table_select_header_cell'),
array(
'class' => 'select-all',
),
array(
'data' => t('Title'),
'field' => 'title',
),
array(
'data' => t('Type'),
'field' => 'type',
),
array(
'data' => t('Author'),
'field' => 'name',
),
array(
'data' => t('Status'),
'field' => 'status',
),
array(
'data' => t('Last changed'),
'field' => 'changed',
'sort' => 'desc',
),
),
);
}
else {
$query = db_select('comment', 'c');
$query
->join('users', 'u', 'u.uid = c.uid');
$query
->join('field_data_comment_body', 'e', 'e.entity_id = c.cid');
$query
->leftJoin('antispam_spam_marks', 's', 's.content_id = c.cid AND s.content_type = :type', array(
':type' => 'comment',
));
$query
->fields('c');
$query
->addField('u', 'name', 'registered_name');
$query
->addField('s', 'spaminess');
$query
->addField('s', 'content_id', 'spam_mark');
$query
->addField('e', 'comment_body_value', 'body');
if ($submode == 'spam') {
$query
->isNotNull('s.content_id');
}
elseif ($submode == 'unpublished') {
$query
->condition('c.status', COMMENT_NOT_PUBLISHED);
}
elseif ($submode == 'published') {
$query
->condition('c.status', COMMENT_PUBLISHED);
}
$form['header'] = array(
'#type' => 'value',
'#value' => array(
// theme('table_select_header_cell'),
array(
'class' => 'select-all',
),
array(
'data' => t('Subject'),
'field' => 'subject',
),
array(
'data' => t('Author'),
'field' => 'name',
),
array(
'data' => t('Status'),
'field' => 'status',
),
array(
'data' => t('Last changed'),
'field' => 'created',
'sort' => 'desc',
),
),
);
}
$records_per_page = variable_get('antispam_records_per_page', 50);
$query = $query
->extend('PagerDefault')
->limit($records_per_page)
->extend('TableSort')
->orderByHeader($form['header']['#value']);
$result = $query
->execute();
$items = array();
$now = time();
foreach ($result as $content) {
// Nodes.
if ($mode == 'nodes') {
$items[$content->nid] = '';
$content->name = $content->uid ? $content->registered_name : $content->name;
$form['title'][$content->nid] = array(
'#value' => l($content->title, 'node/' . $content->nid, array(
'attributes' => array(
'title' => truncate_utf8(render($content->body), ANTISPAM_BODY_TOOLTIP_LEN),
),
)) . ' ' . theme('mark', array(
'type' => node_mark($content->nid, $content->changed),
)),
);
$form['type'][$content->nid] = array(
'#value' => node_type_get_name($content),
);
$form['author'][$content->nid] = array(
'#value' => theme('username', array(
'account' => user_load($content->uid),
)),
);
$form['status'][$content->nid] = array(
'#value' => $content->status ? t('published') : t('not published'),
);
if (empty($content->spam_mark)) {
$content->spam_mark = 0;
}
if ($content->spam_mark) {
$form['status'][$content->nid]['#value'] .= '/' . t('spam');
}
$form['created'][$content->nid] = array(
'#value' => t('%time ago', array(
'%time' => format_interval($now - $content->changed),
)),
);
}
else {
$items[$content->cid] = '';
$content->name = $content->uid ? $content->registered_name : $content->name;
$form['title'][$content->cid] = array(
'#value' => l($content->subject, 'node/' . $content->nid, array(
'attributes' => array(
'title' => truncate_utf8(render($content->body), ANTISPAM_BODY_TOOLTIP_LEN),
),
'fragment' => 'comment-' . $content->cid,
)) . ' ' . theme('mark', array(
'type' => node_mark($content->cid, $content->created),
)),
);
$form['author'][$content->cid] = array(
'#value' => theme('username', array(
'account' => user_load($content->uid),
)),
);
$form['status'][$content->cid] = array(
'#value' => $content->status == COMMENT_PUBLISHED ? t('published') : t('not published'),
);
if ($content->spam_mark) {
$form['status'][$content->cid]['#value'] .= '/' . t('spam');
}
$form['created'][$content->cid] = array(
'#value' => t('%time ago', array(
'%time' => format_interval($now - $content->created),
)),
);
}
}
$form['mode'] = array(
'#type' => 'hidden',
'#value' => $mode,
);
$form['submode'] = array(
'#type' => 'hidden',
'#value' => $submode,
);
$form['items'] = array(
'#type' => 'checkboxes',
'#options' => $items,
);
$form['pager'] = array(
'#value' => theme('pager'),
);
return $form;
}