You are here

function facebookshare_nodeapi in Facebook Share 6.3

Same name and namespace in other branches
  1. 6 facebookshare.module \facebookshare_nodeapi()

Implements hook_nodeapi()

File

./facebookshare.module, line 49
Adds a button to a node to share on a user's Facebook stream

Code

function facebookshare_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if ($op == 'view') {

    // Make sure we're on the right content type.
    if (!in_array($node->type, variable_get('facebookshare_types', array()), TRUE)) {
      return NULL;
    }

    // Make sure we're actually building the page to render in a browser.
    if ($node->build_mode != NODE_BUILD_NORMAL) {
      return NULL;
    }

    // Make sure the user has access to use Facebook Share.
    if (!user_access('access facebookshare')) {
      return NULL;
    }

    // Retrieve the location where we should show it, the style and the URL of the button.
    $location = variable_get('facebookshare_location', array());
    $url = url('node/' . $node->nid, array(
      'absolute' => TRUE,
    ));

    // Check in the teaser and full view.
    if ($teaser && !empty($location['teasers']) || !$teaser && !empty($location['content'])) {
      drupal_add_css(drupal_get_path('module', 'facebookshare') . '/facebookshare.css');
      $node->content['facebookshare'] = array(
        '#value' => theme('facebookshare', $url),
        '#weight' => -10,
      );
    }
  }
}