Link that counts new/unread posts in forum

NeoID - March 9, 2009 - 09:58

Hi,

I'm looking for a way to create a link that outputs the number of new, unread forum posts from all forums on my drupal-board since my last visit....

Like "New forumposts (34)"... any ideas? :)

Partial answer

Michelle - March 10, 2009 - 00:56

This is the code Advanced Forum uses to get the bumber of unread comments in a particular forum. You can expand it to include all forums. This doesn't count nodes, though, so you'd need a seperate query for that and add them.

<?php
/**
* Returns the number of unread posts in a given forum for a given user
*/
function advanced_forum_unread_comments_in_forum($tid, $uid) {
  static
$result_cache = NULL;

  if (
is_NULL($result_cache)) {
   
$result_cache = array();
   
$vid = variable_get('forum_nav_vocabulary', '');
   
$sql = "SELECT COUNT(c.cid) AS count, tn.tid
            FROM {comments} c
            INNER JOIN {term_node} tn ON c.nid = tn.nid
            INNER JOIN {term_data} td ON td.tid = tn.tid AND td.vid = %d
            LEFT JOIN {history} h ON c.nid = h.nid AND h.uid = %d
            WHERE c.status = 0 AND c.timestamp > %d AND (c.timestamp > h.timestamp OR h.timestamp IS NULL)
            GROUP BY tn.tid"
;
   
$sql = db_rewrite_sql($sql, 'c', 'cid');
   
$result = db_query($sql, $vid, $uid, NODE_NEW_LIMIT);
    while (
$row = db_fetch_array($result)) {
       
$result_cache[$row['tid']] = $row['count'];
    }
  }

  return (isset(
$result_cache[$tid])) ? $result_cache[$tid] : 0;
}
?>

---
I'm looking for folks to help me out by posting in my Coulee Region forums. You don't need to live in the area; there's plenty of general forums. But please, no Drupal support questions. :)

Thanks for the snippet, but

NeoID - April 23, 2009 - 15:50

Thanks for the snippet, but my mysql-knowledge is very basic; I'm a themer after all... :)
Would it be possible to show me how to include the first node and comments on a globally basis, but still respecting who has access to read the particular forums?
(If there are only new posts in the protected forums, it should only be displayed to them who also has access to read it...)

I would highly appreciate it if you or anyone else could help me with this one...

 
 

Drupal is a registered trademark of Dries Buytaert.