From 3488a1ed443c92f918e6153c27fd6d6cf3ab287d Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 3 Aug 2007 06:07:52 +0000 Subject: - Patch #158536 by dvessel: more forum template massaging. --- modules/forum/forum-list.tpl.php | 39 +++++++++------------- modules/forum/forum-topic-list.tpl.php | 14 +++----- modules/forum/forum.module | 59 +++++++++++++++++++++------------- modules/forum/forums.tpl.php | 5 ++- 4 files changed, 59 insertions(+), 58 deletions(-) diff --git a/modules/forum/forum-list.tpl.php b/modules/forum/forum-list.tpl.php index 70cf597a2..27419f838 100644 --- a/modules/forum/forum-list.tpl.php +++ b/modules/forum/forum-list.tpl.php @@ -2,15 +2,16 @@ // $Id /** * @file forum-list.tpl.php - * Default theme implementation to display a list of forums. + * Default theme implementation to display a list of forums and containers. * * Available variables: - * - $forums: An array of forums to display. + * - $forums: An array of forums and containers to display. * * Each $forum in $forums contains: * - $forum->is_container: Is TRUE if the forum can contain other forums. Is * FALSE if the forum can contain only topics. * - $forum->depth: How deep the forum is in the current hierarchy. + * - $forum->zebra: 'even' or 'odd' string used for row class. * - $forum->name: The name of the forum. * - $forum->link: The URL to link to this forum. * - $forum->description: The description of this forum. @@ -36,28 +37,20 @@ - - - - is_container): ?> - - - - - - - depth; $i++): ?> -
- '; ?> - + + is_container ? 'colspan="4" class="container"' : 'class="forum"'; ?>> + + ', $forum->depth); ?> -
description; ?>
- - + description): ?> +
description; ?>
+ + ', $forum->depth); ?> + is_container): ?> num_topics ?> @@ -70,8 +63,6 @@ last_reply ?> - - diff --git a/modules/forum/forum-topic-list.tpl.php b/modules/forum/forum-topic-list.tpl.php index 9da332d10..4b2aa48fc 100644 --- a/modules/forum/forum-topic-list.tpl.php +++ b/modules/forum/forum-topic-list.tpl.php @@ -2,24 +2,22 @@ // $Id$ /** * @file forum-topic-list.tpl.php - * * Theme implementation to display a list of forum topics. * * Available variables: - * * - $header: The table header. This is pre-generated with click-sorting * information. If you need to change this, @see template_preprocess_forum_topic_list(). * - $pager: The pager to display beneath the table. * - $topics: An array of topics to be displayed. * - * Each topic contains: - * + * Each $topic in $topics contains: * - $topic->icon: The icon to display. * - $topic->moved: A flag to indicate whether the topic has been moved to * another forum. * - $topic->title: The title of the topic. Safe to output. - * - $topic->description: If the topic has been moved, this contains an + * - $topic->message: If the topic has been moved, this contains an * explanation and a link. + * - $topic->zebra: 'even' or 'odd' string used for row class. * - $topic->num_comments: The number of replies on this topic. * - $topic->new_replies: A flag to indicate whether there are unread comments. * - $topic->new_url: If there are unread replies, this is a link to them. @@ -38,13 +36,12 @@ - - + icon; ?> title; ?> moved): ?> - description; ?> + message; ?> num_comments; ?> @@ -57,7 +54,6 @@ last_reply; ?> - diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 0f306e104..96b5c42ab 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -601,7 +601,6 @@ function _forum_new($tid) { */ function template_preprocess_forums(&$variables) { global $user; - // forum list, topics list, topic browser and 'add new topic' link $vid = variable_get('forum_nav_vocabulary', ''); $vocabulary = taxonomy_vocabulary_load($vid); @@ -630,8 +629,7 @@ function template_preprocess_forums(&$variables) { $breadcrumb[] = array('path' => $_GET['q']); menu_set_location($breadcrumb); - $variables['forums_defined'] = count($variables['forums']) || count($variables['parents']); - if ($variables['forums_defined']) { + if ($variables['forums_defined'] = count($variables['forums']) || count($variables['parents'])) { // Format the "post new content" links listing. $forum_types = array(); @@ -673,19 +671,27 @@ function template_preprocess_forums(&$variables) { } // Provide separate template suggestions based on what's being output. Topic id is also accounted for. - // Check both variables to be safe. + // Check both variables to be safe then the inverse. Forums with topic ID's take precedence. if ($variables['forums'] && !$variables['topics']) { $variables['template_files'][] = 'forums-containers'; + $variables['template_files'][] = 'forums-'. $variables['tid']; $variables['template_files'][] = 'forums-containers-'. $variables['tid']; } - else { + elseif (!$variables['forums'] && $variables['topics']) { $variables['template_files'][] = 'forums-topics'; + $variables['template_files'][] = 'forums-'. $variables['tid']; $variables['template_files'][] = 'forums-topics-'. $variables['tid']; } + else { + $variables['template_files'][] = 'forums-'. $variables['tid']; + } } else { drupal_set_title(t('No forums defined')); + $variables['links'] = array(); + $variables['forums'] = ''; + $variables['topics'] = ''; } } @@ -702,24 +708,28 @@ function template_preprocess_forums(&$variables) { */ function template_preprocess_forum_list(&$variables) { global $user; + $row = 0; // Sanitize each forum so that the template can safely print the data. foreach ($variables['forums'] as $id => $forum) { $variables['forums'][$id]->description = !empty($forum->description) ? filter_xss_admin($forum->description) : ''; $variables['forums'][$id]->link = url("forum/$forum->tid"); $variables['forums'][$id]->name = check_plain($forum->name); $variables['forums'][$id]->is_container = !empty($forum->container); + $variables['forums'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even'; + $row++; + + $variables['forums'][$id]->new_text = ''; + $variables['forums'][$id]->new_url = ''; + $variables['forums'][$id]->new_topics = 0; + $variables['forums'][$id]->old_topics = $forum->num_topics; if ($user->uid) { $variables['forums'][$id]->new_topics = _forum_topics_unread($forum->tid, $user->uid); if ($variables['forums'][$id]->new_topics) { - $variables['forums'][$id]->new_text = format_plural($variables['forums'][$id]->new_topics, '1 new', '@count new'); + $variables['forums'][$id]->new_text = t('!count new', array('!count' => $variables['forums'][$id]->new_topics)); $variables['forums'][$id]->new_url = url("forum/$forum->tid", array('fragment' => 'new')); } $variables['forums'][$id]->old_topics = $forum->num_topics - $variables['forums'][$id]->new_topics; } - else { - $variables['forums'][$id]->new_topics = 0; - $variables['forums'][$id]->old_topics = $forum->num_topics; - } $variables['forums'][$id]->last_reply = theme('forum_submitted', $forum->last_post); } } @@ -748,25 +758,30 @@ function template_preprocess_forum_topic_list(&$variables) { } $variables['header'] = $header; - $rows = array(); if (!empty($variables['topics'])) { + $row = 0; foreach ($variables['topics'] as $id => $topic) { $variables['topics'][$id]->icon = theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky); + $variables['topics'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even'; + $row++; + + $variables['topics'][$id]->title = l($topic->title, "node/$topic->nid"); + $variables['topics'][$id]->created = theme('forum_submitted', $topic); + $variables['topics'][$id]->last_reply = theme('forum_submitted', isset($topic->last_reply) ? $topic->last_reply : NULL); + + $variables['topics'][$id]->new_text = ''; + $variables['topics'][$id]->new_url = ''; + if ($topic->new_replies) { + $variables['topics'][$id]->new_text = t('!count new', array('!count' => $variables['forums'][$id]->new_topics)); + $variables['topics'][$id]->new_url = url("node/$topic->nid", array('fragment' => 'new')); + } + $variables['topics'][$id]->moved = FALSE; + $variables['topics'][$id]->message = ''; if ($topic->tid != $variables['tid']) { $variables['topics'][$id]->moved = TRUE; $variables['topics'][$id]->title = check_plain($topic->title); - $variables['topics'][$id]->description = l(t('This topic has been moved'), "forum/$topic->tid"); - } - else { - $variables['topics'][$id]->moved = FALSE; - $variables['topics'][$id]->title = l($topic->title, "node/$topic->nid"); - if ($topic->new_replies) { - $variables['topics'][$id]->new_text = format_plural($topic->new_replies, '1 new', '@count new'); - $variables['topics'][$id]->new_url = url("node/$topic->nid", array('fragment' => 'new')); - } - $variables['topics'][$id]->created = theme('forum_submitted', $topic); - $variables['topics'][$id]->last_reply = theme('forum_submitted', $topic->last_reply); + $variables['topics'][$id]->message = l(t('This topic has been moved'), "forum/$topic->tid"); } } } diff --git a/modules/forum/forums.tpl.php b/modules/forum/forums.tpl.php index 0b8e1dfb6..28917ba4f 100644 --- a/modules/forum/forums.tpl.php +++ b/modules/forum/forums.tpl.php @@ -1,20 +1,19 @@ -- cgit v1.2.3