| 1 |
#
|
| 2 |
# This patch tracks the active title and path in the accesslog rather than the
|
| 3 |
# nid. It also provides a way to see the most popular titles, users and
|
| 4 |
# hostnames.
|
| 5 |
#
|
| 6 |
# You'll have to run the following in your database before you apply this patch:
|
| 7 |
#
|
| 8 |
# ALTER TABLE accesslog ADD title VARCHAR(255) DEFAULT NULL;
|
| 9 |
# ALTER TABLE accesslog ADD path VARCHAR(255) DEFAULT NULL;
|
| 10 |
#
|
| 11 |
# I don't recommend that you drop the old 'nid' field, as you may end up
|
| 12 |
# wanting to roll back this patch.
|
| 13 |
#
|
| 14 |
--- statistics.module.orig 2004-08-01 12:23:11.857108025 -0400
|
| 15 |
+++ statistics.module 2004-08-01 12:17:20.289754262 -0400
|
| 16 |
@@ -22,14 +22,10 @@ function statistics_exit() {
|
| 17 |
// statistical logs are enabled
|
| 18 |
$referrer = referer_uri();
|
| 19 |
$hostname = $_SERVER['REMOTE_ADDR'];
|
| 20 |
+ $path = (drupal_get_path_alias($_GET['q'])) ? drupal_get_path_alias($_GET['q']) : $_GET['q'];
|
| 21 |
|
| 22 |
// log this page access
|
| 23 |
- if ((arg(0) == "node") && (arg(1) == "view") && arg(2)) {
|
| 24 |
- db_query("INSERT INTO {accesslog} (nid, url, hostname, uid, timestamp) values(%d, '%s', '%s', %d, %d)", arg(2), $referrer, $hostname, $user->uid, time());
|
| 25 |
- }
|
| 26 |
- else {
|
| 27 |
- db_query("INSERT INTO {accesslog} (url, hostname, uid, timestamp) values('%s', '%s', %d, %d)", $referrer, $hostname, $user->uid, time());
|
| 28 |
- }
|
| 29 |
+ db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, timestamp) values('%s', '%s', '%s', '%s', %d, %d)", drupal_get_title(), $path, $referrer, $hostname, $user->uid, time());
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
@@ -56,7 +52,7 @@ function statistics_link($type, $node =
|
| 34 |
$statistics = statistics_get($node->nid);
|
| 35 |
if ($statistics) {
|
| 36 |
if (user_access("administer statistics")) {
|
| 37 |
- $links[] = l(format_plural($statistics["totalcount"], "1 read", "%count reads"), "admin/statistics/log/node/$node->nid");
|
| 38 |
+ $links[] = l(format_plural($statistics["totalcount"], "1 read", "%count reads"), "admin/statistics/log/title/". urlencode($node->title));
|
| 39 |
}
|
| 40 |
else {
|
| 41 |
$links[] = format_plural($statistics["totalcount"], "1 read", "%count reads");
|
| 42 |
@@ -75,13 +71,16 @@ function statistics_link($type, $node =
|
| 43 |
if ((user_access("administer statistics module") || (user_access("administer statistics")))) {
|
| 44 |
|
| 45 |
menu("admin/statistics", t("statistics"), "statistics_admin", 6);
|
| 46 |
- menu("admin/statistics/referrers", t("referrer log"), "statistics_admin");
|
| 47 |
- menu("admin/statistics/referrers/internal", t("internal referrers only"), "statistics_admin");
|
| 48 |
- menu("admin/statistics/referrers/external", t("external referrers only"), "statistics_admin");
|
| 49 |
menu("admin/statistics/log", t("access log"), "statistics_admin");
|
| 50 |
- menu("admin/statistics/log/node", t("track node"), "statistics_admin", 0, MENU_HIDE);
|
| 51 |
+ menu("admin/statistics/log/title", t("track title"), "statistics_admin", 0, MENU_HIDE);
|
| 52 |
menu("admin/statistics/log/user", t("track user"), "statistics_admin", 0, MENU_HIDE);
|
| 53 |
menu("admin/statistics/log/host", t("track host"), "statistics_admin", 0, MENU_HIDE);
|
| 54 |
+ menu("admin/statistics/log/titles", t('titles'), 'statistics_admin', 0);
|
| 55 |
+ menu("admin/statistics/log/users", t('users'), 'statistics_admin', 1);
|
| 56 |
+ menu("admin/statistics/log/hostnames", t('hostnames'), 'statistics_admin', 2);
|
| 57 |
+ menu("admin/statistics/log/referrers", t('referrers'), 'statistics_admin', 3);
|
| 58 |
+ menu("admin/statistics/log/referrers/internal", t('internal'), "statistics_admin");
|
| 59 |
+ menu("admin/statistics/log/referrers/external", t('external'), "statistics_admin");
|
| 60 |
menu("admin/statistics/help", t("help"), "statistics_help_page", 9);
|
| 61 |
}
|
| 62 |
|
| 63 |
@@ -173,7 +172,7 @@ function statistics_help($section = "adm
|
| 64 |
$output = t("This page shows you only 'external referrers'. Links pointing to your web site from outside your web site.");
|
| 65 |
break;
|
| 66 |
case 'admin/statistics/log':
|
| 67 |
- case 'admin/statistics/log/node':
|
| 68 |
+ case 'admin/statistics/log/title':
|
| 69 |
case 'admin/statistics/log/user':
|
| 70 |
case 'admin/statistics/log/host':
|
| 71 |
$output = t("This pages shows you who is accessing your web site. You can see the hostnames, referrers. In particular, it is easy to inspect a user's navigation history/trail by clicking on <em>track user</em>.");
|
| 72 |
@@ -191,23 +190,39 @@ function statistics_help_page() {
|
| 73 |
function statistics_admin() {
|
| 74 |
$op = $_POST["op"];
|
| 75 |
$edit = $_POST["edit"];
|
| 76 |
+ unset($output);
|
| 77 |
|
| 78 |
if (empty($op)) {
|
| 79 |
- $op = arg(2);
|
| 80 |
+ $op = arg(3);
|
| 81 |
}
|
| 82 |
|
| 83 |
/* non-configuration admin pages */
|
| 84 |
switch ($op) {
|
| 85 |
+ case "titles":
|
| 86 |
+ $output = statistics_top_titles();
|
| 87 |
+ break;
|
| 88 |
+ case "users":
|
| 89 |
+ $output = statistics_top_users();
|
| 90 |
+ break;
|
| 91 |
+ case "hostnames":
|
| 92 |
+ $output = statistics_top_hostnames();
|
| 93 |
+ break;
|
| 94 |
case "referrers":
|
| 95 |
$output = statistics_top_refer();
|
| 96 |
break;
|
| 97 |
- case "log":
|
| 98 |
- $output = statistics_admin_displaylog();
|
| 99 |
- break;
|
| 100 |
- default:
|
| 101 |
- $output = statistics_admin_topnodes();
|
| 102 |
}
|
| 103 |
|
| 104 |
+ if (!$output) {
|
| 105 |
+ switch (arg(2)) {
|
| 106 |
+ case "log":
|
| 107 |
+ $output = statistics_admin_displaylog();
|
| 108 |
+ break;
|
| 109 |
+ default:
|
| 110 |
+ $output = statistics_admin_topnodes();
|
| 111 |
+ }
|
| 112 |
+ }
|
| 113 |
+
|
| 114 |
+
|
| 115 |
print theme("page", $output);
|
| 116 |
}
|
| 117 |
|
| 118 |
@@ -226,7 +241,7 @@ function statistics_admin_topnodes_table
|
| 119 |
$result = pager_query($sql, 20); // WHERE s.%s <> '0'
|
| 120 |
|
| 121 |
while ($nid = db_fetch_array($result)) {
|
| 122 |
- $rows[] = array(l($nid["title"], "node/view/". $nid["nid"], array("title" => t("View this posting."))), $nid["daycount"], $nid["totalcount"], format_date($nid["timestamp"], "small"), l("track node", "admin/statistics/log/node/$nid[nid]"));
|
| 123 |
+ $rows[] = array(l($nid["title"], "node/view/". $nid["nid"], array("title" => t("View this posting."))), $nid["daycount"], $nid["totalcount"], format_date($nid["timestamp"], "small"), l("track title", "admin/statistics/log/title/". urlencode($nid[title])));
|
| 124 |
}
|
| 125 |
if ($pager = theme("pager", NULL, 20, 0, tablesort_pager())) {
|
| 126 |
$rows[] = array(array("data" => $pager, "colspan" => 5));
|
| 127 |
@@ -242,29 +257,30 @@ function statistics_admin_accesslog_tabl
|
| 128 |
/* retrieve user access logs */
|
| 129 |
if ($id) {
|
| 130 |
/* retrieve recent access logs for user $id */
|
| 131 |
- $sql = "SELECT a.nid, a.url, a.hostname, a.uid, a.timestamp, n.title FROM {accesslog} a LEFT JOIN {node} n ON a.nid = n.nid WHERE a.uid = ". check_query($id);
|
| 132 |
+ $sql = 'SELECT title, path, url, hostname, uid, timestamp FROM {accesslog} WHERE uid = \''. check_query($id) ."'";
|
| 133 |
+
|
| 134 |
}
|
| 135 |
else {
|
| 136 |
/* retrieve recent access logs for all users */
|
| 137 |
- $sql = "SELECT a.nid, a.url, a.hostname, a.uid, MAX(a.timestamp) AS timestamp, n.title FROM {accesslog} a LEFT JOIN {node} n ON a.nid = n.nid WHERE a.uid <> '0' GROUP BY a.uid, a.nid, a.url, a.hostname";
|
| 138 |
+ $sql = 'SELECT title, path, url, hostname, uid, MAX(a.timestamp) AS timestamp, FROM {accesslog} WHERE a.uid <> 0 GROUP BY uid, title, path, url, hostname';
|
| 139 |
}
|
| 140 |
}
|
| 141 |
else if ($type == 2) {
|
| 142 |
/* retrieve recent access logs for node $id */
|
| 143 |
- $sql = "SELECT a.nid, a.url, a.hostname, a.uid, a.timestamp, n.title FROM {accesslog} a INNER JOIN {node} n ON a.nid = n.nid WHERE a.nid = ". check_query($id);
|
| 144 |
+ $sql = 'SELECT title, path, url, hostname, uid, timestamp FROM {accesslog} WHERE title = \''. check_query($id) ."'";
|
| 145 |
}
|
| 146 |
else if ($type == 3) {
|
| 147 |
/* retrieve recent access logs for hostname $id */
|
| 148 |
- $sql = "SELECT a.nid, a.url, a.hostname, a.uid, a.timestamp, n.title FROM {accesslog} a LEFT JOIN {node} n ON a.nid = n.nid WHERE a.hostname = '". check_query($id) ."'";
|
| 149 |
+ $sql = 'SELECT title, path, url, hostname, uid, timestamp, title FROM {accesslog} WHERE hostname = \''. check_query($id) ."'";
|
| 150 |
}
|
| 151 |
else {
|
| 152 |
/* retrieve all recent access logs */
|
| 153 |
- $sql = "SELECT a.nid, a.url, a.hostname, a.uid, a.timestamp, n.title FROM {accesslog} a LEFT JOIN {node} n ON a.nid = n.nid";
|
| 154 |
+ $sql = 'SELECT title, path, url, hostname, uid, timestamp FROM {accesslog}';
|
| 155 |
}
|
| 156 |
|
| 157 |
$header = array(
|
| 158 |
array("data" => t("timestamp"), "field" => "timestamp", "sort" => "desc"),
|
| 159 |
- array("data" => t("post"), "field" => "nid"),
|
| 160 |
+ array("data" => t("title"), "field" => "title"),
|
| 161 |
array("data" => t("user"), "field" => "uid"),
|
| 162 |
array("data" => t("hostname"), "field" => "hostname"),
|
| 163 |
array("data" => t("referrer"), "field" => "url"),
|
| 164 |
@@ -275,7 +291,11 @@ function statistics_admin_accesslog_tabl
|
| 165 |
|
| 166 |
$result = pager_query($sql, 50);
|
| 167 |
while ($log = db_fetch_object($result)) {
|
| 168 |
- $user = user_load(array("uid" => $log->uid));
|
| 169 |
+ // display title if possible, otherwise display path
|
| 170 |
+ if ($log->title)
|
| 171 |
+ $title = l(_statistics_column_width($log->title), $log->path, array('title' => $log->path));
|
| 172 |
+ else
|
| 173 |
+ $title = '('. l(_statistics_column_width($log->path), $log->path, array('title' => $log->path)) .')';
|
| 174 |
|
| 175 |
if ($log->url) {
|
| 176 |
$url = "<a href=\"$log->url\" title=\"$log->url\">". (strlen($log->url) > 28 ? truncate_utf8($log->url, 28) . '...' : $log->url) ."</a>";
|
| 177 |
@@ -284,7 +304,8 @@ function statistics_admin_accesslog_tabl
|
| 178 |
$url = message_na();
|
| 179 |
}
|
| 180 |
|
| 181 |
- $rows[] = array(array("data" => format_date($log->timestamp, "small"), "nowrap" => "nowrap"), ($log->nid ? l($log->title, "node/view/$log->nid") : message_na()), format_name($user), $log->hostname ? $log->hostname : message_na(), $url, ($log->nid ? l(t("track node"), "admin/statistics/log/node/$log->nid") : ""), ($user->uid ? l(t("track user"), "admin/statistics/log/user/$user->uid") : ""), ($log->hostname ? l(t("track host"), "admin/statistics/log/host/$log->hostname") : ""));
|
| 182 |
+ $user = user_load(array("uid" => $log->uid));
|
| 183 |
+ $rows[] = array(array('data' => format_date($log->timestamp, 'small'), 'nowrap' => 'nowrap'), $title, format_name($user), $log->hostname ? $log->hostname : message_na(), $url, ($user->uid ? l(t('track user'), "admin/statistics/log/user/$user->uid") : ''), ($log->title ? l(t('track title'), "admin/statistics/log/title/". urlencode($log->title)) : ''), ($log->hostname ? l(t('track host'), "admin/statistics/log/host/$log->hostname") : ''));
|
| 184 |
}
|
| 185 |
|
| 186 |
if ($pager = theme("pager", NULL, 50, 0, tablesort_pager())) {
|
| 187 |
@@ -294,9 +315,89 @@ function statistics_admin_accesslog_tabl
|
| 188 |
return theme("table", $header, $rows);
|
| 189 |
}
|
| 190 |
|
| 191 |
+function statistics_top_titles() {
|
| 192 |
+ $sql = "SELECT title, path, MAX(timestamp) AS last_view, COUNT(title) AS count FROM {accesslog} WHERE title <> '' GROUP BY title";
|
| 193 |
+ $sql_cnt = "SELECT COUNT(DISTINCT(title)) FROM {accesslog} WHERE title <> ''";
|
| 194 |
+ $describe = t('Top titles in the past %interval');
|
| 195 |
+
|
| 196 |
+ $page_title = strtr($describe, array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
|
| 197 |
+
|
| 198 |
+ $header = array(
|
| 199 |
+ array('data' => t('title'), 'field' => 'title'),
|
| 200 |
+ array('data' => t('last path'), 'field' => 'path'),
|
| 201 |
+ array('data' => t('last view'), 'field' => 'last_view'),
|
| 202 |
+ array('data' => t('hits'), 'field' => 'count', 'sort' => 'desc')
|
| 203 |
+ );
|
| 204 |
+ $sql .= tablesort_sql($header);
|
| 205 |
+ $result = pager_query($sql, 50, 0, $sql_cnt);
|
| 206 |
+
|
| 207 |
+ while ($title = db_fetch_object($result)) {
|
| 208 |
+ $rows[] = array(l(_statistics_column_width($title->title, '_title', 56), $title->path), _statistics_column_width($title->path, '_title', 56), format_date($title->last_view, 'small'), $title->count);
|
| 209 |
+ }
|
| 210 |
+ if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
|
| 211 |
+ $rows[] = array(array('data' => $pager, 'colspan' => 3));
|
| 212 |
+ }
|
| 213 |
+
|
| 214 |
+ return theme('table', $header, $rows);
|
| 215 |
+}
|
| 216 |
+
|
| 217 |
+function statistics_top_users() {
|
| 218 |
+ $sql = "SELECT uid, hostname, MAX(timestamp) AS last_view, COUNT(uid) AS count FROM {accesslog} GROUP BY uid";
|
| 219 |
+ $sql_cnt = "SELECT COUNT(DISTINCT(uid)) FROM {accesslog}";
|
| 220 |
+ $describe = t('Top users in the past %interval');
|
| 221 |
+
|
| 222 |
+ $page_title = strtr($describe, array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
|
| 223 |
+
|
| 224 |
+ $header = array(
|
| 225 |
+ array('data' => t('user'), 'field' => 'user'),
|
| 226 |
+ array('data' => t('last hostname'), 'field' => 'hostname'),
|
| 227 |
+ array('data' => t('last view'), 'field' => 'last_view'),
|
| 228 |
+ array('data' => t('hits'), 'field' => 'count', 'sort' => 'desc')
|
| 229 |
+ );
|
| 230 |
+ $sql .= tablesort_sql($header);
|
| 231 |
+ $result = pager_query($sql, 50, 0, $sql_cnt);
|
| 232 |
+
|
| 233 |
+ while ($u = db_fetch_object($result)) {
|
| 234 |
+ $user = user_load(array('uid' => $u->uid));
|
| 235 |
+ $rows[] = array(format_name($user), $u->hostname, format_date($u->last_view, 'small'), $u->count);
|
| 236 |
+ }
|
| 237 |
+ if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
|
| 238 |
+ $rows[] = array(array('data' => $pager, 'colspan' => 3));
|
| 239 |
+ }
|
| 240 |
+
|
| 241 |
+ return theme('table', $header, $rows);
|
| 242 |
+}
|
| 243 |
+
|
| 244 |
+function statistics_top_hostnames() {
|
| 245 |
+ $sql = "SELECT hostname, uid, MAX(timestamp) AS last_view, COUNT(hostname) AS count FROM {accesslog} GROUP BY hostname";
|
| 246 |
+ $sql_cnt = "SELECT COUNT(DISTINCT(hostname)) FROM {accesslog}";
|
| 247 |
+ $describe = t('Top hostnames in the past %interval');
|
| 248 |
+
|
| 249 |
+ $page_title = strtr($describe, array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200))));
|
| 250 |
+
|
| 251 |
+ $header = array(
|
| 252 |
+ array('data' => t('hostname'), 'field' => 'hostname'),
|
| 253 |
+ array('data' => t('last user'), 'field' => 'user'),
|
| 254 |
+ array('data' => t('last view'), 'field' => 'last_view'),
|
| 255 |
+ array('data' => t('hits'), 'field' => 'count', 'sort' => 'desc')
|
| 256 |
+ );
|
| 257 |
+ $sql .= tablesort_sql($header);
|
| 258 |
+ $result = pager_query($sql, 50, 0, $sql_cnt);
|
| 259 |
+
|
| 260 |
+ while ($hostname = db_fetch_object($result)) {
|
| 261 |
+ $user = user_load(array('uid' => $hostname->uid));
|
| 262 |
+ $rows[] = array($hostname->hostname, format_name($user), format_date($hostname->last_view, 'small'), $hostname->count);
|
| 263 |
+ }
|
| 264 |
+ if ($pager = theme('pager', NULL, 50, 0, tablesort_pager())) {
|
| 265 |
+ $rows[] = array(array('data' => $pager, 'colspan' => 3));
|
| 266 |
+ }
|
| 267 |
+
|
| 268 |
+ return theme('table', $header, $rows);
|
| 269 |
+}
|
| 270 |
+
|
| 271 |
function statistics_top_refer() {
|
| 272 |
|
| 273 |
- $view = arg(3) ? arg(3) : "all";
|
| 274 |
+ $view = arg(4) ? arg(4) : "all";
|
| 275 |
|
| 276 |
if ($view == "all") {
|
| 277 |
$query = "SELECT url, MAX(timestamp) AS last_view, COUNT(url) AS count FROM {accesslog} WHERE url <> '' GROUP BY url";
|
| 278 |
@@ -359,9 +460,8 @@ function statistics_admin_displaylog() {
|
| 279 |
$output = "<h3>". t("Recent access logs for '%name'", array("%name" => $user->name)) ."</h3>\n";
|
| 280 |
$output .= statistics_admin_accesslog_table(1, $user->uid);
|
| 281 |
break;
|
| 282 |
- case "node":
|
| 283 |
- $node = node_load(array("nid" => $value));
|
| 284 |
- $output = "<h3>". t("Recent access logs for '%title'", array("%title" => $node->title)) ."</h3>\n";
|
| 285 |
+ case "title":
|
| 286 |
+ $output = "<h3>". t("Recent access logs for '%title'", array("%title" => $value)) ."</h3>\n";
|
| 287 |
$output .= statistics_admin_accesslog_table(2, $value);
|
| 288 |
break;
|
| 289 |
case "host":
|
| 290 |
@@ -540,6 +640,18 @@ function statistics_summary($dbfield, $d
|
| 291 |
return $output;
|
| 292 |
}
|
| 293 |
|
| 294 |
+/**
|
| 295 |
+ * It is possible to adjust the width of columns generated by the
|
| 296 |
+ * statistics module. Currently this has to be done manually, by
|
| 297 |
+ * updating the appropriate variable. There are several recognized variables:
|
| 298 |
+ * 'statistics_column_width', 'statistics_column_width_refer', and
|
| 299 |
+ * 'statistics_column_width_title'
|
| 300 |
+ */
|
| 301 |
+function _statistics_column_width($column, $type = "", $default = 26) {
|
| 302 |
+ $max_width = variable_get("statistics_column_width$type", $default);
|
| 303 |
+ return (strlen($column) > $max_width ? substr($column, 0, $max_width) . '...' : $column);
|
| 304 |
+}
|
| 305 |
+
|
| 306 |
function statistics_nodeapi(&$node, $op, $arg = 0) {
|
| 307 |
switch ($op) {
|
| 308 |
case "delete":
|