SNS Count Cache - Version 0.5.0

Version Description

  • Added: function to cache share count for both old and new url in https migration.
  • Fixed: share count of Facebook becomes invalid when the count is more than four digits.

=

Download this release

Release Info

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

Code changes from version 0.4.0 to 0.5.0

includes/admin-dashboard.php CHANGED
@@ -30,53 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30
 
31
  */
32
 
33
- $share_base_custom_post_types = get_option( self::DB_SHARE_CUSTOM_POST_TYPES );
34
-
35
- if ( ! $share_base_custom_post_types ) {
36
- $share_base_custom_post_types = array();
37
- }
38
-
39
- $share_base_check_interval = get_option( self::DB_SHARE_CHECK_INTERVAL );
40
- $share_base_check_interval = ! empty( $share_base_check_interval ) ? intval( $share_base_check_interval ) : self::OPT_SHARE_BASE_CHECK_INTERVAL;
41
-
42
- $share_base_posts_per_check = get_option( self::DB_SHARE_POSTS_PER_CHECK );
43
- $share_base_posts_per_check = ! empty( $share_base_posts_per_check ) ? intval( $share_base_posts_per_check ) : self::OPT_SHARE_BASE_POSTS_PER_CHECK;
44
-
45
- $dynamic_cache = get_option( self::DB_COMMON_DYNAMIC_CACHE );
46
- $dynamic_cache = isset( $dynamic_cache ) ? intval( $dynamic_cache ) : self::OPT_ACCESS_BASED_CACHE_NONE;
47
-
48
- $share_rush_new_content_term = get_option( self::DB_SHARE_NEW_CONTENT_TERM );
49
- $share_rush_new_content_term = ! empty( $share_rush_new_content_term ) ? intval( $share_rush_new_content_term ) : self::OPT_SHARE_RUSH_NEW_CONTENT_TERM;
50
-
51
- $share_base_cache_target = get_option( self::DB_SHARE_CACHE_TARGET );
52
-
53
- $follow_base_cache_target = get_option( self::DB_FOLLOW_CACHE_TARGET );
54
-
55
- $follow_base_check_interval = get_option( self::DB_FOLLOW_CHECK_INTERVAL );
56
- $follow_base_check_interval = ! empty( $follow_base_check_interval ) ? intval( $follow_base_check_interval ) : self::OPT_FOLLOW_BASE_CHECK_INTERVAL;
57
-
58
- $data_export = get_option( self::DB_COMMON_DATA_EXPORT );
59
- $data_export = isset( $data_export ) ? intval( $data_export ) : self::OPT_COMMON_DATA_EXPORT_MANUAL;
60
-
61
- $data_export_interval = get_option( self::DB_COMMON_DATA_EXPORT_INTERVAL );
62
- $data_export_interval = ! empty( $data_export_interval ) ? intval( $data_export_interval ) : self::OPT_COMMON_DATA_EXPORT_INTERVAL;
63
-
64
- if ( ! $share_base_cache_target ) {
65
- $share_base_cache_target[self::REF_SHARE_TWITTER] = true;
66
- $share_base_cache_target[self::REF_SHARE_FACEBOOK] = true;
67
- $share_base_cache_target[self::REF_SHARE_GPLUS] = true;
68
- if ( extension_loaded( 'xml' ) && extension_loaded( 'xmlreader' ) && extension_loaded( 'xmlwriter' )) {
69
- $share_base_cache_target[self::REF_SHARE_POCKET] = true;
70
- }
71
- $share_base_cache_target[self::REF_SHARE_HATEBU] = true;
72
- }
73
-
74
- $share_base_cache_target[self::REF_SHARE_TOTAL] = true;
75
-
76
- if ( ! $follow_base_cache_target ) {
77
- $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = true;
78
- }
79
-
80
  $query_args = array(
81
  'post_type' => $this->share_base_cache_post_types,
82
  'post_status' => 'publish',
@@ -118,19 +71,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
118
  <td>
119
  <?php
120
  $target_sns = array();
121
- if ( isset( $share_base_cache_target[self::REF_SHARE_TWITTER] ) && $share_base_cache_target[self::REF_SHARE_TWITTER] ) {
122
  $target_sns[] = 'Twitter';
123
  }
124
- if ( isset( $share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $share_base_cache_target[self::REF_SHARE_FACEBOOK] ) {
125
  $target_sns[] = 'Facebook';
126
  }
127
- if ( isset( $share_base_cache_target[self::REF_SHARE_GPLUS] ) && $share_base_cache_target[self::REF_SHARE_GPLUS] ) {
128
  $target_sns[] = 'Google+';
129
  }
130
- if ( isset( $share_base_cache_target[self::REF_SHARE_POCKET] ) && $share_base_cache_target[self::REF_SHARE_POCKET] ) {
131
  $target_sns[] = 'Pocket';
132
  }
133
- if ( isset( $share_base_cache_target[self::REF_SHARE_HATEBU] ) && $share_base_cache_target[self::REF_SHARE_HATEBU] ) {
134
  $target_sns[] = 'Hatena Bookmark';
135
  }
136
  echo implode( ", ", $target_sns );
@@ -141,8 +94,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
141
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
142
  <td><?php _e( 'Additional custom post types', self::DOMAIN ) ?></td>
143
  <td><?php
144
- if ( ! empty( $share_base_custom_post_types ) && $share_base_custom_post_types ) {
145
- echo implode( ',', $share_base_custom_post_types );
146
  } else {
147
  _e( 'N/A', self::DOMAIN );
148
  }
@@ -152,22 +105,35 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
152
  <tr>
153
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
154
  <td><?php _e( 'Interval cheking and caching share count', self::DOMAIN ) ?></td>
155
- <td><?php echo $share_base_check_interval . ' seconds'; ?></td>
156
  </tr>
157
  <tr>
158
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
159
  <td><?php _e( 'Number of posts to check at a time', self::DOMAIN ) ?></td>
160
- <td><?php echo $share_base_posts_per_check . ' posts'; ?></td>
161
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  <tr>
163
  <td><?php _e( 'Share Rush Cache', self::DOMAIN ) ?></td>
164
  <td><?php _e( 'Term considering posted content as new content', self::DOMAIN ) ?></td>
165
  <td>
166
  <?php
167
- if ( $share_rush_new_content_term == 1 ) {
168
- echo $share_rush_new_content_term . ' day';
169
- } else if ( $share_rush_new_content_term > 1 ) {
170
- echo $share_rush_new_content_term . ' days';
171
  }
172
  ?>
173
  </td>
@@ -177,7 +143,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
177
  <td>
178
  <?php
179
  $target_sns = array();
180
- if ( isset( $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) {
181
  $target_sns[] = 'Feedly';
182
  }
183
  echo implode( ", ", $target_sns );
@@ -187,21 +153,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
187
  <tr>
188
  <td><?php _e( 'Follow Base Cache', self::DOMAIN ) ?></td>
189
  <td><?php _e( 'Interval cheking and caching follower count', self::DOMAIN ) ?></td>
190
- <td><?php echo $follow_base_check_interval . ' seconds'; ?></td>
191
  </tr>
192
  <tr>
193
  <td><?php _e( 'Dynamic Cache', self::DOMAIN) ?></td><td><?php _e( 'Dynamic caching based on user access', self::DOMAIN ) ?></td><td>
194
  <?php
195
- switch ( $dynamic_cache ) {
196
- case self::OPT_ACCESS_BASED_CACHE_NONE:
197
  _e( 'disabled', self::DOMAIN );
198
  break;
199
- case self::OPT_ACCESS_BASED_SYNC_CACHE:
200
  _e( 'enabled (Synchronous Cache)', self::DOMAIN );
201
  break;
202
- case self::OPT_ACCESS_BASED_ASYNC_CACHE:
203
  _e( 'enabled (Asynchronous Cache)', self::DOMAIN );
204
- case self::OPT_ACCESS_BASED_2ND_CACHE:
 
205
  _e( 'enabled (Asynchronous 2nd Cache)', self::DOMAIN );
206
  break;
207
  }
@@ -211,7 +178,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
211
  <tr>
212
  <td><?php _e( 'Data Export', self::DOMAIN) ?></td><td><?php _e( 'Method of data export', self::DOMAIN ) ?></td><td>
213
  <?php
214
- switch ( $data_export ) {
215
  case self::OPT_COMMON_DATA_EXPORT_MANUAL:
216
  _e( 'Manual', self::DOMAIN );
217
  break;
@@ -223,12 +190,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
223
  </td>
224
  </tr>
225
  <?php
226
- if ( $data_export == self::OPT_COMMON_DATA_EXPORT_AUTO ) {
227
  ?>
228
  <tr>
229
  <td><?php _e( 'Data Export', self::DOMAIN ) ?></td>
230
  <td><?php _e( 'Interval exporting share count to a csv file', self::DOMAIN ) ?></td>
231
- <td><?php echo $data_export_interval / 3600 . ' hours'; ?></td>
232
  </tr>
233
  <?php
234
  }
@@ -243,138 +210,140 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
243
  <div id="share-site-summary" class="postbox">
244
  <div class="handlediv" title="Click to toggle"><br></div>
245
  <h3 class="hndle"><span><?php _e( 'Cache Status', self::DOMAIN ) ?></span></h3>
246
- <div class="inside">
247
-
248
- <table class="view-table">
249
- <thead>
250
- <tr>
251
- <th><?php _e( 'Cache Type', self::DOMAIN ) ?></th>
252
- <th><?php _e( 'Status Overview', self::DOMAIN ) ?></th>
253
- <th><?php _e( 'Total Content', self::DOMAIN ) ?></th>
254
- <th><?php _e( 'State - Full Cache', self::DOMAIN ) ?></th>
255
- <th><?php _e( 'State - Partial Cache', self::DOMAIN ) ?></th>
256
- <th><?php _e( 'State - No Cache', self::DOMAIN ) ?></th>
257
- </tr>
258
- </thead>
259
- <tbody>
260
-
261
- <?php
 
 
 
 
262
 
263
- $share_base_cache_target = $this->share_base_cache_target ;
264
- unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
265
-
266
- $count = 1;
267
-
268
- $posts_count = 0;
269
- $primary_full_cache_count = 0;
270
- $primary_partial_cache_count = 0;
271
- $primary_no_cache_count = 0;
272
-
273
- $secondary_full_cache_count = 0;
274
- $secondary_partial_cache_count = 0;
275
- $secondary_no_cache_count = 0;
276
-
277
- if ( $site_query->have_posts() ) {
278
- while ( $site_query->have_posts() ) {
279
- $site_query->the_post();
280
-
281
- $posts_count++;
282
-
283
- $transient_id = self::OPT_SHARE_BASE_TRANSIENT_PREFIX . get_the_ID();
284
-
285
- if ( false === ( $sns_counts = get_transient( $transient_id ) ) ) {
286
- $primary_no_cache_count++;
287
- } else {
288
- $full_cache_flag = true;
289
- $partial_cache_flag = false;
290
-
291
- foreach ( $share_base_cache_target as $key => $value ) {
292
- if ( $value ) {
293
- if ( isset( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
294
- $partial_cache_flag = true;
295
  } else {
296
- $full_cache_flag = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  }
299
- }
300
-
301
- if ( $partial_cache_flag && $full_cache_flag ) {
302
- $primary_full_cache_count++;
303
- } else if ( $partial_cache_flag && ! $full_cache_flag ) {
304
- $primary_partial_cache_count++;
305
- } else {
306
- $primary_no_cache_count++;
307
- }
308
- }
309
-
310
- $full_cache_flag = true;
311
- $partial_cache_flag = false;
312
- foreach ( $share_base_cache_target as $key => $value ) {
313
- if ( $value ) {
314
-
315
- $meta_key = self::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( $key );
316
- $sns_count = get_post_meta( get_the_ID(), $meta_key, true );
317
-
318
- if ( isset( $sns_count ) && $sns_count >= 0 ) {
319
- $partial_cache_flag = true;
320
- } else {
321
- $full_cache_flag = false;
322
- }
323
-
324
  }
325
- }
326
- if ( $partial_cache_flag && $full_cache_flag ) {
327
- $secondary_full_cache_count++;
328
- } else if ( $partial_cache_flag && ! $full_cache_flag ) {
329
- $secondary_partial_cache_count++;
330
- } else {
331
- $secondary_no_cache_count++;
332
- }
333
- }
334
- wp_reset_postdata();
335
- }
336
-
337
- ?>
338
-
339
- <tr>
340
- <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
341
- <td>
342
- <?php
343
- if ( $primary_full_cache_count == $posts_count ) {
344
- _e( 'Completed', self::DOMAIN );
345
- } else if ( ( $primary_full_cache_count + $primary_partial_cache_count ) == $posts_count ) {
346
- _e( 'Partially Completed', self::DOMAIN );
347
- } else {
348
- _e( 'Ongoing', self::DOMAIN );
349
- }
350
- ?>
351
- </td>
352
- <td class="share-count"><?php echo $posts_count; ?></td>
353
- <td class="share-count full-cache"><?php echo $primary_full_cache_count ; ?></td>
354
- <td class="share-count partial-cache"><?php echo $primary_partial_cache_count ; ?></td>
355
- <td class="share-count no-cache"><?php echo $primary_no_cache_count; ?></td>
356
- </tr>
357
- <tr>
358
- <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
359
- <td>
360
- <?php
361
- if ( $secondary_full_cache_count == $posts_count ) {
362
- _e( 'Completed', self::DOMAIN );
363
- } else if ( ( $secondary_full_cache_count + $secondary_partial_cache_count ) == $posts_count ) {
364
- _e( 'Partially Completed', self::DOMAIN );
365
- } else {
366
- _e( 'Ongoing', self::DOMAIN );
367
- }
368
- ?>
369
- </td>
370
- <td class="share-count"><?php echo $posts_count; ?></td>
371
- <td class="share-count full-cache"><?php echo $secondary_full_cache_count; ?></td>
372
- <td class="share-count partial-cache"><?php echo $secondary_partial_cache_count; ?></td>
373
- <td class="share-count no-cache"><?php echo $secondary_no_cache_count; ?></td>
374
- </tr>
375
-
376
- </tbody>
377
- </table>
378
  </div>
379
  </div>
380
  </div>
@@ -384,88 +353,89 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
384
  <div class="handlediv" title="Click to toggle"><br></div>
385
  <h3 class="hndle"><span><?php _e( 'Share Count', self::DOMAIN ) ?></span></h3>
386
  <div class="inside">
387
-
388
- <table class="view-table">
389
- <thead>
390
- <tr>
391
- <?php
392
-
393
- foreach ( $share_base_cache_target as $key => $value ){
394
- if ( $value ) {
395
- echo '<th>' . $key . '</th>';
396
- }
 
 
 
 
 
 
 
 
 
 
 
 
397
  }
398
- ?>
399
- </tr>
400
- </thead>
401
- <tbody>
402
- <tr>
403
- <?php
404
-
405
- $sum = array();
406
- foreach ( $share_base_cache_target as $key => $value ) {
407
- if( $value ){
408
- $sum[$key] = 0;
409
- }
410
- }
411
-
412
- if ( $site_query->have_posts() ) {
413
- while ( $site_query->have_posts() ) {
414
- $site_query->the_post();
415
-
416
- $transient_id = self::OPT_SHARE_BASE_TRANSIENT_PREFIX . get_the_ID();
417
-
418
- if ( false === ( $sns_counts = get_transient( $transient_id ) ) ) {
419
-
420
- foreach ( $share_base_cache_target as $key => $value ) {
421
- if( $value ){
422
- /**
423
- echo '<td class="not-cached share-count">';
424
- _e( 'N/A', self::DOMAIN );
425
- echo '</td>';
426
- */
427
-
428
- $meta_key = self::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( $key );
429
- $sns_counts[$key] = get_post_meta( get_the_ID(), $meta_key, true );
430
-
431
- if ( isset( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
432
- $sum[$key] = $sum[$key] + $sns_counts[$key];
433
- }
434
- }
 
 
 
435
  }
436
-
437
- } else {
438
-
439
- foreach ( $share_base_cache_target as $key => $value ) {
440
- if ( $value ) {
441
- if ( isset( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
442
- $sum[$key] = $sum[$key] + $sns_counts[$key];
443
- }
444
- }
445
  }
446
-
447
- }
448
- }
449
- }
450
-
451
- foreach ( $share_base_cache_target as $key => $value ) {
452
- if ( $value ) {
453
- echo '<td class="share-count">';
454
- echo number_format( $sum[$key] );
455
- echo '</td>';
456
- }
457
- }
458
-
459
- wp_reset_postdata();
460
-
461
- ?>
462
- </tr>
463
- </tbody>
464
- </table>
465
-
466
  </div>
467
  </div>
468
- </div>
469
-
470
  </div>
471
  </div>
30
 
31
  */
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  $query_args = array(
34
  'post_type' => $this->share_base_cache_post_types,
35
  'post_status' => 'publish',
71
  <td>
72
  <?php
73
  $target_sns = array();
74
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) {
75
  $target_sns[] = 'Twitter';
76
  }
77
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) {
78
  $target_sns[] = 'Facebook';
79
  }
80
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) && $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) {
81
  $target_sns[] = 'Google+';
82
  }
83
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_POCKET] ) && $this->share_base_cache_target[self::REF_SHARE_POCKET] ) {
84
  $target_sns[] = 'Pocket';
85
  }
86
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) && $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) {
87
  $target_sns[] = 'Hatena Bookmark';
88
  }
89
  echo implode( ", ", $target_sns );
94
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
95
  <td><?php _e( 'Additional custom post types', self::DOMAIN ) ?></td>
96
  <td><?php
97
+ if ( ! empty( $this->share_base_custom_post_types ) && $this->share_base_custom_post_types ) {
98
+ echo implode( ',', $this->share_base_custom_post_types );
99
  } else {
100
  _e( 'N/A', self::DOMAIN );
101
  }
105
  <tr>
106
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
107
  <td><?php _e( 'Interval cheking and caching share count', self::DOMAIN ) ?></td>
108
+ <td><?php echo $this->share_base_check_interval . ' seconds'; ?></td>
109
  </tr>
110
  <tr>
111
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
112
  <td><?php _e( 'Number of posts to check at a time', self::DOMAIN ) ?></td>
113
+ <td><?php echo $this->share_base_posts_per_check . ' posts'; ?></td>
114
+ </tr>
115
+ <tr>
116
+ <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
117
+ <td><?php _e( 'Migration mode from http to https', self::DOMAIN ) ?></td>
118
+ <td>
119
+ <?php
120
+ if ( $this->scheme_migration_mode ) {
121
+ echo 'On';
122
+ } else {
123
+ echo 'Off';
124
+ }
125
+ ?>
126
+ </td>
127
+ </tr>
128
  <tr>
129
  <td><?php _e( 'Share Rush Cache', self::DOMAIN ) ?></td>
130
  <td><?php _e( 'Term considering posted content as new content', self::DOMAIN ) ?></td>
131
  <td>
132
  <?php
133
+ if ( $this->share_rush_new_content_term == 1 ) {
134
+ echo $this->share_rush_new_content_term . ' day';
135
+ } else if ( $this->share_rush_new_content_term > 1 ) {
136
+ echo $this->share_rush_new_content_term . ' days';
137
  }
138
  ?>
139
  </td>
143
  <td>
144
  <?php
145
  $target_sns = array();
146
+ if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) {
147
  $target_sns[] = 'Feedly';
148
  }
149
  echo implode( ", ", $target_sns );
153
  <tr>
154
  <td><?php _e( 'Follow Base Cache', self::DOMAIN ) ?></td>
155
  <td><?php _e( 'Interval cheking and caching follower count', self::DOMAIN ) ?></td>
156
+ <td><?php echo $this->follow_base_check_interval . ' seconds'; ?></td>
157
  </tr>
158
  <tr>
159
  <td><?php _e( 'Dynamic Cache', self::DOMAIN) ?></td><td><?php _e( 'Dynamic caching based on user access', self::DOMAIN ) ?></td><td>
160
  <?php
161
+ switch ( $this->dynamic_cache_mode ) {
162
+ case self::OPT_COMMON_ACCESS_BASED_CACHE_NONE:
163
  _e( 'disabled', self::DOMAIN );
164
  break;
165
+ case self::OPT_COMMON_ACCESS_BASED_SYNC_CACHE:
166
  _e( 'enabled (Synchronous Cache)', self::DOMAIN );
167
  break;
168
+ case self::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE:
169
  _e( 'enabled (Asynchronous Cache)', self::DOMAIN );
170
+ break;
171
+ case self::OPT_COMMON_ACCESS_BASED_2ND_CACHE:
172
  _e( 'enabled (Asynchronous 2nd Cache)', self::DOMAIN );
173
  break;
174
  }
178
  <tr>
179
  <td><?php _e( 'Data Export', self::DOMAIN) ?></td><td><?php _e( 'Method of data export', self::DOMAIN ) ?></td><td>
180
  <?php
