You are here

function fblikebutton_node_view in Facebook Like Button 7

Same name and namespace in other branches
  1. 8 fblikebutton.module \fblikebutton_node_view()
  2. 7.2 fblikebutton.module \fblikebutton_node_view()

Implements of hook_node_view().

File

./fblikebutton.module, line 51
Adds Facebook's "Like" button to each selected node type. Adds a block with a global static value where users can "Like" the URL set by admins.

Code

function fblikebutton_node_view($node, $view_mode) {
  global $user, $base_url;
  $types = variable_get('fblikebutton_node_types', array());
  $showonteasers = variable_get('fblikebutton_showonteasers', 0);
  $full = $view_mode == 'full' ? TRUE : FALSE;
  $show = !empty($types[$node->type]) && user_access('access fblikebutton');

  // Thanks to corbacho for supplying the code for the $webpage_to_like variable...
  // (It was apparently throwing errors/notices the way I had it set up.)
  $webpage_to_like = url("node/{$node->nid}", array(
    'absolute' => TRUE,
  ));
  $likebutton_weight = variable_get('fblikebutton_weight', '0');
  $conf = array(
    'layout' => variable_get('fblikebutton_layout', 'standard'),
    'action' => variable_get('fblikebutton_action', 'like'),
    'color_scheme' => variable_get('fblikebutton_color_scheme', 'light'),
    'show_faces' => variable_get('fblikebutton_show_faces', 'true'),
    'font' => variable_get('fblikebutton_font', 'arial'),
    'height' => variable_get('fblikebutton_iframe_height', '80'),
    'width' => variable_get('fblikebutton_iframe_width', '450'),
    'send' => variable_get('fblikebutton_send', 'true'),
    'other_css' => variable_get('fblikebutton_iframe_css', ''),
    'language' => variable_get('fblikebutton_language', 'en_US'),
  );
  if ($show) {
    if ($showonteasers == 0) {
      if ($view_mode == 'teaser') {
        $node->content['fblikebutton_field'] = NULL;
      }
      if ($view_mode == 'full') {
        $node->content['fblikebutton_field'] = array(
          '#markup' => _fblikebutton_field($webpage_to_like, $conf),
          '#weight' => $likebutton_weight,
        );
      }
    }
    elseif ($showonteasers == 1) {
      if ($view_mode == 'teaser' || $view_mode == 'full') {
        $node->content['fblikebutton_field'] = array(
          '#markup' => _fblikebutton_field($webpage_to_like, $conf),
          '#weight' => $likebutton_weight,
        );
      }
    }
  }
}