From c0c4aeeb6611088b63d91e55b53d1ed02a2df0ca Mon Sep 17 00:00:00 2001
From: Angie Byron <webchick@24967.no-reply.drupal.org>
Date: Mon, 22 Nov 2010 08:07:57 +0000
Subject: [PATCH] #405238 by brianV: Fixed Duplicate ID 'new' in forums breaks
 XHTML validation

---
 modules/forum/forum-icon.tpl.php |  8 +++-----
 modules/forum/forum.module       | 13 +++++++++++--
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/modules/forum/forum-icon.tpl.php b/modules/forum/forum-icon.tpl.php
index 4a43dd2ce67c..2b2cf3c109b7 100644
--- a/modules/forum/forum-icon.tpl.php
+++ b/modules/forum/forum-icon.tpl.php
@@ -9,19 +9,17 @@
  * - $new_posts: Indicates whether or not the topic contains new posts.
  * - $icon: The icon to display. May be one of 'hot', 'hot-new', 'new',
  *   'default', 'closed', or 'sticky'.
+ * - $first_new: Indicates whether this is the first topic with new posts.
  *
  * @see template_preprocess_forum_icon()
  * @see theme_forum_icon()
  */
 ?>
 <div class="topic-status-<?php print $icon_class ?>" title="<?php print $icon_title ?>">
-<?php if ($new_posts): ?>
-  <a id="new">
+<?php if ($first_new): ?>
+  <a id="new"></a>
 <?php endif; ?>
 
   <span class="element-invisible"><?php print $icon_title ?></span>
 
-<?php if ($new_posts): ?>
-  </a>
-<?php endif; ?>
 </div>
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 20622a3bef4f..10076a9cd710 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -71,7 +71,7 @@ function forum_theme() {
     ),
     'forum_icon' => array(
       'template' => 'forum-icon',
-      'variables' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0),
+      'variables' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0, 'first_new' => FALSE),
     ),
     'forum_submitted' => array(
       'template' => 'forum-submitted',
@@ -902,6 +902,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
   }
 
   $topics = array();
+  $first_new_found = FALSE;
   foreach ($result as $topic) {
     if ($user->uid) {
       // folder is new if topic is new or there are new comments since last visit
@@ -920,6 +921,13 @@ function forum_get_topics($tid, $sortby, $forum_per_page) {
       $topic->new = 0;
     }
 
+    // Make sure only one topic is indicated as the first new topic.
+    $topic->first_new = FALSE;
+    if ($topic->new != 0 && !$first_new_found) {
+      $topic->first_new = TRUE;
+      $first_new_found = TRUE;
+    }
+
     if ($topic->comment_count > 0) {
       $last_reply = new stdClass();
       $last_reply->created = $topic->last_comment_timestamp;
@@ -1081,7 +1089,7 @@ function template_preprocess_forum_topic_list(&$variables) {
   if (!empty($variables['topics'])) {
     $row = 0;
     foreach ($variables['topics'] as $id => $topic) {
-      $variables['topics'][$id]->icon = theme('forum_icon', array('new_posts' => $topic->new, 'num_posts' => $topic->comment_count, 'comment_mode' => $topic->comment_mode, 'sticky' => $topic->sticky));
+      $variables['topics'][$id]->icon = theme('forum_icon', array('new_posts' => $topic->new, 'num_posts' => $topic->comment_count, 'comment_mode' => $topic->comment_mode, 'sticky' => $topic->sticky, 'first_new' => $topic->first_new));
       $variables['topics'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even';
       $row++;
 
@@ -1130,6 +1138,7 @@ function template_preprocess_forum_topic_list(&$variables) {
  * - $num_posts = 0
  * - $comment_mode = 0
  * - $sticky = 0
+ * - $first_new
  *
  * @see forum-icon.tpl.php
  * @see theme_forum_icon()
-- 
GitLab