function fblikebutton_nodeapi in Facebook Like Button 6
Same name and namespace in other branches
- 6.2 fblikebutton.module \fblikebutton_nodeapi()
Implementation of hook_nodeapi().
File
- ./
fblikebutton.module, line 29 - 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_nodeapi(&$node, $op, $teaser, $page) {
global $user, $base_url, $language;
$likebase = $base_url . '/';
$likepath = drupal_get_path_alias('node/' . $node->nid);
$webpage_to_like = $likebase . $likepath;
$lang_abbr = $language->language;
$fblikebutton_lang = $lang_abbr . '_' . drupal_strtoupper($lang_abbr);
switch ($op) {
case 'view':
// Whether to show faces in the iframe. (Thanks to dizarter for pointing out that the next few lines should be relocated to where they are now.)
$fblikebutton_showonteasers = variable_get('fblikebutton_showonteasers', 0);
// Set which node types users can "like".
$types_to_like = variable_get('fblikebutton_node_types', array(
'page',
));
// Keep the fblikebutton button out of search results, teasers, etc., if set.
if ($fblikebutton_showonteasers == 0) {
if (!$page) {
break;
}
}
// Do not add the like button to any of the unchecked node types.
if (!in_array($node->type, $types_to_like, TRUE)) {
break;
}
// Whether or not to show the faces of people who have "liked" the node.
$show_faces = variable_get('fblikebutton_show_faces', 'true');
// Color scheme of the box. Options: "light" or "dark".
$colorscheme = variable_get('fblikebutton_color_scheme', 'light');
// Layout style. Options: "Standard", "Box Count", or "Button Count".
$layout = variable_get('fblikebutton_layout', 'standard');
// Action to display. Options: "Like" or "Recommend"
$action = variable_get('fblikebutton_action', 'like');
// Font to use.
$font = variable_get('fblikebutton_font', 'arial');
// Iframe height.
$iframe_h = variable_get('fblikebutton_iframe_height', '80');
// Iframe width.
$iframe_w = variable_get('fblikebutton_iframe_width', '450');
// Extra CSS to be tacked on to the end of the iframe. Example: padding-left: 5px; padding-top: 10px;
$other_css = variable_get('fblikebutton_iframe_css', '');
$other_css = trim($other_css);
// Weight on the node
$likebutton_weight = variable_get('fblikebutton_weight', '50');
$likebutton_lang = variable_get('fblikebutton_language', $fblikebutton_lang);
// The next part is whether or not to display the "Send" button next to the "Like" (or "Recommend") button.
// CURRENTLY ONLY WORKS WITH XFBML (NOT IFRAME)... But it doesn't hurt anything and WILL
// be in one of the next stable releases, so I'm leaving it there in case FB decides to enable
// the feature to work with the iframe version. Until then, or until next stable release, see dev snapshot
// if you require the "Send" button.
$displaysend = variable_get('fblikebutton_send', 'true');
// Since we're currently using the iframe version...
$likebutton = '<iframe class="fblikebutton" src="https://www.facebook.com/plugins/like.php?href=' . urlencode($webpage_to_like) . '&send=' . check_plain($displaysend) . '&layout=' . check_plain($layout) . '&show_faces=' . check_plain($show_faces) . '&width=' . check_plain($iframe_w) . '&action=' . check_plain($action) . '&font=' . check_plain($font) . '&colorscheme=' . check_plain($colorscheme) . '&height=' . check_plain($iframe_h) . '&locale=' . check_plain($likebutton_lang) . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:' . check_plain($iframe_w) . 'px; height:' . check_plain($iframe_h) . 'px;' . check_plain($other_css) . '" allowTransparency="true"></iframe>';
// Check permissions
if (user_access('users may access Like button')) {
// If set, keep the button out of teasers:
if ($fblikebutton_showonteasers == 0) {
if ($teaser) {
break;
}
}
$node->content['fblikebutton_button'] = array(
'#value' => $likebutton,
'#weight' => $likebutton_weight,
);
break;
}
}
}