/[drupal]/contributions/modules/xtracker/xtracker.module
ViewVC logotype

Diff of /contributions/modules/xtracker/xtracker.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.9, Fri Apr 13 20:12:11 2007 UTC revision 1.10, Wed Oct 7 01:46:40 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: xtracker.module,v 1.8 2007/04/13 20:08:09 kbahey Exp $  // $Id: xtracker.module,v 1.7.2.3 2008/02/19 18:49:02 kbahey Exp $
3    // modified for D6 hwd 2009/07/31
4    
5  /**  /**
6   * @file   * @file
# Line 8  Line 9 
9    
10  define ('XTRACKER_WEIGHT',     5);  define ('XTRACKER_WEIGHT',     5);
11  define ('XTRACKER_PAGE_COUNT', 'xtracker_page_count');  define ('XTRACKER_PAGE_COUNT', 'xtracker_page_count');
12    define ('XTRACKER_VIEW_TOTALS', 'view nodevote totals');
13    
14  /**  /**
15   * Implementation of hook_help().   * Implementation of hook_help().
16   */   */
17  function xtracker_help($section) {  function xtracker_help($path, $arg) {
18    switch ($section) {    switch ($path) {
19      case 'admin/help#xtracker':      case 'admin/help#xtracker':
20        return t('<p>The xtracker module is a handy module for displaying the most recently added or updated content</p>');        return t('<p>The xtracker module is a handy module for displaying the most recently added or updated content</p>');
21      case 'admin/modules#description':      case 'admin/modules#description':
# Line 21  function xtracker_help($section) { Line 23  function xtracker_help($section) {
23    }    }
24  }  }
25    
26    function xtracker_perm() {
27      return array (XTRACKER_VIEW_TOTALS);
28    }
29    
30  function xtracker_admin_settings() {  function xtracker_admin_settings() {
31    
32    $vocabs = array();    $vocabs = array();
# Line 52  function xtracker_admin_settings() { Line 58  function xtracker_admin_settings() {
58  /**  /**
59   * Implementation of hook_menu().   * Implementation of hook_menu().
60   */   */
61  function xtracker_menu($may_cache) {  function xtracker_menu() {
62    global $user;    global $user;
63    $items = array();    $items = array();
64    
65    $vid = variable_get('xtracker_vid', 0);    $vid = variable_get('xtracker_vid', 0);
66    $terms = xtracker_get_terms($vid);    $terms = xtracker_get_terms($vid);
67    
68    if ($may_cache) {      $items['admin/settings/xtracker'] = array(
69      $items[] = array(        'title' => 'xtracker',
70        'path' => 'admin/settings/xtracker',        'description' => 'xtracker settings.',
71        'title' => t('xtracker'),        'page callback' => 'drupal_get_form',
72        'description' => t('xtracker settings.'),        'page arguments' => array('xtracker_admin_settings'),
73        'callback' => 'drupal_get_form',        'access arguments' => array('administer site configuration'),
       'callback arguments' => array('xtracker_admin_settings'),  
       'access' => user_access('administer site configuration'),  
74        'type' => MENU_NORMAL_ITEM, // optional        'type' => MENU_NORMAL_ITEM, // optional
75      );      );
76    
77      $items[] = array(      $items['xtracker'] = array(
78        'path' => 'xtracker',        'title' => 'Recent posts',
79        'title' => t('Recent posts'),        'page callback' => 'xtracker_page',
80        'callback' => 'xtracker_page',        'access arguments' => array('access content'),
       'access' => user_access('access content'),  
81        'weight' => 1);        'weight' => 1);
82    
83        $items[] = array(        $items['xtracker/all'] = array(
84          'path' => 'xtracker/all',          'title' => 'all',
         'title' => t('all'),  
85          'type' => MENU_DEFAULT_LOCAL_TASK);          'type' => MENU_DEFAULT_LOCAL_TASK);
86    
87    
# Line 87  function xtracker_menu($may_cache) { Line 89  function xtracker_menu($may_cache) {
89      foreach (node_get_types() as $node_type) {      foreach (node_get_types() as $node_type) {
90        $type = $node_type->type;        $type = $node_type->type;
91        $name = $node_type->name;        $name = $node_type->name;
92        $items[] = array(        $items['xtracker/type/'. $type] = array(
93          'path'     => 'xtracker/type/'. $type,          'page callback' => 'xtracker_page',
         'callback' => 'xtracker_page',  
94          'title'    => $name,          'title'    => $name,
95            'access arguments' => array('access content'),
96          'type'     => MENU_LOCAL_TASK,          'type'     => MENU_LOCAL_TASK,
97          'weight'   => XTRACKER_WEIGHT+$i);          'weight'   => XTRACKER_WEIGHT+$i);
98        $i++;        $i++;
# Line 98  function xtracker_menu($may_cache) { Line 100  function xtracker_menu($may_cache) {
100    }    }
101    else {    else {
102      foreach ($terms as $tid => $name) {      foreach ($terms as $tid => $name) {
103        $items[] = array(        $items['xtracker/tid/'. $tid] = array(
104          'path'     => 'xtracker/tid/'. $tid,          'page callback' => 'xtracker_page',
         'callback' => 'xtracker_page',  
105          'title'    => $name,          'title'    => $name,
106            'access callback' => '_xtracker_view_totals',
107    //        'access arguments' => array('access content'),
108          'type'     => MENU_LOCAL_TASK,          'type'     => MENU_LOCAL_TASK,
109          'weight'   => XTRACKER_WEIGHT+$i);          'weight'   => XTRACKER_WEIGHT+$i);
110        $i++;        $i++;
111      }      }
112    }    }
113    
114      if ($user->uid) {  // this doesn't work properly - any help?
115        $items[] = array(      $items['xtracker/%user_uid_optional'] = array(
116          'path' => 'xtracker/uid/'. $user->uid,        'title' => 'my posts',
117          'title' => t('my posts'),        'access callback' => '_xtracker_myrecent_access',
118          'type' => MENU_LOCAL_TASK);        'access arguments' => array(1),
119      }        'type' => MENU_LOCAL_TASK);
120    }  
121    else {      $items['user/%user/xtrack'] = array(
122      if (arg(0) == 'user' && is_numeric(arg(1))) {        'title' => 'track',
123        $items[] = array(        'page callback' => 'xtracker_track_user',
124          'path' => 'user/'. arg(1) .'/xtrack',        'access callback' => '_xtracker_user_access',
125          'title' => t('track'),        'access arguments' => array(1),
126          'callback' => 'xtracker_track_user',        'type' => MENU_IS_LOCAL_TASK);
127          'access' => user_access('access content'),  
128          'type' => MENU_IS_LOCAL_TASK);      $items['user/%user/xtrack/posts'] = array(
129          'title' => 'track posts',
130        $items[] = array(        'type' => MENU_DEFAULT_LOCAL_TASK);
         'path' => 'user/'. arg(1) .'/xtrack/posts',  
         'title' => t('track posts'),  
         'type' => MENU_DEFAULT_LOCAL_TASK);  
     }  
   }  
131    
132    return $items;    return $items;
133  }  }
# Line 144  function xtracker_track_user() { Line 142  function xtracker_track_user() {
142    }    }
143    else {    else {
144      drupal_set_message(t('user not found'));      drupal_set_message(t('user not found'));
145      print theme('page',' ');      print theme('page', ' ');
146    }    }
147  }  }
148    
# Line 161  function xtracker_page($uid = 0) { Line 159  function xtracker_page($uid = 0) {
159      $type = 'uid';      $type = 'uid';
160    }    }
161    
162    if (module_exists('nodevote')) {    $sql_where = ' WHERE n.status = 1 ';
163      $score = true; // Flag we use later  
164      if (module_exists('nodevote') && _xtracker_view_totals()) {
165        $score = TRUE; // Flag we use later
166      $score_column = ',AVG(v.vote) AS score';      $score_column = ',AVG(v.vote) AS score';
167      $nv_join = ' LEFT JOIN {nodevote} v ON n.nid = v.nid ';      $extra_join = ' LEFT JOIN {nodevote} v ON n.nid = v.nid ';
168    }    }
169    
170    switch($type) {    switch ($type) {
171      case 'uid':      case 'uid':
172        $id = (int)$id;        $id = (int)$id;
173        $sql_where = " AND (n.uid = '$id' OR c.uid = '$id') ";        $sql_where .= " AND (n.uid = $id OR c.uid = $id) ";
174        break;        break;
175    
176      case 'tid':      case 'tid':
177        $id = (int)$id;        $id = (int)$id;
178        $sql_where = " AND t.tid =  '$id' ";        $extra_join .= ' INNER JOIN {term_node} t ON t.nid = n.nid ';
179          $sql_where .= " AND t.tid =  $id ";
180        break;        break;
181    
182      case 'type':      case 'type':
183        $id = db_escape_string($id);        $id = db_escape_string($id);
184        $sql_where = " AND n.type = '$id' ";        $sql_where .= " AND n.type = '$id' ";
185        break;        break;
186    
187      case 'all':      case 'all':
188      default:      default:
       $sql_where = ' ';  
189        break;        break;
190    }    }
191    
192    $header = array(    $header = array(
193        array('data' => t('Type'),      'field' => 'type'),        array('data' => t('Type'), 'field' => 'type'),
194        array('data' => t('Post'),      'field' => 'title'),        array('data' => t('Post'), 'field' => 'title'),
195        array('data' => t('Author'),    'field' => 'name',),        array('data' => t('Author'), 'field' => 'uid'),
196        array('data' => t('Replies'),   'field' => 'comment_count'),        array('data' => t('Replies'), 'field' => 'comment_count'),
197        array('data' => t('Last Post'), 'field' => 'last_post', 'sort' => 'desc')        array('data' => t('Last Post'), 'field' => 'last_update', 'sort' => 'desc')
198      );      );
199    
   
   
200    if ($score) {    if ($score) {
201      $header = array_merge($header, array(      $header = array_merge($header, array(
202        array('data' => t('Score'),     'field' => 'score')        array('data' => t('Score'),     'field' => 'score')
203      ));      ));
204    }    }
205    
206    $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, GREATEST(n.changed, l.last_comment_timestamp) AS last_post, l.comment_count ' . $score_column . ' FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid ' . $nv_join . 'LEFT JOIN {term_node} t ON t.nid = n.nid LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.status = 1 ' . $sql_where . ' GROUP BY n.nid ';    $sql_from = ' FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid LEFT JOIN {comments} c ON n.nid = c.nid'. $extra_join;
207    
208    $sql_count = 'SELECT COUNT(t.nid) FROM {node} n LEFT JOIN {term_node} t USING (nid) LEFT JOIN {comments} c ON n.nid = c.nid WHERE n.nid = t.nid AND n.status = 1 ' . $sql_where;    $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, GREATEST(n.changed, l.last_comment_timestamp) AS last_update, l.comment_count '. $score_column . $sql_from . $sql_where .' GROUP BY n.nid ';
209    
210      $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) '. $sql_from . $sql_where;
211    
212    $sql .= tablesort_sql($header);    $sql .= tablesort_sql($header);
213    $result = pager_query($sql, variable_get(XTRACKER_PAGE_COUNT, 10), 0, $sql_count);    $result = pager_query(db_rewrite_sql($sql), variable_get(XTRACKER_PAGE_COUNT, 10), 0, $sql_count);
214    
215    while ($node = db_fetch_object($result)) {    while ($node = db_fetch_object($result)) {
216      // Determine the number of comments:      // Determine the number of comments:
# Line 218  function xtracker_page($uid = 0) { Line 218  function xtracker_page($uid = 0) {
218      if (module_exists('comment') && $node->comment_count) {      if (module_exists('comment') && $node->comment_count) {
219        $comments = $node->comment_count;        $comments = $node->comment_count;
220    
221        if ($new = comment_num_new($node->nid)) {        if ($new == comment_num_new($node->nid)) {
222          $comments .= '<br />';          $comments .= '<br />';
223          $comments .= l(t('@num new', array('@num' => $new)), "node/$node->nid", NULL, NULL, 'new');  //        $comments .= l(t('@num new', array('@num' => $new)), "node/$node->nid", NULL, NULL, 'new');
224            $comments .= l(t('@num new', array('@num' => $new)), "node/$node->nid", array('fragment' => 'new'));
225        }        }
226      }      }
227    
228        $result2 = db_query('SELECT uid, name FROM {users} WHERE uid = %d', $node->uid);
229        $author = db_fetch_object($result2);
230        $author_name = theme_username($author);
231    
232      $row = array(      $row = array(
233        node_get_types('name',$node),        node_get_types('name', $node),
234        l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)),        l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)),
235        theme_username($node),        $author_name,
236        array('class' => 'replies', 'data' => $comments),        array('class' => 'replies', 'data' => $comments),
237        t('@time ago', array('@time' => format_interval(time() - $node->last_post))),        t('@time ago', array('@time' => format_interval(time() - $node->last_update))),
238      );      );
239    
240      if ($score) {      if ($score) {
# Line 266  function xtracker_get_terms($vid) { Line 271  function xtracker_get_terms($vid) {
271    }    }
272    return $data;    return $data;
273  }  }
 ?>  
274    
275    /**
276     * Access callback for tracker/%user_uid_optional
277     */
278    function _xtracker_myrecent_access($account) {
279      // This path is only allowed for authenticated users looking at their own posts.
280      return $account->uid && ($GLOBALS['user']->uid == $account->uid) && user_access('access content');
281    }
282    
283    /**
284     * Access callback for user/%user/track
285     * from core tracker module
286     */
287    function _xtracker_user_access($account) {
288      return user_view_access($account) && user_access('access content');
289    }
290    
291    /**
292     * Access callback for viewing vote totals
293     */
294    function _xtracker_view_totals() {
295      return user_access('access content') && user_access(XTRACKER_VIEW_TOTALS);
296    }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.2