statistics.pages.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. return MENU_NOT_FOUND;
  51. }
  52. /**
  53. * Page callback: Displays statistics for a user.
  54. *
  55. * @return array
  56. * A render array containing user statistics. If information for the user was
  57. * not found, this will deliver a page not found error via drupal_not_found().
  58. */
  59. function statistics_user_tracker() {
  60. if ($account = user_load(arg(1))) {
  61. $header = array(
  62. array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'),
  63. array('data' => t('Page'), 'field' => 'path'),
  64. array('data' => t('Operations')));
  65. $query = db_select('accesslog', 'a', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort');
  66. $query
  67. ->fields('a', array('aid', 'timestamp', 'path', 'title'))
  68. ->condition('uid', $account->uid)
  69. ->limit(30)
  70. ->orderByHeader($header);
  71. $result = $query->execute();
  72. $rows = array();
  73. foreach ($result as $log) {
  74. $rows[] = array(
  75. array('data' => format_date($log->timestamp, 'short'), 'class' => array('nowrap')),
  76. _statistics_format_item($log->title, $log->path),
  77. l(t('details'), "admin/reports/access/$log->aid"));
  78. }
  79. drupal_set_title(format_username($account));
  80. $build['statistics_table'] = array(
  81. '#theme' => 'table',
  82. '#header' => $header,
  83. '#rows' => $rows,
  84. '#empty' => t('No statistics available.'),
  85. );
  86. $build['statistics_pager'] = array('#theme' => 'pager');
  87. return $build;
  88. }
  89. return MENU_NOT_FOUND;
  90. }