You are here

function _addtoany_create_button in AddToAny Share Buttons 7.3

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

Internal function to generate code for AddToAny buttons

Parameters

object $node [optional]:

object $teaser [optional]:

Return value

String containing HTML code for the buttons

3 calls to _addtoany_create_button()
addtoany_block_view in ./addtoany.module
Implements hook_block_view().
addtoany_handler_field_addtoany_link::render in views/addtoany_handler_field_addtoany_link.inc
Render the field.
addtoany_node_view in ./addtoany.module
Implementation of hook_node_view().

File

./addtoany.module, line 221
Stand alone module file to handle AddToAny buttons integration

Code

function _addtoany_create_button($node = NULL) {
  global $_addtoany_counter, $base_path;
  $_addtoany_counter++;
  if ($_addtoany_counter == 1) {
    drupal_add_css(drupal_get_path('module', 'addtoany') . '/addtoany.css');
  }
  $additional_html = variable_get('addtoany_additional_html', '');
  $additional_html_placement = variable_get('addtoany_additional_html_placement', 'before');
  if (is_object($node)) {
    $link_name = module_exists('page_title') ? page_title_page_get_title() : $node->title;
    $link_url = url('node/' . $node->nid, array(
      'absolute' => 1,
    ));
  }
  else {

    // Front page
    $link_name = module_exists('page_title') ? page_title_page_get_title() : variable_get('site_name', 'Drupal');
    $link_url = url('<front>', array(
      'absolute' => 1,
    ));
  }
  $javascript = _addtoany_create_script($_addtoany_counter, $link_name, $link_url);
  $button_setting = variable_get('addtoany_image', 'share_save_171_16.png|171|16');
  if ($button_setting == "custom") {
    $button_image = check_url(variable_get('addtoany_custom_image', ''));
    $button_width = '';
    $button_height = '';
  }
  elseif ($button_setting != "text") {
    $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;
  }
  $button_text = check_plain(variable_get('addtoany_link_text', ''));
  if (strlen($button_text) > 0) {
    $button_text = ' ' . $button_text;
  }
  $button_innerHTML = $button_setting == "text" ? $button_text : sprintf('<img src="%s"%s%s %s/>%s', $button_image, $button_width, $button_height, filter_xss(variable_get('addtoany_image_attributes', 'alt="Share this"'), array()), $button_text);
  return sprintf('
		<span class="a2a_kit a2a_target addtoany_list" id="da2a_%s">
			%s<a%s href="http://www.addtoany.com/share_save#url=%s&amp;title=%s">%s</a>%s
		</span>
		%s
		', $_addtoany_counter, $additional_html_placement == 'before' ? $additional_html : '', ' class="a2a_dd addtoany_share_save"', rawurlencode($link_url), rawurlencode($link_name), $button_innerHTML, $additional_html_placement == 'after' ? $additional_html : '', $javascript);
}