Ok,

I'm currently using Drupal to develop a few sites. One of the things I get the most feedback from my clients about is the poor quality of Drupal's forum (particularly compared to phpBB).

I know, I know. Nobody wants to integrate the two (and you're quite right, it's not a great idea), but nobody can deny that - from the point of view of a user - phpBB does things that Drupal's forums don't.

The most-requested feature I have is a "button that marks all the forum posts as 'read'".

Has anyone done this already?

If not, how hard is it likely to be (not very?) and where would I start? I'd rather develop this as a seperate module rather than hack the forum module, however the feature seems so universal that I find it hard to believe that it hasn't been at least considered before.

Ideally it'd be plain text and located with the "My Discussions", "Active Discussions", and "Post New Forum Topic" links that are displayed at the top of ?q=forum.

Thanks in advance,

Iain Galloway

Comments

Walt Esquivel’s picture

Hmmm. I thought I would try and find out if someone had already submitted your "button that marks all the forum posts as read" as a forum feature request, but when I went to http://drupal.org/support and, under Feature Requests, clicked on:

You may review outstanding feature requests...

...which led to http://drupal.org/project/issues?categories=feature, I didn't see the forum.module as an option from the Project drop-down menu.

Could it be listed as something else? Regardless, where can I find the forum.module's already submitted feature requests?

-----
Walt Esquivel, MBA, MA, Captain - U.S. Marine Corps (Veteran)
President, Wellness Corps, LLC
-----

sepeck’s picture

Drupal covers all the core modules.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

jimw-1’s picture

Go to this advanced search page and you can select 'forum.module' in the components box
http://drupal.org/project/issues/search/drupal

Walt Esquivel’s picture

I'm a firm believer in:
Give a man a fish, feed him for a day;
Teach a man to fish, feed him for life.

So...how did you get from:
http://drupal.org/project/issues/search
to:
http://drupal.org/project/issues/search/drupal

...without, of course, simply adding "drupal" in the browser?

I played around with http://drupal.org/project/issues/search but couldn't figure out a way to get to your link without intuitively knowing to type in drupal at the end of my URL.

By the way, I was able to find exactly what I was looking for using your advanced search URL!
http://drupal.org/node/2748
http://drupal.org/node/1762

Most excellent. Thanks!

-----
Walt Esquivel, MBA, MA, Captain - U.S. Marine Corps (Veteran)
President, Wellness Corps, LLC
-----

Heine’s picture

Select Drupal on http://drupal.org/project/issues/search, click search and click advanced search in the result screen.
--
When your problem is solved, please post a follow-up to the thread you started.

Walt Esquivel’s picture

Thanks Heine! I can now fish for life! ;)

-----
Walt Esquivel, MBA, MA, Captain - U.S. Marine Corps (Veteran)
President, Wellness Corps, LLC
-----

Walt Esquivel’s picture

Iain,

Steven Peck, jimw, and Heine have kindly provided us a way to look for the feature your customers are requesting.

If this is important enough to you, follow my posts and then do the necessary feature request followup.

-----
Walt Esquivel, MBA, MA, Captain - U.S. Marine Corps (Veteran)
President, Wellness Corps, LLC
-----

bobbia’s picture

Have you looked at the markasread.module found at http://drupal.org/node/24883? It is for 4.6, but it could be a good start.

It would be great to see this as a standard module.

Libervisco’s picture

I tried that markasread.module, implemented the link just below "My Discussions" and "Active Discussions" links and it worked. However, when you would click on it to mark all as read it apparently marks it as read forever.

After that even if there are new posts, forums wont display "X new" text in forum index, which is absolutely weird.

Even weirder is that, at least as reported by one of my site users, it did work for a bit and put the "X new" link there and then stopped working again even though there still were new posts..

I'm posting this to ask if anyone else experienced something similar and what could be the cause?

I have disabled the module for now for this reason.

Thank you
Daniel

Libervisco’s picture

Okay here is the module in question, the markasread.module. It is really not a big piece of php so all you php gurus may be able to see what does it do wrong in regards to the Drupal 4.7 and its marking as read/unread functionalities.

Here is it:

function markasread_menu($may_cache)
{
   $toreturn = array();
   if (!$may_cache)
   {
      $toreturn[] = array('path' => 'node/markasread',
            'title' => t('mark all content read'),
            'callback' => '_markasread',
            'access' => user_access('access content'),
            'type' => MENU_CALLBACK);
   }

   return $toreturn;
}

