function antispam_callback_queue in AntiSpam 6
Same name and namespace in other branches
- 7 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 - Implementation of hook_menu().
File
- ./
antispam.admin.inc, line 498
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';
}
else {
if (!in_array($mode, $valid_modes)) {
drupal_not_found();
return;
}
}
if (empty($submode)) {
$submode = 'spam';
}
else {
if (!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;
}
// Dynamically build the queries using a write once method.
if ($allowed_nodes_count > 0) {
$sql_nodetypes = array();
foreach ($allowed_nodes as $type => $name) {
$sql_nodetypes[] = '\'' . $type . '\'';
}
$sql_nodetypes = implode(', ', $sql_nodetypes);
$sql_from = 'FROM {node} n LEFT JOIN {antispam_spam_marks} s ON s.content_id = n.nid AND s.content_type = \'node\'';
$sql_where = 'WHERE n.type IN (' . $sql_nodetypes . ') AND (%cond)';
$sql_nodes_cond = array(
'spam' => 's.content_id IS NOT NULL',
'unpublished' => 'n.status = 0',
'published' => 'n.status = 1',
);
$sql_nodes_stmt = 'SELECT n.*, r.body, u.name, s.spaminess, IFNULL(s.content_id, 0) AS spam_mark ' . $sql_from . ' INNER JOIN {users} u ON n.uid = u.uid ' . ' INNER JOIN {node_revisions} r ON n.nid = r.nid AND n.vid = r.vid ' . $sql_where;
$sql_nodes_cnt = 'SELECT COUNT(*) AS cnt ' . $sql_from . ' ' . $sql_where;
}
if (module_exists('comment') && $allowed_comments) {
$sql_from = 'FROM {comments} c LEFT JOIN {antispam_spam_marks} s ON s.content_id = c.cid AND s.content_type = \'comment\'';
$sql_where = 'WHERE (%cond)';
$sql_comments_cond = array(
'spam' => 's.content_id IS NOT NULL',
'unpublished' => 'c.status = ' . COMMENT_NOT_PUBLISHED,
'published' => 'c.status = ' . COMMENT_PUBLISHED,
);
$sql_comments_stmt = 'SELECT c.*, u.name AS registered_name, s.spaminess, IFNULL(s.content_id, 0) AS spam_mark ' . $sql_from . ' INNER JOIN {users} u ON c.uid = u.uid ' . $sql_where;
$sql_comments_cnt = 'SELECT COUNT(*) AS cnt ' . $sql_from . ' ' . $sql_where;
}
$sql = array(
'sql_comments_cnt' => $sql_comments_cnt,
'sql_comments_stmt' => $sql_comments_stmt,
'sql_comments_cond' => $sql_comments_cond,
'sql_nodes_cnt' => $sql_nodes_cnt,
'sql_nodes_stmt' => $sql_nodes_stmt,
'sql_nodes_cond' => $sql_nodes_cond,
);
// Present the overview page (default).
if ($mode == 'overview') {
$items = array();
if ($allowed_nodes_count > 0) {
$subitems = array();
foreach ($valid_submodes as $key => $title) {
$sql_cnt = str_replace('%cond', $sql_nodes_cond[$key], $sql_nodes_cnt);
$count = db_result(db_query(db_rewrite_sql($sql_cnt)));
$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', $subitems);
}
if (module_exists('comment') && $allowed_comments) {
$subitems = array();
foreach ($valid_submodes as $key => $title) {
$sql_cnt = str_replace('%cond', $sql_comments_cond[$key], $sql_comments_cnt);
$count = db_result(db_query(db_rewrite_sql($sql_cnt, 'c', 'cid')));
$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', $subitems);
}
return '<h3>' . t('Summary of content:') . '</h3>' . theme('item_list', $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>' . theme('item_list', $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', $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', $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) && count($_POST['items']) > 0) {
return drupal_get_form('antispam_confirm_multiple_operation');
}
else {
return drupal_get_form('antispam_moderation_form', $mode, $submode, $sql);
}
}