WordPress Social Tools, Related Posts, Monetization – Shareaholic - Version 7.6.1.7

Version Description

  • Bugfix: fix issue with Server side share count option
Download this release

Release Info

Developer hngu_shareaholic
Plugin Icon 128x128 WordPress Social Tools, Related Posts, Monetization – Shareaholic
Version 7.6.1.7
Comparing to
See all releases

Code changes from version 7.6.1.6 to 7.6.1.7

Files changed (6) hide show
  1. public.php +2 -3
  2. public_js.php +18 -87
  3. readme.txt +8 -2
  4. shareaholic.php +3 -3
  5. templates/script_tag.php +3 -2
  6. utilities.php +13 -2
public.php CHANGED
@@ -60,10 +60,9 @@ class ShareaholicPublic {
60
  if (ShareaholicUtilities::has_accepted_terms_of_service() &&
61
  ShareaholicUtilities::get_or_create_api_key()) {
62
  ShareaholicUtilities::load_template('script_tag', array(
63
- 'shareaholic_url' => Shareaholic::URL,
64
  'api_key' => ShareaholicUtilities::get_option('api_key'),
65
- 'page_config' => ShareaholicPublicJS::get_page_config(),
66
- 'base_settings' => ShareaholicPublicJS::get_base_settings()
67
  ));
68
  }
69
  }
60
  if (ShareaholicUtilities::has_accepted_terms_of_service() &&
61
  ShareaholicUtilities::get_or_create_api_key()) {
62
  ShareaholicUtilities::load_template('script_tag', array(
 
63
  'api_key' => ShareaholicUtilities::get_option('api_key'),
64
+ 'base_settings' => ShareaholicPublicJS::get_base_settings(),
65
+ 'overrides' => ShareaholicPublicJS::get_overrides()
66
  ));
67
  }
68
  }
public_js.php CHANGED
@@ -13,108 +13,39 @@
13
  */
14
  class ShareaholicPublicJS {
15
 
16
- /**
17
- * Gets the page configuration to be used by shareaholic.js
18
- *
19
- * This function returns a string representation of the page config object
20
- * which will be consumed by the shareaholic javascript.
21
- *
22
- * @return string The stringified version of the page config
23
- */
24
- public static function get_page_config() {
25
- $config = self::get_base_settings();
26
- $config['apps'] = array();
27
- $functions_map = self::get_function_definitions();
28
- $share_buttons = self::get_share_buttons_config();
29
-
30
- // if all the configurations are empty, return an empty JS object
31
- if(empty($share_buttons)) {
32
- return '{}';
33
- }
34
-
35
- $config['apps']['share_buttons'] = $share_buttons;
36
-
37
- // Get the json representation of the page configuration
38
- $json_string = json_encode($config);
39
-
40
- // Now iterate through the function mapping and do a string replace
41
- foreach($functions_map as $placeholder => $implementation) {
42
- $json_string = str_replace('"' . $placeholder . '"', $implementation, $json_string);
43
- }
44
- return $json_string;
45
- }
46
-
47
-
48
  /**
49
  * Return a base set of settings for the Shareaholic JS or Publisher SDK
50
  */
51
  public static function get_base_settings() {
52
- return array(
53
  'endpoints' => array(
54
- 'local_recs_url' => admin_url('admin-ajax.php') . '?action=shareaholic_permalink_related',
55
- 'share_counts_url' => admin_url('admin-ajax.php') . '?action=shareaholic_share_counts_api'
56
  )
57
  );
58
- }
59
-
60
- /**
61
- * Get the share_buttons configuration to be used by Shareaholic.js
62
- *
63
- * This function returns an object for the share buttons configuration
64
- * which will be consumed by Shareaholic.js
65
- *
66
- * @return array an associative array of configuration for share buttons
67
- */
68
- public static function get_share_buttons_config() {
69
- $share_buttons = array();
70
  $disable_share_counts_api = ShareaholicUtilities::get_option('disable_internal_share_counts_api');
71
  $share_counts_connect_check = ShareaholicUtilities::get_option('share_counts_connect_check');
72
-
73
  if (isset($disable_share_counts_api)) {
74
  if (isset($share_counts_connect_check) && $share_counts_connect_check == 'SUCCESS' && $disable_share_counts_api != 'on') {
75
- $share_buttons['get_share_counts'] = '%get_share_counts%';
76
  }
77
  }
78
- return $share_buttons;
79
- }
80
 
81
- /**
82
- * Get the mapping of function placeholder to function implementation
83
- *
84
- * This function will return a mapping of a function placeholder to
85
- * the function implementation. This is necessary so that we can send
86
- * functions along to the JS side since json_encode cannot encode functions
87
- *
88
- * @return array an associative array of function placeholder to function implementation
89
- */
90
- public static function get_function_definitions() {
91
- return array(
92
- '%get_share_counts%' => self::get_share_counts_function(),
93
- );
94
  }
95
 
96
- /**
97
- * Get the share counts functions as a string
98
- *
99
- * @return string the stringified version of get_share_counts function
100
- */
101
- public static function get_share_counts_function() {
102
- $ajax_url = admin_url('admin-ajax.php');
103
- $share_counts_function = <<<DOC
104
- function(url, services, cb) {
105
- Shareaholic.Utils.ajax({
106
- cache: true,
107
- cache_ttl: '1 minute',
108
- url: '$ajax_url',
109
- data: { action: 'shareaholic_share_counts_api', url: url, services: services },
110
- success: function(res) {
111
- if(res && res.data) {
112
- cb(res.data, true);
113
- }
114
- }
115
- })
116
- }
117
  DOC;
118
- return $share_counts_function;
119
- }
 
 
 
120
  }
