You are here

function theme_heartbeat_comment in Heartbeat 7

Same name and namespace in other branches
  1. 6.4 modules/heartbeat_comments/heartbeat_comments.module \theme_heartbeat_comment()

Theme function for heartbeat comment

Parameters

$comment Object comment with user in it:

$type Boolean to indicate whether it is a node comment or not:

$last Boolean to indicate if an extra class has to be used:

Return value

String Themed output for a comment

2 theme calls to theme_heartbeat_comment()
heartbeat_comments_form_submit in modules/heartbeat_comments/heartbeat_comments.module
User submitted a heartbeat comment.
theme_heartbeat_comments in modules/heartbeat_comments/heartbeat_comments.module
Theme function for heartbeat comments

File

modules/heartbeat_comments/heartbeat_comments.module, line 690
Heartbeat comments for activity.

Code

function theme_heartbeat_comment($variables) {
  $comment = $variables['comment'];
  $node_comment = $variables['node_comment'];
  $last = $variables['last'];
  $account = user_load($comment->uid);
  $realname = format_username($account);
  $output = '';
  if ($last == TRUE) {
    $class = "heartbeat-comment-last";
  }
  else {
    $class = "";
  }
  $output .= '<li class="heartbeat-comment ' . $class . ' clearfix" id="heartbeat-comment-' . ($node_comment ? $comment->cid : $comment->hcid) . '">';

  // Avatar.
  $filepath = NULL;
  if ($comment->picture) {
    if (is_numeric($comment->picture)) {
      $comment->picture = file_load($comment->picture);
    }
    $filepath = $comment->picture->uri;
  }
  elseif (variable_get('user_picture_default', '')) {
    $filepath = variable_get('user_picture_default', '');
  }
  if ($filepath) {
    $alt = t("@user's picture", array(
      '@user' => $realname,
    ));
    if (module_exists('image') && file_valid_uri($filepath)) {
      $avatar = theme('image_style', array(
        'alt' => $alt,
        'title' => $alt,
        'style_name' => 'comment_avatar',
        'path' => $filepath,
        'attributes' => array(
          'class' => 'avatar',
        ),
      ));
    }
    else {
      $avatar = theme('image', array(
        'alt' => $alt,
        'title' => $alt,
        'path' => $filepath,
        'attributes' => array(
          'class' => 'avatar',
        ),
      ));
    }
    $output .= '<span class="avatar">' . $avatar . '</span>';
  }
  $output .= '<div class="heartbeat-teaser">';
  $output .= l($realname, 'user/' . $comment->uid) . ' ';

  // The actual comment.
  $filter = new stdClass();
  $filter->settings = array(
    'filter_url_length' => 72,
  );
  $output .= _filter_url($comment->comment, $filter);
  $output .= '<span class="heartbeat-time-ago clearfix">' . _theme_time_ago($comment->changed) . '</span>';

  // For node comments link to the standard Drupal comment deletion form under comment/delete/%
  // Only users who have the right permissions should see the delete link.
  // Permissions are provided by the "Comment Delete" module.
  global $user;
  if ($node_comment) {
    if (user_access('delete any comment') || $user->uid == $comment->uid && user_access('delete own comments')) {
      ctools_include('ajax');
      ctools_include('modal');
      drupal_add_library('system', 'drupal.ajax');
      $output .= l(t('Delete'), 'heartbeat/nojs/comment/delete/' . $comment->cid . '/' . $comment->uaid . '/node', array(
        'query' => array(
          'destination' => $_GET['q'],
        ),
        'html' => TRUE,
        'attributes' => array(
          'class' => array(
            'use-ajax',
            'ctools-modal-ctools-heartbeat-style heartbeat-comment-delete',
          ),
          'title' => t('Delete'),
        ),
      ));

      //$output .= ctools_modal_text_button(t('Delete'), 'heartbeat/nojs/comment/delete/' . $comment->cid . '/' . $comment->uaid . '/node', t('Delete'),  'ctools-modal-ctools-heartbeat-style heartbeat-comment-delete');
    }
  }
  elseif (user_access('administer heartbeat comments') || $comment->uid && $user->uid && $comment->uid == $user->uid) {
    ctools_include('ajax');
    ctools_include('modal');
    drupal_add_library('system', 'drupal.ajax');
    $text = t('Delete');
    $dest = 'heartbeat/nojs/comment/delete/' . $comment->hcid . '/' . $comment->uaid;
    $class = 'ctools-modal-ctools-heartbeat-style heartbeat-comment-delete';
    $output .= l($text, $dest, array(
      'html' => TRUE,
      'query' => array(
        'destination' => $_GET['q'],
      ),
      'attributes' => array(
        'class' => array(
          'use-ajax',
          $class,
        ),
        'title' => $text,
      ),
    ));

    //$output .= ctools_modal_text_button($text, $dest, $text,  $class);
  }
  $output .= '</div>';
  $output .= '</li>';
  return $output;
}