Index: modules/forum/forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v
retrieving revision 1.400
diff -u -p -r1.400 forum.module
--- modules/forum/forum.module	30 May 2007 08:04:38 -0000	1.400
+++ modules/forum/forum.module	1 Jun 2007 14:12:39 -0000
@@ -734,9 +734,27 @@ function _forum_get_vid() {
  *
  * @TODO Give a better description. Not sure where this function is used yet.
  */
-function _forum_format($topic) {
+function _forum_format($topic, $show_title = FALSE) {
   if ($topic && !empty($topic->timestamp)) {
-    return t('@time ago<br />by !author', array('@time' => format_interval(time() - $topic->timestamp), '!author' => theme('username', $topic)));
+    if (!$show_title) {
+      return t('@time ago<br />by !author', array('@time' => format_interval(time() - $topic->timestamp), '!author' => theme('username', $topic)));
+    }
+    else {
+      // Fetch the ID of last posted comment.
+      $comment_id = db_result(db_query('SELECT MAX(cid) FROM {comments} WHERE nid = %d AND status = %d', $topic->nid, COMMENT_PUBLISHED));
+
+      $query = array();
+      $comments_per_page = _comment_get_display_setting('comments_per_page');
+      $comments_sort_order = _comment_get_display_setting('sort');
+
+      if ($comments_sort_order == COMMENT_ORDER_OLDEST_FIRST) {
+        $query = array('page' => round($comments_per_page / $topic->comment_count));
+      }
+
+      $fragment = 'comment-'. $comment_id;
+
+      return t('!title<br />@time ago<br />by !author', array('!title' => l(truncate_utf8($topic->title, 25, TRUE, TRUE), "node/$topic->nid", array('query' => $query, 'fragment' => $fragment)), '@time' => format_interval(time() - $topic->timestamp), '!author' => theme('username', $topic)));
+    }
   }
   else {
     return t('n/a');
@@ -790,7 +808,7 @@ function forum_get_forums($tid = 0) {
     // This query does not use full ANSI syntax since MySQL 3.x does not support
     // table1 INNER JOIN table2 INNER JOIN table3 ON table2_criteria ON table3_criteria
     // used to join node_comment_statistics to users.
-    $sql = "SELECT ncs.last_comment_timestamp, IF (ncs.last_comment_uid != 0, u2.name, ncs.last_comment_name) AS last_comment_name, ncs.last_comment_uid FROM {node} n INNER JOIN {users} u1 ON n.uid = u1.uid INNER JOIN {term_node} tn ON n.nid = tn.nid INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {users} u2 ON ncs.last_comment_uid=u2.uid WHERE n.status = 1 AND n.type='forum' AND tn.tid = %d ORDER BY ncs.last_comment_timestamp DESC";
+    $sql = "SELECT ncs.last_comment_timestamp, IF (ncs.last_comment_uid != 0, u2.name, ncs.last_comment_name) AS last_comment_name, ncs.last_comment_uid, ncs.comment_count, n.nid, n.title FROM {node} n INNER JOIN {users} u1 ON n.uid = u1.uid INNER JOIN {term_node} tn ON n.nid = tn.nid INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {users} u2 ON ncs.last_comment_uid=u2.uid WHERE n.status = 1 AND n.type='forum' AND tn.tid = %d ORDER BY ncs.last_comment_timestamp DESC";
     $sql = db_rewrite_sql($sql);
     $topic = db_fetch_object(db_query_range($sql, $forum->tid, 0, 1));
 
@@ -799,6 +817,9 @@ function forum_get_forums($tid = 0) {
       $last_post->timestamp = $topic->last_comment_timestamp;
       $last_post->name = $topic->last_comment_name;
       $last_post->uid = $topic->last_comment_uid;
+      $last_post->comment_count = $topic->comment_count;
+      $last_post->nid = $topic->nid;
+      $last_post->title = $topic->title;
     }
     $forum->last_post = $last_post;
 
@@ -1017,7 +1038,7 @@ function theme_forum_list($forums, $pare
             array('data' => $description, 'class' => 'forum'),
             array('data' => $forum->num_topics . ($new_topics ? '<br />'. l(format_plural($new_topics, '1 new', '@count new'), "forum/$forum->tid", array('fragment' => 'new')) : ''), 'class' => 'topics'),
             array('data' => $forum->num_posts, 'class' => 'posts'),
-            array('data' => _forum_format($forum->last_post), 'class' => 'last-reply'),
+            array('data' => _forum_format($forum->last_post, TRUE), 'class' => 'last-reply'),
           ),
         );
         if ($new_topics > 0) {
