SNS Count Cache - Version 0.9.2

Version Description

  • Fixed: Facebook share count is not retrieved and cached.

=

Download this release

Release Info

Developer marubon
Plugin Icon SNS Count Cache
Version 0.9.2
Comparing to
See all releases

Code changes from version 0.9.1 to 0.9.2

includes/class-share-facebook-strategy.php CHANGED
@@ -32,7 +32,7 @@ class Share_Facebook_Strategy extends Crawl_Strategy {
32
  /**
33
  * SNS base url
34
  */
35
- const DEF_BASE_URL = 'https://api.facebook.com/method/links.getStats';
36
 
37
  /**
38
  * Class constarctor
@@ -43,7 +43,6 @@ class Share_Facebook_Strategy extends Crawl_Strategy {
43
  Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
 
45
  $this->method = 'GET';
46
- $this->query_parameters['format'] = 'json';
47
  }
48
 
49
  /**
@@ -95,8 +94,8 @@ class Share_Facebook_Strategy extends Crawl_Strategy {
95
  if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
96
  $json = json_decode( $content['data'], true );
97
 
98
- if ( isset( $json[0]['total_count'] ) && is_numeric( $json[0]['total_count'] ) ) {
99
- $count = (int) $json[0]['total_count'];
100
  } else {
101
  $count = (int) -1;
102
  }
@@ -110,7 +109,7 @@ class Share_Facebook_Strategy extends Crawl_Strategy {
110
 
111
  public function set_query_parameter( $key, $value ) {
112
  if ( $key === 'url' ) {
113
- $this->query_parameters['urls'] = $value;
114
  } else {
115
  $this->query_parameters[$key] = $value;
116
  }
@@ -124,7 +123,7 @@ class Share_Facebook_Strategy extends Crawl_Strategy {
124
  public function check_configuration() {
125
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
126
 
127
- if ( isset( $this->query_parameters['urls'] ) && $this->query_parameters['urls'] ) {
128
  return true;
129
  } else {
130
  return false;
32
  /**
33
  * SNS base url
34
  */
35
+ const DEF_BASE_URL = 'https://graph.facebook.com/';
36
 
37
  /**
38
  * Class constarctor
43
  Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
 
45
  $this->method = 'GET';
 
46
  }
47
 
48
  /**
94
  if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
  $json = json_decode( $content['data'], true );
96
 
97
+ if ( isset( $json['share']['share_count'] ) && is_numeric( $json['share']['share_count'] ) ) {
98
+ $count = (int) $json['share']['share_count'];
99
  } else {
100
  $count = (int) -1;
101
  }
109
 
110
  public function set_query_parameter( $key, $value ) {
111
  if ( $key === 'url' ) {
112
+ $this->query_parameters['id'] = $value;
113
  } else {
114
  $this->query_parameters[$key] = $value;
115
  }
123
  public function check_configuration() {
124
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
125
 
126
+ if ( isset( $this->query_parameters['id'] ) && $this->query_parameters['id'] ) {
127
  return true;
128
  } else {
129
  return false;
includes/class-wp-cron-util.php CHANGED
@@ -151,14 +151,15 @@ class WP_Cron_Util {
151
  $cron = array();
152
  $cronarray = array();
153
  //Cron string
154
- list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ', $cronstring, 5 );
155
 
156
  //make arrays form string
157
  foreach ( $cronstr as $key => $value ) {
158
- if ( strstr( $value, ',' ) )
159
  $cronarray[ $key ] = explode( ',', $value );
160
- else
161
  $cronarray[ $key ] = array( 0 => $value );
 
162
  }
163
 
164
  //make arrays complete with ranges and steps
@@ -167,49 +168,54 @@ class WP_Cron_Util {
167
  foreach ( $cronarrayvalue as $value ) {
168
  //steps
169
  $step = 1;
170
- if ( strstr( $value, '/' ) )
171
  list( $value, $step ) = explode( '/', $value, 2 );
 
172
  //replace weekday 7 with 0 for sundays
173
- if ( $cronarraykey == 'wday' )
174
  $value = str_replace( '7', '0', $value );
 
175
  //ranges
176
  if ( strstr( $value, '-' ) ) {
177
  list( $first, $last ) = explode( '-', $value, 2 );
178
- if ( ! is_numeric( $first ) || ! is_numeric( $last ) || $last > 60 || $first > 60 ) //check
179
- return 2147483647;
180
- if ( $cronarraykey == 'minutes' && $step < 5 ) //set step minimum to 5 min.
 
181
  $step = 5;
 
182
  $range = array();
183
  for ( $i = $first; $i <= $last; $i = $i + $step ) {
184
  $range[ ] = $i;
185
  }
186
  $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], $range );
187
  }
188
- elseif ( $value == '*' ) {
189
  $range = array();
190
- if ( $cronarraykey == 'minutes' ) {
191
- if ( $step < 10 ) //set step minimum to 5 min.
192
  $step = 10;
 
193
  for ( $i = 0; $i <= 59; $i = $i + $step ) {
194
  $range[ ] = $i;
195
  }
196
  }
197
- if ( $cronarraykey == 'hours' ) {
198
  for ( $i = 0; $i <= 23; $i = $i + $step ) {
199
  $range[ ] = $i;
200
  }
201
  }
202
- if ( $cronarraykey == 'mday' ) {
203
  for ( $i = $step; $i <= 31; $i = $i + $step ) {
204
  $range[ ] = $i;
205
  }
206
  }
207
- if ( $cronarraykey == 'mon' ) {
208
  for ( $i = $step; $i <= 12; $i = $i + $step ) {
209
  $range[ ] = $i;
210
  }
211
  }
212
- if ( $cronarraykey == 'wday' ) {
213
  for ( $i = 0; $i <= 6; $i = $i + $step ) {
214
  $range[ ] = $i;
215
  }
@@ -217,77 +223,41 @@ class WP_Cron_Util {
217
  $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], $range );
218
  }
219
  else {
220
- //Month names
221
- if ( strtolower( $value ) == 'jan' )
222
- $value = 1;
223
- if ( strtolower( $value ) == 'feb' )
224
- $value = 2;
225
- if ( strtolower( $value ) == 'mar' )
226
- $value = 3;
227
- if ( strtolower( $value ) == 'apr' )
228
- $value = 4;
229
- if ( strtolower( $value ) == 'may' )
230
- $value = 5;
231
- if ( strtolower( $value ) == 'jun' )
232
- $value = 6;
233
- if ( strtolower( $value ) == 'jul' )
234
- $value = 7;
235
- if ( strtolower( $value ) == 'aug' )
236
- $value = 8;
237
- if ( strtolower( $value ) == 'sep' )
238
- $value = 9;
239
- if ( strtolower( $value ) == 'oct' )
240
- $value = 10;
241
- if ( strtolower( $value ) == 'nov' )
242
- $value = 11;
243
- if ( strtolower( $value ) == 'dec' )
244
- $value = 12;
245
- //Week Day names
246
- if ( strtolower( $value ) == 'sun' )
247
- $value = 0;
248
- if ( strtolower( $value ) == 'sat' )
249
- $value = 6;
250
- if ( strtolower( $value ) == 'mon' )
251
- $value = 1;
252
- if ( strtolower( $value ) == 'tue' )
253
- $value = 2;
254
- if ( strtolower( $value ) == 'wed' )
255
- $value = 3;
256
- if ( strtolower( $value ) == 'thu' )
257
- $value = 4;
258
- if ( strtolower( $value ) == 'fri' )
259
- $value = 5;
260
- if ( ! is_numeric( $value ) || $value > 60 ) //check
261
- return 2147483647;
262
- $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], array( 0 => $value ) );
263
  }
264
  }
265
  }
266
 
267
  //generate years
268
- for ( $i = gmdate( 'Y' ); $i < gmdate( 'Y', 2147483647 ); $i ++ ) {
 
269
  $cron[ 'year' ][ ] = $i;
270
  }
271
 
272
  //calc next timestamp
273
- $current_timestamp = (int) current_time( 'timestamp', 1 );
274
  foreach ( $cron[ 'year' ] as $year ) {
275
  foreach ( $cron[ 'mon' ] as $mon ) {
276
  foreach ( $cron[ 'mday' ] as $mday ) {
277
- if ( ! checkdate( $mon, $mday, $year ) )
278
  continue;
 
279
  foreach ( $cron[ 'hours' ] as $hours ) {
280
  foreach ( $cron[ 'minutes' ] as $minutes ) {
281
  $timestamp = gmmktime( $hours, $minutes, 0, $mon, $mday, $year );
282
- if ( $timestamp && in_array( gmdate( 'j', $timestamp ), $cron[ 'mday' ] ) && in_array( gmdate( 'w', $timestamp ), $cron[ 'wday' ] ) && $timestamp > $current_timestamp )
283
- return $timestamp - ( get_option( 'gmt_offset' ) * 3600 );
 
284
  }
285
  }
286
  }
287
  }
288
  }
289
 
290
- return 2147483647;
291
  }
292
 
293
  }
151
  $cron = array();
152
  $cronarray = array();
153
  //Cron string
154
+ list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ', trim( $cronstring ), 5 );
155
 
156
  //make arrays form string
157
  foreach ( $cronstr as $key => $value ) {
158
+ if ( strstr( $value, ',' ) ) {
159
  $cronarray[ $key ] = explode( ',', $value );
160
+ } else {
161
  $cronarray[ $key ] = array( 0 => $value );
162
+ }
163
  }
164
 
165
  //make arrays complete with ranges and steps
168
  foreach ( $cronarrayvalue as $value ) {
169
  //steps
170
  $step = 1;
171
+ if ( strstr( $value, '/' ) ) {
172
  list( $value, $step ) = explode( '/', $value, 2 );
173
+ }
174
  //replace weekday 7 with 0 for sundays
175
+ if ( $cronarraykey === 'wday' ) {
176
  $value = str_replace( '7', '0', $value );
177
+ }
178
  //ranges
179
  if ( strstr( $value, '-' ) ) {
180
  list( $first, $last ) = explode( '-', $value, 2 );
181
+ if ( ! is_numeric( $first ) || ! is_numeric( $last ) || $last > 60 || $first > 60 ) { //check
182
+ return PHP_INT_MAX;
183
+ }
184
+ if ( $cronarraykey === 'minutes' && $step < 5 ) { //set step minimum to 5 min.
185
  $step = 5;
186
+ }
187
  $range = array();
188
  for ( $i = $first; $i <= $last; $i = $i + $step ) {
189
  $range[ ] = $i;
190
  }
191
  $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], $range );
192
  }
193
+ elseif ( $value === '*' ) {
194
  $range = array();
195
+ if ( $cronarraykey === 'minutes' ) {
196
+ if ( $step < 10 ) { //set step minimum to 5 min.
197
  $step = 10;
198
+ }
199
  for ( $i = 0; $i <= 59; $i = $i + $step ) {
200
  $range[ ] = $i;
201
  }
202
  }
203
+ if ( $cronarraykey === 'hours' ) {
204
  for ( $i = 0; $i <= 23; $i = $i + $step ) {
205
  $range[ ] = $i;
206
  }
207
  }
208
+ if ( $cronarraykey === 'mday' ) {
209
  for ( $i = $step; $i <= 31; $i = $i + $step ) {
210
  $range[ ] = $i;
211
  }
212
  }
213
+ if ( $cronarraykey === 'mon' ) {
214
  for ( $i = $step; $i <= 12; $i = $i + $step ) {
215
  $range[ ] = $i;
216
  }
217
  }
218
+ if ( $cronarraykey === 'wday' ) {
219
  for ( $i = 0; $i <= 6; $i = $i + $step ) {
220
  $range[ ] = $i;
221
  }
223
  $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], $range );
224
  }
225
  else {
226
+ if ( ! is_numeric( $value ) || (int) $value > 60 ) {
227
+ return PHP_INT_MAX;
228
+ }
229
+ $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], array( 0 => absint( $value ) ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  }
231
  }
232
  }
233
 
234
  //generate years
235
+ $year = (int) gmdate( 'Y' );
236
+ for ( $i = $year; $i < $year + 100; $i ++ ) {
237
  $cron[ 'year' ][ ] = $i;
238
  }
239
 
240
  //calc next timestamp
241
+ $current_timestamp = (int) current_time( 'timestamp' );
242
  foreach ( $cron[ 'year' ] as $year ) {
243
  foreach ( $cron[ 'mon' ] as $mon ) {
244
  foreach ( $cron[ 'mday' ] as $mday ) {
245
+ if ( ! checkdate( $mon, $mday, $year ) ) {
246
  continue;
247
+ }
248
  foreach ( $cron[ 'hours' ] as $hours ) {
249
  foreach ( $cron[ 'minutes' ] as $minutes ) {
250
  $timestamp = gmmktime( $hours, $minutes, 0, $mon, $mday, $year );
251
+ if ( $timestamp && in_array( (int) gmdate( 'j', $timestamp ), $cron[ 'mday' ], true ) && in_array( (int) gmdate( 'w', $timestamp ), $cron[ 'wday' ], true ) && $timestamp > $current_timestamp ) {
252
+ return $timestamp - ( (int) get_option( 'gmt_offset' ) * 3600 );
253
+ }
254
  }
255
  }
256
  }
257
  }
258
  }
259
 
260
+ return PHP_INT_MAX;
261
  }
262
 
263
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: marubon
3
  Donate link:
4
  Tags: performance, SNS, social, cache, share, follower
5
  Requires at least: 3.7
6
- Tested up to: 4.5.2
7
- Stable tag: 0.9.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -154,6 +154,9 @@ There are no questions.
154
  = 0.9.1 =
155
  * Fixed: Follower count is not retrieved and cached at intervals according to your configuration.
156
 
 
 
 
157
  == Upgrade Notice ==
158
  The following functions are deprecated.
159
 
3
  Donate link:
4
  Tags: performance, SNS, social, cache, share, follower
5
  Requires at least: 3.7
6
+ Tested up to: 4.6
7
+ Stable tag: 0.9.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
154
  = 0.9.1 =
155
  * Fixed: Follower count is not retrieved and cached at intervals according to your configuration.
156
 
157
+ = 0.9.2 =
158
+ * Fixed: Facebook share count is not retrieved and cached.
159
+
160
  == Upgrade Notice ==
161
  The following functions are deprecated.
162
 
sns-count-cache.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: SNS Count Cache
4
  Description: SNS Count Cache gets share count for Twitter and Facebook, Google Plus, Pocket, Hatena Bookmark and caches these count in the background. This plugin may help you to shorten page loading time because the share count can be retrieved not through network but through the cache using given functions.
5
- Version: 0.9.1
6
  Plugin URI: https://wordpress.org/plugins/sns-count-cache/
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
@@ -619,7 +619,7 @@ final class SNS_Count_Cache implements Order {
619
  /**
620
  * Plugin version, used for cache-busting of style and script file references.
621
  */
622
- private $version = '0.9.1';
623
 
624
  /**
625
  * Instances of crawler
2
  /*
3
  Plugin Name: SNS Count Cache
4
  Description: SNS Count Cache gets share count for Twitter and Facebook, Google Plus, Pocket, Hatena Bookmark and caches these count in the background. This plugin may help you to shorten page loading time because the share count can be retrieved not through network but through the cache using given functions.
5
+ Version: 0.9.2
6
  Plugin URI: https://wordpress.org/plugins/sns-count-cache/
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
619
  /**
620
  * Plugin version, used for cache-busting of style and script file references.
621
  */
622
+ private $version = '0.9.2';
623
 
624
  /**
625
  * Instances of crawler