You are here

function advanced_forum_markasread in Advanced Forum 5

Same name and namespace in other branches
  1. 6.2 includes/mark-read.inc \advanced_forum_markasread()
  2. 6 advanced_forum.module \advanced_forum_markasread()
  3. 7.2 includes/mark-read.inc \advanced_forum_markasread()

Marks all posts in forums or in a given forum as read by the current user.

1 string reference to 'advanced_forum_markasread'
advanced_forum_menu in ./advanced_forum.module
Implementation of hook_menu().

File

./advanced_forum.module, line 1041
Enables the look and feel of other popular forum software.

Code

function advanced_forum_markasread() {
  global $user;

  // See if we're on a forum or on the forum overview
  // Path will be /forum/markasread or /forum/markasread/tid
  $current_forum_id = arg(2);
  if ($current_forum_id) {

    // Delete the current history entries so already visited nodes get updated.
    $sql = "DELETE h\n            FROM {history} AS h\n              INNER JOIN {term_node} AS tn ON (h.nid = tn.nid)\n            WHERE h.uid = %d AND tn.tid = %d";
    db_query($sql, $user->uid, $current_forum_id);

    // Update the history table with all forum nodes newer than the cutoff.
    $sql = "INSERT INTO {history} (uid, nid, timestamp)\n            SELECT DISTINCT %d, n.nid, %d\n            FROM {node} AS n\n              INNER JOIN {term_node} AS tn ON n.nid = tn.nid\n              INNER JOIN {node_comment_statistics} AS ncs ON ncs.nid = n.nid\n            WHERE (n.changed > %d OR ncs.last_comment_timestamp > %d) AND tn.tid = %d";
    $args = array(
      $user->uid,
      time(),
      NODE_NEW_LIMIT,
      NODE_NEW_LIMIT,
      $current_forum_id,
    );
    db_query($sql, $args);

    // Readpath integration
    if (module_exists('readpath')) {
      readpath_clear_readpath();
    }
    drupal_set_message(t('All content in this forum has been marked as read'));
    drupal_goto('forum/' . $current_forum_id);
  }
  else {

    // We are on the forum overview, requesting all forums be marked read
    $forum_vocabulary_id = variable_get('forum_nav_vocabulary', '');

    // Delete the current history entries so already visited nodes get updated.
    $sql = "DELETE h\n            FROM {history} AS h\n              INNER JOIN {term_node} AS tn ON (h.nid = tn.nid)\n              INNER JOIN {term_data} AS td ON (td.tid = tn.tid)\n            WHERE h.uid = %d AND td.vid = %d";
    db_query($sql, $user->uid, $forum_vocabulary_id);

    // Update the history table with all forum nodes newer than the cutoff.
    $sql = "INSERT INTO {history} (uid, nid, timestamp)\n            SELECT DISTINCT %d, n.nid, %d\n            FROM {node} AS n\n              INNER JOIN {term_node} AS tn ON n.nid=tn.nid\n              INNER JOIN {node_comment_statistics} AS ncs ON ncs.nid = n.nid\n              INNER JOIN {term_data} AS td ON tn.tid = td.tid\n            WHERE (n.changed > %d OR ncs.last_comment_timestamp > %d) AND td.vid = %d";
    $args = array(
      $user->uid,
      time(),
      NODE_NEW_LIMIT,
      NODE_NEW_LIMIT,
      $forum_vocabulary_id,
    );
    db_query($sql, $args);

    // Readpath integration
    if (module_exists('readpath')) {
      readpath_clear_readpath();
    }
    drupal_set_message(t('All forum content been marked as read'));
    drupal_goto('forum');
  }
}