/[drupal]/drupal/modules/statistics/statistics.tokens.inc
ViewVC logotype

Contents of /drupal/modules/statistics/statistics.tokens.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sun Oct 18 07:56:20 2009 UTC (5 weeks, 4 days ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, HEAD
Changes since 1.1: +2 -1 lines
File MIME type: text/x-php
#602200 by stBorchert: Fixed notices in account settings.
1 <?php
2 // $Id: statistics.tokens.inc,v 1.1 2009/08/19 20:19:36 dries Exp $
3
4 /**
5 * @file
6 * Builds placeholder replacement tokens for node visitor statistics.
7 */
8
9 /**
10 * Implement hook_token_info().
11 */
12 function statistics_token_info() {
13 $node['views'] = array(
14 'name' => t("Number of views"),
15 'description' => t("The number of visitors who have read the node."),
16 );
17 $node['day-views'] = array(
18 'name' => t("Views today"),
19 'description' => t("The number of visitors who have read the node today."),
20 );
21 $node['last-view'] = array(
22 'name' => t("Last view"),
23 'description' => t("The date on which a visitor last read the node."),
24 'type' => 'date',
25 );
26
27 return array(
28 'tokens' => array('node' => $node),
29 );
30 }
31
32 /**
33 * Implement hook_tokens().
34 */
35 function statistics_tokens($type, $tokens, array $data = array(), array $options = array()) {
36 $url_options = array('absolute' => TRUE);
37 $replacements = array();
38
39 if ($type == 'node' & !empty($data['node'])) {
40 $node = $data['node'];
41
42 foreach ($tokens as $name => $original) {
43 if ($name == 'views') {
44 $statistics = statistics_get($node->nid);
45 $replacements[$original] = $statistics['totalviews'];
46 }
47 elseif ($name == 'views-today') {
48 $statistics = statistics_get($node->nid);
49 $replacements[$original] = $statistics['dayviews'];
50 }
51 elseif ($name == 'last-view') {
52 $statistics = statistics_get($node->nid);
53 $replacements[$original] = format_date($statistics['timestamp']);
54 }
55 }
56
57 if ($created_tokens = token_find_with_prefix($tokens, 'last-view')) {
58 $statistics = statistics_get($node->nid);
59 $replacements += token_generate('date', $created_tokens, array('date' => $statistics['timestamp']), $options);
60 }
61 }
62
63 return $replacements;
64 }

  ViewVC Help
Powered by ViewVC 1.1.2