181
+ switch ( $this->data_export_mode ) {
182
  case self::OPT_COMMON_DATA_EXPORT_MANUAL:
183
  _e( 'Manual', self::DOMAIN );
184
  break;
190
  </td>
191
  </tr>
192
  <?php
193
+ if ( $this->data_export_mode == self::OPT_COMMON_DATA_EXPORT_AUTO ) {
194
  ?>
195
  <tr>
196
  <td><?php _e( 'Data Export', self::DOMAIN ) ?></td>
197
  <td><?php _e( 'Interval exporting share count to a csv file', self::DOMAIN ) ?></td>
198
+ <td><?php echo $this->data_export_interval / 3600 . ' hours'; ?></td>
199
  </tr>
200
  <?php
201
  }
210
  <div id="share-site-summary" class="postbox">
211
  <div class="handlediv" title="Click to toggle"><br></div>
212
  <h3 class="hndle"><span><?php _e( 'Cache Status', self::DOMAIN ) ?></span></h3>
213
+ <div class="inside">
214
+ <table class="view-table">
215
+ <thead>
216
+ <tr>
217
+ <th><?php _e( 'Cache Type', self::DOMAIN ) ?></th>
218
+ <th><?php _e( 'Status Overview', self::DOMAIN ) ?></th>
219
+ <th><?php _e( 'Total Content', self::DOMAIN ) ?></th>
220
+ <th><?php _e( 'State - Full Cache', self::DOMAIN ) ?></th>
221
+ <th><?php _e( 'State - Partial Cache', self::DOMAIN ) ?></th>
222
+ <th><?php _e( 'State - No Cache', self::DOMAIN ) ?></th>
223
+ </tr>
224
+ </thead>
225
+ <tbody>
226
+
227
+ <?php
228
+
229
+ $share_base_cache_target = $this->share_base_cache_target ;
230
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
231
+
232
+ $count = 1;
233
 
234
+ $posts_count = 0;
235
+ $primary_full_cache_count = 0;
236
+ $primary_partial_cache_count = 0;
237
+ $primary_no_cache_count = 0;
238
+
239
+ $secondary_full_cache_count = 0;
240
+ $secondary_partial_cache_count = 0;
241
+ $secondary_no_cache_count = 0;
242
+
243
+ set_time_limit( $this->extended_max_execution_time );
244
+
245
+ if ( $site_query->have_posts() ) {
246
+ while ( $site_query->have_posts() ) {
247
+ $site_query->the_post();
248
+
249
+ $posts_count++;
250
+
251
+ $transient_id = self::OPT_SHARE_BASE_TRANSIENT_PREFIX . get_the_ID();
252
+
253
+ if ( false === ( $sns_counts = get_transient( $transient_id ) ) ) {
254
+ $primary_no_cache_count++;
 
 
 
 
 
 
 
 
 
 
 
255
  } else {
256
+ $full_cache_flag = true;
257
+ $partial_cache_flag = false;
258
+
259
+ foreach ( $share_base_cache_target as $key => $value ) {
260
+ if ( $value ) {
261
+ if ( isset( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
262
+ $partial_cache_flag = true;
263
+ } else {
264
+ $full_cache_flag = false;
265
+ }
266
+ }
267
+ }
268
+
269
+ if ( $partial_cache_flag && $full_cache_flag ) {
270
+ $primary_full_cache_count++;
271
+ } else if ( $partial_cache_flag && ! $full_cache_flag ) {
272
+ $primary_partial_cache_count++;
273
+ } else {
274
+ $primary_no_cache_count++;
275
+ }
276
  }
277
+
278
+ $full_cache_flag = true;
279
+ $partial_cache_flag = false;
280
+ foreach ( $share_base_cache_target as $key => $value ) {
281
+ if ( $value ) {
282
+
283
+ $meta_key = self::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( $key );
284
+ $sns_count = get_post_meta( get_the_ID(), $meta_key, true );
285
+
286
+ if ( isset( $sns_count ) && $sns_count >= 0 ) {
287
+ $partial_cache_flag = true;
288
+ } else {
289
+ $full_cache_flag = false;
290
+ }
291
+
292
+ }
293
+ }
294
+ if ( $partial_cache_flag && $full_cache_flag ) {
295
+ $secondary_full_cache_count++;
296
+ } else if ( $partial_cache_flag && ! $full_cache_flag ) {
297
+ $secondary_partial_cache_count++;
298
+ } else {
299
+ $secondary_no_cache_count++;
300
+ }
301
  }
302
+ wp_reset_postdata();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
  }
304
+
305
+ set_time_limit( $this->original_max_execution_time );
306
+
307
+ ?>
308
+
309
+ <tr>
310
+ <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
311
+ <td>
312
+ <?php
313
+ if ( $primary_full_cache_count == $posts_count ) {
314
+ _e( 'Completed', self::DOMAIN );
315
+ } else if ( ( $primary_full_cache_count + $primary_partial_cache_count ) == $posts_count ) {
316
+ _e( 'Partially Completed', self::DOMAIN );
317
+ } else {
318
+ _e( 'Ongoing', self::DOMAIN );
319
+ }
320
+ ?>
321
+ </td>
322
+ <td class="share-count"><?php echo $posts_count; ?></td>
323
+ <td class="share-count full-cache"><?php echo $primary_full_cache_count ; ?></td>
324
+ <td class="share-count partial-cache"><?php echo $primary_partial_cache_count ; ?></td>
325
+ <td class="share-count no-cache"><?php echo $primary_no_cache_count; ?></td>
326
+ </tr>
327
+ <tr>
328
+ <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
329
+ <td>
330
+ <?php
331
+ if ( $secondary_full_cache_count == $posts_count ) {
332
+ _e( 'Completed', self::DOMAIN );
333
+ } else if ( ( $secondary_full_cache_count + $secondary_partial_cache_count ) == $posts_count ) {
334
+ _e( 'Partially Completed', self::DOMAIN );
335
+ } else {
336
+ _e( 'Ongoing', self::DOMAIN );
337
+ }
338
+ ?>
339
+ </td>
340
+ <td class="share-count"><?php echo $posts_count; ?></td>
341
+ <td class="share-count full-cache"><?php echo $secondary_full_cache_count; ?></td>
342
+ <td class="share-count partial-cache"><?php echo $secondary_partial_cache_count; ?></td>
343
+ <td class="share-count no-cache"><?php echo $secondary_no_cache_count; ?></td>
344
+ </tr>
345
+ </tbody>
346
+ </table>
 
 
 
 
 
 
 
 
 
 
347
  </div>
348
  </div>
349
  </div>
353
  <div class="handlediv" title="Click to toggle"><br></div>
354
  <h3 class="hndle"><span><?php _e( 'Share Count', self::DOMAIN ) ?></span></h3>
355
  <div class="inside">
356
+ <table class="view-table">
357
+ <thead>
358
+ <tr>
359
+ <?php
360
+
361
+ foreach ( $share_base_cache_target as $key => $value ){
362
+ if ( $value ) {
363
+ echo '<th>' . $key . '</th>';
364
+ }
365
+ }
366
+ ?>
367
+ </tr>
368
+ </thead>
369
+ <tbody>
370
+ <tr>
371
+ <?php
372
+
373
+ $sum = array();
374
+ foreach ( $share_base_cache_target as $key => $value ) {
375
+ if( $value ){
376
+ $sum[$key] = 0;
377
+ }
378
  }
379
+
380
+ set_time_limit( $this->extended_max_execution_time );
381
+
382
+ if ( $site_query->have_posts() ) {
383
+ while ( $site_query->have_posts() ) {
384
+ $site_query->the_post();
385
+
386
+ $transient_id = self::OPT_SHARE_BASE_TRANSIENT_PREFIX . get_the_ID();
387
+
388
+ if ( false === ( $sns_counts = get_transient( $transient_id ) ) ) {
389
+
390
+ foreach ( $share_base_cache_target as $key => $value ) {
391
+ if( $value ){
392
+ /**
393
+ echo '<td class="not-cached share-count">';
394
+ _e( 'N/A', self::DOMAIN );
395
+ echo '</td>';
396
+ */
397
+
398
+ $meta_key = self::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( $key );
399
+ $sns_counts[$key] = get_post_meta( get_the_ID(), $meta_key, true );
400
+
401
+ if ( isset( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
402
+ $sum[$key] = $sum[$key] + $sns_counts[$key];
403
+ }
404
+ }
405
+ }
406
+
407
+ } else {
408
+
409
+ foreach ( $share_base_cache_target as $key => $value ) {
410
+ if ( $value ) {
411
+ if ( isset( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
412
+ $sum[$key] = $sum[$key] + $sns_counts[$key];
413
+ }
414
+ }
415
+ }
416
+
417
+ }
418
+ }
419
  }
420
+
421
+ foreach ( $share_base_cache_target as $key => $value ) {
422
+ if ( $value ) {
423
+ echo '<td class="share-count">';
424
+ echo number_format( (int) $sum[$key] );
425
+ echo '</td>';
426
+ }
 
 
427
  }
428
+
429
+ wp_reset_postdata();
430
+
431
+ set_time_limit( $this->original_max_execution_time );
432
+
433
+ ?>
434
+ </tr>
435
+ </tbody>
436
+ </table>
 
 
 
 
 
 
 
 
 
 
 
437
  </div>
438
  </div>
439
+ </div>
 
440
  </div>
441
  </div>
includes/admin-setting.php CHANGED
@@ -34,63 +34,48 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
34
  if( check_admin_referer( __FILE__, '_wpnonce' ) ) {
35
 
36
  if( isset( $_POST["update_all_options"] ) && $_POST["update_all_options"] === 'Update All Options' ) {
37
-
38
- $share_base_custom_post_types = $_POST["share_base_custom_post_types"];
39
- $share_base_check_interval = $_POST["share_base_check_interval"];
40
- $share_base_posts_per_check = $_POST["share_base_posts_per_check"];
41
- $dynamic_cache = $_POST["dynamic_cache"];
42
- $share_rush_new_content_term = $_POST["share_rush_new_content_term"];
43
-
44
- $share_base_cache_target_twitter = $_POST["share_base_cache_target_twitter"];
45
- $share_base_cache_target_facebook = $_POST["share_base_cache_target_facebook"];
46
- $share_base_cache_target_gplus = $_POST["share_base_cache_target_gplus"];
47
- $share_base_cache_target_pocket = $_POST["share_base_cache_target_pocket"];
48
- $share_base_cache_target_hatebu = $_POST["share_base_cache_target_hatebu"];
49
-
50
- $data_export = $_POST["data_export"];
51
- $data_export_interval = $_POST["data_export_interval"];
52
-
53
  $share_base_cache_target = array();
54
  $follow_base_cache_target = array();
55
 
56
- if ( isset( $share_base_custom_post_types ) && $share_base_custom_post_types ) {
57
- $share_base_custom_post_types = explode( ',', $share_base_custom_post_types );
58
  update_option( self::DB_SHARE_CUSTOM_POST_TYPES, $share_base_custom_post_types );
59
  } else {
60
- update_option( self::DB_SHARE_CUSTOM_POST_TYPES, $share_base_custom_post_types );
61
  }
62
 
63
- if ( isset( $share_base_check_interval ) && $share_base_check_interval && is_numeric( $share_base_check_interval ) ) {
64
- update_option( self::DB_SHARE_CHECK_INTERVAL, $share_base_check_interval );
65
  }
66
 
67
- if ( isset( $share_base_posts_per_check ) && $share_base_posts_per_check && is_numeric( $share_base_posts_per_check ) ) {
68
- update_option( self::DB_SHARE_POSTS_PER_CHECK, $share_base_posts_per_check );
69
  }
70
 
71
- if ( isset( $dynamic_cache ) ) {
72
- update_option( self::DB_COMMON_DYNAMIC_CACHE, $dynamic_cache );
73
  }
74
 
75
- if ( isset( $share_rush_new_content_term ) && $share_rush_new_content_term && is_numeric( $share_rush_new_content_term ) ) {
76
- update_option( self::DB_SHARE_NEW_CONTENT_TERM, $share_rush_new_content_term );
77
  }
78
 
79
- if ( isset( $data_export ) ) {
80
- update_option( self::DB_COMMON_DATA_EXPORT, $data_export );
81
  }
82
 
83
- if ( isset( $data_export_interval ) && $data_export_interval && is_numeric( $data_export_interval ) ) {
84
- update_option( self::DB_COMMON_DATA_EXPORT_INTERVAL, $data_export_interval );
85
  }
86
 
87
- if ( isset( $share_base_cache_target_twitter ) && $share_base_cache_target_twitter ) {
88
  $share_base_cache_target[self::REF_SHARE_TWITTER] = true;
89
  } else {
90
  $share_base_cache_target[self::REF_SHARE_TWITTER] = false;
91
  }
92
 
93
- if ( isset( $share_base_cache_target_facebook ) && $share_base_cache_target_facebook ) {
94
  if ( Common_Util::extension_loaded_php_xml() ) {
95
  $share_base_cache_target[self::REF_SHARE_FACEBOOK] = true;
96
  } else {
@@ -100,13 +85,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
100
  $share_base_cache_target[self::REF_SHARE_FACEBOOK] = false;
101
  }
102
 
103
- if ( isset( $share_base_cache_target_gplus ) && $share_base_cache_target_gplus ) {
104
  $share_base_cache_target[self::REF_SHARE_GPLUS] = true;
105
  } else {
106
  $share_base_cache_target[self::REF_SHARE_GPLUS] = false;
107
  }
108
 
109
- if ( isset( $share_base_cache_target_pocket ) && $share_base_cache_target_pocket ) {
110
  if ( Common_Util::extension_loaded_php_xml() ) {
111
  $share_base_cache_target[self::REF_SHARE_POCKET] = true;
112
  } else {
@@ -116,7 +101,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
116
  $share_base_cache_target[self::REF_SHARE_POCKET] = false;
117
  }
118
 
119
- if ( isset( $share_base_cache_target_hatebu ) && $share_base_cache_target_hatebu ) {
120
  $share_base_cache_target[self::REF_SHARE_HATEBU] = true;
121
  } else {
122
  $share_base_cache_target[self::REF_SHARE_HATEBU] = false;
@@ -126,15 +111,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
126
  update_option( self::DB_SHARE_CACHE_TARGET, $share_base_cache_target );
127
  }
128
 
129
- $follow_base_check_interval = $_POST["follow_base_check_interval"];
130
-
131
- if ( isset( $follow_base_check_interval ) && $follow_base_check_interval && is_numeric( $follow_base_check_interval ) ) {
132
- update_option(self::DB_FOLLOW_CHECK_INTERVAL, $follow_base_check_interval);
133
  }
134
-
135
- $follow_base_cache_target_feedly = $_POST["follow_base_cache_target_feedly"];
136
-
137
- if ( isset( $follow_base_cache_target_feedly ) && $follow_base_cache_target_feedly ) {
138
  $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = true;
139
  } else {
140
  $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = false;
@@ -143,85 +124,70 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
143
  if ( ! empty( $follow_base_cache_target ) ) {
144
  update_option( self::DB_FOLLOW_CACHE_TARGET, $follow_base_cache_target );
145
  }
146
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  $this->reactivate_plugin();
148
 
149
  }
150
 
151
  if( isset( $_POST["reset_data"] ) && $_POST["reset_data"] === 'Reset' ) {
152
  Common_Util::log( '[' . __METHOD__ . '] reset' );
 
153
  $this->export_engines[self::REF_COMMON_EXPORT]->reset_export();
154
  }
155
 
156
  if( isset( $_POST["export_data"] ) && $_POST["export_data"] === 'Export' ) {
157
  Common_Util::log( '[' . __METHOD__ . '] export' );
 
158
  $this->export_engines[self::REF_COMMON_EXPORT]->execute_export( NULL );
159
  }
160
 
161
  if( isset( $_POST["clear_share_base_cache"] ) && $_POST["clear_share_base_cache"] === 'Clear Cache' ) {
162
  Common_Util::log( '[' . __METHOD__ . '] clear cache' );
 
163
  $this->cache_engines[self::REF_SHARE_BASE]->clear_cache();
164
  //$this->cache_engines[self::REF_SHARE_2ND]->clear_cache();
 
 
 
165
  $this->cache_engines[self::REF_SHARE_2ND]->initialize_cache();
 
 
166
  }
167
 
168
  if( isset( $_POST["clear_follow_base_cache"] ) && $_POST["clear_follow_base_cache"] === 'Clear Cache' ) {
169
  Common_Util::log( '[' . __METHOD__ . '] clear cache' );
 
170
  $this->cache_engines[self::REF_FOLLOW_BASE]->clear_cache();
171
  //$this->cache_engines[self::REF_FOLLOW_2ND]->clear_cache();
 
 
 
172
  $this->cache_engines[self::REF_FOLLOW_2ND]->initialize_cache();
 
 
173
  }
174
- }
175
-
176
- }
177
-
178
- $share_base_custom_post_types = get_option( self::DB_SHARE_CUSTOM_POST_TYPES );
179
-
180
- if ( ! $share_base_custom_post_types ) {
181
- $share_base_custom_post_types = array();
182
- }
183
-
184
- $share_base_check_interval = get_option( self::DB_SHARE_CHECK_INTERVAL );
185
- $share_base_check_interval = ! empty( $share_base_check_interval ) ? intval( $share_base_check_interval ) : self::OPT_SHARE_BASE_CHECK_INTERVAL;
186
-
187
- $share_base_posts_per_check = get_option( self::DB_SHARE_POSTS_PER_CHECK );
188
- $share_base_posts_per_check = ! empty( $share_base_posts_per_check ) ? intval( $share_base_posts_per_check ) : self::OPT_SHARE_BASE_POSTS_PER_CHECK;
189
-
190
- $dynamic_cache = get_option( self::DB_COMMON_DYNAMIC_CACHE );
191
- $dynamic_cache = isset( $dynamic_cache ) ? intval( $dynamic_cache ) : self::OPT_ACCESS_BASED_CACHE_NONE;
192
-
193
- $share_rush_new_content_term = get_option( self::DB_SHARE_NEW_CONTENT_TERM );
194
- $share_rush_new_content_term = ! empty( $share_rush_new_content_term ) ? intval( $share_rush_new_content_term ) : self::OPT_SHARE_RUSH_NEW_CONTENT_TERM;
195
-
196
- $share_base_cache_target = get_option( self::DB_SHARE_CACHE_TARGET );
197
-
198
- $follow_base_cache_target = get_option( self::DB_FOLLOW_CACHE_TARGET );
199
-
200
- $follow_base_check_interval = get_option( self::DB_FOLLOW_CHECK_INTERVAL );
201
- $follow_base_check_interval = ! empty( $follow_base_check_interval ) ? intval( $follow_base_check_interval ) : self::OPT_FOLLOW_BASE_CHECK_INTERVAL;
202
-
203
- $data_export = get_option( self::DB_COMMON_DATA_EXPORT );
204
- $data_export = isset( $data_export ) ? intval( $data_export ) : self::OPT_COMMON_DATA_EXPORT_MANUAL;
205
-
206
- $data_export_interval = get_option( self::DB_COMMON_DATA_EXPORT_INTERVAL );
207
- $data_export_interval = ! empty( $data_export_interval ) ? intval( $data_export_interval ) : self::OPT_COMMON_DATA_EXPORT_INTERVAL;
208
-
209
- if ( ! $share_base_cache_target ) {
210
- $share_base_cache_target[self::REF_SHARE_TWITTER] = true;
211
- $share_base_cache_target[self::REF_SHARE_FACEBOOK] = true;
212
- $share_base_cache_target[self::REF_SHARE_GPLUS] = true;
213
- if ( extension_loaded( 'xml' ) && extension_loaded( 'xmlreader' ) && extension_loaded( 'xmlwriter' )) {
214
- $share_base_cache_target[self::REF_SHARE_POCKET] = true;
215
- }
216
- $share_base_cache_target[self::REF_SHARE_HATEBU] = true;
217
  }
218
 
219
- $share_base_cache_target[self::REF_SHARE_TOTAL] = true;
220
-
221
- if ( ! $follow_base_cache_target ) {
222
- $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = true;
223
- }
224
-
225
  ?>
226
  <div class="wrap">
227
  <h2><a href="admin.php?page=scc-setting"><?php _e( 'SNS Count Cache', self::DOMAIN ) ?></a></h2>
@@ -255,19 +221,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
255
  <td>
256
  <?php
257
  $target_sns = array();
258
- if ( isset( $share_base_cache_target[self::REF_SHARE_TWITTER] ) && $share_base_cache_target[self::REF_SHARE_TWITTER] ) {
259
  $target_sns[] = 'Twitter';
260
  }
261
- if ( isset( $share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $share_base_cache_target[self::REF_SHARE_FACEBOOK] ) {
262
  $target_sns[] = 'Facebook';
263
  }
264
- if ( isset( $share_base_cache_target[self::REF_SHARE_GPLUS] ) && $share_base_cache_target[self::REF_SHARE_GPLUS] ) {
265
  $target_sns[] = 'Google+';
266
  }
267
- if ( isset( $share_base_cache_target[self::REF_SHARE_POCKET] ) && $share_base_cache_target[self::REF_SHARE_POCKET] ) {
268
  $target_sns[] = 'Pocket';
269
  }
270
- if ( isset( $share_base_cache_target[self::REF_SHARE_HATEBU] ) && $share_base_cache_target[self::REF_SHARE_HATEBU] ) {
271
  $target_sns[] = 'Hatena Bookmark';
272
  }
273
  echo implode( ", ", $target_sns );
@@ -278,8 +244,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
278
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
279
  <td><?php _e( 'Additional custom post types', self::DOMAIN ) ?></td>
280
  <td><?php
281
- if ( ! empty( $share_base_custom_post_types ) && $share_base_custom_post_types ) {
282
- echo implode( ',', $share_base_custom_post_types );
283
  } else {
284
  _e( 'N/A', self::DOMAIN );
285
  }
@@ -289,22 +255,35 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
289
  <tr>
290
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
291
  <td><?php _e( 'Interval cheking and caching share count', self::DOMAIN ) ?></td>
292
- <td><?php echo $share_base_check_interval . ' seconds'; ?></td>
293
  </tr>
294
  <tr>
295
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
296
  <td><?php _e( 'Number of posts to check at a time', self::DOMAIN ) ?></td>
297
- <td><?php echo $share_base_posts_per_check . ' posts'; ?></td>
298
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  <tr>
300
  <td><?php _e( 'Share Rush Cache', self::DOMAIN ) ?></td>
301
  <td><?php _e( 'Term considering posted content as new content', self::DOMAIN ) ?></td>
302
  <td>
303
  <?php
304
- if ( $share_rush_new_content_term == 1 ) {
305
- echo $share_rush_new_content_term . ' day';
306
- } else if ( $share_rush_new_content_term > 1 ) {
307
- echo $share_rush_new_content_term . ' days';
308
  }
309
  ?>
310
  </td>
@@ -314,7 +293,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
314
  <td>
315
  <?php
316
  $target_sns = array();
317
- if ( isset( $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) {
318
  $target_sns[] = 'Feedly';
319
  }
320
  echo implode( ", ", $target_sns );
@@ -324,21 +303,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
324
  <tr>
325
  <td><?php _e( 'Follow Base Cache', self::DOMAIN ) ?></td>
326
  <td><?php _e( 'Interval cheking and caching follower count', self::DOMAIN ) ?></td>
327
- <td><?php echo $follow_base_check_interval . ' seconds'; ?></td>
328
  </tr>
329
  <tr>
330
  <td><?php _e( 'Dynamic Cache', self::DOMAIN) ?></td><td><?php _e( 'Dynamic caching based on user access', self::DOMAIN ) ?></td><td>
331
  <?php
332
- switch ( $dynamic_cache ) {
333
- case self::OPT_ACCESS_BASED_CACHE_NONE:
334
  _e( 'disabled', self::DOMAIN );
335
  break;
336
- case self::OPT_ACCESS_BASED_SYNC_CACHE:
337
  _e( 'enabled (Synchronous Cache)', self::DOMAIN );
338
  break;
339
- case self::OPT_ACCESS_BASED_ASYNC_CACHE:
340
  _e( 'enabled (Asynchronous Cache)', self::DOMAIN );
341
- case self::OPT_ACCESS_BASED_2ND_CACHE:
 
342
  _e( 'enabled (Asynchronous 2nd Cache)', self::DOMAIN );
343
  break;
344
  }
@@ -348,7 +328,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
348
  <tr>
349
  <td><?php _e( 'Data Export', self::DOMAIN) ?></td><td><?php _e( 'Method of data export', self::DOMAIN ) ?></td><td>
350
  <?php
351
- switch ( $data_export ) {
352
  case self::OPT_COMMON_DATA_EXPORT_MANUAL:
353
  _e( 'Manual', self::DOMAIN );
354
  break;
@@ -360,12 +340,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
360
  </td>
361
  </tr>
362
  <?php
363
- if ( $data_export == self::OPT_COMMON_DATA_EXPORT_AUTO ) {
364
  ?>
365
  <tr>
366
  <td><?php _e( 'Data Export', self::DOMAIN ) ?></td>
367
  <td><?php _e( 'Interval exporting share count to a csv file', self::DOMAIN ) ?></td>
368
- <td><?php echo $data_export_interval / 3600 . ' hours'; ?></td>
369
  </tr>
370
  <?php
371
  }
@@ -387,23 +367,23 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
387
  <th><label><?php _e( 'Target SNS', self::DOMAIN ) ?></label></th>
388
  <td>
389
  <div class="sns-check">
390
- <input type="checkbox" value="1" name="share_base_cache_target_twitter"<?php if ( $share_base_cache_target[self::REF_SHARE_TWITTER] ) echo ' checked="checked"'; ?> />
391
  <label><?php _e( 'Twitter', self::DOMAIN ) ?></label>
392
  </div>
393
  <div class="sns-check">
394
- <input type="checkbox" value="1" name="share_base_cache_target_facebook"<?php if ( $share_base_cache_target[self::REF_SHARE_FACEBOOK] ) echo ' checked="checked"'; ?> />
395
  <label><?php _e( 'Facebook', self::DOMAIN ) ?></label>
396
  </div>
397
  <div class="sns-check">
398
- <input type="checkbox" value="1" name="share_base_cache_target_gplus"<?php if ( $share_base_cache_target[self::REF_SHARE_GPLUS] ) echo ' checked="checked"'; ?> />
399
  <label><?php _e( 'Google+', self::DOMAIN ) ?></label>
400
  </div>
401
  <div class="sns-check">
402
- <input type="checkbox" value="1" name="share_base_cache_target_pocket"<?php if ( $share_base_cache_target[self::REF_SHARE_POCKET] ) echo ' checked="checked"'; ?> />
403
  <label><?php _e( 'Pocket', self::DOMAIN ) ?></label>
404
  </div>
405
  <div class="sns-check">
406
- <input type="checkbox" value="1" name="share_base_cache_target_hatebu"<?php if ( $share_base_cache_target[self::REF_SHARE_HATEBU] ) echo ' checked="checked"'; ?> />
407
  <label><?php _e( 'Hatena Bookmark', self::DOMAIN ) ?></label>
408
  </div>
409
  </td>
@@ -411,7 +391,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
411
  <tr>
412
  <th><label><?php _e( 'Additional custom post types', self::DOMAIN ) ?></label></th>
413
  <td>
414
- <input type="text" class="text" name="share_base_custom_post_types" size="60" value="" />
415
  <br>
416
  <label><?php _e( 'e.g. aaa, bbb, ccc (comma-delimited)', self::DOMAIN ) ?></label>
417
  </td>
@@ -419,17 +399,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
419
  <tr>
420
  <th><label><?php _e( 'Interval cheking and caching share count (sec)', self::DOMAIN ) ?></label></th>
421
  <td>
422
- <input type="text" class="text" name="share_base_check_interval" size="20" value="" />
423
  <label><?php _e( 'Default: 600', self::DOMAIN ) ?></label>
424
  </td>
425
  </tr>
426
  <tr>
427
  <th><label><?php _e( 'Number of posts to check at a time (posts)', self::DOMAIN ) ?></label></th>
428
  <td>
429
- <input type="text" class="text" name="share_base_posts_per_check" size="20" value="" />
430
  <label><?php _e( 'Default: 20', self::DOMAIN ) ?></label>
431
  </td>
432
  </tr>
 
 
 
 
 
 
 
 
 
 
433
  </table>
434
  <div class="submit-button">
435
  <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
@@ -446,20 +436,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
446
  <th><label><?php _e( 'Term considering posted content as new content', self::DOMAIN ) ?></label></th>
447
  <td>
448
  <select name="share_rush_new_content_term">
449
- <option value="1"<?php if ( $share_rush_new_content_term == 1 ) echo ' selected="selected"'; ?>>1 day</option>
450
- <option value="2"<?php if ( $share_rush_new_content_term == 2 ) echo ' selected="selected"'; ?>>2 days</option>
451
- <option value="3"<?php if ( $share_rush_new_content_term == 3 ) echo ' selected="selected"'; ?>>3 days</option>
452
- <option value="4"<?php if ( $share_rush_new_content_term == 4 ) echo ' selected="selected"'; ?>>4 days</option>
453
- <option value="5"<?php if ( $share_rush_new_content_term == 5 ) echo ' selected="selected"'; ?>>5 days</option>
454
- <option value="6"<?php if ( $share_rush_new_content_term == 6 ) echo ' selected="selected"'; ?>>6 days</option>
455
- <option value="7"<?php if ( $share_rush_new_content_term == 7 ) echo ' selected="selected"'; ?>>7 days</option>
456
- <option value="8"<?php if ( $share_rush_new_content_term == 8 ) echo ' selected="selected"'; ?>>8 days</option>
457
- <option value="9"<?php if ( $share_rush_new_content_term == 9 ) echo ' selected="selected"'; ?>>9 days</option>
458
- <option value="10"<?php if ( $share_rush_new_content_term == 10 ) echo ' selected="selected"'; ?>>10 days</option>
459
- <option value="11"<?php if ( $share_rush_new_content_term == 11 ) echo ' selected="selected"'; ?>>11 days</option>
460
- <option value="12"<?php if ( $share_rush_new_content_term == 12 ) echo ' selected="selected"'; ?>>12 days</option>
461
- <option value="13"<?php if ( $share_rush_new_content_term == 13 ) echo ' selected="selected"'; ?>>13 days</option>
462
- <option value="14"<?php if ( $share_rush_new_content_term == 14 ) echo ' selected="selected"'; ?>>14 days</option>
463
  </select>
464
  <label><?php _e( 'Default: 3 days', self::DOMAIN ) ?></label>
465
  </td>
@@ -479,7 +469,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
479
  <th><label><?php _e( 'Target SNS', self::DOMAIN ) ?></label></th>
480
  <td>
481
  <div class="sns-check">
482
- <input type="checkbox" value="1" name="follow_base_cache_target_feedly"<?php if ( $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) echo ' checked="checked"'; ?> />
483
  <label><?php _e( 'Feedly', self::DOMAIN ) ?></label>
484
  </div>
485
  </td>
@@ -487,7 +477,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
487
  <tr>
488
  <th><label><?php _e( 'Interval cheking and caching follower count (sec)', self::DOMAIN ) ?></label></th>
489
  <td>
490
- <input type="text" class="text" name="follow_base_check_interval" size="20" value="" />
491
  <label><?php _e( 'Default: 1800', self::DOMAIN ) ?></label>
492
  </td>
493
  </tr>
@@ -506,11 +496,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
506
  <tr>
507
  <th><label><?php _e( 'Dynamic caching based on user access', self::DOMAIN ) ?></label></th>
508
  <td>
509
- <select name="dynamic cache">
510
- <option value="0"<?php if ( $dynamic_cache == 0 ) echo ' selected="selected"'; ?>><?php _e( 'None', self::DOMAIN ) ?></option>
511
- <option value="1"<?php if ( $dynamic_cache == 1 ) echo ' selected="selected"'; ?>><?php _e( 'Synchronous Cache', self::DOMAIN ) ?></option>
512
- <option value="2"<?php if ( $dynamic_cache == 2 ) echo ' selected="selected"'; ?>><?php _e( 'Asynchronous Cache', self::DOMAIN ) ?></option>
513
- <option value="3"<?php if ( $dynamic_cache == 3 ) echo ' selected="selected"'; ?>><?php _e( 'Asynchronous 2nd Cache', self::DOMAIN ) ?></option>
514
  </select>
515
  <label><?php _e('Default: None', self::DOMAIN) ?></label>
516
  </td>
@@ -529,29 +519,180 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
529
  <tr>
530
  <th><label><?php _e( 'Method of data export', self::DOMAIN ) ?></label></th>
531
  <td>
532
- <select name="data_export">
533
- <option value="0"<?php if ( $data_export == 0 ) echo ' selected="selected"'; ?>><?php _e( 'Manual', self::DOMAIN ) ?></option>
534
- <option value="1" disabled<?php if ( $data_export == 1 ) echo ' selected="selected"'; ?>><?php _e( 'Auto', self::DOMAIN ) ?></option>
535
  </select>
536
  <label><?php _e('Default: Manual', self::DOMAIN) ?></label>
537
  </td>
538
  </tr>
539
  <?php
540
- if ( $data_export == 1 ) {
541
  ?>
542
 
543
  <tr>
544
  <th><label><?php _e( 'Interval exporting share count to a csv file', self::DOMAIN ) ?></label></th>
545
  <td>
546
  <select name="data_export_interval">
547
- <option value="10800"<?php if ( $data_export_interval == 10800 ) echo ' selected="selected"'; ?>>3 hours</option>
548
- <option value="21600"<?php if ( $data_export_interval == 21600 ) echo ' selected="selected"'; ?>>6 hours</option>
549
- <option value="43200"<?php if ( $data_export_interval == 43200 ) echo ' selected="selected"'; ?>>12 hours</option>
550
- <option value="86400"<?php if ( $data_export_interval == 86400 ) echo ' selected="selected"'; ?>>24 hours</option>
 
551
  </select>
552
  <label><?php _e( 'Default: 12 hours', self::DOMAIN ) ?></label>
553
  </td>
554
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
555
  <?php
556
  }
557
  ?>
34
  if( check_admin_referer( __FILE__, '_wpnonce' ) ) {
35
 
36
  if( isset( $_POST["update_all_options"] ) && $_POST["update_all_options"] === 'Update All Options' ) {
37
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  $share_base_cache_target = array();
39
  $follow_base_cache_target = array();
40
 
41
+ if ( isset( $_POST["share_base_custom_post_types"] ) && $_POST["share_base_custom_post_types"] ) {
42
+ $share_base_custom_post_types = explode( ',', $_POST["share_base_custom_post_types"] );
43
  update_option( self::DB_SHARE_CUSTOM_POST_TYPES, $share_base_custom_post_types );
44
  } else {
45
+ update_option( self::DB_SHARE_CUSTOM_POST_TYPES, array() );
46
  }
47
 
48
+ if ( isset( $_POST["share_base_check_interval"] ) && $_POST["share_base_check_interval"] && is_numeric( $_POST["share_base_check_interval"] ) ) {
49
+ update_option( self::DB_SHARE_CHECK_INTERVAL, $_POST["share_base_check_interval"] );
50
  }
51
 
52
+ if ( isset( $_POST["share_base_posts_per_check"] ) && $_POST["share_base_posts_per_check"] && is_numeric( $_POST["share_base_posts_per_check"] ) ) {
53
+ update_option( self::DB_SHARE_POSTS_PER_CHECK, $_POST["share_base_posts_per_check"] );
54
  }
55
 
56
+ if ( isset( $_POST["dynamic_cache_mode"] ) ) {
57
+ update_option( self::DB_COMMON_DYNAMIC_CACHE, $_POST["dynamic_cache_mode"] );
58
  }
59
 
60
+ if ( isset( $_POST["share_rush_new_content_term"] ) && $_POST["share_rush_new_content_term"] && is_numeric( $_POST["share_rush_new_content_term"] ) ) {
61
+ update_option( self::DB_SHARE_NEW_CONTENT_TERM, $_POST["share_rush_new_content_term"] );
62
  }
63
 
64
+ if ( isset( $_POST["data_export_mode"] ) ) {
65
+ update_option( self::DB_COMMON_DATA_EXPORT, $_POST["data_export_mode"] );
66
  }
67
 
68
+ if ( isset( $_POST["data_export_interval"] ) && $_POST["data_export_interval"] && is_numeric( $_POST["data_export_interval"] ) ) {
69
+ update_option( self::DB_COMMON_DATA_EXPORT_INTERVAL, $_POST["data_export_interval"] );
70
  }
71
 
72
+ if ( isset( $_POST["share_base_cache_target_twitter"] ) && $_POST["share_base_cache_target_twitter"] ) {
73
  $share_base_cache_target[self::REF_SHARE_TWITTER] = true;
74
  } else {
75
  $share_base_cache_target[self::REF_SHARE_TWITTER] = false;
76
  }
77
 
78
+ if ( isset( $_POST["share_base_cache_target_facebook"] ) && $_POST["share_base_cache_target_facebook"] ) {
79
  if ( Common_Util::extension_loaded_php_xml() ) {
80
  $share_base_cache_target[self::REF_SHARE_FACEBOOK] = true;
81
  } else {
85
  $share_base_cache_target[self::REF_SHARE_FACEBOOK] = false;
86
  }
87
 
88
+ if ( isset( $_POST["share_base_cache_target_gplus"] ) && $_POST["share_base_cache_target_gplus"] ) {
89
  $share_base_cache_target[self::REF_SHARE_GPLUS] = true;
90
  } else {
91
  $share_base_cache_target[self::REF_SHARE_GPLUS] = false;
92
  }
93
 
94
+ if ( isset( $_POST["share_base_cache_target_pocket"] ) && $_POST["share_base_cache_target_pocket"] ) {
95
  if ( Common_Util::extension_loaded_php_xml() ) {
96
  $share_base_cache_target[self::REF_SHARE_POCKET] = true;
97
  } else {
101
  $share_base_cache_target[self::REF_SHARE_POCKET] = false;
102
  }
103
 
104
+ if ( isset( $_POST["share_base_cache_target_hatebu"] ) && $_POST["share_base_cache_target_hatebu"] ) {
105
  $share_base_cache_target[self::REF_SHARE_HATEBU] = true;
106
  } else {
107
  $share_base_cache_target[self::REF_SHARE_HATEBU] = false;
111
  update_option( self::DB_SHARE_CACHE_TARGET, $share_base_cache_target );
112
  }
113
 
114
+ if ( isset( $_POST["follow_base_check_interval"] ) && $_POST["follow_base_check_interval"] && is_numeric( $_POST["follow_base_check_interval"] ) ) {
115
+ update_option( self::DB_FOLLOW_CHECK_INTERVAL, $_POST["follow_base_check_interval"] );
 
 
116
  }
117
+
118
+ if ( isset( $_POST["follow_base_cache_target_feedly"] ) && $_POST["follow_base_cache_target_feedly"] ) {
 
 
119
  $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = true;
120
  } else {
121
  $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = false;
124
  if ( ! empty( $follow_base_cache_target ) ) {
125
  update_option( self::DB_FOLLOW_CACHE_TARGET, $follow_base_cache_target );
126
  }
127
+
128
+ if ( isset( $_POST["scheme_migration_mode"] ) && $_POST["scheme_migration_mode"] ) {
129
+ update_option( self::DB_COMMON_SCHEME_MIGRATION_MODE, self::OPT_COMMON_SCHEME_MIGRATION_MODE_ON );
130
+ } else {
131
+ update_option( self::DB_COMMON_SCHEME_MIGRATION_MODE, self::OPT_COMMON_SCHEME_MIGRATION_MODE_OFF );
132
+ }
133
+
134
+ if ( isset( $_POST['cronbtype'] ) && $_POST['cronbtype'] == 'mon' ) {
135
+ update_option( self::DB_COMMON_DATA_EXPORT_SCHEDULE, $_POST['moncronminutes'] . ' ' . $_POST['moncronhours'] . ' ' . $_POST['moncronmday'] . ' * *' );
136
+ }
137
+ if ( isset( $_POST['cronbtype'] ) && $_POST['cronbtype'] == 'week' ) {
138
+ update_option( self::DB_COMMON_DATA_EXPORT_SCHEDULE, $_POST['weekcronminutes'] . ' ' . $_POST['weekcronhours'] . ' * * ' . $_POST['weekcronwday'] );
139
+ }
140
+ if ( isset( $_POST['cronbtype'] ) && $_POST['cronbtype'] == 'day' ) {
141
+ update_option( self::DB_COMMON_DATA_EXPORT_SCHEDULE, $_POST['daycronminutes'] . ' ' . $_POST['daycronhours'] . ' * * *' );
142
+ }
143
+ if ( isset( $_POST['cronbtype'] ) && $_POST['cronbtype'] == 'hour' ) {
144
+ update_option( self::DB_COMMON_DATA_EXPORT_SCHEDULE, $_POST['hourcronminutes'] . ' * * * *' );
145
+ }
146
+
147
  $this->reactivate_plugin();
148
 
149
  }
150
 
151
  if( isset( $_POST["reset_data"] ) && $_POST["reset_data"] === 'Reset' ) {
152
  Common_Util::log( '[' . __METHOD__ . '] reset' );
153
+
154
  $this->export_engines[self::REF_COMMON_EXPORT]->reset_export();
155
  }
156
 
157
  if( isset( $_POST["export_data"] ) && $_POST["export_data"] === 'Export' ) {
158
  Common_Util::log( '[' . __METHOD__ . '] export' );
159
+
160
  $this->export_engines[self::REF_COMMON_EXPORT]->execute_export( NULL );
161
  }
162
 
163
  if( isset( $_POST["clear_share_base_cache"] ) && $_POST["clear_share_base_cache"] === 'Clear Cache' ) {
164
  Common_Util::log( '[' . __METHOD__ . '] clear cache' );
165
+
166
  $this->cache_engines[self::REF_SHARE_BASE]->clear_cache();
167
  //$this->cache_engines[self::REF_SHARE_2ND]->clear_cache();
168
+
169
+ set_time_limit( $this->extended_max_execution_time );
170
+
171
  $this->cache_engines[self::REF_SHARE_2ND]->initialize_cache();
172
+
173
+ set_time_limit( $this->original_max_execution_time );
174
  }
175
 
176
  if( isset( $_POST["clear_follow_base_cache"] ) && $_POST["clear_follow_base_cache"] === 'Clear Cache' ) {
177
  Common_Util::log( '[' . __METHOD__ . '] clear cache' );
178
+
179
  $this->cache_engines[self::REF_FOLLOW_BASE]->clear_cache();
180
  //$this->cache_engines[self::REF_FOLLOW_2ND]->clear_cache();
181
+
182
+ set_time_limit( $this->extended_max_execution_time );
183
+
184
  $this->cache_engines[self::REF_FOLLOW_2ND]->initialize_cache();
185
+
186
+ set_time_limit( $this->original_max_execution_time );
187
  }
188
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  }
190
 
 
 
 
 
 
 
191
  ?>
192
  <div class="wrap">
193
  <h2><a href="admin.php?page=scc-setting"><?php _e( 'SNS Count Cache', self::DOMAIN ) ?></a></h2>
221
  <td>
222
  <?php
223
  $target_sns = array();
224
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) {
225
  $target_sns[] = 'Twitter';
226
  }
227
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) {
228
  $target_sns[] = 'Facebook';
229
  }
230
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) && $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) {
231
  $target_sns[] = 'Google+';
232
  }
233
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_POCKET] ) && $this->share_base_cache_target[self::REF_SHARE_POCKET] ) {
234
  $target_sns[] = 'Pocket';
235
  }
236
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) && $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) {
237
  $target_sns[] = 'Hatena Bookmark';
238
  }
239
  echo implode( ", ", $target_sns );
244
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
245
  <td><?php _e( 'Additional custom post types', self::DOMAIN ) ?></td>
246
  <td><?php
247
+ if ( ! empty( $this->share_base_custom_post_types ) && $this->share_base_custom_post_types ) {
248
+ echo implode( ',', $this->share_base_custom_post_types );
249
  } else {
250
  _e( 'N/A', self::DOMAIN );
251
  }
255
  <tr>
256
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
257
  <td><?php _e( 'Interval cheking and caching share count', self::DOMAIN ) ?></td>
258
+ <td><?php echo $this->share_base_check_interval . ' seconds'; ?></td>
259
  </tr>
260
  <tr>
261
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
262
  <td><?php _e( 'Number of posts to check at a time', self::DOMAIN ) ?></td>
263
+ <td><?php echo $this->share_base_posts_per_check . ' posts'; ?></td>
264
+ </tr>
265
+ <tr>
266
+ <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
267
+ <td><?php _e( 'Migration mode from http to https', self::DOMAIN ) ?></td>
268
+ <td>
269
+ <?php
270
+ if ( $this->scheme_migration_mode ) {
271
+ echo 'On';
272
+ } else {
273
+ echo 'Off';
274
+ }
275
+ ?>
276
+ </td>
277
+ </tr>
278
  <tr>
279
  <td><?php _e( 'Share Rush Cache', self::DOMAIN ) ?></td>
280
  <td><?php _e( 'Term considering posted content as new content', self::DOMAIN ) ?></td>
281
  <td>
282
  <?php
283
+ if ( $this->share_rush_new_content_term == 1 ) {
284
+ echo $this->share_rush_new_content_term . ' day';
285
+ } else if ( $this->share_rush_new_content_term > 1 ) {
286
+ echo $this->share_rush_new_content_term . ' days';
287
  }
288
  ?>
289
  </td>
293
  <td>
294
  <?php
295
  $target_sns = array();
296
+ if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) {
297
  $target_sns[] = 'Feedly';
298
  }
299
  echo implode( ", ", $target_sns );
303
  <tr>
304
  <td><?php _e( 'Follow Base Cache', self::DOMAIN ) ?></td>
305
  <td><?php _e( 'Interval cheking and caching follower count', self::DOMAIN ) ?></td>
306
+ <td><?php echo $this->follow_base_check_interval . ' seconds'; ?></td>
307
  </tr>
308
  <tr>
309
  <td><?php _e( 'Dynamic Cache', self::DOMAIN) ?></td><td><?php _e( 'Dynamic caching based on user access', self::DOMAIN ) ?></td><td>
310
  <?php
311
+ switch ( $this->dynamic_cache_mode ) {
312
+ case self::OPT_COMMON_ACCESS_BASED_CACHE_NONE:
313
  _e( 'disabled', self::DOMAIN );
314
  break;
315
+ case self::OPT_COMMON_ACCESS_BASED_SYNC_CACHE:
316
  _e( 'enabled (Synchronous Cache)', self::DOMAIN );
317
  break;
318
+ case self::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE:
319
  _e( 'enabled (Asynchronous Cache)', self::DOMAIN );
320
+ break;
321
+ case self::OPT_COMMON_ACCESS_BASED_2ND_CACHE:
322
  _e( 'enabled (Asynchronous 2nd Cache)', self::DOMAIN );
323
  break;
324
  }
328
  <tr>
329
  <td><?php _e( 'Data Export', self::DOMAIN) ?></td><td><?php _e( 'Method of data export', self::DOMAIN ) ?></td><td>
330
  <?php
331
+ switch ( $this->data_export_mode ) {
332
  case self::OPT_COMMON_DATA_EXPORT_MANUAL:
333
  _e( 'Manual', self::DOMAIN );
334
  break;
340
  </td>
341
  </tr>
342
  <?php
343
+ if ( $this->data_export_mode == self::OPT_COMMON_DATA_EXPORT_AUTO ) {
344
  ?>
345
  <tr>
346
  <td><?php _e( 'Data Export', self::DOMAIN ) ?></td>
347
  <td><?php _e( 'Interval exporting share count to a csv file', self::DOMAIN ) ?></td>
348
+ <td><?php echo $this->data_export_interval / 3600 . ' hours'; ?></td>
349
  </tr>
350
  <?php
351
  }
367
  <th><label><?php _e( 'Target SNS', self::DOMAIN ) ?></label></th>
368
  <td>
369
  <div class="sns-check">
370
+ <input type="checkbox" value="1" name="share_base_cache_target_twitter"<?php if ( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) echo ' checked="checked"'; ?> />
371
  <label><?php _e( 'Twitter', self::DOMAIN ) ?></label>
372
  </div>
373
  <div class="sns-check">
374
+ <input type="checkbox" value="1" name="share_base_cache_target_facebook"<?php if ( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) echo ' checked="checked"'; ?> />
375
  <label><?php _e( 'Facebook', self::DOMAIN ) ?></label>
376
  </div>
377
  <div class="sns-check">
378
+ <input type="checkbox" value="1" name="share_base_cache_target_gplus"<?php if ( $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) echo ' checked="checked"'; ?> />
379
  <label><?php _e( 'Google+', self::DOMAIN ) ?></label>
380
  </div>
381
  <div class="sns-check">
382
+ <input type="checkbox" value="1" name="share_base_cache_target_pocket"<?php if ( $this->share_base_cache_target[self::REF_SHARE_POCKET] ) echo ' checked="checked"'; ?> />
383
  <label><?php _e( 'Pocket', self::DOMAIN ) ?></label>
384
  </div>
385
  <div class="sns-check">
386
+ <input type="checkbox" value="1" name="share_base_cache_target_hatebu"<?php if ( $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) echo ' checked="checked"'; ?> />
387
  <label><?php _e( 'Hatena Bookmark', self::DOMAIN ) ?></label>
388
  </div>
389
  </td>
391
  <tr>
392
  <th><label><?php _e( 'Additional custom post types', self::DOMAIN ) ?></label></th>
393
  <td>
394
+ <input type="text" class="text" name="share_base_custom_post_types" size="60" value="<?php echo implode( ',', $this->share_base_custom_post_types ); ?>" />
395
  <br>
396
  <label><?php _e( 'e.g. aaa, bbb, ccc (comma-delimited)', self::DOMAIN ) ?></label>
397
  </td>
399
  <tr>
400
  <th><label><?php _e( 'Interval cheking and caching share count (sec)', self::DOMAIN ) ?></label></th>
401
  <td>
402
+ <input type="text" class="text" name="share_base_check_interval" size="20" value="<?php echo $this->share_base_check_interval; ?>" />
403
  <label><?php _e( 'Default: 600', self::DOMAIN ) ?></label>
404
  </td>
405
  </tr>
406
  <tr>
407
  <th><label><?php _e( 'Number of posts to check at a time (posts)', self::DOMAIN ) ?></label></th>
408
  <td>
409
+ <input type="text" class="text" name="share_base_posts_per_check" size="20" value="<?php echo $this->share_base_posts_per_check; ?>" />
410
  <label><?php _e( 'Default: 20', self::DOMAIN ) ?></label>
411
  </td>
412
  </tr>
413
+ <tr>
414
+ <th><label><?php _e( 'Migration mode from http to https', self::DOMAIN ) ?></label></th>
415
+ <td>
416
+ <select name="scheme_migration_mode">
417
+ <option value="0"<?php if ( $this->scheme_migration_mode == self::OPT_COMMON_SCHEME_MIGRATION_MODE_OFF ) echo ' selected="selected"'; ?>><?php _e( 'Off', self::DOMAIN ) ?></option>
418
+ <option value="1"<?php if ( $this->scheme_migration_mode == self::OPT_COMMON_SCHEME_MIGRATION_MODE_ON ) echo ' selected="selected"'; ?>><?php _e( 'On', self::DOMAIN ) ?></option>
419
+ </select>
420
+ <label><?php _e('Default: Off', self::DOMAIN) ?></label>
421
+ </td>
422
+ </tr>
423
  </table>
424
  <div class="submit-button">
425
  <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
436
  <th><label><?php _e( 'Term considering posted content as new content', self::DOMAIN ) ?></label></th>
437
  <td>
438
  <select name="share_rush_new_content_term">
439
+ <option value="1"<?php if ( $this->share_rush_new_content_term == 1 ) echo ' selected="selected"'; ?>>1 day</option>
440
+ <option value="2"<?php if ( $this->share_rush_new_content_term == 2 ) echo ' selected="selected"'; ?>>2 days</option>
441
+ <option value="3"<?php if ( $this->share_rush_new_content_term == 3 ) echo ' selected="selected"'; ?>>3 days</option>
442
+ <option value="4"<?php if ( $this->share_rush_new_content_term == 4 ) echo ' selected="selected"'; ?>>4 days</option>
443
+ <option value="5"<?php if ( $this->share_rush_new_content_term == 5 ) echo ' selected="selected"'; ?>>5 days</option>
444
+ <option value="6"<?php if ( $this->share_rush_new_content_term == 6 ) echo ' selected="selected"'; ?>>6 days</option>
445
+ <option value="7"<?php if ( $this->share_rush_new_content_term == 7 ) echo ' selected="selected"'; ?>>7 days</option>
446
+ <option value="8"<?php if ( $this->share_rush_new_content_term == 8 ) echo ' selected="selected"'; ?>>8 days</option>
447
+ <option value="9"<?php if ( $this->share_rush_new_content_term == 9 ) echo ' selected="selected"'; ?>>9 days</option>
448
+ <option value="10"<?php if ( $this->share_rush_new_content_term == 10 ) echo ' selected="selected"'; ?>>10 days</option>
449
+ <option value="11"<?php if ( $this->share_rush_new_content_term == 11 ) echo ' selected="selected"'; ?>>11 days</option>
450
+ <option value="12"<?php if ( $this->share_rush_new_content_term == 12 ) echo ' selected="selected"'; ?>>12 days</option>
451
+ <option value="13"<?php if ( $this->share_rush_new_content_term == 13 ) echo ' selected="selected"'; ?>>13 days</option>
452
+ <option value="14"<?php if ( $this->share_rush_new_content_term == 14 ) echo ' selected="selected"'; ?>>14 days</option>
453
  </select>
454
  <label><?php _e( 'Default: 3 days', self::DOMAIN ) ?></label>
455
  </td>
469
  <th><label><?php _e( 'Target SNS', self::DOMAIN ) ?></label></th>
470
  <td>
471
  <div class="sns-check">
472
+ <input type="checkbox" value="1" name="follow_base_cache_target_feedly"<?php if ( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) echo ' checked="checked"'; ?> />
473
  <label><?php _e( 'Feedly', self::DOMAIN ) ?></label>
474
  </div>
475
  </td>
477
  <tr>
478
  <th><label><?php _e( 'Interval cheking and caching follower count (sec)', self::DOMAIN ) ?></label></th>
479
  <td>
480
+ <input type="text" class="text" name="follow_base_check_interval" size="20" value="<?php echo $this->follow_base_check_interval; ?>" />
481
  <label><?php _e( 'Default: 1800', self::DOMAIN ) ?></label>
482
  </td>
483
  </tr>
496
  <tr>
497
  <th><label><?php _e( 'Dynamic caching based on user access', self::DOMAIN ) ?></label></th>
498
  <td>
499
+ <select name="dynamic_cache_mode">
500
+ <option value="0"<?php if ( $this->dynamic_cache_mode == self::OPT_COMMON_ACCESS_BASED_CACHE_NONE ) echo ' selected="selected"'; ?>><?php _e( 'None', self::DOMAIN ) ?></option>
501
+ <option value="1"<?php if ( $this->dynamic_cache_mode == self::OPT_COMMON_ACCESS_BASED_SYNC_CACHE ) echo ' selected="selected"'; ?>><?php _e( 'Synchronous Cache', self::DOMAIN ) ?></option>
502
+ <option value="2"<?php if ( $this->dynamic_cache_mode == self::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE ) echo ' selected="selected"'; ?>><?php _e( 'Asynchronous Cache', self::DOMAIN ) ?></option>
503
+ <option value="3"<?php if ( $this->dynamic_cache_mode == self::OPT_COMMON_ACCESS_BASED_2ND_CACHE ) echo ' selected="selected"'; ?>><?php _e( 'Asynchronous 2nd Cache', self::DOMAIN ) ?></option>
504
  </select>
505
  <label><?php _e('Default: None', self::DOMAIN) ?></label>
506
  </td>
519
  <tr>
520
  <th><label><?php _e( 'Method of data export', self::DOMAIN ) ?></label></th>
521
  <td>
522
+ <select name="data_export_mode">
523
+ <option value="0"<?php if ( $this->data_export_mode == self::OPT_COMMON_DATA_EXPORT_MANUAL ) echo ' selected="selected"'; ?>><?php _e( 'Manual', self::DOMAIN ) ?></option>
524
+ <option value="1"<?php if ( $this->data_export_mode == self::OPT_COMMON_DATA_EXPORT_AUTO ) echo ' selected="selected"'; ?> disabled="disabled"><?php _e( 'Auto', self::DOMAIN ) ?></option>
525
  </select>
526
  <label><?php _e('Default: Manual', self::DOMAIN) ?></label>
527
  </td>
528
  </tr>
529
  <?php
530
+ if ( $this->data_export_mode == self::OPT_COMMON_DATA_EXPORT_AUTO ) {
531
  ?>
532
 
533
  <tr>
534
  <th><label><?php _e( 'Interval exporting share count to a csv file', self::DOMAIN ) ?></label></th>
535
  <td>
536
  <select name="data_export_interval">
537
+ <option value="600"<?php if ( $this->data_export_interval == 600 ) echo ' selected="selected"'; ?>>10 minites</option>
538
+ <option value="10800"<?php if ( $this->data_export_interval == 10800 ) echo ' selected="selected"'; ?>>3 hours</option>
539
+ <option value="21600"<?php if ( $this->data_export_interval == 21600 ) echo ' selected="selected"'; ?>>6 hours</option>
540
+ <option value="43200"<?php if ( $this->data_export_interval == 43200 ) echo ' selected="selected"'; ?>>12 hours</option>
541
+ <option value="86400"<?php if ( $this->data_export_interval == 86400 ) echo ' selected="selected"'; ?>>24 hours</option>
542
  </select>
543
  <label><?php _e( 'Default: 12 hours', self::DOMAIN ) ?></label>
544
  </td>
545
+ </tr>
546
+
547
+ <?php
548
+
549
+ list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ', $this->data_export_schedule, 5 );
550
+ if ( strstr( $cronstr[ 'minutes' ], '*/' ) ) {
551
+ $minutes = explode( '/', $cronstr[ 'minutes' ] );
552
+ } else {
553
+ $minutes = explode( ',', $cronstr[ 'minutes' ] );
554
+ }
555
+ if ( strstr( $cronstr[ 'hours' ], '*/' ) ) {
556
+ $hours = explode( '/', $cronstr[ 'hours' ] );
557
+ } else {
558
+ $hours = explode( ',', $cronstr[ 'hours' ] );
559
+ }
560
+ if ( strstr( $cronstr[ 'mday' ], '*/' ) ) {
561
+ $mday = explode( '/', $cronstr[ 'mday' ] );
562
+ } else {
563
+ $mday = explode( ',', $cronstr[ 'mday' ] );
564
+ }
565
+ if ( strstr( $cronstr[ 'mon' ], '*/' ) ) {
566
+ $mon = explode( '/', $cronstr[ 'mon' ] );
567
+ } else {
568
+ $mon = explode( ',', $cronstr[ 'mon' ] );
569
+ }
570
+ if ( strstr( $cronstr[ 'wday' ], '*/' ) ) {
571
+ $wday = explode( '/', $cronstr[ 'wday' ] );
572
+ } else {
573
+ $wday = explode( ',', $cronstr[ 'wday' ] );
574
+ }
575
+ ?>
576
+
577
+ <tr class="wpcronbasic">
578
+ <th scope="row"><?php _e( 'Scheduler', self::DOMAIN ); ?></th>
579
+ <td>
580
+ <table id="wpcronbasic">
581
+ <tr>
582
+ <th>
583
+ <?php _e( 'Type', self::DOMAIN ); ?>
584
+ </th>
585
+ <th>
586
+ </th>
587
+ <th>
588
+ <?php _e( 'Hour', self::DOMAIN ); ?>
589
+ </th>
590
+ <th>
591
+ <?php _e( 'Minute', self::DOMAIN ); ?>
592
+ </th>
593
+ </tr>
594
+ <tr>
595
+ <td>
596
+ <label for="idcronbtype-mon">
597
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $mday[ 0 ] ), FALSE ) . ' name="cronbtype" id="idcronbtype-mon" value="mon" /> ' . __( 'monthly', self::DOMAIN ); ?>
598
+ </label>
599
+ </td>
600
+ <td>
601
+ <select name="moncronmday">
602
+ <?php for ( $i = 1; $i <= 31; $i ++ ) {
603
+ echo '<option ' . selected( in_array( "$i", $mday, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . __( 'on', self::DOMAIN ) . ' ' . $i . '.</option>';
604
+ } ?>
605
+ </select>
606
+ </td>
607
+ <td>
608
+ <select name="moncronhours">
609
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
610
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
611
+ } ?>
612
+ </select>
613
+ </td>
614
+ <td>
615
+ <select name="moncronminutes">
616
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
617
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
618
+ } ?>
619
+ </select>
620
+ </td>
621
+ </tr>
622
+ <tr>
623
+ <td>
624
+ <label for="idcronbtype-week">
625
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $wday[ 0 ] ), FALSE ) . ' name="cronbtype" id="idcronbtype-week" value="week" /> ' . __( 'weekly', self::DOMAIN ); ?>
626
+ </label>
627
+ </td>
628
+ <td>
629
+ <select name="weekcronwday">
630
+ <?php echo '<option ' . selected( in_array( "0", $wday, TRUE ), TRUE, FALSE ) . ' value="0" />' . __( 'Sunday', self::DOMAIN ) . '</option>';
631
+ echo '<option ' . selected( in_array( "1", $wday, TRUE ), TRUE, FALSE ) . ' value="1" />' . __( 'Monday', self::DOMAIN ) . '</option>';
632
+ echo '<option ' . selected( in_array( "2", $wday, TRUE ), TRUE, FALSE ) . ' value="2" />' . __( 'Tuesday', self::DOMAIN ) . '</option>';
633
+ echo '<option ' . selected( in_array( "3", $wday, TRUE ), TRUE, FALSE ) . ' value="3" />' . __( 'Wednesday', self::DOMAIN ) . '</option>';
634
+ echo '<option ' . selected( in_array( "4", $wday, TRUE ), TRUE, FALSE ) . ' value="4" />' . __( 'Thursday', self::DOMAIN ) . '</option>';
635
+ echo '<option ' . selected( in_array( "5", $wday, TRUE ), TRUE, FALSE ) . ' value="5" />' . __( 'Friday', self::DOMAIN ) . '</option>';
636
+ echo '<option ' . selected( in_array( "6", $wday, TRUE ), TRUE, FALSE ) . ' value="6" />' . __( 'Saturday', self::DOMAIN ) . '</option>'; ?>
637
+ </select>
638
+ </td>
639
+ <td>
640
+ <select name="weekcronhours">
641
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
642
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
643
+ } ?>
644
+ </select>
645
+ </td>
646
+ <td>
647
+ <select name="weekcronminutes">
648
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
649
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
650
+ } ?></select>
651
+ </td>
652
+ </tr>
653
+ <tr>
654
+ <td>
655
+ <label for="idcronbtype-day">
656
+ <?php echo '<input class="radio" type="radio"' . checked( "**", $mday[ 0 ] . $wday[ 0 ], FALSE ) . ' name="cronbtype" id="idcronbtype-day" value="day" /> ' . __( 'daily', self::DOMAIN ); ?>
657
+ </label>
658
+ </td>
659
+ <td>
660
+ </td>
661
+ <td>
662
+ <select name="daycronhours">
663
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
664
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
665
+ } ?>
666
+ </select>
667
+ </td>
668
+ <td>
669
+ <select name="daycronminutes">
670
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
671
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
672
+ } ?>
673
+ </select>
674
+ </td>
675
+ </tr>
676
+ <tr>
677
+ <td>
678
+ <label for="idcronbtype-hour">
679
+ <?php echo '<input class="radio" type="radio"' . checked( "*", $hours[ 0 ], FALSE, FALSE ) . ' name="cronbtype" id="idcronbtype-hour" value="hour" /> ' . __( 'hourly', self::DOMAIN ); ?>
680
+ </label>
681
+ </td>
682
+ <td></td>
683
+ <td></td>
684
+ <td>
685
+ <select name="hourcronminutes">
686
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
687
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
688
+ } ?>
689
+ </select>
690
+ </td>
691
+ </tr>
692
+ </table>
693
+ </td>
694
+ </tr>
695
+
696
  <?php
