From 935ed4838cc9564c1f831b7d1ba4f9783d3f81a0 Mon Sep 17 00:00:00 2001 From: Jeremy Trojan Date: Sat, 21 May 2011 15:45:25 -0700 Subject: Added option to adjust weight on nodes. Added option to include button on teasers. Added option to include custom iframe width. Added option to include custom iframe height. Added option to include custom CSS. Updated fetched Facebook URL to "https" so button can be displayed on secure sites Updated hook_uninstall() to reflect above changes. --- fblikebutton.admin.inc | 152 +++++++++++++++++++++++++++++--------------- fblikebutton.info | 3 +- fblikebutton.install | 19 +++++- fblikebutton.module | 166 ++++++++++++++++++++++++++++++------------------- 4 files changed, 224 insertions(+), 116 deletions(-) diff --git a/fblikebutton.admin.inc b/fblikebutton.admin.inc index 34fe686..104a93f 100644 --- a/fblikebutton.admin.inc +++ b/fblikebutton.admin.inc @@ -7,67 +7,101 @@ */ /** - * Configure which node types can be "liked" by users. + * Settings for nodes. */ function fblikebutton_admin_settings() { $fblikebutton_node_options = node_type_get_names(); $form['fblikebutton_node_types'] = array( '#type' => 'checkboxes', - '#title' => t('Display the button on these content types'), + '#title' => t('Display the Like button on these content types:'), '#options' => $fblikebutton_node_options, - '#default_value' => variable_get('fblikebutton_node_types', array()), + '#default_value' => variable_get('fblikebutton_node_types', array('article')), '#description' => t('Each of these content types will have the "like" button automatically added to them.'), ); - $form['fblikebutton_api'] = array( - '#type' => 'fieldset', - '#title' => t('FB Like Button settings'), - '#collapsible' => true, - '#collapsed' => true, + $form['fblikebutton_showonteasers'] = array( + '#type' => 'radios', + '#title' => t('Display on teasers?'), + '#options' => array(t('No'), t('Yes')), + '#default_value' => variable_get('fblikebutton_showonteasers', 0), + '#description' => t('If Yes is selected, the button will appear even when the node being viewed is a teaser. Otherwise it will only appear when the full node is being viewed.'), + ); + $form['fblikebutton_iframe_width'] = array( + '#type' => 'textfield', + '#title' => t('Width of the iframe (px)'), + '#default_value' => variable_get('fblikebutton_iframe_width', '450'), + '#description' => t('Width of the iframe, in pixels. Default is 450. Note: lower values may crop the output.'), + ); + $form['fblikebutton_iframe_height'] = array( + '#type' => 'textfield', + '#title' => t('Height of the iframe (px)'), + '#default_value' => variable_get('fblikebutton_iframe_height', '80'), + '#description' => t('Height of the iframe, in pixels. Default is 80. Note: lower values may crop the output.'), + ); + $form['fblikebutton_iframe_css'] = array( + '#type' => 'textfield', + '#title' => t('Extra css styling needed'), + '#default_value' => variable_get('fblikebutton_iframe_css', ''), + '#description' => t('Extra css attributes needed to make the iframe behave for your specific requirements. Will not necessarily overwrite existing styling. To alter the dimensions of the iframe, use the height and width fields found above.
Example: float: right; padding: 5px;'), ); - $form['fblikebutton_api']['fblikebutton_layout'] = array( + $form['fblikebutton_layout'] = array( '#type' => 'select', '#title' => t('Layout style'), '#options' => array('standard' => t('Standard'), 'box_count' => t('Box Count'), 'button_count' => t('Button Count')), '#default_value' => variable_get('fblikebutton_layout', 'standard'), - '#description' => t('Determines the size and amount of social context next to the button'), + '#description' => t('Determines the size and amount of social context next to the button.'), ); - $form['fblikebutton_api']['fblikebutton_show_faces'] = array( + $form['fblikebutton_show_faces'] = array( '#type' => 'select', - '#title' => t('Display faces in the box'), + '#title' => t('Show faces in the box?'), '#options' => array('show' => t('Show faces'), 'hide' => t('Do not show faces')), '#default_value' => variable_get('fblikebutton_show_faces', 'show'), - '#description' => t('Show profile pictures below the button. Only work on Standard layout'), + '#description' => t('Show profile pictures below the button. Only works if Layout style (found above) is set to Standard (otherwise, value is ignored).'), ); - $form['fblikebutton_api']['fblikebutton_action'] = array( + $form['fblikebutton_action'] = array( '#type' => 'select', '#title' => t('Verb to display'), '#options' => array('like' => t('Like'), 'recommend' => t('Recommend')), '#default_value' => variable_get('fblikebutton_action', 'like'), - '#description' => t('The verb to display in the button.'), + '#description' => t('The verbiage to display inside the button itself.'), ); - $form['fblikebutton_api']['fblikebutton_font'] = array( - '#type' => 'select', - '#title' => t('Font'), - '#options' => array('arial' => 'Arial', - 'lucida+grande' => 'Lucida Grande', - 'segoe+ui' => 'Segoe UI', - 'tahoma' => 'Tahoma', - 'trebuchet+ms' => 'Trebuchet MS', - 'verdana' => 'Verdana'), - '#default_value' => variable_get('fblikebutton_font', 'arial'), - '#description' => t('The font to display in the button'), - ); - $form['fblikebutton_api']['fblikebutton_color_scheme'] = array( - '#type' => 'select', - '#title' => t('Color scheme'), - '#options' => array('light' => t('Light'), 'dark' => t('Dark')), - '#default_value' => variable_get('fblikebutton_color_scheme', 'light'), - '#description' => t('The color scheme of box environtment'), +/** $form['fblikebutton_displaysend'] = array( + '#type' => 'select', + '#title' => t('Display send option?'), + '#options' => array('true' => t('Display'), 'false' => t('Do not display')), + '#default_value' => variable_get('fblikebutton_displaysend', 'false'), + '#description' => t('Optionally display the Send button next to the Like/Recommend box.
Note: this feature is currently unavailable from Facebook. Although setting the value to Display will not hurt anything, the output will not be affected either way.'), + ); */ + $form['fblikebutton_font'] = array( + '#type' => 'select', + '#title' => t('Font'), + '#options' => array('arial' => 'Arial', + 'lucida+grande' => 'Lucida Grande', + 'segoe+ui' => 'Segoe UI', + 'tahoma' => 'Tahoma', + 'trebuchet+ms' => 'Trebuchet MS', + 'verdana' => 'Verdana'), + '#default_value' => variable_get('fblikebutton_font', 'arial'), + '#description' => t('The font with which to display the text of the button.'), ); + $form['fblikebutton_color_scheme'] = array( + '#type' => 'select', + '#title' => t('Color scheme'), + '#options' => array('light' => t('Light'), 'dark' => t('Dark')), + '#default_value' => variable_get('fblikebutton_color_scheme', 'light'), + '#description' => t('The color scheme of the box environtment.'), + ); + $form['fblikebutton_weight'] = array( + '#type' => 'select', + '#title' => t('Weight'), + '#options' => array('-50' => '-50', '-49' => '-49', '-48' => '-48', '-47' => '-47', '-46' => '-46', '-45' => '-45', '-44' => '-44', '-43' => '-43', '-42' => '-42', '-41' => '-41', '-40' => '-40', '-39' => '-39', '-38' => '-38', '-37' => '-37', '-36' => '-36', '-35' => '-35', '-34' => '-34', '-33' => '-33', '-32' => '-32', '-31' => '-31', '-30' => '-30', '-29' => '-29', '-28' => '-28', '-27' => '-27', '-26' => '-26', '-25' => '-25', '-24' => '-24', '-23' => '-23', '-22' => '-22', '-21' => '-21', '-20' => '-20', '-19' => '-19', '-18' => '-18', '-17' => '-17', '-16' => '-16', '-15' => '-15', '-14' => '-14', '-13' => '-13', '-12' => '-12', '-11' => '-11', '-10' => '-10', '-9' => '-9', '-8' => '-8', '-7' => '-7', '-6' => '-6', '-5' => '-5', '-4' => '-4', '-3' => '-3', '-2' => '-2', '-1' => '-1', '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30', '31' => '31', '32' => '32', '33' => '33', '34' => '34', '35' => '35', '36' => '36', '37' => '37', '38' => '38', '39' => '39', '40' => '40', '41' => '41', '42' => '42', '43' => '43', '44' => '44', '45' => '45', '46' => '46', '47' => '47', '48' => '48', '49' => '49', '50' => '50'), + '#default_value' => variable_get('fblikebutton_weight', '50'), + '#description' => t('The weight determines where on a node the like button will appear. The larger the weight, the lower it will appear on the node. For example, if you want the button to appear more toward the top of the node, choose -40 as opposed to -39, -38, 0, 1, or 50, etc.'), + ); return system_settings_form($form); } + /** - * Configure form block configuration + * Settings for the block. */ function fblikebutton_block_settings() { global $base_url; @@ -103,24 +137,42 @@ function fblikebutton_block_settings() { '#description' => t('The verb to display in the button.'), ); $form['fblikebutton_block']['fblikebutton_bl_font'] = array( - '#type' => 'select', - '#title' => t('Font'), - '#options' => array('arial' => 'Arial', - 'lucida+grande' => 'Lucida Grande', - 'segoe+ui' => 'Segoe UI', - 'tahoma' => 'Tahoma', - 'trebuchet+ms' => 'Trebuchet MS', - 'verdana' => 'Verdana'), - '#default_value' => variable_get('fblikebutton_bl_font', 'arial'), - '#description' => t('The font to display in the button'), + '#type' => 'select', + '#title' => t('Font'), + '#options' => array('arial' => 'Arial', + 'lucida+grande' => 'Lucida Grande', + 'segoe+ui' => 'Segoe UI', + 'tahoma' => 'Tahoma', + 'trebuchet+ms' => 'Trebuchet MS', + 'verdana' => 'Verdana'), + '#default_value' => variable_get('fblikebutton_bl_font', 'arial'), + '#description' => t('The font to display in the button'), ); $form['fblikebutton_block']['fblikebutton_bl_color_scheme'] = array( - '#type' => 'select', - '#title' => t('Color scheme'), - '#options' => array('light' => t('Light'), 'dark' => t('Dark')), - '#default_value' => variable_get('fblikebutton_bl_color_scheme', 'light'), - '#description' => t('The color scheme of box environtment'), + '#type' => 'select', + '#title' => t('Color scheme'), + '#options' => array('light' => t('Light'), 'dark' => t('Dark')), + '#default_value' => variable_get('fblikebutton_bl_color_scheme', 'light'), + '#description' => t('The color scheme of box environtment'), + ); + $form['fblikebutton_block']['fblikebutton_bl_iframe_width'] = array( + '#type' => 'textfield', + '#title' => t('Width of the iframe (px)'), + '#default_value' => variable_get('fblikebutton_bl_iframe_width', '450'), + '#description' => t('Width of the iframe, in pixels. Default is 450. Note: lower values may crop the output.'), + ); + $form['fblikebutton_block']['fblikebutton_bl_iframe_height'] = array( + '#type' => 'textfield', + '#title' => t('Height of the iframe (px)'), + '#default_value' => variable_get('fblikebutton_bl_iframe_height', '80'), + '#description' => t('Height of the iframe, in pixels. Default is 80. Note: lower values may crop the output.'), ); - return system_settings_form($form); + $form['fblikebutton_block']['fblikebutton_bl_iframe_css'] = array( + '#type' => 'textfield', + '#title' => t('Extra css styling needed'), + '#default_value' => variable_get('fblikebutton_bl_iframe_css', ''), + '#description' => t('Extra css attributes needed to make the iframe behave for your specific requirements. Will not necessarily overwrite existing styling. To alter the dimensions of the iframe, use the height and width fields found above.
Example: float: right; padding: 5px;'), + ); + return system_settings_form($form); } \ No newline at end of file diff --git a/fblikebutton.info b/fblikebutton.info index 8a60e9f..b9b5565 100644 --- a/fblikebutton.info +++ b/fblikebutton.info @@ -1,6 +1,5 @@ ; $Id$ name = Facebook Like Button -description = "Adds Facebook's Like button to each selected node type." +description = Adds a configurable Like button for Facebook to each selected node type, as well as a configurable block with a Like box in it. core = 7.x -package = Other configure = admin/config/fblikebutton diff --git a/fblikebutton.install b/fblikebutton.install index 9a9f853..f11c08b 100644 --- a/fblikebutton.install +++ b/fblikebutton.install @@ -16,5 +16,22 @@ function fblikebutton_uninstall() { variable_del('fblikebutton_show_faces'); variable_del('fblikebutton_layout'); variable_del('fblikebutton_color_scheme'); - variable_del('fblikebutton_action'); + variable_del('fblikebutton_iframe_height'); + variable_del('fblikebutton_iframe_width'); + variable_del('fblikebutton_iframe_css'); + variable_del('fblikebutton_displaysend'); + variable_del('fblikebutton_font'); + variable_del('fblikebutton_weight'); + variable_del('fblikebutton_showonteasers'); + variable_del('fblikebutton_xfbml'); + variable_del('fblikebutton_appid'); + variable_del('fblikebutton_bl_layout'); + variable_del('fblikebutton_bl_layout'); + variable_del('fblikebutton_bl_show_faces'); + variable_del('fblikebutton_bl_action'); + variable_del('fblikebutton_bl_font'); + variable_del('fblikebutton_bl_color_scheme'); + variable_del('fblikebutton_bl_iframe_width'); + variable_del('fblikebutton_bl_iframe_height'); + variable_del('fblikebutton_bl_iframe_css'); } diff --git a/fblikebutton.module b/fblikebutton.module index 2451d2f..3ab8693 100644 --- a/fblikebutton.module +++ b/fblikebutton.module @@ -4,15 +4,16 @@ /** * @file * 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. */ /** - * Implementation of hook_menu(). + * Implements of hook_menu(). */ function fblikebutton_menu() { $items['admin/config/fblikebutton'] = array( - 'title' => 'FB Like settings', - 'description' => 'Configure FB Like Button', + 'title' => 'FB Like Button', + 'description' => 'Configure the Facebook Like button', 'page callback' => 'system_admin_menu_block_page', 'access arguments' => array('administer fblikebutton'), 'position' => 'right', @@ -22,8 +23,8 @@ function fblikebutton_menu() { 'file path' => drupal_get_path('module', 'system'), ); $items['admin/config/fblikebutton/general'] = array( - 'title' => 'FB Like settings', - 'description' => 'Configure which the button should appear on.', + 'title' => 'General settings', + 'description' => 'Configure the settings for the Like button as it appears on individual nodes.', 'page callback' => 'drupal_get_form', 'page arguments' => array('fblikebutton_admin_settings'), 'access arguments' => array('administer fblikebutton'), @@ -32,8 +33,8 @@ function fblikebutton_menu() { 'weight' => 0, ); $items['admin/config/fblikebutton/block'] = array( - 'title' => 'FB Like block settings', - 'description' => 'Configure which the block should appear on.', + 'title' => 'Block settings', + 'description' => 'Configure the settings for the Like button as it appears in the block.', 'page callback' => 'drupal_get_form', 'page arguments' => array('fblikebutton_block_settings'), 'access arguments' => array('administer fblikebutton block'), @@ -45,7 +46,54 @@ function fblikebutton_menu() { } /** - * Implementation of hook_permission() + * Implements of hook_node_view(). + */ +function fblikebutton_node_view($node, $view_mode) { + global $user, $base_url; + $types = variable_get('fblikebutton_node_types', array()); + $showonteasers = variable_get('fblikebutton_showonteasers', 0); + $full = ($view_mode == 'full') ? TRUE : FALSE; + $show = ( ! empty($types[$node->type]) && user_access('access fblikebutton')); + $likebase = $base_url . '/'; + $likepath = drupal_get_path_alias($node->uri['path']); + $webpage_to_like = $likebase . $likepath; + $likebutton_weight = variable_get('fblikebutton_weight', '0'); + $conf = array( + 'layout' => variable_get('fblikebutton_layout', 'standard'), + 'action' => variable_get('fblikebutton_action', 'like'), + 'color_scheme' => variable_get('fblikebutton_color_scheme', 'light'), + 'show_faces' => variable_get('fblikebutton_show_faces', 'true'), + 'font' => variable_get('fblikebutton_font', 'arial'), + 'height' => variable_get('fblikebutton_iframe_height', '80'), + 'width' => variable_get('fblikebutton_iframe_width', '450'), + 'send' => variable_get('fblikebutton_send', 'true'), + 'other_css' => variable_get('fblikebutton_iframe_css', ''), + ); + if ($show) { + if ($showonteasers == 0) { + if ($view_mode == 'teaser') { + $node->content['fblikebutton_field'] = NULL; + } + if ($view_mode == 'full') { + $node->content['fblikebutton_field'] = array( + '#markup' => _fblikebutton_field($webpage_to_like, $conf), + '#weight' => $likebutton_weight, + ); + } + } + elseif ($showonteasers == 1) { + if ($view_mode == 'teaser' || $view_mode == 'full') { + $node->content['fblikebutton_field'] = array( + '#markup' => _fblikebutton_field($webpage_to_like, $conf), + '#weight' => $likebutton_weight, + ); + } + } + } +} + +/** + * Implements of hook_permission(). */ function fblikebutton_permission() { return array( @@ -63,30 +111,6 @@ function fblikebutton_permission() { ); } -/** - * Implementation of hook_node_view() - */ -function fblikebutton_node_view($node, $view_mode) { - $types = variable_get('fblikebutton_node_types', array()); - $full = ($view_mode == 'full') ? TRUE : FALSE; - $show = ( ! empty($types[$node->type]) && - $full && user_access('access fblikebutton')); - if ($show) { - $url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - $http = ( ! empty($_SERVER['HTTPS'])) ? 'https://' : 'http://'; - $addr = $http . $url; - $conf = array( - 'layout' => variable_get('fblikebutton_layout', "standard"), - 'action' => variable_get('fblikebutton_action', "like"), - 'color_scheme' => variable_get('fblikebutton_color_scheme', "light"), - 'show_faces' => variable_get('fblikebutton_show_faces', "false"), - 'font' => variable_get('fblikebutton_font', "arial"), - ); - $node->content['fblikebutton_field'] = array( - '#markup' => _fblikebutton_field($addr, $conf), - ); - } -} /** * Implementation of hook_block_info() @@ -140,24 +164,42 @@ function fblikebutton_block_configure($delta = '') { '#description' => t('The verb to display in the button.'), ); $form['block']['fblikebutton_bl_font'] = array( - '#type' => 'select', - '#title' => t('Font'), - '#options' => array('arial' => 'Arial', - 'lucida+grande' => 'Lucida Grande', - 'segoe+ui' => 'Segoe UI', - 'tahoma' => 'Tahoma', - 'trebuchet+ms' => 'Trebuchet MS', - 'verdana' => 'Verdana'), - '#default_value' => variable_get('fblikebutton_bl_font', 'arial'), - '#description' => t('The font to display in the button'), + '#type' => 'select', + '#title' => t('Font'), + '#options' => array('arial' => 'Arial', + 'lucida+grande' => 'Lucida Grande', + 'segoe+ui' => 'Segoe UI', + 'tahoma' => 'Tahoma', + 'trebuchet+ms' => 'Trebuchet MS', + 'verdana' => 'Verdana'), + '#default_value' => variable_get('fblikebutton_bl_font', 'arial'), + '#description' => t('The font to display in the button'), ); $form['block']['fblikebutton_bl_color_scheme'] = array( - '#type' => 'select', - '#title' => t('Color scheme'), - '#options' => array('light' => t('Light'), 'dark' => t('Dark')), - '#default_value' => variable_get('fblikebutton_bl_color_scheme', 'light'), - '#description' => t('The color scheme of box environtment'), + '#type' => 'select', + '#title' => t('Color scheme'), + '#options' => array('light' => t('Light'), 'dark' => t('Dark')), + '#default_value' => variable_get('fblikebutton_bl_color_scheme', 'light'), + '#description' => t('The color scheme of box environtment'), ); + $form['block']['fblikebutton_bl_iframe_width'] = array( + '#type' => 'textfield', + '#title' => t('Width of the iframe (px)'), + '#default_value' => variable_get('fblikebutton_bl_iframe_width', '450'), + '#description' => t('Width of the iframe, in pixels. Default is 450. Note: lower values may crop the output.'), + ); + $form['block']['fblikebutton_bl_iframe_height'] = array( + '#type' => 'textfield', + '#title' => t('Height of the iframe (px)'), + '#default_value' => variable_get('fblikebutton_bl_iframe_height', '80'), + '#description' => t('Height of the iframe, in pixels. Default is 80. Note: lower values may crop the output.'), + ); + $form['block']['fblikebutton_bl_iframe_css'] = array( + '#type' => 'textfield', + '#title' => t('Extra css styling needed'), + '#default_value' => variable_get('fblikebutton_bl_iframe_css', ''), + '#description' => t('Extra css attributes needed to make the iframe behave for your specific requirements. Will not necessarily overwrite existing styling. To alter the dimensions of the iframe, use the height and width fields found above.
Example: float: right; padding: 5px;'), + ); } return $form; } @@ -173,6 +215,9 @@ function fblikebutton_block_save($delta = '', $edit = array()) { variable_set('fblikebutton_bl_action', $edit['fblikebutton_bl_action']); variable_set('fblikebutton_bl_font', $edit['fblikebutton_bl_font']); variable_set('fblikebutton_bl_color_scheme', $edit['fblikebutton_bl_color_scheme']); + variable_set('fblikebutton_bl_iframe_width', $edit['fblikebutton_bl_iframe_width']); + variable_set('fblikebutton_bl_iframe_height', $edit['fblikebutton_bl_iframe_height']); + variable_set('fblikebutton_bl_iframe_css', $edit['fblikebutton_bl_iframe_css']); } } @@ -192,33 +237,28 @@ function fblikebutton_block_view($delta = '') { 'color_scheme' => variable_get('fblikebutton_bl_color_scheme', "light"), 'show_faces' => variable_get('fblikebutton_bl_show_faces', "false"), 'font' => variable_get('fblikebutton_bl_font', "arial"), + 'height' => variable_get('fblikebutton_bl_iframe_height', '80'), + 'width' => variable_get('fblikebutton_bl_iframe_width', '450'), + 'other_css' => variable_get('fblikebutton_bl_iframe_css', ''), ); $block['content'] = _fblikebutton_field($addr, $conf); } return $block; } -function _fblikebutton_field($addr, $conf) { - $addr = urlencode($addr); - $width = "100%"; +function _fblikebutton_field($webpage_to_like, $conf) { + $webpage_to_like = urlencode($webpage_to_like); + $width = $conf['width']; + $height = $conf['height']; $layout = $conf['layout']; $action = $conf['action']; $colorscheme = $conf['color_scheme']; $show_faces = $conf['show_faces']; $font = $conf['font']; - switch ($layout) { - case "box_count": - $height = 65; - case "button_count": - $height = 21; - case "standard": - default: - $height = $show_faces == "false" ? 35 : 80; - } - $height = 60; - - $params = "href=$addr&layout=$layout&show_faces=false&width&font=$font&height=$height&action=$action&colorscheme=$colorscheme"; +// $send = $conf['send']; + $other_css = $conf['other_css']; + $params = "href={$webpage_to_like}&layout={$layout}&show_faces={$show_faces}&width={$width}px&font={$font}&height={$height}px&action={$action}&colorscheme={$colorscheme}"; $src = htmlentities($params); - $output = ""; + $output = ''; return $output; } -- cgit v1.2.3