function commons_roots_preprocess_comment in Drupal Commons 6.2
Comment preprocessing
File
- themes/
commons_roots/ template.php, line 90
Code
function commons_roots_preprocess_comment(&$vars) {
global $user;
static $comment_odd = TRUE;
// Comment is odd or even
// Build array of handy comment classes
$comment_classes = array();
$comment_classes[] = $comment_odd ? 'odd' : 'even';
$comment_odd = !$comment_odd;
$comment_classes[] = $vars['comment']->status == COMMENT_NOT_PUBLISHED ? 'comment-unpublished' : '';
// Comment is unpublished
$comment_classes[] = $vars['comment']->new ? 'comment-new' : '';
// Comment is new
$comment_classes[] = $vars['comment']->uid == 0 ? 'comment-by-anon' : '';
// Comment is by anonymous user
$comment_classes[] = $user->uid && $vars['comment']->uid == $user->uid ? 'comment-mine' : '';
// Comment is by current user
$node = node_load($vars['comment']->nid);
// Comment is by node author
$vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
$comment_classes[] = $vars['author_comment'] ? 'comment-by-author' : '';
$comment_classes = array_filter($comment_classes);
// Remove empty elements
$vars['comment_classes'] = implode(' ', $comment_classes);
// Create class list separated by spaces
// Date & author
$ago = t('!interval ago', array(
'!interval' => format_interval(time() - $vars['comment']->timestamp),
));
$submitted_by = '<span class="comment-name">' . theme('username', $vars['comment']) . '</span>';
$submitted_by .= '<span class="comment-date">' . $ago . '</span>';
// Format date as small, medium, or large
$vars['submitted'] = $submitted_by;
// Picture
if (theme_get_setting('toggle_comment_user_picture')) {
if (!$vars['comment']->picture && variable_get('user_picture_default', '') != '') {
$vars['comment']->picture = variable_get('user_picture_default', '');
}
if ($vars['comment']->picture) {
$picture = theme_imagecache('user_picture_meta', $vars['comment']->picture, $vars['comment']->name, $vars['comment']->name);
if (user_access('access user profiles')) {
$vars['comment']->picture = l($picture, "user/{$vars['comment']->uid}", array(
'html' => TRUE,
));
}
else {
$vars['comment']->picture = $picture;
}
}
}
else {
unset($vars['comment']);
}
}