Commit 3488a1ed authored by Dries's avatar Dries
Browse files

- Patch #158536 by dvessel: more forum template massaging.

parent f1d2f5a1
...@@ -2,15 +2,16 @@ ...@@ -2,15 +2,16 @@
// $Id // $Id
/** /**
* @file forum-list.tpl.php * @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: * Available variables:
* - $forums: An array of forums to display. * - $forums: An array of forums and containers to display.
* *
* Each $forum in $forums contains: * Each $forum in $forums contains:
* - $forum->is_container: Is TRUE if the forum can contain other forums. Is * - $forum->is_container: Is TRUE if the forum can contain other forums. Is
* FALSE if the forum can contain only topics. * FALSE if the forum can contain only topics.
* - $forum->depth: How deep the forum is in the current hierarchy. * - $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->name: The name of the forum.
* - $forum->link: The URL to link to this forum. * - $forum->link: The URL to link to this forum.
* - $forum->description: The description of this forum. * - $forum->description: The description of this forum.
...@@ -36,28 +37,20 @@ ...@@ -36,28 +37,20 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php // Keep a row count for striping. ?>
<?php $row = 0; ?>
<?php foreach ($forums as $forum): ?> <?php foreach ($forums as $forum): ?>
<tr class="<?php print $row % 2 == 0 ? 'odd' : 'even';?>"> <tr class="<?php print $forum->zebra; ?>">
<?php if ($forum->is_container): ?> <td <?php print $forum->is_container ? 'colspan="4" class="container"' : 'class="forum"'; ?>>
<td colspan="4" class="container"> <?php /* Enclose the contents of this cell with X divs, where X is the
<?php else: ?> * depth this forum resides at. This will allow us to use CSS
<td class="forum"> * left-margin for indenting.
<?php endif; ?> */ ?>
<?php /* Enclose the contents of this cell with X divs, where X is the <?php print str_repeat('<div class="indent">', $forum->depth); ?>
* depth this forum resides at. This will allow us to use CSS
* left-margin for indenting.
*/ ?>
<?php $end_divs = ''; ?>
<?php for ($i = 0; $i < $forum->depth; $i++): ?>
<div class="indent">
<?php $end_divs .= '</div>'; ?>
<?php endfor; ?>
<div class="name"><a href="<?php print $forum->link; ?>"><?php print $forum->name; ?></a></div> <div class="name"><a href="<?php print $forum->link; ?>"><?php print $forum->name; ?></a></div>
<div class="description"><?php print $forum->description; ?></div> <?php if ($forum->description): ?>
<?php print $end_divs; ?> <div class="description"><?php print $forum->description; ?></div>
</td> <?php endif; ?>
<?php print str_repeat('</div>', $forum->depth); ?>
</td>
<?php if (!$forum->is_container): ?> <?php if (!$forum->is_container): ?>
<td class="topics"> <td class="topics">
<?php print $forum->num_topics ?> <?php print $forum->num_topics ?>
...@@ -70,8 +63,6 @@ ...@@ -70,8 +63,6 @@
<td class="last-reply"><?php print $forum->last_reply ?></td> <td class="last-reply"><?php print $forum->last_reply ?></td>
<?php endif; ?> <?php endif; ?>
</tr> </tr>
<?php $row++; ?>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
...@@ -2,24 +2,22 @@ ...@@ -2,24 +2,22 @@
// $Id$ // $Id$
/** /**
* @file forum-topic-list.tpl.php * @file forum-topic-list.tpl.php
*
* Theme implementation to display a list of forum topics. * Theme implementation to display a list of forum topics.
* *
* Available variables: * Available variables:
*
* - $header: The table header. This is pre-generated with click-sorting * - $header: The table header. This is pre-generated with click-sorting
* information. If you need to change this, @see template_preprocess_forum_topic_list(). * information. If you need to change this, @see template_preprocess_forum_topic_list().
* - $pager: The pager to display beneath the table. * - $pager: The pager to display beneath the table.
* - $topics: An array of topics to be displayed. * - $topics: An array of topics to be displayed.
* *
* Each topic contains: * Each $topic in $topics contains:
*
* - $topic->icon: The icon to display. * - $topic->icon: The icon to display.
* - $topic->moved: A flag to indicate whether the topic has been moved to * - $topic->moved: A flag to indicate whether the topic has been moved to
* another forum. * another forum.
* - $topic->title: The title of the topic. Safe to output. * - $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. * 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->num_comments: The number of replies on this topic.
* - $topic->new_replies: A flag to indicate whether there are unread comments. * - $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. * - $topic->new_url: If there are unread replies, this is a link to them.
...@@ -38,13 +36,12 @@ ...@@ -38,13 +36,12 @@
<tr><?php print $header; ?></tr> <tr><?php print $header; ?></tr>
</thead> </thead>
<tbody> <tbody>
<?php $row = 0; ?>
<?php foreach ($topics as $topic): ?> <?php foreach ($topics as $topic): ?>
<tr class="<?php print $row % 2 == 0 ? 'odd' : 'even';?>"> <tr class="<?php print $topic->zebra;?>">
<td class="icon"><?php print $topic->icon; ?></td> <td class="icon"><?php print $topic->icon; ?></td>
<td class="title"><?php print $topic->title; ?></td> <td class="title"><?php print $topic->title; ?></td>
<?php if ($topic->moved): ?> <?php if ($topic->moved): ?>
<td colspan="3"><?php print $topic->description; ?></td> <td colspan="3"><?php print $topic->message; ?></td>
<?php else: ?> <?php else: ?>
<td class="replies"> <td class="replies">
<?php print $topic->num_comments; ?> <?php print $topic->num_comments; ?>
...@@ -57,7 +54,6 @@ ...@@ -57,7 +54,6 @@
<td class="last-reply"><?php print $topic->last_reply; ?> <td class="last-reply"><?php print $topic->last_reply; ?>
<?php endif; ?> <?php endif; ?>
</tr> </tr>
<?php $row++; ?>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
......
...@@ -601,7 +601,6 @@ function _forum_new($tid) { ...@@ -601,7 +601,6 @@ function _forum_new($tid) {
*/ */
function template_preprocess_forums(&$variables) { function template_preprocess_forums(&$variables) {
global $user; global $user;
// forum list, topics list, topic browser and 'add new topic' link
$vid = variable_get('forum_nav_vocabulary', ''); $vid = variable_get('forum_nav_vocabulary', '');
$vocabulary = taxonomy_vocabulary_load($vid); $vocabulary = taxonomy_vocabulary_load($vid);
...@@ -630,8 +629,7 @@ function template_preprocess_forums(&$variables) { ...@@ -630,8 +629,7 @@ function template_preprocess_forums(&$variables) {
$breadcrumb[] = array('path' => $_GET['q']); $breadcrumb[] = array('path' => $_GET['q']);
menu_set_location($breadcrumb); menu_set_location($breadcrumb);
$variables['forums_defined'] = count($variables['forums']) || count($variables['parents']); if ($variables['forums_defined'] = count($variables['forums']) || count($variables['parents'])) {
if ($variables['forums_defined']) {
// Format the "post new content" links listing. // Format the "post new content" links listing.
$forum_types = array(); $forum_types = array();
...@@ -673,19 +671,27 @@ function template_preprocess_forums(&$variables) { ...@@ -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. // 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']) { if ($variables['forums'] && !$variables['topics']) {
$variables['template_files'][] = 'forums-containers'; $variables['template_files'][] = 'forums-containers';
$variables['template_files'][] = 'forums-'. $variables['tid'];
$variables['template_files'][] = 'forums-containers-'. $variables['tid']; $variables['template_files'][] = 'forums-containers-'. $variables['tid'];
} }
else { elseif (!$variables['forums'] && $variables['topics']) {
$variables['template_files'][] = 'forums-topics'; $variables['template_files'][] = 'forums-topics';
$variables['template_files'][] = 'forums-'. $variables['tid'];
$variables['template_files'][] = 'forums-topics-'. $variables['tid']; $variables['template_files'][] = 'forums-topics-'. $variables['tid'];
} }
else {
$variables['template_files'][] = 'forums-'. $variables['tid'];
}
} }
else { else {
drupal_set_title(t('No forums defined')); drupal_set_title(t('No forums defined'));
$variables['links'] = array();
$variables['forums'] = '';
$variables['topics'] = '';
} }
} }
...@@ -702,24 +708,28 @@ function template_preprocess_forums(&$variables) { ...@@ -702,24 +708,28 @@ function template_preprocess_forums(&$variables) {
*/ */
function template_preprocess_forum_list(&$variables) { function template_preprocess_forum_list(&$variables) {
global $user; global $user;
$row = 0;
// Sanitize each forum so that the template can safely print the data. // Sanitize each forum so that the template can safely print the data.
foreach ($variables['forums'] as $id => $forum) { foreach ($variables['forums'] as $id => $forum) {
$variables['forums'][$id]->description = !empty($forum->description) ? filter_xss_admin($forum->description) : ''; $variables['forums'][$id]->description = !empty($forum->description) ? filter_xss_admin($forum->description) : '';
$variables['forums'][$id]->link = url("forum/$forum->tid"); $variables['forums'][$id]->link = url("forum/$forum->tid");
$variables['forums'][$id]->name = check_plain($forum->name); $variables['forums'][$id]->name = check_plain($forum->name);
$variables['forums'][$id]->is_container = !empty($forum->container); $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) { if ($user->uid) {
$variables['forums'][$id]->new_topics = _forum_topics_unread($forum->tid, $user->uid); $variables['forums'][$id]->new_topics = _forum_topics_unread($forum->tid, $user->uid);
if ($variables['forums'][$id]->new_topics) { 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]->new_url = url("forum/$forum->tid", array('fragment' => 'new'));
} }
$variables['forums'][$id]->old_topics = $forum->num_topics - $variables['forums'][$id]->new_topics; $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); $variables['forums'][$id]->last_reply = theme('forum_submitted', $forum->last_post);
} }
} }
...@@ -748,25 +758,30 @@ function template_preprocess_forum_topic_list(&$variables) { ...@@ -748,25 +758,30 @@ function template_preprocess_forum_topic_list(&$variables) {
} }
$variables['header'] = $header; $variables['header'] = $header;
$rows = array();
if (!empty($variables['topics'])) { if (!empty($variables['topics'])) {
$row = 0;
foreach ($variables['topics'] as $id => $topic) { 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]->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']) { if ($topic->tid != $variables['tid']) {
$variables['topics'][$id]->moved = TRUE; $variables['topics'][$id]->moved = TRUE;
$variables['topics'][$id]->title = check_plain($topic->title); $variables['topics'][$id]->title = check_plain($topic->title);
$variables['topics'][$id]->description = l(t('This topic has been moved'), "forum/$topic->tid"); $variables['topics'][$id]->message = 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);
} }
} }
} }
......
<?php // $Id$ <?php // $Id$
/** /**
* @file forums.tpl.php * @file forums.tpl.php
* Default theme implementation to display a forum, which may contain forum * Default theme implementation to display a forum which may contain forum
* containers as well as forum topics. * containers as well as forum topics.
* *
* Variables available: * Variables available:
*
* - $links: An array of links that allow a user to post new forum topics. * - $links: An array of links that allow a user to post new forum topics.
* It may also contain a string telling a user they must log in in order * It may also contain a string telling a user they must log in in order
* to post. * to post.
* - $forums: The forums to display (as processed by forum-list.tpl.php) * - $forums: The forums to display (as processed by forum-list.tpl.php)
* - $topics: The topics to display (as processed by forum-topic-list.tpl.php) * - $topics: The topics to display (as processed by forum-topic-list.tpl.php)
* - $forums_defined: A flag to indicate that the forums are configured.
* *
* @see template_preprocess_forums() * @see template_preprocess_forums()
* @see theme_forums() * @see theme_forums()
*
*/ */
?> ?>
<?php if ($forums_defined): ?> <?php if ($forums_defined): ?>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment