aboutsummaryrefslogtreecommitdiff
path: root/fblikebutton.module
blob: a6b2a9594120a6c925ba915ac2ceedcf2103e83e (plain)
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
<?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 settings',
    '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).
 * Should $likebutton be wrapped in t()?
 */
function fblikebutton_nodeapi(&$node, $op, $teaser, $page) {
  global $user;
  switch ($op) {
    case 'view':
      // Set which node types users can "like".
      $types_to_like = variable_get('fblikebutton_node_types', array('page'));
      // Replace with drupal_get_path_alias() or something?
      $likepath = $_SERVER['SCRIPT_URI'];
      $likepath = urlencode($likepath);
      // 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 .= $likepath;
      $likebutton .= '&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;font&amp;colorscheme=light&amp;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');
}