You are here

function statistics_exit in Drupal 6

Same name and namespace in other branches
  1. 4 modules/statistics.module \statistics_exit()
  2. 5 modules/statistics/statistics.module \statistics_exit()
  3. 7 modules/statistics/statistics.module \statistics_exit()

Implementation of hook_exit().

This is where statistics are gathered on page accesses.

File

modules/statistics/statistics.module, line 44
Logs access statistics for your site.

Code

function statistics_exit() {
  global $user, $recent_activity;
  drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);
  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_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), arg(1));

      // If we affected 0 rows, this is the first time viewing the node.
      if (!db_affected_rows()) {

        // We must create a new row to store counters for the new node.
        db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', arg(1), time());
      }
    }
  }
  if (variable_get('statistics_enable_access_log', 0) && module_invoke('throttle', 'status') == 0) {

    // Log this page access.
    db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", strip_tags(drupal_get_title()), $_GET['q'], referer_uri(), ip_address(), $user->uid, session_id(), timer_read('page'), time());
  }
}