You are here

function better_statistics_get_field_value in Better Statistics 7

Returns a value to be inserted into the accesslog based on a field name provided. This handles Drupal Core's values as well as our own.

Parameters

$field: The name of the field for which to return data.

Return value

The data to be inserted into the accesslog for the provided field.

2 string references to 'better_statistics_get_field_value'
better_statistics_better_statistics_fields in ./better_statistics.statistics.inc
Implements hook_better_statistics_fields().
better_statistics_get_default_fields in ./better_statistics.module
Returns default fields in the exact same form expected of fields exposed via hook_better_statistics_fields().

File

./better_statistics.statistics.inc, line 106
Statistics API functions and hooks for the Better Statistics module.

Code

function better_statistics_get_field_value($field) {
  switch ($field) {
    case 'title':
      return truncate_utf8(strip_tags(drupal_get_title()), 255);
    case 'path':
      return truncate_utf8($_GET['q'], 255);
    case 'url':
      return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
    case 'hostname':
      return ip_address();
    case 'uid':
      global $user;
      return $user->uid;
    case 'sid':
      return session_id();
    case 'timer':
      return (int) timer_read('page');
    case 'timestamp':
      return REQUEST_TIME;
    case 'cache':
      $cached = NULL;
      $cache_status = better_statistics_served_from_cache();
      if ($cache_status === TRUE) {
        $cached = 'HIT';
      }
      elseif ($cache_status === FALSE) {
        $cached = 'MISS';
      }
      return $cached;
    case 'user_agent':
      return isset($_SERVER['HTTP_USER_AGENT']) ? truncate_utf8($_SERVER['HTTP_USER_AGENT'], 255) : '';
  }
}