summaryrefslogtreecommitdiff
path: root/modules/forum.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/forum.module')
-rw-r--r--modules/forum.module26
1 files changed, 10 insertions, 16 deletions
diff --git a/modules/forum.module b/modules/forum.module
index 99c17849d..1909a6e93 100644
--- a/modules/forum.module
+++ b/modules/forum.module
@@ -703,18 +703,14 @@ function forum_get_forums($tid = 0) {
return $forums;
}
-function _forum_topics_read($term, $uid) {
- // Calculate the number of topics the user has read. Assume all entries older
- // than NODE_NEW_LIMIT are read, and include the recent posts that user has
- // read.
- $sql = "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.created <= %d AND n.status = 1 AND n.type = 'forum'";
- $sql = db_rewrite_sql($sql);
- $ancient = db_result(db_query($sql, $term, NODE_NEW_LIMIT));
- $sql = "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {history} h ON n.nid = h.nid AND h.uid = %d INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 AND n.type = 'forum' AND n.created > %d";
+/**
+ * Calculate the number of nodes the user has not yet read and are newer
+ * than NODE_NEW_LIMIT.
+ */
+function _forum_topics_unread($term, $uid) {
+ $sql = 'SELECT COUNT(n.nid) FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid AND tn.tid = %d 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';
$sql = db_rewrite_sql($sql);
- $recent = db_result(db_query($sql, $uid, $term, NODE_NEW_LIMIT));
-
- return $ancient + $recent;
+ return db_result(db_query($sql, $term, $uid, NODE_NEW_LIMIT));
}
function forum_get_topics($tid, $sortby, $forum_per_page) {
@@ -915,11 +911,9 @@ function theme_forum_list($forums, $parents, $tid) {
$rows[] = array(array('data' => $description, 'class' => 'container', 'colspan' => '4'));
}
else {
- $forum->old_topics = _forum_topics_read($forum->tid, $user->uid);
- if ($user->uid) {
- $new_topics = $forum->num_topics - $forum->old_topics;
- }
- else {
+ $new_topics = _forum_topics_unread($forum->tid, $user->uid);
+ $forum->old_topics = $forum->num_topics - $new_topics;
+ if (!$user->uid) {
$new_topics = 0;
}