697
  }
698
  ?>
includes/admin-share-count.php CHANGED
@@ -200,7 +200,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
200
 
201
  if ( isset( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
202
  echo '<td class="share-count">';
203
- echo number_format( $sns_counts[$key] );
204
  echo '</td>';
205
  } else {
206
  echo '<td class="not-cached share-count">';
@@ -232,7 +232,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
232
  if ( $value ) {
233
  if ( isset( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
234
  echo '<td class="share-count">';
235
- echo number_format( $sns_counts[$key] );
236
  echo '</td>';
237
  } else {
238
  echo '<td class="not-cached share-count">';
200
 
201
  if ( isset( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
202
  echo '<td class="share-count">';
203
+ echo number_format( (int) $sns_counts[$key] );
204
  echo '</td>';
205
  } else {
206
  echo '<td class="not-cached share-count">';
232
  if ( $value ) {
233
  if ( isset( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
234
  echo '<td class="share-count">';
235
+ echo number_format( (int) $sns_counts[$key] );
236
  echo '</td>';
237
  } else {
238
  echo '<td class="not-cached share-count">';
includes/class-cache-engine.php CHANGED
@@ -31,38 +31,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31
  */
32
 
33
 
34
- abstract class Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
38
  */
39
  protected $transient_prefix = NULL;
40
 
41
- /**
42
- * Cron name to schedule cache processing
43
- */
44
- protected $prime_cron = NULL;
45
-
46
- /**
47
- * Cron name to execute cache processing
48
- */
49
- protected $execute_cron = NULL;
50
-
51
- /**
52
- * Schedule name for cache processing
53
- */
54
- protected $event_schedule = NULL;
55
-
56
- /**
57
- * Schedule description for cache processing
58
- */
59
- protected $event_description = NULL;
60
-
61
  /**
62
- * Instance
63
- */
64
- private static $instance = array();
65
-
66
  /**
67
  * Class constarctor
68
  * Hook onto all of the actions and filters needed by the plugin.
@@ -71,55 +51,7 @@ abstract class Cache_Engine {
71
  protected function __construct() {
72
  Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
73
  }
74
-
75
- /**
76
- * Get instance
77
- *
78
- * @since 0.1.1
79
- */
80
- public static function get_instance() {
81
-
82
- $class_name = get_called_class();
83
- if ( ! isset( self::$instance[$class_name] ) ) {
84
- self::$instance[$class_name] = new $class_name();
85
- //self::$instance[$class_name]->initialize($crawler, $options=array());
86
- }
87
-
88
- return self::$instance[$class_name];
89
- }
90
-
91
- /**
92
- * Initialization
93
- *
94
- * @since 0.1.1
95
- */
96
- abstract public function initialize( $options = array() );
97
-
98
- /**
99
- * Register base schedule for this engine
100
- *
101
- * @since 0.1.0
102
- */
103
- public function register_schedule() {
104
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
105
-
106
- if ( ! wp_next_scheduled( $this->prime_cron ) ) {
107
- wp_schedule_event( time(), $this->event_schedule, $this->prime_cron );
108
- }
109
- }
110
-
111
- /**
112
- * Unregister base schedule for this engine
113
- *
114
- * @since 0.1.0
115
- */
116
- public function unregister_schedule() {
117
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
118
-
119
- wp_clear_scheduled_hook( $this->prime_cron );
120
- WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
121
- }
122
-
123
  /**
124
  * Get cache expiration based on current number of total post and page
125
  *
@@ -156,7 +88,7 @@ abstract class Cache_Engine {
156
  protected function get_transient_ID( $suffix ) {
157
  return $this->transient_prefix . $suffix;
158
  }
159
-
160
  }
161
 
162
  ?>
31
  */
32
 
33
 
34
+ abstract class Cache_Engine extends Engine {
35
 
36
  /**
37
  * Prefix of cache ID
38
  */
39
  protected $transient_prefix = NULL;
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  /**
42
+ * instance for delegation
43
+ */
44
+ protected $delegate = NULL;
45
+
46
  /**
47
  * Class constarctor
48
  * Hook onto all of the actions and filters needed by the plugin.
51
  protected function __construct() {
52
  Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
53
  }
54
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  /**
56
  * Get cache expiration based on current number of total post and page
57
  *
88
  protected function get_transient_ID( $suffix ) {
89
  return $this->transient_prefix . $suffix;
90
  }
91
+
92
  }
93
 
94
  ?>
includes/class-common-data-export-engine.php CHANGED
@@ -72,6 +72,11 @@ class Common_Data_Export_Engine extends Export_Engine {
72
  * Interval for data export
73
  */
74
  private $export_interval = 43200;
 
 
 
 
 
75
 
76
  /**
77
  * Excluded keys of data export
@@ -124,6 +129,7 @@ class Common_Data_Export_Engine extends Export_Engine {
124
 
125
  if ( isset( $options['export_activation'] ) ) $this->export_activation = $options['export_activation'];
126
  if ( isset( $options['export_interval'] ) ) $this->export_interval = $options['export_interval'];
 
127
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
128
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
129
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
@@ -165,20 +171,26 @@ class Common_Data_Export_Engine extends Export_Engine {
165
  public function prime_export() {
166
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
167
 
168
- $next_exec_time = time() + $this->export_interval;
169
 
170
  //$next_exec_time = time() + 5;
171
 
 
 
172
  Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->export_interval );
173
- Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
174
 
175
- /*
 
 
 
176
  if( ! WP_Cron_Util::is_scheduled_hook( $this->execute_cron ) ) {
177
- wp_schedule_single_event( WP_Cron_Util::next_exec_time( '0 0 * * *' ), $this->execute_cron, array( Common_Util::short_hash( $next_exec_time ) ) );
178
  }
179
- */
180
 
 
181
  wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( Common_Util::short_hash( $next_exec_time ) ) );
 
182
  }
183
 
184
 
72
  * Interval for data export
73
  */
74
  private $export_interval = 43200;
75
+
76
+ /**
77
+ * Schedule for data export
78
+ */
79
+ private $export_schedule = '0 0 * * *';
80
 
81
  /**
82
  * Excluded keys of data export
129
 
130
  if ( isset( $options['export_activation'] ) ) $this->export_activation = $options['export_activation'];
131
  if ( isset( $options['export_interval'] ) ) $this->export_interval = $options['export_interval'];
132
+ if ( isset( $options['export_schedule'] ) ) $this->export_schedule = $options['export_schedule'];
133
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
134
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
135
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
171
  public function prime_export() {
172
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
173
 
174
+ //$next_exec_time = time() + $this->export_interval;
175
 
176
  //$next_exec_time = time() + 5;
177
 
178
+ $next_exec_time = WP_Cron_Util::next_exec_time( $this->export_schedule );
179
+
180
  Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->export_interval );
 
181
 
182
+ Common_Util::log( '[' . __METHOD__ . '] next_exec_time (timesatamp): ' . $next_exec_time );
183
+ Common_Util::log( '[' . __METHOD__ . '] next_exec_time (date): ' . date_i18n( 'Y/m/d H:i:s', $next_exec_time ) );
184
+
185
+
186
  if( ! WP_Cron_Util::is_scheduled_hook( $this->execute_cron ) ) {
187
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( Common_Util::short_hash( $next_exec_time ) ) );
188
  }
189
+
190
 
191
+ /*
192
  wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( Common_Util::short_hash( $next_exec_time ) ) );
193
+ */
194
  }
195
 
196
 
includes/class-common-job-reset-engine.php ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-common-job-reset-engine.php
4
+
5
+ Description: This class is a job reset engine whitch reset expired jobs
6
+ Version: 0.4.0
7
+ Author: Daisuke Maruyama
8
+ Author URI: http://marubon.info/
9
+ License: GPL2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11
+ */
12
+
13
+ /*
14
+
15
+ Copyright (C) 2014 Daisuke Maruyama
16
+
17
+ This program is free software; you can redistribute it and/or
18
+ modify it under the terms of the GNU General Public License
19
+ as published by the Free Software Foundation; either version 2
20
+ of the License, or (at your option) any later version.
21
+
22
+ This program is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ GNU General Public License for more details.
26
+
27
+ You should have received a copy of the GNU General Public License
28
+ along with this program; if not, write to the Free Software
29
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30
+
31
+ */
32
+
33
+
34
+ class Common_Job_Reset_Engine extends Engine {
35
+
36
+ /**
37
+ * Cron name to schedule reset processing
38
+ */
39
+ const DEF_PRIME_CRON = 'scc_common_jobreset_prime';
40
+
41
+ /**
42
+ * Cron name to execute reset processing
43
+ */
44
+ const DEF_EXECUTE_CRON = 'scc_common_jobreset_exec';
45
+
46
+ /**
47
+ * Schedule name for reset processing
48
+ */
49
+ const DEF_EVENT_SCHEDULE = 'common_job_reset_event';
50
+
51
+ /**
52
+ * Schedule description for reset processing
53
+ */
54
+ const DEF_EVENT_DESCRIPTION = '[SCC] Common Job Reset Interval';
55
+
56
+ /**
57
+ * Interval cheking and caching target data
58
+ */
59
+ private $check_interval = 600;
60
+
61
+ /**
62
+ * Time expired
63
+ */
64
+ private $expiration_time = 1800;
65
+
66
+ /**
67
+ * Cache target
68
+ */
69
+ private $target_cron = array();
70
+
71
+ /**
72
+ * instance for delegation
73
+ */
74
+ private $delegate = NULL;
75
+
76
+ /**
77
+ * Class constarctor
78
+ * Hook onto all of the actions and filters needed by the plugin.
79
+ *
80
+ */
81
+ protected function __construct() {
82
+ Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
83
+ }
84
+
85
+ /**
86
+ * Initialization
87
+ *
88
+ * @since 0.1.1
89
+ */
90
+ public function initialize( $options = array() ) {
91
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
92
+
93
+ $this->prime_cron = self::DEF_PRIME_CRON;
94
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
95
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
96
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
97
+
98
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
99
+ if ( isset( $options['target_cron'] ) ) $this->target_cron = $options['target_cron'];
100
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
101
+ if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
102
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
103
+ if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
104
+ if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
105
+ if ( isset( $options['expiration_time'] ) ) $this->expiration_time = $options['expiration_time'];
106
+
107
+ add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
108
+ add_action( $this->prime_cron, array( $this, 'prime_reset' ) );
109
+ add_action( $this->execute_cron, array( $this, 'execute_reset' ), 10, 0 );
110
+
111
+ }
112
+
113
+ /**
114
+ * Register event schedule for this engine
115
+ *
116
+ * @since 0.1.0
117
+ */
118
+ public function schedule_check_interval( $schedules ) {
119
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
120
+
121
+ $schedules[$this->event_schedule] = array(
122
+ 'interval' => $this->check_interval,
123
+ 'display' => $this->event_description
124
+ );
125
+
126
+ return $schedules;
127
+ }
128
+
129
+ /**
130
+ * Schedule job reset processing
131
+ *
132
+ * @since 0.2.0
133
+ */
134
+ public function prime_reset() {
135
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
136
+
137
+ $next_exec_time = time() + $this->check_interval;
138
+
139
+ Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
140
+ Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
141
+
142
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array() );
143
+
144
+ }
145
+
146
+ /**
147
+ * Reset expired jobs
148
+ *
149
+ * @since 0.2.0
150
+ */
151
+ public function execute_reset() {
152
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
153
+
154
+ foreach ( $this->target_cron as $key => $hook ) {
155
+ Common_Util::log( '[' . __METHOD__ . '] hook: ' . $hook );
156
+ WP_Cron_Util::clear_expired_scheduled_hook( $hook, $this->expiration_time );
157
+ }
158
+
159
+ }
160
+
161
+ }
162
+
163
+ ?>
includes/class-common-util.php CHANGED
@@ -119,7 +119,12 @@ class Common_Util {
119
 
120
  return $custom_post_types;
121
  }
122
-
 
 
 
 
 
123
  public static function extension_loaded_php_xml() {
124
  if ( extension_loaded( 'xml' ) && extension_loaded( 'xmlreader' ) && extension_loaded( 'xmlwriter' ) ) {
125
  return true;
@@ -127,6 +132,58 @@ class Common_Util {
127
  return false;
128
  }
129
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  }
132
 
119
 
120
  return $custom_post_types;
121
  }
122
+
123
+ /**
124
+ * check if php-xml module is loaded or not
125
+ *
126
+ * @since 0.4.0
127
+ */
128
  public static function extension_loaded_php_xml() {
129
  if ( extension_loaded( 'xml' ) && extension_loaded( 'xmlreader' ) && extension_loaded( 'xmlwriter' ) ) {
130
  return true;
132
  return false;
133
  }
134
  }
135
+
136
+ /**
137
+ * convert url based on http into url based on https
138
+ *
139
+ * @since 0.4.0
140
+ */
141
+ public static function get_secure_url( $url ){
142
+
143
+ $url = str_replace( 'http://', 'https://', $url );
144
+
145
+ return $url;
146
+ }
147
+
148
+ /**
149
+ * convert url based on https into url based on http
150
+ *
151
+ * @since 0.4.0
152
+ */
153
+ public static function get_normal_url( $url ){
154
+
155
+ $url = str_replace( 'https://', 'http://', $url );
156
+
157
+ return $url;
158
+ }
159
+
160
+ /**
161
+ * check if a given url is based on https or not.
162
+ *
163
+ * @since 0.4.0
164
+ */
165
+ public static function is_secure_url( $url ){
166
+
167
+ if ( preg_match('/^(https)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $url ) ) {
168
+ return true;
169
+ } else {
170
+ return false;
171
+ }
172
+ }
173
+
174
+ /**
175
+ * check if a given url is based on http or not.
176
+ *
177
+ * @since 0.4.0
178
+ */
179
+ public static function is_normal_url( $url ){
180
+
181
+ if ( preg_match('/^(http)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $url ) ) {
182
+ return true;
183
+ } else {
184
+ return false;
185
+ }
186
+ }
187
 
188
  }
189
 
includes/class-engine.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-engine.php
4
+
5
+ Description: This class is a engine
6
+ Version: 0.4.0
7
+ Author: Daisuke Maruyama
8
+ Author URI: http://marubon.info/
9
+ License: GPL2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11
+ */
12
+
13
+ /*
14
+
15
+ Copyright (C) 2014 Daisuke Maruyama
16
+
17
+ This program is free software; you can redistribute it and/or
18
+ modify it under the terms of the GNU General Public License
19
+ as published by the Free Software Foundation; either version 2
20
+ of the License, or (at your option) any later version.
21
+
22
+ This program is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ GNU General Public License for more details.
26
+
27
+ You should have received a copy of the GNU General Public License
28
+ along with this program; if not, write to the Free Software
29
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30
+
31
+ */
32
+
33
+
34
+ abstract class Engine {
35
+
36
+ /**
37
+ * Cron name to schedule cache processing
38
+ */
39
+ protected $prime_cron = NULL;
40
+
41
+ /**
42
+ * Cron name to execute cache processing
43
+ */
44
+ protected $execute_cron = NULL;
45
+
46
+ /**
47
+ * Schedule name for cache processing
48
+ */
49
+ protected $event_schedule = NULL;
50
+
51
+ /**
52
+ * Schedule description for cache processing
53
+ */
54
+ protected $event_description = NULL;
55
+
56
+ /**
57
+ * Instance
58
+ */
59
+ private static $instance = array();
60
+
61
+ /**
62
+ * Class constarctor
63
+ * Hook onto all of the actions and filters needed by the plugin.
64
+ *
65
+ */
66
+ protected function __construct() {
67
+ Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
68
+ }
69
+
70
+ /**
71
+ * Get instance
72
+ *
73
+ * @since 0.1.1
74
+ */
75
+ public static function get_instance() {
76
+
77
+ $class_name = get_called_class();
78
+ if ( ! isset( self::$instance[$class_name] ) ) {
79
+ self::$instance[$class_name] = new $class_name();
80
+ //self::$instance[$class_name]->initialize($crawler, $options=array());
81
+ }
82
+
83
+ return self::$instance[$class_name];
84
+ }
85
+
86
+ /**
87
+ * Register base schedule for this engine
88
+ *
89
+ * @since 0.1.0
90
+ */
91
+ public function register_schedule() {
92
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
93
+
94
+ if ( ! wp_next_scheduled( $this->prime_cron ) ) {
95
+ wp_schedule_event( time(), $this->event_schedule, $this->prime_cron );
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Unregister base schedule for this engine
101
+ *
102
+ * @since 0.1.0
103
+ */
104
+ public function unregister_schedule() {
105
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
106
+
107
+ wp_clear_scheduled_hook( $this->prime_cron );
108
+ WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
109
+ }
110
+
111
+ /**
112
+ * Get name of prime cron
113
+ *
114
+ * @since 0.1.1
115
+ */
116
+ public function get_prime_cron() {
117
+ return $this->prime_cron;
118
+ }
119
+
120
+ /**
121
+ * Get name of execute cron
122
+ *
123
+ * @since 0.1.1
124
+ */
125
+ public function get_excute_cron() {
126
+ return $this->execute_cron;
127
+ }
128
+
129
+ /**
130
+ * Initialization
131
+ *
132
+ * @since 0.1.1
133
+ */
134
+ abstract public function initialize( $options = array() );
135
+
136
+
137
+ }
138
+
139
+ ?>
includes/class-export-engine.php CHANGED
@@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31
  */
32
 
33
 
34
- abstract class Export_Engine {
35
 
36
  /**
37
  * Meta key for share second cache
@@ -42,32 +42,7 @@ abstract class Export_Engine {
42
  * Meta key for follow second cache
43
  */
44
  protected $follow_meta_key_prefix = NULL;
45
-
46
- /**
47
- * Cron name to schedule cache processing
48
- */
49
- protected $prime_cron = NULL;
50
-
51
- /**
52
- * Cron name to execute cache processing
53
- */
54
- protected $execute_cron = NULL;
55
-
56
- /**
57
- * Schedule name for cache processing
58
- */
59
- protected $event_schedule = NULL;
60
-
61
- /**
62
- * Schedule description for cache processing
63
- */
64
- protected $event_description = NULL;
65
-
66
- /**
67
- * Instance
68
- */
69
- private static $instance = array();
70
-
71
  /**
72
  * Class constarctor
73
  * Hook onto all of the actions and filters needed by the plugin.
@@ -76,55 +51,7 @@ abstract class Export_Engine {
76
  protected function __construct() {
77
  Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
78
  }
79
-
80
- /**
81
- * Get instance
82
- *
83
- * @since 0.1.1
84
- */
85
- public static function get_instance() {
86
-
87
- $class_name = get_called_class();
88
- if ( ! isset( self::$instance[$class_name] ) ) {
89
- self::$instance[$class_name] = new $class_name();
90
- //self::$instance[$class_name]->initialize($crawler, $options=array());
91
- }
92
-
93
- return self::$instance[$class_name];
94
- }
95
-
96
- /**
97
- * Initialization
98
- *
99
- * @since 0.1.1
100
- */
101
- abstract public function initialize( $options = array() );
102
-
103
- /**
104
- * Register base schedule for this engine
105
- *
106
- * @since 0.1.0
107
- */
108
- public function register_schedule() {
109
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
110
-
111
- if ( ! wp_next_scheduled( $this->prime_cron ) ) {
112
- wp_schedule_event( time(), $this->event_schedule, $this->prime_cron );
113
- }
114
- }
115
-
116
- /**
117
- * Unregister base schedule for this engine
118
- *
119
- * @since 0.1.0
120
- */
121
- public function unregister_schedule() {
122
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
123
-
124
- wp_clear_scheduled_hook( $this->prime_cron );
125
- WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
126
- }
127
-
128
  }
129
 
130
  ?>
31
  */
32
 
33
 
34
+ abstract class Export_Engine extends Engine {
35
 
36
  /**
37
  * Meta key for share second cache
42
  * Meta key for follow second cache
43
  */
44
  protected $follow_meta_key_prefix = NULL;
45
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  /**
47
  * Class constarctor
48
  * Hook onto all of the actions and filters needed by the plugin.
51
  protected function __construct() {
52
  Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
53
  }
54
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
 
57
  ?>
includes/class-follow-base-cache-engine.php CHANGED
@@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31
  */
32
 
33
 
34
- class Follow_Base_Cache_Engine extends Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
@@ -58,9 +58,6 @@ class Follow_Base_Cache_Engine extends Cache_Engine {
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Follow Base Cache Interval';
60
 
61
-
62
- private $crawler = NULL;
63
-
64
  /**
65
  * Interval cheking and caching target data
66
  */
@@ -70,16 +67,6 @@ class Follow_Base_Cache_Engine extends Cache_Engine {
70
  * Offset suffix
71
  */
72
  private $offset_suffix = 'follow_base_cache_offset';
73
-
74
- /**
75
- * Cache target
76
- */
77
- private $target_sns = array();
78
-
79
- /**
80
- * Cache post types
81
- */
82
- private $post_types = array( 'post', 'page' );
83
 
84
  /**
85
  * Class constarctor
@@ -104,6 +91,7 @@ class Follow_Base_Cache_Engine extends Cache_Engine {
104
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
105
  $this->event_description = self::DEF_EVENT_DESCRIPTION;
106
 
 
107
  if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
108
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
109
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
@@ -114,6 +102,8 @@ class Follow_Base_Cache_Engine extends Cache_Engine {
114
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
115
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
116
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
 
 
117
 
118
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
119
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
@@ -169,7 +159,10 @@ class Follow_Base_Cache_Engine extends Cache_Engine {
169
 
170
  $this->cache( NULL, $this->target_sns, $cache_expiration );
171
 
172
- //$this->prime_follow_second_cache_once();
 
 
 
173
  }
174
 
175
  /**
@@ -198,33 +191,6 @@ class Follow_Base_Cache_Engine extends Cache_Engine {
198
  return 3 * $this->check_interval;
199
  }
200
 
201
- /**
202
- * Get and cache data for a given post
203
- *
204
- * @since 0.4.0
205
- */
206
- public function cache( $post_ID, $target_sns, $cache_expiration ) {
207
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
208
-
209
- $url = get_feed_link();
210
-
211
- Common_Util::log( '[' . __METHOD__ . '] feed: ' . $url );
212
-
213
- $transient_ID = $this->get_transient_ID( 'follow' );
214
-
215
- $data = $this->crawler->get_data( $target_sns, $url );
216
-
217
- Common_Util::log( $data );
218
-
219
- if ( $data ) {
220
- $result = set_transient( $transient_ID, $data, $cache_expiration );
221
-
222
- Common_Util::log( '[' . __METHOD__ . '] set_transient result: ' . $result );
223
- }
224
-
225
- return $data;
226
- }
227
-
228
  /**
229
  * Initialize meta key for ranking
230
  *
31
  */
32
 
33
 
34
+ class Follow_Base_Cache_Engine extends Follow_Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Follow Base Cache Interval';
60
 
 
 
 
61
  /**
62
  * Interval cheking and caching target data
63
  */
67
  * Offset suffix
68
  */
69
  private $offset_suffix = 'follow_base_cache_offset';
 
 
 
 
 
 
 
 
 
 
70
 
71
  /**
72
  * Class constarctor
91
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
92
  $this->event_description = self::DEF_EVENT_DESCRIPTION;
93
 
94
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
95
  if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
96
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
97
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
102
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
103
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
104
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
105
+ if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
106
+ if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
107
 
108
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
109
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
159
 
160
  $this->cache( NULL, $this->target_sns, $cache_expiration );
161
 
162
+ if ( ! is_null( $this->delegate ) && method_exists( $this->delegate, 'order_cache' ) ) {
163
+ $this->delegate->order_cache( $this, NULL );
164
+ }
165
+
166
  }
167
 
168
  /**
191
  return 3 * $this->check_interval;
192
  }
193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  /**
195
  * Initialize meta key for ranking
196
  *
includes/class-follow-cache-engine.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-follow-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Version: 0.4.0
7
+ Author: Daisuke Maruyama
8
+ Author URI: http://marubon.info/
9
+ License: GPL2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11
+ */
12
+
13
+ /*
14
+
15
+ Copyright (C) 2014 Daisuke Maruyama
16
+
17
+ This program is free software; you can redistribute it and/or
18
+ modify it under the terms of the GNU General Public License
19
+ as published by the Free Software Foundation; either version 2
20
+ of the License, or (at your option) any later version.
21
+
22
+ This program is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ GNU General Public License for more details.
26
+
27
+ You should have received a copy of the GNU General Public License
28
+ along with this program; if not, write to the Free Software
29
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30
+
31
+ */
32
+
33
+
34
+ abstract class Follow_Cache_Engine extends Cache_Engine {
35
+
36
+ /**
37
+ * Crawler instance
38
+ */
39
+ protected $crawler = NULL;
40
+
41
+ /**
42
+ * Cache target
43
+ */
44
+ protected $target_sns = array();
45
+
46
+ /**
47
+ * Cache post types
48
+ */
49
+ protected $post_types = array( 'post', 'page' );
50
+
51
+ /**
52
+ * migration between http and https
53
+ */
54
+ protected $scheme_migration_mode = false;
55
+
56
+ /**
57
+ * excluded keys in scheme migration
58
+ */
59
+ protected $scheme_migration_exclude_keys = array();
60
+
61
+ /**
62
+ * Get and cache data for a given post
63
+ *
64
+ * @since 0.4.0
65
+ */
66
+ public function cache( $post_ID, $target_sns, $cache_expiration ) {
67
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
+
69
+ $url = get_feed_link();
70
+
71
+ Common_Util::log( '[' . __METHOD__ . '] feed: ' . $url );
72
+
73
+ $transient_ID = $this->get_transient_ID( 'follow' );
74
+
75
+ $data = $this->crawler->get_data( $target_sns, $url );
76
+
77
+ Common_Util::log( $data );
78
+
79
+ if ( $this->scheme_migration_mode && Common_Util::is_secure_url( $url ) ) {
80
+ $url = Common_Util::get_normal_url( $url );
81
+
82
+ $target_sns_migrated = $target_sns;
83
+
84
+ foreach ( $this->scheme_migration_exclude_keys as $sns_key ) {
85
+ unset( $target_sns_migrated[$sns_key] );
86
+ }
87
+
88
+ Common_Util::log( '[' . __METHOD__ . '] feed: ' . $url );
89
+
90
+ $migrated_data = $this->crawler->get_data( $target_sns_migrated, $url );
91
+
92
+ Common_Util::log( $migrated_data );
93
+
94
+ foreach ( $target_sns_migrated as $key => $value ) {
95
+ if ( $value && is_numeric( $migrated_data[$key] ) && $migrated_data[$key] > 0 ){
96
+ $data[$key] = $data[$key] + $migrated_data[$key];
97
+ }
98
+ }
99
+
100
+ }
101
+
102
+ if ( $data ) {
103
+ $result = set_transient( $transient_ID, $data, $cache_expiration );
104
+
105
+ Common_Util::log( '[' . __METHOD__ . '] set_transient result: ' . $result );
106
+ }
107
+
108
+ return $data;
109
+ }
110
+
111
+ }
112
+
113
+ ?>
includes/class-follow-crawler.php CHANGED
@@ -63,7 +63,7 @@ class Follow_Crawler extends Data_Crawler {
63
  $sns_counts = array();
64
 
65
  if ( isset( $cache_target[SNS_Count_Cache::REF_FOLLOW_FEEDLY] ) && $cache_target[SNS_Count_Cache::REF_FOLLOW_FEEDLY] ) {
66
- $sns_counts[SNS_Count_Cache::REF_FOLLOW_FEEDLY] = $this->get_feedly_follow( $url );
67
  }
68
 
69
  return $sns_counts;
@@ -94,15 +94,19 @@ class Follow_Crawler extends Data_Crawler {
94
  private function remote_get( $url ) {
95
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
96
 
 
 
97
  $curl = curl_init();
98
 
99
  curl_setopt( $curl, CURLOPT_URL, $url );
100
- curl_setopt( $curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
101
- //curl_setopt( $curl, CURLOPT_FAILONERROR, true );
102
  curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
103
  curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
104
  curl_setopt( $curl, CURLOPT_TIMEOUT, $this->timeout );
105
-
 
 
106
  $curl_results = curl_exec( $curl );
107
 
108
  if ( curl_error( $curl ) ) {
63
  $sns_counts = array();
64
 
65
  if ( isset( $cache_target[SNS_Count_Cache::REF_FOLLOW_FEEDLY] ) && $cache_target[SNS_Count_Cache::REF_FOLLOW_FEEDLY] ) {
66
+ $sns_counts[SNS_Count_Cache::REF_FOLLOW_FEEDLY] = ( int )$this->get_feedly_follow( $url );
67
  }
68
 
69
  return $sns_counts;
94
  private function remote_get( $url ) {
95
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
96
 
97
+ global $wp_version;
98
+
99
  $curl = curl_init();
100
 
101
  curl_setopt( $curl, CURLOPT_URL, $url );
102
+ curl_setopt( $curl, CURLOPT_USERAGENT, 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
103
+ //curl_setopt( $curl, CURLOPT_FAILONERROR, true );
104
  curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
105
  curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
106
  curl_setopt( $curl, CURLOPT_TIMEOUT, $this->timeout );
107
+ //curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
108
+ //curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false );
109
+
110
  $curl_results = curl_exec( $curl );
111
 
112
  if ( curl_error( $curl ) ) {
includes/class-follow-lazy-cache-engine.php CHANGED
@@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31
  */
32
 
33
 
34
- class Follow_Lazy_Cache_Engine extends Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
@@ -58,9 +58,6 @@ class Follow_Lazy_Cache_Engine extends Cache_Engine {
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Follow Lazy Cache Interval';
60
 
61
-
62
- private $crawler = NULL;
63
-
64
  /**
65
  * Interval cheking and caching target data
66
  */
@@ -70,12 +67,7 @@ class Follow_Lazy_Cache_Engine extends Cache_Engine {
70
  * Latency suffix
71
  */
72
  private $check_latency = 10;
73
-
74
- /**
75
- * Cache target
76
- */
77
- private $target_sns = array();
78
-
79
  /**
80
  * Class constarctor
81
  * Hook onto all of the actions and filters needed by the plugin.
@@ -99,6 +91,7 @@ class Follow_Lazy_Cache_Engine extends Cache_Engine {
99
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
100
  $this->event_description = self::DEF_EVENT_DESCRIPTION;
101
 
 
102
  if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
103
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
104
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
@@ -106,6 +99,8 @@ class Follow_Lazy_Cache_Engine extends Cache_Engine {
106
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
107
  if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
108
  if ( isset( $options['cache_post_types'] ) ) $this->cache_post_types = $options['cache_post_types'];
 
 
109
 
110
  add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
111
 
@@ -150,6 +145,10 @@ class Follow_Lazy_Cache_Engine extends Cache_Engine {
150
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
151
 
152
  $this->cache( NULL, $this->target_sns, $cache_expiration );
 
 
 
 
153
  }
154
 
155
  /**
@@ -163,33 +162,6 @@ class Follow_Lazy_Cache_Engine extends Cache_Engine {
163
  return 3 * $this->check_interval;
164
  }
165
 
166
- /**
167
- * Get and cache data for a given post
168
- *
169
- * @since 0.4.0
170
- */
171
- public function cache( $post_ID, $target_sns, $cache_expiration ) {
172
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
173
-
174
- $url = get_feed_link();
175
-
176
- Common_Util::log( '[' . __METHOD__ . '] feed: ' . $url );
177
-
178
- $transient_ID = $this->get_transient_ID( 'follow' );
179
-
180
- $data = $this->crawler->get_data( $target_sns, $url );
181
-
182
- Common_Util::log( $data );
183
-
184
- if ( $data ) {
185
- $result = set_transient( $transient_ID, $data, $cache_expiration );
186
-
187
- Common_Util::log( '[' . __METHOD__ . '] set_transient result: ' . $result );
188
- }
189
-
190
- return $data;
191
- }
192
-
193
  /**
194
  * Initialize meta key for ranking
195
  *
31
  */
32
 
33
 
34
+ class Follow_Lazy_Cache_Engine extends Follow_Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Follow Lazy Cache Interval';
60
 
 
 
 
61
  /**
62
  * Interval cheking and caching target data
63
  */
67
  * Latency suffix
68
  */
69
  private $check_latency = 10;
70
+
 
 
 
 
 
71
  /**
72
  * Class constarctor
73
  * Hook onto all of the actions and filters needed by the plugin.
91
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
92
  $this->event_description = self::DEF_EVENT_DESCRIPTION;
93
 
94
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
95
  if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
96
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
97
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
99
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
100
  if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
101
  if ( isset( $options['cache_post_types'] ) ) $this->cache_post_types = $options['cache_post_types'];
102
+ if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
103
+ if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
104
 
105
  add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
106
 
145
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
146
 
147
  $this->cache( NULL, $this->target_sns, $cache_expiration );
148
+
149
+ if ( ! is_null( $this->delegate ) && method_exists( $this->delegate, 'order_cache' ) ) {
150
+ $this->delegate->order_cache( $this, NULL );
151
+ }
152
  }
153
 
154
  /**
162
  return 3 * $this->check_interval;
163
  }
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  /**
166
  * Initialize meta key for ranking
167
  *
includes/class-follow-second-cache-engine.php CHANGED
@@ -156,27 +156,8 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
156
  public function execute_cache() {
157
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
158
 
159
- $query_args = array(
160
- 'post_type' => $this->post_types,
161
- 'post_status' => 'publish',
162
- 'nopaging' => true,
163
- 'update_post_term_cache' => false,
164
- 'update_post_meta_cache' => false
165
- );
166
-
167
- $posts_query = new WP_Query( $query_args );
168
-
169
- if ( $posts_query->have_posts() ) {
170
- while ( $posts_query->have_posts() ) {
171
- $posts_query->the_post();
172
-
173
- $post_ID = get_the_ID();
174
-
175
- $this->cache( $post_ID, $this->target_sns, 0 );
176
-
177
- }
178
- }
179
- wp_reset_postdata();
180
  }
181
 
182
  /**
@@ -188,7 +169,7 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
188
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
189
 
190
  $transient_ID = $this->get_transient_ID( 'follow' );
191
-
192
  if ( false !== ( $sns_followers = get_transient( $transient_ID ) ) ) {
193
 
194
  foreach ( $target_sns as $key => $value ) {
@@ -199,13 +180,12 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
199
  if ( isset( $sns_followers[$key] ) && $sns_followers[$key] >= 0 ) {
200
  Common_Util::log( '[' . __METHOD__ . '] meta_key: ' . $meta_key . ' SNS: ' . $key . ' post_ID: ' . $post_ID . ' - ' . $sns_followers[$key] );
201
 
202
- update_post_meta($post_ID, $meta_key, $sns_followers[$key]);
203
- //$data[$key][$post_ID] = $sns_counts[$key];
204
  }
205
  }
206
  }
207
  }
208
-
209
  }
210
 
211
  /**
@@ -227,33 +207,15 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
227
  public function initialize_cache() {
228
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
229
 
230
- $query_args = array(
231
- 'post_type' => $this->post_types,
232
- 'post_status' => 'publish',
233
- 'nopaging' => true,
234
- 'update_post_term_cache' => false,
235
- 'update_post_meta_cache' => false
236
- );
237
-
238
- $posts_query = new WP_Query( $query_args );
239
-
240
- if ( $posts_query->have_posts() ) {
241
- while ( $posts_query->have_posts() ) {
242
- $posts_query->the_post();
243
-
244
- $post_ID = get_the_ID();
245
-
246
- foreach ( $this->target_sns as $key => $value ) {
247
 
248
- $meta_key = $this->meta_key_prefix . strtolower( $key );
249
 
250
- if ( $value ) {
251
- update_post_meta($post_ID, $meta_key, -1);
252
- }
253
- }
254
  }
255
- }
256
- wp_reset_postdata();
257
  }
258
 
259
  /**
@@ -263,7 +225,17 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
263
  */
264
  public function clear_cache() {
265
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
 
 
 
 
 
 
 
 
 
266
 
 
267
  $query_args = array(
268
  'post_type' => $this->post_types,
269
  'post_status' => 'publish',
@@ -291,6 +263,9 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
291
  }
292
  }
293
  wp_reset_postdata();
 
 
 
294
  }
295
 
296
  }
156
  public function execute_cache() {
157
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
158
 
159
+ $this->cache( NULL, $this->target_sns, NULL );
160
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  }
162
 
163
  /**
169
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
170
 
171
  $transient_ID = $this->get_transient_ID( 'follow' );
172
+
173
  if ( false !== ( $sns_followers = get_transient( $transient_ID ) ) ) {
174
 
175
  foreach ( $target_sns as $key => $value ) {
180
  if ( isset( $sns_followers[$key] ) && $sns_followers[$key] >= 0 ) {
181
  Common_Util::log( '[' . __METHOD__ . '] meta_key: ' . $meta_key . ' SNS: ' . $key . ' post_ID: ' . $post_ID . ' - ' . $sns_followers[$key] );
182
 
183
+ update_option( $meta_key, $sns_followers[$key] );
 
184
  }
185
  }
186
  }
187
  }
188
+
189
  }
190
 
191
  /**
207
  public function initialize_cache() {
208
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
209
 
210
+ foreach ( $this->target_sns as $key => $value ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
+ $meta_key = $this->meta_key_prefix . strtolower( $key );
213
 
214
+ if ( $value ) {
215
+ update_option( $meta_key, -1 );
 
 
216
  }
217
+ }
218
+
219
  }
220
 
221
  /**
225
  */
226
  public function clear_cache() {
227
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
228
+
229
+ foreach ( $this->target_sns as $key => $value ) {
230
+
231
+ $meta_key = $this->meta_key_prefix . strtolower( $key );
232
+
233
+ if ( $value ) {
234
+ delete_option( $meta_key );
235
+ }
236
+ }
237
 
238
+ // compatibility for old version
239
  $query_args = array(
240
  'post_type' => $this->post_types,
241
  'post_status' => 'publish',
263
  }
264
  }
265
  wp_reset_postdata();
266
+
267
+
268
+
269
  }
270
 
271
  }
includes/class-share-base-cache-engine.php CHANGED
@@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31
  */
32
 
33
 
34
- class Share_Base_Cache_Engine extends Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
@@ -58,9 +58,6 @@ class Share_Base_Cache_Engine extends Cache_Engine {
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Share Base Cache Interval';
60
 
61
-
62
- private $crawler = NULL;
63
-
64
  /**
65
  * Interval cheking and caching target data
66
  */
@@ -76,21 +73,6 @@ class Share_Base_Cache_Engine extends Cache_Engine {
76
  */
77
  private $offset_suffix = 'base_offset';
78
 
79
- /**
80
- * Cache target
81
- */
82
- private $target_sns = array();
83
-
84
- /**
85
- * Cache post types
86
- */
87
- private $post_types = array( 'post', 'page' );
88
-
89
- /**
90
- * instance for delegation
91
- */
92
- private $delegate = NULL;
93
-
94
  /**
95
  * Class constarctor
96
  * Hook onto all of the actions and filters needed by the plugin.
@@ -125,7 +107,9 @@ class Share_Base_Cache_Engine extends Cache_Engine {
125
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
126
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
127
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
128
-
 
 
129
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
130
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
131
  add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
@@ -277,33 +261,6 @@ class Share_Base_Cache_Engine extends Cache_Engine {
277
  return ceil( $posts_total / $this->posts_per_check ) * $this->check_interval * 3;
278
  }
279
 
280
- /**
281
- * Get and cache data for a given post
282
- *
283
- * @since 0.1.1
284
- */
285
- public function cache( $post_ID, $target_sns, $cache_expiration ) {
286
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
287
-
288
- Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
289
-
290
- $transient_ID = $this->get_transient_ID( $post_ID );
291
-
292
- $url = get_permalink( $post_ID );
293
-
294
- $data = $this->crawler->get_data( $target_sns, $url );
295
-
296
- Common_Util::log( $data );
297
-
298
- if ( $data ) {
299
- $result = set_transient( $transient_ID, $data, $cache_expiration );
300
-
301
- Common_Util::log( '[' . __METHOD__ . '] set_transient result: ' . $result );
302
- }
303
-
304
- return $data;
305
- }
306
-
307
  /**
308
  * Initialize meta key for ranking
309
  *
31
  */
32
 
33
 
34
+ class Share_Base_Cache_Engine extends Share_Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Share Base Cache Interval';
60
 
 
 
 
61
  /**
62
  * Interval cheking and caching target data
63
  */
73
  */
74
  private $offset_suffix = 'base_offset';
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  /**
77
  * Class constarctor
78
  * Hook onto all of the actions and filters needed by the plugin.
107
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
108
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
109
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
110
+ if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
111
+ if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
112
+
113
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
114
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
115
  add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
261
  return ceil( $posts_total / $this->posts_per_check ) * $this->check_interval * 3;
262
  }
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  /**
265
  * Initialize meta key for ranking
266
  *
includes/class-share-cache-engine.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-share-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Version: 0.4.0
7
+ Author: Daisuke Maruyama
8
+ Author URI: http://marubon.info/
9
+ License: GPL2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11
+ */
12
+
13
+ /*
14
+
15
+ Copyright (C) 2014 Daisuke Maruyama
16
+
17
+ This program is free software; you can redistribute it and/or
18
+ modify it under the terms of the GNU General Public License
19
+ as published by the Free Software Foundation; either version 2
20
+ of the License, or (at your option) any later version.
21
+
22
+ This program is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ GNU General Public License for more details.
26
+
27
+ You should have received a copy of the GNU General Public License
28
+ along with this program; if not, write to the Free Software
29
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30
+
31
+ */
32
+
33
+ abstract class Share_Cache_Engine extends Cache_Engine {
34
+
35
+ /**
36
+ * Crawler instance
37
+ */
38
+ protected $crawler = NULL;
39
+
40
+ /**
41
+ * Cache target
42
+ */
43
+ protected $target_sns = array();
44
+
45
+ /**
46
+ * Cache post types
47
+ */
48
+ protected $post_types = array( 'post', 'page' );
49
+
50
+ /**
51
+ * migration between http and https
52
+ */
53
+ protected $scheme_migration_mode = false;
54
+
55
+ /**
56
+ * excluded keys in scheme migration
57
+ */
58
+ protected $scheme_migration_exclude_keys = array();
59
+
60
+ /**
61
+ * Get and cache data for a given post
62
+ *
63
+ * @since 0.1.1
64
+ */
65
+ public function cache( $post_ID, $target_sns, $cache_expiration ) {
66
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
67
+
68
+ Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
69
+
70
+ $transient_ID = $this->get_transient_ID( $post_ID );
71
+
72
+ $url = get_permalink( $post_ID );
73
+
74
+ Common_Util::log( '[' . __METHOD__ . '] target url: ' . $url );
75
+
76
+ $data = $this->crawler->get_data( $target_sns, $url );
77
+
78
+ Common_Util::log( $data );
79
+
80
+ if ( $this->scheme_migration_mode && Common_Util::is_secure_url( $url ) ) {
81
+ $url = Common_Util::get_normal_url( $url );
82
+
83
+ $target_sns_migrated = $target_sns;
84
+
85
+ foreach ( $this->scheme_migration_exclude_keys as $sns_key ) {
86
+ unset( $target_sns_migrated[$sns_key] );
87
+ }
88
+
89
+ Common_Util::log( '[' . __METHOD__ . '] target url: ' . $url );
90
+
91
+ $migrated_data = $this->crawler->get_data( $target_sns_migrated, $url );
92
+
93
+ Common_Util::log( $migrated_data );
94
+
95
+ foreach ( $target_sns_migrated as $key => $value ) {
96
+ if ( $value && is_numeric( $migrated_data[$key] ) && $migrated_data[$key] > 0 ){
97
+ $data[$key] = $data[$key] + $migrated_data[$key];
98
+ }
99
+ }
100
+
101
+ }
102
+
103
+ if ( $data ) {
104
+ $result = set_transient( $transient_ID, $data, $cache_expiration );
105
+
106
+ Common_Util::log( '[' . __METHOD__ . '] set_transient result: ' . $result );
107
+ }
108
+
109
+ return $data;
110
+ }
111
+
112
+ }
113
+
114
+
115
+
116
+ ?>
includes/class-share-crawler.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- class-sns-count-crawler.php
4
 
5
  Description: This class is a data crawler whitch get share count using given API and cURL
6
  Version: 0.3.0
@@ -63,16 +63,16 @@ class Share_Crawler extends Data_Crawler {
63
  $sns_counts = array();
64
 
65
  if ( isset( $cache_target[SNS_Count_Cache::REF_SHARE_HATEBU] ) && $cache_target[SNS_Count_Cache::REF_SHARE_HATEBU] ) {
66
- $sns_counts[SNS_Count_Cache::REF_SHARE_HATEBU] = $this->get_hatebu_count( $url );
67
  }
68
 
69
  if ( isset( $cache_target[SNS_Count_Cache::REF_SHARE_TWITTER] ) && $cache_target[SNS_Count_Cache::REF_SHARE_TWITTER] ) {
70
- $sns_counts[SNS_Count_Cache::REF_SHARE_TWITTER] = $this->get_twitter_count( $url );
71
  }
72
 
73
  if ( isset( $cache_target[SNS_Count_Cache::REF_SHARE_FACEBOOK] ) && $cache_target[SNS_Count_Cache::REF_SHARE_FACEBOOK] ) {
74
  if ( Common_Util::extension_loaded_php_xml() ) {
75
- $sns_counts[SNS_Count_Cache::REF_SHARE_FACEBOOK] = $this->get_facebook_count( $url );
76
  } else {
77
  Common_Util::log( '[' . __METHOD__ . '] php-xml is not installed.' );
78
  }
@@ -80,12 +80,12 @@ class Share_Crawler extends Data_Crawler {
80
  }
81
 
82
  if ( isset( $cache_target[SNS_Count_Cache::REF_SHARE_GPLUS] ) && $cache_target[SNS_Count_Cache::REF_SHARE_GPLUS] ) {
83
- $sns_counts[SNS_Count_Cache::REF_SHARE_GPLUS] = $this->get_gplus_count( $url );
84
  }
85
 
86
  if ( isset( $cache_target[SNS_Count_Cache::REF_SHARE_POCKET] ) && $cache_target[SNS_Count_Cache::REF_SHARE_POCKET] ) {
87
  if ( Common_Util::extension_loaded_php_xml() ) {
88
- $sns_counts[SNS_Count_Cache::REF_SHARE_POCKET] = $this->get_pocket_count( $url );
89
  } else {
90
  Common_Util::log( '[' . __METHOD__ . '] php-xml is not installed.' );
91
  }
@@ -151,35 +151,17 @@ class Share_Crawler extends Data_Crawler {
151
  public function get_facebook_count( $url ) {
152
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
153
 
154
- /*
155
- $query = 'http://graph.facebook.com/' . $url;
156
-
157
- $json = $this->remote_get( $query );
158
-
159
- $facebook = json_decode( $json, true );
160
-
161
- return isset( $facebook['shares'] ) ? intval( $facebook['shares'] ) : 0;
162
- */
163
-
164
  $query = 'http://www.facebook.com/plugins/like.php?href=' . $url . '&width&layout=standard&action=like&show_faces=false&share=false&height=35&locale=ja_JP';
165
 
166
  Common_Util::log( '[' . __METHOD__ . '] facebookquery: ' . $query );
167
 
168
  $html = $this->remote_get( $query );
169
 
170
- //$html = wp_remote_get( $query );
171
-
172
- //Common_Util::log( $html );
173
- //Common_Util::log( '[' . __METHOD__ . '] facebookhtml: ' . $html['body'] );
174
-
175
  $dom = new DOMDocument( '1.0', 'UTF-8' );
176
  $dom->preserveWhiteSpace = false;
177
  $dom->formatOutput = true;
178
 
179
  $dom->loadHTML( $html );
180
- //$dom->loadXml( $html );
181
-
182
- //$dom->loadHTML( $html['body'] );
183
 
184
  $xpath = new DOMXPath( $dom );
185
 
@@ -187,7 +169,7 @@ class Share_Crawler extends Data_Crawler {
187
 
188
  Common_Util::log( '[' . __METHOD__ . '] count element: ' . $result->nodeValue );
189
 
190
- if ( preg_match( '/([0-9.]+)/', $result->nodeValue, $match ) ) {
191
  $count = str_replace( ',', '', $match[1] );
192
  Common_Util::log( '[' . __METHOD__ . '] count: ' . $count );
193
  } else {
@@ -223,7 +205,8 @@ class Share_Crawler extends Data_Crawler {
223
  public function get_pocket_count( $url ) {
224
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
225
 
226
- $query = 'http://widgets.getpocket.com/v1/button?v=1&count=horizontal&url=' . $url;
 
227
  $html = $this->remote_get( $query );
228
 
229
  $dom = new DOMDocument( '1.0', 'UTF-8' );
@@ -253,12 +236,13 @@ class Share_Crawler extends Data_Crawler {
253
  $curl = curl_init();
254
 
255
  curl_setopt( $curl, CURLOPT_URL, $url );
256
- //curl_setopt( $curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
257
  curl_setopt( $curl, CURLOPT_USERAGENT, 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
258
  //curl_setopt( $curl, CURLOPT_FAILONERROR, true );
259
  curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
260
  curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
261
  curl_setopt( $curl, CURLOPT_TIMEOUT, $this->timeout );
 
 
262
 
263
  $curl_results = curl_exec( $curl );
264
 
1
  <?php
2
  /*
3
+ class-share-crawler.php
4
 
5
  Description: This class is a data crawler whitch get share count using given API and cURL
6
  Version: 0.3.0
63
  $sns_counts = array();
64
 
65
  if ( isset( $cache_target[SNS_Count_Cache::REF_SHARE_HATEBU] ) && $cache_target[SNS_Count_Cache::REF_SHARE_HATEBU] ) {
66
+ $sns_counts[SNS_Count_Cache::REF_SHARE_HATEBU] = ( int )$this->get_hatebu_count( $url );
67
  }
68
 
69
  if ( isset( $cache_target[SNS_Count_Cache::REF_SHARE_TWITTER] ) && $cache_target[SNS_Count_Cache::REF_SHARE_TWITTER] ) {
70
+ $sns_counts[SNS_Count_Cache::REF_SHARE_TWITTER] = ( int )$this->get_twitter_count( $url );
71
  }
72
 
73
  if ( isset( $cache_target[SNS_Count_Cache::REF_SHARE_FACEBOOK] ) && $cache_target[SNS_Count_Cache::REF_SHARE_FACEBOOK] ) {
74
  if ( Common_Util::extension_loaded_php_xml() ) {
75
+ $sns_counts[SNS_Count_Cache::REF_SHARE_FACEBOOK] = ( int )$this->get_facebook_count( $url );
76
  } else {
77
  Common_Util::log( '[' . __METHOD__ . '] php-xml is not installed.' );
78
  }
80
  }
81
 
82
  if ( isset( $cache_target[SNS_Count_Cache::REF_SHARE_GPLUS] ) && $cache_target[SNS_Count_Cache::REF_SHARE_GPLUS] ) {
83
+ $sns_counts[SNS_Count_Cache::REF_SHARE_GPLUS] = ( int )$this->get_gplus_count( $url );
84
  }
85
 
86
  if ( isset( $cache_target[SNS_Count_Cache::REF_SHARE_POCKET] ) && $cache_target[SNS_Count_Cache::REF_SHARE_POCKET] ) {
87
  if ( Common_Util::extension_loaded_php_xml() ) {
88
+ $sns_counts[SNS_Count_Cache::REF_SHARE_POCKET] = ( int )$this->get_pocket_count( $url );
89
  } else {
90
  Common_Util::log( '[' . __METHOD__ . '] php-xml is not installed.' );
91
  }
151
  public function get_facebook_count( $url ) {
152
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
153
 
 
 
 
 
 
 
 
 
 
 
154
  $query = 'http://www.facebook.com/plugins/like.php?href=' . $url . '&width&layout=standard&action=like&show_faces=false&share=false&height=35&locale=ja_JP';
155
 
156
  Common_Util::log( '[' . __METHOD__ . '] facebookquery: ' . $query );
157
 
158
  $html = $this->remote_get( $query );
159
 
 
 
 
 
 
160
  $dom = new DOMDocument( '1.0', 'UTF-8' );
161
  $dom->preserveWhiteSpace = false;
162
  $dom->formatOutput = true;
163
 
164
  $dom->loadHTML( $html );
 
 
 
165
 
166
  $xpath = new DOMXPath( $dom );
167
 
169
 
170
  Common_Util::log( '[' . __METHOD__ . '] count element: ' . $result->nodeValue );
171
 
172
+ if ( preg_match( '/([0-9,]+)/', $result->nodeValue, $match ) ) {
173
  $count = str_replace( ',', '', $match[1] );
174
  Common_Util::log( '[' . __METHOD__ . '] count: ' . $count );
175
  } else {
205
  public function get_pocket_count( $url ) {
206
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
207
 
208
+ $query = 'http://widgets.getpocket.com/v1/button?v=1&count=horizontal&url=' . $url;
209
+
210
  $html = $this->remote_get( $query );
211
 
212
  $dom = new DOMDocument( '1.0', 'UTF-8' );
236
  $curl = curl_init();
237
 
238
  curl_setopt( $curl, CURLOPT_URL, $url );
 
239
  curl_setopt( $curl, CURLOPT_USERAGENT, 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
240
  //curl_setopt( $curl, CURLOPT_FAILONERROR, true );
241
  curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
242
  curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
243
  curl_setopt( $curl, CURLOPT_TIMEOUT, $this->timeout );
244
+ //curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
245
+ //curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false );
246
 
247
  $curl_results = curl_exec( $curl );
248
 
includes/class-share-lazy-cache-engine.php CHANGED
@@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31
  */
32
 
33
 
34
- class Share_Lazy_Cache_Engine extends Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
@@ -58,9 +58,6 @@ class Share_Lazy_Cache_Engine extends Cache_Engine {
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Share Lazy Cache Interval';
60
 
61
-
62
- private $crawler = NULL;
63
-
64
  /**
65
  * Interval cheking and caching target data
66
  */
@@ -76,21 +73,6 @@ class Share_Lazy_Cache_Engine extends Cache_Engine {
76
  */
77
  private $check_latency = 10;
78
 
79
- /**
80
- * Cache target
81
- */
82
- private $target_sns = array();
83
-
84
- /**
85
- * Cache post types
86
- */
87
- private $post_types = array( 'post', 'page' );
88
-
89
- /**
90
- * instance for delegation
91
- */
92
- private $delegate = NULL;
93
-
94
  /**
95
  * Class constarctor
96
  * Hook onto all of the actions and filters needed by the plugin.
@@ -123,6 +105,8 @@ class Share_Lazy_Cache_Engine extends Cache_Engine {
123
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
124
  if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
125
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
 
 
126
 
127
  add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
128
 
@@ -221,33 +205,6 @@ class Share_Lazy_Cache_Engine extends Cache_Engine {
221
  return $posts_query->found_posts;
222
  }
223
 
224
- /**
225
- * Get and cache data for a given post
226
- *
227
- * @since 0.1.1
228
- */
229
- public function cache( $post_ID, $target_sns, $cache_expiration ) {
230
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
231
-
232
- Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
233
-
234
- $transient_ID = $this->get_transient_ID( $post_ID );
235
-
236
- $url = get_permalink( $post_ID );
237
-
238
- $data = $this->crawler->get_data( $target_sns, $url );
239
-
240
- Common_Util::log( $data );
241
-
242
- if ( $data ) {
243
- $result = set_transient( $transient_ID, $data, $cache_expiration );
244
-
245
- Common_Util::log( '[' . __METHOD__ . '] set_transient result: ' . $result );
246
- }
247
-
248
- return $data;
249
- }
250
-
251
  /**
252
  * Initialize meta key for ranking
253
  *
31
  */
32
 
33
 
34
+ class Share_Lazy_Cache_Engine extends Share_Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Share Lazy Cache Interval';
60
 
 
 
 
61
  /**
62
  * Interval cheking and caching target data
63
  */
73
  */
74
  private $check_latency = 10;
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  /**
77
  * Class constarctor
78
  * Hook onto all of the actions and filters needed by the plugin.
105
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
106
  if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
107
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
108
+ if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
109
+ if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
110
 
111
  add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
112
 
205
  return $posts_query->found_posts;
206
  }
207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  /**
209
  * Initialize meta key for ranking
210
  *
includes/class-share-rescue-cache-engine.php CHANGED
@@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31
  */
32
 
33
 
34
- class Share_Rescue_Cache_Engine extends Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
@@ -58,9 +58,6 @@ class Share_Rescue_Cache_Engine extends Cache_Engine {
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Share Rescue Cache Interval';
60
 
61
-
62
- private $crawler = NULL;
63
-
64
  /**
65
  * Interval cheking and caching target data
66
  */
@@ -71,26 +68,11 @@ class Share_Rescue_Cache_Engine extends Cache_Engine {
71
  */
72
  private $posts_per_check = 20;
73
 
74
- /**
75
- * Cache target
76
- */
77
- private $target_sns = array();
78
-
79
  /**
80
  * Prefix of cache ID
81
  */
82
  private $meta_key_prefix = 'scc_share_count_';
83
-
84
- /**
85
- * Cache post types
86
- */
87
- private $post_types = array( 'post', 'page' );
88
 
89
- /**
90
- * instance for delegation
91
- */
92
- private $delegate = NULL;
93
-
94
  /**
95
  * Class constarctor
96
  * Hook onto all of the actions and filters needed by the plugin.
@@ -126,6 +108,8 @@ class Share_Rescue_Cache_Engine extends Cache_Engine {
126
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
127
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
128
  if ( isset( $options['meta_key_prefix'] ) ) $this->meta_key_prefix = $options['meta_key_prefix'];
 
 
129
 
130
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
131
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
@@ -177,7 +161,6 @@ class Share_Rescue_Cache_Engine extends Cache_Engine {
177
  public function execute_cache( $hash ) {
178
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
179
 
180
- Common_Util::log( '[' . __METHOD__ . '] posts_offset: ' . $posts_offset );
181
  Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
182
  Common_Util::log( '[' . __METHOD__ . '] posts_per_check: ' . $this->posts_per_check );
183
 
@@ -224,7 +207,7 @@ class Share_Rescue_Cache_Engine extends Cache_Engine {
224
  $full_cache_flag = true;
225
  $partial_cache_flag = false;
226
 
227
- foreach ( $target_sns as $key => $value ) {
228
 
229
  if ( $value ) {
230
 
@@ -322,33 +305,6 @@ class Share_Rescue_Cache_Engine extends Cache_Engine {
322
  return ( ( ceil( $posts_total / $this->posts_per_check ) + 2 ) * $this->check_interval ) + 2 * $this->check_interval;
323
  }
324
 
325
- /**
326
- * Get and cache data for a given post
327
- *
328
- * @since 0.1.1
329
- */
330
- public function cache( $post_ID, $target_sns, $cache_expiration ) {
331
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
332
-
333
- Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
334
-
335
- $transient_ID = $this->get_transient_ID( $post_ID );
336
-
337
- $url = get_permalink( $post_ID );
338
-
339
- $data = $this->crawler->get_data( $target_sns, $url );
340
-
341
- Common_Util::log( $data );
342
-
343
- if ( $data ) {
344
- $result = set_transient( $transient_ID, $data, $cache_expiration );
345
-
346
- Common_Util::log( '[' . __METHOD__ . '] set_transient result: ' . $result );
347
- }
348
-
349
- return $data;
350
- }
351
-
352
  /**
353
  * Initialize meta key for ranking
354
  *
31
  */
32
 
33
 
34
+ class Share_Rescue_Cache_Engine extends Share_Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Share Rescue Cache Interval';
60
 
 
 
 
61
  /**
62
  * Interval cheking and caching target data
63
  */
68
  */
69
  private $posts_per_check = 20;
70
 
 
 
 
 
 
71
  /**
72
  * Prefix of cache ID
73
  */
74
  private $meta_key_prefix = 'scc_share_count_';
 
 
 
 
 
75
 
 
 
 
 
 
76
  /**
77
  * Class constarctor
78
  * Hook onto all of the actions and filters needed by the plugin.
108
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
109
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
110
  if ( isset( $options['meta_key_prefix'] ) ) $this->meta_key_prefix = $options['meta_key_prefix'];
111
+ if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
112
+ if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
113
 
114
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
115
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
161
  public function execute_cache( $hash ) {
162
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
163
 
 
164
  Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
165
  Common_Util::log( '[' . __METHOD__ . '] posts_per_check: ' . $this->posts_per_check );
166
 
207
  $full_cache_flag = true;
208
  $partial_cache_flag = false;
209
 
210
+ foreach ( $this->target_sns as $key => $value ) {
211
 
212
  if ( $value ) {
213
 
305
  return ( ( ceil( $posts_total / $this->posts_per_check ) + 2 ) * $this->check_interval ) + 2 * $this->check_interval;
306
  }
307
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  /**
309
  * Initialize meta key for ranking
310
  *
includes/class-share-rush-cache-engine.php CHANGED
@@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31
  */
32
 
33
 
34
- class Share_Rush_Cache_Engine extends Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
@@ -58,9 +58,6 @@ class Share_Rush_Cache_Engine extends Cache_Engine {
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Share Rush Cache Interval';
60
 
61
-
62
- private $crawler = NULL;
63
-
64
  /**
65
  * Interval cheking and caching target data
66
  */
@@ -80,22 +77,7 @@ class Share_Rush_Cache_Engine extends Cache_Engine {
80
  * Term considered as new content
81
  */
82
  private $new_content_term = 3;
83
-
84
- /**
85
- * Cache target
86
- */
87
- private $target_sns = array();
88
-
89
- /**
90
- * Cache post types
91
- */
92
- private $post_types = array( 'post', 'page' );
93
-
94
- /**
95
- * instance for delegation
96
- */
97
- private $delegate = NULL;
98
-
99
  /**
100
  * Class constarctor
101
  * Hook onto all of the actions and filters needed by the plugin.
@@ -131,6 +113,8 @@ class Share_Rush_Cache_Engine extends Cache_Engine {
131
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
132
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
133
  if ( isset( $options['new_content_term'] ) ) $this->new_content_term = $options['new_content_term'];
 
 
134
 
135
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
136
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
@@ -315,33 +299,6 @@ class Share_Rush_Cache_Engine extends Cache_Engine {
315
  return $posts_query->found_posts;
316
  }
317
 
318
- /**
319
- * Get and cache data for a given post
320
- *
321
- * @since 0.1.1
322
- */
323
- public function cache( $post_ID, $target_sns, $cache_expiration ) {
324
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
325
-
326
- Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
327
-
328
- $transient_ID = $this->get_transient_ID( $post_ID );
329
-
330
- $url = get_permalink( $post_ID );
331
-
332
- $data = $this->crawler->get_data( $target_sns, $url );
333
-
334
- Common_Util::log( $data );
335
-
336
- if ( $data ) {
337
- $result = set_transient( $transient_ID, $data, $cache_expiration );
338
-
339
- Common_Util::log( '[' . __METHOD__ . '] set_transient result: ' . $result );
340
- }
341
-
342
- return $data;
343
- }
344
-
345
  /**
346
  * Initialize meta key for ranking
347
  *
31
  */
32
 
33
 
34
+ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
35
 
36
  /**
37
  * Prefix of cache ID
58
  */
59
  const DEF_EVENT_DESCRIPTION = '[SCC] Share Rush Cache Interval';
60
 
 
 
 
61
  /**
62
  * Interval cheking and caching target data
63
  */
77
  * Term considered as new content
78
  */
79
  private $new_content_term = 3;
80
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  /**
82
  * Class constarctor
83
  * Hook onto all of the actions and filters needed by the plugin.
113
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
114
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
115
  if ( isset( $options['new_content_term'] ) ) $this->new_content_term = $options['new_content_term'];
116
+ if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
117
+ if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
118
 
119
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
120
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
299
  return $posts_query->found_posts;
300
  }
301
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  /**
303
  * Initialize meta key for ranking
304
  *
includes/class-wp-cron-util.php CHANGED
@@ -42,6 +42,33 @@ class WP_Cron_Util {
42
 
43
  }
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  /**
46
  * Clear scheduled hook based related to specified hook name
47
  *
@@ -86,7 +113,7 @@ class WP_Cron_Util {
86
  * @since 0.1.1
87
  */
88
  public static function get_scheduled_hook( $hook ) {
89
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
90
 
91
  $crons = _get_cron_array();
92
 
@@ -97,10 +124,10 @@ class WP_Cron_Util {
97
 
98
  foreach( $crons as $timestamp => $cron ) {
99
  if( isset( $cron[$hook] ) ) {
100
- Common_Util::log( $cron[$hook] );
101
  foreach ( $cron[$hook] as $signature => $data ) {
102
 
103
- Common_Util::log( '[' . __METHOD__ . '] hook: ' . $hook . ' offset: ' . $data['args'][0]. ' timestamp: ' . $timestamp );
104
 
105
  $info[$index]['hook'] = $hook;
106
  $info[$index]['timestamp'] = $timestamp;
@@ -113,6 +140,159 @@ class WP_Cron_Util {
113
 
114
  return $info;
115
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  }
118
 
42
 
43
  }
44
 
45
+
46
+ /**
47
+ * Clear expired scheduled hook based related to specified hook name
48
+ *
49
+ * @since 0.4.1
50
+ */
51
+ public static function clear_expired_scheduled_hook( $hook, $elapsed_time ) {
52
+ $crons = _get_cron_array();
53
+
54
+ if ( empty( $crons ) ) return;
55
+
56
+ $current_time = time();
57
+
58
+ foreach( $crons as $timestamp => $cron ) {
59
+ if( isset( $cron[$hook] ) ) {
60
+ $duration = $timestamp - $current_time;
61
+
62
+ if ( $duration > $elapsed_time ) {
63
+ foreach ( $cron[$hook] as $signature => $data ) {
64
+ wp_unschedule_event( $timestamp, $hook, $data['args'] );
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+
71
+
72
  /**
73
  * Clear scheduled hook based related to specified hook name
74
  *
113
  * @since 0.1.1
114
  */
115
  public static function get_scheduled_hook( $hook ) {
116
+ //Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
117
 
118
  $crons = _get_cron_array();
119
 
124
 
125
  foreach( $crons as $timestamp => $cron ) {
126
  if( isset( $cron[$hook] ) ) {
127
+ //Common_Util::log( $cron[$hook] );
128
  foreach ( $cron[$hook] as $signature => $data ) {
129
 
130
+ //Common_Util::log( '[' . __METHOD__ . '] hook: ' . $hook . ' offset: ' . $data['args'][0]. ' timestamp: ' . $timestamp );
131
 
132
  $info[$index]['hook'] = $hook;
133
  $info[$index]['timestamp'] = $timestamp;
140
 
141
  return $info;
142
  }
143
+
144
+ /**
145
+ *
146
+ * Get the local time timestamp of the next cron execution
147
+ * This code is cited from wordpress plugin BackWPup
148
+ *
149
+ * @param string $cronstring cron (* * * * *)
150
+ * @return int timestamp
151
+ */
152
+ public static function next_exec_time( $cronstring ) {
153
+
154
+ $cron = array();
155
+ $cronarray = array();
156
+ //Cron string
157
+ list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ', $cronstring, 5 );
158
+
159
+ //make arrays form string
160
+ foreach ( $cronstr as $key => $value ) {
161
+ if ( strstr( $value, ',' ) )
162
+ $cronarray[ $key ] = explode( ',', $value );
163
+ else
164
+ $cronarray[ $key ] = array( 0 => $value );
165
+ }
166
+
167
+ //make arrays complete with ranges and steps
168
+ foreach ( $cronarray as $cronarraykey => $cronarrayvalue ) {
169
+ $cron[ $cronarraykey ] = array();
170
+ foreach ( $cronarrayvalue as $value ) {
171
+ //steps
172
+ $step = 1;
173
+ if ( strstr( $value, '/' ) )
174
+ list( $value, $step ) = explode( '/', $value, 2 );
175
+ //replace weekday 7 with 0 for sundays
176
+ if ( $cronarraykey == 'wday' )
177
+ $value = str_replace( '7', '0', $value );
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 2147483647;
183
+ if ( $cronarraykey == 'minutes' && $step < 5 ) //set step minimum to 5 min.
184
+ $step = 5;
185
+ $range = array();
186
+ for ( $i = $first; $i <= $last; $i = $i + $step ) {
187
+ $range[ ] = $i;
188
+ }
189
+ $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], $range );
190
+ }
191
+ elseif ( $value == '*' ) {
192
+ $range = array();
193
+ if ( $cronarraykey == 'minutes' ) {
194
+ if ( $step < 10 ) //set step minimum to 5 min.
195
+ $step = 10;
196
+ for ( $i = 0; $i <= 59; $i = $i + $step ) {
197
+ $range[ ] = $i;
198
+ }
199
+ }
200
+ if ( $cronarraykey == 'hours' ) {
201
+ for ( $i = 0; $i <= 23; $i = $i + $step ) {
202
+ $range[ ] = $i;
203
+ }
204
+ }
205
+ if ( $cronarraykey == 'mday' ) {
206
+ for ( $i = $step; $i <= 31; $i = $i + $step ) {
207
+ $range[ ] = $i;
208
+ }
209
+ }
210
+ if ( $cronarraykey == 'mon' ) {
211
+ for ( $i = $step; $i <= 12; $i = $i + $step ) {
212
+ $range[ ] = $i;
213
+ }
214
+ }
215
+ if ( $cronarraykey == 'wday' ) {
216
+ for ( $i = 0; $i <= 6; $i = $i + $step ) {
217
+ $range[ ] = $i;
218
+ }
219
+ }
220
+ $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], $range );
221
+ }
222
+ else {
223
+ //Month names
224
+ if ( strtolower( $value ) == 'jan' )
225
+ $value = 1;
226
+ if ( strtolower( $value ) == 'feb' )
227
+ $value = 2;
228
+ if ( strtolower( $value ) == 'mar' )
229
+ $value = 3;
230
+ if ( strtolower( $value ) == 'apr' )
231
+ $value = 4;
232
+ if ( strtolower( $value ) == 'may' )
233
+ $value = 5;
234
+ if ( strtolower( $value ) == 'jun' )
235
+ $value = 6;
236
+ if ( strtolower( $value ) == 'jul' )
237
+ $value = 7;
238
+ if ( strtolower( $value ) == 'aug' )
239
+ $value = 8;
240
+ if ( strtolower( $value ) == 'sep' )
241
+ $value = 9;
242
+ if ( strtolower( $value ) == 'oct' )
243
+ $value = 10;
244
+ if ( strtolower( $value ) == 'nov' )
245
+ $value = 11;
246
+ if ( strtolower( $value ) == 'dec' )
247
+ $value = 12;
248
+ //Week Day names
249
+ if ( strtolower( $value ) == 'sun' )
250
+ $value = 0;
251
+ if ( strtolower( $value ) == 'sat' )
252
+ $value = 6;
253
+ if ( strtolower( $value ) == 'mon' )
254
+ $value = 1;
255
+ if ( strtolower( $value ) == 'tue' )
256
+ $value = 2;
257
+ if ( strtolower( $value ) == 'wed' )
258
+ $value = 3;
259
+ if ( strtolower( $value ) == 'thu' )
260
+ $value = 4;
261
+ if ( strtolower( $value ) == 'fri' )
262
+ $value = 5;
263
+ if ( ! is_numeric( $value ) || $value > 60 ) //check
264
+ return 2147483647;
265
+ $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], array( 0 => $value ) );
266
+ }
267
+ }
268
+ }
269
+
270
+ //generate years
271
+ for ( $i = gmdate( 'Y' ); $i < gmdate( 'Y', 2147483647 ); $i ++ ) {
272
+ $cron[ 'year' ][ ] = $i;
273
+ }
274
+
275
+ //calc next timestamp
276
+ $current_timestamp = current_time( 'timestamp' );
277
+ foreach ( $cron[ 'year' ] as $year ) {
278
+ foreach ( $cron[ 'mon' ] as $mon ) {
279
+ foreach ( $cron[ 'mday' ] as $mday ) {
280
+ if ( ! checkdate( $mon, $mday, $year ) )
281
+ continue;
282
+ foreach ( $cron[ 'hours' ] as $hours ) {
283
+ foreach ( $cron[ 'minutes' ] as $minutes ) {
284
+ $timestamp = gmmktime( $hours, $minutes, 0, $mon, $mday, $year );
285
+ if ( $timestamp && in_array( gmdate( 'j', $timestamp ), $cron[ 'mday' ] ) && in_array( gmdate( 'w', $timestamp ), $cron[ 'wday' ] ) && $timestamp > $current_timestamp )
286
+ return $timestamp - ( get_option( 'gmt_offset' ) * 3600 );
287
+ }
288
+ }
289
+ }
290
+ }
291
+ }
292
+
293
+ return 2147483647;
294
+ }
295
+
296
 
297
  }
298
 
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === SNS Count Cache ===
2
  Contributors: marubon
3
  Donate link:
4
- Tags: performance, SNS, social, cache
5
  Requires at least: 3.7
6
- Tested up to: 4.1
7
- Stable tag: 0.4.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -15,6 +15,8 @@ This plugin gets and caches SNS share count in the background, and provides func
15
  SNS Count Cache gets share count for Twitter and Facebook, Google Plus, Pocket, Hatena Bookmark and caches these count in the background.
16
  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.
17
 
 
 
18
  The following shows functions to get share count from the cache:
19
 
20
  * scc_get_share_twitter()
@@ -83,6 +85,10 @@ There are no questions.
83
  * Added: function to export share count data was added.
84
  * Added: cache logic was improved.
85
 
 
 
 
 
86
  == Upgrade Notice ==
87
  The following functions are deprecated.
88
 
@@ -93,5 +99,5 @@ The following functions are deprecated.
93
  * get_scc_hatebu()
94
 
95
  == Arbitrary section ==
96
- * PHP Version: 5.3+
97
 
1
  === SNS Count Cache ===
2
  Contributors: marubon
3
  Donate link:
4
+ Tags: performance, SNS, social, cache, share
5
  Requires at least: 3.7
6
+ Tested up to: 4.1.1
7
+ Stable tag: 0.5.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
15
  SNS Count Cache gets share count for Twitter and Facebook, Google Plus, Pocket, Hatena Bookmark and caches these count in the background.
16
  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.
17
 
18
+ Notice: PHP Version 5.3+ is required in order to activate and execute this plugin.
19
+
20
  The following shows functions to get share count from the cache:
21
 
22
  * scc_get_share_twitter()
85
  * Added: function to export share count data was added.
86
  * Added: cache logic was improved.
87
 
88
+ = 0.5.0 =
89
+ * Added: function to cache share count for both old and new url in https migration.
90
+ * Fixed: share count of Facebook becomes invalid when the count is more than four digits.
91
+
92
  == Upgrade Notice ==
93
  The following functions are deprecated.
94
 
99
  * get_scc_hatebu()
100
 
101
  == Arbitrary section ==
102
+
103
 
screenshot-4.png CHANGED
Binary file
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.4.0
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
@@ -29,28 +29,33 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29
 
30
  */
31
 
 
 
 
 
32
  require_once ( dirname( __FILE__ ) . '/includes/class-cache-engine.php' );
33
 
 
34
  require_once ( dirname( __FILE__ ) . '/includes/class-share-base-cache-engine.php' );
35
  require_once ( dirname( __FILE__ ) . '/includes/class-share-rush-cache-engine.php' );
36
  require_once ( dirname( __FILE__ ) . '/includes/class-share-lazy-cache-engine.php' );
37
  require_once ( dirname( __FILE__ ) . '/includes/class-share-second-cache-engine.php' );
38
  require_once ( dirname( __FILE__ ) . '/includes/class-share-rescue-cache-engine.php' );
39
 
 
40
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-base-cache-engine.php' );
41
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-lazy-cache-engine.php' );
42
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-second-cache-engine.php' );
43
-
44
- require_once ( dirname( __FILE__ ) . '/includes/class-data-crawler.php' );
45
- require_once ( dirname( __FILE__ ) . '/includes/class-share-crawler.php' );
46
- require_once ( dirname( __FILE__ ) . '/includes/class-follow-crawler.php' );
47
- require_once ( dirname( __FILE__ ) . '/includes/class-common-util.php' );
48
- require_once ( dirname( __FILE__ ) . '/includes/class-wp-cron-util.php' );
49
 
50
  require_once ( dirname( __FILE__ ) . '/includes/class-export-engine.php' );
51
  require_once ( dirname( __FILE__ ) . '/includes/class-common-data-export-engine.php' );
52
 
53
- require_once ( dirname( __FILE__ ) . '/includes/interface-cache-order.php' );
 
 
 
 
54
 
55
  if ( ! class_exists( 'SNS_Count_Cache' ) ) {
56
 
@@ -131,26 +136,41 @@ class SNS_Count_Cache implements Cache_Order {
131
  */
132
  const OPT_COMMON_DATA_EXPORT_INTERVAL = 43200;
133
 
 
 
 
 
 
134
  /**
135
  * Type of dynamic cache processing
136
  */
137
- const OPT_ACCESS_BASED_CACHE_NONE = 0;
138
 
139
  /**
140
  * Type of dynamic cache processing
141
  */
142
- const OPT_ACCESS_BASED_SYNC_CACHE = 1;
143
 
144
  /**
145
  * Type of dynamic cache processing
146
  */
147
- const OPT_ACCESS_BASED_ASYNC_CACHE = 2;
148
 
149
  /**
150
  * Type of dynamic cache processing
151
  */
152
- const OPT_ACCESS_BASED_2ND_CACHE = 3;
153
-
 
 
 
 
 
 
 
 
 
 
154
  /**
155
  * Option key for custom post types for share base cache
156
  */
@@ -169,7 +189,7 @@ class SNS_Count_Cache implements Cache_Order {
169
  /**
170
  * Option key for dynamic cache
171
  */
172
- const DB_COMMON_DYNAMIC_CACHE = 'scc_dynamic_cache';
173
 
174
  /**
175
  * Option key for new content term for share rush cache
@@ -194,12 +214,22 @@ class SNS_Count_Cache implements Cache_Order {
194
  /**
195
  * Option key of data export
196
  */
197
- const DB_COMMON_DATA_EXPORT = 'scc_data_export';
198
 
199
  /**
200
  * Option key of data export interval
201
  */
202
- const DB_COMMON_DATA_EXPORT_INTERVAL = 'scc_data_export_interval';
 
 
 
 
 
 
 
 
 
 
203
 
204
  /**
205
  * Slug of the plugin
@@ -250,6 +280,11 @@ class SNS_Count_Cache implements Cache_Order {
250
  * ID of common data export
251
  */
252
  const REF_COMMON_EXPORT = 'common-export';
 
 
 
 
 
253
 
254
  /**
255
  * ID of share
@@ -320,6 +355,11 @@ class SNS_Count_Cache implements Cache_Order {
320
  * Instance of export engine
321
  */
322
  private $export_engines = array();
 
 
 
 
 
323
 
324
  /**
325
  * Slug of the plugin screen
@@ -330,32 +370,87 @@ class SNS_Count_Cache implements Cache_Order {
330
  * Cache target for share base cache
331
  */
332
  private $share_base_cache_target = array();
 
 
 
 
 
333
 
334
  /**
335
- * Cache target for follow base cache
336
  */
337
- private $follow_base_cache_target = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
 
339
  /**
340
- * Post types to be cached
341
  */
342
- private $share_base_cache_post_types = array( 'post', 'page' );
343
 
344
  /**
345
- * Option flag of dynamic cache
 
 
 
 
 
346
  */
347
- private $dynamic_cache = 0;
348
 
349
  /**
350
- * Option flag of data export
351
  */
352
- private $data_export = 0;
353
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  /**
355
  * Instance
356
  */
357
  private static $instance = NULL;
358
-
359
  /**
360
  * Class constarctor
361
  * Hook onto all of the actions and filters needed by the plugin.
@@ -400,28 +495,33 @@ class SNS_Count_Cache implements Cache_Order {
400
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
401
 
402
  $share_base_check_interval = get_option( self::DB_SHARE_CHECK_INTERVAL );
403
- $share_base_check_interval = ! empty( $share_base_check_interval ) ? intval( $share_base_check_interval ) : self::OPT_SHARE_BASE_CHECK_INTERVAL;
404
 
405
  $share_base_posts_per_check = get_option( self::DB_SHARE_POSTS_PER_CHECK );
406
- $share_base_posts_per_check = ! empty( $share_base_posts_per_check ) ? intval( $share_base_posts_per_check ) : self::OPT_SHARE_BASE_POSTS_PER_CHECK;
407
 
408
  $follow_base_check_interval = get_option( self::DB_FOLLOW_CHECK_INTERVAL );
409
- $follow_base_check_interval = ! empty( $follow_base_check_interval ) ? intval( $follow_base_check_interval ) : self::OPT_FOLLOW_BASE_CHECK_INTERVAL;
410
 
411
- $dynamic_cache = get_option( self::DB_COMMON_DYNAMIC_CACHE );
412
- $this->dynamic_cache = ! empty( $dynamic_cache ) ? $dynamic_cache : false;
413
 
414
  $share_rush_new_content_term = get_option( self::DB_SHARE_NEW_CONTENT_TERM );
415
- $share_rush_new_content_term = ! empty( $share_rush_new_content_term ) ? intval( $share_rush_new_content_term ) : self::OPT_SHARE_RUSH_NEW_CONTENT_TERM;
416
 
417
  $this->share_base_cache_target = get_option( self::DB_SHARE_CACHE_TARGET );
418
  $this->follow_base_cache_target = get_option( self::DB_FOLLOW_CACHE_TARGET );
419
 
420
- $data_export = get_option( self::DB_COMMON_DATA_EXPORT );
421
- $this->data_export = isset( $data_export ) ? intval( $data_export ) : self::OPT_COMMON_DATA_EXPORT_MANUAL;
422
 
423
  $data_export_interval = get_option( self::DB_COMMON_DATA_EXPORT_INTERVAL );
424
- $data_export_interval = ! empty( $data_export_interval ) ? intval( $data_export_interval ) : self::OPT_COMMON_DATA_EXPORT_INTERVAL;
 
 
 
 
 
425
 
426
  if ( ! $this->share_base_cache_target ) {
427
  $this->share_base_cache_target[self::REF_SHARE_TWITTER] = true;
@@ -440,17 +540,17 @@ class SNS_Count_Cache implements Cache_Order {
440
  $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = true;
441
  }
442
 
443
- $share_base_custom_post_types = get_option( self::DB_SHARE_CUSTOM_POST_TYPES );
444
 
445
- if ( ! $share_base_custom_post_types ) {
446
- $share_base_custom_post_types = array();
447
  }
448
 
449
- //$custom_post_types = Common_Util::get_custom_post_types();
450
- $this->share_base_cache_post_types = array_merge( $this->share_base_cache_post_types, $share_base_custom_post_types );
451
- //$custom_post_types = get_post_types( array( 'public' => true, '_builtin' => false ) );
452
- //$this->share_base_cache_post_types = array_merge( $this->share_base_cache_post_types, $share_base_custom_post_types );
453
 
 
 
 
454
  // Crawler
455
  $this->crawlers[self::REF_SHARE] = Share_Crawler::get_instance();
456
  $this->crawlers[self::REF_FOLLOW] = Follow_Crawler::get_instance();
@@ -460,9 +560,11 @@ class SNS_Count_Cache implements Cache_Order {
460
  'delegate' => $this,
461
  'crawler' => $this->crawlers[self::REF_SHARE],
462
  'target_sns' => $this->share_base_cache_target,
463
- 'check_interval' => $share_base_check_interval,
464
- 'posts_per_check' => $share_base_posts_per_check,
465
- 'post_types' => $this->share_base_cache_post_types
 
 
466
  );
467
 
468
  $this->cache_engines[self::REF_SHARE_BASE] = Share_Base_Cache_Engine::get_instance();
@@ -474,9 +576,11 @@ class SNS_Count_Cache implements Cache_Order {
474
  'crawler' => $this->crawlers[self::REF_SHARE],
475
  'target_sns' => $this->share_base_cache_target,
476
  'check_interval' => self::OPT_SHARE_RUSH_CHECK_INTERVAL,
477
- 'posts_per_check' => $share_base_posts_per_check,
478
- 'new_content_term' => $share_rush_new_content_term,
479
- 'post_types' => $this->share_base_cache_post_types
 
 
480
  );
481
 
482
  $this->cache_engines[self::REF_SHARE_RUSH] = Share_Rush_Cache_Engine::get_instance();
@@ -487,9 +591,11 @@ class SNS_Count_Cache implements Cache_Order {
487
  'delegate' => $this,
488
  'crawler' => $this->crawlers[self::REF_SHARE],
489
  'target_sns' => $this->share_base_cache_target,
490
- 'check_interval' => $share_base_check_interval,
491
- 'posts_per_check' => $share_base_posts_per_check,
492
- 'post_types' => $this->share_base_cache_post_types
 
 
493
  );
494
 
495
  $this->cache_engines[self::REF_SHARE_LAZY] = Share_Lazy_Cache_Engine::get_instance();
@@ -500,7 +606,9 @@ class SNS_Count_Cache implements Cache_Order {
500
  'target_sns' => $this->share_base_cache_target,
501
  'check_interval' => self::OPT_SHARE_2ND_CHECK_INTERVAL,
502
  'post_types' => $this->share_base_cache_post_types,
503
- 'meta_key_prefix' => self::OPT_SHARE_2ND_META_KEY_PREFIX
 
 
504
  );
505
 
506
  $this->cache_engines[self::REF_SHARE_2ND] = Share_Second_Cache_Engine::get_instance();
@@ -511,9 +619,11 @@ class SNS_Count_Cache implements Cache_Order {
511
  'delegate' => $this,
512
  'crawler' => $this->crawlers[self::REF_SHARE],
513
  'target_sns' => $this->share_base_cache_target,
514
- 'check_interval' => $share_base_check_interval,
515
- 'posts_per_check' => $share_base_posts_per_check,
516
- 'post_types' => $this->share_base_cache_post_types
 
 
517
  );
518
 
519
  $this->cache_engines[self::REF_SHARE_RESCUE] = Share_Rescue_Cache_Engine::get_instance();
@@ -521,10 +631,12 @@ class SNS_Count_Cache implements Cache_Order {
521
 
522
  // Follow base cache engine
523
  $options = array(
 
524
  'crawler' => $this->crawlers[self::REF_FOLLOW],
525
  'target_sns' => $this->follow_base_cache_target,
526
- 'check_interval' => $follow_base_check_interval,
527
- 'post_types' => $this->share_base_cache_post_types
 
528
  );
529
 
530
  $this->cache_engines[self::REF_FOLLOW_BASE] = Follow_Base_Cache_Engine::get_instance();
@@ -532,9 +644,11 @@ class SNS_Count_Cache implements Cache_Order {
532
 
533
  // Follow lazy cache engine
534
  $options = array(
 
535
  'crawler' => $this->crawlers[self::REF_FOLLOW],
536
  'target_sns' => $this->follow_base_cache_target,
537
- 'check_interval' => $follow_base_check_interval,
 
538
  );
539
 
540
  $this->cache_engines[self::REF_FOLLOW_LAZY] = Follow_Lazy_Cache_Engine::get_instance();
@@ -553,8 +667,9 @@ class SNS_Count_Cache implements Cache_Order {
553
 
554
  // Data export engine
555
  $options = array(
556
- 'export_activation' => $this->data_export,
557
- 'export_interval' => $data_export_interval,
 
558
  'share_target_sns' => $this->share_base_cache_target,
559
  'follow_target_sns' => $this->follow_base_cache_target,
560
  'export_file_name' => self::OPT_COMMON_DATA_EXPORT_FILE_NAME,
@@ -564,11 +679,45 @@ class SNS_Count_Cache implements Cache_Order {
564
 
565
  $this->export_engines[self::REF_COMMON_EXPORT] = Common_Data_Export_Engine::get_instance();
566
  $this->export_engines[self::REF_COMMON_EXPORT]->initialize( $options );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
567
 
 
 
 
568
  // delete old hooks
569
  WP_Cron_Util::clear_scheduled_hook( 'scc_basecache_prime' );
570
  WP_Cron_Util::clear_scheduled_hook( 'scc_rushcache_prime' );
571
  WP_Cron_Util::clear_scheduled_hook( 'scc_2ndcache_prime' );
 
 
 
 
 
 
 
 
 
572
  }
573
 
574
  /**
@@ -620,17 +769,35 @@ class SNS_Count_Cache implements Cache_Order {
620
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
621
 
622
  $this->initialize();
 
 
623
 
624
  foreach ( $this->cache_engines as $key => $cache_engine ) {
625
- $cache_engine->initialize_cache();
626
- $cache_engine->register_schedule();
 
 
 
 
 
 
 
 
 
627
  }
628
-
629
- if ( $this->data_export ) {
 
 
 
 
630
  $this->export_engines[self::REF_COMMON_EXPORT]->register_schedule();
631
  }
 
 
 
632
  }
633
-
634
  /**
635
  * Deactivate cache engine (schedule cron)
636
  *
@@ -638,13 +805,22 @@ class SNS_Count_Cache implements Cache_Order {
638
  */
639
  function deactivate_plugin() {
640
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
641
-
 
 
642
  foreach ( $this->cache_engines as $key => $cache_engine ) {
643
  $cache_engine->unregister_schedule();
644
  $cache_engine->clear_cache();
645
  }
646
-
 
 
 
 
647
  $this->export_engines[self::REF_COMMON_EXPORT]->unregister_schedule();
 
 
 
648
  }
649
 
650
  /**
@@ -655,23 +831,9 @@ class SNS_Count_Cache implements Cache_Order {
655
  function reactivate_plugin() {
656
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
657
 
658
- foreach ( $this->cache_engines as $key => $cache_engine ) {
659
- $cache_engine->unregister_schedule();
660
- $cache_engine->clear_cache();
661
- }
662
-
663
- $this->export_engines[self::REF_COMMON_EXPORT]->unregister_schedule();
664
-
665
- $this->initialize();
666
-
667
- foreach ( $this->cache_engines as $key => $cache_engine ) {
668
- $cache_engine->initialize_cache();
669
- $cache_engine->register_schedule();
670
- }
671
-
672
- if ( $this->data_export ) {
673
- $this->export_engines[self::REF_COMMON_EXPORT]->register_schedule();
674
- }
675
  }
676
 
677
  /**
@@ -743,10 +905,10 @@ class SNS_Count_Cache implements Cache_Order {
743
  *
744
  * @since 0.2.0
745
  */
746
- public function get_dynamic_cache_type() {
747
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
748
 
749
- return $this->dynamic_cache;
750
  }
751
 
752
  /**
@@ -754,10 +916,10 @@ class SNS_Count_Cache implements Cache_Order {
754
  *
755
  * @since 0.2.0
756
  */
757
- public function retrieve_share_cache( $post_ID ) {
758
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
759
 
760
- return $this->cache_engines[self::REF_SHARE_BASE]->direct_cache( $post_ID, false );
761
  }
762
 
763
  /**
@@ -835,7 +997,13 @@ class SNS_Count_Cache implements Cache_Order {
835
  break;
836
  case 'Share_Rush_Cache_Engine':
837
  $this->cache_engines[self::REF_SHARE_2ND]->cache( $options['post_id'], $this->share_base_cache_target, NULL );
 
 
 
838
  break;
 
 
 
839
  }
840
 
841
  }
@@ -953,8 +1121,7 @@ function scc_get_share( $options = array( 'id' => '', 'url' => '', 'sns' => '' )
953
  $sns_counts[$sns_key] = $sns_count;
954
  } else {
955
  $sns_counts[$sns_key] = 0;
956
- }
957
-
958
  return $sns_counts[$sns_key];
959
  } else {
960
 
@@ -964,15 +1131,14 @@ function scc_get_share( $options = array( 'id' => '', 'url' => '', 'sns' => '' )
964
  } else {
965
  $sns_counts[$key] = 0;
966
  }
967
- }
968
-
969
  return $sns_counts;
970
  }
971
  } else {
972
  $sns_count_cache = SNS_Count_Cache::get_instance();
973
 
974
- switch ( $sns_count_cache->get_dynamic_cache_type() ) {
975
- case SNS_Count_Cache::OPT_ACCESS_BASED_CACHE_NONE:
976
  if ( $sns_key ) {
977
  $sns_counts[$sns_key] = 0;
978
  return $sns_counts[$sns_key];
@@ -987,15 +1153,15 @@ function scc_get_share( $options = array( 'id' => '', 'url' => '', 'sns' => '' )
987
  return $sns_counts;
988
  }
989
  break;
990
- case SNS_Count_Cache::OPT_ACCESS_BASED_SYNC_CACHE:
991
- $sns_counts = $sns_count_cache->retrieve_share_cache( $post_ID );
992
  if ( $sns_key ) {
993
  return $sns_counts[$sns_key];
994
  } else {
995
  return $sns_counts;
996
  }
997
  break;
998
- case SNS_Count_Cache::OPT_ACCESS_BASED_ASYNC_CACHE:
999
  $sns_count_cache->reserve_share_cache( $post_ID );
1000
  if ( $sns_key ) {
1001
  $sns_counts[$sns_key] = 0;
@@ -1011,7 +1177,7 @@ function scc_get_share( $options = array( 'id' => '', 'url' => '', 'sns' => '' )
1011
  return $sns_counts;
1012
  }
1013
  break;
1014
- case SNS_Count_Cache::OPT_ACCESS_BASED_2ND_CACHE:
1015
  $sns_count_cache->reserve_share_cache( $post_ID );
1016
  if ( $sns_key ) {
1017
  $meta_key = SNS_Count_Cache::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( $sns_key );
@@ -1022,8 +1188,7 @@ function scc_get_share( $options = array( 'id' => '', 'url' => '', 'sns' => '' )
1022
  $sns_counts[$sns_key] = $sns_count;
1023
  } else {
1024
  $sns_counts[$sns_key] = 0;
1025
- }
1026
-
1027
  return $sns_counts[$sns_key];
1028
  } else {
1029
  $base_cache_target = $sns_count_cache->get_share_base_cache_target();
@@ -1089,15 +1254,14 @@ function scc_get_follow( $options = array( 'id' => '', 'sns' => '' ) ) {
1089
  } else {
1090
  $sns_followers[$key] = 0;
1091
  }
1092
- }
1093
-
1094
  return $sns_followers;
1095
  }
1096
  } else {
1097
  $sns_count_cache = SNS_Count_Cache::get_instance();
1098
 
1099
- switch ( $sns_count_cache->get_dynamic_cache_type() ) {
1100
- case SNS_Count_Cache::OPT_ACCESS_BASED_CACHE_NONE:
1101
  if ( $sns_key ) {
1102
  $sns_followers[$sns_key] = 0;
1103
  return $sns_followers[$sns_key];
@@ -1108,12 +1272,11 @@ function scc_get_follow( $options = array( 'id' => '', 'sns' => '' ) ) {
1108
  if ( $value ) {
1109
  $sns_followers[$key] = 0;
1110
  }
1111
- }
1112
-
1113
  return $sns_followers;
1114
  }
1115
  break;
1116
- case SNS_Count_Cache::OPT_ACCESS_BASED_SYNC_CACHE:
1117
  $sns_followers = $sns_count_cache->retrieve_follow_cache();
1118
  if ( $sns_key ) {
1119
  return $sns_followers[$sns_key];
@@ -1121,7 +1284,7 @@ function scc_get_follow( $options = array( 'id' => '', 'sns' => '' ) ) {
1121
  return $sns_followers;
1122
  }
1123
  break;
1124
- case SNS_Count_Cache::OPT_ACCESS_BASED_ASYNC_CACHE:
1125
  $sns_count_cache->reserve_follow_cache();
1126
  if ( $sns_key ) {
1127
  $sns_followers[$sns_key] = 0;
@@ -1137,20 +1300,19 @@ function scc_get_follow( $options = array( 'id' => '', 'sns' => '' ) ) {
1137
  return $sns_followers;
1138
  }
1139
  break;
1140
- case SNS_Count_Cache::OPT_ACCESS_BASED_2ND_CACHE:
1141
  $sns_count_cache->reserve_follow_cache();
1142
 
1143
  if ( $sns_key ) {
1144
  $meta_key = SNS_Count_Cache::OPT_FOLLOW_2ND_META_KEY_PREFIX . strtolower( $sns_key );
1145
-
1146
- $sns_follower = get_post_meta( $post_ID, $meta_key, true );
1147
 
1148
  if ( isset( $sns_follower ) && $sns_follower >= 0 ) {
1149
  $sns_followers[$sns_key] = $sns_follower;
1150
  } else {
1151
  $sns_followers[$sns_key] = 0;
1152
- }
1153
-
1154
  return $sns_followers[$sns_key];
1155
  } else {
1156
  $base_cache_target = $sns_count_cache->get_follow_base_cache_target();
@@ -1159,8 +1321,8 @@ function scc_get_follow( $options = array( 'id' => '', 'sns' => '' ) ) {
1159
  if ( $value ) {
1160
  $meta_key = SNS_Count_Cache::OPT_FOLLOW_2ND_META_KEY_PREFIX . strtolower( $key );
1161
 
1162
- $sns_follower = get_post_meta( $post_ID, $meta_key, true );
1163
-
1164
  if ( isset( $sns_follower ) && $sns_follower >= 0 ) {
1165
  $sns_followers[$key] = $sns_follower;
1166
  } else {
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.5.0
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
29
 
30
  */
31
 
32
+ require_once ( dirname( __FILE__ ) . '/includes/class-common-util.php' );
33
+ require_once ( dirname( __FILE__ ) . '/includes/class-wp-cron-util.php' );
34
+
35
+ require_once ( dirname( __FILE__ ) . '/includes/class-engine.php' );
36
  require_once ( dirname( __FILE__ ) . '/includes/class-cache-engine.php' );
37
 
38
+ require_once ( dirname( __FILE__ ) . '/includes/class-share-cache-engine.php' );
39
  require_once ( dirname( __FILE__ ) . '/includes/class-share-base-cache-engine.php' );
40
  require_once ( dirname( __FILE__ ) . '/includes/class-share-rush-cache-engine.php' );
41
  require_once ( dirname( __FILE__ ) . '/includes/class-share-lazy-cache-engine.php' );
42
  require_once ( dirname( __FILE__ ) . '/includes/class-share-second-cache-engine.php' );
43
  require_once ( dirname( __FILE__ ) . '/includes/class-share-rescue-cache-engine.php' );
44
 
45
+ require_once ( dirname( __FILE__ ) . '/includes/class-follow-cache-engine.php' );
46
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-base-cache-engine.php' );
47
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-lazy-cache-engine.php' );
48
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-second-cache-engine.php' );
49
+ require_once ( dirname( __FILE__ ) . '/includes/interface-cache-order.php' );
 
 
 
 
 
50
 
51
  require_once ( dirname( __FILE__ ) . '/includes/class-export-engine.php' );
52
  require_once ( dirname( __FILE__ ) . '/includes/class-common-data-export-engine.php' );
53
 
54
+ require_once ( dirname( __FILE__ ) . '/includes/class-common-job-reset-engine.php' );
55
+
56
+ require_once ( dirname( __FILE__ ) . '/includes/class-data-crawler.php' );
57
+ require_once ( dirname( __FILE__ ) . '/includes/class-share-crawler.php' );
58
+ require_once ( dirname( __FILE__ ) . '/includes/class-follow-crawler.php' );
59
 
60
  if ( ! class_exists( 'SNS_Count_Cache' ) ) {
61
 
136
  */
137
  const OPT_COMMON_DATA_EXPORT_INTERVAL = 43200;
138
 
139
+ /**
140
+ * Data export schedule
141
+ */
142
+ const OPT_COMMON_DATA_EXPORT_SCHEDULE = '0 0 * * *';
143
+
144
  /**
145
  * Type of dynamic cache processing
146
  */
147
+ const OPT_COMMON_ACCESS_BASED_CACHE_NONE = 0;
148
 
149
  /**
150
  * Type of dynamic cache processing
151
  */
152
+ const OPT_COMMON_ACCESS_BASED_SYNC_CACHE = 1;
153
 
154
  /**
155
  * Type of dynamic cache processing
156
  */
157
+ const OPT_COMMON_ACCESS_BASED_ASYNC_CACHE = 2;
158
 
159
  /**
160
  * Type of dynamic cache processing
161
  */
162
+ const OPT_COMMON_ACCESS_BASED_2ND_CACHE = 3;
163
+
164
+ /**
165
+ * Type of scheme migration mode
166
+ */
167
+ const OPT_COMMON_SCHEME_MIGRATION_MODE_OFF = false;
168
+
169
+ /**
170
+ * Type of scheme migration mode
171
+ */
172
+ const OPT_COMMON_SCHEME_MIGRATION_MODE_ON = true;
173
+
174
  /**
175
  * Option key for custom post types for share base cache
176
  */
189
  /**
190
  * Option key for dynamic cache
191
  */
192
+ const DB_COMMON_DYNAMIC_CACHE = 'scc_dynamic_cache_mode';
193
 
194
  /**
195
  * Option key for new content term for share rush cache
214
  /**
215
  * Option key of data export
216
  */
217
+ const DB_COMMON_DATA_EXPORT = 'scc_data_export_mode';
218
 
219
  /**
220
  * Option key of data export interval
221
  */
222
+ const DB_COMMON_DATA_EXPORT_INTERVAL = 'scc_data_export_mode_interval';
223
+
224
+ /**
225
+ * Option key of data export schedule
226
+ */
227
+ const DB_COMMON_DATA_EXPORT_SCHEDULE = 'scc_data_export_schedule';
228
+
229
+ /**
230
+ * Option key of http migration
231
+ */
232
+ const DB_COMMON_SCHEME_MIGRATION_MODE = 'scc_scheme_migration_mode';
233
 
234
  /**
235
  * Slug of the plugin
280
  * ID of common data export
281
  */
282
  const REF_COMMON_EXPORT = 'common-export';
283
+
284
+ /**
285
+ * ID of common data export
286
+ */
287
+ const REF_COMMON_CONTROL = 'common-control';
288
 
289
  /**
290
  * ID of share
355
  * Instance of export engine
356
  */
357
  private $export_engines = array();
358
+
359
+ /**
360
+ * Instance of control engine
361
+ */
362
+ private $control_engines = array();
363
 
364
  /**
365
  * Slug of the plugin screen
370
  * Cache target for share base cache
371
  */
372
  private $share_base_cache_target = array();
373
+
374
+ /**
375
+ * Post types to be cached
376
+ */
377
+ private $share_base_cache_post_types = array( 'post', 'page' );
378
 
379
  /**
380
+ * Post types to be cached
381
  */
382
+ private $share_base_custom_post_types = array();
383
+
384
+ /**
385
+ * Check interval for share base cahce
386
+ */
387
+ private $share_base_check_interval = 600;
388
+
389
+ /**
390
+ * Post per check for share base cache
391
+ */
392
+ private $share_base_posts_per_check = 20;
393
+
394
+ /**
395
+ * Term considering content as new one
396
+ */
397
+ private $share_rush_new_content_term = 3;
398
 
399
  /**
400
+ * Cache target for follow base cache
401
  */
402
+ private $follow_base_cache_target = array();
403
 
404
  /**
405
+ * Check interval for follow base cache
406
+ */
407
+ private $follow_base_check_interval = 1800;
408
+
409
+ /**
410
+ * Dynamic cache mode
411
  */
412
+ private $dynamic_cache_mode = 0;
413
 
414
  /**
415
+ * Data export mode
416
  */
417
+ private $data_export_mode = 0;
418
+
419
+ /**
420
+ * Data export interval
421
+ */
422
+ private $data_export_interval = 3600;
423
+
424
+ /**
425
+ * Data export schedule
426
+ */
427
+ private $data_export_schedule = '* * * * *';
428
+
429
+ /**
430
+ * Migration mode from http to https
431
+ */
432
+ private $scheme_migration_mode = false;
433
+
434
+ /**
435
+ * Excluded key in migration from http to https
436
+ */
437
+ private $scheme_migration_exclude_keys = array();
438
+
439
+ /**
440
+ * Max execution time
441
+ */
442
+ private $original_max_execution_time = 0;
443
+
444
+ /**
445
+ * Extended max execution time
446
+ */
447
+ private $extended_max_execution_time = 300;
448
+
449
  /**
450
  * Instance
451
  */
452
  private static $instance = NULL;
453
+
454
  /**
455
  * Class constarctor
456
  * Hook onto all of the actions and filters needed by the plugin.
495
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
496
 
497
  $share_base_check_interval = get_option( self::DB_SHARE_CHECK_INTERVAL );
498
+ $this->share_base_check_interval = ! empty( $share_base_check_interval ) ? intval( $share_base_check_interval ) : self::OPT_SHARE_BASE_CHECK_INTERVAL;
499
 
500
  $share_base_posts_per_check = get_option( self::DB_SHARE_POSTS_PER_CHECK );
501
+ $this->share_base_posts_per_check = ! empty( $share_base_posts_per_check ) ? intval( $share_base_posts_per_check ) : self::OPT_SHARE_BASE_POSTS_PER_CHECK;
502
 
503
  $follow_base_check_interval = get_option( self::DB_FOLLOW_CHECK_INTERVAL );
504
+ $this->follow_base_check_interval = ! empty( $follow_base_check_interval ) ? intval( $follow_base_check_interval ) : self::OPT_FOLLOW_BASE_CHECK_INTERVAL;
505
 
506
+ $dynamic_cache_mode = get_option( self::DB_COMMON_DYNAMIC_CACHE );
507
+ $this->dynamic_cache_mode = ! empty( $dynamic_cache_mode ) ? $dynamic_cache_mode : self::OPT_COMMON_ACCESS_BASED_CACHE_NONE;
508
 
509
  $share_rush_new_content_term = get_option( self::DB_SHARE_NEW_CONTENT_TERM );
510
+ $this->share_rush_new_content_term = ! empty( $share_rush_new_content_term ) ? intval( $share_rush_new_content_term ) : self::OPT_SHARE_RUSH_NEW_CONTENT_TERM;
511
 
512
  $this->share_base_cache_target = get_option( self::DB_SHARE_CACHE_TARGET );
513
  $this->follow_base_cache_target = get_option( self::DB_FOLLOW_CACHE_TARGET );
514
 
515
+ $data_export_mode = get_option( self::DB_COMMON_DATA_EXPORT );
516
+ $this->data_export_mode = isset( $data_export_mode ) ? intval( $data_export_mode ) : self::OPT_COMMON_DATA_EXPORT_MANUAL;
517
 
518
  $data_export_interval = get_option( self::DB_COMMON_DATA_EXPORT_INTERVAL );
519
+ $this->data_export_interval = ! empty( $data_export_interval ) ? intval( $data_export_interval ) : self::OPT_COMMON_DATA_EXPORT_INTERVAL;
520
+
521
+ $scheme_migration_mode = get_option( self::DB_COMMON_SCHEME_MIGRATION_MODE );
522
+ $this->scheme_migration_mode = isset( $scheme_migration_mode ) ? $scheme_migration_mode : self::OPT_COMMON_SCHEME_MIGRATION_MODE_OFF;
523
+
524
+ $this->scheme_migration_exclude_keys = array( self::REF_SHARE_POCKET, self::REF_SHARE_GPLUS );
525
 
526
  if ( ! $this->share_base_cache_target ) {
527
  $this->share_base_cache_target[self::REF_SHARE_TWITTER] = true;
540
  $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = true;
541
  }
542
 
543
+ $this->share_base_custom_post_types = get_option( self::DB_SHARE_CUSTOM_POST_TYPES );
544
 
545
+ if ( ! $this->share_base_custom_post_types ) {
546
+ $this->share_base_custom_post_types = array();
547
  }
548
 
549
+ $this->share_base_cache_post_types = array_merge( $this->share_base_cache_post_types, $this->share_base_custom_post_types );
 
 
 
550
 
551
+ $data_export_schedule = get_option( self::DB_COMMON_DATA_EXPORT_SCHEDULE );
552
+ $this->data_export_schedule = ! empty( $data_export_schedule ) ? $data_export_schedule : self::OPT_COMMON_DATA_EXPORT_SCHEDULE;
553
+
554
  // Crawler
555
  $this->crawlers[self::REF_SHARE] = Share_Crawler::get_instance();
556
  $this->crawlers[self::REF_FOLLOW] = Follow_Crawler::get_instance();
560
  'delegate' => $this,
561
  'crawler' => $this->crawlers[self::REF_SHARE],
562
  'target_sns' => $this->share_base_cache_target,
563
+ 'check_interval' => $this->share_base_check_interval,
564
+ 'posts_per_check' => $this->share_base_posts_per_check,
565
+ 'post_types' => $this->share_base_cache_post_types,
566
+ 'scheme_migration_mode' => $this->scheme_migration_mode,
567
+ 'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
568
  );
569
 
570
  $this->cache_engines[self::REF_SHARE_BASE] = Share_Base_Cache_Engine::get_instance();
576
  'crawler' => $this->crawlers[self::REF_SHARE],
577
  'target_sns' => $this->share_base_cache_target,
578
  'check_interval' => self::OPT_SHARE_RUSH_CHECK_INTERVAL,
579
+ 'posts_per_check' => $this->share_base_posts_per_check,
580
+ 'new_content_term' => $this->share_rush_new_content_term,
581
+ 'post_types' => $this->share_base_cache_post_types,
582
+ 'scheme_migration_mode' => $this->scheme_migration_mode,
583
+ 'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
584
  );
585
 
586
  $this->cache_engines[self::REF_SHARE_RUSH] = Share_Rush_Cache_Engine::get_instance();
591
  'delegate' => $this,
592
  'crawler' => $this->crawlers[self::REF_SHARE],
593
  'target_sns' => $this->share_base_cache_target,
594
+ 'check_interval' => $this->share_base_check_interval,
595
+ 'posts_per_check' => $this->share_base_posts_per_check,
596
+ 'post_types' => $this->share_base_cache_post_types,
597
+ 'scheme_migration_mode' => $this->scheme_migration_mode,
598
+ 'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
599
  );
600
 
601
  $this->cache_engines[self::REF_SHARE_LAZY] = Share_Lazy_Cache_Engine::get_instance();
606
  'target_sns' => $this->share_base_cache_target,
607
  'check_interval' => self::OPT_SHARE_2ND_CHECK_INTERVAL,
608
  'post_types' => $this->share_base_cache_post_types,
609
+ 'meta_key_prefix' => self::OPT_SHARE_2ND_META_KEY_PREFIX,
610
+ 'scheme_migration_mode' => $this->scheme_migration_mode,
611
+ 'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
612
  );
613
 
614
  $this->cache_engines[self::REF_SHARE_2ND] = Share_Second_Cache_Engine::get_instance();
619
  'delegate' => $this,
620
  'crawler' => $this->crawlers[self::REF_SHARE],
621
  'target_sns' => $this->share_base_cache_target,
622
+ 'check_interval' => $this->share_base_check_interval,
623
+ 'posts_per_check' => $this->share_base_posts_per_check,
624
+ 'post_types' => $this->share_base_cache_post_types,
625
+ 'scheme_migration_mode' => $this->scheme_migration_mode,
626
+ 'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
627
  );
628
 
629
  $this->cache_engines[self::REF_SHARE_RESCUE] = Share_Rescue_Cache_Engine::get_instance();
631
 
632
  // Follow base cache engine
633
  $options = array(
634
+ 'delegate' => $this,
635
  'crawler' => $this->crawlers[self::REF_FOLLOW],
636
  'target_sns' => $this->follow_base_cache_target,
637
+ 'check_interval' => $this->follow_base_check_interval,
638
+ 'post_types' => $this->share_base_cache_post_types,
639
+ 'scheme_migration_mode' => $scheme_migration_mode
640
  );
641
 
642
  $this->cache_engines[self::REF_FOLLOW_BASE] = Follow_Base_Cache_Engine::get_instance();
644
 
645
  // Follow lazy cache engine
646
  $options = array(
647
+ 'delegate' => $this,
648
  'crawler' => $this->crawlers[self::REF_FOLLOW],
649
  'target_sns' => $this->follow_base_cache_target,
650
+ 'check_interval' => $this->follow_base_check_interval,
651
+ 'scheme_migration_mode' => $this->scheme_migration_mode
652
  );
653
 
654
  $this->cache_engines[self::REF_FOLLOW_LAZY] = Follow_Lazy_Cache_Engine::get_instance();
667
 
668
  // Data export engine
669
  $options = array(
670
+ 'export_activation' => $this->data_export_mode,
671
+ 'export_interval' => $this->data_export_interval,
672
+ 'export_schedule' => $this->data_export_schedule,
673
  'share_target_sns' => $this->share_base_cache_target,
674
  'follow_target_sns' => $this->follow_base_cache_target,
675
  'export_file_name' => self::OPT_COMMON_DATA_EXPORT_FILE_NAME,
679
 
680
  $this->export_engines[self::REF_COMMON_EXPORT] = Common_Data_Export_Engine::get_instance();
681
  $this->export_engines[self::REF_COMMON_EXPORT]->initialize( $options );
682
+
683
+ // Job reset engine
684
+ $target_crons = array();
685
+
686
+ foreach ( $this->cache_engines as $key => $cache_engine ) {
687
+ $target_crons[] = $cache_engine->get_excute_cron();
688
+ }
689
+
690
+ foreach ( $this->control_engines as $key => $control_engine ) {
691
+ $target_crons[] = $control_engine->get_excute_cron();
692
+ }
693
+
694
+ if ( $this->data_export_mode ) {
695
+ $target_crons[] = $this->export_engines[self::REF_COMMON_EXPORT]->get_excute_cron();
696
+ }
697
+
698
+ $options = array(
699
+ 'delegate' => $this,
700
+ 'check_interval' => 600,
701
+ 'expiration_time ' => 1800,
702
+ 'target_cron' => $target_crons
703
+ );
704
 
705
+ $this->control_engines[self::REF_COMMON_CONTROL] = Common_Job_Reset_Engine::get_instance();
706
+ $this->control_engines[self::REF_COMMON_CONTROL]->initialize( $options );
707
+
708
  // delete old hooks
709
  WP_Cron_Util::clear_scheduled_hook( 'scc_basecache_prime' );
710
  WP_Cron_Util::clear_scheduled_hook( 'scc_rushcache_prime' );
711
  WP_Cron_Util::clear_scheduled_hook( 'scc_2ndcache_prime' );
712
+
713
+ $tmp_max_execution_time = ini_get( 'max_execution_time' );
714
+
715
+ if ( isset( $tmp_max_execution_time ) && $tmp_max_execution_time > 0 ) {
716
+ $this->original_max_execution_time = $tmp_max_execution_time;
717
+ } else {
718
+ $this->original_max_execution_time = 30;
719
+ }
720
+
721
  }
722
 
723
  /**
769
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
770
 
771
  $this->initialize();
772
+
773
+ set_time_limit( $this->extended_max_execution_time );
774
 
775
  foreach ( $this->cache_engines as $key => $cache_engine ) {
776
+ switch ( $key ) {
777
+ case self::REF_SHARE_2ND:
778
+ $cache_engine->initialize_cache();
779
+ break;
780
+ case self::REF_FOLLOW_2ND:
781
+ $cache_engine->initialize_cache();
782
+ break;
783
+ default:
784
+ $cache_engine->initialize_cache();
785
+ $cache_engine->register_schedule();
786
+ }
787
  }
788
+
789
+ foreach ( $this->control_engines as $key => $control_engine ) {
790
+ $control_engine->register_schedule();
791
+ }
792
+
793
+ if ( $this->data_export_mode ) {
794
  $this->export_engines[self::REF_COMMON_EXPORT]->register_schedule();
795
  }
796
+
797
+ set_time_limit( $this->original_max_execution_time );
798
+
799
  }
800
+
801
  /**
802
  * Deactivate cache engine (schedule cron)
803
  *
805
  */
806
  function deactivate_plugin() {
807
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
808
+
809
+ set_time_limit( $this->extended_max_execution_time );
810
+
811
  foreach ( $this->cache_engines as $key => $cache_engine ) {
812
  $cache_engine->unregister_schedule();
813
  $cache_engine->clear_cache();
814
  }
815
+
816
+ foreach ( $this->control_engines as $key => $control_engine ) {
817
+ $control_engine->unregister_schedule();
818
+ }
819
+
820
  $this->export_engines[self::REF_COMMON_EXPORT]->unregister_schedule();
821
+
822
+ set_time_limit( $this->original_max_execution_time );
823
+
824
  }
825
 
826
  /**
831
  function reactivate_plugin() {
832
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
833
 
834
+ $this->deactivate_plugin();
835
+ $this->activate_plugin();
836
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
837
  }
838
 
839
  /**
905
  *
906
  * @since 0.2.0
907
  */
908
+ public function get_dynamic_cache_mode() {
909
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
910
 
911
+ return $this->dynamic_cache_mode;
912
  }
913
 
914
  /**
916
  *
917
  * @since 0.2.0
918
  */
919
+ public function retrieve_share_cache( $post_ID, $second_sync = false ) {
920
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
921
 
922
+ return $this->cache_engines[self::REF_SHARE_BASE]->direct_cache( $post_ID, $second_sync );
923
  }
924
 
925
  /**
997
  break;
998
  case 'Share_Rush_Cache_Engine':
999
  $this->cache_engines[self::REF_SHARE_2ND]->cache( $options['post_id'], $this->share_base_cache_target, NULL );
1000
+ break;
1001
+ case 'Follow_Lazy_Cache_Engine':
1002
+ $this->cache_engines[self::REF_FOLLOW_2ND]->cache( NULL, $this->follow_base_cache_target, NULL );
1003
  break;
1004
+ case 'Follow_Base_Cache_Engine':
1005
+ $this->cache_engines[self::REF_FOLLOW_2ND]->cache( NULL, $this->follow_base_cache_target, NULL );
1006
+ break;
1007
  }
1008
 
1009
  }
1121
  $sns_counts[$sns_key] = $sns_count;
1122
  } else {
1123
  $sns_counts[$sns_key] = 0;
1124
+ }
 
1125
  return $sns_counts[$sns_key];
1126
  } else {
1127
 
1131
  } else {
1132
  $sns_counts[$key] = 0;
1133
  }
1134
+ }
 
1135
  return $sns_counts;
1136
  }
1137
  } else {
1138
  $sns_count_cache = SNS_Count_Cache::get_instance();
1139
 
1140
+ switch ( $sns_count_cache->get_dynamic_cache_mode() ) {
1141
+ case SNS_Count_Cache::OPT_COMMON_ACCESS_BASED_CACHE_NONE:
1142
  if ( $sns_key ) {
1143
  $sns_counts[$sns_key] = 0;
1144
  return $sns_counts[$sns_key];
1153
  return $sns_counts;
1154
  }
1155
  break;
1156
+ case SNS_Count_Cache::OPT_COMMON_ACCESS_BASED_SYNC_CACHE:
1157
+ $sns_counts = $sns_count_cache->retrieve_share_cache( $post_ID, true );
1158
  if ( $sns_key ) {
1159
  return $sns_counts[$sns_key];
1160
  } else {
1161
  return $sns_counts;
1162
  }
1163
  break;
1164
+ case SNS_Count_Cache::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE:
1165
  $sns_count_cache->reserve_share_cache( $post_ID );
1166
  if ( $sns_key ) {
1167
  $sns_counts[$sns_key] = 0;
1177
  return $sns_counts;
1178
  }
1179
  break;
1180
+ case SNS_Count_Cache::OPT_COMMON_ACCESS_BASED_2ND_CACHE:
1181
  $sns_count_cache->reserve_share_cache( $post_ID );
1182
  if ( $sns_key ) {
1183
  $meta_key = SNS_Count_Cache::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( $sns_key );
1188
  $sns_counts[$sns_key] = $sns_count;
1189
  } else {
1190
  $sns_counts[$sns_key] = 0;
1191
+ }
 
1192
  return $sns_counts[$sns_key];
1193
  } else {
1194
  $base_cache_target = $sns_count_cache->get_share_base_cache_target();
1254
  } else {
1255
  $sns_followers[$key] = 0;
1256
  }
1257
+ }
 
1258
  return $sns_followers;
1259
  }
1260
  } else {
1261
  $sns_count_cache = SNS_Count_Cache::get_instance();
1262
 
1263
+ switch ( $sns_count_cache->get_dynamic_cache_mode() ) {
1264
+ case SNS_Count_Cache::OPT_COMMON_ACCESS_BASED_CACHE_NONE:
1265
  if ( $sns_key ) {
1266
  $sns_followers[$sns_key] = 0;
1267
  return $sns_followers[$sns_key];
1272
  if ( $value ) {
1273
  $sns_followers[$key] = 0;
1274
  }
1275
+ }
 
1276
  return $sns_followers;
1277
  }
1278
  break;
1279
+ case SNS_Count_Cache::OPT_COMMON_ACCESS_BASED_SYNC_CACHE:
1280
  $sns_followers = $sns_count_cache->retrieve_follow_cache();
1281
  if ( $sns_key ) {
1282
  return $sns_followers[$sns_key];
1284
  return $sns_followers;
1285
  }
1286
  break;
1287
+ case SNS_Count_Cache::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE:
1288
  $sns_count_cache->reserve_follow_cache();
1289
  if ( $sns_key ) {
1290
  $sns_followers[$sns_key] = 0;
1300
  return $sns_followers;
1301
  }
1302
  break;
1303
+ case SNS_Count_Cache::OPT_COMMON_ACCESS_BASED_2ND_CACHE:
1304
  $sns_count_cache->reserve_follow_cache();
1305
 
1306
  if ( $sns_key ) {
1307
  $meta_key = SNS_Count_Cache::OPT_FOLLOW_2ND_META_KEY_PREFIX . strtolower( $sns_key );
1308
+
1309
+ $sns_follower = get_option( $meta_key );
1310
 
1311
  if ( isset( $sns_follower ) && $sns_follower >= 0 ) {
1312
  $sns_followers[$sns_key] = $sns_follower;
1313
  } else {
1314
  $sns_followers[$sns_key] = 0;
1315
+ }
 
1316
  return $sns_followers[$sns_key];
1317
  } else {
1318
  $base_cache_target = $sns_count_cache->get_follow_base_cache_target();
1321
  if ( $value ) {
1322
  $meta_key = SNS_Count_Cache::OPT_FOLLOW_2ND_META_KEY_PREFIX . strtolower( $key );
1323
 
1324
+ $sns_follower = get_option( $meta_key );
1325
+
1326
  if ( isset( $sns_follower ) && $sns_follower >= 0 ) {
1327
  $sns_followers[$key] = $sns_follower;
1328
  } else {
uninstall.php CHANGED
@@ -1,30 +1,40 @@
1
  <?php
2
  //if uninstall not called from WordPress exit
3
- if(!defined('WP_UNINSTALL_PLUGIN')) exit();
4
 
5
  $db_check_interval = 'scc_check_interval';
6
  $db_follow_check_interval = 'scc_follow_check_interval';
7
  $db_posts_per_check = 'scc_posts_per_check';
8
  $db_dynamic_cache = 'scc_dynamic_cache';
 
9
  $db_new_content_term = 'scc_new_content_term';
10
  $db_cache_target = 'scc_cache_target';
11
  $db_data_export = 'scc_data_export';
 
12
  $db_data_export_interval = 'scc_data_export_interval';
13
  $db_custom_post_types = 'scc_custom_post_types';
14
  $db_follow_cache_target = 'scc_follow_cache_target';
 
 
 
15
 
16
  // For Single site
17
- if(!is_multisite()){
18
- delete_option($db_custom_post_types);
19
- delete_option($db_check_interval);
20
- delete_option($db_follow_check_interval);
21
- delete_option($db_posts_per_check);
22
- delete_option($db_dynamic_cache);
23
- delete_option($db_new_content_term);
24
- delete_option($db_cache_target);
25
- delete_option($db_data_export);
26
- delete_option($db_data_export_interval);
27
- delete_option($db_follow_cache_target);
 
 
 
 
 
28
  }
29
  // For Multisite
30
  else {
@@ -32,20 +42,25 @@ else {
32
  $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
33
  $original_blog_id = get_current_blog_id();
34
 
35
- foreach($blog_ids as $blog_id){
36
- switch_to_blog($blog_id);
37
 
38
- delete_option($db_custom_post_types);
39
- delete_option($db_check_interval);
40
- delete_option($db_follow_check_interval);
41
- delete_option($db_posts_per_check);
42
- delete_option($db_dynamic_cache);
43
- delete_option($db_new_content_term);
44
- delete_option($db_cache_target);
45
- delete_option($db_data_export);
46
- delete_option($db_data_export_interval);
47
- delete_option($db_follow_cache_target);
 
 
 
 
 
48
  }
49
- switch_to_blog($original_blog_id);
50
  }
51
  ?>
1
  <?php
2
  //if uninstall not called from WordPress exit
3
+ if( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) exit();
4
 
5
  $db_check_interval = 'scc_check_interval';
6
  $db_follow_check_interval = 'scc_follow_check_interval';
7
  $db_posts_per_check = 'scc_posts_per_check';
8
  $db_dynamic_cache = 'scc_dynamic_cache';
9
+ $db_dynamic_cache_mode = 'scc_dynamic_cache_mode';
10
  $db_new_content_term = 'scc_new_content_term';
11
  $db_cache_target = 'scc_cache_target';
12
  $db_data_export = 'scc_data_export';
13
+ $db_data_export_mode = 'scc_data_export_mode';
14
  $db_data_export_interval = 'scc_data_export_interval';
15
  $db_custom_post_types = 'scc_custom_post_types';
16
  $db_follow_cache_target = 'scc_follow_cache_target';
17
+ $db_data_export_schedule = 'scc_data_export_schedule';
18
+ $db_http_migration_mode = 'scc_http_migration_mode';
19
+ $db_scheme_migration_mode = 'scc_scheme_migration_mode';
20
 
21
  // For Single site
22
+ if( ! is_multisite() ) {
23
+ delete_option( $db_custom_post_types );
24
+ delete_option( $db_check_interval );
25
+ delete_option( $db_follow_check_interval );
26
+ delete_option( $db_posts_per_check );
27
+ delete_option( $db_dynamic_cache );
28
+ delete_option( $db_dynamic_cache_mode );
29
+ delete_option( $db_new_content_term );
30
+ delete_option( $db_cache_target );
31
+ delete_option( $db_data_export );
32
+ delete_option( $db_data_export_mode );
33
+ delete_option( $db_data_export_interval );
34
+ delete_option( $db_follow_cache_target );
35
+ delete_option( $db_data_export_schedule );
36
+ delete_option( $db_http_migration_mode );
37
+ delete_option( $db_scheme_migration_mode );
38
  }
39
  // For Multisite
40
  else {
42
  $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
43
  $original_blog_id = get_current_blog_id();
44
 
45
+ foreach( $blog_ids as $blog_id ) {
46
+ switch_to_blog( $blog_id );
47
 
48
+ delete_option( $db_custom_post_types );
49
+ delete_option( $db_check_interval );
50
+ delete_option( $db_follow_check_interval );
51
+ delete_option( $db_posts_per_check );
52
+ delete_option( $db_dynamic_cache );
53
+ delete_option( $db_dynamic_cache_mode );
54
+ delete_option( $db_new_content_term );
55
+ delete_option( $db_cache_target );
56
+ delete_option( $db_data_export );
57
+ delete_option( $db_data_export_mode );
58
+ delete_option( $db_data_export_interval );
59
+ delete_option( $db_follow_cache_target );
60
+ delete_option( $db_data_export_schedule );
61
+ delete_option( $db_http_migration_mode );
62
+ delete_option( $db_scheme_migration_mode );
63
  }
64
+ switch_to_blog( $original_blog_id );
65
  }
66
  ?>