? base_referrers.patch
Index: xstatistics.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xstatistics/xstatistics.module,v
retrieving revision 1.6.2.2
retrieving revision 1.6.2.3
diff -u -p -r1.6.2.2 -r1.6.2.3
--- xstatistics.module	28 Feb 2007 15:10:42 -0000	1.6.2.2
+++ xstatistics.module	28 Feb 2007 16:48:44 -0000	1.6.2.3
@@ -1,5 +1,5 @@
 <?php
-// $Id: xstatistics.module,v 1.6.2.2 2007/02/28 15:10:42 ber Exp $
+// $Id: xstatistics.module,v 1.6.2.3 2007/02/28 16:48:44 ber Exp $
 
 /**
  * @file
@@ -20,6 +20,10 @@ function xstatistics_menu($may_cache) {
                      'path' => 'admin/logs/usage',
                      'callback' => 'xstatistics_usage',
                      'access' => user_access('access statistics'));
+    $items[] = array('title' => t('Referrer by base'),
+                     'path' => 'admin/logs/referrers/base',
+                     'callback' => 'xstatistics_referrers_by_base',
+                     'access' => user_access('access statistics'));
   }
   return $items;
 }
@@ -153,3 +157,29 @@ function xstatistics_do_usage() {
   $attributes = array('summary' => t('xstatistics usage'));
   return theme('table', $header, $rows, $attributes);
 }
+
+/**
+ * Menu callback; presents the "referrer by base" page.
+ */
+function xstatistics_referrers_by_base() {
+  $query = "SELECT SUBSTRING_INDEX(url, '/', 3) as base, COUNT(url) AS hits, MAX(timestamp) AS last FROM {accesslog} WHERE url NOT LIKE '%%%s%%' AND url <> '' GROUP BY base";
+  $query_cnt = "SELECT COUNT(SUBSTRING_INDEX(url, '/', 3)) FROM {accesslog} WHERE url <> '' AND url NOT LIKE '%%%s%%'";
+  drupal_set_title(t('Top referrers in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))));
+
+  $header = array(
+    array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
+    array('data' => t('Base url'), 'field' => 'base'),
+    array('data' => t('Last visit'), 'field' => 'last'),
+  );
+
+  $query .= tablesort_sql($header);
+  $result = pager_query($query, 30, 0, $query_cnt, $_SERVER['HTTP_HOST']);
+
+  while ($referrer = db_fetch_object($result)) {
+    $rows[] = array($referrer->hits, '<a href="'. check_url($referrer->base) .'">'. check_plain(_statistics_column_width($referrer->base)) .'</a>', t('%time ago', array('%time' => format_interval(time() - $referrer->last))));
+  }
+
+  $output = theme('table', $header, $rows);
+  $output .= theme('pager', NULL, 30, 0);
+  return $output;
+}
\ No newline at end of file
