You are here

function statistics_node_view in Drupal 7

Same name and namespace in other branches
  1. 8 core/modules/statistics/statistics.module \statistics_node_view()
  2. 9 core/modules/statistics/statistics.module \statistics_node_view()

Implements hook_node_view().

File

modules/statistics/statistics.module, line 115
Logs and displays access statistics for a site.

Code

function statistics_node_view($node, $view_mode) {

  // Attach Ajax node count statistics if configured.
  if (variable_get('statistics_count_content_views', 0) && variable_get('statistics_count_content_views_ajax', 0)) {
    if (!empty($node->nid) && $view_mode == 'full' && node_is_page($node) && empty($node->in_preview)) {
      $statistics = drupal_get_path('module', 'statistics') . '/statistics.js';
      $node->content['#attached']['js'][$statistics] = array(
        'scope' => 'footer',
      );
      $settings = array(
        'data' => array(
          'nid' => $node->nid,
        ),
        'url' => url(drupal_get_path('module', 'statistics') . '/statistics.php'),
      );
      $node->content['#attached']['js'][] = array(
        'data' => array(
          'statistics' => $settings,
        ),
        'type' => 'setting',
      );
    }
  }
  if ($view_mode != 'rss') {
    if (user_access('view post access counter')) {
      $statistics = statistics_get($node->nid);
      if ($statistics) {
        $links['statistics_counter']['title'] = format_plural($statistics['totalcount'], '1 read', '@count reads');
        $node->content['links']['statistics'] = array(
          '#theme' => 'links__node__statistics',
          '#links' => $links,
          '#attributes' => array(
            'class' => array(
              'links',
              'inline',
            ),
          ),
        );
      }
    }
  }
}