13
  */
14
  class ShareaholicPublicJS {
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  /**
17
  * Return a base set of settings for the Shareaholic JS or Publisher SDK
18
  */
19
  public static function get_base_settings() {
20
+ $base_settings = array(
21
  'endpoints' => array(
22
+ 'local_recs_url' => admin_url('admin-ajax.php') . '?action=shareaholic_permalink_related'
 
23
  )
24
  );
 
 
 
 
 
 
 
 
 
 
 
 
25
  $disable_share_counts_api = ShareaholicUtilities::get_option('disable_internal_share_counts_api');
26
  $share_counts_connect_check = ShareaholicUtilities::get_option('share_counts_connect_check');
27
+
28
  if (isset($disable_share_counts_api)) {
29
  if (isset($share_counts_connect_check) && $share_counts_connect_check == 'SUCCESS' && $disable_share_counts_api != 'on') {
30
+ $base_settings['endpoints']['share_counts_url'] = admin_url('admin-ajax.php') . '?action=shareaholic_share_counts_api';
31
  }
32
  }
 
 
33
 
34
+ return $base_settings;
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
36
 
37
+ public static function get_overrides() {
38
+ $output = '';
39
+
40
+ if (ShareaholicUtilities::get_env() === 'staging') {
41
+ $output = <<< DOC
42
+ shr.setAttribute('data-shr-environment', 'stage');
43
+ shr.setAttribute('data-shr-assetbase', '//cdn-staging-shareaholic.s3.amazonaws.com/v2/');
44
+ shr.src = '//cdn-staging-shareaholic.s3.amazonaws.com/assets/pub/shareaholic.js';
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  DOC;
46
+ }
47
+
48
+ return $output;
49
+ }
50
+
51
  }
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: shareaholic
3
  Tags: sexybookmarks, shareaholic, shareholic, recommendations, related content, cookie consent, share buttons, email button, social sharing, social bookmarking, share image, image sharing, follow buttons, floated share buttons, analytics, social media, social plugin
4
  Requires at least: 3.0
5
- Tested up to: 4.2.1
6
- Stable tag: 7.6.1.6
7
 
8
  The easiest, most effective way to grow your website traffic, effectively engage your audience, monetize, and gain insights for free.
9
 
@@ -170,6 +170,9 @@ Please see here: [Usage & Installation Instructions](http://support.shareaholic.
170
 
171
  == Changelog ==
172
 
 
 
 
173
  = 7.6.1.6 =
174
  * Enhancement: remove analytics option from Advanced Settings page
175
 
@@ -1210,6 +1213,9 @@ Please see here: [Usage & Installation Instructions](http://support.shareaholic.
1210
 
1211
  == Upgrade Notice ==
1212
 
 
 
 
1213
  = 7.6.1.6 =
1214
  * Enhancement: remove analytics option from Advanced Settings page
1215
 
2
  Contributors: shareaholic
3
  Tags: sexybookmarks, shareaholic, shareholic, recommendations, related content, cookie consent, share buttons, email button, social sharing, social bookmarking, share image, image sharing, follow buttons, floated share buttons, analytics, social media, social plugin
4
  Requires at least: 3.0
5
+ Tested up to: 4.2.2
6
+ Stable tag: 7.6.1.7
7
 
8
  The easiest, most effective way to grow your website traffic, effectively engage your audience, monetize, and gain insights for free.
9
 
170
 
171
  == Changelog ==
172
 
173
+ = 7.6.1.7 =
174
+ * Bugfix: fix issue with Server side share count option
175
+
176
  = 7.6.1.6 =
177
  * Enhancement: remove analytics option from Advanced Settings page
178
 
1213
 
1214
  == Upgrade Notice ==
1215
 
1216
+ = 7.6.1.7 =
1217
+ * Bugfix: fix issue with Server side share count option
1218
+
1219
  = 7.6.1.6 =
1220
  * Enhancement: remove analytics option from Advanced Settings page
1221
 
shareaholic.php CHANGED
@@ -3,14 +3,14 @@
3
  * The main file!
4
  *
5
  * @package shareaholic
6
- * @version 7.6.1.6
7
  */
8
 
9
  /*
10
  Plugin Name: Shareaholic | share buttons, analytics, related content
11
  Plugin URI: https://shareaholic.com/publishers/
12
  Description: Whether you want to get people sharing, grow your fans, make money, or know who's reading your content, Shareaholic will help you get it done. See <a href="admin.php?page=shareaholic-settings">configuration panel</a> for more settings.
13
- Version: 7.6.1.6
14
  Author: Shareaholic
15
  Author URI: https://shareaholic.com
16
  Text Domain: shareaholic
@@ -64,7 +64,7 @@ if (!class_exists('Shareaholic')) {
64
  const CM_API_URL = 'https://cm-web.shareaholic.com'; // uses static IPs for firewall whitelisting
65
  const REC_API_URL = 'http://recommendations.shareaholic.com';
66
 
67
- const VERSION = '7.6.1.6';
68
 
69
  /**
70
  * Starts off as false so that ::get_instance() returns
3
  * The main file!
4
  *
5
  * @package shareaholic
6
+ * @version 7.6.1.7
7
  */
8
 
9
  /*
10
  Plugin Name: Shareaholic | share buttons, analytics, related content
11
  Plugin URI: https://shareaholic.com/publishers/
12
  Description: Whether you want to get people sharing, grow your fans, make money, or know who's reading your content, Shareaholic will help you get it done. See <a href="admin.php?page=shareaholic-settings">configuration panel</a> for more settings.
13
+ Version: 7.6.1.7
14
  Author: Shareaholic
15
  Author URI: https://shareaholic.com
16
  Text Domain: shareaholic
64
  const CM_API_URL = 'https://cm-web.shareaholic.com'; // uses static IPs for firewall whitelisting
65
  const REC_API_URL = 'http://recommendations.shareaholic.com';
66
 
67
+ const VERSION = '7.6.1.7';
68
 
69
  /**
70
  * Starts off as false so that ::get_instance() returns
templates/script_tag.php CHANGED
@@ -8,12 +8,13 @@
8
  shr.setAttribute('data-cfasync', 'false');
9
  shr.src = '<?php echo ShareaholicUtilities::asset_url('assets/pub/shareaholic.js') ?>';
10
  shr.type = 'text/javascript'; shr.async = 'true';
 
 
11
  shr.onload = shr.onreadystatechange = function() {
12
  var rs = this.readyState;
13
  if (rs && rs != 'complete' && rs != 'loaded') return;
14
  var site_id = '<?php echo $api_key; ?>';
15
- var page_config = <?php echo $page_config; ?>;
16
- try { Shareaholic.init(site_id, page_config); } catch (e) {}
17
  };
18
  var s = document.getElementsByTagName('script')[0];
19
  s.parentNode.insertBefore(shr, s);
8
  shr.setAttribute('data-cfasync', 'false');
9
  shr.src = '<?php echo ShareaholicUtilities::asset_url('assets/pub/shareaholic.js') ?>';
10
  shr.type = 'text/javascript'; shr.async = 'true';
11
+ <?php echo $overrides; ?>
12
+
13
  shr.onload = shr.onreadystatechange = function() {
14
  var rs = this.readyState;
15
  if (rs && rs != 'complete' && rs != 'loaded') return;
16
  var site_id = '<?php echo $api_key; ?>';
17
+ try { Shareaholic.init(site_id); } catch (e) {}
 
18
  };
19
  var s = document.getElementsByTagName('script')[0];
20
  s.parentNode.insertBefore(shr, s);
utilities.php CHANGED
@@ -361,14 +361,25 @@ class ShareaholicUtilities {
361
  * @return string
362
  */
363
  public static function asset_url($asset) {
364
- if (preg_match('/spreadaholic/', Shareaholic::URL)) {
 
365
  return "http://spreadaholic.com:8080/" . $asset;
366
- } elseif (preg_match('/stageaholic/', Shareaholic::URL)) {
367
  return '//d2062rwknz205x.cloudfront.net/' . $asset;
368
  } else {
369
  return '//dsms0mj1bbhn4.cloudfront.net/' . $asset;
370
  }
371
  }
 
 
 
 
 
 
 
 
 
 
372
 
373
  /**
374
  * Returns the appropriate asset path for environment - admin
361
  * @return string
362
  */
363
  public static function asset_url($asset) {
364
+ $env = self::get_env();
365
+ if ($env === 'development') {
366
  return "http://spreadaholic.com:8080/" . $asset;
367
+ } elseif ($env === 'staging') {
368
  return '//d2062rwknz205x.cloudfront.net/' . $asset;
369
  } else {
370
  return '//dsms0mj1bbhn4.cloudfront.net/' . $asset;
371
  }
372
  }
373
+
374
+ public static function get_env() {
375
+ if (preg_match('/spreadaholic/', Shareaholic::URL)) {
376
+ return 'development';
377
+ } elseif (preg_match('/stageaholic/', Shareaholic::URL)) {
378
+ return 'staging';
379
+ } else {
380
+ return 'production';
381
+ }
382
+ }
383
 
384
  /**
385
  * Returns the appropriate asset path for environment - admin