Révision 4543c6c7
Ajouté par Assos Assos il y a plus de 10 ans
htmltest/sites/all/modules/addthis/classes/AddThis.php | ||
---|---|---|
17 | 17 |
const STYLE_KEY = 'addthis_style'; |
18 | 18 |
const WIDGET_TYPE = 'addthis_button_widget'; |
19 | 19 |
|
20 |
// AddThis attribute and parameter names (as defined in AddThis APIs) |
|
20 |
// AddThis attribute and parameter names (as defined in AddThis APIs).
|
|
21 | 21 |
const PROFILE_ID_QUERY_PARAMETER = 'pubid'; |
22 | 22 |
const TITLE_ATTRIBUTE = 'addthis:title'; |
23 | 23 |
const URL_ATTRIBUTE = 'addthis:url'; |
24 | 24 |
|
25 |
// Persistent variable keys |
|
25 |
// Persistent variable keys.
|
|
26 | 26 |
const ADDRESSBOOK_ENABLED_KEY = 'addthis_addressbook_enabled'; |
27 | 27 |
const BLOCK_WIDGET_TYPE_KEY = 'addthis_block_widget_type'; |
28 |
const BLOCK_WIDGET_SETTINGS_KEY = 'addthis_block_widget_settings'; |
|
28 | 29 |
const BOOKMARK_URL_KEY = 'addthis_bookmark_url'; |
29 | 30 |
const CLICKBACK_TRACKING_ENABLED_KEY = 'addthis_clickback_tracking_enabled'; |
30 | 31 |
const CLICK_TO_OPEN_COMPACT_MENU_ENABLED_KEY = 'addthis_click_to_open_compact_menu_enabled'; |
... | ... | |
45 | 46 |
const UI_HEADER_BACKGROUND_COLOR_KEY = 'addthis_ui_header_background_color'; |
46 | 47 |
const UI_HEADER_COLOR_KEY = 'addthis_ui_header_color'; |
47 | 48 |
const WIDGET_JS_URL_KEY = 'addthis_widget_js_url'; |
48 |
const WIDGET_JS_ASYNC = 'addthis_widget_async';
|
|
49 |
const WIDGET_JS_LOAD_TYPE = 'addthis_widget_load_type';
|
|
49 | 50 |
|
50 |
|
|
51 |
// Twitter.
|
|
51 | 52 |
const TWITTER_VIA_KEY = 'addthis_twitter_via'; |
52 | 53 |
const TWITTER_VIA_DEFAULT = 'AddThis'; |
53 | 54 |
const TWITTER_TEMPLATE_KEY = 'addthis_twitter_template'; |
54 | 55 |
const TWITTER_TEMPLATE_DEFAULT = '{{title}} {{url}} via @AddThis'; |
55 | 56 |
|
56 |
// External resources |
|
57 |
const DEFAULT_BOOKMARK_URL = 'http://www.addthis.com/bookmark.php?v=250';
|
|
57 |
// External resources.
|
|
58 |
const DEFAULT_BOOKMARK_URL = 'http://www.addthis.com/bookmark.php?v=300';
|
|
58 | 59 |
const DEFAULT_SERVICES_CSS_URL = 'http://cache.addthiscdn.com/icons/v1/sprites/services.css'; |
59 | 60 |
const DEFAULT_SERVICES_JSON_URL = 'http://cache.addthiscdn.com/services/v1/sharing.en.json'; |
60 |
const DEFAULT_WIDGET_JS_URL = 'http://s7.addthis.com/js/250/addthis_widget.js';
|
|
61 |
const DEFAULT_WIDGET_JS_ASYNC = TRUE;
|
|
61 |
const DEFAULT_WIDGET_JS_URL = 'http://s7.addthis.com/js/300/addthis_widget.js';
|
|
62 |
const DEFAULT_WIDGET_JS_LOAD_TYPE = 'async';
|
|
62 | 63 |
|
63 |
// Internal resources |
|
64 |
// Internal resources.
|
|
64 | 65 |
const ADMIN_CSS_FILE = 'addthis.admin.css'; |
65 | 66 |
const ADMIN_INCLUDE_FILE = 'includes/addthis.admin.inc'; |
66 | 67 |
|
67 |
// Widget types |
|
68 |
// Widget types.
|
|
68 | 69 |
const WIDGET_TYPE_DISABLED = 'addthis_disabled'; |
69 | 70 |
|
70 |
// Styles |
|
71 |
// Styles.
|
|
71 | 72 |
const CSS_32x32 = 'addthis_32x32_style'; |
72 | 73 |
const CSS_16x16 = 'addthis_16x16_style'; |
73 | 74 |
|
... | ... | |
77 | 78 |
private $json; |
78 | 79 |
|
79 | 80 |
/** |
81 |
* Get the singleton instance of the AddThis class. |
|
82 |
* |
|
80 | 83 |
* @return AddThis |
84 |
* Instance of AddThis. |
|
81 | 85 |
*/ |
82 | 86 |
public static function getInstance() { |
83 | 87 |
module_load_include('php', 'addthis', 'classes/AddThisJson'); |
88 |
module_load_include('php', 'addthis', 'classes/AddThisWidgetJs'); |
|
89 |
|
|
84 | 90 |
if (!isset(self::$instance)) { |
85 |
$addThis = new AddThis();
|
|
86 |
$addThis->setJson(new AddThisJson());
|
|
87 |
self::$instance = $addThis;
|
|
91 |
$add_this = new AddThis();
|
|
92 |
$add_this->setJson(new AddThisJson());
|
|
93 |
self::$instance = $add_this;
|
|
88 | 94 |
} |
95 |
|
|
89 | 96 |
return self::$instance; |
90 | 97 |
} |
91 | 98 |
|
99 |
/** |
|
100 |
* Set the json object. |
|
101 |
*/ |
|
92 | 102 |
public function setJson(AddThisJson $json) { |
93 | 103 |
$this->json = $json; |
94 | 104 |
} |
... | ... | |
124 | 134 |
return array(); |
125 | 135 |
} |
126 | 136 |
|
137 |
// Load resources. |
|
138 |
self::$instance->includeWidgetJs(); |
|
139 |
self::$instance->addConfigurationOptionsJs(); |
|
140 |
|
|
127 | 141 |
// The display type exists. Now get it and get the markup. |
128 | 142 |
$display_information = $formatters[$display]; |
129 | 143 |
|
... | ... | |
192 | 206 |
return $rows; |
193 | 207 |
} |
194 | 208 |
|
209 |
/** |
|
210 |
* Add the AddThis Widget JavaScript to the page. |
|
211 |
*/ |
|
195 | 212 |
public function addWidgetJs() { |
196 |
$async_parameter = self::isWidgetJsAsync() ? '?async=1' : ''; |
|
197 |
$url = self::getWidgetUrl() . $async_parameter; |
|
198 |
if (self::isWidgetJsAsync()) { |
|
199 |
drupal_add_js( |
|
200 |
array( |
|
201 |
'addthis' => array( |
|
202 |
'widget_url' => $url, |
|
203 |
), |
|
204 |
), |
|
205 |
'setting' |
|
206 |
); |
|
213 |
$widgetjs = new AddThisWidgetJs(self::getWidgetUrl()); |
|
214 |
$widgetjs->addAttribute('pubid', $this->getProfileId()); |
|
215 |
|
|
216 |
if (self::getWidgetJsLoadType() != 'include') { |
|
217 |
$widgetjs->addAttribute(self::getWidgetJsLoadType(), '1'); |
|
207 | 218 |
} |
208 |
else { |
|
209 |
// Add AddThis.com resources |
|
210 |
drupal_add_js( |
|
211 |
$url, |
|
212 |
array( |
|
213 |
'type' => 'external', |
|
214 |
'group' => JS_LIBRARY, |
|
215 |
'every_page' => TRUE, |
|
216 |
'weight' => 9, |
|
217 |
) |
|
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; |
|
219 | 267 |
} |
220 |
// Add local internal behaviours |
|
221 |
if (self::isWidgetJsAsync()) { |
|
222 |
drupal_add_js( |
|
223 |
drupal_get_path('module', 'addthis') . '/addthis.js', |
|
224 |
array( |
|
225 |
'group' => JS_DEFAULT, |
|
226 |
'weight' => 10, |
|
227 |
'every_page' => TRUE, |
|
228 |
'preprocess' => TRUE, |
|
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', |
|
229 | 275 |
) |
230 |
); |
|
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; |
|
231 | 292 |
} |
293 |
return FALSE; |
|
232 | 294 |
} |
233 | 295 |
|
234 | 296 |
public function addConfigurationOptionsJs() { |
... | ... | |
240 | 302 |
|
241 | 303 |
global $language; |
242 | 304 |
$configuration = array( |
305 |
'pubid' => $this->getProfileId(), |
|
243 | 306 |
'services_compact' => $enabledServices, |
244 | 307 |
'data_track_clickback' => $this->isClickbackTrackingEnabled(), |
245 | 308 |
'ui_508_compliant' => $this->get508Compliant(), |
... | ... | |
295 | 358 |
return variable_get(self::BLOCK_WIDGET_TYPE_KEY, self::WIDGET_TYPE_DISABLED); |
296 | 359 |
} |
297 | 360 |
|
361 |
public function getBlockDisplaySettings() { |
|
362 |
return variable_get(self::BLOCK_WIDGET_SETTINGS_KEY, array()); |
|
363 |
} |
|
364 |
|
|
298 | 365 |
public function getProfileId() { |
299 | 366 |
return check_plain(variable_get(AddThis::PROFILE_ID_KEY)); |
300 | 367 |
} |
... | ... | |
311 | 378 |
return variable_get(self::ENABLED_SERVICES_KEY, array()); |
312 | 379 |
} |
313 | 380 |
|
314 |
public function isWidgetJsAsync() { |
|
315 |
return variable_get(self::WIDGET_JS_ASYNC, self::DEFAULT_WIDGET_JS_ASYNC); |
|
381 |
/** |
|
382 |
* Return the type of loading. |
|
383 |
* |
|
384 |
* @return string |
|
385 |
* Retuns domready or async. |
|
386 |
*/ |
|
387 |
public function getWidgetJsLoadType() { |
|
388 |
return variable_get(self::WIDGET_JS_LOAD_TYPE, self::DEFAULT_WIDGET_JS_LOAD_TYPE); |
|
316 | 389 |
} |
317 | 390 |
|
318 | 391 |
public function isClickToOpenCompactMenuEnabled() { |
... | ... | |
446 | 519 |
return $this->getProfileIdQueryParameter('#'); |
447 | 520 |
} |
448 | 521 |
|
522 |
/** |
|
523 |
* Get the url for the AddThis Widget. |
|
524 |
*/ |
|
449 | 525 |
private function getWidgetUrl() { |
450 |
return check_url($this->validateSecureUrl($this->getBaseWidgetJsUrl()) . $this->getProfileIdQueryParameterPrefixedWithHash()); |
|
526 |
$url = ($this->currentlyOnHttps() ? |
|
527 |
$this->getBaseWidgetJsUrl() : // Not https url. |
|
528 |
$this->transformToSecureUrl($this->getBaseWidgetJsUrl()) // Transformed to https url. |
|
529 |
); |
|
530 |
return check_url($url); |
|
451 | 531 |
} |
452 | 532 |
|
453 |
private function validateSecureUrl($url) { |
|
533 |
/** |
|
534 |
* Request if we are currently on a https connection. |
|
535 |
* |
|
536 |
* @return True if we are currently on a https connection. |
|
537 |
*/ |
|
538 |
public function currentlyOnHttps() { |
|
454 | 539 |
global $base_root; |
455 |
if (strpos($base_root, 'https://') !== FALSE) { |
|
540 |
return (strpos($base_root, 'https://') !== FALSE) ? TRUE : FALSE; |
|
541 |
} |
|
542 |
|
|
543 |
/** |
|
544 |
* Transform a url to secure url with https prefix. |
|
545 |
*/ |
|
546 |
public function transformToSecureUrl($url) { |
|
547 |
if ($this->currentlyOnHttps()) { |
|
456 | 548 |
$url = (strpos($url, 'http://') === 0 ? 'https://' . substr($url, 7) : $url); |
457 | 549 |
} |
458 | 550 |
return $url; |
Formats disponibles : Unified diff
Weekly update of contrib modules