Preprocesses variables for comment.tpl.php.
function template_preprocess_comment(&$variables) {
$comment = $variables['elements']['#comment'];
$node = $variables['elements']['#node'];
$variables['comment'] = $comment;
$variables['node'] = $node;
$variables['author'] = theme('username', array(
'account' => $comment,
));
$variables['created'] = format_date($comment->created);
$variables['changed'] = format_date($comment->changed);
$variables['new'] = !empty($comment->new) ? t('new') : '';
if (theme_get_setting('toggle_comment_user_picture')) {
// To change user picture settings (e.g., image style), edit the 'compact'
// view mode on the User entity.
$variables['user_picture'] = user_view($comment->account, 'compact');
}
else {
$variables['user_picture'] = array();
}
$variables['signature'] = $comment->signature;
$uri = $comment
->uri();
$uri['options'] += array(
'attributes' => array(
'class' => 'permalink',
'rel' => 'bookmark',
),
);
$variables['title'] = l($comment->subject, $uri['path'], $uri['options']);
$variables['permalink'] = l(t('Permalink'), $uri['path'], $uri['options']);
$variables['submitted'] = t('Submitted by !username on !datetime', array(
'!username' => $variables['author'],
'!datetime' => $variables['created'],
));
if ($comment->pid > 0) {
// Fetch and store the parent comment information for use in templates.
$comment_parent = comment_load($comment->pid);
$variables['parent_comment'] = $comment_parent;
$variables['parent_author'] = theme('username', array(
'account' => $comment_parent,
));
$variables['parent_created'] = format_date($comment_parent->created);
$variables['parent_changed'] = format_date($comment_parent->changed);
$uri_parent = $comment_parent
->uri();
$uri_parent['options'] += array(
'attributes' => array(
'class' => 'permalink',
'rel' => 'bookmark',
),
);
$variables['parent_title'] = l($comment_parent->subject, $uri_parent['path'], $uri_parent['options']);
$variables['parent_permalink'] = l(t('Parent permalink'), $uri_parent['path'], $uri_parent['options']);
$variables['parent'] = t('In reply to !parent_title by !parent_username', array(
'!parent_username' => $variables['parent_author'],
'!parent_title' => $variables['parent_title'],
));
}
else {
$variables['parent_comment'] = '';
$variables['parent_author'] = '';
$variables['parent_created'] = '';
$variables['parent_changed'] = '';
$variables['parent_title'] = '';
$variables['parent_permalink'] = '';
$variables['parent'] = '';
}
// Preprocess fields.
field_attach_preprocess('comment', $comment, $variables['elements'], $variables);
// Helpful $content variable for templates.
foreach (element_children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
// Set status to a string representation of comment->status.
if (isset($comment->in_preview)) {
$variables['status'] = 'preview';
}
else {
$variables['status'] = $comment->status == COMMENT_NOT_PUBLISHED ? 'unpublished' : 'published';
}
// Gather comment classes.
// 'published' class is not needed, it is either 'preview' or 'unpublished'.
if ($variables['status'] != 'published') {
$variables['attributes']['class'][] = $variables['status'];
}
if ($variables['new']) {
$variables['attributes']['class'][] = 'new';
}
if (!$comment->uid) {
$variables['attributes']['class'][] = 'by-anonymous';
}
else {
if ($comment->uid == $variables['node']->uid) {
$variables['attributes']['class'][] = 'by-node-author';
}
if ($comment->uid == $variables['user']->uid) {
$variables['attributes']['class'][] = 'by-viewer';
}
}
}