You are here

function _addtoany_create_button in AddToAny Share Buttons 5.2

Same name and namespace in other branches
  1. 5.0 addtoany.module \_addtoany_create_button()
  2. 6.3 addtoany.module \_addtoany_create_button()
  3. 6.2 addtoany.module \_addtoany_create_button()
  4. 7 addtoany.module \_addtoany_create_button()
  5. 7.3 addtoany.module \_addtoany_create_button()

Internal function to generate code for AddToAny button and script

Return value

String containing html code for the button

2 calls to _addtoany_create_button()
addtoany_block in ./addtoany.module
Implementation of hook_block().
addtoany_link in ./addtoany.module
Implementation of hook_link().

File

./addtoany.module, line 176
Stand alone module file to handle AddToAny button integration

Code

function _addtoany_create_button($node = NULL, $teaser = FALSE) {
  global $_addtoany_counter, $base_path;
  $_addtoany_counter++;
  if ($_addtoany_counter == 1) {
    drupal_add_css(drupal_get_path('module', 'addtoany') . '/addtoany.css');
  }
  if ($node) {
    $linkname = $node->title;
    $linkurl = url('node/' . $node->nid, NULL, NULL, TRUE);
  }
  else {
    $linkname = drupal_get_title() ? strip_tags(drupal_get_title()) . " - " . variable_get('site_name', 'Drupal') : variable_get('site_name', 'Drupal');
    $linkurl = url(ltrim(request_uri(), "/"), NULL, NULL, TRUE);
  }

  // Drop-down disabled?
  if (variable_get('addtoany_dropdown_disabled', '0')) {
    return;
  }
  global $_addtoany_script, $_addtoany_script_init;
  if (!$_addtoany_script_init) {
    $_addtoany_script = '<script type="text/javascript">';
  }
  else {
    $_addtoany_script .= '<script type="text/javascript">';
  }
  $_addtoany_script .= 'a2a_linkname="' . addslashes($linkname) . '";a2a_linkurl="' . $linkurl . '";';
  if (!$_addtoany_script_init) {
    $_addtoany_script .= variable_get('addtoany_additional_js', '');
    $_addtoany_script .= '</script><script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>';
  }
  else {
    $_addtoany_script .= 'a2a_init("page");</script>';
  }
  $_addtoany_script_init = TRUE;
  $disable_dropdown = variable_get('addtoany_dropdown_disabled', '0');
  $button_setting = variable_get('addtoany_image', 'share_save_171_16.png|171|16');
  if ($button_setting == "custom") {
    $button_image = variable_get('addtoany_custom_image', '');
    $button_width = '';
    $button_height = '';
  }
  else {
    $button = explode('|', $button_setting);
    $button_filename = $button[0];
    $button_width = ' width="' . $button[1] . '"';
    $button_height = ' height="' . $button[2] . '"';
    $button_image = $base_path . drupal_get_path('module', 'addtoany') . '/images/' . $button_filename;
  }
  return sprintf('
      <a%s href="http://www.addtoany.com/share_save?linkurl=%s&amp;linkname=%s"><img src="%s"%s%s %s/></a>
      ', $disable_dropdown ? '' : ' class="a2a_dd"', rawurlencode($linkurl), rawurlencode($linkname), $button_image, $button_width, $button_height, variable_get('addtoany_image_attributes', 'alt="Share/Save"'));
}