| 1 |
<?php
|
| 2 |
// $Id: forum_mark_read.module,v 1.2 2006/10/31 22:04:12 sanduhrs Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Allow users to mark all new forum nodes as read.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_help().
|
| 11 |
*/
|
| 12 |
function forum_mark_read_help($section) {
|
| 13 |
switch ($section) {
|
| 14 |
case 'admin/help#forum_mark_read':
|
| 15 |
return t('Allow users to mark all new forum nodes as read.');
|
| 16 |
case 'admin/modules#description':
|
| 17 |
return t('Allow users to mark all new forum nodes as read.');
|
| 18 |
}
|
| 19 |
}
|
| 20 |
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Implementation of hook_menu().
|
| 24 |
*/
|
| 25 |
function forum_mark_read_menu($may_cache) {
|
| 26 |
$items = array();
|
| 27 |
$tid = is_numeric(arg(1)) ? arg(1) : 0;
|
| 28 |
|
| 29 |
if ($may_cache) {
|
| 30 |
} else {
|
| 31 |
$items[] = array('path' => 'forum/'.$tid.'/markasread',
|
| 32 |
'title' => t('mark all topics read'),
|
| 33 |
'callback' => '_forum_mark_read_mark',
|
| 34 |
'access' => user_access('access content'),
|
| 35 |
'type' => MENU_NORMAL_ITEM,
|
| 36 |
'callback arguments' => array($tid),
|
| 37 |
);
|
| 38 |
}
|
| 39 |
|
| 40 |
return $items;
|
| 41 |
}
|
| 42 |
|
| 43 |
function _forum_mark_read_mark($tid = '') {
|
| 44 |
global $user;
|
| 45 |
|
| 46 |
if ($tid == 0) {
|
| 47 |
// Select all new forum nodes and nodes with new comments
|
| 48 |
$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')";
|
| 49 |
|
| 50 |
$result = db_query($sql, $user->uid, NODE_NEW_LIMIT, COMMENT_PUBLISHED);
|
| 51 |
while ($node = db_fetch_object($result)) {
|
| 52 |
// Mark the node as read
|
| 53 |
node_tag_new($node->nid);
|
| 54 |
}
|
| 55 |
|
| 56 |
// Tell the user what we did
|
| 57 |
drupal_set_message(t('All new nodes in all forums were marked as read.'));
|
| 58 |
|
| 59 |
// Redirect to where we came from
|
| 60 |
drupal_goto('forum');
|
| 61 |
|
| 62 |
} else if (is_numeric($tid)) {
|
| 63 |
// Select all new forum nodes and nodes with new comments from term $tid
|
| 64 |
$sql = "SELECT DISTINCT(n.nid) FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid AND tn.tid = %d 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')";
|
| 65 |
|
| 66 |
$result = db_query($sql, $tid, $user->uid, NODE_NEW_LIMIT, COMMENT_PUBLISHED);
|
| 67 |
while ($node = db_fetch_object($result)) {
|
| 68 |
node_tag_new($node->nid);
|
| 69 |
}
|
| 70 |
|
| 71 |
// Tell the user what we did
|
| 72 |
drupal_set_message(t('All new nodes in this forum were marked as read.'));
|
| 73 |
|
| 74 |
// Redirect to where we came from
|
| 75 |
drupal_goto('forum/'.$tid);
|
| 76 |
}
|
| 77 |
}
|