Social Media Share Buttons | MashShare - Version 3.2.9

Version Description

  • New: Better prevent excessive Rate Limit exceeding of the facebook api on high traffic sites which results in 0 facebook share counts
  • New: Create warning notices that appears when caching is disabled or cache is purged permanetely
  • New: Debug mode writes debug notices into footer of the site available only for administrators
Download this release

Release Info

Developer ReneHermi
Plugin Icon 128x128 Social Media Share Buttons | MashShare
Version 3.2.9
Comparing to
See all releases

Code changes from version 3.2.8 to 3.2.9

includes/admin/admin-notices.php CHANGED
@@ -47,6 +47,26 @@ function mashsb_admin_messages() {
47
  return;
48
  }
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  //mashsb_update_notice_101();
51
 
52
  if( mashsb_is_admin_page() && !function_exists( 'curl_init' ) ) {
@@ -163,7 +183,6 @@ function mashsb_admin_messages() {
163
  }
164
  add_action( 'admin_notices', 'mashsb_admin_messages' );
165
 
166
-
167
  /**
168
  * Check if sharebar add-on version is fully supported
169
  *
@@ -367,3 +386,23 @@ function mashsb_in_plugin_update_message( $args ) {
367
  }
368
 
369
  add_action( 'in_plugin_update_message-mashsharer/mashshare.php', 'mashsb_in_plugin_update_message' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  return;
48
  }
49
 
50
+ // Rate Limit warning
51
+ if( mashsb_is_admin_page() && mashsb_rate_limit_exceeded() ) {
52
+ echo '<div class="error">';
53
+ echo '<p>' . sprintf(__('Your website exceeded the Facebook rate limit. Share count requests to Facebook will be delayed for 60min and the Facebook Share Count will not grow during this time. If you see this notice often consider to change <strong>MashShare Caching Method</strong> to <a href="%s">Refresh while Loading</a> and use a higher cache expiration. MashShare tries again to request shares in ' . mashsbGetRemainingRateLimitTime() , 'mashsb'), admin_url() . 'admin.php?page=mashsb-settings') . '</p>';
54
+ echo '</div>';
55
+ }
56
+
57
+ // Cache warning
58
+ if( mashsb_is_deactivated_cache() ) {
59
+ echo '<div class="error">';
60
+ echo '<p>' . sprintf(__('Attention: The Mashshare Cache is deactivated. <a href="%s">Activate it</a> or share count requests to social networks will be rate limited.', 'mashsb'), admin_url() . 'admin.php?page=mashsb-settings#mashsb_settingsdebug_header') . '</p>';
61
+ echo '</div>';
62
+ }
63
+ // Cache warning
64
+ if( mashsb_is_deleted_cache() ) {
65
+ echo '<div class="error">';
66
+ echo '<p>' . sprintf(__('Attention: The Mashshare Cache is permanetely purged. <a href="%s">Disable this</a> or share count requests to social networks will be rate limited.', 'mashsb'), admin_url() . 'admin.php?page=mashsb-settings#mashsb_settingsdebug_header') . '</p>';
67
+ echo '</div>';
68
+ }
69
+
70
  //mashsb_update_notice_101();
71
 
72
  if( mashsb_is_admin_page() && !function_exists( 'curl_init' ) ) {
183
  }
184
  add_action( 'admin_notices', 'mashsb_admin_messages' );
185
 
 
186
  /**
187
  * Check if sharebar add-on version is fully supported
188
  *
386
  }
387
 
388
  add_action( 'in_plugin_update_message-mashsharer/mashshare.php', 'mashsb_in_plugin_update_message' );
389
+
390
+ /**
391
+ * Get remaining time in seconds of the rate limit transient
392
+ * @return type
393
+ */
394
+ function mashsbGetRemainingRateLimitTime() {
395
+ $trans_time = get_transient( 'timeout_mash_rate_limit' );
396
+
397
+ if( false !== $trans_time ) {
398
+ $rest = time() - $trans_time;
399
+
400
+ if ($rest < 60){
401
+ return $rest . ' seconds.';
402
+ } else {
403
+ $minutes = floor($rest / 60) . ' minutes.';
404
+ return $minutes;
405
+ }
406
+ }
407
+ return time();
408
+ }
includes/admin/settings/register-settings.php CHANGED
@@ -1726,7 +1726,8 @@ function mashsb_delete_cache_objects() {
1726
  }
1727
  }
