- Patch #160589 by dvessel: tpl-ify the comment module's theme functions.

6.x
Dries Buytaert 2007-07-20 08:51:13 +00:00
parent 1cd02d7ec1
commit 7d0cf742f7
7 changed files with 131 additions and 32 deletions

View File

@ -0,0 +1,20 @@
<?php
// $Id
/**
* @file comment-folded.tpl.php
* Default theme implementation for folded comments.
*
* Available variables:
* - $title: Linked title to full comment.
* - $new: New comment marker.
* - $author: Comment author. Can be link or plain text.
* - $date: Date and time of posting.
* - $comment: Full comment object.
*
* @see template_preprocess_comment_folded()
* @see theme_comment_folded()
*/
?>
<div class="comment-folded">
<span class="subject"><?php print $title .' '. $new; ?></span><span class="credit"><?php print t('by') .' '. $author; ?></span>
</div>

View File

@ -0,0 +1,35 @@
<?php
// $Id
/**
* @file comment-wrapper.tpl.php
* Default theme implementation to wrap comments.
*
* Available variables:
* - $content: All comments for a given page. Also contains sorting controls
* and comment forms if the site is configured for it.
*
* The following variables are provided for contextual information.
* - $node: Node object the comments are attached to.
* The constants below the variables show the possible values and should be
* used for comparison.
* - $display_mode
* - COMMENT_MODE_FLAT_COLLAPSED
* - COMMENT_MODE_FLAT_EXPANDED
* - COMMENT_MODE_THREADED_COLLAPSED
* - COMMENT_MODE_THREADED_EXPANDED
* - $display_order
* - COMMENT_ORDER_NEWEST_FIRST
* - COMMENT_ORDER_OLDEST_FIRST
* - $comment_controls_state
* - COMMENT_CONTROLS_ABOVE
* - COMMENT_CONTROLS_BELOW
* - COMMENT_CONTROLS_ABOVE_BELOW
* - COMMENT_CONTROLS_HIDDEN
*
* @see template_preprocess_comment_wrapper()
* @see theme_comment_wrapper()
*/
?>
<div id="comments">
<?php print $content; ?>
</div>

View File

