function facebookshare_node_view in Facebook Share 7
Same name and namespace in other branches
- 8 facebookshare.module \facebookshare_node_view()
Implements hook_node_view()
File
- ./
facebookshare.module, line 61 - Adds a button to a node to share on a user's Facebook stream
Code
function facebookshare_node_view($node, $view_mode = 'full') {
// Make sure we're on the right content type.
if (!in_array($node->type, variable_get('facebookshare_types', array()), TRUE)) {
return NULL;
}
// We only render the button on full pages and on teasers
if ($view_mode != 'teaser' && $view_mode != 'full') {
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
$location = variable_get('facebookshare_location', array());
// Check if the current $view_mode has content to show
if ($view_mode == 'teaser' && !empty($location['teasers']) || $view_mode == 'full' && !empty($location['content'])) {
// Retrieve the weight and url of the button
$url = url('node/' . $node->nid, array(
'absolute' => TRUE,
));
$weight = check_plain(variable_get('facebookshare_weight', -10));
// Add and theme the button
$node->content['facebookshare'] = array(
'#markup' => theme('facebookshare', array(
'url' => $url,
)),
'#weight' => is_numeric($weight) ? (int) $weight : -10,
);
}
}