1728
 
1729
- /* returns Cache Status if enabled or disabled
 
1730
  *
1731
  * @since 2.0.4
1732
  * @return string
@@ -1739,6 +1740,34 @@ function mashsb_cache_status() {
1739
  }
1740
  }
1741
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1742
  /* Permission check if logfile is writable
1743
  *
1744
  * @since 2.0.6
1726
  }
1727
  }
1728
 
1729
+ /*
1730
+ * Check Cache Status if enabled or disabled
1731
  *
1732
  * @since 2.0.4
1733
  * @return string
1740
  }
1741
  }
1742
 
1743
+ /**
1744
+ * Check if cache is deactivated
1745
+ *
1746
+ * @global $mashsb_options $mashsb_options
1747
+ * @return boolean
1748
+ */
1749
+ function mashsb_is_deactivated_cache() {
1750
+ global $mashsb_options;
1751
+ if( isset( $mashsb_options['disable_cache'] ) ) {
1752
+ return true;
1753
+ }
1754
+ return false;
1755
+ }
1756
+
1757
+ /**
1758
+ * Check if cache gets deleted
1759
+ *
1760
+ * @global $mashsb_options $mashsb_options
1761
+ * @return boolean
1762
+ */
1763
+ function mashsb_is_deleted_cache() {
1764
+ global $mashsb_options;
1765
+ if( isset( $mashsb_options['delete_cache_objects'] ) ) {
1766
+ return true;
1767
+ }
1768
+ return false;
1769
+ }
1770
+
1771
  /* Permission check if logfile is writable
1772
  *
1773
  * @since 2.0.6
includes/libraries/RolingCurlX.php CHANGED
@@ -110,7 +110,7 @@ Class RollingCurlX {
110
  $ch = $completed['handle'];
111
  $request_info = curl_getinfo($ch);
112
  if(curl_errno($ch) !== 0 || intval($request_info['http_code']) !== 200) { //if server responded with http error
113
- $response = false;
114
  } else { //sucessful response
115
  $response = curl_multi_getcontent($ch);
116
  }
110
  $ch = $completed['handle'];
111
  $request_info = curl_getinfo($ch);
112
  if(curl_errno($ch) !== 0 || intval($request_info['http_code']) !== 200) { //if server responded with http error
113
+ $response = json_encode(array('error'=>curl_multi_getcontent($ch)));
114
  } else { //sucessful response
115
  $response = curl_multi_getcontent($ch);
116
  }
includes/mashengine.php CHANGED
@@ -7,6 +7,7 @@ class mashengine {
7
  private $timeout;
8
  private $http_scheme_url;
9
  private $https_scheme_url;
 
10
 
11
  function __construct( $url, $timeout = 10 ) {
12
  // remove http and https
@@ -24,10 +25,15 @@ class mashengine {
24
  public function getALLCounts() {
25
  $this->data = new stdClass;
26
  $this->data->total = 0;
27
- $data = $this->getSharesALL();
28
- return $data;
29
- //return $this->data;
30
- //wp_die(var_dump($this->data->total));
 
 
 
 
 
31
  }
32
 
33
  /* Collect share count from facebook and twitter */