function _markasread($tid  = NULL)
{
  global $user;
  if ($user && $user->uid)
  {
      if (!is_null($tid))
      {
        if (is_numeric($tid) && $tid)
         {
            db_query("REPLACE INTO {history} (uid,nid,timestamp)
SELECT '%d',n.nid,UNIX_TIMESTAMP() FROM {node} n
INNER JOIN {term_node} r ON n.nid=r.nid
INNER JOIN {node_comment_statistics} l ON l.nid=n.nid
WHERE (n.created > '%d' OR l.last_comment_timestamp > '%d')
AND r.tid='%d'", $user->uid,NODE_NEW_LIMIT,NODE_NEW_LIMIT,$tid);
            drupal_goto("forum/$tid");
         }
         else
         {
            db_query("REPLACE INTO {history} (uid,nid,timestamp)
SELECT '%d',n.nid,UNIX_TIMESTAMP() FROM {node} n
INNER JOIN {node_comment_statistics} l ON l.nid=n.nid
WHERE (n.created > '%d' OR l.last_comment_timestamp > '%d')",
$user->uid,NODE_NEW_LIMIT,NODE_NEW_LIMIT);
            drupal_goto("forum");
         }
         print theme('page',"All content has been marked read");
      }
   }
   drupal_goto('forum');
}

So, any clues?

Thanks alot!
Daniel

rkn-dupe’s picture

Would love to know if anyone had an answer for this :)

slayerment’s picture

Me too

sanduhrs’s picture

krzysiek@palikowski.vel.pl’s picture

i add /markasread to the forum with id link ( e.g. http://localhost/b2k7/?q=forum/23/markasread, tested also with clean urls on production site, both are 4.7.3 )

and i get blank page with:

query: SELECT DISTINCT(n.nid) FROM node n INNER JOIN term_node tn ON n.nid = tn.nid AND tn.tid = 24 LEFT JOIN comments c ON n.nid = c.nid LEFT JOIN history h ON n.nid = h.nid AND h.uid = 1 WHERE (n.status = 1 AND n.type = 'forum' AND n.created > 1160134798 AND h.nid IS NULL) OR (h.timestamp < c.timestamp AND c.status='0')
error:

after i hit back button i get drupal msgbox with info:

All new nodes in this forum were marked as read.

warning: Cannot modify header information - headers already sent by (output started at D:\xampp\xampp\htdocs\b2k7\includes\database.mysql.inc:113) in D:\xampp\xampp\htdocs\b2k7\includes\common.inc on line 266.

and even stranger it works for some topics and for some don't... i can't specify why, but maybe it has something to do with topics moved from board to board or maybe with the fact that i migrated from pnphpbb with phpbb2drupal module?

If you could also post how and where add code that will show link 'mark as read' to all logged users?

EDIT

After some time i have "mark ALL forums as read" option working, but not "mark posts on THIS specific forum as read"...

and even if i click "mark all forums topics as read", then somenting strange happens - when somebody write new topics, on front page of the forum (with all forums and subforums) there are no indications that there are new posts. If i enter the specific board, i see x new posts beside topic titles... strange, huh?

sanduhrs’s picture

and i get blank page with:
Please retry [1], i changed from debug-mode to normal.

If you could also post how and where add code that will show link 'mark as read' to all logged users?
There should be a link in the menu, now.

After some time i have "mark ALL forums as read" option working, but not "mark posts on THIS specific forum as read"...
Should work with the provided link.

and even if i click "mark all forums topics as read", then somenting strange happens - when somebody write new topics, on front page of the forum (with all forums and subforums) there are no indications that there are new posts. If i enter the specific board, i see x new posts beside topic titles... strange, huh?
The "new indicator" as far as I know, is only shown when new topics are posted, not when new comments are posted, please confirm that there are new topics, not just new comments on topics.

[1] http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/sanduhrs/foru...

krzysiek@palikowski.vel.pl’s picture

The "new indicator" as far as I know, is only shown when new topics are posted, not when new comments are posted, please confirm that there are new topics, not just new comments on topics.

That is totally right, i see now that it works exactly like that... sorry :)

But

1) after installing Your module there is no new menu link,
2) mark specific forum as read works great (e.g. forum/2/markasread), but forum/markasread goes to page that has forum table heading, but no content, and nothing happens (posts are not marked read)... look at screenshot, maybe i try it on clean install of drupal, to verify if this is due to my site config or is this really a bug.

http://img165.imageshack.us/my.php?image=drupalmarfasread1hi1.jpg

And one more question - is it possible to add link from this module to links above the forum table (in list with "Start new topic" etc. ?).

great work, anyway, cheers

timatlee’s picture

I just downloaded the module, and enabled it.

Works great, as long as your forums link is in a block on one of the side bars. My forum link happens to be a primary link, and as such, doesn't display the 'mark as read' link.

I looked in forum.module - you could override theme_forum_display() to display the link in the position of your liking. I think this is how I'm going to circumvent this problem.

kimadactyl’s picture

yup i got no menu link either.

if you add a menu item with the link 'forum/0/markasread' then this works fine, though :) 0 is for all forums, or you can put a specific number in there if you know the id.

while it's very hacky i also inserted this line

$output .= ' <li>'. l(t('Mark all as read.'), "forum/0/markasread") .'</li>';

after line 887 in my version of forum.module, so it looks like this:

if (module_exist('tracker')) {
      if ($user->uid) {
        $output .= ' <li>'. l(t('My discussions.'), "tracker/$user->uid") .'</li>';
	# ADDED MARK ALL READ BUTTON
        $output .= ' <li>'. l(t('Mark all as read.'), "forum/0/markasread") .'</li>';
      }

      $output .= ' <li>'. l(t('Active discussions.'), 'tracker') .'</li>';
}

