summaryrefslogtreecommitdiff
path: root/modules/tracker/tracker.module
blob: 33665f552ebff472aa40d87c60c956e2d24e2143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
// $Id$

/**
 * Implementation of hook_help().
 */
function tracker_help($section) {
  switch ($section) {
    case 'admin/help#tracker':
      return t('<p>The tracker module is a handy module for displaying the most recent posts.  By following the <em>recent posts</em> link in the user block, a user may quickly review all recent postings.</p>');
    case 'admin/modules#description':
      return t('Enables tracking of recent posts for users.');
  }
}

/**
 * Implementation of hook_menu().
 */
function tracker_menu() {
  $items = array();
  $items[] = array('path' => 'tracker', 'title' => t('recent posts'),
    'callback' => 'tracker_page',
    'access' => user_access('access content'),
    'weight' => 1);
  return $items;
}

/**
 * Menu callback. Prints a listing of active nodes on the site.
 */
function tracker_page($uid = 0) {
  global $user;

  $output .= '';

  if ($user->uid) {
    $output .= '<ul>';
    $output .= ' <li>'. l(t('Your active posts and discussions'), "tracker/$user->uid") .'</li>';
    $output .= ' <li>'. l(t('All active posts and discussions'), 'tracker') .'</li>';
    $output .= '</ul>';
  }

  if ($uid) {
    $uid = check_query($uid);

    $result = pager_query("SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_post FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND (n.uid = $uid OR c.uid = $uid) GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_post DESC", 25, 0, "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.status = 1 AND (n.uid = $uid OR c.uid = $uid)");

  }
  else {
    $result = pager_query('SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, MAX(GREATEST(n.changed, c.timestamp)) AS last_post FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 GROUP BY n.nid, n.title, n.type, n.changed, n.uid, u.name ORDER BY last_post DESC', 25, 0, 'SELECT COUNT(nid) FROM {node} WHERE status = 1');
  }

  while ($node = db_fetch_object($result)) {
    // Determine the number of comments:
    if ($all = comment_num_all($node->nid)) {
      $comments = $all;

      if ($new = comment_num_new($node->nid)) {
        $comments .= '<br />';
        $comments .= l(t('%num new', array('%num' => $new)), "node/$node->nid", NULL, NULL, 'new');
      }
    }
    else {
      $comments = 0;
    }

    $rows[] = array(
      ucfirst(node_invoke($node->type, 'node_name')),
      l($node->title, "node/$node->nid") .' '. (node_is_new($node->nid, $node->changed) ? theme('mark') : ''),
      format_name($node),
      array('class' => 'replies', 'data' => $comments),
      format_interval(time() - $node->last_post) .' '. t('ago')
    );
  }

  if ($pager = theme('pager', NULL, 25, 0)) {
   $rows[] = array(array('data' => $pager, 'colspan' => 4));
  }

  $header = array(t('Type'),  t('Post'), t('Author'), t('Replies'), t('Last post'));

  $output .= '<div id="tracker">';
  $output .= theme('table', $header, $rows);
  $output .= '</div>';

  print theme('page', $output);
}

function tracker_user($type, &$edit, &$user) {
  if ($type == 'view' && user_access('access content')) {
    return array(t('History') => form_item(t('Recent posts'), l(t('recent posts'), "tracker/$user->uid")));
  }
}

?>