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('
![]()
',
$disable_dropdown ? '' : ' class="a2a_dd"',
$link_url,
$link_name,
$button_image,
$button_width,
$button_height,
variable_get('addtoany_image_attributes', 'alt="Share/Save"')
));
}
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | addtoany.zip | 17.03 KB | cmcintosh |
Comments
Comment #1
Fidelix commentedSeems cool man, but how can i apply this?
Comment #2
cmcintosh commented@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.
Comment #3
micropat commentedPlanning to support this in the next version. A complete patch is welcomed in the meantime.
Comment #4
cmcintosh commentedIll 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,.
Comment #5
cmcintosh commentedwell, 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
Comment #6
nitrospectide commentedI 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?
Comment #7
xjmTracking.
Comment #8
cmcintosh commented@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.
Comment #9
micropat commentedComment #10
cmcintosh commentedHard to believe this was 6 years ago, one of my first things i did in drupal.
Comment #11
micropat commentedWhat a trip it's been @cmcintosh :)