statistics_exit

Versions
4.6 – 7
statistics_exit()

Implement hook_exit().

This is where statistics are gathered on page accesses.

Code

modules/statistics/statistics.module, line 50

<?php
function statistics_exit() {
  global $user;

  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

  if (variable_get('statistics_count_content_views', 0)) {
    // We are counting content views.
    if ((arg(0) == 'node') && is_numeric(arg(1)) && arg(2) == '') {
      // A node has been viewed, so update the node's counters.
      db_merge('node_counter')
        ->key(array('nid' => arg(1)))
        ->fields(array(
          'daycount' => 1,
          'totalcount' => 1,
          'timestamp' => REQUEST_TIME,
        ))
        ->expression('daycount', 'daycount + 1')
        ->expression('totalcount', 'totalcount + 1')
        ->execute();
    }
  }
  if (variable_get('statistics_enable_access_log', 0)) {
    // Log this page access.
    db_insert('accesslog')
      ->fields(array(
        'title' => strip_tags(drupal_get_title()),
        'path' => $_GET['q'],
        'url' => $_SERVER['HTTP_REFERER'],
        'hostname' => ip_address(),
        'uid' => $user->uid,
        'sid' => session_id(),
        'timer' => (int) timer_read('page'),
        'timestamp' => REQUEST_TIME,
      ))
      ->execute();
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.