This patch adds URLs in the form of 'node/readall' and 'node/readall/$tid' that mark all nodes, or all nodes within a given category, as read by the current user.

This also adds "mark all read" and "mark this forum read" links to the forums.

CommentFileSizeAuthor
#3 markasread.module1.37 KBWesley Tanaka
mark_read.patch2.25 KBpyromanfo
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

killes@www.drop.org’s picture

Version: 4.6.0 »
Status: Needs review » Needs work

1) new features go into cvs, not stable

2) does not conform to codign standards

3) uses REPLACE, does not work with pgsql

I recommend making this a contrib module if possible.

Marandb’s picture

I am very interested in seeing this / functionality added...

I have tried to apply the patch above & it says "There was nothing but garbage found". Any updates on this?

Thank alot,

-- Marand B

Wesley Tanaka’s picture

FileSize
1.37 KB

I didn't like the way that this was marking things as a result of a GET request, so I modified it to accept POST instead.

Added this code to template.php to create the associated UI buttons.

function phptemplate_forum_display($forums, $topics, $parents, $tid,
      $sortby, $forum_per_page)
{
   $forum_display = theme_forum_display($forums, $topics, $parents,
         $tid, $sortby, $forum_per_page);
   $markbutton = form(form_hidden('tid', $tid)
         . form_button($tid ? t('Mark this thread as read') :
            t('Mark all as read')),
         'post', url('node/markasread'));
   return $forum_display .$markbutton;
}
Jaza’s picture

Version: » 4.7.x-dev
Status: Needs work » Closed (fixed)

Agreed, this belongs in a contrib module (perhaps someone has written a contrib module for this by now? :P).

Closing issue.

Wesley Tanaka’s picture

Status: Closed (fixed) » Active

How would one add a button to the forum page to trigger the "mark as read" action from a module? forum.module does not seem to ever call module_invoke()

Frando’s picture

hook_link_alter() is your friend, at least in Drupal 5.x

Wesley Tanaka’s picture

I believe that hook_link etc are insufficient because:

1. This should be a POST button, not a link, because it modifies data
2. Links are associated with nodes and comments. The button needs to be on the main forum page and on each individual forum page

magico’s picture

Version: 4.7.x-dev » 6.x-dev
Marandb’s picture

Any chance of anyone updating this for 5.x? IMO this is a much needed and missing feature in drupal. Without this functionality on any sizeable site the "Updated" notations become somewhat worthless. Just my opinion.

Regardless, how can we implement this in drupal 5.x?

Thanks,
-- Marandb

Wesley Tanaka’s picture

I just looked through the module in #3 -- it looks like it should still work in 5.0 as well as it did before (i.e. mysql specific, and what appears to be a few bugs)

Also see: http://drupal.org/node/63416

Wesley Tanaka’s picture

Is this bug a duplicate of bug 1672?

> Any chance of anyone updating this for 5.x?
I see -- the 4.6 specific code is the snippet in comment #3

You might try out these instructions: http://ofb.net/~wtanaka/drupal/markasread

catch’s picture

Status: Active » Closed (duplicate)

marking as duplicate:
http://drupal.org/node/1762

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;
      }

raintonr’s picture

+1 for this, although...

We have a 'my unread' view on site. Kindof like the regular 'tracker' page but with only nodes/comments unseen by user listed.

It would therfore be better, IMHO, to have this module:

- Ask for simple confirmation
- Show a 'all posts marked as read' info message rather than as a page
- Redirect back to the previous page after this

This shouldn't be too hard. We're on 5.x so if I get round to sorting this will post the module here.

raintonr’s picture

The given SQL wasn't working here so I tweaked it as follows:

    $sql = <<<EOF
REPLACE INTO {history} (uid, nid, timestamp)
SELECT '%d', n.nid, UNIX_TIMESTAMP()
FROM {node} n
LEFT JOIN {history} h ON (h.nid = n.nid AND h.uid = %d)
LEFT JOIN {node_comment_statistics} ncs ON (ncs.nid = n.nid)
WHERE (h.timestamp is null or h.timestamp < n.changed)
OR (h.timestamp IS NOT NULL AND ncs.last_comment_timestamp > h.timestamp)
EOF;
    db_query($sql, $user->uid, $user->uid);

As for the request for a confirmation & redirect. Well - the redirect was easily handled with a change to the drupal_goto function and the confirmation by a drupal_set_message call.

I added a link to the footer of our 'my unseen' view which asks for confirmation before marking nodes. Of course the input format has to be 'php' for this to work:

<?php

  $links['mark_all'] = array(
    'title' => t('Mark all content as read'),
    'href' => 'node/markasread',
    'attributes' => array('onclick' => "return confirm('". t('Are you sure you want to mark all content as read?') ."')")
  );

  print theme('links', $links);
?>