6 * Stand alone module file to handle AddThis button integration
10 * Implementation of hook_perm().
12 function addthis_perm() {
13 $perms[] = 'administer addthis';
14 $perms[] = 'view addthis';
19 * Implementation of hook_link().
21 function addthis_link($type, $node=NULL
, $teaser = FALSE
) {
24 if ($type == 'node' && user_access('view addthis') && $teaser ?
variable_get('addthis_display_in_teasers', '0') : variable_get('addthis_display_in_links', '0') ) {
25 $links['addthis'] = array(
26 'title' => _addthis_create_button($node,$teaser),
34 * Implementation of hook_menu().
36 function addthis_menu() {
39 $items['admin/settings/addthis'] = array(
40 'title' => t('AddThis module settings'),
41 'description' => t('Set username and customize look and feel for <a href="http://www.addthis.com/">AddThis</a> button.'),
42 'page callback' => 'drupal_get_form',
43 'page arguments' => array('addthis_admin_settings'),
44 'access arguments' => array('administer addthis'),
51 * Administration settings form.
54 * The completed form definition.
56 function addthis_admin_settings() {
59 $form['addthis_general_settings'] = array(
60 '#type' => 'fieldset',
61 '#title' => t('General settings'),
63 $form['addthis_general_settings']['addthis_username'] = array(
64 '#type' => 'textfield',
65 '#title' => t('Username'),
66 '#default_value' => variable_get('addthis_username', 'my-username'),
67 '#description' => t('Your username for <a href="http://www.addthis.com/">addthis.com</a>. Example: my-username'),
69 $form['addthis_general_settings']['addthis_display_in_links'] = array(
70 '#type' => 'checkbox',
71 '#title' => t('Display on node pages'),
72 '#default_value' => variable_get('addthis_display_in_links', '0'),
73 '#description' => t('Display an AddThis button always on a node page\'s links section.'),
75 $form['addthis_general_settings']['addthis_display_in_teasers'] = array(
76 '#type' => 'checkbox',
77 '#title' => t('Display in node teasers'),
78 '#default_value' => variable_get('addthis_display_in_teasers', '0'),
79 '#description' => t('Display an AddThis button in the node teasers.'),
82 $form['addthis_button_settings'] = array(
83 '#type' => 'fieldset',
84 '#title' => t('Button image settings'),
85 '#collapsible' => TRUE
,
88 $form['addthis_button_settings']['addthis_image'] = array(
89 '#type' => 'textfield',
90 '#title' => t('Button image url'),
91 '#default_value' => variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif'),
92 '#description' => t('URL for small image in the button. Example: http://s9.addthis.com/button1-share.gif'),
94 $form['addthis_button_settings']['addthis_image_width'] = array(
95 '#type' => 'textfield',
96 '#title' => t('Button image width'),
97 '#default_value' => variable_get('addthis_image_width', '125'),
98 '#description' => t('Width for button image. Example: 125'),
100 $form['addthis_button_settings']['addthis_image_height'] = array(
101 '#type' => 'textfield',
102 '#title' => t('Button image height'),
103 '#default_value' => variable_get('addthis_image_height', '16'),
104 '#description' => t('Height for button image. Example: 16'),
106 $form['addthis_button_settings']['addthis_image_attributes'] = array(
107 '#type' => 'textfield',
108 '#title' => t('Button image HTML attributes'),
109 '#default_value' => variable_get('addthis_image_attributes', 'alt=""'),
110 '#description' => t('Extra HTML attributes for img tag. Example: alt=""'),
113 $form['addthis_widget_settings'] = array(
114 '#type' => 'fieldset',
115 '#title' => t('Widget settings'),
116 '#collapsible' => TRUE
,
117 '#collapsed' => TRUE
,
119 $form['addthis_widget_settings']['addthis_logo'] = array(
120 '#type' => 'textfield',
121 '#title' => t('Logo url'),
122 '#default_value' => variable_get('addthis_logo', 'http://www.addthis.com/images/yourlogo.png'),
123 '#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'),
125 $form['addthis_widget_settings']['addthis_logo_background'] = array(
126 '#type' => 'textfield',
127 '#title' => t('Logo background color'),
128 '#default_value' => variable_get('addthis_logo_background', 'EFEFFF'),
129 '#description' => t('The color to use as a background around the logo in the popup. Example: EFEFEF'),
131 $form['addthis_widget_settings']['addthis_logo_color'] = array(
132 '#type' => 'textfield',
133 '#title' => t('Logo text color'),
134 '#default_value' => variable_get('addthis_logo_color', '666699'),
135 '#description' => t('The color to use for the text next to the logo in the popup. Example: 666666'),
137 $form['addthis_widget_settings']['addthis_brand'] = array(
138 '#type' => 'textfield',
139 '#title' => t('Brand text'),
140 '#default_value' => variable_get('addthis_brand', 'Your Site'),
141 '#description' => t('The brand name to display in the drop-down (top right). Example: My Website'),
143 $form['addthis_widget_settings']['addthis_options'] = array(
144 '#type' => 'textfield',
145 '#title' => t('Options'),
146 '#default_value' => variable_get('addthis_options', 'favorites, email, digg, delicious, myspace, facebook, google, live, more'),
147 '#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/>
148 delicious, digg, email, favorites, facebook, fark, furl, google, live, myweb, myspace, newsvine, reddit, slashdot, stumbleupon, technorati, twitter, more'),
150 $form['addthis_widget_settings']['addthis_offset_top'] = array(
151 '#type' => 'textfield',
152 '#title' => t('Offset top'),
153 '#default_value' => variable_get('addthis_offset_top', '2'),
154 '#description' => t('Vertical offset for the drop-down window (in pixels). Example: 2'),
156 $form['addthis_widget_settings']['addthis_offset_left'] = array(
157 '#type' => 'textfield',
158 '#title' => t('Offset top'),
159 '#default_value' => variable_get('addthis_offset_left', '2'),
160 '#description' => t('Horizontal offset for the drop-down window (in pixels). Example: 2'),
162 return system_settings_form($form);
166 * Implementation of hook_block().
168 function addthis_block($op = 'list', $delta = 0) {
170 $blocks[0]['info'] = t('AddThis button');
173 else if ($op == 'view' && user_access('view addthis')) {
174 $block['subject'] = t('AddThis');
175 $block['content'] = _addthis_create_button();
181 * Internal function to generate code for AddThis button
184 * String containing html code for the button
186 function _addthis_create_button($node=NULL
, $teaser = FALSE
) {
187 drupal_add_css((drupal_get_path('module', 'addthis') .
'/addthis.css'), $type = 'module', $media = 'all', $preprocess = TRUE
);
189 <script type="text/javascript">
190 addthis_pub = \'%s\';
191 addthis_logo = \'%s\';
192 addthis_logo_background = \'%s\';
193 addthis_logo_color = \'%s\';
194 addthis_brand = \'%s\';
195 addthis_options = \'%s\';
196 addthis_offset_top = \'%d\';
197 addthis_offset_left = \'%d\';
199 <div class="addthis"><a href="http://www.addthis.com/bookmark.php"
200 onmouseover="return addthis_open(this, \'\', \'%s\', \'%s\')"
201 onmouseout="addthis_close()"
202 onclick="return addthis_sendto()"><img src="%s" width="%d" height="%d" %s /></a></div>
203 <script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script>
205 variable_get('addthis_user', 'my-username'),
206 variable_get('addthis_logo', 'http://www.addthis.com/images/yourlogo.png'),
207 variable_get('addthis_logo_background', 'EFEFFF'),
208 variable_get('addthis_logo_color', '666699'),
209 variable_get('addthis_brand', 'Your Site'),
210 variable_get('addthis_options', 'favorites, email, digg, delicious, myspace, facebook, google, live, more'),
211 variable_get('addthis_offset_top', '2'),
212 variable_get('addthis_offset_left', '2'),
213 $teaser ?
url('node/'.
$node->nid
, array('absolute' => 1) ) : '[URL]',
214 $teaser ?
addslashes($node->title
) : '[TITLE]',
215 variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif'),
216 variable_get('addthis_image_width', '125'),
217 variable_get('addthis_image_height', '16'),
218 variable_get('addthis_image_attributes', 'alt=""')