Active
Project:
Mollom
Version:
6.x-1.15
Component:
User interface
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
1 Nov 2010 at 19:35 UTC
Updated:
11 Jan 2011 at 23:26 UTC
You might be interested in doing this (I have it in a custom module):
function mollom_menu{
$items['block_ip/%'] = array(
'title' => 'Block an IP address',
'page callback' => 'mollom_block_ip',
'page arguments' => array(1),
'access arguments' => array('access statistics'),
'type' => MENU_CALLBACK,
);
$items['admin/reports/top_spammers'] = array(
'title' => 'Top Spammers',
'description' => 'Spam count by IP address',
'page callback' => 'mollom_top_spammers',
'access arguments' => array('access statistics'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Count spams by IP.
*/
function mollom_top_spammers() {
$rows_per_page = isset($_REQUEST['rows']) ? $_REQUEST['rows'] : variable_get('default_nodes_main', 10);
$noyes = array(t('No'), t('Yes'));
$dest = drupal_get_destination();
$rows = array();
$header = array(t('IP Address'), t('Count'), t('Blocked'));
$title = t('Top @count Spam Addresses', array('@count' => $rows_per_page));
drupal_set_title($title);
$query = "SELECT hostname, COUNT(hostname) AS num "
. "FROM {watchdog} "
. "WHERE type='mollom' AND message LIKE 'Spam%' "
. "GROUP BY hostname "
. "ORDER BY num DESC";
$result = db_query_range($query, 0, $rows_per_page);
while ($row = db_fetch_object($result)) {
$denied = drupal_is_denied('host', $row->hostname);
$rows[] = array(
$row->hostname,
array('data' => number_format($row->num), 'align' => 'right'),
array('data' => $noyes[$denied], 'align' => 'center'),
array('data' => ($denied ? NULL : l(t('block'), "block_ip/$row->hostname", array('query' => $dest))), 'align' => 'center'),
);
}
if (!$rows) {
$rows[] = array(array('data' => t('None found.'), 'colspan' => '20'));
}
return "<h1 class=\"title\">$title</h1>" . theme('table', $header, $rows);
}
/**
* Block an IP address.
*
* @param $ip - the IP address to block.
* @return none.
*
* NOTE: a destination query parameter is required.
*/
function mollom_block_ip($ip) {
db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', 'host', 0)", $ip);
drupal_set_message(t('The access rule has been added.'));
drupal_goto();
}
Comments
Comment #1
sun#1009760: Top Spammers report has been marked as duplicate of this issue, contains a different code proposal.
Comment #2
nancydruI think it was an older version. Sorry for the dupe.