You are here

function likebtn_entity_view in Like Button 8.2

Same name and namespace in other branches
  1. 7 likebtn.module \likebtn_entity_view()

Implements hook_entity_view().

File

./likebtn.module, line 270
Implements the LikeBtn module.

Code

function likebtn_entity_view($entity, $type, $view_mode, $langcode) {
  if (!in_array($type, array(
    'node',
    'comment',
  ))) {
    return;
  }

  // Check if module is enabled for the current entity view mode.
  if (!in_array($view_mode, variable_get('likebtn_view_modes', array()), TRUE)) {
    return;
  }

  // Check user authorization.
  $user_logged_in = variable_get('likebtn_user_logged_in', 'all');
  if ($user_logged_in != 'all') {
    if ($user_logged_in == 'logged_in' && !user_is_logged_in()) {
      return;
    }
    if ($user_logged_in == 'not_logged_in' && user_is_logged_in()) {
      return;
    }
  }
  if ($type == 'comment') {
    $comment_node = node_load($entity->nid);

    // Check if LikeBtn is enabled for comments to the current node type.
    if (!in_array($comment_node->type, variable_get('likebtn_comments_nodetypes', array()), TRUE)) {
      return;
    }
    $entity_id = $entity->cid;
  }
  else {

    // Check if LikeBtn is enabled for the current node type.
    if (!in_array($entity->type, variable_get('likebtn_nodetypes', array()), TRUE)) {
      return;
    }
    $entity_id = $entity->nid;
  }
  $entity->content['likebtn_display'] = array(
    '#markup' => _likebtn_get_markup($type, $entity_id),
    '#weight' => variable_get('likebtn_weight'),
  );
}