@@ -35,8 +41,15 @@ class mashengine {
35
  public function getFBTWCounts() {
36
  $this->data = new stdClass;
37
  $this->data->total = 0;
38
- $data = $this->getSharesFBTW();
39
- return $data;
 
 
 
 
 
 
 
40
  }
41
 
42
  /* Build the multi_curl() crawler for facebook and twitter
@@ -63,37 +76,36 @@ class mashengine {
63
  $RollingCurlX->setOptions( $options );
64
  switch ( $fb_mode ) {
65
  case $fb_mode === 'likes':
66
- if( isset( $mashsb_options['cumulate_http_https'] ) ) {
67
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
68
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
69
- }else {
70
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
71
- }
72
-
73
  break;
74
  case $fb_mode === 'total':
75
- if( isset( $mashsb_options['cumulate_http_https'] ) ) {
76
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
77
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
78
- }else{
79
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
80
- }
81
 
82
  break;
83
  default:
84
 
85
- if( isset( $mashsb_options['cumulate_http_https'] ) ) {
86
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
87
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
88
- }else{
89
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
90
- }
91
-
92
  }
93
  if( isset( $mashsb_options['cumulate_http_https'] ) ) {
94
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
95
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
96
- }else{
97
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
98
  }
99
 
@@ -112,53 +124,51 @@ class mashengine {
112
 
113
  public function getSharesALL() {
114
  global $mashsb_options;
115
-
116
  $fb_mode = isset( $mashsb_options['facebook_count_mode'] ) ? $mashsb_options['facebook_count_mode'] : 'shares';
117
  $post_data = null;
118
  $headers = null;
119
 
120
  $options = array(
121
  CURLOPT_SSL_VERIFYPEER => FALSE,
122
- CURLOPT_SSL_VERIFYHOST => FALSE,
123
  );
124
 
125
  $RollingCurlX = new RollingCurlX( 10 ); // max 10 simultaneous downloads
126
  $RollingCurlX->setOptions( $options );
127
-
128
  switch ( $fb_mode ) {
129
  case $fb_mode === 'likes':
130
 
131
- if( isset( $mashsb_options['cumulate_http_https'] ) ) {
132
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
133
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
134
- }else{
135
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
136
- }
137
 
138
  break;
139
  case $fb_mode === 'total':
140
- if( isset( $mashsb_options['cumulate_http_https'] ) ) {
141
- //wp_die("http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
142
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
143
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
144
- }else{
145
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
146
- }
147
 
148
  break;
149
  default:
150
- if( isset( $mashsb_options['cumulate_http_https'] ) ) {
151
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
152
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
153
- }else{
154
- $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
155
- }
156
-
157
  }
158
  if( isset( $mashsb_options['cumulate_http_https'] ) ) {
159
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
160
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
161
- }else{
162
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
163
  }
164
  $RollingCurlX->addRequest( "https://www.linkedin.com/countserv/count/share?format=json&url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('linkedin'), $headers );
@@ -183,29 +193,42 @@ class mashengine {
183
  */
184
 
185
  function getCount( $data, $url, $request_info, $service, $time ) {
 
186
  $count = 0;
187
 
 
188
  if( $data ) {
189
  switch ( $service[0] ) {
190
  // not used any longer. Keep it here for compatibility reasons and return share count
191
  case "facebook_likes":
192
  $data = json_decode( $data, true );
193
  $count = isset( $data['share']['share_count'] ) || array_key_exists( 'share_count', $data ) ? $data['share']['share_count'] : 0;
 
 
 
 
194
  break;
195
  case "facebook_shares":
196
  $data = json_decode( $data, true ); // return assoc array
197
  $count = isset( $data['share']['share_count'] ) || array_key_exists( 'share_count', $data ) ? $data['share']['share_count'] : 0;
 
 
 
 
198
  break;
199
  case "facebook_total":
200
- //wp_die($fb_mode . 1);
201
  $data = json_decode( $data, true );
202
  $share_count = isset( $data['share']['share_count'] ) || array_key_exists( 'share_count', $data ) ? $data['share']['share_count'] : 0;
203
  $comment_count = isset( $data['share']['comment_count'] ) || array_key_exists( 'comment_count', $data ) ? $data['share']['comment_count'] : 0;
204
  $count = $share_count + $comment_count;
 
 
 
 
205
  break;
206
  case "google":
207
  //preg_match( '/window\.__SSR = {c: ([\d]+)TEST/', $data, $matches );
208
- preg_match("#window\.__SSR = {c: ([\d]+)#", $data, $matches);
209
  if( isset( $matches[0] ) )
210
  $count = str_replace( 'window.__SSR = {c: ', '', $matches[0] );
211
  break;
@@ -254,12 +277,41 @@ class mashengine {
254
  * */
255
  $this->data->total += $count;
256
  $this->data->{$service[0]} = $count;
257
-
258
  MASHSB()->logger->info( 'MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count );
259
  mashdebug()->info( 'MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count );
260
- //echo 'MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count;
 
 
 
261
  }
262
  return;
263
  }
264
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
  }
7
  private $timeout;
8
  private $http_scheme_url;
9
  private $https_scheme_url;
10
+ private $debug_notices;
11
 
12
  function __construct( $url, $timeout = 10 ) {
13
  // remove http and https
25
  public function getALLCounts() {
26
  $this->data = new stdClass;
27
  $this->data->total = 0;
28
+
29
+ if( false === mashsb_rate_limit_exceeded() ) {
30
+ $data = $this->getSharesALL();
31
+ return $data;
32
+ }
33
+ $this->debug_notices[] = 'MashShare: Facebook Rate Limit Exceeded. Try again in ' . $this->getRemainingRateLimitTime() . 'seconds' ;
34
+ add_action( 'wp_footer', array($this, 'outputDebug'), 100 );
35
+ // return 0;
36
+ return $this->data;
37
  }
38
 
39
  /* Collect share count from facebook and twitter */
41
  public function getFBTWCounts() {
42
  $this->data = new stdClass;
43
  $this->data->total = 0;
44
+
45
+ if( false === mashsb_rate_limit_exceeded() ) {
46
+ $data = $this->getSharesFBTW();
47
+ return $data;
48
+ }
49
+ $this->debug_notices[] = 'MashShare: Facebook Rate Limit Exceeded<br>';
50
+ add_action( 'wp_footer', array($this, 'outputDebug'), 100 );
51
+ // return 0;
52
+ return $this->data;
53
  }
54
 
55
  /* Build the multi_curl() crawler for facebook and twitter
76
  $RollingCurlX->setOptions( $options );
77
  switch ( $fb_mode ) {
78
  case $fb_mode === 'likes':
79
+ if( isset( $mashsb_options['cumulate_http_https'] ) ) {
80
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
81
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
82
+ } else {
83
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
84
+ }
85
+
86
  break;
87
  case $fb_mode === 'total':
88
+ if( isset( $mashsb_options['cumulate_http_https'] ) ) {
89
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
90
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
91
+ } else {
92
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
93
+ }
94
 
95
  break;
96
  default:
97
 
98
+ if( isset( $mashsb_options['cumulate_http_https'] ) ) {
99
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
100
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
101
+ } else {
102
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
103
+ }
 
104
  }
105
  if( isset( $mashsb_options['cumulate_http_https'] ) ) {
106
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
107
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
108
+ } else {
109
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
110
  }
111
 
124
 
125
  public function getSharesALL() {
126
  global $mashsb_options;
127
+
128
  $fb_mode = isset( $mashsb_options['facebook_count_mode'] ) ? $mashsb_options['facebook_count_mode'] : 'shares';
129
  $post_data = null;
130
  $headers = null;
131
 
132
  $options = array(
133
  CURLOPT_SSL_VERIFYPEER => FALSE,
134
+ CURLOPT_SSL_VERIFYHOST => FALSE
135
  );
136
 
137
  $RollingCurlX = new RollingCurlX( 10 ); // max 10 simultaneous downloads
138
  $RollingCurlX->setOptions( $options );
139
+
140
  switch ( $fb_mode ) {
141
  case $fb_mode === 'likes':
142
 
143
+ if( isset( $mashsb_options['cumulate_http_https'] ) ) {
144
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
145
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
146
+ } else {
147
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers );
148
+ }
149
 
150
  break;
151
  case $fb_mode === 'total':
152
+ if( isset( $mashsb_options['cumulate_http_https'] ) ) {
153
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
154
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
155
+ } else {
156
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers );
157
+ }
 
158
 
159
  break;
160
  default:
161
+ if( isset( $mashsb_options['cumulate_http_https'] ) ) {
162
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
163
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
164
+ } else {
165
+ $RollingCurlX->addRequest( "http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers );
166
+ }
 
167
  }
168
  if( isset( $mashsb_options['cumulate_http_https'] ) ) {
169
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
170
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
171
+ } else {
172
  $RollingCurlX->addRequest( "http://public.newsharecounts.com/count.json?url=" . $this->url, $post_data, array($this, 'getCount'), array('twitter'), $headers );
173
  }
174
  $RollingCurlX->addRequest( "https://www.linkedin.com/countserv/count/share?format=json&url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('linkedin'), $headers );
193
  */
194
 
195
  function getCount( $data, $url, $request_info, $service, $time ) {
196
+ global $mashsb_options;
197
  $count = 0;
198
 
199
+
200
  if( $data ) {
201
  switch ( $service[0] ) {
202
  // not used any longer. Keep it here for compatibility reasons and return share count
203
  case "facebook_likes":
204
  $data = json_decode( $data, true );
205
  $count = isset( $data['share']['share_count'] ) || array_key_exists( 'share_count', $data ) ? $data['share']['share_count'] : 0;
206
+ if( isset( $data['error'] ) ) {
207
+ // Probably rate limit exceed
208
+ $this->setRateLimitTransient();
209
+ }
210
  break;
211
  case "facebook_shares":
212
  $data = json_decode( $data, true ); // return assoc array
213
  $count = isset( $data['share']['share_count'] ) || array_key_exists( 'share_count', $data ) ? $data['share']['share_count'] : 0;
214
+ if( isset( $data['error'] ) ) {
215
+ // Probably rate limit exceed
216
+ $this->setRateLimitTransient();
217
+ }
218
  break;
219
  case "facebook_total":
 
220
  $data = json_decode( $data, true );
221
  $share_count = isset( $data['share']['share_count'] ) || array_key_exists( 'share_count', $data ) ? $data['share']['share_count'] : 0;
222
  $comment_count = isset( $data['share']['comment_count'] ) || array_key_exists( 'comment_count', $data ) ? $data['share']['comment_count'] : 0;
223
  $count = $share_count + $comment_count;
224
+ if( isset( $data['error'] ) ) {
225
+ // Probably rate limit exceed
226
+ $this->setRateLimitTransient();
227
+ }
228
  break;
229
  case "google":
230
  //preg_match( '/window\.__SSR = {c: ([\d]+)TEST/', $data, $matches );
231
+ preg_match( "#window\.__SSR = {c: ([\d]+)#", $data, $matches );
232
  if( isset( $matches[0] ) )
233
  $count = str_replace( 'window.__SSR = {c: ', '', $matches[0] );
234
  break;
277
  * */
278
  $this->data->total += $count;
279
  $this->data->{$service[0]} = $count;
280
+
281
  MASHSB()->logger->info( 'MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count );
282
  mashdebug()->info( 'MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count );
283
+ //echo 'MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count . '<br>';
284
+ $this->debug_notices[] = 'MashEngine - URL: ' . $url . ' ' . $service[0] . ': ' . $count . '<br>';
285
+
286
+ add_action( 'wp_footer', array($this, 'outputDebug'), 100 );
287
  }
288
  return;
289
  }
290
 
291
+ public function outputDebug() {
292
+ global $mashsb_options;
293
+
294
+ if( current_user_can( 'install_plugins' ) && isset( $mashsb_options['debug_mode'] ) ) {
295
+ echo '<div class="mash-debug" style="display:block;z-index:250000;font-size:11px;text-align:center;">';
296
+ var_dump($this->debug_notices);
297
+ echo '</div>';
298
+ }
299
+ }
300
+
301
+ public function setRateLimitTransient() {
302
+ set_transient( 'mash_rate_limit', 'true', 60 * 60 );
303
+
304
+ MASHSB()->logger->info( 'Error: Probably Facebook Rate Limit hit' );
305
+ $this->debug_notices[] = 'Error: Requests to Facebook probably hit Rate Limit.' ;
306
+ }
307
+
308
+ public function getRemainingRateLimitTime(){
309
+ $trans_time = get_transient('timeout_mash_rate_limit');
310
+
311
+ if (false !== $trans_time){
312
+ return time() - $trans_time;
313
+ }
314
+ return time();
315
+ }
316
+
317
  }
includes/template-functions.php CHANGED
@@ -120,6 +120,17 @@ function mashsbGetNonPostShares( $url ) {
120
  }
121
  }
122
 
 
 
 
 
 
 
 
 
 
 
 
123
  /*
124
  * Return the share count
125
  *
@@ -189,6 +200,8 @@ function getSharedcount( $url ) {
189
  * Update post_meta only when API is requested and
190
  * API share count is greater than real fresh requested share count ->
191
  */
 
 
192
 
193
  if( $mashsbShareCounts->total >= $mashsbStoredShareCount ) {
194
  update_post_meta( $post->ID, 'mashsb_shares', $mashsbShareCounts->total );
120
  }
121
  }
122
 
123
+ /**
124
+ * Check if the facebook rate limit has been exceeded
125
+ * @return boolean
126
+ */
127
+ function mashsb_rate_limit_exceeded(){
128
+ if (false === get_transient('mash_rate_limit')){
129
+ return false;
130
+ }
131
+ return true;
132
+ }
133
+
134
  /*
135
  * Return the share count
136
  *
200
  * Update post_meta only when API is requested and
201
  * API share count is greater than real fresh requested share count ->
202
  */
203
+
204
+
205
 
206
  if( $mashsbShareCounts->total >= $mashsbStoredShareCount ) {
207
  update_post_meta( $post->ID, 'mashsb_shares', $mashsbShareCounts->total );
mashshare.php CHANGED
@@ -6,7 +6,7 @@
6
  * Description: Mashshare is a Share functionality inspired by the the great website Mashable for Facebook and Twitter. More networks available.
7
  * Author: René Hermenau
8
  * Author URI: https://www.mashshare.net
9
- * Version: 3.2.8
10
  * Text Domain: mashsb
11
  * Domain Path: /languages
12
  * Credits: Thanks go to Pippin Williamson and the edd team. When we started with Mashshare we decided to use the EDD code base and
@@ -37,7 +37,7 @@ if( !defined( 'ABSPATH' ) )
37
 
38
  // Plugin version
39
  if( !defined( 'MASHSB_VERSION' ) ) {
40
- define( 'MASHSB_VERSION', '3.2.8' );
41
  }
42
 
43
  // Debug mode
6
  * Description: Mashshare is a Share functionality inspired by the the great website Mashable for Facebook and Twitter. More networks available.
7
  * Author: René Hermenau
8
  * Author URI: https://www.mashshare.net
9
+ * Version: 3.2.9
10
  * Text Domain: mashsb
11
  * Domain Path: /languages
12
  * Credits: Thanks go to Pippin Williamson and the edd team. When we started with Mashshare we decided to use the EDD code base and
37
 
38
  // Plugin version
39
  if( !defined( 'MASHSB_VERSION' ) ) {
40
+ define( 'MASHSB_VERSION', '3.2.9' );
41
  }
42
 
43
  // Debug mode
readme.txt CHANGED
@@ -9,7 +9,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Tags: Share buttons, Social Sharing, social media, Facebook, Twitter, Subscribe, Traffic posts, pages, widget, social share buttons, analytics, email
10
  Requires at least: 3.6+
11
  Tested up to: 4.7
12
- Stable tag: 3.2.8
13
 
14
  Social Media Share Buttons for Twitter, Facebook and other social networks. Highly customizable Social Media ecosystem
15
 
@@ -319,6 +319,11 @@ Read here more FAQ: [https://www.mashshare.net/faq/](https://www.mashshare.net/f
319
 
320
  == Changelog ==
321
 
 
 
 
 
 
322
  = 3.2.8 =
323
  * Fix: Custom field mashsb_jsonshares facebook is empty when old "refresh while loading" share count method is used
324
  * New: Add more unit tests to make sure that future updates do not break share count generation
9
  Tags: Share buttons, Social Sharing, social media, Facebook, Twitter, Subscribe, Traffic posts, pages, widget, social share buttons, analytics, email
10
  Requires at least: 3.6+
11
  Tested up to: 4.7
12
+ Stable tag: 3.2.9
13
 
14
  Social Media Share Buttons for Twitter, Facebook and other social networks. Highly customizable Social Media ecosystem
15
 
319
 
320
  == Changelog ==
321
 
322
+ = 3.2.9 =
323
+ * New: Better prevent excessive Rate Limit exceeding of the facebook api on high traffic sites which results in 0 facebook share counts
324
+ * New: Create warning notices that appears when caching is disabled or cache is purged permanetely
325
+ * New: Debug mode writes debug notices into footer of the site available only for administrators
326
+
327
  = 3.2.8 =
328
  * Fix: Custom field mashsb_jsonshares facebook is empty when old "refresh while loading" share count method is used
329
  * New: Add more unit tests to make sure that future updates do not break share count generation