From 48adbcdc150d7872d350ff5641a4942a0cdcd8c0 Mon Sep 17 00:00:00 2001 From: Jeremy Trojan Date: Wed, 16 Mar 2011 22:44:29 -0700 Subject: Initial commit. --- fblikebutton.module | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 fblikebutton.module (limited to 'fblikebutton.module') diff --git a/fblikebutton.module b/fblikebutton.module new file mode 100644 index 0000000..a6b2a95 --- /dev/null +++ b/fblikebutton.module @@ -0,0 +1,69 @@ + '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 = ''; + // 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'); +} -- cgit v1.2.3