function antispam_callback_queue in AntiSpam 7
Same name and namespace in other branches
- 6 antispam.admin.inc \antispam_callback_queue()
Menu callback; Moderation queue.
Parameters
string mode: 'overview' (default), 'nodes', 'comments', 'statistics'.
string submode: 'spam' (default), 'unpublished', 'published'.
1 string reference to 'antispam_callback_queue'
- antispam_menu in ./
antispam.module - Implements hook_menu().
File
- ./
antispam.admin.inc, line 492 - The antispam admin theme.
Code
function antispam_callback_queue($mode = '', $submode = '') {
// Make sure we're dealing with a valid mode and submode.
$valid_modes = array(
'nodes',
'comments',
'statistics',
);
$valid_submodes = array(
'spam' => t('Spam'),
'unpublished' => t('Unpublished'),
'published' => t('Published'),
);
if (empty($mode)) {
$mode = 'overview';
}
elseif (!in_array($mode, $valid_modes)) {
drupal_not_found();
return;
}
if (empty($submode)) {
$submode = 'spam';
}
elseif (!isset($valid_submodes[$submode])) {
drupal_not_found();
return;
}
// Compute exactly what the current user is allowed to moderate.
$moderator_types = antispam_get_moderator_types();
$moderator_types_count = count($moderator_types);
$allowed_comments = isset($moderator_types['comments']) ? TRUE : FALSE;
$allowed_nodes = $moderator_types;
if ($allowed_comments) {
unset($allowed_nodes['comments']);
}
$allowed_nodes_count = count($allowed_nodes);
// Make sure the user has some kind of content administration/moderation
// permission.
if ($allowed_nodes_count <= 0 && !$allowed_comments) {
drupal_access_denied();
return;
}
// Present the overview page (default).
if ($mode == 'overview') {
$items = array();
// ------ node ------
if ($allowed_nodes_count > 0) {
$subitems = array();
foreach ($valid_submodes as $key => $title) {
$query = db_select('node', 'n');
$query
->leftJoin('antispam_spam_marks', 's', 's.content_id = n.nid AND s.content_type = :type', array(
':type' => 'node',
));
$query
->fields('n');
if ($key == 'spam') {
$query
->isNotNull('s.content_id');
}
elseif ($key == 'unpublished') {
$query
->condition('n.status', NODE_NOT_PUBLISHED);
}
elseif ($key == 'published') {
$query
->condition('n.status', NODE_PUBLISHED);
}
$query
->addTag('node_access');
$count = $query
->countQuery()
->execute()
->fetchField();
/*
$sql_cnt = str_replace('%cond', $sql_nodes_cond[$key], $sql_nodes_cnt);
$count = db_query(db_rewrite_sql($sql_cnt))->fetchField();
*/
$path = 'admin/content/antispam/nodes' . ($key == 'spam' ? '' : '/' . $key);
$label = $count > 0 ? l($title, $path) : $title;
$subitems[] = '<p><strong>' . $label . ': ' . $count . '</strong></p>';
}
$items[] = '<h4>' . t('Nodes') . '</h4>' . theme('item_list', array(
'items' => $subitems,
));
}
// ------ comment ------
if ($allowed_comments) {
$subitems = array();
foreach ($valid_submodes as $key => $title) {
$query = db_select('comment', 'c');
$query
->leftJoin('antispam_spam_marks', 's', 's.content_id = c.cid AND s.content_type = :type', array(
':type' => 'comment',
));
$query
->fields('c');
if ($key == 'spam') {
$query
->isNotNull('s.content_id');
}
elseif ($key == 'unpublished') {
$query
->condition('c.status', 0);
}
elseif ($key == 'published') {
$query
->condition('c.status', 1);
}
$query
->addTag('node_access');
$count = $query
->countQuery()
->execute()
->fetchField();
$path = 'admin/content/antispam/comments' . ($key == 'spam' ? '' : '/' . $key);
$label = $count > 0 ? l($title, $path) : $title;
$subitems[] = '<p><strong>' . $label . ': ' . $count . '</strong></p>';
}
$items[] = '<h4>' . t('Comments') . '</h4>' . theme('item_list', array(
'items' => $subitems,
));
}
return '<h3>' . t('Summary of content:') . '</h3>' . theme('item_list', array(
'items' => $items,
));
}
// Present the statistics page (default).
if ($mode == 'statistics') {
$items = array();
$provider_name = antispam_get_provider_name(antispam_get_service_provider(), TRUE);
$items[] = $provider_name;
$output = '<h3>' . t('Current Service Provider') . '</h3>';
$output .= theme('item_list', array(
'items' => $items,
)) . '<br />';
$items = array();
$counts = antispam_get_total_counter();
$total_checked = $counts['total_spam'] + $counts['total_ham'];
$total_false = $counts['total_fnegative'] + $counts['total_fpositive'];
$accuracy = $total_checked ? round(100.0 - (double) $total_false / (double) $total_checked * 100, 2) : 0;
$since = variable_get('antispam_counter_since', array(
'day' => date('j'),
'month' => date('n'),
'year' => date('Y'),
));
$start = mktime(0, 0, 0, $since['month'], $since['day'], $since['year']);
$days = (int) ((time() - $start) / (60 * 60 * 24) + 1);
$subitems = array();
$subitems[] = t('Total Spams: !total (avg: !avg/day)', array(
'!total' => $counts['total_spam'],
'!avg' => round($counts['total_spam'] / $days, 2),
));
$subitems[] = t('Total Hams: !total (avg: !avg/day)', array(
'!total' => $counts['total_ham'],
'!avg' => round($counts['total_ham'] / $days, 2),
));
$items[] = '<p>' . t('Total Checked: !total (avg: !avg/day)', array(
'!total' => $total_checked,
'!avg' => round($total_checked / $days, 2),
)) . theme('item_list', array(
'items' => $subitems,
)) . '</p>';
$items[] = '<p>' . t('Total False Negatives: !total (avg: !avg/day)', array(
'!total' => $counts['total_fnegative'],
'!avg' => round($counts['total_fnegative'] / $days, 2),
)) . '</p>';
$items[] = '<p>' . t('Total False Positives: !total (avg: !avg/day)', array(
'!total' => $counts['total_fpositive'],
'!avg' => round($counts['total_fpositive'] / $days, 2),
)) . '</p>';
$items[] = '<p><strong>' . t('Accuracy: !accuracy %', array(
'!accuracy' => $accuracy,
)) . '</strong></p>';
$output .= '<h3>' . t('Statistics since @since (!days)', array(
'@since' => antispam_get_counting_since(),
'!days' => format_plural($days, '1 day', '@count days'),
)) . '</h3>' . theme('item_list', array(
'items' => $items,
));
// Generate graph using Google Chart API.
$output .= antispam_generate_statistics_graph();
// Footnotes.
$output .= '<p><br /><i>' . t('Note: <strong>False negatives</strong> is the number of spams that were incorrectly tagged as hams, while <strong>false positives</strong> is the number of hams that were incorrectly tagged as spams. These numbers totally depends on your manual operation to retrain the antispam service using <strong>submit as spam</strong> and <strong>submit as ham</strong> feature.') . '</i></p>';
$output .= '<p><i>' . t('Note: <strong>Accuracy</strong> is calculated by the following formula:<br /> accuracy(%) = 100 - (((false negative + false positive) / total checked) * 100)') . '</i></p>';
return $output;
}
if (isset($_POST) && isset($_POST['items']) && count($_POST['items']) > 0) {
return drupal_get_form('antispam_confirm_multiple_operation', $mode, $submode);
}
else {
return drupal_get_form('antispam_moderation_form', $mode, $submode);
}
}