I made this hack to the code so that I could be better able to handle Views, etc. As well as being able to through theming place the addtoany button anywhere on a page, not just in the links section.

function _addtoany_create_button($node=NULL, $teaser = FALSE, $title= null, $path = null) {
global $_addtoany_counter, $base_path;

$_addtoany_counter++;
if ($_addtoany_counter == 1) {
drupal_add_css((drupal_get_path('module', 'addtoany') .'/addtoany.css'));
}

_addtoany_create_script($node);

$disable_dropdown = variable_get('addtoany_dropdown_disabled', '0');

if (is_object($node)) {
$link_name = rawurlencode($node->title);
$link_url = rawurlencode(url('node/'. $node->nid, array('absolute' => 1) ));
} else if($path){
$link_name = rawurlencode($title);
$link_url = rawurlencode(url($path, array('absolute' => 1)));
}else { // Front page
$link_name = rawurlencode(variable_get('page_title_front', variable_get('site_name', '')));
$link_url = rawurlencode(url('', array('absolute' => 1)));
}

$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('
Only local images are allowed.
',
$disable_dropdown ? '' : ' class="a2a_dd"',
$link_url,
$link_name,
$button_image,
$button_width,
$button_height,
variable_get('addtoany_image_attributes', 'alt="Share/Save"')
));

}

CommentFileSizeAuthor
#5 addtoany.zip17.03 KBcmcintosh

Comments

Fidelix’s picture

Seems cool man, but how can i apply this?

cmcintosh’s picture

@fidelix it is more of a patch to the existing module, what it adds is a $path argument to the existing function, which you can then use to feed in your current url or whichever url you want to have the addtoany module share.

micropat’s picture

Assigned: Unassigned » micropat
Status: Active » Needs work

Planning to support this in the next version. A complete patch is welcomed in the meantime.

cmcintosh’s picture

Ill roll a patch here in a minute. One thing to keep in mind and this is probably something to do with the JS, is that if you have multiple AddToAny buttons on a page, then only the first instance will get the hover effects, the others will still link you into the AddToAny interface, but maybe there is a way to fix this,.

cmcintosh’s picture

StatusFileSize
new17.03 KB

well, looks like i am having issues rolling a patch. I use Git for my version control and do not see a method to roll on right now. Something they are working on. Ill include the zip off what i put together and if someone that has patch abilities would roll one, it would be great.

McIntosh Designs - http://chrismcintoshdesigns.com

nitrospectide’s picture

I thought that because the widget could be placed in a block, it would do this automatically. I have my block set up, and it only passes the base url, not the path in the address bar. Is this why? If so, what does the block placement do without the above capability?

xjm’s picture

Tracking.

cmcintosh’s picture

@nitrospectide you could pass in the full url if you needed to, all I did was add handling for you to pass in a custom path into the addtoany widget, so that doing something like:

print _addtoany_create_button('', false, 'My Custom AddToAny Button', 'http://mysite.com/'.$_GET['q']);

Should get you something that works fine. This biggest reason i didnt hard code in the path handling was that you could then setup a views page to point someone to the proper page your wanting them to go do, or you could point them to the first view page.

micropat’s picture

Status: Needs work » Closed (outdated)
cmcintosh’s picture

Hard to believe this was 6 years ago, one of my first things i did in drupal.

micropat’s picture

Assigned: micropat » Unassigned

What a trip it's been @cmcintosh :)