1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
<?php
// $Id$
/**
* @file
* Adds Facebook's "Like" button to each selected node type.
*/
/**
* Implementation of hook_menu().
*/
function fblikebutton_menu() {
$items['admin/settings/fblikebutton'] = array(
'title' => 'FB Like Button',
'description' => 'Control which content types the "like" button should appear on.',
'page callback' => 'drupal_get_form',
'page arguments' => array('fblikebutton_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
'file' => 'fblikebutton.admin.inc',
);
return $items;
}
/**
* Implementation of hook_nodeapi().
* @todo
* Add more config options for like button (size, etc).
*/
function fblikebutton_nodeapi(&$node, $op, $teaser, $page) {
global $user;
global $base_url;
$likebase = $base_url . '/';
$likepath = drupal_get_path_alias($_GET['q']);
$webpage_to_like = $likebase . $likepath;
switch ($op) {
case 'view':
// Set which node types users can "like".
$types_to_like = variable_get('fblikebutton_node_types', array('page'));
$show_faces = variable_get('fblikebutton_show_faces', 'true');
// Facebook is doing away with FBML, so we use the iframe plugin option instead.
$likebutton = '<iframe src="http://www.facebook.com/plugins/like.php?href=';
$likebutton .= urlencode($webpage_to_like);
$likebutton .= '&layout=standard&show_faces=';
$likebutton .= $show_faces;
$likebutton .= '&width=450&action=like&font&colorscheme=light&height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>';
// Keep the fblikebutton button out of search results, etc.
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;
}
// Set permissions, and keep the button out of teasers. Otherwise, there
// would be 50 "like" buttons on the front page of some sites... Not good.
if (!$teaser && user_access('users may access Like button')) {
$node->content['fblikebutton_button'] = array(
'#value' => $likebutton,
'#weight' => 100,
);
}
break;
}
}
/**
* Implementation of hook_perm().
*/
function fblikebutton_perm() {
return array('users may access Like button');
}
|