You are here

function better_statistics_exit in Better Statistics 7

Same name and namespace in other branches
  1. 6 better_statistics.module \better_statistics_exit()

Implements hook_exit().

Gathers additional data and inserts our data into accesslog.

File

./better_statistics.module, line 106
Drupal hook implementations for the Better Statistics module.

Code

function better_statistics_exit() {

  // If statistics access log is set to run, run our code.
  $mode = variable_get('statistics_enable_access_log', BETTER_STATISTICS_ACCESSLOG_DISABLED);
  $default_mode = $mode == BETTER_STATISTICS_ACCESSLOG_DEFAULT;
  $mixed_mode = $mode == BETTER_STATISTICS_ACCESSLOG_MIXED;
  $client_mode = $mode == BETTER_STATISTICS_ACCESSLOG_CLIENT;
  if ($default_mode || $mixed_mode) {

    // Force a recheck on cache status, just in case this function was called
    // before the X-Drupal-Cache header was set.
    $cache_status = better_statistics_served_from_cache(TRUE);

    // @see statistics_exit()
    drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
    include_once DRUPAL_ROOT . '/includes/unicode.inc';

    // Load all relevant module.statistics.inc files for hook invocations.
    better_statistics_load_active_incs();

    // Allow all modules to react before logging begins.
    module_invoke_all('better_statistics_prelog');

    // Log the request if the request is loggable.
    if (better_statistics_request_is_loggable()) {

      // Get all declared fields and their computed values.
      $fields = better_statistics_get_fields_data();

      // Allow modules to log statistics data.
      module_invoke_all('better_statistics_log', $fields);
    }
  }

  // Keep statistics from writing additional data to the accesslog.
  global $conf;
  $conf['statistics_enable_access_log'] = FALSE;

  // If client-side or mixed-mode are set, disable server-side node counter.
  if ($mixed_mode || $client_mode) {
    $conf['statistics_count_content_views'] = FALSE;
  }
}