5 * Builds placeholder replacement tokens for node visitor statistics.
9 * Implements hook_token_info().
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."),
16 $node['day-count'] = array(
17 'name' => t("Views today"),
18 'description' => t("The number of visitors who have read the node today."),
20 $node['last-view'] = array(
21 'name' => t("Last view"),
22 'description' => t("The date on which a visitor last read the node."),
27 'tokens' => array('node' => $node),
32 * Implements hook_tokens().
34 function statistics_tokens($type, $tokens, array $data = array(), array $options = array()) {
35 $url_options = array('absolute' => TRUE);
36 $replacements = array();
38 if ($type == 'node' & !empty($data['node'])) {
39 $node = $data['node'];
41 foreach ($tokens as $name => $original) {
42 if ($name == 'total-count') {
43 $statistics = statistics_get($node->nid);
44 $replacements[$original] = $statistics['totalcount'];
46 elseif ($name == 'day-count') {
47 $statistics = statistics_get($node->nid);
48 $replacements[$original] = $statistics['daycount'];
50 elseif ($name == 'last-view') {
51 $statistics = statistics_get($node->nid);
52 $replacements[$original] = format_date($statistics['timestamp']);
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);