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

Contents of /contributions/modules/addtoany/addtoany.module

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


Revision 1.8 - (show annotations) (download) (as text)
Tue Jan 20 01:44:35 2009 UTC (10 months, 1 week ago) by micropat
Branch: MAIN
CVS Tags: DRUPAL-5--2-0
Branch point for: DRUPAL-5--2
Changes since 1.7: +103 -11 lines
File MIME type: text/x-php
initial 5.2 commit
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Stand alone module file to handle AddToAny button integration
7 */
8
9 /**
10 * Implementation of hook_perm().
11 */
12 function addtoany_perm() {
13 $perms[] = 'administer addtoany';
14 $perms[] = 'view addtoany';
15 return $perms;
16 }
17
18 /**
19 * Implementation of hook_link().
20 */
21 function addtoany_link($type, $node=NULL, $teaser = FALSE) {
22 $links = array();
23
24 if ($type === 'node' && user_access('view addtoany')) {
25 if (($teaser && variable_get('addtoany_display_in_teasers', '0')) ||
26 (!$teaser && variable_get('addtoany_display_in_links', '0'))) {
27 $links['addtoany'] = array(
28 'title' => _addtoany_create_button($node, $teaser),
29 'html' => TRUE,
30 );
31 }
32 }
33
34 return $links;
35 }
36 /**
37 * Implementation of hook_menu().
38 */
39 function addtoany_menu($may_cache) {
40 $items = array();
41
42 if ($may_cache) {
43 $items['admin/settings/addtoany'] = array(
44 'path' => 'admin/settings/addtoany',
45 'title' => t('AddToAny'),
46 'description' => t('Settings for your <a href="http://www.addtoany.com/" target="blank">AddToAny</a> Share/Save buttons.'),
47 'callback' => 'drupal_get_form',
48 'callback arguments' => array('addtoany_admin_settings'),
49 'access' => array('administer addtoany'),
50 );
51 }
52
53 return $items;
54 }
55
56 /**
57 * Administration settings form.
58 *
59 * @return
60 * The completed form definition.
61 */
62 function addtoany_admin_settings() {
63 $form = array();
64
65 global $base_path;
66 $button_img = '<img src="' . $base_path . drupal_get_path('module', 'addtoany') . '/images/%s" width="%d" height="%d" />';
67
68 $button_options = array(
69 'share_16_16.png|16|16' => sprintf($button_img, 'share_16_16.png', 16, 16),
70 'share_save_171_16.png|171|16' => sprintf($button_img, 'share_save_171_16.png', 171, 16),
71 'share_save_256_24.png|256|24' => sprintf($button_img, 'share_save_256_24.png', 256, 24),
72 'custom' => 'Custom button',
73 );
74
75 $form['addtoany_general_settings'] = array(
76 '#type' => 'fieldset',
77 '#title' => t('General'),
78 );
79 $form['addtoany_general_settings']['addtoany_display_in_links'] = array(
80 '#type' => 'checkbox',
81 '#title' => t('Display on node pages'),
82 '#default_value' => variable_get('addtoany_display_in_links', '0'),
83 '#description' => t('Display an addtoany button always on a node page\'s links section.'),
84 );
85 $form['addtoany_general_settings']['addtoany_display_in_teasers'] = array(
86 '#type' => 'checkbox',
87 '#title' => t('Display in node teasers'),
88 '#default_value' => variable_get('addtoany_display_in_teasers', '0'),
89 '#description' => t('Display an addtoany button in the node teasers.'),
90 );
91
92 $form['addtoany_button_settings'] = array(
93 '#type' => 'fieldset',
94 '#title' => t('Button'),
95 '#collapsible' => TRUE,
96 '#collapsed' => FALSE,
97 );
98 $form['addtoany_button_settings']['addtoany_image'] = array(
99 '#type' => 'radios',
100 '#title' => t('Button'),
101 '#default_value' => variable_get('addtoany_image', 'share_save_171_16.png|171|16'),
102 '#options' => $button_options,
103 );
104 $form['addtoany_button_settings']['addtoany_custom_image'] = array(
105 '#type' => 'textfield',
106 '#title' => t('Custom button URL'),
107 '#default_value' => variable_get('addtoany_custom_image', ''),
108 '#description' => t('URL to the button image of your choosing. Example: http://example.com/share.png'),
109 );
110 $form['addtoany_button_settings']['addtoany_custom_image_attributes'] = array(
111 '#type' => 'textfield',
112 '#title' => t('Button image HTML attributes'),
113 '#default_value' => variable_get('addtoany_image_attributes', 'alt="Share/Save"'),
114 '#description' => t('Extra HTML attributes for img tag. Example: alt=""'),
115 );
116
117 $form['addtoany_additional_settings'] = array(
118 '#type' => 'fieldset',
119 '#title' => t('Additional options'),
120 '#collapsible' => TRUE,
121 '#collapsed' => TRUE,
122 );
123 $form['addtoany_additional_settings']['addtoany_additional_js'] = array(
124 '#type' => 'textarea',
125 '#title' => t('Additional script'),
126 '#default_value' => variable_get('addtoany_additional_js', ''),
127 '#description' => t('You can set special JavaScript variables for each Share/Save menu. Advanced users might want to check out Add to Any\'s <a href="http://www.addtoany.com/buttons/api/">JavaScript API</a>.'),
128 );
129
130 $form['addtoany_widget_settings'] = array(
131 '#type' => 'fieldset',
132 '#title' => t('Drop-down menu'),
133 '#collapsible' => TRUE,
134 '#collapsed' => TRUE,
135 );
136 $form['addtoany_widget_settings']['addtoany_dropdown_disabled'] = array(
137 '#type' => 'checkbox',
138 '#title' => t('Disable dropdown'),
139 '#default_value' => variable_get('addtoany_dropdown_disabled', '0'),
140 '#description' => t('You can disable the drop-down for selecting where to share your link and use a pop-up window instead.'),
141 );
142
143 return system_settings_form($form);
144 }
145
146 /**
147 * Implementation of hook_block().
148 */
149 function addtoany_block($op = 'list', $delta = 0) {
150 if ($op == 'list') {
151 $blocks[0]['info'] = t('AddToAny button');
152 return $blocks;
153 }
154 else if ($op == 'view' && user_access('view addtoany')) {
155 $block['subject'] = t('AddToAny');
156 $block['content'] = _addtoany_create_button();
157 return $block;
158 }
159 }
160
161 /**
162 * Implementation of hook_footer(). Would use drupal_add_js, but external scripts are not well supported
163 *
164 * @return
165 * String containing JavaScript code for the drop-down
166 */
167 function addtoany_footer($main = 0) {
168 global $_addtoany_script;
169 return $_addtoany_script;
170 }
171
172 function _addtoany_create_script($node = NULL) {
173
174 // Drop-down disabled?
175 if(variable_get('addtoany_dropdown_disabled', '0')) return;
176
177 global $_addtoany_script, $_addtoany_script_init;
178
179 if ( ! $_addtoany_script_init)
180 $_addtoany_script = '<script type="text/javascript">';
181 else
182 $_addtoany_script .= '<script type="text/javascript">';
183
184 $_addtoany_script .= 'a2a_linkname="'. addslashes($node->title) .'";a2a_linkurl="'. url('node/'. $node->nid ) .'";';
185
186 if ( ! $_addtoany_script_init) {
187 $_addtoany_script .= variable_get('addtoany_additional_js', '');
188 $_addtoany_script .= '</script><script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>';
189 } else {
190 $_addtoany_script .= 'a2a_init("page");</script>';
191 }
192
193 $_addtoany_script_init = TRUE;
194
195 return $_addtoany_script;
196 }
197
198 /**
199 * Internal function to generate code for AddToAny button
200 *
201 * @return
202 * String containing html code for the button
203 */
204 function _addtoany_create_button($node=NULL, $teaser = FALSE) {
205 global $_addtoany_counter, $base_path;
206
207 $_addtoany_counter++;
208 if ($_addtoany_counter == 1) {
209 drupal_add_css((drupal_get_path('module', 'addtoany') .'/addtoany.css'));
210 }
211
212 _addtoany_create_script($node);
213
214 $disable_dropdown = variable_get('addtoany_dropdown_disabled', '0');
215
216 $button_setting = variable_get('addtoany_image', 'share_save_171_16.png|171|16');
217
218 if ($button_setting == "custom") {
219 $button_image = variable_get('addtoany_custom_image', '');
220 $button_width = '';
221 $button_height = '';
222 } else {
223 $button = explode('|', $button_setting);
224 $button_filename = $button[0];
225 $button_width = ' width="' . $button[1] . '"';
226 $button_height = ' height="' . $button[2] . '"';
227 $button_image = $base_path . drupal_get_path('module', 'addtoany') . '/images/' . $button_filename;
228 }
229
230 return ( sprintf('
231 <div class="addtoany"><a%s href="http://www.addtoany.com/share_save?linkurl=%s&amp;linkname=%s"><img src="%s"%s%s %s/></a></div>
232 ',
233 $disable_dropdown ? '' : ' class="a2a_dd"',
234 rawurlencode(url('node/'. $node->nid )),
235 rawurlencode($node->title),
236 $button_image,
237 $button_width,
238 $button_height,
239 variable_get('addtoany_image_attributes', 'alt="Share/Save"')
240 ));
241
242 }

  ViewVC Help
Powered by ViewVC 1.1.2