aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Trojan <jer@jerdiggity.com>2011-03-16 22:44:29 -0700
committerJeremy Trojan <jer@jerdiggity.com>2011-03-16 22:44:29 -0700
commit48adbcdc150d7872d350ff5641a4942a0cdcd8c0 (patch)
treeb177784c58045447f2f5d811d8d83a4a7a42b635
parentd568753643fca4f94bc8722841a458c5133abf1a (diff)
downloadfblikebutton-48adbcdc150d7872d350ff5641a4942a0cdcd8c0.tar.gz
fblikebutton-48adbcdc150d7872d350ff5641a4942a0cdcd8c0.tar.bz2
Initial commit.
-rw-r--r--fblikebutton.admin.inc29
-rw-r--r--fblikebutton.install16
-rw-r--r--fblikebutton.module69
3 files changed, 114 insertions, 0 deletions
diff --git a/fblikebutton.admin.inc b/fblikebutton.admin.inc
new file mode 100644
index 0000000..a11e682
--- /dev/null
+++ b/fblikebutton.admin.inc
@@ -0,0 +1,29 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Admin functions for fblikebutton.
+ */
+
+/**
+ * Configure which node types can be "liked" by users.
+ */
+function fblikebutton_admin_settings() {
+ $fblikebutton_node_options = node_get_types('names');
+ $form['fblikebutton_node_types'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Display the Like button on these content types'),
+ '#options' => $fblikebutton_node_options,
+ '#default_value' => variable_get('fblikebutton_node_types', array('page')),
+ '#description' => t('Each of these content types will have the "like" button automatically added to them.'),
+ );/**
+ $form['fblikebutton_show_faces'] = array(
+ '#type' => 'radios',
+ '#title' => t('Display faces in the Like box'),
+ '#options' => array('true' => t('Show faces'), 'false' => t('Do not show faces'))
+ '#default_value' => variable_get('fblikebutton_show_faces', array('true')),
+ '#description' => t('Should users see the faces of other people who have "liked" the same content?'),
+ ); */
+ return system_settings_form($form);
+}
diff --git a/fblikebutton.install b/fblikebutton.install
new file mode 100644
index 0000000..b6d4a63
--- /dev/null
+++ b/fblikebutton.install
@@ -0,0 +1,16 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_install().
+ */
+function fblikebutton_install() {
+// There really is no "schema" to install.
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function fblikebutton_uninstall() {
+ variable_del('fblikebutton_node_types');
+}
diff --git a/fblikebutton.module b/fblikebutton.module
new file mode 100644
index 0000000..a6b2a95
--- /dev/null
+++ b/fblikebutton.module
@@ -0,0 +1,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');
+}