Drupal PHP Cross Reference Content Management Systems

Source: /modules/statistics/statistics.pages.inc - 105 lines - 3284 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /**
   4   * @file
   5   * User page callbacks for the Statistics module.
   6   */
   7  
   8  /**
   9   * Page callback: Displays statistics for a node.
  10   *
  11   * @return
  12   *   A render array containing node statistics. If information for the node was
  13   *   not found, this will deliver a page not found error via drupal_not_found().
  14   */
  15  function statistics_node_tracker() {
  16    if ($node = node_load(arg(1))) {
  17  
  18      $header = array(
  19          array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'),
  20          array('data' => t('Referrer'), 'field' => 'a.url'),
  21          array('data' => t('User'), 'field' => 'u.name'),
  22          array('data' => t('Operations')));
  23  
  24      $query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort');
  25      $query->join('users', 'u', 'a.uid = u.uid');
  26  
  27      $query
  28        ->fields('a', array('aid', 'timestamp', 'url', 'uid'))
  29        ->fields('u', array('name'))
  30        ->condition(db_or()
  31          ->condition('a.path', 'node/' . $node->nid)
  32          ->condition('a.path', 'node/' . $node->nid . '/%', 'LIKE'))
  33        ->limit(30)
  34        ->orderByHeader($header);
  35  
  36      $result = $query->execute();
  37      $rows = array();
  38      foreach ($result as $log) {
  39        $rows[] = array(
  40          array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')),
  41          _statistics_link($log->url),
  42          theme('username', array('account' => $log)),
  43          l(t('details'), "admin/reports/access/$log->aid"),
  44        );
  45      }
  46  
  47      drupal_set_title($node->title);
  48      $build['statistics_table'] = array(
  49        '#theme' => 'table',
  50        '#header' => $header,
  51        '#rows' => $rows,
  52        '#empty' => t('No statistics available.'),
  53      );
  54      $build['statistics_pager'] = array('#theme' => 'pager');
  55      return $build;
  56    }
  57    else {
  58      drupal_not_found();
  59    }
  60  }
  61  
  62  /**
  63   * Page callback: Displays statistics for a user.
  64   *
  65   * @return array
  66   *   A render array containing user statistics. If information for the user was
  67   *   not found, this will deliver a page not found error via drupal_not_found().
  68   */
  69  function statistics_user_tracker() {
  70    if ($account = user_load(arg(1))) {
  71  
  72      $header = array(
  73          array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'),
  74          array('data' => t('Page'), 'field' => 'path'),
  75          array('data' => t('Operations')));
  76      $query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort');
  77      $query
  78        ->fields('a', array('aid', 'timestamp', 'path', 'title'))
  79        ->condition('uid', $account->uid)
  80        ->limit(30)
  81        ->orderByHeader($header);
  82  
  83      $result = $query->execute();
  84      $rows = array();
  85      foreach ($result as $log) {
  86        $rows[] = array(
  87          array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')),
  88          _statistics_format_item($log->title, $log->path),
  89          l(t('details'), "admin/reports/access/$log->aid"));
  90      }
  91  
  92      drupal_set_title(format_username($account));
  93      $build['statistics_table'] = array(
  94        '#theme' => 'table',
  95        '#header' => $header,
  96        '#rows' => $rows,
  97        '#empty' => t('No statistics available.'),
  98      );
  99      $build['statistics_pager'] = array('#theme' => 'pager');
 100      return $build;
 101    }
 102    else {
 103      drupal_not_found();
 104    }
 105  }

title

Description

title

Description

title

Description

title

title

Body