function theme_google_plusone_badge in Google Plus One Button | Google+ Badge 7
Same name and namespace in other branches
- 6 google_plusone.module \theme_google_plusone_badge()
Returns HTML for the Google +1 badge.
Parameters
$variables: An associative array containing:
- page_id: (required) A URL of the Google+ page. Example 'https://plus.google.com/109000232948849684578'
- style: (optional) A string 'badge', 'smallbadge', 'smallicon', 'mediumicon', 'largeicon'. By default 'badge'
- width: (optional) A string containing the width of badge in pixels (from 100 to 1024). By default '300'
- theme: (optional) A string containing 'light' or 'dark', the only 2 themes supported by Google+ badge. By default 'light'
- custom_name: (optional) A string with the Custom name of your Google+ page. It's only used in the Icon style
2 theme calls to theme_google_plusone_badge()
- google_plusone_block_view in ./
google_plusone.module - Implements hook_block_view().
- google_plusone_demo_badge_preview in ./
google_plusone.admin.inc - Page callback for previewing the Google+ badge in block configuration page. It's meant to be called from an iframe element
File
- ./
google_plusone.module, line 182
Code
function theme_google_plusone_badge($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);
// The URL with the page id is mandatory
if (empty($variables['page_id'])) {
return '';
}
else {
$page_id = check_url($variables['page_id']);
}
$icon_sizes = array(
'smallicon' => '16',
'mediumicon' => '32',
'largeicon' => '64',
);
if (key_exists($variables['style'], $icon_sizes)) {
$custom_name = check_plain($variables['custom_name']);
$icon_size = $icon_sizes[$variables['style']];
$badge = '<a href="' . $page_id . '?prsrc=3" style="display:inline-block;text-decoration:none;color:#333;text-align:center;font:13px/16px arial,sans-serif;white-space:nowrap;">';
if ($icon_size === '64') {
$badge .= '<img src="https://ssl.gstatic.com/images/icons/gplus-64.png" alt="" style="border:0;width:64px;height:64px;margin-bottom:7px;">';
$badge .= '<br/><span style="font-weight:bold;">' . t($custom_name) . '</span><br/><span> ' . t('on') . ' Google+</span></a>';
}
elseif ($icon_size === '32') {
$badge .= '<span style="display:inline-block;font-weight:bold;vertical-align:top;margin-right:5px;margin-top:8px;">' . t($custom_name) . '</span>';
$badge .= '<span style="display:inline-block;vertical-align:top;margin-right:15px;margin-top:8px;">' . t('on') . '</span>';
$badge .= '<img src="https://ssl.gstatic.com/images/icons/gplus-32.png" alt="" style="border:0;width:32px;height:32px;"></a>';
}
else {
$badge .= '<span style="display:inline-block;font-weight:bold;vertical-align:top;margin-right:5px;margin-top:0px;">' . t($custom_name) . '</span>';
$badge .= '<span style="display:inline-block;vertical-align:top;margin-right:13px;margin-top:0px;">' . t('on') . '</span>';
$badge .= '<img src="https://ssl.gstatic.com/images/icons/gplus-16.png" alt="" style="border:0;width:16px;height:16px;"></a>';
}
}
elseif ($variables['style'] == 'page') {
$add_js = TRUE;
$width = (int) $variables['width'];
$badge = '<div class="g-page" data-rel="publisher" data-href="' . check_url($page_id) . '" data-width="' . check_plain($width) . '"></div>';
}
else {
$add_js = TRUE;
$width = (int) $variables['width'];
$height = 131;
if ($variables['style'] === 'small_badge' && $width >= 170) {
$height = 69;
// Calculations based on what you get in the Google Badge Tool.
}
$theme = check_plain($variables['theme']);
$syntax = 'HTML5';
// todo: provide option in block settings.
$tag_start = $syntax === 'g:plus' ? '<g:plus ' : '<div class="g-plus"';
$tag_end = $syntax === 'g:plus' ? '></g:plus>' : '></div>';
$badge = '<div class="g-badge-wrapper">' . $tag_start . ' data-href="' . $page_id . '" data-theme="' . $theme . '" data-height="' . $height . '" data-width="' . $width . '"' . $tag_end . '</div>';
}
return $badge;
}