statistics.pages.inc 3.2 KB

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