You are here

function adsense_click_log in Google AdSense integration 7

Same name and namespace in other branches
  1. 5.3 contrib/adsense_click/adsense_click.logs.inc \adsense_click_log()
  2. 5 adsense.module \adsense_click_log()
  3. 5.2 adsense.module \adsense_click_log()
  4. 6 contrib/adsense_click/adsense_click.logs.inc \adsense_click_log()

Click log.

1 string reference to 'adsense_click_log'
adsense_click_menu in contrib/adsense_click/adsense_click.module
Implements hook_menu().

File

contrib/adsense_click/adsense_click.logs.inc, line 11
Functions to display the logs tracked by the adsense_click module.

Code

function adsense_click_log() {
  $header = array(
    array(
      'data' => t('Timestamp'),
      'field' => 'ads.timestamp',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Path'),
      'field' => 'ads.path',
    ),
    array(
      'data' => t('IP/Host'),
      'field' => 'ads.ip',
    ),
    array(
      'data' => t('Referrer'),
      'field' => 'ads.referrer',
    ),
  );
  $rows = array();
  $name_resolve = variable_get('adsense_click_tracking_name_resolve', ADSENSE_CLICK_TRACKING_NAME_RESOLVE_DEFAULT);

  // Create our base query.
  $query = db_select('adsense_clicks', 'ads');
  $query = $query
    ->extend('PagerDefault')
    ->extend('TableSort');
  $query
    ->fields('ads', array(
    'ip',
    'timestamp',
    'path',
    'title',
    'referrer',
  ))
    ->limit(50)
    ->orderByHeader($header);
  $result = $query
    ->execute();
  foreach ($result as $log) {
    if ($name_resolve) {
      $host = gethostbyaddr($log->ip);
    }
    else {
      $host = $log->ip;
    }
    $rows[] = array(
      array(
        'data' => format_date($log->timestamp, 'small'),
        'nowrap' => 'nowrap',
      ),
      _adsense_click_format_path($log->path, $log->title),
      l($host, 'http://whois.domaintools.com/' . $log->ip),
      _adsense_click_format_path($log->referrer),
    );
  }
  return theme('table', array(
    'header' => $header,
    'rows' => $rows,
  )) . theme('pager');
}