type, 1)) &&
(($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,
);
}
}
return $links;
}
/**
* Implementation of hook_menu().
*/
function addthis_menu() {
$items = array();
$items['admin/settings/addthis'] = array(
'title' => 'AddThis',
'description' => 'Set username and customize look and feel for AddThis button.',
'page callback' => 'drupal_get_form',
'page arguments' => array('addthis_admin_settings'),
'access arguments' => array('administer addthis'),
'file' => 'addthis.admin.inc',
);
return $items;
}
/**
* Implementation of hook_block().
*/
function addthis_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('AddThis button');
return $blocks;
}
elseif ($op == 'view' && user_access('view addthis')) {
$block['subject'] = t('AddThis');
$block['content'] = _addthis_create_button();
return $block;
}
}
/**
* Implementation of hook_form_alter().
*/
function addthis_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
$form['workflow']['addthis_nodetype'] = array(
'#type' => 'checkbox',
'#title' => t('Show AddThis button on this type of node'),
'#default_value' => variable_get('addthis_nodetype_' . $form['#node_type']->type, 1),
'#description' => t('Select whether the AddThis button should be shown or not on this type of node.'),
);
}
}
/**
* Implementation of hook_theme().
*/
function addthis_theme() {
return array(
'addthis_button' => array(
'arguments' => array(
'node' => NULL,
'teaser' => NULL,
),
),
);
}
/**
* Implementation of hook_views_api().
*/
function addthis_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'addthis'),
);
}
/**
* Implementation of hook_ds_fields().
*/
function addthis_ds_fields($type_name, $build_mode, $extra) {
if (variable_get('addthis_nodetype_' . $type_name, 1)) {
return array(
'nd' => array(
'addthis' => array(
'title' => t('AddThis'),
'type' => DS_FIELD_TYPE_FUNCTION,
'status' => DS_FIELD_STATUS_STATIC,
'properties' => array(
'formatters' => array(
'_addthis_ds_create_button' => t('AddThis'),
),
),
),
),
);
}
}
/**
* Internal function for Display Suite to return the code for AddThis button.
*/
function _addthis_ds_create_button($field) {
if (isset($field['object'])) {
return _addthis_create_button($field['object'], TRUE);
}
}
/**
* Internal function to generate code for AddThis button
*
* @return
* String containing html code for the button
*/
function _addthis_create_button($node=NULL, $teaser = FALSE) {
global $_addthis_counter;
$_addthis_counter++;
$brand = variable_get('addthis_brand', '');
if ($brand == '') {
$brand = variable_get('site_name', 'Drupal');
}
$addthis_options = variable_get('addthis_options', 'favorites, email, digg, delicious, myspace, facebook, google, live, more');
$addthis_options = str_replace("\n", "", $addthis_options);
$addthis_options = str_replace("\r", "", $addthis_options);
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\';
addthis_disable_flash = \'%s\';
',
addslashes(check_plain(variable_get('addthis_username', 'my-username'))),
addslashes(check_plain(variable_get('addthis_logo', 'http://www.addthis.com/images/yourlogo.png'))),
addslashes(check_plain(variable_get('addthis_logo_background', 'EFEFFF'))),
addslashes(check_plain(variable_get('addthis_logo_color', '666699'))),
addslashes(check_plain($brand)),
addslashes(check_plain($addthis_options)),
variable_get('addthis_disable_flash', FALSE) ? 'true' : 'false'
), 'inline');
}
return theme('addthis_button', $node, $teaser);
}
/**
* Theme the AddThis button.
*/
function theme_addthis_button($node, $teaser) {
global $_addthis_counter;
// Fix IE's bug.
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
$protocol = $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
drupal_add_link(array(
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => $protocol."s7.addthis.com/static/r07/widget02.css",
));
}
if (variable_get('addthis_dropdown_disabled', '0')) {
$button = sprintf('
',
$_SERVER['HTTPS'] == 'on' ? addslashes(check_plain(variable_get('addthis_image_secure', 'https://secure.addthis.com/button1-share.gif'))) : addslashes(check_plain(variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif'))),
variable_get('addthis_image_width', '125'),
variable_get('addthis_image_height', '16'),
trim(check_plain(strip_tags(variable_get('addthis_image_attributes_alt', 'share')))),
trim(check_plain(strip_tags(variable_get('addthis_image_attributes_class', 'addthisimage'))))
);
}
else {
$button = sprintf('
',
$teaser ? url('node/'. $node->nid, array('absolute' => 1) ) : '[URL]',
$teaser ? addslashes($node->title) : '[TITLE]',
$teaser ? url('node/'. $node->nid, array('absolute' => 1) ) : '[URL]',
$teaser ? addslashes($node->title) : '[TITLE]',
$_SERVER['HTTPS'] == 'on' ? addslashes(check_plain(variable_get('addthis_image_secure', 'https://secure.addthis.com/button1-share.gif'))) : addslashes(check_plain(variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif'))),
variable_get('addthis_image_width', '125'),
variable_get('addthis_image_height', '16'),
trim(check_plain(strip_tags(variable_get('addthis_image_attributes_alt', 'share')))),
trim(check_plain(strip_tags(variable_get('addthis_image_attributes_class', 'addthisimage'))))
);
if ($_addthis_counter == 1) {
$button .= sprintf('';
}
}
return $button;
}