/[drupal]/contributions/modules/addthis/addthis.module
ViewVC logotype

Contents of /contributions/modules/addthis/addthis.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.15 - (show annotations) (download) (as text)
Sat Sep 6 11:57:04 2008 UTC (14 months, 3 weeks ago) by wesku
Branch: MAIN
Changes since 1.14: +85 -77 lines
File MIME type: text/x-php
Quick and dirty port to D7. This port has still some issues with current Drupal HEAD
1 <?php
2 // $Id: addthis.module,v 1.14 2008/08/23 11:49:21 wesku Exp $
3
4 /**
5 * @file
6 * Stand alone module file to handle AddThis button integration
7 */
8
9 /**
10 * Implementation of hook_perm().
11 */
12 function addthis_perm() {
13 $perms[] = 'administer addthis';
14 $perms[] = 'view addthis';
15 return $perms;
16 }
17
18 /**
19 * Implementation of hook_link().
20 */
21 function addthis_link($type, $node=NULL, $teaser = FALSE) {
22 $links = array();
23
24 if ($type === 'node' && user_access('view addthis')) {
25 if (! $teaser || variable_get('addthis_display_in_teasers', '1')) {
26 $links['addthis'] = array(
27 'title' => _addthis_create_button($node, $teaser),
28 'html' => TRUE,
29 );
30 }
31 }
32
33 return $links;
34 }
35 /**
36 * Implementation of hook_menu().
37 */
38 function addthis_menu() {
39 $items = array();
40
41 $items['admin/settings/addthis'] = array(
42 'title' => 'AddThis module settings',
43 'page callback' => 'drupal_get_form',
44 'page arguments' => array('addthis_admin_settings'),
45 'description' => 'Set username and customize look and feel for <a href="http://www.addthis.com/">AddThis</a> button.',
46 'access arguments' => array('addthis_admin_settings'),
47 'menu_name' => 'settings',
48 );
49
50 return $items;
51 }
52
53 /**
54 * Implementation of hook_block().
55 */
56 function addthis_block($op = 'list', $delta = 0) {
57 if ($op == 'list') {
58 $blocks[0]['info'] = t('AddThis button');
59 return $blocks;
60 }
61 else if ($op == 'view' && user_access('view addthis')) {
62 $block['subject'] = t('AddThis');
63 $block['content'] = _addthis_create_button();
64 return $block;
65 }
66 }
67
68 /**
69 * Internal function to generate code for AddThis button
70 *
71 * @return
72 * String containing html code for the button
73 */
74 function _addthis_create_button($node=NULL, $teaser = FALSE) {
75 global $_addthis_counter;
76 $_addthis_counter++;
77 if ($_addthis_counter == 1) {
78 drupal_add_css((drupal_get_path('module', 'addthis') .'/addthis.css'));
79 drupal_add_js(sprintf('
80 addthis_pub = \'%s\';
81 addthis_logo = \'%s\';
82 addthis_logo_background = \'%s\';
83 addthis_logo_color = \'%s\';
84 addthis_brand = \'%s\';
85 addthis_options = \'%s\';
86 addthis_offset_top = \'%d\';
87 addthis_offset_left = \'%d\';
88 ',
89 variable_get('addthis_username', 'my-username'),
90 variable_get('addthis_logo', 'http://www.addthis.com/images/yourlogo.png'),
91 variable_get('addthis_logo_background', 'EFEFFF'),
92 variable_get('addthis_logo_color', '666699'),
93 variable_get('addthis_brand', 'Your Site'),
94 variable_get('addthis_options', 'favorites, email, digg, delicious, myspace, facebook, google, live, more'),
95 variable_get('addthis_offset_top', '2'),
96 variable_get('addthis_offset_left', '2')
97 ), 'inline');
98 }
99
100 return ( sprintf('
101 <div class="addthis"><a href="http://www.addthis.com/bookmark.php"
102 onmouseover="return addthis_open(this, \'\', \'%s\', \'%s\')"
103 onmouseout="addthis_close()"
104 onclick="return addthis_sendto()"><img src="%s" width="%d" height="%d" %s /></a></div>
105 <script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script>
106 ',
107 $teaser ? url('node/'. $node->nid, NULL, NULL, TRUE) : '[URL]',
108 $teaser ? addslashes($node->title) : '[TITLE]',
109 variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif'),
110 variable_get('addthis_image_width', '125'),
111 variable_get('addthis_image_height', '16'),
112 variable_get('addthis_image_attributes', 'alt=""')
113 ));
114 }
115
116 /**
117 * Administration settings form.
118 *
119 * @return
120 * The completed form definition.
121 */
122 function addthis_admin_settings() {
123 $form = array();
124
125 $form['addthis_general_settings'] = array(
126 '#type' => 'fieldset',
127 '#title' => t('General settings'),
128 );
129 $form['addthis_general_settings']['addthis_username'] = array(
130 '#type' => 'textfield',
131 '#title' => t('Username'),
132 '#default_value' => variable_get('addthis_username', 'my-username'),
133 '#description' => t('Your username for <a href="http://www.addthis.com/">addthis.com</a>. Example: my-username'),
134 );
135 $form['addthis_general_settings']['addthis_display_in_links'] = array(
136 '#type' => 'checkbox',
137 '#title' => t('Display on node pages'),
138 '#default_value' => variable_get('addthis_display_in_links', '0'),
139 '#description' => t('Display an AddThis button always on a node page\'s links section.'),
140 );
141 $form['addthis_general_settings']['addthis_display_in_teasers'] = array(
142 '#type' => 'checkbox',
143 '#title' => t('Display in node teasers'),
144 '#default_value' => variable_get('addthis_display_in_teasers', '0'),
145 '#description' => t('Display an AddThis button in the node teasers.'),
146 );
147
148 $form['addthis_button_settings'] = array(
149 '#type' => 'fieldset',
150 '#title' => t('Button image settings'),
151 '#collapsible' => TRUE,
152 '#collapsed' => TRUE,
153 );
154 $form['addthis_button_settings']['addthis_image'] = array(
155 '#type' => 'textfield',
156 '#title' => t('Button image url'),
157 '#default_value' => variable_get('addthis_image', 'http://s9.addthis.com/button1-share.gif'),
158 '#description' => t('URL for small image in the button. Example: http://s9.addthis.com/button1-share.gif'),
159 );
160 $form['addthis_button_settings']['addthis_image_width'] = array(
161 '#type' => 'textfield',
162 '#title' => t('Button image width'),
163 '#default_value' => variable_get('addthis_image_width', '125'),
164 '#description' => t('Width for button image. Example: 125'),
165 );
166 $form['addthis_button_settings']['addthis_image_height'] = array(
167 '#type' => 'textfield',
168 '#title' => t('Button image height'),
169 '#default_value' => variable_get('addthis_image_height', '16'),
170 '#description' => t('Height for button image. Example: 16'),
171 );
172 $form['addthis_button_settings']['addthis_image_attributes'] = array(
173 '#type' => 'textfield',
174 '#title' => t('Button image HTML attributes'),
175 '#default_value' => variable_get('addthis_image_attributes', 'alt=""'),
176 '#description' => t('Extra HTML attributes for img tag. Example: alt=""'),
177 );
178
179 $form['addthis_widget_settings'] = array(
180 '#type' => 'fieldset',
181 '#title' => t('Widget settings'),
182 '#collapsible' => TRUE,
183 '#collapsed' => TRUE,
184 );
185 $form['addthis_widget_settings']['addthis_dropdown_disabled'] = array(
186 '#type' => 'checkbox',
187 '#title' => t('Disable dropdown'),
188 '#default_value' => variable_get('addthis_dropdown_disabled', '0'),
189 '#description' => t('You can disable the dropdown for selecting where to share your link and use a pop-up window instead. This can be useful if the button is for example located next to a flash object.'),
190 );
191 $form['addthis_widget_settings']['addthis_logo'] = array(
192 '#type' => 'textfield',
193 '#title' => t('Logo url'),
194 '#default_value' => variable_get('addthis_logo', 'http://www.addthis.com/images/yourlogo.png'),
195 '#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'),
196 );
197 $form['addthis_widget_settings']['addthis_logo_background'] = array(
198 '#type' => 'textfield',
199 '#title' => t('Logo background color'),
200 '#default_value' => variable_get('addthis_logo_background', 'EFEFFF'),
201 '#description' => t('The color to use as a background around the logo in the popup. Example: EFEFEF'),
202 );
203 $form['addthis_widget_settings']['addthis_logo_color'] = array(
204 '#type' => 'textfield',
205 '#title' => t('Logo text color'),
206 '#default_value' => variable_get('addthis_logo_color', '666699'),
207 '#description' => t('The color to use for the text next to the logo in the popup. Example: 666666'),
208 );
209 $form['addthis_widget_settings']['addthis_brand'] = array(
210 '#type' => 'textfield',
211 '#title' => t('Brand text'),
212 '#default_value' => variable_get('addthis_brand', 'Your Site'),
213 '#description' => t('The brand name to display in the drop-down (top right). Example: My Website'),
214 );
215 $form['addthis_widget_settings']['addthis_options'] = array(
216 '#type' => 'textfield',
217 '#title' => t('Options'),
218 '#default_value' => variable_get('addthis_options', 'favorites, email, digg, delicious, myspace, facebook, google, live, more'),
219 '#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/>
220 delicious, digg, email, favorites, facebook, fark, furl, google, live, myweb, myspace, newsvine, reddit, slashdot, stumbleupon, technorati, twitter, more'),
221 );
222 $form['addthis_widget_settings']['addthis_offset_top'] = array(
223 '#type' => 'textfield',
224 '#title' => t('Offset top'),
225 '#default_value' => variable_get('addthis_offset_top', '2'),
226 '#description' => t('Vertical offset for the drop-down window (in pixels). Example: 2'),
227 );
228 $form['addthis_widget_settings']['addthis_offset_left'] = array(
229 '#type' => 'textfield',
230 '#title' => t('Offset top'),
231 '#default_value' => variable_get('addthis_offset_left', '2'),
232 '#description' => t('Horizontal offset for the drop-down window (in pixels). Example: 2'),
233 );
234 return system_settings_form($form);
235 }

  ViewVC Help
Powered by ViewVC 1.1.2