[ PHPXref.com ] [ Generated: Sun Jul 20 17:22:00 2008 ] [ Drupal 5.0 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/modules/tracker/ -> tracker.module (source)

   1  <?php
   2  // $Id: tracker.module,v 1.143 2007/01/10 15:17:51 dries Exp $
   3  
   4  /**
   5   * @file
   6   * Enables tracking of recent posts for users.
   7   */
   8  
   9  /**
  10   * Implementation of hook_help().
  11   */
  12  function tracker_help($section) {
  13    switch ($section) {
  14      case 'admin/help#tracker':
  15        $output = '<p>'. t('The tracker module displays the most recently added or updated content to the website allowing users to see the most recent contributions. The tracker module provides user level tracking for those who like to follow the contributions of particular authors.') .'</p>';
  16        $output .= '<p>'. t('The  &quot;recent posts&quot; page is available via a link in the navigation menu block and contains a reverse chronological list of new and recently-updated content. The table displays  the content type, the title, the author\'s name, how many comments that item has received, and when it was last updated. Updates include any changes to the text, either by the original author or someone else, as well as any new comments added to an item. To use the tracker module to <em>watch</em> for a user\'s updated content, click on that user\'s profile, then the <em>track</em> tab.') .'</p>';
  17        $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@tracker">Tracker page</a>.', array('@tracker' => 'http://drupal.org/handbook/modules/tracker/')) .'</p>';
  18        return $output;
  19    }
  20  }
  21  
  22  /**
  23   * Implementation of hook_menu().
  24   */
  25  function tracker_menu($may_cache) {
  26    global $user;
  27    $items = array();
  28  
  29    if ($may_cache) {
  30      $items[] = array('path' => 'tracker', 'title' => t('Recent posts'),
  31        'callback' => 'tracker_page', 'access' => user_access('access content'),
  32        'weight' => 1);
  33  
  34      if ($user->uid) {
  35        $items[] = array('path' => 'tracker/all', 'title' => t('All recent posts'),
  36          'type' => MENU_DEFAULT_LOCAL_TASK);
  37        $items[] = array('path' => 'tracker/'. $user->uid, 'title' => t('My recent posts'),
  38          'type' => MENU_LOCAL_TASK);
  39      }
  40    }
  41    else {
  42      if (arg(0) == 'user' && is_numeric(arg(1))) {
  43        $items[] = array('path' => 'user/'. arg(1) .'/track', 'title' => t('Track'),
  44            'callback' => 'tracker_track_user', 'access' => user_access('access content'),
  45            'type' => MENU_IS_LOCAL_TASK);
  46        $items[] = array('path' => 'user/'. arg(1) .'/track/posts', 'title' => t('Track posts'),
  47            'type' => MENU_DEFAULT_LOCAL_TASK);
  48      }
  49    }
  50  
  51    return $items;
  52  }
  53  
  54  /**
  55   * Menu callback. Prints a listing of active nodes on the site.
  56   */
  57  function tracker_track_user() {
  58    if ($account = user_load(array('uid' => arg(1)))) {
  59      if ($account->status || user_access('administer users')) {
  60        drupal_set_title(check_plain($account->name));
  61        return tracker_page($account->uid);
  62      }
  63      else {
  64        drupal_access_denied();
  65      }
  66    }
  67    else {
  68      drupal_not_found();
  69    }
  70  }
  71  
  72  /**
  73   * Menu callback. Prints a listing of active nodes on the site.
  74   */
  75  function tracker_page($uid = 0) {
  76    // Add CSS
  77    drupal_add_css(drupal_get_path('module', 'tracker') .'/tracker.css', 'module', 'all', FALSE);
  78  
  79    // TODO: These queries are very expensive, see http://drupal.org/node/105639
  80    if ($uid) {
  81      $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d) ORDER BY last_updated DESC';
  82      $sql = db_rewrite_sql($sql);
  83      $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d)';
  84      $sql_count = db_rewrite_sql($sql_count);
  85      $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $uid, $uid);
  86    }
  87    else {
  88      $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 ORDER BY last_updated DESC';
  89      $sql = db_rewrite_sql($sql);
  90      $sql_count = 'SELECT COUNT(n.nid) FROM {node} n WHERE n.status = 1';
  91      $sql_count = db_rewrite_sql($sql_count);
  92      $result = pager_query($sql, 25, 0, $sql_count);
  93    }
  94  
  95    $rows = array();
  96    while ($node = db_fetch_object($result)) {
  97      // Determine the number of comments:
  98      $comments = 0;
  99      if (module_exists('comment') && $node->comment_count) {
 100        $comments = $node->comment_count;
 101  
 102        if ($new = comment_num_new($node->nid)) {
 103          $comments .= '<br />';
 104          $comments .= l(format_plural($new, '1 new', '@count new'), "node/$node->nid", NULL, NULL, 'new');
 105        }
 106      }
 107  
 108      $rows[] = array(
 109        node_get_types('name', $node->type),
 110        l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)),
 111        theme('username', $node),
 112        array('class' => 'replies', 'data' => $comments),
 113        t('!time ago', array('!time' => format_interval(time() - $node->last_updated)))
 114      );
 115    }
 116  
 117    if (!$rows) {
 118      $rows[] = array(array('data' => t('No posts available.'), 'colspan' => '5'));
 119    }
 120  
 121    $header = array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last updated'));
 122  
 123    $output = '<div id="tracker">';
 124    $output .= theme('table', $header, $rows);
 125    $output .= theme('pager', NULL, 25, 0);
 126    $output .= '</div>';
 127  
 128    return $output;
 129  }


[ Powered by PHPXref - Served by Debian GNU/Linux ]