You are here

function theme_google_plusone_button in Google Plus One Button | Google+ Badge 7

Same name and namespace in other branches
  1. 6 google_plusone.module \theme_google_plusone_button()

Returns HTML for the Google +1 button.

Parameters

$variables: An associative array containing:

  • syntax: (optional) A string. If contains 'g:plusone' will be used that syntax. Otherwise, HTML5 syntax by default.
  • url: (optional) A string containing the URL to use in the button, or '<front>' (language-aware) or leaving it empty, the URL will be deducted on-the-fly by Google.
  • node: (optional) The node object. (Only will be use its nid)
  • size: (optional) A string 'small', 'medium', 'standard' (default), 'tall'
  • annotation: (optional) A string 'none', 'bubble' (default), 'inline'
  • width: (optional) An integer to indicate width of button in case of inline annotation. Default 250
  • css: (optional) A string with inline CSS rules for the wrapper.
3 theme calls to theme_google_plusone_button()
google_plusone_block_view in ./google_plusone.module
Implements hook_block_view().
google_plusone_node_view in ./google_plusone.module
Implements hook_node_view().
_google_plusone_ds_field in ./google_plusone.module
Callback for Display Suite field hook.

File

./google_plusone.module, line 122

Code

function theme_google_plusone_button($variables) {

  // This flag will be used later to decide if including plusone.js script
  // in google_plusone_page_alter().
  $add_js =& drupal_static('google_plusone_js_added', FALSE);
  $add_js = TRUE;

  // URL negotiation
  $url = '';
  if (!empty($variables['node']->nid)) {
    if ($variables['alias'] === 'aliased') {
      $url = url('node/' . $variables['node']->nid, array(
        'absolute' => TRUE,
      ));
    }
    else {
      $url = url('node/' . $variables['node']->nid, array(
        'absolute' => TRUE,
        'alias' => TRUE,
      ));
    }
  }
  elseif (!empty($variables['url'])) {

    // See block settings to understand the 'url' setting
    if ($variables['url'] === '<front>') {
      $url = url('', array(
        'absolute' => TRUE,
      ));

      // language-aware
    }
    else {
      $url = check_url($variables['url']);
    }
  }
  $syntax = empty($variables['syntax']) ? '' : $variables['syntax'];
  $data = $syntax === 'g:plusone' ? '' : 'data-';

  // HTML5 valid attributes must have 'data-' prefix
  $url = empty($url) ? '' : $data . 'href="' . $url . '" ';
  $size = empty($variables['size']) ? '' : $data . 'size="' . check_plain($variables['size']) . '" ';
  $annotation = empty($variables['annotation']) ? '' : $data . 'annotation="' . check_plain($variables['annotation']) . '" ';
  $width = empty($variables['width']) ? '' : $data . 'width="' . check_plain($variables['width']) . '" ';
  $tag_start = $syntax === 'g:plusone' ? '<g:plusone ' : '<div class="g-plusone" ';
  $tag_end = $syntax === 'g:plusone' ? '></g:plusone>' : '></div>';

  // Putting it all together
  $button = $tag_start . $url . $size . $annotation . $width . $tag_end;

  // Wrap it and serve it
  if ($variables['css'] !== 'nowrapper') {
    $css = empty($variables['css']) ? '' : 'style="' . check_plain($variables['css']) . '"';
    $button = '<div class="g-plusone-wrapper" ' . $css . ' >' . $button . '</div>';
  }
  return $button;
}