You are here

function talk_node_view in Talk 7

Implements hook_node_view().

File

./talk.module, line 183
Comments are displayed in a separate 'talk' tab, for node types you wish

Code

function talk_node_view($node, $view_mode, $langcode) {
  global $conf;
  $clone = clone $node;
  $clone->comment = _talk_node_comment_value($clone);
  $recover = FALSE;
  if (array_key_exists('comment_form_location_' . $node->type, $conf)) {
    $original_setting = $conf['comment_form_location_' . $node->type];
    $recover = TRUE;
  }
  $conf['comment_form_location_' . $node->type] = COMMENT_FORM_SEPARATE_PAGE;
  comment_node_view($clone, $view_mode, $langcode);
  if ($recover) {
    $conf['comment_form_location_' . $node->type] = $original_setting;
  }
  else {
    unset($conf['comment_form_location_' . $node->type]);
  }

  // Display comment summary
  $addcmnt = _talk_node_comment_value($node) == COMMENT_NODE_OPEN && ($view_mode != "teaser" || variable_get('talk_addcmnt_teaser', TRUE));
  if ($addcmnt) {
    $links = $clone->content['links']['comment']['#links'];
    $node->content['links']['comment'] = array(
      '#theme' => 'links__node__comment__talk',
      '#attributes' => array(
        'class' => array(
          'links',
          'inline',
        ),
      ),
    );
    foreach ($links as $link) {
      if (talk_activated($node->type)) {
        if (isset($link['href']) && $link['href'] == 'node/' . $node->nid) {
          $link['href'] .= '/talk';
        }
      }
      $node->content['links']['comment']['#links'][] = $link;
    }
  }

  // Add the Talk link if user has access and it's not blank
  if (_talk_access($node) && strlen(variable_get('talk_link', '')) > 0) {
    $node->content['links']['comment']['#links'][] = array(
      'href' => 'node/' . $node->nid . '/talk',
      'title' => talk_title($node, 'link'),
    );
  }

  // Remove comments from page if viewing a node page for a node type for which
  // Talk is enabled.
  if (talk_activated($node->type) && arg(0) == 'node' && !arg(2)) {
    $node->content['comments'] = array();
  }
}