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') && $teaser ? variable_get('addthis_display_in_teasers', '0') : variable_get('addthis_display_in_links', '0') ) {
Vesa Palmu
committed
$links['addthis'] = array(
Vesa Palmu
committed
'html' => TRUE,
);
Vesa Palmu
committed
return $links;
}
/**
* Implementation of hook_menu().
*/
function addthis_menu() {
$items = array();
$items['admin/settings/addthis'] = array(
'title' => t('AddThis module settings'),
'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'),
/**
* Administration settings form.
*
* @return
* The completed form definition.
*/
function addthis_admin_settings() {
$form = array();
$form['addthis_general_settings'] = array(
'#type' => 'fieldset',
'#title' => t('General settings'),
);
$form['addthis_general_settings']['addthis_username'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#default_value' => variable_get('addthis_username', 'my-username'),
'#description' => t('Your username for <a href="http://www.addthis.com/">addthis.com</a>. Example: my-username'),
);
$form['addthis_general_settings']['addthis_display_in_links'] = array(
'#type' => 'checkbox',
Vesa Palmu
committed
'#title' => t('Display on node pages'),
'#default_value' => variable_get('addthis_display_in_links', '0'),
Vesa Palmu
committed
'#description' => t('Display an AddThis button always on a node page\'s links section.'),
);
$form['addthis_general_settings']['addthis_display_in_teasers'] = array(
'#type' => 'checkbox',
'#title' => t('Display in node teasers'),
'#default_value' => variable_get('addthis_display_in_teasers', '0'),
'#description' => t('Display an AddThis button in the node teasers.'),
Vesa Palmu
committed
'#type' => 'fieldset',
'#title' => t('Button image settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['addthis_button_settings']['addthis_image'] = array(
'#type' => 'textfield',
'#title' => t('Button image url'),
'#default_value' => variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif'),
'#description' => t('URL for small image in the button. Example: http://s9.addthis.com/button1-share.gif'),
);
$form['addthis_button_settings']['addthis_image_width'] = array(
'#type' => 'textfield',
'#title' => t('Button image width'),
'#default_value' => variable_get('addthis_image_width', '125'),
'#description' => t('Width for button image. Example: 125'),
);
$form['addthis_button_settings']['addthis_image_height'] = array(
'#type' => 'textfield',
'#title' => t('Button image height'),
'#default_value' => variable_get('addthis_image_height', '16'),
'#description' => t('Height for button image. Example: 16'),
);
$form['addthis_button_settings']['addthis_image_attributes'] = array(
'#type' => 'textfield',
'#title' => t('Button image HTML attributes'),
Vesa Palmu
committed
'#default_value' => variable_get('addthis_image_attributes', 'alt=""'),
'#description' => t('Extra HTML attributes for img tag. Example: alt=""'),
Vesa Palmu
committed
'#type' => 'fieldset',
'#title' => t('Widget settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
);
$form['addthis_widget_settings']['addthis_logo'] = array(
'#type' => 'textfield',
'#title' => t('Logo url'),
'#default_value' => variable_get('addthis_logo', 'http://www.addthis.com/images/yourlogo.png'),
'#description' => t('The logo to display on the popup window (about 200x50 pixels). The popup window is show when the user selects the \'More\' choice. Example: http://www.your-website.com/img/mylogo.gif'),
);
$form['addthis_widget_settings']['addthis_logo_background'] = array(
'#type' => 'textfield',
'#title' => t('Logo background color'),
'#default_value' => variable_get('addthis_logo_background', 'EFEFFF'),
'#description' => t('The color to use as a background around the logo in the popup. Example: EFEFEF'),
);
$form['addthis_widget_settings']['addthis_logo_color'] = array(
'#type' => 'textfield',
'#title' => t('Logo text color'),
'#default_value' => variable_get('addthis_logo_color', '666699'),
'#description' => t('The color to use for the text next to the logo in the popup. Example: 666666'),
);
$form['addthis_widget_settings']['addthis_brand'] = array(
'#type' => 'textfield',
'#title' => t('Brand text'),
'#default_value' => variable_get('addthis_brand', 'Your Site'),
'#description' => t('The brand name to display in the drop-down (top right). Example: My Website'),
);
$form['addthis_widget_settings']['addthis_options'] = array(
'#type' => 'textfield',
'#title' => t('Options'),
'#default_value' => variable_get('addthis_options', 'favorites, email, digg, delicious, myspace, facebook, google, live, more'),
'#description' => t('A comma-separated ordered list of options to include in the drop-down. Example: favorites, email, digg, delicious, more<br/>Currently supported options:<br/>
delicious, digg, email, favorites, facebook, fark, furl, google, live, myweb, myspace, newsvine, reddit, slashdot, stumbleupon, technorati, twitter, more'),
);
$form['addthis_widget_settings']['addthis_offset_top'] = array(
'#type' => 'textfield',
'#title' => t('Offset top'),
'#default_value' => variable_get('addthis_offset_top', '2'),
'#description' => t('Vertical offset for the drop-down window (in pixels). Example: 2'),
);
$form['addthis_widget_settings']['addthis_offset_left'] = array(
'#type' => 'textfield',
'#title' => t('Offset top'),
'#default_value' => variable_get('addthis_offset_left', '2'),
'#description' => t('Horizontal offset for the drop-down window (in pixels). Example: 2'),
);
return system_settings_form($form);
/**
* 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\';
addthis_offset_top = \'%d\';
addthis_offset_left = \'%d\';
',
variable_get('addthis_user', 'my-username'),
variable_get('addthis_logo', 'http://www.addthis.com/images/yourlogo.png'),
variable_get('addthis_logo_background', 'EFEFFF'),
variable_get('addthis_logo_color', '666699'),
variable_get('addthis_brand', 'Your Site'),
variable_get('addthis_options', 'favorites, email, digg, delicious, myspace, facebook, google, live, more'),
variable_get('addthis_offset_top', '2'),
variable_get('addthis_offset_left', '2')
), 'inline');
Vesa Palmu
committed
<div class="addthis"><a href="http://www.addthis.com/bookmark.php"
Vesa Palmu
committed
onmouseover="return addthis_open(this, \'\', \'%s\', \'%s\')"
Vesa Palmu
committed
onmouseout="addthis_close()"
Vesa Palmu
committed
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]',
Vesa Palmu
committed
$teaser ? addslashes($node->title) : '[TITLE]',
variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif'),
variable_get('addthis_image_width', '125'),
variable_get('addthis_image_height', '16'),
Vesa Palmu
committed
variable_get('addthis_image_attributes', 'alt=""')