You are here

function facebook_comments_node_view in Facebook Comments Social Plugin 7

Implements hook_node_view().

File

./facebook_comments.module, line 387
Facebook Comments Social Plugin module file.

Code

function facebook_comments_node_view($node, $view_mode, $langcode) {

  // Check if the node is published.
  if (!variable_get('facebook_comments_status', 0) && !$node->status) {
    return;
  }

  // Check the view mode to display the comments or not.
  $fc_viewmode = variable_get('facebook_comments_viewmode', 'full');
  if ($fc_viewmode != "both" && $view_mode != $fc_viewmode) {
    return;
  }

  // Check if Facebook comments are enabled for this node.
  $comments = db_select('facebook_comments', 'f')
    ->fields('f', array(
    'enabled',
    'amount',
  ))
    ->condition('f.nid', $node->nid, '=')
    ->execute()
    ->fetchObject();
  if (!isset($comments->enabled) || !$comments->enabled) {
    return;
  }

  // Add the Facebook App ID if it exists.
  $width = variable_get('facebook_comments_width', 620);
  $fluid = variable_get('facebook_comments_width_fluid', 1);
  $fragment = variable_get('facebook_comments_views', 0) ? $node->nid : 0;
  $output = facebook_comments_display('node', $width, $comments->amount, $fluid, $fragment);
  $node->content['facebook_comments'] = array(
    '#markup' => $output,
    '#weight' => 1002,
  );
}