Commit a4663548 authored by Dries's avatar Dries

- Patch #158536 by merlinofchaos and dvessel: tpl-ified the forum module.

parent 9339b704
<?php // $Id$
/**
* @file forum-display.tpl.php
* Default theme implementation to display a forum, which may contain forum
* containers as well as forum topics.
*
* Variables available:
*
* - $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
* to post.
* - $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)
*
* @see template_preprocess_forum_display()
* @see theme_forum_display()
*
*/
?>
<?php if ($forums_defined): ?>
<div id="forum">
<?php print theme('links', $links); ?>
<?php print $forums; ?>
<?php print $topics; ?>
</div>
<?php endif; ?>
<?php
// $Id$
/**
* @file forum-format-topic.tpl.php
* Default theme implementation to format a simple string indicated when and
* by whom a topic was posted.
*
* Available variables:
*
* - $author: The author of the post.
* - $time: How long ago the post was created.
* - $topic: An object with the raw data of the post. Unsafe, be sure
* to clean this data before printing.
*
* @see template_preprocess_forum_format_topic()
* @see theme_forum_format_topic()
*/
?>
<?php if ($topic->timestamp): ?>
<?php print t(
'@time ago<br />by !author', array(
'@time' => $time,
'!author' => $author,
)); ?>
<?php else: ?>
<?php print t('n/a'); ?>
<?php endif; ?>
<?php
// $Id$
/**
* @file forum-icon.tpl.php
* Display an appropriate icon for a forum post.
*
* Available variables:
* - $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'.
*
* @see template_preprocess_forum_icon()
* @see theme_forum_icon()
*/
?>
<?php if ($new_posts): ?>
<a name="new">
<?php endif; ?>
<?php print theme('image', "misc/forum-$icon.png") ?>
<?php if ($new_posts): ?>
</a>
<?php endif; ?>
<?php
// $Id
/**
* @file forum-list.tpl.php
* Default theme implementation to display a list of forums.
*
* Available variables:
* - $forums: An array of forums 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->name: The name of the forum.
* - $forum->link: The URL to link to this forum.
* - $forum->description: The description of this forum.
* - $forum->new_topics: True if the forum contains unread posts.
* - $forum->new_url: A URL to the forum's unread posts.
* - $forum->new_text: Text for the above URL which tells how many new posts.
* - $forum->old_topics: A count of posts that have already been read.
* - $forum->num_posts: The total number of posts in the forum.
* - $forum->last_reply: Text representing the last time a forum was posted or
* commented in.
*
* @see template_preprocess_forum_list()
* @see theme_forum_list()
*/
?>
<table>
<thead>
<tr>
<th><?php print t('Forum'); ?></th>
<th><?php print t('Topics');?></th>
<th><?php print t('Posts'); ?></th>
<th><?php print t('Last post'); ?></th>
</tr>
</thead>
<tbody>
<?php // Keep a row count for striping. ?>
<?php $row = 0; ?>
<?php foreach ($forums as $forum): ?>
<tr class="<?php print $row % 2 == 0 ? 'odd' : 'even';?>">
<?php if ($forum->is_container): ?>
<td colspan="4" class="container">
<?php else: ?>
<td class="forum">
<?php endif; ?>
<?php /* Enclose the contents of this cell with X divs, where X is the
* 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="description"><?php print $forum->description; ?></div>
<?php print $end_divs; ?>
</td>
<?php if (!$forum->is_container): ?>
<td class="topics">
<?php print $forum->num_topics ?>
<?php if ($forum->new_topics): ?>
<br />
<a href="<?php print $forum->new_url; ?>"><?php print $forum->new_text; ?></a>
<?php endif; ?>
</td>
<td class="posts"><?php print $forum->num_posts ?></td>
<td class="last-reply"><?php print $forum->last_reply ?></td>
<?php endif; ?>
</tr>
<?php $row++; ?>
<?php endforeach; ?>
</tbody>
</table>
<?php
// $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:
*
* - $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
* explanation and a link.
* - $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.
* - $topic->new_text: Text containing the translated, properly pluralized count.
* - $topic->created: An outputtable string represented when the topic was posted.
* - $topic->last_reply: An outputtable string representing when the topic was
* last replied to.
* - $topic->timestamp: The raw timestamp this topic was posted.
*
* @see template_preprocess_forum_topic_list()
* @see theme_forum_topic_list()
*/
?>
<table>
<thead>
<tr><?php print $header; ?></tr>
</thead>
<tbody>
<?php $row = 0; ?>
<?php foreach ($topics as $topic): ?>
<tr class="<?php print $row % 2 == 0 ? 'odd' : 'even';?>">
<td class="icon"><?php print $topic->icon; ?></td>
<td class="title"><?php print $topic->title; ?></td>
<?php if ($topic->moved): ?>
<td colspan="3"><?php print $topic->description; ?></td>
<?php else: ?>
<td class="replies">
<?php print $topic->num_comments; ?>
<?php if ($topic->new_replies): ?>
<br />
<a href="<?php print $topic->new_url; ?>"><?php print $topic->new_text; ?></a>
<?php endif; ?>
</td>
<td class="created"><?php print $topic->created; ?>
<td class="last-reply"><?php print $topic->last_reply; ?>
<?php endif; ?>
</tr>
<?php $row++; ?>
<?php endforeach; ?>
</tbody>
</table>
<?php print $pager; ?>
<?php
// $Id$
/**
* @file forum-topic-navigation.tpl.php
* Default theme implementation to display the topic navigation string at the
* bottom of all forum topics.
*
* Available variables:
*
* - $prev: The node ID of the previous post.
* - $prev_url: The URL of the previous post.
* - $prev_title: The title of the previous post.
*
* - $next: The node ID of the next post.
* - $next_url: The URL of the next post.
* - $next_title: The title of the next post.
*
* - $node: The raw node currently being viewed. Contains unsafe data
* and any data in this must be cleaned before presenting.
*
* @see template_preprocess_forum_topic_navigation()
* @see theme_forum_topic_navigation()
*/
?>
<?php if ($prev || $next): ?>
<div class="forum-topic-navigation clear-block">
<?php if ($prev): ?>
<a href="<?php print $prev_url; ?>" class="topic-previous" title="<?php print t('Go to previous forum topic') ?>"><?php print $prev_title ?></a>
<?php endif; ?>
<?php if ($next): ?>
<a href="<?php print $next_url; ?>" class="topic-next" title="<?php print t('Go to next forum topic') ?>"><?php print $next_title ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
......@@ -19,6 +19,10 @@
#forum tr.new-topics td.forum {
background-image: url(../../misc/forum-new.png);
}
#forum div.indent {
margin-left: 20px;
}
.forum-topic-navigation {
padding: 1em 0 0 3em; /* LTR */
border-top: 1px solid #888;
......
......@@ -34,20 +34,29 @@ function forum_help($path, $arg) {
function forum_theme() {
return array(
'forum_display' => array(
'file' => 'forum-display',
'arguments' => array('forums' => NULL, 'topics' => NULL, 'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),
),
'forum_list' => array(
'file' => 'forum-list',
'arguments' => array('forums' => NULL, 'parents' => NULL, 'tid' => NULL),
),
'forum_topic_list' => array(
'file' => 'forum-topic-list',
'arguments' => array('tid' => NULL, 'topics' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),
),
'forum_icon' => array(
'file' => 'forum-icon',
'arguments' => array('new_posts' => NULL, 'num_posts' => 0, 'comment_mode' => 0, 'sticky' => 0),
),
'forum_topic_navigation' => array(
'file' => 'forum-topic-navigation',
'arguments' => array('node' => NULL),
),
'forum_format_topic' => array(
'file' => 'forum-format-topic',
'arguments' => array('topic' => NULL),
),
);
}
......@@ -688,20 +697,6 @@ function forum_link_alter(&$links, $node) {
}
}
/**
* Formats a topic for display
*
* @TODO Give a better description. Not sure where this function is used yet.
*/
function _forum_format($topic) {
if ($topic && !empty($topic->timestamp)) {
return t('@time ago<br />by !author', array('@time' => format_interval(time() - $topic->timestamp), '!author' => theme('username', $topic)));
}
else {
return t('n/a');
}
}
/**
* Returns a list of all forums for a given taxonomy id
*
......@@ -868,11 +863,19 @@ function forum_page($tid = 0) {
}
/**
* Format the forum body.
* Process variables for forum-display.tpl.php
*
* The $variables array contains the following arguments:
* - $forums
* - $topics
* - $parents
* - $tid
* - $sortby
* - $forum_per_page
*
* @ingroup themeable
* @see forum-display.tpl.php
*/
function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_per_page) {
function template_preprocess_forum_display(&$variables) {
global $user;
// forum list, topics list, topic browser and 'add new topic' link
......@@ -882,14 +885,14 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p
// Breadcrumb navigation:
$breadcrumb = array();
if ($tid) {
if ($variables['tid']) {
$breadcrumb[] = array('path' => 'forum', 'title' => $title);
}
if ($parents) {
$parents = array_reverse($parents);
foreach ($parents as $p) {
if ($p->tid == $tid) {
if ($variables['parents']) {
$variables['parents'] = array_reverse($variables['parents']);
foreach ($variables['parents'] as $p) {
if ($p->tid == $variables['tid']) {
$title = $p->name;
}
else {
......@@ -903,235 +906,236 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p
$breadcrumb[] = array('path' => $_GET['q']);
menu_set_location($breadcrumb);
if (count($forums) || count($parents)) {
$output = '<div id="forum">';
$output .= '<ul>';
$variables['forums_defined'] = count($variables['forums']) || count($variables['parents']);
if ($variables['forums_defined']) {
// Format the "post new content" links listing.
$forum_types = array();
// Load the vocabulary.
$forum_vid = variable_get('forum_nav_vocabulary', '');
$vocabulary = taxonomy_vocabulary_load($forum_vid);
// Loop through all node types for forum vocabulary.
foreach ($vocabulary->nodes as $type) {
// Check if the current user has the 'create' permission for this node type.
if (node_access('create', $type)) {
// Fetch the "General" name of the content type;
// Push the link with title and url to the array.
$forum_types[$type] = array('title' => t('Post new @node_type', array('@node_type' => node_get_types('name', $type))), 'href' => "node/add/$type/$tid");
$forum_types[$type] = array('title' => t('Post new @node_type', array('@node_type' => node_get_types('name', $type))), 'href' => "node/add/$type/$variables[tid]");
}
}
if (!empty($forum_types)) {
// Theme links for the prepared content types data.
$output .= theme('links', $forum_types);
}
else {
$output .= '<li>'. t('<a href="@login">Login</a> to post a new forum topic.', array('@login' => url('user/login', array('query' => drupal_get_destination())))) .'</li>';
if (empty($forum_types)) {
// The user is logged-in; but denied access to create any new forum content type.
if ($user->uid) {
$output .= t('You are not allowed to post new content in forum.');
$forum_types['disallowed'] = array('title' => t('You are not allowed to post new content in forum.'));
}
// The user is not logged-in; and denied access to create any new forum content type.
else {
$output .= t('<a href="@login">Login</a> to post new content in forum.', array('@login' => url('user/login', array('query' => drupal_get_destination()))));
$forum_types['login'] = array('title' => t('<a href="@login">Login</a> to post new content in forum.', array('@login' => url('user/login', array('query' => drupal_get_destination())))), 'html' => TRUE);
}
}
$output .= '</ul>';
$variables['links'] = $forum_types;
$output .= theme('forum_list', $forums, $parents, $tid);
if (!empty($variables['forums'])) {
$variables['forums'] = theme('forum_list', $variables['forums'], $variables['parents'], $variables['tid']);
}
else {
$variables['forums'] = '';
}
if ($tid && !in_array($tid, variable_get('forum_containers', array()))) {
$output .= theme('forum_topic_list', $tid, $topics, $sortby, $forum_per_page);
drupal_add_feed(url('taxonomy/term/'. $tid .'/0/feed'), 'RSS - '. $title);
if ($variables['tid'] && !in_array($variables['tid'], variable_get('forum_containers', array()))) {
$variables['topics'] = theme('forum_topic_list', $variables['tid'], $variables['topics'], $variables['sortby'], $variables['forum_per_page']);
drupal_add_feed(url('taxonomy/term/'. $variables['tid'] .'/0/feed'), 'RSS - '. $title);
}
$output .= '</div>';
else {
$variables['topics'] = '';
}
// Provide separate template suggestions based on what's being output. Topic id is also accounted for.
// Check both variables to be safe.
if ($variables['forums'] && !$variables['topics']) {
$variables['template_files'][] = 'forum-display-container';
$variables['template_files'][] = 'forum-display-container-'. $variables['tid'];
}
else {
$variables['template_files'][] = 'forum-display-topics';
$variables['template_files'][] = 'forum-display-topics-'. $variables['tid'];
}
}
else {
drupal_set_title(t('No forums defined'));
$output = '';
}
return $output;
}
/**
* Format the forum listing.
* Process variables to format a forum listing.
*
* @ingroup themeable
* $variables contains the following information:
* - $forums
* - $parents
* - $tid
*
* @see forum-list.tpl.php
* @see theme_forum_list()
*/
function theme_forum_list($forums, $parents, $tid) {
function template_preprocess_forum_list(&$variables) {
global $user;
if ($forums) {
$header = array(t('Forum'), t('Topics'), t('Posts'), t('Last post'));
foreach ($forums as $forum) {
if (!empty($forum->container)) {
$description = '<div style="margin-left: '. ($forum->depth * 30) ."px;\">\n";
$description .= ' <div class="name">'. l($forum->name, "forum/$forum->tid") ."</div>\n";
if (!empty($forum->description)) {
$description .= ' <div class="description">'. filter_xss_admin($forum->description) ."</div>\n";
}
$description .= "</div>\n";
$rows[] = array(array('data' => $description, 'class' => 'container', 'colspan' => '4'));
}
else {
$new_topics = _forum_topics_unread($forum->tid, $user->uid);
$forum->old_topics = $forum->num_topics - $new_topics;
if (!$user->uid) {
$new_topics = 0;
}
$description = '<div style="margin-left: '. ($forum->depth * 30) ."px;\">\n";
$description .= ' <div class="name">'. l($forum->name, "forum/$forum->tid") ."</div>\n";
if (!empty($forum->description)) {
$description .= ' <div class="description">'. filter_xss_admin($forum->description) ."</div>\n";
}
$description .= "</div>\n";
$row = array(
'data' => array(
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'),
),
);
if ($new_topics > 0) {
$row['class'] = 'new-topics';
}
$rows[] = $row;
// 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);
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_url = url("forum/$forum->tid", array('fragment' => 'new'));
}
$variables['forums'][$id]->old_topics = $forum->num_topics - $variables['forums'][$id]->new_topics;
}
return theme('table', $header, $rows);
else {
$variables['forums'][$id]->new_topics = 0;
$variables['forums'][$id]->old_topics = $forum->num_topics;
}
$variables['forums'][$id]->last_reply = theme('forum_format_topic', $forum->last_post);
}
}
/**
* Format the topic listing.
* Preprocess variables to format the topic listing.
*
* $variables contains the following data:
* - $tid
* - $topics
* - $sortby
* - $forum_per_page
*
* @ingroup themeable
* @see forum-topic-list.tpl.php
* @see theme_forum_topic_list()
*/
function theme_forum_topic_list($tid, $topics, $sortby, $forum_per_page) {
function template_preprocess_forum_topic_list(&$variables) {
global $forum_topic_list_header;
$rows = array();
if ($topics) {
foreach ($topics as $topic) {
// folder is new if topic is new or there are new comments since last visit
if ($topic->tid != $tid) {
$rows[] = array(
array('data' => theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
array('data' => check_plain($topic->title), 'class' => 'title'),
array('data' => l(t('This topic has been moved'), "forum/$topic->tid"), 'colspan' => '3')
);
// Create the tablesorting header.
$ts = tablesort_init($forum_topic_list_header);
$header = '';
foreach ($forum_topic_list_header as $cell) {
$cell = tablesort_header($cell, $forum_topic_list_header, $ts);
$header .= _theme_table_cell($cell, TRUE);
}
$variables['header'] = $header;
$rows = array();
if (!empty($variables['topics'])) {
foreach ($variables['topics'] as $id => $topic) {
$variables['topics'][$id]->icon = theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky);
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 {
$rows[] = array(
array('data' => theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
array('data' => l($topic->title, "node/$topic->nid"), 'class' => 'topic'),
array('data' => $topic->num_comments . ($topic->new_replies ? '<br />'. l(format_plural($topic->new_replies, '1 new', '@count new'), "node/$topic->nid", array('fragment' => 'new')) : ''), 'class' => 'replies'),
array('data' => _forum_format($topic), 'class' => 'created'),
array('data' => _forum_format(isset($topic->last_reply) ? $topic->last_reply : NULL), 'class' => 'last-reply')
);
$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_format_topic', $topic);