Révision 2c8c2b87
Ajouté par Assos Assos il y a presque 9 ans
drupal7/sites/all/modules/addthis/classes/AddThis.php | ||
---|---|---|
34 | 34 |
const CUSTOM_CONFIGURATION_CODE_ENABLED_KEY = 'addthis_custom_configuration_code_enabled'; |
35 | 35 |
const CUSTOM_CONFIGURATION_CODE_KEY = 'addthis_custom_configuration_code'; |
36 | 36 |
const ENABLED_SERVICES_KEY = 'addthis_enabled_services'; |
37 |
const EXCLUDED_SERVICES_KEY = 'addthis_excluded_services'; |
|
37 | 38 |
const GOOGLE_ANALYTICS_TRACKING_ENABLED_KEY = 'addthis_google_analytics_tracking_enabled'; |
38 | 39 |
const GOOGLE_ANALYTICS_SOCIAL_TRACKING_ENABLED_KEY = 'addthis_google_analytics_social_tracking_enabled'; |
39 | 40 |
const FACEBOOK_LIKE_COUNT_SUPPORT_ENABLED = 'addthis_facebook_like_count_support_enabled'; |
... | ... | |
46 | 47 |
const UI_HEADER_BACKGROUND_COLOR_KEY = 'addthis_ui_header_background_color'; |
47 | 48 |
const UI_HEADER_COLOR_KEY = 'addthis_ui_header_color'; |
48 | 49 |
const WIDGET_JS_URL_KEY = 'addthis_widget_js_url'; |
49 |
const WIDGET_JS_LOAD_TYPE = 'addthis_widget_load_type'; |
|
50 |
const WIDGET_JS_LOAD_DOMREADY = 'addthis_widget_load_domready'; |
|
51 |
const WIDGET_JS_LOAD_ASYNC = 'addthis_widget_load_async'; |
|
52 |
const WIDGET_JS_INCLUDE = 'addthis_widget_include'; |
|
50 | 53 |
|
51 | 54 |
// Twitter. |
52 | 55 |
const TWITTER_VIA_KEY = 'addthis_twitter_via'; |
... | ... | |
59 | 62 |
const DEFAULT_SERVICES_CSS_URL = 'http://cache.addthiscdn.com/icons/v1/sprites/services.css'; |
60 | 63 |
const DEFAULT_SERVICES_JSON_URL = 'http://cache.addthiscdn.com/services/v1/sharing.en.json'; |
61 | 64 |
const DEFAULT_WIDGET_JS_URL = 'http://s7.addthis.com/js/300/addthis_widget.js'; |
62 |
const DEFAULT_WIDGET_JS_LOAD_TYPE = 'async'; |
|
65 |
const DEFAULT_WIDGET_JS_LOAD_DOMREADY = TRUE; |
|
66 |
const DEFAULT_WIDGET_JS_LOAD_ASYNC = FALSE; |
|
67 |
|
|
68 |
// Type of inclusion. |
|
69 |
// 0 = don't include, 1 = pages no admin, 2 = on usages only. |
|
70 |
const DEFAULT_WIDGET_JS_INCLUDE = 2; |
|
71 |
const WIDGET_JS_INCLUDE_NONE = 0; |
|
72 |
const WIDGET_JS_INCLUDE_PAGE = 1; |
|
73 |
const WIDGET_JS_INCLUDE_USAGE = 2; |
|
74 |
|
|
63 | 75 |
|
64 | 76 |
// Internal resources. |
65 | 77 |
const ADMIN_CSS_FILE = 'addthis.admin.css'; |
... | ... | |
84 | 96 |
* Instance of AddThis. |
85 | 97 |
*/ |
86 | 98 |
public static function getInstance() { |
87 |
module_load_include('php', 'addthis', 'classes/AddThisJson'); |
|
88 |
module_load_include('php', 'addthis', 'classes/AddThisWidgetJs'); |
|
89 | 99 |
|
90 | 100 |
if (!isset(self::$instance)) { |
91 | 101 |
$add_this = new AddThis(); |
... | ... | |
134 | 144 |
return array(); |
135 | 145 |
} |
136 | 146 |
|
137 |
// Load resources. |
|
138 |
self::$instance->includeWidgetJs(); |
|
139 |
self::$instance->addConfigurationOptionsJs(); |
|
140 |
|
|
141 | 147 |
// The display type exists. Now get it and get the markup. |
142 | 148 |
$display_information = $formatters[$display]; |
143 | 149 |
|
... | ... | |
206 | 212 |
return $rows; |
207 | 213 |
} |
208 | 214 |
|
209 |
/** |
|
210 |
* Add the AddThis Widget JavaScript to the page. |
|
211 |
*/ |
|
212 |
public function addWidgetJs() { |
|
213 |
$widgetjs = new AddThisWidgetJs(self::getWidgetUrl()); |
|
214 |
$widgetjs->addAttribute('pubid', $this->getProfileId()); |
|
215 |
|
|
216 |
if (self::getWidgetJsLoadType() != 'include') { |
|
217 |
$widgetjs->addAttribute(self::getWidgetJsLoadType(), '1'); |
|
218 |
} |
|
219 |
|
|
220 |
$url = $widgetjs->getFullUrl(); |
|
221 |
|
|
222 |
switch (self::getWidgetJsLoadType()) { |
|
223 |
|
|
224 |
// Load as DOM is ready. |
|
225 |
case 'domready': |
|
226 |
drupal_add_js( |
|
227 |
array( |
|
228 |
'addthis' => array( |
|
229 |
'widget_url' => $url, |
|
230 |
'load_type' => self::getWidgetJsLoadType(), |
|
231 |
), |
|
232 |
), |
|
233 |
'setting' |
|
234 |
); |
|
235 |
break; |
|
236 |
|
|
237 |
// Load as async. |
|
238 |
case 'async': |
|
239 |
drupal_add_js( |
|
240 |
array( |
|
241 |
'addthis' => array( |
|
242 |
'load_type' => self::getWidgetJsLoadType(), |
|
243 |
), |
|
244 |
), |
|
245 |
'setting' |
|
246 |
); |
|
247 |
|
|
248 |
drupal_add_js( |
|
249 |
$url, |
|
250 |
array( |
|
251 |
'type' => 'external', |
|
252 |
'scope' => 'footer', |
|
253 |
) |
|
254 |
); |
|
255 |
break; |
|
256 |
|
|
257 |
// Load as include in the page. |
|
258 |
default: |
|
259 |
drupal_add_js( |
|
260 |
$url, |
|
261 |
array( |
|
262 |
'type' => 'external', |
|
263 |
'scope' => 'footer', |
|
264 |
) |
|
265 |
); |
|
266 |
break; |
|
267 |
} |
|
268 |
|
|
269 |
// Add local internal behaviours. |
|
270 |
drupal_add_js( |
|
271 |
drupal_get_path('module', 'addthis') . '/addthis.js', |
|
272 |
array( |
|
273 |
'type' => 'file', |
|
274 |
'scope' => 'footer', |
|
275 |
) |
|
276 |
); |
|
277 |
} |
|
278 |
|
|
279 |
/** |
|
280 |
* Load function for widget information. |
|
281 |
* |
|
282 |
* Loading widget information only once. |
|
283 |
*/ |
|
284 |
public function includeWidgetJs() { |
|
285 |
static $loaded; |
|
286 |
|
|
287 |
if (!isset($loaded)) { |
|
288 |
$loaded = TRUE; |
|
289 |
$this->addWidgetJs(); |
|
290 |
|
|
291 |
return TRUE; |
|
292 |
} |
|
293 |
return FALSE; |
|
294 |
} |
|
295 |
|
|
296 |
public function addConfigurationOptionsJs() { |
|
297 |
if ($this->isCustomConfigurationCodeEnabled()) { |
|
298 |
$configurationOptionsJavascript = $this->getCustomConfigurationCode(); |
|
299 |
} |
|
300 |
else { |
|
301 |
$enabledServices = $this->getServiceNamesAsCommaSeparatedString() . 'more'; |
|
302 |
|
|
303 |
global $language; |
|
304 |
$configuration = array( |
|
305 |
'pubid' => $this->getProfileId(), |
|
306 |
'services_compact' => $enabledServices, |
|
307 |
'data_track_clickback' => $this->isClickbackTrackingEnabled(), |
|
308 |
'ui_508_compliant' => $this->get508Compliant(), |
|
309 |
'ui_click' => $this->isClickToOpenCompactMenuEnabled(), |
|
310 |
'ui_cobrand' => $this->getCoBrand(), |
|
311 |
'ui_delay' => $this->getUiDelay(), |
|
312 |
'ui_header_background' => $this->getUiHeaderBackgroundColor(), |
|
313 |
'ui_header_color' => $this->getUiHeaderColor(), |
|
314 |
'ui_open_windows' => $this->isOpenWindowsEnabled(), |
|
315 |
'ui_use_css' => $this->isStandardCssEnabled(), |
|
316 |
'ui_use_addressbook' => $this->isAddressbookEnabled(), |
|
317 |
'ui_language' => $language->language, |
|
318 |
); |
|
319 |
if (module_exists('googleanalytics')) { |
|
320 |
if ($this->isGoogleAnalyticsTrackingEnabled()) { |
|
321 |
$configuration['data_ga_property'] = variable_get('googleanalytics_account', ''); |
|
322 |
$configuration['data_ga_social'] = $this->isGoogleAnalyticsSocialTrackingEnabled(); |
|
323 |
} |
|
324 |
} |
|
325 |
$configuration['templates']['twitter'] = $this->getTwitterTemplate(); |
|
326 |
drupal_alter('addthis_configuration', $configuration); |
|
327 |
|
|
328 |
$templates = array('templates' => $configuration['templates']); |
|
329 |
unset($configuration['templates']); |
|
330 |
$configurationOptionsJavascript = 'var addthis_config = ' . drupal_json_encode($configuration) . "\n"; |
|
331 |
$configurationOptionsJavascript .= 'var addthis_share = ' . drupal_json_encode($templates); |
|
332 |
} |
|
333 |
drupal_add_js( |
|
334 |
$configurationOptionsJavascript, |
|
335 |
array( |
|
336 |
'type' => 'inline', |
|
337 |
'scope' => 'footer', |
|
338 |
'every_page' => TRUE, |
|
339 |
) |
|
340 |
); |
|
341 |
} |
|
342 |
|
|
343 | 215 |
public function getAddThisAttributesMarkup($options) { |
344 | 216 |
if (isset($options)) { |
345 | 217 |
$attributes = array(); |
... | ... | |
390 | 262 |
return variable_get(self::ENABLED_SERVICES_KEY, array()); |
391 | 263 |
} |
392 | 264 |
|
265 |
public function getExcludedServices() { |
|
266 |
return variable_get(self::EXCLUDED_SERVICES_KEY, array()); |
|
267 |
} |
|
268 |
|
|
393 | 269 |
/** |
394 |
* Return the type of loading.
|
|
270 |
* Return the type of inclusion.
|
|
395 | 271 |
* |
396 | 272 |
* @return string |
397 | 273 |
* Retuns domready or async. |
398 | 274 |
*/ |
399 |
public function getWidgetJsLoadType() { |
|
400 |
return variable_get(self::WIDGET_JS_LOAD_TYPE, self::DEFAULT_WIDGET_JS_LOAD_TYPE); |
|
275 |
public function getWidgetJsInclude() { |
|
276 |
return variable_get(self::WIDGET_JS_INCLUDE, self::DEFAULT_WIDGET_JS_INCLUDE); |
|
277 |
} |
|
278 |
|
|
279 |
/** |
|
280 |
* Return if domready loading should be active. |
|
281 |
* |
|
282 |
* @return bool |
|
283 |
* Returns TRUE if domready is enabled. |
|
284 |
*/ |
|
285 |
public function getWidgetJsDomReady() { |
|
286 |
return variable_get(self::WIDGET_JS_LOAD_DOMREADY, self::DEFAULT_WIDGET_JS_LOAD_DOMREADY); |
|
287 |
} |
|
288 |
|
|
289 |
/** |
|
290 |
* Return if async initialization should be active. |
|
291 |
* |
|
292 |
* @return bool |
|
293 |
* Returns TRUE if async is enabled. |
|
294 |
*/ |
|
295 |
public function getWidgetJsAsync() { |
|
296 |
return variable_get(self::WIDGET_JS_LOAD_ASYNC, self::DEFAULT_WIDGET_JS_LOAD_ASYNC); |
|
401 | 297 |
} |
402 | 298 |
|
403 | 299 |
public function isClickToOpenCompactMenuEnabled() { |
... | ... | |
485 | 381 |
return $this->getBaseBookmarkUrl() . $this->getProfileIdQueryParameterPrefixedWithAmp(); |
486 | 382 |
} |
487 | 383 |
|
384 |
/** |
|
385 |
* Transform the entity title to a attribute. |
|
386 |
* |
|
387 |
* @remarks |
|
388 |
* The title of the entity and site can not contain double-qoutes. These are |
|
389 |
* encoded into html chars. |
|
390 |
*/ |
|
488 | 391 |
private function getAttributeTitle($entity) { |
489 | 392 |
if (isset($entity->title)) { |
490 | 393 |
return array( |
491 |
self::TITLE_ATTRIBUTE => (check_plain($entity->title) . ' - ' . variable_get('site_name')),
|
|
394 |
self::TITLE_ATTRIBUTE => htmlentities($entity->title . ' - ' . variable_get('site_name'), ENT_COMPAT),
|
|
492 | 395 |
); |
493 | 396 |
} |
494 | 397 |
return array(); |
... | ... | |
503 | 406 |
return array(); |
504 | 407 |
} |
505 | 408 |
|
506 |
private function getServiceNamesAsCommaSeparatedString() {
|
|
507 |
$enabledServiceNames = array_values($this->getEnabledServices());
|
|
508 |
$enabledServicesAsCommaSeparatedString = '';
|
|
509 |
foreach ($enabledServiceNames as $enabledServiceName) {
|
|
510 |
if ($enabledServiceName != '0') {
|
|
511 |
$enabledServicesAsCommaSeparatedString .= $enabledServiceName . ',';
|
|
409 |
public function getServiceNamesAsCommaSeparatedString($services) {
|
|
410 |
$serviceNames = array_values($services);
|
|
411 |
$servicesAsCommaSeparatedString = '';
|
|
412 |
foreach ($serviceNames as $serviceName) {
|
|
413 |
if ($serviceName != '0') {
|
|
414 |
$servicesAsCommaSeparatedString .= $serviceName . ',';
|
|
512 | 415 |
} |
513 | 416 |
} |
514 |
return $enabledServicesAsCommaSeparatedString;
|
|
417 |
return $servicesAsCommaSeparatedString;
|
|
515 | 418 |
} |
516 | 419 |
|
517 | 420 |
private function getAdminCssFilePath() { |
Formats disponibles : Unified diff
Weekly update of contrib modules