You are here

function facebookshare_nodeapi in Facebook Share 6

Same name and namespace in other branches
  1. 6.3 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,
    ));
    $weight = check_plain(variable_get('facebookshare_weight', -10));

    // 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' => is_numeric($weight) ? (int) $weight : -10,
      );
    }
  }
}