8.5.x statistics.tokens.inc statistics_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata)
8.0.x statistics.tokens.inc statistics_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata)
8.1.x statistics.tokens.inc statistics_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata)
8.2.x statistics.tokens.inc statistics_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata)
8.3.x statistics.tokens.inc statistics_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata)
8.4.x statistics.tokens.inc statistics_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata)
8.6.x statistics.tokens.inc statistics_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata)
7.x statistics.tokens.inc statistics_tokens($type, $tokens, array $data = array(), array $options = array())

Implements hook_tokens().

File

modules/statistics/statistics.tokens.inc, line 34
Builds placeholder replacement tokens for node visitor statistics.

Code

function statistics_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $url_options = array(
    'absolute' => TRUE,
  );
  $replacements = array();
  if ($type == 'node' & !empty($data['node'])) {
    $node = $data['node'];
    foreach ($tokens as $name => $original) {
      if ($name == 'total-count') {
        $statistics = statistics_get($node->nid);
        $replacements[$original] = $statistics['totalcount'];
      }
      elseif ($name == 'day-count') {
        $statistics = statistics_get($node->nid);
        $replacements[$original] = $statistics['daycount'];
      }
      elseif ($name == 'last-view') {
        $statistics = statistics_get($node->nid);
        $replacements[$original] = format_date($statistics['timestamp']);
      }
    }
    if ($created_tokens = token_find_with_prefix($tokens, 'last-view')) {
      $statistics = statistics_get($node->nid);
      $replacements += token_generate('date', $created_tokens, array(
        'date' => $statistics['timestamp'],
      ), $options);
    }
  }
  return $replacements;
}