HTH!

hedac’s picture

I'm also interested in this but don't know how to implement this...
could anyone explain it a little more please?

sanduhrs’s picture

Simply download the module [1], save it to your Drupal installation's module-directory and activate it.

[1] http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/sanduhrs/foru...

jm9’s picture

Thank you sanduhrs for sharing your module. I've implemented it on one of my sites with a slight change that others may find useful.

I noticed the original routine doesn't mark nodes with recent comments if the original node is older than NODE_NEW_LIMIT, so I updated the SQL to handle this special situation. With the change, old nodes are correctly marked if there is a comment that's newer than NODE_NEW_LIMIT.

Original SQL

    $sql = "SELECT DISTINCT(n.nid) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid
            LEFT JOIN {history} h ON n.nid = h.nid AND h.uid = %d
            WHERE (n.status = 1 AND n.type = 'forum' AND n.created > %d AND h.nid IS NULL)
            OR (h.timestamp < c.timestamp AND c.status='%s')";

    $result = db_query($sql, $user->uid, NODE_NEW_LIMIT, COMMENT_PUBLISHED);

Modified SQL

    $sql = "SELECT DISTINCT(n.nid) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid
            LEFT JOIN {history} h ON n.nid = h.nid AND h.uid = %d 
            WHERE n.status = 1 AND n.type = 'forum' AND (
            (h.nid IS NULL AND (n.created > %d OR (c.timestamp > %d AND c.status='%s')))
            OR (h.timestamp < c.timestamp AND c.status='%s')
            )";

    $result = db_query($sql, $user->uid, NODE_NEW_LIMIT, NODE_NEW_LIMIT, COMMENT_PUBLISHED, COMMENT_PUBLISHED);

Note: There is also a second SQL statement that requires similar modifications. I've only shown the first to keep this post easy to read.

JM

Wesley Tanaka’s picture

I've updated the code that came from http://drupal.org/node/24883 for Drupal 5.0. It can be found here:

http://ofb.net/~wtanaka/drupal/markasread

Wesley Tanaka

gcassie’s picture

Hey, thanks very much Wesley. That seems to work quite nicely. Very helpful.

jaydub’s picture

This is in relation to the module markasread available at http://wtanaka.com/drupal/markasread

I unfortunately do not have a PostgreSQL drupal setup at the moment to verify this test but I believe this should work...

I modified the REPLACE INTO query to a switch test for db_type and used a slightly different query for PostgreSQL. Adding a join to the history table for the user will ensure that the INSERT will not attempt to insert duplicate rows. At least that's the theory :)

      switch($GLOBALS['db_type']) {
        case 'mysql':
        case 'mysqli':
          $sql = 'REPLACE INTO {history} (uid,nid,timestamp)'
            .' SELECT %d, n.nid, %d FROM {node} n'
            .($tid ? ' INNER JOIN {term_node} r ON n.nid=r.nid' : '')
            .' INNER JOIN {node_comment_statistics} l ON l.nid=n.nid'
            .' WHERE (n.created > %d'
            .' OR l.last_comment_timestamp > %d)';
          $args = array($user->uid, time(), NODE_NEW_LIMIT, NODE_NEW_LIMIT);
          break;
        case 'pgsql':
          $sql = 'INSERT INTO {history} (uid,nid,timestamp)'
            .' SELECT %d, n.nid, %d FROM {node} n'
            .($tid ? ' INNER JOIN {term_node} r ON n.nid=r.nid' : '')
            .' INNER JOIN {node_comment_statistics} l ON l.nid=n.nid'
            .' LEFT JOIN {history} h ON n.nid=h.nid AND h.uid = %d'
            .' WHERE (n.created > %d'
            .' OR l.last_comment_timestamp > %d)'
            .' AND h.uid IS NULL';
          $args = array($user->uid, time(), $user->uid, NODE_NEW_LIMIT, NODE_NEW_LIMIT);
          break;
      }

swill’s picture

(in regards to the module at http://wtanaka.com/drupal/markasread)

The module is not quite working as expected. Here is a list of things that I have questions about...

1. When someone uses the 'Mark all forums read', it shows up in the forum as marking all of the forums as read. This is good, but when comments are added to existing topics, the forum does not reflect that there is new content. (it does however reflect new topics being added.)
How can I fix this???

2. If I have the same forum topics/comments that have been marked as read in a different view (user_tracker for example), that same content shows up as 'new' in the other view even though it should have been marked as read.

3. Probably similar to 2, but the view filter (Node: Has New Content) still shows content that has been 'marked as read' with this module.
How do I fix this???

Cheers and thanks for the module... :)

Swill

seanmclucas’s picture

I haven't looked at the code yet, but if this still needs to be upgraded to D6, I am more than willing to help.

hedac’s picture

Advanced forum is a great solution

http://drupal.org/project/advanced_forum

Melot’s picture

Has anyone come up with a Drupal 6 solution?