1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Builds placeholder replacement tokens for node visitor statistics.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_token_info().
|
10 |
|
|
*/
|
11 |
|
|
function statistics_token_info() {
|
12 |
|
|
$node['total-count'] = array(
|
13 |
|
|
'name' => t("Number of views"),
|
14 |
|
|
'description' => t("The number of visitors who have read the node."),
|
15 |
|
|
);
|
16 |
|
|
$node['day-count'] = array(
|
17 |
|
|
'name' => t("Views today"),
|
18 |
|
|
'description' => t("The number of visitors who have read the node today."),
|
19 |
|
|
);
|
20 |
|
|
$node['last-view'] = array(
|
21 |
|
|
'name' => t("Last view"),
|
22 |
|
|
'description' => t("The date on which a visitor last read the node."),
|
23 |
|
|
'type' => 'date',
|
24 |
|
|
);
|
25 |
|
|
|
26 |
|
|
return array(
|
27 |
|
|
'tokens' => array('node' => $node),
|
28 |
|
|
);
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
/**
|
32 |
|
|
* Implements hook_tokens().
|
33 |
|
|
*/
|
34 |
|
|
function statistics_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
35 |
|
|
$url_options = array('absolute' => TRUE);
|
36 |
|
|
$replacements = array();
|
37 |
|
|
|
38 |
|
|
if ($type == 'node' & !empty($data['node'])) {
|
39 |
|
|
$node = $data['node'];
|
40 |
|
|
|
41 |
|
|
foreach ($tokens as $name => $original) {
|
42 |
|
|
if ($name == 'total-count') {
|
43 |
|
|
$statistics = statistics_get($node->nid);
|
44 |
|
|
$replacements[$original] = $statistics['totalcount'];
|
45 |
|
|
}
|
46 |
|
|
elseif ($name == 'day-count') {
|
47 |
|
|
$statistics = statistics_get($node->nid);
|
48 |
|
|
$replacements[$original] = $statistics['daycount'];
|
49 |
|
|
}
|
50 |
|
|
elseif ($name == 'last-view') {
|
51 |
|
|
$statistics = statistics_get($node->nid);
|
52 |
|
|
$replacements[$original] = format_date($statistics['timestamp']);
|
53 |
|
|
}
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
if ($created_tokens = token_find_with_prefix($tokens, 'last-view')) {
|
57 |
|
|
$statistics = statistics_get($node->nid);
|
58 |
|
|
$replacements += token_generate('date', $created_tokens, array('date' => $statistics['timestamp']), $options);
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
return $replacements;
|
63 |
|
|
} |