From cebe74c25878b5fa984796e3ca011b864c6c13a8 Mon Sep 17 00:00:00 2001
From: Roman Zimmermann <roman@more-onion.com>
Date: Sat, 17 Mar 2012 19:29:29 +0100
Subject: [PATCH] support for the html5 button format

---
 fblikebutton.admin.inc |    6 ++++++
 fblikebutton.module    |   46 ++++++++++++++++++++++++++++++++++------------
 2 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/fblikebutton.admin.inc b/fblikebutton.admin.inc
index fd1a259..b883049 100644
--- a/fblikebutton.admin.inc
+++ b/fblikebutton.admin.inc
@@ -104,6 +104,12 @@ function fblikebutton_admin_settings() {
     '#default_value' => variable_get('fblikebutton_language', 'en_US'),
     '#description' => t('Specific language to use. Default is English. Examples:<br/>French (France): <em>fr_FR</em><br/>French (Canada): <em>fr_CA</em>'),
   );
+	$form['fblikebutton_format'] = array(
+    '#type' => 'select',
+    '#title' => t('Format'),
+		'#description' => t("Format for the facebook like buttons. iframes work without the facebook connect javascript but don't fire javascript events. If you use fbconnect anyway use the HTML5 version."),
+		'#options' => array('iframe' => t('iframe-element'), 'html5' => t('HTML5-div')),
+	);
   return system_settings_form($form);
 }
 
diff --git a/fblikebutton.module b/fblikebutton.module
index 0992cb4..d99e46f 100644
--- a/fblikebutton.module
+++ b/fblikebutton.module
@@ -256,19 +256,41 @@ function fblikebutton_block_view($delta = '') {
 }
 
 function _fblikebutton_field($webpage_to_like, $conf) {
-  $webpage_to_like = urlencode($webpage_to_like);
+	switch (variable_get('fblikebutton_format', 'iframe')) {
+		case 'iframe':
+			return _fblikebutton_field_iframe($webpage_to_like, $conf);
+		case 'html5':
+			return _fblikebutton_field_html5($webpage_to_like, $conf);
+	}
+}
+
+function _fblikebutton_field_iframe($webpage_to_like, $conf) {
+  $conf['href'] = $webpage_to_like;
+  $other_css = $conf['other_css'];
   $width = $conf['width'];
   $height = $conf['height'];
-  $layout = $conf['layout'];
-  $action = $conf['action'];
-  $colorscheme = $conf['color_scheme'];
-  $show_faces = $conf['show_faces'];
-  $font = $conf['font'];
-//  $send = $conf['send'];
-  $other_css = $conf['other_css'];
-  $language = $conf['language'];
-  $params = "href={$webpage_to_like}&layout={$layout}&show_faces={$show_faces}&width={$width}px&font={$font}&height={$height}px&action={$action}&colorscheme={$colorscheme}&locale={$language}";
-  $src = htmlentities($params);
-  $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>';
+	unset($conf['other_css']);
+	unset($conf['width']);
+	unset($conf['height']);
+
+	$url = url('https://www.facebook.com/plugins/like.php', array('query' => $conf, 'external' => TRUE));
+	
+  $output = '<iframe src="'. $url . '" scrolling="no" frameborder="0" style="border: none; overflow: hidden; width: ' . $width . 'px; height: ' . $height . 'px;' . $other_css . '" allowTransparency="true"></iframe>';
   return $output;
 }
+
+function _fblikebutton_field_html5($webpage_to_like, $conf) {
+  $conf['href'] = $webpage_to_like;
+  $other_css = $conf['other_css'];
+	unset($conf['other_css']);
+  
+	$params = array();
+	foreach ($conf as $key => $v) {
+		$params['data-' . str_replace('_', '-', $key)] = $v;
+	}
+	if ($other_css) {
+		$params['style'] = $other_css;
+	}
+	$output = '<div class="fb-like" ' . drupal_attributes($params) . '></div>';
+  return $output;
+}
\ No newline at end of file
-- 
1.7.3.4

