function visitors_hosts in Visitors 8
Same name and namespace in other branches
- 7.2 reports/hosts.inc \visitors_hosts()
- 7 reports/hosts.inc \visitors_hosts()
- 7.0 reports/hosts.inc \visitors_hosts()
Menu callback; presents the "hosts" page.
Return value
string hosts report html source.
1 string reference to 'visitors_hosts'
- visitors_menu in ./
visitors.module - Menu callback. Prints a listing of active nodes on the site.
File
- reports/
hosts.inc, line 108 - Hours report and hits from host report for the visitors module.
Code
function visitors_hosts() {
$items_per_page = variable_get('visitors_lines_per_page', 10);
$header = array(
array(
'data' => t('#'),
),
array(
'data' => t('Host'),
'field' => 'visitors_ip',
),
array(
'data' => t('Pages'),
'field' => 'count',
'sort' => 'desc',
),
array(
'data' => t('Operations'),
),
);
$query = db_select('visitors', 'v')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
$query
->addExpression('COUNT(*)', 'count');
$query
->fields('v', array(
'visitors_ip',
));
visitors_date_filter_sql_condition($query);
$query
->groupBy('visitors_ip');
$query
->orderByHeader($header);
$query
->limit($items_per_page);
$count_query = db_select('visitors', 'v');
$count_query
->addExpression('COUNT(DISTINCT visitors_ip)');
visitors_date_filter_sql_condition($count_query);
$query
->setCountQuery($count_query);
$results = $query
->execute();
$rows = array();
$page = isset($_GET['page']) ? (int) $_GET['page'] : '';
$i = 0 + $page * $items_per_page;
$whois_enable = module_exists('whois');
$attr = array(
'attributes' => array(
'target' => '_blank',
'title' => t('Whois lookup'),
),
);
foreach ($results as $data) {
$ip = long2ip($data->visitors_ip);
$rows[] = array(
++$i,
$whois_enable ? l($ip, 'whois/' . $ip, $attr) : check_plain($ip),
$data->count,
l(t('hits'), 'visitors/hosts/' . $ip),
);
}
$output = visitors_date_filter();
$output .= theme('table', array(
'header' => $header,
'rows' => $rows,
));
$output .= theme('pager', array(
'quantity' => $items_per_page,
));
return $output;
}