geeky notes on web (drupal) and .net (c#) programming, whichever prevails at the moment

 

All commits tagged "module"

 

Enhancing the drupal statistics: ip geolocation

Drupal statistics logs every access to a page. It is kind-of useful when the user is logged in, but there are times when you want to see where the user physically comes from. For this situation you can just go into "details" and see his ip address. Copy and paste it into some kind of online ip2location service and see the results.

This code allows you to shorten that cycle to just one click.

Here we will enhance the statistics page, providing link to a ip2location free service

open the statistics.module and find the statistics_recent_hits function. The changes in code are marked bold

function statistics_recent_hits() {
....
  $sql = 'SELECT a.aid, a.path, a.title, a.uid, u.name, a.timestamp<b>, a.hostname</b> FROM {accesslog} a LEFT JOIN {users} u ON u.uid = a.uid' . tablesort_sql($header);

  $result = pager_query($sql, 30);
  while ($log = db_fetch_object($result)) {
    $rows[] = array(
      array('data' => format_date($log->timestamp, 'small'), 'class' => 'nowrap'),
      _statistics_format_item($log->title, $log->path),
      theme('username', $log)<strong>.", ". l(check_plain($log->hostname), "http://www.ip2location.com/$log->hostname")</strong>,
      l(t('details'), "admin/logs/access/$log->aid"));
  }
...

after that you will have clickable ip address in the username column.

}