Mark As Read module

sites/all/modules/markasread/markasread.info

; $Id$
name = Mark Forums As Read
description = Provides a way to clear the new flag for all topics in a forum or all topics on the site
core = 6.x

 


sites/all/modules/markasread/markasread.module

<?php
  
// $Id$

  /**
   * Implementation of hook_menu()
   */
  
function markasread_menu() {
    
$items = array();
    
$items['forum/markasread'] = array(
      
'page callback' => 'markasread_doit',
      
'access arguments' => array('access content'),
      
'type' => MENU_CALLBACK
    
);
    return 
$items;
  }

  
/**
   * Function that does all the work - marking content as read
   */
  
function markasread_doit() {
    
$goto 'forum';
    global 
$user;
    if (
$user && $user->uid) {
      if (isset(
$_POST['tid'])) {
        
$tid $_POST['tid'];
        
settype($tid'integer');
        if (
$tid <= 0$tid null;
      }
      else 
$tid null;
      if (isset(
$_POST['uid'])) {
        
$uid $_POST['uid'];
        
settype($uid'integer');
        if (
$uid 0$uid null;
      }
      else 
$uid null;

      
$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'. ($uid ' INNER JOIN {node_revisions} v ON n.nid=v.nid' '') .' WHERE (n.created > %d OR l.last_comment_timestamp > %d)';
      
$args = array($user->uidtime(), NODE_NEW_LIMITNODE_NEW_LIMIT);

      if (
$tid) {
        
$sql .= ' AND r.tid = %d';
        
$args[] = $tid;
      }

      if (
$uid) {
        
$sql .= ' AND v.uid = %d';
        
$args[] = $uid;
      }

      if (isset(
$_POST['type'])) {
        
$type $_POST['type'];
        
$sql .= ' AND n.type = \'%s\'';
        
$args[] = $type;
      }
      else 
$type null;

      
db_query($sql$args);

      if (
$type == 'forum') {
        if (
$tid) {
          
drupal_set_message(t('All topics in forum marked as read'));
          
$goto 'forum/'$tid;
        }
        else {
          
drupal_set_message(t('All forum posts have been marked as read'));
          
$goto 'forum';
        }
      }
      else if (!
$type) {
        if (
$uid && $tracker_user=user_load($uid)) {
          
drupal_set_message(t('All content by %user has been marked as read', array('%user' => $tracker_user->name)));
        } else {
          
drupal_set_message(t('All content has been marked as read'));
          
$goto 'tracker';
        }
      }
    }

    if (isset(
$_POST["goto"])) $goto $_POST["goto"];

    
drupal_goto($goto);
  }

   
/**
    * Helper function that generates a form with a button to mark
    * certain nodes as read for all forum pages.
    */
    
function markasread_generate_button($label$tid=null$uid=null$type=null) {
    global 
$user;
    if (
$user->uid) {
      
$markbutton '<form method="post" action="'url('forum/markasread') .'">';
      if (
$type !== null$markbutton .= '<input type="hidden" name="type" value="'check_plain($type) .'" />';
      if (
$tid !== null$markbutton .= '<input type="hidden" name="tid" value="'check_plain($tid) .'" />';
      if (
$uid !== null$markbutton .= '<input type="hidden" name="uid" value="'check_plain($uid) .'" />';
      
$markbutton .= '<input type="hidden" name="goto" value="'ltrim(request_uri(), '/') .'" /><input type="submit" value="'check_plain($label) .'" /></form>';
      return 
$markbutton;
    }
  }

  
/**
   * Place button on forum display.
   */
  
function markasread_preprocess_forums(&$variables) {
    
$variables['topics'] .= markasread_generate_button($variables['tid'] ? t('Mark all topics read') : t('Mark all forums read'), $variables['tid'], null'forum');
  }

 


themes/garland/page-tracker.tpl.php (put in active theme\'s folder)

<?php
  $tracker_uid 
null;
  foreach (
$template_files as $template_file) {
    if (
substr($template_file013) == 'page-tracker-' && is_numeric(substr($template_file13))) {
      
$tracker_uid = (int) substr($template_file13);
      if (
$tracker_uid <= 0$tracker_uid null;
    }
  }
  if (
function_exists('markasread_generate_button') && $tracker_uid$content .= markasread_generate_button(t("Mark all user's content read"), null$tracker_uid);
  if (
function_exists('markasread_generate_button') && !$tracker_uid$content .= markasread_generate_button(t("Mark all content read"));
  unset(
$template_file);
  unset(
$tracker_uid);
  include(
'page.tpl.php');

 


themes/garland/page-user-track.tpl.php (put in active theme\'s folder)

<?php
  $tracker_uid 
null;
  foreach (
$template_files as $template_file) {
    if (
substr($template_file013) == 'page-tracker-' && is_numeric(substr($template_file13))) {
      
$tracker_uid = (int) substr($template_file13);
      if (
$tracker_uid <= 0$tracker_uid null;
    }
  }
  if (
function_exists('markasread_generate_button') && $tracker_uid$content .= markasread_generate_button(t("Mark all user's content read"), null$tracker_uid);
  if (
function_exists('markasread_generate_button') && !$tracker_uid$content .= markasread_generate_button(t("Mark all content read"));
  unset(
$template_file);
  unset(
$tracker_uid);
  include(
'page.tpl.php');