You are here

function _easy_social_widget_facebook_markup in Easy Social 7.2

Generate the needed markup for the facebook share link.

Parameters

$url The url to be shared:

$type Generate horizontal or vertical widgets:

$title The title to be shared:

$lang The language of the facebook button:

Return value

string the html markup

1 string reference to '_easy_social_widget_facebook_markup'
easy_social_easy_social_widget in ./easy_social.module
Implements hook_easy_social_widget().

File

includes/easy_social.widgets.inc, line 16
Easy Social default widget functions.

Code

function _easy_social_widget_facebook_markup($url, $type, $title = NULL, $lang = 'en') {

  // Correct for different language identification strings.
  $lang = _easy_social_facebook_langcodes($lang);
  static $js_added;

  // @TODO Subscribe to the 'edge.create' event through FB.Event.subscribe to
  // track successful shares. This will likely be in either a seperate module
  // or a new version.
  if ($type == EASY_SOCIAL_WIDGET_HORIZONTAL) {
    $width = variable_get_value('easy_social_facebook_width_horizontal');
    $type_box = 'button_count';
    $height = '21';
  }
  else {
    $width = variable_get_value('easy_social_facebook_width_vertical');
    $type_box = 'box_count';
    $height = '90';
  }
  $appid = variable_get_value('easy_social_facebook_appid');
  $facebook_type = variable_get_value('easy_social_facebook_widget_type');
  $send_button = variable_get_value('easy_social_facebook_send_button') ? 'true' : 'false';
  $show_faces = variable_get_value('easy_social_facebook_show_faces') ? 'true' : 'false';
  $action = variable_get_value('easy_social_facebook_verb');
  $color_scheme = variable_get_value('easy_social_facebook_color_scheme');
  $font = variable_get_value('easy_social_facebook_font');
  if ($font === 'default') {
    $font = '';
  }
  if ($facebook_type !== 'iframe') {

    // This is done here instead of using the proper hook method because the
    // script is only added in the HTMl5 and XFBML versions, not iframe.
    if (!$js_added) {
      $script = <<<JS
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/{<span class="php-variable">$lang</span>}/all.js#xfbml=1&appId={<span class="php-variable">$appid</span>}";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
JS;
      drupal_add_js($script, 'inline');
      $js_added = TRUE;
    }
  }
  if ($facebook_type === 'html5') {
    $markup = <<<FB
<div class="fb-like" data-href="{<span class="php-variable">$url</span>}" data-send="{<span class="php-variable">$send_button</span>}" data-layout="{<span class="php-variable">$type_box</span>}" data-width="{<span class="php-variable">$width</span>}" data-show-faces="{<span class="php-variable">$show_faces</span>}" data-action="{<span class="php-variable">$action</span>}" data-colorscheme="{<span class="php-variable">$color_scheme</span>}" data-font="{<span class="php-variable">$font</span>}"></div>
FB;
  }
  elseif ($facebook_type === 'xfbml') {
    $markup = <<<FB
<fb:like href="{<span class="php-variable">$url</span>}" send="{<span class="php-variable">$send_button</span>}" layout="{<span class="php-variable">$type_box</span>}" width="{<span class="php-variable">$width</span>}" show_faces="{<span class="php-variable">$show_faces</span>}" action="{<span class="php-variable">$action</span>}" colorscheme="{<span class="php-variable">$color_scheme</span>}" font="{<span class="php-variable">$font</span>}"></fb:like>
FB;
  }
  else {
    $url = drupal_encode_path($url);
    $font = drupal_encode_path($font);
    $markup = <<<FB
<iframe src="//www.facebook.com/plugins/like.php?locale={<span class="php-variable">$lang</span>}&amp;href={<span class="php-variable">$url</span>}&amp;send=false&amp;layout={<span class="php-variable">$type_box</span>}&amp;width={<span class="php-variable">$width</span>}&amp;show_faces={<span class="php-variable">$show_faces</span>}&amp;action={<span class="php-variable">$action</span>}&amp;colorscheme={<span class="php-variable">$color_scheme</span>}&amp;font={<span class="php-variable">$font</span>}&amp;height={<span class="php-variable">$height</span>}&amp;appId={<span class="php-variable">$appid</span>}" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:{<span class="php-variable">$width</span>}px; height:{<span class="php-variable">$height</span>}px;" allowTransparency="true"></iframe>
FB;
  }
  return $markup;
}