@ -160,10 +160,11 @@ function comment_theme() {
'arguments' => array('form' => NULL),
),
'comment' => array(
'arguments' => array('comment' => NULL, 'node' => NULL, 'links' => array()),
'file' => 'comment.tpl.php',
'arguments' => array('comment' => NULL, 'node' => NULL, 'links' => array()),
),
'comment_folded' => array(
'file' => 'comment-folded',
'arguments' => array('comment' => NULL),
),
'comment_flat_collapsed' => array(
@ -182,7 +183,8 @@ function comment_theme() {
'arguments' => array('nid' => NULL),
),
'comment_wrapper' => array(
'arguments' => array('content' => NULL),
'file' => 'comment-wrapper',
'arguments' => array('content' => NULL, 'node' => NULL),
),
'comment_submitted' => array(
'arguments' => array('comment' => NULL),
@ -1077,7 +1079,7 @@ function comment_render($node, $cid = 0) {
$output .= comment_form_box(array('nid' => $nid), t('Post new comment'));
}
$output = theme('comment_wrapper', $output);
$output = theme('comment_wrapper', $output, $node);
}
return $output;
@ -1776,7 +1778,7 @@ function comment_controls($mode = COMMENT_MODE_THREADED_EXPANDED, $order = COMME
}
function theme_comment_controls($form) {
$output .= '<div class="container-inline">';
$output = '<div class="container-inline">';
$output .= drupal_render($form);
$output .= '</div>';
$output .= '<div class="description">'. t('Select your preferred way to display the comments and click "Save settings" to activate your changes.') .'</div>';
@ -1801,13 +1803,20 @@ function comment_controls_submit($form, &$form_state) {
}
/**
* Prepare values for comment.tpl.php
* Process variables for comment.tpl.php.
*
* The $variables array contains the following arguments:
* - $comment
* - $node
* - $links
*
* @see comment.tpl.php
* @see theme_comment()
*/
function template_preprocess_comment(&$variables) {
$comment = $variables['comment'];
$node = $variables['node'];
$variables['author'] = theme('username', $comment);
$variables['comment'] = $comment;
$variables['content'] = $comment->comment;
$variables['date'] = format_date($comment->timestamp);
$variables['links'] = isset($variables['links']) ? theme('links', $variables['links']) : '';
@ -1819,12 +1828,21 @@ function template_preprocess_comment(&$variables) {
$variables['template_files'][] = 'comment-'. $node->type;
}
function theme_comment_folded($comment) {
$output = "<div class=\"comment-folded\">\n";
$output .= ' <span class="subject">'. l($comment->subject, comment_node_url() .'/'. $comment->cid, array('fragment' => "comment-$comment->cid")) .' '. theme('mark', $comment->new) .'</span> ';
$output .= '<span class="credit">'. t('by') .' '. theme('username', $comment) ."</span>\n";
$output .= "</div>\n";
return $output;
/**
* Process variables for comment-folded.tpl.php.
*
* The $variables array contains the following arguments:
* - $comment
*
* @see comment-folded.tpl.php
* @see theme_comment_folded()
*/
function template_preprocess_comment_folded(&$variables) {
$comment = $variables['comment'];
$variables['author'] = theme('username', $comment);
$variables['date'] = format_date($comment->timestamp);
$variables['new'] = $comment->new ? t('new') : '';
$variables['title'] = l($comment->subject, comment_node_url() .'/'. $comment->cid, array('fragment' => "comment-$comment->cid"));
}
function theme_comment_flat_collapsed($comment, $node) {
@ -1836,14 +1854,11 @@ function theme_comment_flat_expanded($comment, $node) {
}
function theme_comment_thread_collapsed($comment, $node) {
$output .= theme('comment_view', $comment, $node, '', 0);
return $output;
return theme('comment_view', $comment, $node, '', 0);
}
function theme_comment_thread_expanded($comment, $node) {
$output = '';
$output .= theme('comment_view', $comment, $node, module_invoke_all('link', 'comment', $comment, 0));
return $output;
return theme('comment_view', $comment, $node, module_invoke_all('link', 'comment', $comment, 0));
}
function theme_comment_post_forbidden($nid) {
@ -1870,10 +1885,21 @@ function theme_comment_post_forbidden($nid) {
}
/**
* Allow themeable wrapping of all comments.
* Process variables for comment-wrapper.tpl.php.
*
* The $variables array contains the following arguments:
* - $content
* - $node
*
* @see comment-wrapper.tpl.php
* @see theme_comment_wrapper()
*/
function theme_comment_wrapper($content) {
return '<div id="comments">'. $content .'</div>';
function template_preprocess_comment_wrapper(&$variables) {
// Provide contextual information.
$variables['display_mode'] = _comment_get_display_setting('mode');
$variables['display_order'] = _comment_get_display_setting('sort');
$variables['comment_controls_state'] = variable_get('comment_controls', COMMENT_CONTROLS_HIDDEN);
$variables['template_files'][] = 'comment-wrapper-'. $variables['node']->type;
}
/**

View File

@ -1,10 +1,34 @@
<?php
// $Id
/**
* @file comment.tpl.php
* Default theme implementation for comments.
*
* Available variables:
* - $author: Comment author. Can be link or plain text.
* - $content: Body of the post.
* - $date: Date and time of posting.
* - $links: Various operational links.
* - $new: New comment marker.
* - $picture: Authors picture.
* - $signature: Authors signature.
* - $submitted: By line with date and time.
* - $title: Linked title.
*
* These two variables are provided for context.
* - $comment: Full comment object.
* - $node: Node object the comments are attached to.
*
* @see template_preprocess_comment()
* @see theme_comment()
*/
?>
<div class="comment<?php print ($comment->new) ? ' comment-new' : ''; print ($comment->status == COMMENT_NOT_PUBLISHED) ? ' comment-unpublished' : ''; ?> clear-block">
<?php print $picture ?>
<?php if ($comment->new) : ?>
<a id="new"></a>
<span class="new"><?php print $new ?></span>
<?php endif; ?>
<?php if ($comment->new): ?>
<span class="new"><?php print $new ?></span>
<?php endif; ?>
<h3><?php print $title ?></h3>

View File

@ -6,7 +6,6 @@
<?php endif; ?>
<?php if ($comment->new) : ?>
<a id="new"></a>
<span class="new"><?php print drupal_ucfirst($new) ?></span>
<?php endif; ?>

View File

@ -1,5 +1,3 @@
<?php phptemplate_comment_wrapper(NULL, $node->type); ?>
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
<?php print $picture ?>

View File

@ -40,11 +40,8 @@ function phptemplate_breadcrumb($breadcrumb) {
/**
* Allow themable wrapping of all comments.
*/
function phptemplate_comment_wrapper($content, $type = null) {
static $node_type;
if (isset($type)) $node_type = $type;
if (!$content || $node_type == 'forum') {
function phptemplate_comment_wrapper($content, $node) {
if (!$content || $node->type == 'forum') {
return '<div id="comments">'. $content .'</div>';
}
else {