aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fblikebutton.admin.inc115
-rw-r--r--fblikebutton.info6
-rw-r--r--fblikebutton.install4
-rw-r--r--fblikebutton.module238
4 files changed, 309 insertions, 54 deletions
diff --git a/fblikebutton.admin.inc b/fblikebutton.admin.inc
index fdc8d4c..34fe686 100644
--- a/fblikebutton.admin.inc
+++ b/fblikebutton.admin.inc
@@ -10,20 +10,117 @@
* Configure which node types can be "liked" by users.
*/
function fblikebutton_admin_settings() {
- $fblikebutton_node_options = node_get_types('names');
+ $fblikebutton_node_options = node_type_get_names();
$form['fblikebutton_node_types'] = array(
'#type' => 'checkboxes',
- '#title' => t('Display the Like button on these content types'),
+ '#title' => t('Display the button on these content types'),
'#options' => $fblikebutton_node_options,
- '#default_value' => variable_get('fblikebutton_node_types', array('page')),
+ '#default_value' => variable_get('fblikebutton_node_types', array()),
'#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('Show faces in the Like box'),
- '#default_value' => variable_get('fblikebutton_show_faces', 'true'),
- '#options' => array('true' => t('Show faces'), 'false' => t('Do not show faces')),
- '#description' => t('Should users see the faces of other people who have "liked" the same content?'),
+ $form['fblikebutton_api'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('FB Like Button settings'),
+ '#collapsible' => true,
+ '#collapsed' => true,
+ );
+ $form['fblikebutton_api']['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'),
+ );
+ $form['fblikebutton_api']['fblikebutton_show_faces'] = array(
+ '#type' => 'select',
+ '#title' => t('Display 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'),
+ );
+ $form['fblikebutton_api']['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.'),
+ );
+ $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'),
);
return system_settings_form($form);
}
+/**
+ * Configure form block configuration
+ */
+function fblikebutton_block_settings() {
+ global $base_url;
+ $form['fblikebutton_block_url'] = array(
+ '#type' => 'textfield',
+ '#default_value' => variable_get('fblikebutton_block_url', $base_url),
+ '#description' => t('URL of your homepage to like')
+ );
+ $form['fblikebutton_block'] = array(
+ '#type' => 'fieldset',
+ '#title' => 'Block configuration',
+ '#collapsible' => false,
+ );
+ $form['fblikebutton_block']['fblikebutton_bl_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_bl_layout', 'standard'),
+ '#description' => t('Determines the size and amount of social context next to the button'),
+ );
+ $form['fblikebutton_block']['fblikebutton_bl_show_faces'] = array(
+ '#type' => 'select',
+ '#title' => t('Display faces in the box'),
+ '#options' => array('show' => t('Show faces'), 'hide' => t('Do not show faces')),
+ '#default_value' => variable_get('fblikebutton_bl_show_faces', 'show'),
+ '#description' => t('Show profile pictures below the button. Only works with Standard layout'),
+ );
+ $form['fblikebutton_block']['fblikebutton_bl_action'] = array(
+ '#type' => 'select',
+ '#title' => t('Verb to display'),
+ '#options' => array('like' => t('Like'), 'recommend' => t('Recommend')),
+ '#default_value' => variable_get('fblikebutton_bl_action', 'like'),
+ '#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'),
+ );
+ $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'),
+ );
+ return system_settings_form($form);
+ }
+ \ No newline at end of file
diff --git a/fblikebutton.info b/fblikebutton.info
index ebd47d0..8a60e9f 100644
--- a/fblikebutton.info
+++ b/fblikebutton.info
@@ -1,4 +1,6 @@
; $Id$
name = Facebook Like Button
-description = Adds Facebook's "Like" button to each selected node type.
-core = 6.x
+description = "Adds Facebook's <em>Like</em> button to each selected node type."
+core = 7.x
+package = Other
+configure = admin/config/fblikebutton
diff --git a/fblikebutton.install b/fblikebutton.install
index b6d4a63..9a9f853 100644
--- a/fblikebutton.install
+++ b/fblikebutton.install
@@ -13,4 +13,8 @@ function fblikebutton_install() {
*/
function fblikebutton_uninstall() {
variable_del('fblikebutton_node_types');
+ variable_del('fblikebutton_show_faces');
+ variable_del('fblikebutton_layout');
+ variable_del('fblikebutton_color_scheme');
+ variable_del('fblikebutton_action');
}
diff --git a/fblikebutton.module b/fblikebutton.module
index 646b02a..2451d2f 100644
--- a/fblikebutton.module
+++ b/fblikebutton.module
@@ -10,63 +10,215 @@
* Implementation of hook_menu().
*/
function fblikebutton_menu() {
- $items['admin/settings/fblikebutton'] = array(
- 'title' => 'FB Like Button',
- 'description' => 'Control which content types the "like" button should appear on.',
+ $items['admin/config/fblikebutton'] = array(
+ 'title' => 'FB Like settings',
+ 'description' => 'Configure FB Like Button',
+ 'page callback' => 'system_admin_menu_block_page',
+ 'access arguments' => array('administer fblikebutton'),
+ 'position' => 'right',
+ 'weight' => -20,
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'system.admin.inc',
+ '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.',
'page callback' => 'drupal_get_form',
'page arguments' => array('fblikebutton_admin_settings'),
- 'access arguments' => array('administer site configuration'),
+ 'access arguments' => array('administer fblikebutton'),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'fblikebutton.admin.inc',
+ 'weight' => 0,
+ );
+ $items['admin/config/fblikebutton/block'] = array(
+ 'title' => 'FB Like block settings',
+ 'description' => 'Configure which the block should appear on.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('fblikebutton_block_settings'),
+ 'access arguments' => array('administer fblikebutton block'),
'type' => MENU_NORMAL_ITEM,
'file' => 'fblikebutton.admin.inc',
+ 'weight' => 1,
);
return $items;
}
/**
- * Implementation of hook_nodeapi().
- * @todo
- * Add more config options for like button (size, etc).
+ * Implementation of hook_permission()
+ */
+function fblikebutton_permission() {
+ return array(
+ 'administer fblikebutton' => array(
+ 'title' => t('Administer FB Like button'),
+ 'description' => t('Perform administration tasks for FB Like button')
+ ),
+ 'administer fblikebutton block' => array(
+ 'title' => t('Administer FB Like button block'),
+ 'description' => t('Perform administration tasks for FB Like button block')
+ ),
+ 'access fblikebutton' => array(
+ 'title' => t('Access FB Like button'),
+ ),
+ );
+}
+
+/**
+ * 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()
*/
-function fblikebutton_nodeapi(&$node, $op, $teaser, $page) {
- global $user;
+function fblikebutton_block_info() {
+ $blocks['fblikebutton_block'] = array(
+ 'info' => t('FB Like button'),
+ );
+ return $blocks;
+}
+
+/**
+ * Implementation of hook_block_configure()
+ */
+function fblikebutton_block_configure($delta = '') {
global $base_url;
- $likebase = $base_url . '/';
- $likepath = drupal_get_path_alias($_GET['q']);
- $webpage_to_like = $likebase . $likepath;
- switch ($op) {
- case 'view':
- // Set which node types users can "like".
- $types_to_like = variable_get('fblikebutton_node_types', array('page'));
- $show_faces = variable_get('fblikebutton_show_faces', 'true');
- // 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 .= urlencode($webpage_to_like);
- $likebutton .= '&amp;layout=standard&amp;show_faces=';
- $likebutton .= $show_faces;
- $likebutton .= '&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;
+ $form = array();
+ if ($delta == 'fblikebutton_block') {
+ $form['fblikebutton_block_url'] = array(
+ '#title' => t('Homepage URL'),
+ '#type' => 'textfield',
+ '#default_value' => variable_get('fblikebutton_block_url', $base_url),
+ '#description' => t('URL of your homepage to like'),
+ );
+ $form['block'] = array(
+ '#type' => 'fieldset',
+ '#collapsible' => false,
+ '#collapsed' => false,
+ '#title' => t('Options'),
+ '#description' => '',
+ );
+ $form['block']['fblikebutton_bl_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_bl_layout', 'standard'),
+ '#description' => t('Determines the size and amount of social context next to the button'),
+ );
+ $form['block']['fblikebutton_bl_show_faces'] = array(
+ '#type' => 'select',
+ '#title' => t('Display faces in the box'),
+ '#options' => array('show' => t('Show faces'), 'hide' => t('Do not show faces')),
+ '#default_value' => variable_get('fblikebutton_bl_show_faces', 'show'),
+ '#description' => t('Show profile pictures below the button. Only work on Standard layout'),
+ );
+ $form['block']['fblikebutton_bl_action'] = array(
+ '#type' => 'select',
+ '#title' => t('Verb to display'),
+ '#options' => array('like' => t('Like'), 'recommend' => t('Recommend')),
+ '#default_value' => variable_get('fblikebutton_bl_action', 'like'),
+ '#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'),
+ );
+ $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'),
+ );
}
+ return $form;
}
/**
- * Implementation of hook_perm().
+ * Implementation of hook_block_save()
*/
-function fblikebutton_perm() {
- return array('users may access Like button');
+function fblikebutton_block_save($delta = '', $edit = array()) {
+ if ($delta == 'fblikebutton_block') {
+ variable_set('fblikebutton_bl_layout', $edit['fblikebutton_bl_layout']);
+ variable_set('fblikebutton_bl_layout', $edit['fblikebutton_bl_layout']);
+ variable_set('fblikebutton_bl_show_faces', $edit['fblikebutton_bl_show_faces']);
+ 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']);
+ }
+}
+
+/**
+ * Implementation of hook_block_view()
+ */
+function fblikebutton_block_view($delta = '') {
+ global $base_url;
+ $block = array();
+ switch ($delta) {
+ case 'fblikebutton_block':
+ default:
+ $addr = variable_get('fblikebutton_block_url', $base_url);
+ $conf = array(
+ 'layout' => variable_get('fblikebutton_bl_layout', "standard"),
+ 'action' => variable_get('fblikebutton_bl_action', "like"),
+ '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"),
+ );
+ $block['content'] = _fblikebutton_field($addr, $conf);
+ }
+ return $block;
+}
+
+function _fblikebutton_field($addr, $conf) {
+ $addr = urlencode($addr);
+ $width = "100%";
+ $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";
+ $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>";
+ return $output;
}