Projet

Général

Profil

Paste
Télécharger (15,7 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / addthis / includes / addthis.admin.inc @ 2c8c2b87

1
<?php
2
/**
3
 * @file
4
 * Administrative page callbacks for the AddThis-module.
5
 */
6

    
7
/**
8
 * Form handler for admin_settings_form.
9
 */
10
function addthis_admin_settings_form($form_state) {
11
  AddThis::getInstance()->addStylesheets();
12

    
13
  // Visual settings.
14
  $form['fieldset_compact_menu'] = array(
15
    '#type' => 'fieldset',
16
    '#title' => t('Compact menu'),
17
    '#collapsible' => FALSE,
18
    '#collapsed' => TRUE,
19
    '#description' => '<p>' . t('Configure the global behavior and style of the compact menu and some additional settings related to the interface.') . '</p>'
20
  );
21
  $form['fieldset_compact_menu']['fieldset_menu_style'] = array(
22
    '#type' => 'fieldset',
23
    '#title' => t('Style'),
24
    '#collapsible' => TRUE,
25
    '#collapsed' => TRUE,
26
  );
27
  $form['fieldset_compact_menu']['fieldset_menu_style'][AddThis::CO_BRAND_KEY] = array(
28
    '#type' => 'textfield',
29
    '#title' => t('Branding text'),
30
    '#description' => t('Additional branding message to be rendered in the upper-right-hand corner of the compact menus.<br />Should be less than 15 characters in most cases to render properly.'),
31
    '#default_value' => AddThis::getInstance()->getCoBrand(),
32
    '#required' => FALSE,
33
    '#maxlength' => 15,
34
  );
35
  $form['fieldset_compact_menu']['fieldset_menu_style'][AddThis::UI_HEADER_COLOR_KEY] = array(
36
    '#type' => 'textfield',
37
    '#title' => t('Header text color'),
38
    '#default_value' => AddThis::getInstance()->getUiHeaderColor(),
39
    '#description' => t('Something like #FFFFFF'),
40
    '#size' => 8,
41
    '#maxlength' => 7,
42
    '#required' => FALSE,
43
  );
44
  $form['fieldset_compact_menu']['fieldset_menu_style'][AddThis::UI_HEADER_BACKGROUND_COLOR_KEY] = array(
45
    '#type' => 'textfield',
46
    '#title' => t('Header background color'),
47
    '#default_value' => AddThis::getInstance()->getUiHeaderBackgroundColor(),
48
    '#description' => t('Something like #000000'),
49
    '#size' => 8,
50
    '#maxlength' => 7,
51
    '#required' => FALSE,
52
  );
53
  $form['fieldset_compact_menu']['fieldset_menu_style'][AddThis::CLICK_TO_OPEN_COMPACT_MENU_ENABLED_KEY] = array(
54
    '#type' => 'checkbox',
55
    '#title' => t('Open compact menu on click'),
56
    '#description' => t('Default behavior is to open compact menu on hover.'),
57
    '#default_value' => AddThis::getInstance()->isClickToOpenCompactMenuEnabled(),
58
    '#required' => FALSE,
59
  );
60
  $form['fieldset_compact_menu']['fieldset_menu_style'][AddThis::OPEN_WINDOWS_ENABLED_KEY] = array(
61
    '#type' => 'checkbox',
62
    '#title' => t('Use pop-up windows'),
63
    '#description' => t('If checked, all shares will open in a new pop-up window instead of a new tab or regular browser window.'),
64
    '#default_value' => AddThis::getInstance()->isOpenWindowsEnabled(),
65
    '#required' => FALSE,
66
  );
67
  $form['fieldset_compact_menu']['fieldset_menu_style'][AddThis::UI_DELAY_KEY] = array(
68
    '#type' => 'textfield',
69
    '#title' => t('Menu open delay'),
70
    '#description' => t('Delay, in milliseconds, before compact menu appears when mousing over a regular button. Capped at 500 ms.'),
71
    '#default_value' => AddThis::getInstance()->getUiDelay(),
72
    '#required' => FALSE,
73
    '#size' => 3,
74
    '#maxlength' => 3,
75
  );
76

    
77
  // Enabled services settings.
78
  $form['fieldset_compact_menu']['enabled_services_fieldset'] = array(
79
    '#type' => 'fieldset',
80
    '#title' => t('Compact menu enabled services'),
81
    '#description' => t('The sharing services you select here will be displayed in the compact menu. If you select no services, AddThis will provide a list of frequently used services. This list is updated regularly. <b>Notice that this setting does not define what services should be display in a toolbox.</b>'),
82
    '#collapsible' => TRUE,
83
    '#collapsed' => TRUE,
84
  );
85
  $form['fieldset_compact_menu']['enabled_services_fieldset'][AddThis::ENABLED_SERVICES_KEY] = array(
86
    '#type' => 'checkboxes',
87
    '#title' => t('Enabled services'),
88
    '#options' => AddThis::getInstance()->getServices(),
89
    '#default_value' => AddThis::getInstance()->getEnabledServices(),
90
    '#required' => FALSE,
91
    '#columns' => 3,
92
  );
93

    
94
  // Additional visual settings.
95
  $form['fieldset_compact_menu']['fieldset_additionals'] = array(
96
    '#type' => 'fieldset',
97
    '#title' => t('Additional configuration'),
98
    '#collapsible' => TRUE,
99
    '#collapsed' => TRUE,
100
  );
101
  $form['fieldset_compact_menu']['fieldset_additionals'][AddThis::STANDARD_CSS_ENABLED_KEY] = array(
102
    '#type' => 'checkbox',
103
    '#title' => t('Use standard AddThis stylesheet'),
104
    '#description' => t('If not checked, AddThis will not load standard CSS file, allowing you to style everything yourself without incurring the cost of an additional load.'),
105
    '#default_value' => AddThis::getInstance()->isStandardCssEnabled(),
106
    '#required' => FALSE,
107
  );
108
  $form['fieldset_compact_menu']['fieldset_additionals'][AddThis::COMPLIANT_508_KEY] = array(
109
    '#type' => 'checkbox',
110
    '#title' => t('508 compliant'),
111
    '#description' => 'If checked, clicking the AddThis button will open a new window to a page that is keyboard navigable.',
112
    '#default_value' => AddThis::getInstance()->get508Compliant(),
113
    '#required' => FALSE,
114
  );
115
  $form['fieldset_compact_menu']['fieldset_additionals'][AddThis::ADDRESSBOOK_ENABLED_KEY] = array(
116
    '#type' => 'checkbox',
117
    '#title' => t('Use addressbook'),
118
    '#description' => 'If checked, the user will be able import their contacts from popular webmail services when using AddThis\'s email sharing.',
119
    '#default_value' => AddThis::getInstance()->isAddressbookEnabled(),
120
    '#required' => FALSE,
121
  );
122

    
123
  // Excluded Services.
124
  $form['fieldset_excluded_services'] = array(
125
    '#type' => 'fieldset',
126
    '#title' => t('Excluded services'),
127
    '#description' => t('The sharing services you select here will be excluded from all AddThis menus. This applies globally.'),
128
    '#collapsible' => TRUE,
129
    '#collapsed' => TRUE,
130
  );
131
  $form['fieldset_excluded_services'][AddThis::EXCLUDED_SERVICES_KEY] = array(
132
    '#type' => 'checkboxes',
133
    '#title' => t('Excluded services'),
134
    '#options' => AddThis::getInstance()->getServices(),
135
    '#default_value' => AddThis::getInstance()->getExcludedServices(),
136
    '#required' => FALSE,
137
    '#columns' => 3,
138
  );
139

    
140
  // Analytics settings.
141
  $profile_id = AddThis::getInstance()->getProfileId();
142
  $can_track_clicks = empty($profile_id) ? FALSE : TRUE;
143
  $form['fieldset_analytics'] = array(
144
    '#type' => 'fieldset',
145
    '#title' => t('Analytics & Tracking'),
146
    '#collapsible' => TRUE,
147
    '#collapsed' => $can_track_clicks ? TRUE : FALSE,
148
  );
149

    
150
  if (!$can_track_clicks) {
151
    $form['fieldset_analytics']['can_track_notice'] = array(
152
      '#theme' => 'html_tag',
153
      '#tag' => 'div',
154
      '#value' => t('For click analytics and statistics you have to provide a ProfileID from <a href="http://www.addthis.com">AddThis.com</a>. Register <a href="https://www.addthis.com/register" targt="_blank">here</a>.'),
155
      '#attributes' => array('class' => array('messages', 'warning')),
156
    );
157
  }
158
  $form['fieldset_analytics'][AddThis::PROFILE_ID_KEY] = array(
159
    '#type' => 'textfield',
160
    '#title' => t('AddThis ProfileID'),
161
    '#default_value' => AddThis::getInstance()->getProfileId(),
162
    '#required' => FALSE,
163
    '#size' => 25,
164
    '#description' => t('ProfileID at <a href="http://addthis.com/" target="_blank">AddThis.com</a>. Required for statistics.'),
165
  );
166
  $form['fieldset_analytics'][AddThis::CLICKBACK_TRACKING_ENABLED_KEY] = array(
167
    '#type' => 'checkbox',
168
    '#title' => t('Track clickback'),
169
    '#description' => 'Check to allow AddThis to append a variable to your URLs upon sharing. AddThis will use this to track how many people come back to your content via links shared with AddThis. Highly recommended. Always global.',
170
    '#default_value' => AddThis::getInstance()->isClickbackTrackingEnabled(),
171
    '#required' => FALSE,
172
  );
173

    
174
  // Facebook Like tracking requires a namespace to be added.
175
  $rdf_enabled = module_exists('rdf');
176
  if (!$rdf_enabled) {
177
    $rdf_description = '<span class="admin-disabled">' . t('The RDF module needs to be enabled to support Facebook Like tracking support.<br />Enable the module on <a href="!modules">modules</a> page.',
178
      array('!modules' => base_path() . 'admin/modules')
179
    ) . '</span>';
180
  }
181
  else {
182
    $rdf_description = t('Check to enable Facebook Like tracking support. Always global.');
183
  }
184
  $form['fieldset_analytics']['title_facebook'] = array(
185
    '#theme' => 'html_tag',
186
    '#tag' => 'div',
187
    '#value' => '<b>' . t('Facebook') . '</b>',
188
  );
189
  $form['fieldset_analytics']['facebook_notice'] = array(
190
    '#theme' => 'html_tag',
191
    '#tag' => 'p',
192
    '#value' => $rdf_description,
193
    '#access' => !$rdf_enabled,
194
  );
195

    
196
  $form['fieldset_analytics'][AddThis::FACEBOOK_LIKE_COUNT_SUPPORT_ENABLED] = array(
197
    '#type' => 'checkbox',
198
    '#title' => t('Enable Facebook Like tracking'),
199
    '#description' => filter_xss($rdf_description, array('span')),
200
    '#default_value' => AddThis::getInstance()->isFacebookLikeCountSupportEnabled(),
201
    '#required' => FALSE,
202
    '#disabled' => !$rdf_enabled,
203
  );
204

    
205
  // Google Analytics and Google Social Tracking support.
206
  $can_do_google_social_tracking = module_exists('googleanalytics');
207
  $is_google_analytics_setup = $can_do_google_social_tracking && variable_get('googleanalytics_account', '');
208
  $form['fieldset_analytics']['google_analytics'] = array(
209
    '#theme' => 'html_tag',
210
    '#tag' => 'div',
211
    '#value' => '<b>' . t('Google Analytics') . '</b>',
212
  );
213
  if (!$can_do_google_social_tracking) {
214
    $form['fieldset_analytics']['can_do_google_analytics'] = array(
215
      '#theme' => 'html_tag',
216
      '#tag' => 'p',
217
      '#value' => '<span class="admin-disabled">' . t('Install/enable the <a href="http://drupal.org/project/google_analytics" target="_blank">Google Analytics</a> module for Social Tracking support.') . '</span>',
218
    );
219
  }
220
  elseif ($can_do_google_social_tracking && !$is_google_analytics_setup) {
221
    $form['fieldset_analytics']['can_do_google_analytics'] = array(
222
      '#theme' => 'html_tag',
223
      '#tag' => 'p',
224
      '#value' => '<span class="admin-disabled">' . t('Configure the Google Analytics module correctly with the account code to use this feature.') . '</span>',
225
    );
226
  }
227
  $form['fieldset_analytics'][AddThis::GOOGLE_ANALYTICS_TRACKING_ENABLED_KEY] = array(
228
    '#type' => 'checkbox',
229
    '#title' => t('Track with Google Analytics'),
230
    '#description' => t('Check to track shares in your Google Analytics account reports (<a href="http://www.addthis.com/help/google-analytics-integration">more info</a>). Always global.'),
231
    '#default_value' => AddThis::getInstance()->isGoogleAnalyticsTrackingEnabled(),
232
    '#required' => FALSE,
233
    '#disabled' => !$is_google_analytics_setup,
234
  );
235
  $form['fieldset_analytics'][AddThis::GOOGLE_ANALYTICS_SOCIAL_TRACKING_ENABLED_KEY] = array(
236
    '#type' => 'checkbox',
237
    '#title' => t('Track with Google Analytics social'),
238
    '#description' => t('Check to track shares in the new Google Analytics social interaction reports (<a href="http://www.addthis.com/help/google-analytics-integration#social">more info</a>). Always global.'),
239
    '#default_value' => AddThis::getInstance()->isGoogleAnalyticsSocialTrackingEnabled(),
240
    '#required' => FALSE,
241
    '#disabled' => !$is_google_analytics_setup,
242
  );
243

    
244
  // Third party settings.
245
  $form['third_party_fieldset'] = array(
246
    '#type' => 'fieldset',
247
    '#title' => t('Third party settings'),
248
    '#collapsible' => TRUE,
249
    '#collapsed' => TRUE,
250
  );
251
  $form['third_party_fieldset']['twitter_service'] = array(
252
    '#type' => 'fieldset',
253
    '#title' => t('Twitter'),
254
    '#collapsible' => TRUE,
255
    '#collapsed' => TRUE,
256
  );
257
  $form['third_party_fieldset']['twitter_service'][AddThis::TWITTER_VIA_KEY] = array(
258
    '#type' => 'textfield',
259
    '#title' => t('Send via'),
260
    '#description' => t('When sending a tweet this is the screen name of the user to attribute the Tweet to. (Relates to Tweet Button)'),
261
    '#default_value' => AddThis::getInstance()->getTwitterVia(),
262
    '#size' => 15,
263
  );
264
  $form['third_party_fieldset']['twitter_service'][AddThis::TWITTER_TEMPLATE_KEY] = array(
265
    '#type' => 'textfield',
266
    '#title' => t('Template text'),
267
    '#description' => t('The {{title}} and {{url}} are replaced from the Twitter Button.'),
268
    '#default_value' => AddThis::getInstance()->getTwitterTemplate(),
269
  );
270

    
271
  return system_settings_form($form);
272
}
273

    
274
/**
275
 * Form handler for admin_settings_advanced_form.
276
 */
277
function addthis_admin_settings_advanced_form($form_state) {
278

    
279
  // Service URL's settings.
280
  $form['service_urls_fieldset'] = array(
281
    '#type' => 'fieldset',
282
    '#title' => t('Service URLs'),
283
    '#collapsible' => TRUE,
284
    '#collapsed' => TRUE,
285
  );
286
  $form['service_urls_fieldset'][AddThis::BOOKMARK_URL_KEY] = array(
287
    '#type' => 'textfield',
288
    '#title' => t('AddThis bookmark URL'),
289
    '#default_value' => AddThis::getInstance()->getBaseBookmarkUrl(),
290
    '#required' => TRUE,
291
  );
292
  $form['service_urls_fieldset'][AddThis::SERVICES_CSS_URL_KEY] = array(
293
    '#type' => 'textfield',
294
    '#title' => t('AddThis services stylesheet URL'),
295
    '#default_value' => AddThis::getInstance()->getServicesCssUrl(),
296
    '#required' => TRUE,
297
  );
298
  $form['service_urls_fieldset'][AddThis::SERVICES_JSON_URL_KEY] = array(
299
    '#type' => 'textfield',
300
    '#title' => t('AddThis services json URL'),
301
    '#default_value' => AddThis::getInstance()->getServicesJsonUrl(),
302
    '#required' => TRUE,
303
  );
304
  $form['service_urls_fieldset'][AddThis::WIDGET_JS_URL_KEY] = array(
305
    '#type' => 'textfield',
306
    '#title' => t('AddThis javascript widget URL'),
307
    '#default_value' => AddThis::getInstance()->getBaseWidgetJsUrl(),
308
    '#required' => TRUE,
309
  );
310

    
311
  // Advanced settings.
312
  $form['advanced_settings_fieldset'] = array(
313
    '#type' => 'fieldset',
314
    '#title' => t('Advanced settings'),
315
    '#access' => user_access(AddThis::PERMISSION_ADMINISTER_ADVANCED_ADDTHIS),
316
    '#collapsible' => TRUE,
317
    '#collapsed' => TRUE,
318
  );
319
  $form['advanced_settings_fieldset'][AddThis::CUSTOM_CONFIGURATION_CODE_ENABLED_KEY] = array(
320
    '#type' => 'checkbox',
321
    '#title' => t('Use custom AddThis configuration code'),
322
    '#default_value' => AddThis::getInstance()->isCustomConfigurationCodeEnabled(),
323
    '#required' => FALSE,
324
    '#description' => t('Use custom AddThis configuration code. If checked, custom configuration will be used instead of other configuration settings provided in AddThis administration user interface.'),
325
  );
326
  $form['advanced_settings_fieldset'][AddThis::CUSTOM_CONFIGURATION_CODE_KEY] = array(
327
    '#type' => 'textarea',
328
    '#title' => t('AddThis custom configuration code'),
329
    '#default_value' => AddThis::getInstance()->getCustomConfigurationCode(),
330
    '#required' => FALSE,
331
    '#description' => t('AddThis custom configuration code. See format at <a href="http://addthis.com/" target="_blank">AddThis.com</a>'),
332
  );
333
  $form['advanced_settings_fieldset'][AddThis::WIDGET_JS_LOAD_DOMREADY] = array(
334
    '#type' => 'checkbox',
335
    '#title' => t('Load the AddThis resources after the DOM is ready.'),
336
    '#default_value' => AddThis::getInstance()->getWidgetJsDomReady(),
337
  );
338
  $form['advanced_settings_fieldset'][AddThis::WIDGET_JS_LOAD_ASYNC] = array(
339
    '#type' => 'checkbox',
340
    '#title' => t('Initialize asynchronously through addthis.init().'),
341
    '#description' => t('Use this when you have your own Ajax functionality or create things after the DOM is ready trough Javascript. Initialize the addthis functionality through addthis.init().'),
342
    '#default_value' => AddThis::getInstance()->getWidgetJsAsync(),
343
  );
344
  $form['advanced_settings_fieldset'][AddThis::WIDGET_JS_INCLUDE] = array(
345
      '#type' => 'select',
346
      '#title' => t('Load widget js.'),
347
      '#options' => array(
348
        '0' => t('Don\'t include at all.'),
349
        '1' => t('Include on all (non admin) pages'),
350
        '2' => t('(Default) Include on widget rendering by Drupal.'),
351
      ),
352
      '#default_value' => AddThis::getInstance()->getWidgetJsInclude(),
353
  );
354
  return system_settings_form($form);
355
}