aboutsummaryrefslogtreecommitdiff
path: root/fblikebutton.module
diff options
context:
space:
mode:
authorJeremy Trojan <jer@jerdiggity.com>2011-05-21 15:45:25 -0700
committerJeremy Trojan <jer@jerdiggity.com>2011-05-21 15:45:25 -0700
commit935ed4838cc9564c1f831b7d1ba4f9783d3f81a0 (patch)
tree2ce4411c8cfc6d87aff2530c9565840bf288521d /fblikebutton.module
parent584e199d1dcaa2f3d7bef48b16799344b33a3ed4 (diff)
downloadfblikebutton-935ed4838cc9564c1f831b7d1ba4f9783d3f81a0.tar.gz
fblikebutton-935ed4838cc9564c1f831b7d1ba4f9783d3f81a0.tar.bz2
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.
Diffstat (limited to 'fblikebutton.module')
-rw-r--r--fblikebutton.module166
1 files changed, 103 insertions, 63 deletions
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. <em>Note: lower values may crop the output.</em>'),
+ );
+ $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. <em>Note: lower values may crop the output.</em>'),
+ );
+ $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.<br/>Example: <em>float: right; padding: 5px;</em>'),
+ );
}
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 = "<iframe src=\"http://www.facebook.com/plugins/like.php?$src\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width: ".$width."; height: ".$height."px; allowTransparency=\"true\"></iframe>";
+ $output = '<iframe src="https://www.facebook.com/plugins/like.php?' . $src . '" scrolling="no" frameborder="0" style="border: none; overflow: hidden; width: ' . $width . 'px; height: ' . $height . 'px;' . $other_css . '" allowTransparency="true"></iframe>';
return $output;
}