1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* User page callbacks for the Statistics module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Page callback: Displays statistics for a node.
|
10
|
*
|
11
|
* @return
|
12
|
* A render array containing node statistics. If information for the node was
|
13
|
* not found, this will deliver a page not found error via drupal_not_found().
|
14
|
*/
|
15
|
function statistics_node_tracker() {
|
16
|
if ($node = node_load(arg(1))) {
|
17
|
|
18
|
$header = array(
|
19
|
array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'),
|
20
|
array('data' => t('Referrer'), 'field' => 'a.url'),
|
21
|
array('data' => t('User'), 'field' => 'u.name'),
|
22
|
array('data' => t('Operations')));
|
23
|
|
24
|
$query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort');
|
25
|
$query->join('users', 'u', 'a.uid = u.uid');
|
26
|
|
27
|
$query
|
28
|
->fields('a', array('aid', 'timestamp', 'url', 'uid'))
|
29
|
->fields('u', array('name'))
|
30
|
->condition(db_or()
|
31
|
->condition('a.path', 'node/' . $node->nid)
|
32
|
->condition('a.path', 'node/' . $node->nid . '/%', 'LIKE'))
|
33
|
->limit(30)
|
34
|
->orderByHeader($header);
|
35
|
|
36
|
$result = $query->execute();
|
37
|
$rows = array();
|
38
|
foreach ($result as $log) {
|
39
|
$rows[] = array(
|
40
|
array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')),
|
41
|
_statistics_link($log->url),
|
42
|
theme('username', array('account' => $log)),
|
43
|
l(t('details'), "admin/reports/access/$log->aid"),
|
44
|
);
|
45
|
}
|
46
|
|
47
|
drupal_set_title($node->title);
|
48
|
$build['statistics_table'] = array(
|
49
|
'#theme' => 'table',
|
50
|
'#header' => $header,
|
51
|
'#rows' => $rows,
|
52
|
'#empty' => t('No statistics available.'),
|
53
|
);
|
54
|
$build['statistics_pager'] = array('#theme' => 'pager');
|
55
|
return $build;
|
56
|
}
|
57
|
return MENU_NOT_FOUND;
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* Page callback: Displays statistics for a user.
|
62
|
*
|
63
|
* @return array
|
64
|
* A render array containing user statistics. If information for the user was
|
65
|
* not found, this will deliver a page not found error via drupal_not_found().
|
66
|
*/
|
67
|
function statistics_user_tracker() {
|
68
|
if ($account = user_load(arg(1))) {
|
69
|
|
70
|
$header = array(
|
71
|
array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'),
|
72
|
array('data' => t('Page'), 'field' => 'path'),
|
73
|
array('data' => t('Operations')));
|
74
|
$query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort');
|
75
|
$query
|
76
|
->fields('a', array('aid', 'timestamp', 'path', 'title'))
|
77
|
->condition('uid', $account->uid)
|
78
|
->limit(30)
|
79
|
->orderByHeader($header);
|
80
|
|
81
|
$result = $query->execute();
|
82
|
$rows = array();
|
83
|
foreach ($result as $log) {
|
84
|
$rows[] = array(
|
85
|
array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')),
|
86
|
_statistics_format_item($log->title, $log->path),
|
87
|
l(t('details'), "admin/reports/access/$log->aid"));
|
88
|
}
|
89
|
|
90
|
drupal_set_title(format_username($account));
|
91
|
$build['statistics_table'] = array(
|
92
|
'#theme' => 'table',
|
93
|
'#header' => $header,
|
94
|
'#rows' => $rows,
|
95
|
'#empty' => t('No statistics available.'),
|
96
|
);
|
97
|
$build['statistics_pager'] = array('#theme' => 'pager');
|
98
|
return $build;
|
99
|
}
|
100
|
return MENU_NOT_FOUND;
|
101
|
}
|