Newer
Older
Vesa Palmu
committed
* @file
* Stand alone module file to handle AddThis button integration
*/
$perms[] = 'administer addthis';
$perms[] = 'view addthis';
return $perms;
}
Vesa Palmu
committed
/**
* Implementation of hook_link().
*/
Vesa Palmu
committed
function addthis_link($type, $node=NULL, $teaser = FALSE) {
$links = array();
Vesa Palmu
committed
if ($type === 'node' && user_access('view addthis')) {
Vesa Palmu
committed
if (($teaser && variable_get('addthis_display_in_teasers', '0')) ||
(!$teaser && variable_get('addthis_display_in_links', '0'))) {
$links['addthis'] = array(
'title' => _addthis_create_button($node, $teaser),
'html' => TRUE,
);
}
Vesa Palmu
committed
return $links;
}
/**
* Implementation of hook_menu().
*/
function addthis_menu() {
$items = array();
$items['admin/settings/addthis'] = array(
'description' => t('Set username and customize look and feel for <a href="http://www.addthis.com/">AddThis</a> button.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('addthis_admin_settings'),
'access arguments' => array('administer addthis'),
'file' => 'addthis.admin.inc',
/**
* Implementation of hook_block().
*/
function addthis_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('AddThis button');
return $blocks;
}
else if ($op == 'view' && user_access('view addthis')) {
$block['subject'] = t('AddThis');
$block['content'] = _addthis_create_button();
return $block;
}
}
/**
* Internal function to generate code for AddThis button
*
* @return
* String containing html code for the button
*/
Vesa Palmu
committed
function _addthis_create_button($node=NULL, $teaser = FALSE) {
global $_addthis_counter;
$_addthis_counter++;
if ($_addthis_counter == 1) {
drupal_add_css((drupal_get_path('module', 'addthis') .'/addthis.css'));
drupal_add_js(sprintf('
addthis_pub = \'%s\';
addthis_logo = \'%s\';
addthis_logo_background = \'%s\';
addthis_logo_color = \'%s\';
addthis_brand = \'%s\';
addthis_options = \'%s\';
',
addslashes(variable_get('addthis_username', 'my-username')),
addslashes(variable_get('addthis_logo', 'http://www.addthis.com/images/yourlogo.png')),
addslashes(variable_get('addthis_logo_background', 'EFEFFF')),
addslashes(variable_get('addthis_logo_color', '666699')),
addslashes(variable_get('addthis_brand', 'Your Site')),
addslashes(variable_get('addthis_options', 'favorites, email, digg, delicious, myspace, facebook, google, live, more'))
if (variable_get('addthis_dropdown_disabled', '0')) {
return ( sprintf('
<div class="addthis"><a href="http://www.addthis.com/bookmark.php"
onclick="addthis_url = location.href; addthis_title = document.title; return addthis_click(this);">
<img src="%s" width="%d" height="%d" %s /></a></div>
',
addslashes(variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif')),
addslashes(variable_get('addthis_image_width', '125')),
addslashes(variable_get('addthis_image_height', '16')),
addslashes(variable_get('addthis_image_attributes', 'alt=""'))
return ( sprintf('
<div class="addthis"><a href="http://www.addthis.com/bookmark.php"
onmouseover="return addthis_open(this, \'\', \'%s\', \'%s\')"
onmouseout="addthis_close()"
onclick="return addthis_sendto()"><img src="%s" width="%d" height="%d" %s /></a></div>
<script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script>
',
$teaser ? url('node/'. $node->nid, array('absolute' => 1) ) : '[URL]',
$teaser ? addslashes($node->title) : '[TITLE]',
addslashes(variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif')),
addslashes(variable_get('addthis_image_width', '125')),
addslashes(variable_get('addthis_image_height', '16')),
variable_get('addthis_image_attributes', 'alt=""')
));
}