You are here

function oa_comment_preprocess_comment in OA Comment 7.2

Implements hook_preprocess_comment().

File

./oa_comment.theme.inc, line 147
Preprocess functions for comments.

Code

function oa_comment_preprocess_comment(&$vars) {

  // Include ctools files.
  ctools_include('modal');
  ctools_include('ajax');
  $comment = $vars['comment'];
  $vars['show_links'] = TRUE;

  // Convert thread to a human comment number
  // First, remove trailing slash.
  $thread = substr($comment->thread, 0, -1);
  $parts = explode('.', $thread);
  foreach ($parts as $key => &$part) {
    $parts[$key] = vancode2int($part);

    // First id starts at 1, but rest start at zero.
    if ($key > 0) {
      $parts[$key]++;
    }
  }
  $vars['thread'] = implode('.', $parts);

  // Add our template for individual comments.
  $vars['theme_hook_suggestions'][] = 'oa_comment__comment';

  // If we are using ajax don't display the action links.
  if (strpos($_GET['q'], 'ajax') > 0) {
    $vars['show_links'] = FALSE;
  }

  // Render the paragraph field if this comment contains one.
  if (!empty($vars['elements']['field_oa_related'])) {
    $vars['paragraphs'] = render($vars['elements']['field_oa_related']);
  }

  // Get the user picture.
  $user_details = oa_users_build_user_details(user_load($comment->uid), 'oa_medium_thumbnail');
  $vars['user_picture'] = $user_details['picture'];
  $vars['body'] = !empty($comment->comment_body[LANGUAGE_NONE][0]['safe_value']) ? oa_comment_filter_body($comment->comment_body[LANGUAGE_NONE][0]['safe_value']) : NULL;
  $vars['comment_link'] = l(t('#!comment_id', array(
    '!comment_id' => $vars['thread'],
  )), 'node/' . $vars['node']->nid, array(
    'attributes' => array(
      'class' => array(
        'oa-pullout-left',
      ),
      'title' => t('Copy this link to share.'),
    ),
    'fragment' => 'comment-' . $comment->cid,
  ));

  // Remove Reply link if comments are not threaded
  $threaded = variable_get('comment_default_mode_' . $vars['node']->type, COMMENT_MODE_THREADED);
  if (!$threaded) {
    unset($vars['content']['links']['comment']['#links']['comment-reply']);
  }

  // Action links for each comment.
  // @todo Figure out how do add delete confirm_form in modal.
  $links = array();
  foreach ($vars['content']['links']['comment']['#links'] as $key => $link) {
    if (in_array($key, array(
      'comment-edit',
      'comment-reply',
    ))) {

      // Convert these comment links to ajax callbacks
      $links[$key] = ctools_modal_text_button($link['title'], 'oa/nojs/' . $link['href'], $link['title']);
    }
    elseif (!isset($link['href'])) {
      $links[$key] = !empty($link['html']) ? $link['title'] : check_plain($link['title']);
    }
    else {
      $links[$key] = l($link['title'], $link['href'], $link);
    }
  }
  $vars['comment_links'] = $links;
}