SNS Count Cache - Version 0.6.0

Version Description

  • Added: function to cache share count for home page.
  • Improved: Each retrieval time of SNS count is shortened.
  • Improved: loading time of dashboard page is shortened using ajax loading technique.
  • Fixed: SNS count of facebook can be 0.
  • Fixed: "PHP Notice: has_cap..." is output.

=

Download this release

Release Info

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

Code changes from version 0.5.0 to 0.6.0

Files changed (41) hide show
  1. css/sns-count-cache.css +16 -6
  2. images/loading.gif +0 -0
  3. includes/admin-cache-status.php +225 -139
  4. includes/admin-dashboard-widget.php +126 -0
  5. includes/admin-dashboard.php +38 -333
  6. includes/admin-help.php +1 -2
  7. includes/admin-notice.php +21 -0
  8. includes/admin-setting.php +589 -499
  9. includes/admin-share-count.php +190 -202
  10. includes/class-cache-engine.php +22 -21
  11. includes/class-common-data-export-engine.php +40 -25
  12. includes/class-common-job-reset-engine.php +2 -12
  13. includes/class-common-util.php +123 -6
  14. includes/class-data-crawler.php +55 -12
  15. includes/class-engine.php +28 -4
  16. includes/class-export-engine.php +2 -12
  17. includes/class-follow-base-cache-engine.php +35 -26
  18. includes/class-follow-cache-engine.php +19 -24
  19. includes/class-follow-crawler.php +77 -63
  20. includes/class-follow-lazy-cache-engine.php +23 -23
  21. includes/class-follow-second-cache-engine.php +44 -79
  22. includes/class-share-base-cache-engine.php +91 -50
  23. includes/class-share-cache-engine.php +23 -20
  24. includes/class-share-crawler.php +154 -188
  25. includes/class-share-lazy-cache-engine.php +23 -18
  26. includes/class-share-rescue-cache-engine.php +31 -43
  27. includes/class-share-rush-cache-engine.php +28 -32
  28. includes/class-share-second-cache-engine.php +64 -40
  29. includes/class-wp-cron-util.php +1 -2
  30. includes/download.php +32 -30
  31. includes/interface-cache-order.php +1 -2
  32. js/jquery.scc-cache-info.js +46 -0
  33. js/jquery.scc-cache-info.min.js +3 -0
  34. js/jquery.sns-count-cache.js +0 -22
  35. readme.txt +12 -3
  36. screenshot-1.png +0 -0
  37. screenshot-2.png +0 -0
  38. screenshot-3.png +0 -0
  39. screenshot-4.png +0 -0
  40. sns-count-cache.php +955 -414
  41. uninstall.php +5 -2
css/sns-count-cache.css CHANGED
@@ -7,14 +7,20 @@
7
  font-size: 16px !important;
8
  }
9
 
 
 
 
 
 
 
10
  .sns-cnt-cache .postbox .inside {
11
  padding: 0 10px;
12
  }
13
 
14
  .sns-cnt-cache .view-table {
15
  border: 1px solid #000;
16
- margin: 20px 0;
17
- padding: 0px;
18
  width: 100%;
19
  border-collapse: collapse;
20
  border-spacing: 0;
@@ -28,6 +34,10 @@
28
  background-color: #f9f9f9;
29
  }
30
 
 
 
 
 
31
  .sns-cnt-cache .view-table th {
32
  vertical-align: middle;
33
  padding: 3px;
@@ -36,6 +46,10 @@
36
  color: #fff;
37
  }
38
 
 
 
 
 
39
  .sns-cnt-cache .form-table .section-label {
40
  font-weight: 600;
41
  font-size: 1.3em;
@@ -97,10 +111,6 @@
97
  color: #fff;
98
  }
99
 
100
- .sns-cnt-cache h4 {
101
- font-size: 15px;
102
- }
103
-
104
  .sns-cnt-cache a.sort-exec-key {
105
  text-decoration: underline;
106
  }
7
  font-size: 16px !important;
8
  }
9
 
10
+ .sns-cnt-cache h4 {
11
+ font-size: 15px;
12
+ padding: 15px 0 10px 0 !important;
13
+ font-weight: 700;
14
+ }
15
+
16
  .sns-cnt-cache .postbox .inside {
17
  padding: 0 10px;
18
  }
19
 
20
  .sns-cnt-cache .view-table {
21
  border: 1px solid #000;
22
+ margin: 0;
23
+ padding: 0;
24
  width: 100%;
25
  border-collapse: collapse;
26
  border-spacing: 0;
34
  background-color: #f9f9f9;
35
  }
36
 
37
+ .sns-cnt-cache .view-table tr.home {
38
+ border-bottom: 1px solid #dbdbdb;
39
+ }
40
+
41
  .sns-cnt-cache .view-table th {
42
  vertical-align: middle;
43
  padding: 3px;
46
  color: #fff;
47
  }
48
 
49
+ .sns-cnt-cache .pagination {
50
+ margin: 10px 0;
51
+ }
52
+
53
  .sns-cnt-cache .form-table .section-label {
54
  font-weight: 600;
55
  font-size: 1.3em;
111
  color: #fff;
112
  }
113
 
 
 
 
 
114
  .sns-cnt-cache a.sort-exec-key {
115
  text-decoration: underline;
116
  }
images/loading.gif ADDED
Binary file
includes/admin-cache-status.php CHANGED
@@ -3,7 +3,6 @@
3
  admin-cache-status.php
4
 
5
  Description: Option page implementation
6
- Version: 0.4.0
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -40,32 +39,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
40
  $paged = 1;
41
  }
42
 
43
- if ( isset( $_GET['_wpnonce'] ) && $_GET['_wpnonce'] ) {
44
- $nonce = $_GET['_wpnonce'];
45
-
46
- if ( wp_verify_nonce( $nonce, __FILE__ ) ) {
47
  if( isset( $_GET["action"] ) && $_GET["action"] === 'cache' ) {
48
-
49
  if( isset( $_GET["post_id"] ) ) {
50
  $post_id = $_GET["post_id"];
51
 
52
- $this->retrieve_share_cache( $post_id, true );
53
- }
54
-
 
 
 
55
  }
56
- }
 
57
  }
58
 
59
- /*
60
- $query_args = array(
61
- 'post_type' => $this->share_base_cache_post_types,
62
- 'post_status' => 'publish',
63
- 'nopaging' => true,
64
- 'update_post_term_cache' => false,
65
- 'update_post_meta_cache' => false
66
- );
67
- */
68
-
69
  $query_args = array(
70
  'post_type' => $this->share_base_cache_post_types,
71
  'post_status' => 'publish',
@@ -79,69 +71,106 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
79
  ?>
80
  <div class="wrap">
81
  <h2><a href="admin.php?page=scc-cache-status"><?php _e( 'SNS Count Cache', self::DOMAIN ) ?></a></h2>
82
- <div class="sns-cnt-cache">
83
- <h3 class="nav-tab-wrapper">
84
- <a class="nav-tab" href="admin.php?page=scc-dashboard">Dashboard</a>
85
- <a class="nav-tab nav-tab-active" href="admin.php?page=scc-cache-status">Cache Status</a>
86
- <a class="nav-tab" href="admin.php?page=scc-share-count">Share Count</a>
87
- <a class="nav-tab" href="admin.php?page=scc-setting">Setting</a>
88
- <a class="nav-tab" href="admin.php?page=scc-help">Help</a>
89
- </h3>
90
-
91
- <div class="metabox-holder">
92
- <div id="share-site-summary" class="postbox">
93
- <div class="handlediv" title="Click to toggle"><br></div>
94
- <h3 class="hndle"><span><?php _e( 'Cache Status', self::DOMAIN ) ?></span></h3>
95
- <div class="inside">
96
-
97
- <table class="view-table">
98
- <thead>
99
- <tr>
100
- <th>No.</th>
101
- <th><?php _e( 'Target Content', self::DOMAIN ) ?></th>
102
- <th><?php _e( 'Primary Cache', self::DOMAIN ) ?></th>
103
- <th><?php _e( 'Secondary Cache', self::DOMAIN ) ?></th>
104
- <th><?php _e( 'Crawl Date', self::DOMAIN ) ?></th>
105
- <th></th>
106
- </tr>
107
- </thead>
108
- <tbody>
109
-
110
- <?php
111
 
112
- $count = ($paged - 1) * $posts_per_page + 1;
113
 
114
- $share_base_cache_target = $this->share_base_cache_target ;
115
- unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
116
 
117
- if ( $posts_query->have_posts() ) {
118
- while ( $posts_query->have_posts() ) {
119
- $posts_query->the_post();
120
- ?>
121
- <tr>
122
- <td><?php echo $count; ?></td>
123
- <td><a href="<?php echo esc_url( get_permalink( get_the_ID() ) ); ?>" target="_blank"><?php echo esc_html( get_permalink( get_the_ID() ) ); ?></a></td>
124
- <?php
125
- $transient_id = self::OPT_SHARE_BASE_TRANSIENT_PREFIX . get_the_ID();
126
-
127
- if ( false === ( $sns_counts = get_transient( $transient_id ) ) ) {
128
- echo '<td class="no-cache">';
129
- _e( 'no cache', self::DOMAIN );
130
- echo '</td>';
131
- } else {
132
- $full_cache_flag = true;
133
- $partial_cache_flag = false;
134
 
135
- foreach ( $share_base_cache_target as $key => $value ) {
136
- if ( $value ) {
137
- if ( isset( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
138
- $partial_cache_flag = true;
139
- } else {
140
- $full_cache_flag = false;
 
141
  }
142
- }
143
- }
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  if ( $partial_cache_flag && $full_cache_flag ) {
146
  echo '<td class="full-cache">';
147
  _e( 'full cache', self::DOMAIN );
@@ -154,85 +183,142 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
154
  echo '<td class="no-cache">';
155
  _e( 'no cache', self::DOMAIN );
156
  echo '</td>';
157
- }
158
- }
 
 
 
 
 
 
 
 
 
159
 
160
- $full_cache_flag = true;
161
- $partial_cache_flag = false;
 
 
 
 
 
162
 
163
- foreach ( $share_base_cache_target as $key => $value ) {
164
- if ( $value ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
- $meta_key = self::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( $key );
167
- $sns_count = get_post_meta( get_the_ID(), $meta_key, true );
 
 
 
 
168
 
169
- if ( isset( $sns_count ) && $sns_count >= 0 ) {
170
- $partial_cache_flag = true;
171
- } else {
172
- $full_cache_flag = false;
 
173
  }
174
-
175
  }
176
- }
177
 
178
- if ( $partial_cache_flag && $full_cache_flag ) {
179
- echo '<td class="full-cache">';
180
- _e( 'full cache', self::DOMAIN );
181
- echo '</td>';
182
- } else if ( $partial_cache_flag && ! $full_cache_flag ) {
183
- echo '<td class="partial-cache">';
184
- _e( 'partial cache', self::DOMAIN );
185
- echo '</td>';
186
- } else {
187
- echo '<td class="no-cache">';
188
- _e( 'no cache', self::DOMAIN );
189
- echo '</td>';
190
- }
191
-
192
- if ( isset( $sns_counts[self::REF_CRAWL_DATE] ) ) {
193
- echo '<td class="full-cache">';
194
- echo $sns_counts[self::REF_CRAWL_DATE];
195
- echo '</td>';
196
- } else {
197
-
198
- $meta_key = self::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( self::REF_CRAWL_DATE );
199
- $crawl_date = get_post_meta( get_the_ID(), $meta_key, true );
200
-
201
- if ( isset( $crawl_date ) && $crawl_date != -1 ) {
202
  echo '<td class="full-cache">';
203
- echo $crawl_date;
204
  echo '</td>';
 
 
 
 
205
  } else {
206
  echo '<td class="no-cache">';
207
- _e( 'no data', self::DOMAIN );
 
 
 
 
 
 
208
  echo '</td>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  }
210
-
211
- }
212
 
213
- $nonce = wp_create_nonce( __FILE__ );
214
- $cache_url = esc_url( 'admin.php?page=scc-cache-status&action=cache&post_id=' . get_the_ID() . '&_wpnonce=' . $nonce . '&paged=' . $paged );
215
-
216
  ?>
217
- <td><a class="button" href="<?php echo $cache_url ?>">Cache</a></td>
218
- </tr>
219
 
220
- <?php
221
- $count++;
222
 
 
223
  }
224
- }
225
  ?>
226
- </tbody>
227
- </table>
228
- <?php
229
- $this->pagination( $posts_query->max_num_pages, '', $paged, false );
230
 
231
- wp_reset_postdata();
232
- ?>
233
- </div>
234
- </div>
235
- </div>
236
-
237
  </div>
238
- </div>
3
  admin-cache-status.php
4
 
5
  Description: Option page implementation
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
39
  $paged = 1;
40
  }
41
 
42
+ if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], __FILE__ ) ) {
43
+
44
+ if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
45
+
46
  if( isset( $_GET["action"] ) && $_GET["action"] === 'cache' ) {
 
47
  if( isset( $_GET["post_id"] ) ) {
48
  $post_id = $_GET["post_id"];
49
 
50
+ //$this->retrieve_share_cache( $post_id, true );
51
+ $this->cache_engines[self::REF_SHARE_BASE]->direct_cache( $post_id, true );
52
+
53
+ //Common_Util::log( '[' . __METHOD__ . '] redirect destination: ' . menu_page_url( 'scc-cache-status', false ) );
54
+ //wp_safe_redirect( menu_page_url( 'scc-cache-status', false ) );
55
+ }
56
  }
57
+ }
58
+
59
  }
60
 
 
 
 
 
 
 
 
 
 
 
61
  $query_args = array(
62
  'post_type' => $this->share_base_cache_post_types,
63
  'post_status' => 'publish',
71
  ?>
72
  <div class="wrap">
73
  <h2><a href="admin.php?page=scc-cache-status"><?php _e( 'SNS Count Cache', self::DOMAIN ) ?></a></h2>
74
+ <div class="sns-cnt-cache">
75
+ <h3 class="nav-tab-wrapper">
76
+ <a class="nav-tab" href="admin.php?page=scc-dashboard">Dashboard</a>
77
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-cache-status">Cache Status</a>
78
+ <a class="nav-tab" href="admin.php?page=scc-share-count">Share Count</a>
79
+ <a class="nav-tab" href="admin.php?page=scc-setting">Setting</a>
80
+ <a class="nav-tab" href="admin.php?page=scc-help">Help</a>
81
+ </h3>
82
+ <div class="metabox-holder">
83
+ <div id="share-site-summary" class="postbox">
84
+ <div class="handlediv" title="Click to toggle"><br></div>
85
+ <h3 class="hndle"><span><?php _e( 'Cache Status', self::DOMAIN ) ?></span></h3>
86
+ <div class="inside">
87
+ <table class="view-table">
88
+ <thead>
89
+ <tr>
90
+ <th>No.</th>
91
+ <th><?php _e( 'Target Content', self::DOMAIN ) ?></th>
92
+ <th><?php _e( 'Primary Cache', self::DOMAIN ) ?></th>
93
+ <th><?php _e( 'Secondary Cache', self::DOMAIN ) ?></th>
94
+ <th><?php _e( 'Crawl Date', self::DOMAIN ) ?></th>
95
+ <th></th>
96
+ </tr>
97
+ </thead>
98
+ <tbody>
99
+
100
+ <?php
 
 
101
 
102
+ $count = ( $paged - 1 ) * $posts_per_page + 1;
103
 
104
+ $share_base_cache_target = $this->share_base_cache_target ;
105
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
106
 
107
+ if ( $paged === 1 ) {
108
+ ?>
109
+ <tr class="home">
110
+ <td><?php echo '-'; ?></td>
111
+ <td><a href="<?php echo esc_url( home_url( '/' ) ); ?>" target="_blank"><?php echo esc_html( home_url( '/' ) ); ?></a></td>
112
+
113
+ <?php
114
+
115
+ $share_base_cache_target = $this->share_base_cache_target ;
116
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
117
+
118
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
119
+
120
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
121
+ $full_cache_flag = true;
122
+ $partial_cache_flag = false;
 
123
 
124
+ foreach ( $share_base_cache_target as $sns => $active ) {
125
+ if ( $active ) {
126
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
127
+ $partial_cache_flag = true;
128
+ } else {
129
+ $full_cache_flag = false;
130
+ }
131
  }
132
+ }
 
133
 
134
+ if ( $partial_cache_flag && $full_cache_flag ) {
135
+ echo '<td class="full-cache">';
136
+ _e( 'full cache', self::DOMAIN );
137
+ echo '</td>';
138
+ } else if ( $partial_cache_flag && ! $full_cache_flag ) {
139
+ echo '<td class="partial-cache">';
140
+ _e( 'partial cache', self::DOMAIN );
141
+ echo '</td>';
142
+ } else {
143
+ echo '<td class="no-cache">';
144
+ _e( 'no cache', self::DOMAIN );
145
+ echo '</td>';
146
+ }
147
+ } else {
148
+ Common_Util::log( '[' . __METHOD__ . '] : no transient' );
149
+ echo '<td class="no-cache">';
150
+ _e( 'no cache', self::DOMAIN );
151
+ echo '</td>';
152
+ }
153
+
154
+ $full_cache_flag = true;
155
+ $partial_cache_flag = false;
156
+
157
+ $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
158
+
159
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
160
+ foreach ( $share_base_cache_target as $sns => $active ) {
161
+ if ( $active ) {
162
+ if ( $sns_counts[$sns] >= 0 ){
163
+ $partial_cache_flag = true;
164
+ } else {
165
+ $full_cache_flag = false;
166
+ }
167
+ }
168
+ }
169
+
170
+ } else {
171
+ $full_cache_flag = false;
172
+ }
173
+
174
  if ( $partial_cache_flag && $full_cache_flag ) {
175
  echo '<td class="full-cache">';
176
  _e( 'full cache', self::DOMAIN );
183
  echo '<td class="no-cache">';
184
  _e( 'no cache', self::DOMAIN );
185
  echo '</td>';
186
+ }
187
+
188
+ if ( isset( $sns_counts[self::REF_CRAWL_DATE] ) && $sns_counts[self::REF_CRAWL_DATE] && $sns_counts[self::REF_CRAWL_DATE] !== -1 ) {
189
+ echo '<td class="full-cache">';
190
+ echo esc_html( $sns_counts[self::REF_CRAWL_DATE] );
191
+ echo '</td>';
192
+ } else {
193
+ echo '<td class="no-cache">';
194
+ _e( 'no data', self::DOMAIN );
195
+ echo '</td>';
196
+ }
197
 
198
+ $nonce = wp_create_nonce( __FILE__ );
199
+ $cache_url = esc_url( 'admin.php?page=scc-cache-status&action=cache&post_id=' . 'home' . '&_wpnonce=' . $nonce . '&paged=' . $paged );
200
+ ?>
201
+ <td><a class="button" href="<?php echo $cache_url ?>">Cache</a></td>
202
+ </tr>
203
+ <?php
204
+ }
205
 
206
+ if ( $posts_query->have_posts() ) {
207
+ while ( $posts_query->have_posts() ) {
208
+ $posts_query->the_post();
209
+ ?>
210
+ <tr>
211
+ <td><?php echo $count; ?></td>
212
+ <td><a href="<?php echo esc_url( get_permalink( get_the_ID() ) ); ?>" target="_blank"><?php echo esc_html( get_permalink( get_the_ID() ) ); ?></a></td>
213
+ <?php
214
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( get_the_ID() );
215
+
216
+ if ( false === ( $sns_counts = get_transient( $transient_id ) ) ) {
217
+ echo '<td class="no-cache">';
218
+ _e( 'no cache', self::DOMAIN );
219
+ echo '</td>';
220
+ } else {
221
+ $full_cache_flag = true;
222
+ $partial_cache_flag = false;
223
+
224
+ foreach ( $share_base_cache_target as $sns => $active ) {
225
+ if ( $active ) {
226
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
227
+ $partial_cache_flag = true;
228
+ } else {
229
+ $full_cache_flag = false;
230
+ }
231
+ }
232
+ }
233
+
234
+ if ( $partial_cache_flag && $full_cache_flag ) {
235
+ echo '<td class="full-cache">';
236
+ _e( 'full cache', self::DOMAIN );
237
+ echo '</td>';
238
+ } else if ( $partial_cache_flag && ! $full_cache_flag ) {
239
+ echo '<td class="partial-cache">';
240
+ _e( 'partial cache', self::DOMAIN );
241
+ echo '</td>';
242
+ } else {
243
+ echo '<td class="no-cache">';
244
+ _e( 'no cache', self::DOMAIN );
245
+ echo '</td>';
246
+ }
247
+ }
248
+
249
+ $full_cache_flag = true;
250
+ $partial_cache_flag = false;
251
 
252
+ foreach ( $share_base_cache_target as $sns => $active ) {
253
+ if ( $active ) {
254
+
255
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
256
+
257
+ $sns_count = get_post_meta( get_the_ID(), $meta_key, true );
258
 
259
+ if ( isset( $sns_count ) && $sns_count !== '' && $sns_count >= 0 ) {
260
+ $partial_cache_flag = true;
261
+ } else {
262
+ $full_cache_flag = false;
263
+ }
264
  }
 
265
  }
 
266
 
267
+ if ( $partial_cache_flag && $full_cache_flag ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  echo '<td class="full-cache">';
269
+ _e( 'full cache', self::DOMAIN );
270
  echo '</td>';
271
+ } else if ( $partial_cache_flag && ! $full_cache_flag ) {
272
+ echo '<td class="partial-cache">';
273
+ _e( 'partial cache', self::DOMAIN );
274
+ echo '</td>';
275
  } else {
276
  echo '<td class="no-cache">';
277
+ _e( 'no cache', self::DOMAIN );
278
+ echo '</td>';
279
+ }
280
+
281
+ if ( isset( $sns_counts[self::REF_CRAWL_DATE] ) ) {
282
+ echo '<td class="full-cache">';
283
+ echo esc_html( $sns_counts[self::REF_CRAWL_DATE] );
284
  echo '</td>';
285
+ } else {
286
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( self::REF_CRAWL_DATE );
287
+
288
+ $crawl_date = get_post_meta( get_the_ID(), $meta_key, true );
289
+
290
+ if ( isset( $crawl_date ) && $crawl_date !== '' && $crawl_date !== '-1' ) {
291
+ echo '<td class="full-cache">';
292
+ echo esc_html( $crawl_date );
293
+ echo '</td>';
294
+ } else {
295
+ echo '<td class="no-cache">';
296
+ _e( 'no data', self::DOMAIN );
297
+ echo '</td>';
298
+ }
299
  }
 
 
300
 
301
+ $nonce = wp_create_nonce( __FILE__ );
302
+ $cache_url = esc_url( 'admin.php?page=scc-cache-status&action=cache&post_id=' . get_the_ID() . '&_wpnonce=' . $nonce . '&paged=' . $paged );
 
303
  ?>
304
+ <td><a class="button" href="<?php echo $cache_url ?>">Cache</a></td>
305
+ </tr>
306
 
307
+ <?php
308
+ ++$count;
309
 
310
+ }
311
  }
 
312
  ?>
313
+ </tbody>
314
+ </table>
315
+ <?php
316
+ $this->pagination( $posts_query->max_num_pages, '', $paged, false );
317
 
318
+ wp_reset_postdata();
319
+ ?>
320
+ </div>
321
+ </div>
322
+ </div>
 
323
  </div>
324
+ </div>
includes/admin-dashboard-widget.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ admin-dashboard-widget.php
4
+
5
+ Description: Option page implementation
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
+
16
+ This program is free software; you can redistribute it and/or
17
+ modify it under the terms of the GNU General Public License
18
+ as published by the Free Software Foundation; either version 2
19
+ of the License, or (at your option) any later version.
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
+
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program; if not, write to the Free Software
28
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29
+
30
+ */
31
+
32
+ $query_args = array(
33
+ 'post_type' => $this->share_base_cache_post_types,
34
+ 'post_status' => 'publish',
35
+ 'nopaging' => true,
36
+ 'update_post_term_cache' => false,
37
+ 'update_post_meta_cache' => false
38
+ );
39
+
40
+ $site_query = new WP_Query( $query_args );
41
+
42
+ ?>
43
+
44
+ <div class="sns-cnt-cache">
45
+ <div id="scc-dashboard">
46
+ <div id="site-summary-cache" class="site-summary">
47
+ <h4><a href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ) ?></a></h4>
48
+ <table class="view-table">
49
+ <thead>
50
+ <tr>
51
+ <th><?php _e( 'Cache Type', self::DOMAIN ) ?></th>
52
+ <th><?php _e( 'Status Overview', self::DOMAIN ) ?></th>
53
+ <th><?php _e( 'Total Content', self::DOMAIN ) ?></th>
54
+ <th><?php _e( 'State - Full Cache', self::DOMAIN ) ?></th>
55
+ <th><?php _e( 'State - Partial Cache', self::DOMAIN ) ?></th>
56
+ <th><?php _e( 'State - No Cache', self::DOMAIN ) ?></th>
57
+ </tr>
58
+ </thead>
59
+ <tbody>
60
+ <tr>
61
+ <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
62
+ <td>
63
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="pcs"></span>
64
+ </td>
65
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='pc'></span></td>
66
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='pfcc'></span></td>
67
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='ppcc'></span></td>
68
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='pncc'></span></td>
69
+ </tr>
70
+ <tr>
71
+ <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
72
+ <td>
73
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="scs"></span>
74
+ </td>
75
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='pc'></span></td>
76
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sfcc'></span></td>
77
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spcc'></span></td>
78
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sncc'></span></td>
79
+ </tr>
80
+ </tbody>
81
+ </table>
82
+ </div>
83
+ <div id="site-summary-count" class="site-summary">
84
+ <h4><a href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ) ?></a></h4>
85
+ <table class="view-table">
86
+ <thead>
87
+ <tr>
88
+ <?php
89
+ $share_base_cache_target = $this->share_base_cache_target ;
90
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
91
+
92
+ foreach ( $share_base_cache_target as $sns => $active ){
93
+ if ( $active ) {
94
+ echo '<th>' . $sns . '</th>';
95
+ }
96
+ }
97
+ ?>
98
+ </tr>
99
+ </thead>
100
+ <tbody>
101
+ <tr>
102
+ <?php
103
+
104
+ foreach ( $share_base_cache_target as $sns => $active ) {
105
+ if ( $active ) {
106
+ if ( $sns === self::REF_SHARE_GPLUS ){
107
+ echo '<td class="share-count">';
108
+ echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="gplus"></span>';
109
+ echo '</td>';
110
+ } else {
111
+ echo '<td class="share-count">';
112
+ echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="' . strtolower( $sns ) . '"></span>';
113
+ echo '</td>';
114
+ }
115
+
116
+ }
117
+ }
118
+
119
+ ?>
120
+ </tr>
121
+ </tbody>
122
+ </table>
123
+ </div>
124
+ </div>
125
+ </div>
126
+
includes/admin-dashboard.php CHANGED
@@ -3,7 +3,6 @@
3
  admin-dashboard.php
4
 
5
  Description: Option page implementation
6
- Version: 0.4.0
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -44,170 +43,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
44
  <div class="wrap">
45
  <h2><a href="admin.php?page=scc-dashboard"><?php _e( 'SNS Count Cache', self::DOMAIN ) ?></a></h2>
46
  <div class="sns-cnt-cache">
 
47
  <h3 class="nav-tab-wrapper">
48
- <a class="nav-tab nav-tab-active" href="admin.php?page=scc-dashboard">Dashboard</a>
49
- <a class="nav-tab" href="admin.php?page=scc-cache-status">Cache Status</a>
50
- <a class="nav-tab" href="admin.php?page=scc-share-count">Share Count</a>
51
- <a class="nav-tab" href="admin.php?page=scc-setting">Setting</a>
52
- <a class="nav-tab" href="admin.php?page=scc-help">Help</a>
53
  </h3>
54
- <div class="metabox-holder">
55
- <div id="current-parameter" class="postbox">
56
- <div class="handlediv" title="Click to toggle"><br></div>
57
- <h3 class="hndle"><span><?php _e( 'Current Setting', self::DOMAIN ) ?></span></h3>
58
- <div class="inside">
59
- <p><?php _e( 'The following describes registered parameters.', self::DOMAIN ) ?></p>
60
- <table class="view-table">
61
- <thead>
62
- <tr>
63
- <th><?php _e( 'Function', self::DOMAIN ) ?></th>
64
- <th><?php _e( 'Parameter', self::DOMAIN ) ?></th>
65
- <th><?php _e( 'Value', self::DOMAIN ) ?></th>
66
- </tr>
67
- </thead>
68
- <tbody>
69
- <tr>
70
- <td><?php _e( 'Share Base Cache', self::DOMAIN) ?></td><td><?php _e('Target SNS', self::DOMAIN ) ?></td>
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 );
90
- ?>
91
- </td>
92
- </tr>
93
- <tr>
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
- }
102
- ?>
103
- </td>
104
- </tr>
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>
140
- </tr>
141
- <tr>
142
- <td><?php _e( 'Follow Base Cache', self::DOMAIN) ?></td><td><?php _e('Target SNS', self::DOMAIN ) ?></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 );
150
- ?>
151
- </td>
152
- </tr>
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
- }
175
- ?>
176
- </td>
177
- </tr>
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;
185
- case self::OPT_COMMON_DATA_EXPORT_AUTO:
186
- _e( 'Auto', self::DOMAIN );
187
- break;
188
- }
189
- ?>
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
- }
202
- ?>
203
- </tbody>
204
- </table>
205
- </div>
206
- </div>
207
- </div>
208
 
209
  <div class="metabox-holder">
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">
@@ -222,125 +68,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
@@ -349,7 +96,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
349
  </div>
350
 
351
  <div class="metabox-holder">
352
- <div id="share-site-summary" class="postbox">
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">
@@ -357,10 +104,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
  ?>
@@ -370,72 +119,28 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
3
  admin-dashboard.php
4
 
5
  Description: Option page implementation
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
43
  <div class="wrap">
44
  <h2><a href="admin.php?page=scc-dashboard"><?php _e( 'SNS Count Cache', self::DOMAIN ) ?></a></h2>
45
  <div class="sns-cnt-cache">
46
+ <div id="scc-dashboard">
47
  <h3 class="nav-tab-wrapper">
48
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ) ?></a>
49
+ <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ) ?></a>
50
+ <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ) ?></a>
51
+ <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ) ?></a>
52
+ <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ) ?></a>
53
  </h3>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  <div class="metabox-holder">
56
+ <div id="site-summary-cache" class="site-summary postbox">
57
  <div class="handlediv" title="Click to toggle"><br></div>
58
  <h3 class="hndle"><span><?php _e( 'Cache Status', self::DOMAIN ) ?></span></h3>
59
  <div class="inside">
68
  <th><?php _e( 'State - No Cache', self::DOMAIN ) ?></th>
69
  </tr>
70
  </thead>
71
+ <tbody>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  <tr>
73
  <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
74
  <td>
75
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="pcs"></span>
 
 
 
 
 
 
 
 
76
  </td>
77
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='pc'></span></td>
78
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='pfcc'></span></td>
79
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='ppcc'></span></td>
80
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='pncc'></span></td>
81
  </tr>
82
  <tr>
83
  <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
84
  <td>
85
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="scs"></span>
 
 
 
 
 
 
 
 
86
  </td>
87
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='pc'></span></td>
88
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sfcc'></span></td>
89
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spcc'></span></td>
90
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sncc'></span></td>
91
  </tr>
92
  </tbody>
93
  </table>
96
  </div>
97
 
98
  <div class="metabox-holder">
99
+ <div id="site-summary-count" class="site-summary postbox">
100
  <div class="handlediv" title="Click to toggle"><br></div>
101
  <h3 class="hndle"><span><?php _e( 'Share Count', self::DOMAIN ) ?></span></h3>
102
  <div class="inside">
104
  <thead>
105
  <tr>
106
  <?php
107
+ $share_base_cache_target = $this->share_base_cache_target ;
108
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
109
 
110
+ foreach ( $share_base_cache_target as $sns => $active ){
111
+ if ( $active ) {
112
+ echo '<th>' . $sns . '</th>';
113
  }
114
  }
115
  ?>
119
  <tr>
120
  <?php
121
 
122
+ foreach ( $share_base_cache_target as $sns => $active ) {
123
+ if ( $active ) {
124
+ if ( $sns === self::REF_SHARE_GPLUS ){
125
+ echo '<td class="share-count">';
126
+ echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="gplus"></span>';
127
+ echo '</td>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  } else {
129
+ echo '<td class="share-count">';
130
+ echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="' . strtolower( $sns ) . '"></span>';
131
+ echo '</td>';
 
 
 
 
 
 
132
  }
133
+
134
  }
135
  }
136
+
 
 
 
 
 
 
 
 
 
 
 
 
137
  ?>
138
  </tr>
139
  </tbody>
140
  </table>
141
  </div>
142
  </div>
143
+ </div>
144
+ </div>
145
  </div>
146
  </div>
includes/admin-help.php CHANGED
@@ -3,7 +3,6 @@
3
  admin-help.php
4
 
5
  Description: Option page implementation
6
- Version: 0.4.0
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
3
  admin-help.php
4
 
5
  Description: Option page implementation
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
includes/admin-notice.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ <?php
4
+
5
+ if ( $messages = get_option( self::OPT_COMMON_ERROR_MESSAGE ) ) {
6
+ ?>
7
+ <div class="error">
8
+ <ul>
9
+ <?php
10
+ foreach( $messages as $message ) {
11
+ ?>
12
+ <li><?php echo esc_html( $message ); ?></li>
13
+ <?php
14
+ }
15
+ ?>
16
+ </ul>
17
+ </div>
18
+ <?php
19
+ delete_option( self::OPT_COMMON_ERROR_MESSAGE );
20
+ }
21
+ ?>
includes/admin-setting.php CHANGED
@@ -3,7 +3,6 @@
3
  admin-setting.php
4
 
5
  Description: Option page implementation
6
- Version: 0.4.0
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -33,40 +32,44 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
33
  if ( isset( $_POST['_wpnonce'] ) && $_POST['_wpnonce'] ) {
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"] ) {
@@ -76,11 +79,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 {
82
- $share_base_cache_target[self::REF_SHARE_FACEBOOK] = false;
83
- }
84
  } else {
85
  $share_base_cache_target[self::REF_SHARE_FACEBOOK] = false;
86
  }
@@ -92,11 +91,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 {
98
- $share_base_cache_target[self::REF_SHARE_POCKET] = false;
99
- }
100
  } else {
101
  $share_base_cache_target[self::REF_SHARE_POCKET] = false;
102
  }
@@ -108,11 +103,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
108
  }
109
 
110
  if ( ! empty( $share_base_cache_target ) ) {
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"] ) {
@@ -122,45 +117,62 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
122
  }
123
 
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();
@@ -170,10 +182,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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();
@@ -183,7 +197,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
183
 
184
  $this->cache_engines[self::REF_FOLLOW_2ND]->initialize_cache();
185
 
186
- set_time_limit( $this->original_max_execution_time );
 
 
187
  }
188
  }
189
  }
@@ -191,31 +207,49 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
191
  ?>
192
  <div class="wrap">
193
  <h2><a href="admin.php?page=scc-setting"><?php _e( 'SNS Count Cache', self::DOMAIN ) ?></a></h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  <div class="sns-cnt-cache">
195
-
196
- <h3 class="nav-tab-wrapper">
197
- <a class="nav-tab" href="admin.php?page=scc-dashboard">Dashboard</a>
198
- <a class="nav-tab" href="admin.php?page=scc-cache-status">Cache Status</a>
199
- <a class="nav-tab" href="admin.php?page=scc-share-count">Share Count</a>
200
- <a class="nav-tab nav-tab-active" href="admin.php?page=scc-setting">Setting</a>
201
- <a class="nav-tab" href="admin.php?page=scc-help">Help</a>
202
- </h3>
203
-
204
- <div class="metabox-holder">
205
- <div id="current-parameter" class="postbox">
206
- <div class="handlediv" title="Click to toggle"><br></div>
207
- <h3 class="hndle"><span><?php _e( 'Current Setting', self::DOMAIN ) ?></span></h3>
208
- <div class="inside">
209
- <p><?php _e( 'The following describes registered parameters.', self::DOMAIN ) ?></p>
210
- <table class="view-table">
211
- <thead>
212
- <tr>
213
- <th><?php _e( 'Function', self::DOMAIN ) ?></th>
214
- <th><?php _e( 'Parameter', self::DOMAIN ) ?></th>
215
- <th><?php _e( 'Value', self::DOMAIN ) ?></th>
216
- </tr>
217
- </thead>
218
- <tbody>
219
  <tr>
220
  <td><?php _e( 'Share Base Cache', self::DOMAIN) ?></td><td><?php _e('Target SNS', self::DOMAIN ) ?></td>
221
  <td>
@@ -236,7 +270,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 );
240
  ?>
241
  </td>
242
  </tr>
@@ -245,7 +279,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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,12 +289,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
@@ -268,9 +302,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
268
  <td>
269
  <?php
270
  if ( $this->scheme_migration_mode ) {
271
- echo 'On';
272
  } else {
273
- echo 'Off';
274
  }
275
  ?>
276
  </td>
@@ -281,9 +315,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
@@ -296,21 +330,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 );
300
  ?>
301
  </td>
302
  </tr>
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 );
@@ -324,8 +358,34 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
324
  }
325
  ?>
326
  </td>
327
- </tr>
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 ) {
@@ -345,443 +405,473 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
  }
352
  ?>
353
- </tbody>
354
- </table>
355
- </div>
356
- </div>
357
- </div>
358
- <div class="metabox-holder">
359
- <form action="admin.php?page=scc-setting" method="post">
360
- <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
361
- <div id="share-base-cache" class="postbox">
362
- <div class="handlediv" title="Click to toggle"><br></div>
363
- <h3 class="hndle"><span><?php _e('Share Base Cache', self::DOMAIN) ?></span></h3>
364
- <div class="inside">
365
- <table class="form-table">
366
- <tr>
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>
390
- </tr>
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>
398
- </tr>
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 ) ?>" />
426
- <input type="submit" class="button" name="clear_share_base_cache" value="<?php _e( 'Clear Cache', self::DOMAIN ) ?>">
427
- </div>
428
- </div>
429
  </div>
430
- <div id="share-rush-cache" class="postbox">
431
- <div class="handlediv" title="Click to toggle"><br></div>
432
- <h3 class="hndle"><span><?php _e('Share Rush Cache', self::DOMAIN) ?></span></h3>
433
- <div class="inside">
434
- <table class="form-table">
435
- <tr>
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>
456
- </tr>
457
- </table>
458
- <div class="submit-button">
459
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
460
- </div>
461
- </div>
462
  </div>
463
- <div id="follow-base-cache" class="postbox">
464
- <div class="handlediv" title="Click to toggle"><br></div>
465
- <h3 class="hndle"><span><?php _e('Follow Base Cache', self::DOMAIN) ?></span></h3>
466
- <div class="inside">
467
- <table class="form-table">
468
- <tr>
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>
476
- </tr>
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>
484
- </table>
485
- <div class="submit-button">
486
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
487
- <input type="submit" class="button" name="clear_follow_base_cache" value="<?php _e( 'Clear Cache', self::DOMAIN ) ?>">
488
- </div>
489
- </div>
490
- </div>
491
- <div id="common-dynamic-cache" class="postbox">
492
- <div class="handlediv" title="Click to toggle"><br></div>
493
- <h3 class="hndle"><span><?php _e( 'Dynamic Cache', self::DOMAIN ) ?></span></h3>
494
- <div class="inside">
495
- <table class="form-table">
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>
507
- </tr>
508
- </table>
509
- <div class="submit-button">
510
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
511
- </div>
512
- </div>
513
  </div>
514
- <div id="common-data-export" class="postbox">
515
- <div class="handlediv" title="Click to toggle"><br></div>
516
- <h3 class="hndle"><span><?php _e('Data Export', self::DOMAIN) ?></span></h3>
517
- <div class="inside">
518
- <table class="form-table">
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
- ?>
699
- </table>
700
- <div class="submit-button">
701
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
702
- </div>
703
- </div>
704
  </div>
705
- </form>
706
- </div>
707
- <div class="metabox-holder">
708
- <div id="exported-file" class="postbox">
709
- <div class="handlediv" title="Click to toggle"><br></div>
710
- <h3 class="hndle"><span><?php _e('Exported File', self::DOMAIN) ?></span></h3>
711
- <div class="inside">
712
- <table class="form-table">
713
- <tbody>
714
- <tr>
715
- <th><?php _e( 'Disk usage of exported file', self::DOMAIN ) ?></th>
716
- <td>
717
- <?php
718
- $abs_path = WP_PLUGIN_DIR . '/sns-count-cache/data/sns-count-cache-data.csv';
719
- $file_size = Common_Util::get_file_size( $abs_path );
 
720
 
721
- if ( isset( $file_size ) ) {
722
- echo $file_size;
723
- } else {
724
- _e('No exported file', self::DOMAIN);
725
- }
726
- ?>
727
- </td>
728
- </tr>
729
- </tbody>
730
- </table>
731
- <form action="admin.php?page=scc-setting" method="post">
732
- <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
733
- <table class="form-table">
734
- <tbody>
735
- <tr>
736
- <th><?php _e( 'Manual export', self::DOMAIN ) ?></th>
737
- <td>
738
- <input type="submit" class="button" name="export_data" value="<?php _e( 'Export', self::DOMAIN ) ?>" />
739
- <br>
740
- <span class="description">Export share count to a csv file.</span>
741
- </td>
742
- </tr>
743
- </tbody>
744
- </table>
745
- </form>
746
- <?php
747
- if ( file_exists( $abs_path ) ) {
748
- ?>
749
- <form action="admin.php?page=scc-setting" method="post">
750
- <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
751
- <table class="form-table">
752
- <tbody>
753
- <tr>
754
- <th>Reset of exported file</th>
755
- <td>
756
- <input type="submit" class="button" name="reset_data" value="<?php _e( 'Reset', self::DOMAIN ) ?>" />
757
- <br>
758
- <span class="description">Clear exported csv file.</span>
759
- </td>
760
- </tr>
761
  </tbody>
762
  </table>
763
- </form>
764
- <form action="<?php echo plugins_url(); ?>/sns-count-cache/includes/download.php" method="post">
765
- <?php wp_nonce_field( 'mynonce', '_wpnonce' ); ?>
766
- <table class="form-table">
767
- <tbody>
768
- <tr>
769
- <th>Download of exported file</th>
770
- <td>
771
- <input type="submit" class="button" name="download_data" value="<?php _e( 'Download', self::DOMAIN ) ?>" />
772
- <br>
773
- <span class="description">Download the exported csv file.</span>
774
- </td>
775
- </tr>
776
- </tbody>
777
- </table>
778
- </form>
779
- <?php
780
- }
781
- ?>
782
- </div>
783
- </div>
784
- </div>
785
-
786
- </div>
787
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  admin-setting.php
4
 
5
  Description: Option page implementation
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
32
  if ( isset( $_POST['_wpnonce'] ) && $_POST['_wpnonce'] ) {
33
  if( check_admin_referer( __FILE__, '_wpnonce' ) ) {
34
 
35
+ if( isset( $_POST["update_all_options"] ) && $_POST["update_all_options"] === __( 'Update All Options', self::DOMAIN ) ) {
36
 
37
+ $wp_error = new WP_Error();
38
+
39
+ $settings = array();
40
+
41
  $share_base_cache_target = array();
42
  $follow_base_cache_target = array();
43
 
44
  if ( isset( $_POST["share_base_custom_post_types"] ) && $_POST["share_base_custom_post_types"] ) {
45
  $share_base_custom_post_types = explode( ',', $_POST["share_base_custom_post_types"] );
46
+ $settings[self::DB_SHARE_CUSTOM_POST_TYPES] = $share_base_custom_post_types;
47
  } else {
48
+ $settings[self::DB_SHARE_CUSTOM_POST_TYPES] = array();
49
  }
50
 
51
  if ( isset( $_POST["share_base_check_interval"] ) && $_POST["share_base_check_interval"] && is_numeric( $_POST["share_base_check_interval"] ) ) {
52
+ $settings[self::DB_SHARE_CHECK_INTERVAL] = $_POST["share_base_check_interval"];
53
  }
54
 
55
  if ( isset( $_POST["share_base_posts_per_check"] ) && $_POST["share_base_posts_per_check"] && is_numeric( $_POST["share_base_posts_per_check"] ) ) {
56
+ $settings[self::DB_SHARE_POSTS_PER_CHECK] = $_POST["share_base_posts_per_check"];
57
  }
58
 
59
+ if ( isset( $_POST["dynamic_cache_mode"] ) && $_POST["dynamic_cache_mode"] ) {
60
+ $settings[self::DB_COMMON_DYNAMIC_CACHE_MODE] = $_POST["dynamic_cache_mode"];
61
  }
62
+
63
+ if ( isset( $_POST["share_rush_new_content_term"] ) && $_POST["share_rush_new_content_term"] && is_numeric( $_POST["share_rush_new_content_term"] ) ) {
64
+ $settings[self::DB_SHARE_NEW_CONTENT_TERM] = $_POST["share_rush_new_content_term"];
65
  }
66
 
67
+ if ( isset( $_POST["data_export_mode"] ) && $_POST["data_export_mode"] ) {
68
+ $settings[self::DB_COMMON_DATA_EXPORT_MODE] = $_POST["data_export_mode"];
69
  }
70
 
71
  if ( isset( $_POST["data_export_interval"] ) && $_POST["data_export_interval"] && is_numeric( $_POST["data_export_interval"] ) ) {
72
+ $settings[self::DB_COMMON_DATA_EXPORT_INTERVAL] = $_POST["data_export_interval"];
73
  }
74
 
75
  if ( isset( $_POST["share_base_cache_target_twitter"] ) && $_POST["share_base_cache_target_twitter"] ) {
79
  }
80
 
81
  if ( isset( $_POST["share_base_cache_target_facebook"] ) && $_POST["share_base_cache_target_facebook"] ) {
82
+ $share_base_cache_target[self::REF_SHARE_FACEBOOK] = true;
 
 
 
 
83
  } else {
84
  $share_base_cache_target[self::REF_SHARE_FACEBOOK] = false;
85
  }
91
  }
92
 
93
  if ( isset( $_POST["share_base_cache_target_pocket"] ) && $_POST["share_base_cache_target_pocket"] ) {
94
+ $share_base_cache_target[self::REF_SHARE_POCKET] = true;
 
 
 
 
95
  } else {
96
  $share_base_cache_target[self::REF_SHARE_POCKET] = false;
97
  }
103
  }
104
 
105
  if ( ! empty( $share_base_cache_target ) ) {
106
+ $settings[self::DB_SHARE_CACHE_TARGET] = $share_base_cache_target;
107
  }
108
 
109
  if ( isset( $_POST["follow_base_check_interval"] ) && $_POST["follow_base_check_interval"] && is_numeric( $_POST["follow_base_check_interval"] ) ) {
110
+ $settings[self::DB_FOLLOW_CHECK_INTERVAL] = $_POST["follow_base_check_interval"];
111
  }
112
 
113
  if ( isset( $_POST["follow_base_cache_target_feedly"] ) && $_POST["follow_base_cache_target_feedly"] ) {
117
  }
118
 
119
  if ( ! empty( $follow_base_cache_target ) ) {
120
+ $settings[self::DB_FOLLOW_CACHE_TARGET] = $follow_base_cache_target;
121
  }
122
 
123
  if ( isset( $_POST["scheme_migration_mode"] ) && $_POST["scheme_migration_mode"] ) {
124
+ $settings[self::DB_COMMON_SCHEME_MIGRATION_MODE] = self::OPT_COMMON_SCHEME_MIGRATION_MODE_ON;
125
  } else {
126
+ $settings[self::DB_COMMON_SCHEME_MIGRATION_MODE] = self::OPT_COMMON_SCHEME_MIGRATION_MODE_OFF;
127
  }
128
+
129
+ if ( isset( $_POST["crawler_ssl_verification"] ) && $_POST["crawler_ssl_verification"] ) {
130
+ $settings[self::DB_COMMON_CRAWLER_SSL_VERIFICATION] = self::OPT_COMMON_CRAWLER_SSL_VERIFY_ON;
131
+ } else {
132
+ $settings[self::DB_COMMON_CRAWLER_SSL_VERIFICATION] = self::OPT_COMMON_CRAWLER_SSL_VERIFY_OFF;
133
+ }
134
+
135
  if ( isset( $_POST['cronbtype'] ) && $_POST['cronbtype'] == 'mon' ) {
136
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['moncronminutes'] . ' ' . $_POST['moncronhours'] . ' ' . $_POST['moncronmday'] . ' * *';
137
  }
138
  if ( isset( $_POST['cronbtype'] ) && $_POST['cronbtype'] == 'week' ) {
139
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['weekcronminutes'] . ' ' . $_POST['weekcronhours'] . ' * * ' . $_POST['weekcronwday'];
140
  }
141
  if ( isset( $_POST['cronbtype'] ) && $_POST['cronbtype'] == 'day' ) {
142
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['daycronminutes'] . ' ' . $_POST['daycronhours'] . ' * * *';
143
  }
144
  if ( isset( $_POST['cronbtype'] ) && $_POST['cronbtype'] == 'hour' ) {
145
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['hourcronminutes'] . ' * * * *';
146
  }
147
+
148
+ update_option( self::DB_SETTINGS, $settings );
149
+
150
  $this->reactivate_plugin();
151
+
152
+ set_transient( self::OPT_COMMON_ERROR_MESSAGE, $wp_error->get_error_messages(), 10 );
153
+
154
+ //wp_safe_redirect( menu_page_url( 'scc-setting', false ) );
155
 
156
  }
157
 
158
+ if( isset( $_POST["reset_data"] ) && $_POST["reset_data"] === __( 'Reset', self::DOMAIN ) ) {
159
  Common_Util::log( '[' . __METHOD__ . '] reset' );
160
 
161
  $this->export_engines[self::REF_COMMON_EXPORT]->reset_export();
162
+
163
+ //wp_safe_redirect( menu_page_url( 'scc-setting', false ) );
164
+
165
  }
166
 
167
+ if( isset( $_POST["export_data"] ) && $_POST["export_data"] === __( 'Export', self::DOMAIN ) ) {
168
  Common_Util::log( '[' . __METHOD__ . '] export' );
169
 
170
  $this->export_engines[self::REF_COMMON_EXPORT]->execute_export( NULL );
171
+
172
+ //wp_safe_redirect( menu_page_url('scc-setting', false ) );
173
  }
174
 
175
+ if( isset( $_POST["clear_share_base_cache"] ) && $_POST["clear_share_base_cache"] === __( 'Clear Cache', self::DOMAIN ) ) {
176
  Common_Util::log( '[' . __METHOD__ . '] clear cache' );
177
 
178
  $this->cache_engines[self::REF_SHARE_BASE]->clear_cache();
182
 
183
  $this->cache_engines[self::REF_SHARE_2ND]->initialize_cache();
184
 
185
+ set_time_limit( $this->original_max_execution_time );
186
+
187
+ //wp_safe_redirect( menu_page_url('scc-setting', false ) );
188
  }
189
 
190
+ if( isset( $_POST["clear_follow_base_cache"] ) && $_POST["clear_follow_base_cache"] === __( 'Clear Cache', self::DOMAIN ) ) {
191
  Common_Util::log( '[' . __METHOD__ . '] clear cache' );
192
 
193
  $this->cache_engines[self::REF_FOLLOW_BASE]->clear_cache();
197
 
198
  $this->cache_engines[self::REF_FOLLOW_2ND]->initialize_cache();
199
 
200
+ set_time_limit( $this->original_max_execution_time );
201
+
202
+ //wp_safe_redirect( menu_page_url('scc-setting', false ) );
203
  }
204
  }
205
  }
207
  ?>
208
  <div class="wrap">
209
  <h2><a href="admin.php?page=scc-setting"><?php _e( 'SNS Count Cache', self::DOMAIN ) ?></a></h2>
210
+ <?php
211
+ if ( $messages = get_transient( self::OPT_COMMON_ERROR_MESSAGE ) ) {
212
+ ?>
213
+ <div class="error">
214
+ <ul>
215
+ <?php
216
+ foreach( $messages as $message ) {
217
+ ?>
218
+ <li><?php echo esc_html( $message ); ?></li>
219
+ <?php
220
+ }
221
+ ?>
222
+ </ul>
223
+ </div>
224
+ <?php
225
+ delete_option( self::OPT_COMMON_ERROR_MESSAGE );
226
+ }
227
+ ?>
228
  <div class="sns-cnt-cache">
229
+ <h3 class="nav-tab-wrapper">
230
+ <a class="nav-tab" href="admin.php?page=scc-dashboard">Dashboard</a>
231
+ <a class="nav-tab" href="admin.php?page=scc-cache-status">Cache Status</a>
232
+ <a class="nav-tab" href="admin.php?page=scc-share-count">Share Count</a>
233
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-setting">Setting</a>
234
+ <a class="nav-tab" href="admin.php?page=scc-help">Help</a>
235
+ </h3>
236
+ <p id="options-menu">
237
+ <a href="#current-parameter"><?php _e( 'Current Setting', self::DOMAIN ); ?></a> | <a href="#share-base-cache"><?php _e( 'Share Base Cache', self::DOMAIN ); ?></a> | <a href="#share-rush-cache"><?php _e( 'Share Rush Cache', self::DOMAIN ); ?></a> | <a href="#follow-base-cache"><?php _e( 'Follow Base Cache', self::DOMAIN ); ?></a> | <a href="#common-dynamic-cache"><?php _e( 'Dynamic Cache', self::DOMAIN ); ?></a> | <a href="#common-data-crawler"><?php _e( 'Crawler', self::DOMAIN ); ?></a> | <a href="#common-data-export"><?php _e( 'Data Export', self::DOMAIN ); ?></a> | <a href="#common-exported-file"><?php _e( 'Exported File', self::DOMAIN ); ?></a>
238
+ </p>
239
+ <div class="metabox-holder">
240
+ <div id="current-parameter" class="postbox">
241
+ <div class="handlediv" title="Click to toggle"><br></div>
242
+ <h3 class="hndle"><span><?php _e( 'Current Setting', self::DOMAIN ) ?></span></h3>
243
+ <div class="inside">
244
+ <table class="view-table">
245
+ <thead>
246
+ <tr>
247
+ <th><?php _e( 'Function', self::DOMAIN ) ?></th>
248
+ <th><?php _e( 'Parameter', self::DOMAIN ) ?></th>
249
+ <th><?php _e( 'Value', self::DOMAIN ) ?></th>
250
+ </tr>
251
+ </thead>
252
+ <tbody>
253
  <tr>
254
  <td><?php _e( 'Share Base Cache', self::DOMAIN) ?></td><td><?php _e('Target SNS', self::DOMAIN ) ?></td>
255
  <td>
270
  if ( isset( $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) && $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) {
271
  $target_sns[] = 'Hatena Bookmark';
272
  }
273
+ echo esc_html( implode( ", ", $target_sns ) );
274
  ?>
275
  </td>
276
  </tr>
279
  <td><?php _e( 'Additional custom post types', self::DOMAIN ) ?></td>
280
  <td><?php
281
  if ( ! empty( $this->share_base_custom_post_types ) && $this->share_base_custom_post_types ) {
282
+ echo esc_html( implode( ',', $this->share_base_custom_post_types ) );
283
  } else {
284
  _e( 'N/A', self::DOMAIN );
285
  }
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 esc_html( $this->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 esc_html( $this->share_base_posts_per_check ) . ' posts'; ?></td>
298
  </tr>
299
  <tr>
300
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
302
  <td>
303
  <?php
304
  if ( $this->scheme_migration_mode ) {
305
+ _e( 'On', self::DOMAIN );
306
  } else {
307
+ _e( 'Off', self::DOMAIN );
308
  }
309
  ?>
310
  </td>
315
  <td>
316
  <?php
317
  if ( $this->share_rush_new_content_term == 1 ) {
318
+ echo esc_html( $this->share_rush_new_content_term ) . ' day';
319
  } else if ( $this->share_rush_new_content_term > 1 ) {
320
+ echo esc_html( $this->share_rush_new_content_term ) . ' days';
321
  }
322
  ?>
323
  </td>
330
  if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) {
331
  $target_sns[] = 'Feedly';
332
  }
333
+ echo esc_html( implode( ", ", $target_sns ) );
334
  ?>
335
  </td>
336
  </tr>
337
  <tr>
338
  <td><?php _e( 'Follow Base Cache', self::DOMAIN ) ?></td>
339
  <td><?php _e( 'Interval cheking and caching follower count', self::DOMAIN ) ?></td>
340
+ <td><?php echo esc_html( $this->follow_base_check_interval ) . ' seconds'; ?></td>
341
  </tr>
342
  <tr>
343
  <td><?php _e( 'Dynamic Cache', self::DOMAIN) ?></td><td><?php _e( 'Dynamic caching based on user access', self::DOMAIN ) ?></td><td>
344
  <?php
345
  switch ( $this->dynamic_cache_mode ) {
346
  case self::OPT_COMMON_ACCESS_BASED_CACHE_NONE:
347
+ _e( 'disabled (None)', self::DOMAIN );
348
  break;
349
  case self::OPT_COMMON_ACCESS_BASED_SYNC_CACHE:
350
  _e( 'enabled (Synchronous Cache)', self::DOMAIN );
358
  }
359
  ?>
360
  </td>
361
+ </tr>
362
  <tr>
363
+ <td><?php _e( 'Data Crawler', self::DOMAIN) ?></td><td><?php _e( 'Crawl method', self::DOMAIN ) ?></td>
364
+ <td>
365
+ <?php
366
+ switch ( $this->crawler_method ) {
367
+ case self::OPT_COMMON_CRAWLER_METHOD_NORMAL:
368
+ _e( 'Normal (Sequential Retrieval)', self::DOMAIN );
369
+ break;
370
+ case self::OPT_COMMON_CRAWLER_METHOD_CURL:
371
+ _e( 'Extended (Parallel Retrieval)', self::DOMAIN );
372
+ break;
373
+ }
374
+ ?>
375
+ </td>
376
+ </tr>
377
+ <tr>
378
+ <td><?php _e( 'Data Crawler', self::DOMAIN) ?></td><td><?php _e( 'SSL verification', self::DOMAIN ) ?></td>
379
+ <td>
380
+ <?php
381
+ if ( $this->crawler_ssl_verification ) {
382
+ _e( 'On', self::DOMAIN );
383
+ } else {
384
+ _e( 'Off', self::DOMAIN );
385
+ }
386
+ ?>
387
+ </td>
388
+ </tr> <tr>
389
  <td><?php _e( 'Data Export', self::DOMAIN) ?></td><td><?php _e( 'Method of data export', self::DOMAIN ) ?></td><td>
390
  <?php
391
  switch ( $this->data_export_mode ) {
405
  <tr>
406
  <td><?php _e( 'Data Export', self::DOMAIN ) ?></td>
407
  <td><?php _e( 'Interval exporting share count to a csv file', self::DOMAIN ) ?></td>
408
+ <td><?php echo esc_html( $this->data_export_interval / 3600 ) . ' hours'; ?></td>
409
  </tr>
410
  <?php
411
  }
412
  ?>
413
+ </tbody>
414
+ </table>
415
+ </div>
416
+ </div>
417
+ </div>
418
+ <div class="metabox-holder">
419
+ <form action="admin.php?page=scc-setting" method="post">
420
+ <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
421
+ <div id="share-base-cache" class="postbox">
422
+ <div class="handlediv" title="Click to toggle"><br></div>
423
+ <h3 class="hndle"><span><?php _e('Share Base Cache', self::DOMAIN) ?></span></h3>
424
+ <div class="inside">
425
+ <table class="form-table">
426
+ <tr>
427
+ <th><label><?php _e( 'Target SNS', self::DOMAIN ) ?></label></th>
428
+ <td>
429
+ <div class="sns-check">
430
+ <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"'; ?> />
431
+ <label><?php _e( 'Twitter', self::DOMAIN ) ?></label>
432
+ </div>
433
+ <div class="sns-check">
434
+ <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"'; ?> />
435
+ <label><?php _e( 'Facebook', self::DOMAIN ) ?></label>
436
+ </div>
437
+ <div class="sns-check">
438
+ <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"'; ?> />
439
+ <label><?php _e( 'Google+', self::DOMAIN ) ?></label>
440
+ </div>
441
+ <div class="sns-check">
442
+ <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"'; ?> />
443
+ <label><?php _e( 'Pocket', self::DOMAIN ) ?></label>
444
+ </div>
445
+ <div class="sns-check">
446
+ <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"'; ?> />
447
+ <label><?php _e( 'Hatena Bookmark', self::DOMAIN ) ?></label>
448
+ </div>
449
+ </td>
450
+ </tr>
451
+ <tr>
452
+ <th><label><?php _e( 'Additional custom post types', self::DOMAIN ) ?></label></th>
453
+ <td>
454
+ <input type="text" class="text" name="share_base_custom_post_types" size="60" value="<?php echo esc_html( implode( ',', $this->share_base_custom_post_types ) ); ?>" />
455
+ <br>
456
+ <label><?php _e( 'e.g. aaa, bbb, ccc (comma-delimited)', self::DOMAIN ) ?></label>
457
+ </td>
458
+ </tr>
459
+ <tr>
460
+ <th><label><?php _e( 'Interval cheking and caching share count (sec)', self::DOMAIN ) ?></label></th>
461
+ <td>
462
+ <input type="text" class="text" name="share_base_check_interval" size="20" value="<?php echo esc_html( $this->share_base_check_interval ); ?>" />
463
+ <label><?php _e( 'Default: 600', self::DOMAIN ) ?></label>
464
+ </td>
465
+ </tr>
466
+ <tr>
467
+ <th><label><?php _e( 'Number of posts to check at a time (posts)', self::DOMAIN ) ?></label></th>
468
+ <td>
469
+ <input type="text" class="text" name="share_base_posts_per_check" size="20" value="<?php echo esc_html( $this->share_base_posts_per_check ); ?>" />
470
+ <label><?php _e( 'Default: 20', self::DOMAIN ) ?></label>
471
+ </td>
472
+ </tr>
473
+ <tr>
474
+ <th><label><?php _e( 'Migration mode from http to https', self::DOMAIN ) ?></label></th>
475
+ <td>
476
+ <select name="scheme_migration_mode">
477
+ <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>
478
+ <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>
479
+ </select>
480
+ <label><?php _e('Default: Off', self::DOMAIN) ?></label>
481
+ </td>
482
+ </tr>
483
+ </table>
484
+ <div class="submit-button">
485
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
486
+ <input type="submit" class="button" name="clear_share_base_cache" value="<?php _e( 'Clear Cache', self::DOMAIN ) ?>">
487
+ </div>
 
488
  </div>
489
+ </div>
490
+ <div id="share-rush-cache" class="postbox">
491
+ <div class="handlediv" title="Click to toggle"><br></div>
492
+ <h3 class="hndle"><span><?php _e('Share Rush Cache', self::DOMAIN) ?></span></h3>
493
+ <div class="inside">
494
+ <table class="form-table">
495
+ <tr>
496
+ <th><label><?php _e( 'Term considering posted content as new content', self::DOMAIN ) ?></label></th>
497
+ <td>
498
+ <select name="share_rush_new_content_term">
499
+ <option value="1"<?php if ( $this->share_rush_new_content_term == 1 ) echo ' selected="selected"'; ?>>1 day</option>
500
+ <option value="2"<?php if ( $this->share_rush_new_content_term == 2 ) echo ' selected="selected"'; ?>>2 days</option>
501
+ <option value="3"<?php if ( $this->share_rush_new_content_term == 3 ) echo ' selected="selected"'; ?>>3 days</option>
502
+ <option value="4"<?php if ( $this->share_rush_new_content_term == 4 ) echo ' selected="selected"'; ?>>4 days</option>
503
+ <option value="5"<?php if ( $this->share_rush_new_content_term == 5 ) echo ' selected="selected"'; ?>>5 days</option>
504
+ <option value="6"<?php if ( $this->share_rush_new_content_term == 6 ) echo ' selected="selected"'; ?>>6 days</option>
505
+ <option value="7"<?php if ( $this->share_rush_new_content_term == 7 ) echo ' selected="selected"'; ?>>7 days</option>
506
+ <option value="8"<?php if ( $this->share_rush_new_content_term == 8 ) echo ' selected="selected"'; ?>>8 days</option>
507
+ <option value="9"<?php if ( $this->share_rush_new_content_term == 9 ) echo ' selected="selected"'; ?>>9 days</option>
508
+ <option value="10"<?php if ( $this->share_rush_new_content_term == 10 ) echo ' selected="selected"'; ?>>10 days</option>
509
+ <option value="11"<?php if ( $this->share_rush_new_content_term == 11 ) echo ' selected="selected"'; ?>>11 days</option>
510
+ <option value="12"<?php if ( $this->share_rush_new_content_term == 12 ) echo ' selected="selected"'; ?>>12 days</option>
511
+ <option value="13"<?php if ( $this->share_rush_new_content_term == 13 ) echo ' selected="selected"'; ?>>13 days</option>
512
+ <option value="14"<?php if ( $this->share_rush_new_content_term == 14 ) echo ' selected="selected"'; ?>>14 days</option>
513
+ </select>
514
+ <label><?php _e( 'Default: 3 days', self::DOMAIN ) ?></label>
515
+ </td>
516
+ </tr>
517
+ </table>
518
+ <div class="submit-button">
519
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
520
+ </div>
521
  </div>
522
+ </div>
523
+ <div id="follow-base-cache" class="postbox">
524
+ <div class="handlediv" title="Click to toggle"><br></div>
525
+ <h3 class="hndle"><span><?php _e('Follow Base Cache', self::DOMAIN) ?></span></h3>
526
+ <div class="inside">
527
+ <table class="form-table">
528
+ <tr>
529
+ <th><label><?php _e( 'Target SNS', self::DOMAIN ) ?></label></th>
530
+ <td>
531
+ <div class="sns-check">
532
+ <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"'; ?> />
533
+ <label><?php _e( 'Feedly', self::DOMAIN ) ?></label>
534
+ </div>
535
+ </td>
536
+ </tr>
537
+ <tr>
538
+ <th><label><?php _e( 'Interval cheking and caching follower count (sec)', self::DOMAIN ) ?></label></th>
539
+ <td>
540
+ <input type="text" class="text" name="follow_base_check_interval" size="20" value="<?php echo esc_html( $this->follow_base_check_interval); ?>" />
541
+ <label><?php _e( 'Default: 1800', self::DOMAIN ) ?></label>
542
+ </td>
543
+ </tr>
544
+ </table>
545
+ <div class="submit-button">
546
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
547
+ <input type="submit" class="button" name="clear_follow_base_cache" value="<?php _e( 'Clear Cache', self::DOMAIN ) ?>">
548
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
549
  </div>
550
+ </div>
551
+ <div id="common-dynamic-cache" class="postbox">
552
+ <div class="handlediv" title="Click to toggle"><br></div>
553
+ <h3 class="hndle"><span><?php _e( 'Dynamic Cache', self::DOMAIN ) ?></span></h3>
554
+ <div class="inside">
555
+ <table class="form-table">
556
+ <tr>
557
+ <th><label><?php _e( 'Dynamic caching based on user access', self::DOMAIN ) ?></label></th>
558
+ <td>
559
+ <select name="dynamic_cache_mode">
560
+ <option value="1"<?php if ( $this->dynamic_cache_mode == self::OPT_COMMON_ACCESS_BASED_CACHE_NONE ) echo ' selected="selected"'; ?>><?php _e( 'None', self::DOMAIN ) ?></option>
561
+ <option value="2"<?php if ( $this->dynamic_cache_mode == self::OPT_COMMON_ACCESS_BASED_SYNC_CACHE ) echo ' selected="selected"'; ?>><?php _e( 'Synchronous Cache', self::DOMAIN ) ?></option>
562
+ <option value="3"<?php if ( $this->dynamic_cache_mode == self::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE ) echo ' selected="selected"'; ?>><?php _e( 'Asynchronous Cache', self::DOMAIN ) ?></option>
563
+ <option value="4"<?php if ( $this->dynamic_cache_mode == self::OPT_COMMON_ACCESS_BASED_2ND_CACHE ) echo ' selected="selected"'; ?>><?php _e( 'Asynchronous 2nd Cache', self::DOMAIN ) ?></option>
564
+ </select>
565
+ <label><?php _e('Default: Asynchronous 2nd Cache', self::DOMAIN) ?></label>
566
+ </td>
567
+ </tr>
568
+ </table>
569
+ <div class="submit-button">
570
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
571
+ </div>
572
+ </div>
573
+ </div>
574
+ <div id="common-data-crawler" class="postbox">
575
+ <div class="handlediv" title="Click to toggle"><br></div>
576
+ <h3 class="hndle"><span><?php _e('Data Crawler', self::DOMAIN) ?></span></h3>
577
+ <div class="inside">
578
+ <table class="form-table">
579
+ <tr>
580
+ <th><label><?php _e( 'Crawl method', self::DOMAIN ) ?></label></th>
581
+ <td>
582
+ <?php
583
+ switch ( $this->crawler_method ) {
584
+ case self::OPT_COMMON_CRAWLER_METHOD_NORMAL:
585
+ _e( 'Normal (Sequential Retrieval)', self::DOMAIN );
586
+ break;
587
+ case self::OPT_COMMON_CRAWLER_METHOD_CURL:
588
+ _e( 'Extended (Parallel Retrieval)', self::DOMAIN );
589
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
590
  }
591
+ ?>
592
+ </td>
593
+ </tr>
594
+ <tr>
595
+ <th><label><?php _e( 'SSL verification', self::DOMAIN ) ?></label></th>
596
+ <td>
597
+ <select name="crawler_ssl_verification">
598
+ <option value="0"<?php if ( $this->crawler_ssl_verification == self::OPT_COMMON_CRAWLER_SSL_VERIFY_OFF ) echo ' selected="selected"'; ?>><?php _e( 'Off', self::DOMAIN ) ?></option>
599
+ <option value="1"<?php if ( $this->crawler_ssl_verification == self::OPT_COMMON_CRAWLER_SSL_VERIFY_ON ) echo ' selected="selected"'; ?>><?php _e( 'On', self::DOMAIN ) ?></option>
600
+ </select>
601
+ <label><?php _e('Default: On', self::DOMAIN) ?></label>
602
+ </td>
603
+ </tr>
604
+ </table>
605
+ <div class="submit-button">
606
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
607
+ </div>
608
+ </div>
609
+ </div>
610
+ <div id="common-data-export" class="postbox">
611
+ <div class="handlediv" title="Click to toggle"><br></div>
612
+ <h3 class="hndle"><span><?php _e('Data Export', self::DOMAIN) ?></span></h3>
613
+ <div class="inside">
614
+ <table class="form-table">
615
+ <tr>
616
+ <th><label><?php _e( 'Method of data export', self::DOMAIN ) ?></label></th>
617
+ <td>
618
+ <select name="data_export_mode">
619
+ <option value="1"<?php if ( $this->data_export_mode == self::OPT_COMMON_DATA_EXPORT_MANUAL ) echo ' selected="selected"'; ?>><?php _e( 'Manual', self::DOMAIN ) ?></option>
620
+ <option value="2"<?php if ( $this->data_export_mode == self::OPT_COMMON_DATA_EXPORT_AUTO ) echo ' selected="selected"'; ?> disabled="disabled"><?php _e( 'Auto', self::DOMAIN ) ?></option>
621
+ </select>
622
+ <label><?php _e('Default: Manual', self::DOMAIN) ?></label>
623
+ </td>
624
+ </tr>
625
+ <?php
626
+ if ( $this->data_export_mode == self::OPT_COMMON_DATA_EXPORT_AUTO ) {
627
+ ?>
628
+ <tr>
629
+ <th><label><?php _e( 'Interval exporting share count to a csv file', self::DOMAIN ) ?></label></th>
630
+ <td>
631
+ <select name="data_export_interval">
632
+ <option value="600"<?php if ( $this->data_export_interval == 600 ) echo ' selected="selected"'; ?>>10 minites</option>
633
+ <option value="10800"<?php if ( $this->data_export_interval == 10800 ) echo ' selected="selected"'; ?>>3 hours</option>
634
+ <option value="21600"<?php if ( $this->data_export_interval == 21600 ) echo ' selected="selected"'; ?>>6 hours</option>
635
+ <option value="43200"<?php if ( $this->data_export_interval == 43200 ) echo ' selected="selected"'; ?>>12 hours</option>
636
+ <option value="86400"<?php if ( $this->data_export_interval == 86400 ) echo ' selected="selected"'; ?>>24 hours</option>
637
+ </select>
638
+ <label><?php _e( 'Default: 12 hours', self::DOMAIN ) ?></label>
639
+ </td>
640
+ </tr>
641
+ <?php
642
+ list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ', $this->data_export_schedule, 5 );
643
+ if ( strstr( $cronstr[ 'minutes' ], '*/' ) ) {
644
+ $minutes = explode( '/', $cronstr[ 'minutes' ] );
645
+ } else {
646
+ $minutes = explode( ',', $cronstr[ 'minutes' ] );
647
+ }
648
+ if ( strstr( $cronstr[ 'hours' ], '*/' ) ) {
649
+ $hours = explode( '/', $cronstr[ 'hours' ] );
650
+ } else {
651
+ $hours = explode( ',', $cronstr[ 'hours' ] );
652
+ }
653
+ if ( strstr( $cronstr[ 'mday' ], '*/' ) ) {
654
+ $mday = explode( '/', $cronstr[ 'mday' ] );
655
+ } else {
656
+ $mday = explode( ',', $cronstr[ 'mday' ] );
657
+ }
658
+ if ( strstr( $cronstr[ 'mon' ], '*/' ) ) {
659
+ $mon = explode( '/', $cronstr[ 'mon' ] );
660
+ } else {
661
+ $mon = explode( ',', $cronstr[ 'mon' ] );
662
+ }
663
+ if ( strstr( $cronstr[ 'wday' ], '*/' ) ) {
664
+ $wday = explode( '/', $cronstr[ 'wday' ] );
665
+ } else {
666
+ $wday = explode( ',', $cronstr[ 'wday' ] );
667
+ }
668
+ ?>
669
+ <tr class="wpcronbasic">
670
+ <th scope="row"><?php _e( 'Scheduler', self::DOMAIN ); ?></th>
671
+ <td>
672
+ <table id="wpcronbasic">
673
+ <tr>
674
+ <th>
675
+ <?php _e( 'Type', self::DOMAIN ); ?>
676
+ </th>
677
+ <th>
678
+ </th>
679
+ <th>
680
+ <?php _e( 'Hour', self::DOMAIN ); ?>
681
+ </th>
682
+ <th>
683
+ <?php _e( 'Minute', self::DOMAIN ); ?>
684
+ </th>
685
+ </tr>
686
+ <tr>
687
+ <td>
688
+ <label for="idcronbtype-mon">
689
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $mday[ 0 ] ), FALSE ) . ' name="cronbtype" id="idcronbtype-mon" value="mon" /> ' . __( 'monthly', self::DOMAIN ); ?>
690
+ </label>
691
+ </td>
692
+ <td>
693
+ <select name="moncronmday">
694
+ <?php for ( $i = 1; $i <= 31; $i ++ ) {
695
  echo '<option ' . selected( in_array( "$i", $mday, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . __( 'on', self::DOMAIN ) . ' ' . $i . '.</option>';
696
+ } ?>
697
+ </select>
698
+ </td>
699
+ <td>
700
+ <select name="moncronhours">
701
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
702
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
703
+ } ?>
704
+ </select>
705
+ </td>
706
+ <td>
707
+ <select name="moncronminutes">
708
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
709
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
710
+ } ?>
711
+ </select>
712
+ </td>
713
+ </tr>
714
+ <tr>
715
+ <td>
716
+ <label for="idcronbtype-week">
717
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $wday[ 0 ] ), FALSE ) . ' name="cronbtype" id="idcronbtype-week" value="week" /> ' . __( 'weekly', self::DOMAIN ); ?>
718
+ </label>
719
+ </td>
720
+ <td>
721
+ <select name="weekcronwday">
722
+ <?php echo '<option ' . selected( in_array( "0", $wday, TRUE ), TRUE, FALSE ) . ' value="0" />' . __( 'Sunday', self::DOMAIN ) . '</option>';
723
  echo '<option ' . selected( in_array( "1", $wday, TRUE ), TRUE, FALSE ) . ' value="1" />' . __( 'Monday', self::DOMAIN ) . '</option>';
724
  echo '<option ' . selected( in_array( "2", $wday, TRUE ), TRUE, FALSE ) . ' value="2" />' . __( 'Tuesday', self::DOMAIN ) . '</option>';
725
  echo '<option ' . selected( in_array( "3", $wday, TRUE ), TRUE, FALSE ) . ' value="3" />' . __( 'Wednesday', self::DOMAIN ) . '</option>';
726
  echo '<option ' . selected( in_array( "4", $wday, TRUE ), TRUE, FALSE ) . ' value="4" />' . __( 'Thursday', self::DOMAIN ) . '</option>';
727
  echo '<option ' . selected( in_array( "5", $wday, TRUE ), TRUE, FALSE ) . ' value="5" />' . __( 'Friday', self::DOMAIN ) . '</option>';
728
  echo '<option ' . selected( in_array( "6", $wday, TRUE ), TRUE, FALSE ) . ' value="6" />' . __( 'Saturday', self::DOMAIN ) . '</option>'; ?>
729
+ </select>
730
+ </td>
731
+ <td>
732
+ <select name="weekcronhours">
733
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
734
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
735
+ } ?>
736
+ </select>
737
+ </td>
738
+ <td>
739
+ <select name="weekcronminutes">
740
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
741
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
742
+ } ?></select>
743
+ </td>
744
+ </tr>
745
+ <tr>
746
+ <td>
747
+ <label for="idcronbtype-day">
748
+ <?php echo '<input class="radio" type="radio"' . checked( "**", $mday[ 0 ] . $wday[ 0 ], FALSE ) . ' name="cronbtype" id="idcronbtype-day" value="day" /> ' . __( 'daily', self::DOMAIN ); ?>
749
+ </label>
750
+ </td>
751
+ <td>
752
+ </td>
753
+ <td>
754
+ <select name="daycronhours">
755
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
756
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
757
+ } ?>
758
+ </select>
759
+ </td>
760
+ <td>
761
+ <select name="daycronminutes">
762
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
763
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
764
+ } ?>
765
+ </select>
766
+ </td>
767
+ </tr>
768
+ <tr>
769
+ <td>
770
+ <label for="idcronbtype-hour">
771
+ <?php echo '<input class="radio" type="radio"' . checked( "*", $hours[ 0 ], FALSE, FALSE ) . ' name="cronbtype" id="idcronbtype-hour" value="hour" /> ' . __( 'hourly', self::DOMAIN ); ?>
772
+ </label>
773
+ </td>
774
+ <td></td>
775
+ <td></td>
776
+ <td>
777
+ <select name="hourcronminutes">
778
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
779
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
780
+ } ?>
781
+ </select>
782
+ </td>
783
+ </tr>
784
+ </table>
785
+ </td>
786
+ </tr>
787
+ <?php
788
+ }
789
+ ?>
790
+ </table>
791
+ <div class="submit-button">
792
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
793
+ </div>
 
 
794
  </div>
795
+ </div>
796
+ </form>
797
+ </div>
798
+ <div class="metabox-holder">
799
+ <div id="common-exported-file" class="postbox">
800
+ <div class="handlediv" title="Click to toggle"><br></div>
801
+ <h3 class="hndle"><span><?php _e('Exported File', self::DOMAIN) ?></span></h3>
802
+ <div class="inside">
803
+ <table class="form-table">
804
+ <tbody>
805
+ <tr>
806
+ <th><?php _e( 'Disk usage of exported file', self::DOMAIN ) ?></th>
807
+ <td>
808
+ <?php
809
+ $abs_path = WP_PLUGIN_DIR . '/sns-count-cache/data/sns-count-cache-data.csv';
810
+ $file_size = Common_Util::get_file_size( $abs_path );
811
 
812
+ if ( isset( $file_size ) ) {
813
+ echo $file_size;
814
+ } else {
815
+ _e('No exported file', self::DOMAIN);
816
+ }
817
+ ?>
818
+ </td>
819
+ </tr>
820
+ </tbody>
821
+ </table>
822
+ <form action="admin.php?page=scc-setting" method="post">
823
+ <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
824
+ <table class="form-table">
825
+ <tbody>
826
+ <tr>
827
+ <th><?php _e( 'Manual export', self::DOMAIN ) ?></th>
828
+ <td>
829
+ <input type="submit" class="button" name="export_data" value="<?php _e( 'Export', self::DOMAIN ) ?>" />
830
+ <br>
831
+ <span class="description">Export share count to a csv file.</span>
832
+ </td>
833
+ </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
834
  </tbody>
835
  </table>
836
+ </form>
837
+ <?php
838
+ if ( file_exists( $abs_path ) ) {
839
+ ?>
840
+ <form action="admin.php?page=scc-setting" method="post">
841
+ <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
842
+ <table class="form-table">
843
+ <tbody>
844
+ <tr>
845
+ <th>Reset of exported file</th>
846
+ <td>
847
+ <input type="submit" class="button" name="reset_data" value="<?php _e( 'Reset', self::DOMAIN ) ?>" />
848
+ <br>
849
+ <span class="description">Clear exported csv file.</span>
850
+ </td>
851
+ </tr>
852
+ </tbody>
853
+ </table>
854
+ </form>
855
+ <form action="<?php echo plugins_url(); ?>/sns-count-cache/includes/download.php" method="post">
856
+ <?php wp_nonce_field( 'mynonce', '_wpnonce' ); ?>
857
+ <table class="form-table">
858
+ <tbody>
859
+ <tr>
860
+ <th>Download of exported file</th>
861
+ <td>
862
+ <input type="submit" class="button" name="download_data" value="<?php _e( 'Download', self::DOMAIN ) ?>" />
863
+ <br>
864
+ <span class="description">Download the exported csv file.</span>
865
+ </td>
866
+ </tr>
867
+ </tbody>
868
+ </table>
869
+ </form>
870
+ <?php
871
+ }
872
+ ?>
873
+ </div>
874
+ </div>
875
+ </div>
876
+ </div>
877
+ </div>
includes/admin-share-count.php CHANGED
@@ -3,7 +3,6 @@
3
  admin-share-count.php
4
 
5
  Description: Option page implementation
6
- Version: 0.4.0
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -34,44 +33,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
34
 
35
  $sort_mode = false;
36
  $sort_exec_key = '';
37
- /*
38
- if ( isset( $_GET['_wpnonce'] ) && $_GET['_wpnonce'] ) {
39
- $nonce = $_GET['_wpnonce'];
40
-
41
- if ( wp_verify_nonce( $nonce, __FILE__ ) ) {
42
- if( isset( $_GET["action"] ) && $_GET["action"] === 'sort' ) {
43
-
44
- if( isset( $_GET["key"] ) ) {
45
- $sort_mode = true;
46
- $key = $_GET["key"];
47
-
48
- if ( $key === 'Google' ) {
49
- $key = $key . '+';
50
- }
51
-
52
- $sort_exec_key = $key;
53
- $meta_key = self::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( $key );
54
- }
55
-
56
- }
57
- }
58
- }
59
- */
60
 
61
  if( isset( $_GET["action"] ) && $_GET["action"] === 'sort' ) {
62
-
63
- if( isset( $_GET["key"] ) ) {
64
- $sort_mode = true;
65
- $key = $_GET["key"];
 
66
 
67
- if ( $key === 'Google' ) {
68
- $key = $key . '+';
69
- }
70
 
71
- $sort_exec_key = $key;
72
- $meta_key = self::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( $key );
 
 
73
  }
74
-
75
  }
76
 
77
  $paged = 1;
@@ -87,197 +66,206 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
87
 
88
  ?>
89
  <div class="wrap">
90
- <h2><a href="admin.php?page=scc-share-count"><?php _e( 'SNS Count Cache', self::DOMAIN ) ?></a></h2>
91
- <div class="sns-cnt-cache">
92
- <h3 class="nav-tab-wrapper">
93
- <a class="nav-tab" href="admin.php?page=scc-dashboard">Dashboard</a>
94
- <a class="nav-tab" href="admin.php?page=scc-cache-status">Cache Status</a>
95
- <a class="nav-tab nav-tab-active" href="admin.php?page=scc-share-count">Share Count</a>
96
- <a class="nav-tab" href="admin.php?page=scc-setting">Setting</a>
97
- <a class="nav-tab" href="admin.php?page=scc-help">Help</a>
98
- </h3>
99
-
100
- <div class="metabox-holder">
101
- <div id="share-each-content" class="postbox">
102
- <div class="handlediv" title="Click to toggle"><br></div>
103
- <h3 class="hndle"><span><?php _e( 'Share Count', self::DOMAIN ) ?></span></h3>
104
- <div class="inside">
105
-
106
-
107
- <table class="view-table">
108
- <thead>
109
- <tr>
110
- <th>No.</th>
111
- <th><?php _e( 'Content', self::DOMAIN ) ?></th>
112
- <?php
113
 
114
- foreach ( $share_base_cache_target as $key => $value ){
115
 
116
- if ( $value ) {
117
 
118
- $nonce = wp_create_nonce( __FILE__ );
119
-
120
- $sort_key = $key;
121
 
122
- if ( $sort_key === self::REF_SHARE_GPLUS ) {
123
- $sort_key = str_replace( '+', '', $sort_key );
124
- }
125
 
126
- //$sort_url = esc_url( 'admin.php?page=scc-share-count&_wpnonce=' . $nonce . '&action=sort&key=' . $sort_key );
127
- $sort_url = esc_url( 'admin.php?page=scc-share-count&action=sort&key=' . $sort_key );
128
 
129
- if ( $key === $sort_exec_key ){
130
- echo '<th><a class="sort-exec-key" href="' . $sort_url . '">' . $key . '</th>';
131
- } else {
132
- echo '<th><a href="' . $sort_url . '">' . $key . '</th>';
133
- }
134
- }
135
-
136
- }
 
 
 
137
 
138
- /*
139
- if ( function_exists( 'wpp_get_views' ) ) {
140
- echo '<th>Views</th>';
141
- }
142
- */
143
 
144
- ?>
145
- </tr>
146
- </thead>
147
- <tbody>
 
 
 
 
 
 
 
 
 
148
 
149
- <?php
 
 
 
 
 
 
 
150
 
151
- if( $sort_mode ) {
152
- $query_args = array(
153
- 'post_type' => $this->share_base_cache_post_types,
154
- 'post_status' => 'publish',
155
- 'posts_per_page' => $posts_per_page,
156
- 'paged' => $paged,
157
- 'meta_key' => $meta_key,
158
- 'orderby' => 'meta_value_num',
159
- 'update_post_term_cache' => false,
160
- 'order' => 'DESC'
161
- );
162
-
163
- } else {
164
 
165
- $query_args = array(
166
- 'post_type' => $this->share_base_cache_post_types,
167
- 'post_status' => 'publish',
168
- 'posts_per_page' => $posts_per_page,
169
- 'paged' => $paged,
170
- 'update_post_term_cache' => false
171
- );
172
- }
173
 
174
- $posts_query = new WP_Query( $query_args );
 
175
 
176
- $count = ($paged - 1) * $posts_per_page + 1;
 
 
 
 
 
 
177
 
178
- if ( $posts_query->have_posts() ) {
179
- while ( $posts_query->have_posts() ) {
180
- $posts_query->the_post();
181
- ?>
182
- <tr>
183
- <td><?php echo $count; ?></td>
184
- <td><a href="<?php echo esc_url( get_permalink( get_the_ID() ) ); ?>" target="_blank"><?php echo esc_html( get_the_title( get_the_ID() ) ); ?></a></td>
185
- <?php
186
- $transient_id = self::OPT_SHARE_BASE_TRANSIENT_PREFIX . get_the_ID();
187
-
188
- if ( $sort_mode || false === ( $sns_counts = get_transient( $transient_id ) ) ) {
189
-
190
- foreach ( $share_base_cache_target as $key => $value ) {
191
- if( $value ){
192
- /**
193
- echo '<td class="not-cached share-count">';
194
- _e( 'N/A', self::DOMAIN );
195
- echo '</td>';
196
- */
197
-
198
- $meta_key = self::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( $key );
199
- $sns_counts[$key] = get_post_meta( get_the_ID(), $meta_key, true );
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">';
207
- _e( 'N/A', self::DOMAIN );
208
- echo '</td>';
209
- }
210
- }
211
- }
212
-
213
- /*
214
- // WordPress Popular Posts
215
- if ( function_exists( 'wpp_get_views' ) ) {
216
- $views = wpp_get_views( get_the_ID(), 'all', true);
217
-
218
- if ( $views >= 0 ) {
219
- echo '<td class="share-count">';
220
- echo $views;
221
- echo '</td>';
222
  } else {
223
- echo '<td class="not-cached share-count">';
224
- _e( 'N/A', self::DOMAIN );
225
- echo '</td>';
226
- }
227
- }
228
- */
229
- } else {
230
 
231
- foreach ( $share_base_cache_target as $key => $value ) {
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">';
239
- _e( 'N/A', self::DOMAIN );
240
- echo '</td>';
241
- }
242
- }
243
- }
244
- /*
245
- // WordPress Popular Posts
246
- if ( function_exists( 'wpp_get_views' ) ) {
247
- $views = wpp_get_views( get_the_ID(), 'all', true );
248
-
249
- if ( $views >= 0 ) {
250
- echo '<td class="share-count">';
251
- echo $views;
252
- echo '</td>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  } else {
254
- echo '<td class="not-cached share-count">';
255
- _e( 'N/A', self::DOMAIN );
256
- echo '</td>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  }
 
 
 
 
 
 
258
  }
259
- */
260
-
261
  }
262
  ?>
263
- </tr>
264
-
265
- <?php
266
- $count++;
267
-
268
- }
269
- }
270
- ?>
271
- </tbody>
272
- </table>
273
  <?php
274
- $this->pagination( $posts_query->max_num_pages, '', $paged, true );
275
-
276
- wp_reset_postdata();
277
  ?>
278
 
279
- </div>
280
- </div>
281
- </div>
282
  </div>
283
  </div>
3
  admin-share-count.php
4
 
5
  Description: Option page implementation
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
33
 
34
  $sort_mode = false;
35
  $sort_exec_key = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  if( isset( $_GET["action"] ) && $_GET["action"] === 'sort' ) {
38
+
39
+ if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
40
+ if( isset( $_GET["key"] ) ) {
41
+ $sort_mode = true;
42
+ $sns = $_GET["key"];
43
 
44
+ if ( $sns === 'Google' ) {
45
+ $sns = $sns . '+';
46
+ }
47
 
48
+ $sort_exec_key = $sns;
49
+
50
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
51
+ }
52
  }
53
+
54
  }
55
 
56
  $paged = 1;
66
 
67
  ?>
68
  <div class="wrap">
69
+ <h2><a href="admin.php?page=scc-share-count"><?php _e( 'SNS Count Cache', self::DOMAIN ) ?></a></h2>
70
+ <div class="sns-cnt-cache">
71
+ <h3 class="nav-tab-wrapper">
72
+ <a class="nav-tab" href="admin.php?page=scc-dashboard">Dashboard</a>
73
+ <a class="nav-tab" href="admin.php?page=scc-cache-status">Cache Status</a>
74
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-share-count">Share Count</a>
75
+ <a class="nav-tab" href="admin.php?page=scc-setting">Setting</a>
76
+ <a class="nav-tab" href="admin.php?page=scc-help">Help</a>
77
+ </h3>
78
+ <div class="metabox-holder">
79
+ <div id="share-each-content" class="postbox">
80
+ <div class="handlediv" title="Click to toggle"><br></div>
81
+ <h3 class="hndle"><span><?php _e( 'Share Count', self::DOMAIN ) ?></span></h3>
82
+ <div class="inside">
83
+ <table class="view-table">
84
+ <thead>
85
+ <tr>
86
+ <th>No.</th>
87
+ <th><?php _e( 'Content', self::DOMAIN ) ?></th>
88
+ <?php
 
 
 
89
 
90
+ foreach ( $share_base_cache_target as $sns => $active ){
91
 
92
+ if ( $active ) {
93
 
94
+ $sort_key = $sns;
 
 
95
 
96
+ if ( $sort_key === self::REF_SHARE_GPLUS ) {
97
+ $sort_key = str_replace( '+', '', $sort_key );
98
+ }
99
 
100
+ $sort_url = esc_url( 'admin.php?page=scc-share-count&action=sort&key=' . $sort_key );
 
101
 
102
+ if ( $sns === $sort_exec_key ){
103
+ echo '<th><a class="sort-exec-key" href="' . $sort_url . '">' . esc_html( $sns ) . '</th>';
104
+ } else {
105
+ echo '<th><a href="' . $sort_url . '">' . esc_html( $sns ) . '</th>';
106
+ }
107
+ }
108
+ }
109
+ ?>
110
+ </tr>
111
+ </thead>
112
+ <tbody>
113
 
114
+ <?php
 
 
 
 
115
 
116
+ if( $sort_mode ) {
117
+ $query_args = array(
118
+ 'post_type' => $this->share_base_cache_post_types,
119
+ 'post_status' => 'publish',
120
+ 'posts_per_page' => $posts_per_page,
121
+ 'paged' => $paged,
122
+ 'meta_key' => $meta_key,
123
+ 'orderby' => 'meta_value_num',
124
+ 'update_post_term_cache' => false,
125
+ 'order' => 'DESC'
126
+ );
127
+
128
+ } else {
129
 
130
+ $query_args = array(
131
+ 'post_type' => $this->share_base_cache_post_types,
132
+ 'post_status' => 'publish',
133
+ 'posts_per_page' => $posts_per_page,
134
+ 'paged' => $paged,
135
+ 'update_post_term_cache' => false
136
+ );
137
+ }
138
 
139
+ $posts_query = new WP_Query( $query_args );
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
+ $count = ( $paged - 1 ) * $posts_per_page + 1;
 
 
 
 
 
 
 
142
 
143
+ if ( $paged === 1 ) {
144
+ ?>
145
 
146
+ <tr class="home">
147
+ <td><?php echo '-'; ?></td>
148
+ <td><a href="<?php echo esc_url( home_url( '/' ) ); ?>" target="_blank"><?php echo esc_html( bloginfo('name') ); ?></a></td>
149
+ <?php
150
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
151
+
152
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
153
 
154
+ foreach ( $share_base_cache_target as $sns => $active ) {
155
+ if ( $active ) {
156
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
157
+ echo '<td class="share-count">';
158
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
159
+ echo '</td>';
160
+ } else {
161
+ echo '<td class="not-cached share-count">';
162
+ _e( 'N/A', self::DOMAIN );
163
+ echo '</td>';
164
+ }
165
+ }
166
+ }
167
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  } else {
 
 
 
 
 
 
 
169
 
170
+ $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
171
+
172
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
173
+
174
+ foreach ( $share_base_cache_target as $sns => $active ) {
175
+ if( $active ){
176
+
177
+ if ( $sns_counts[$sns] >= 0 ) {
178
+ echo '<td class="share-count">';
179
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
180
+ echo '</td>';
181
+ } else {
182
+ echo '<td class="not-cached share-count">';
183
+ _e( 'N/A', self::DOMAIN );
184
+ echo '</td>';
185
+ }
186
+ }
187
+ }
188
  } else {
189
+ foreach ( $share_base_cache_target as $sns => $active ) {
190
+ if( $active ){
191
+ echo '<td class="not-cached share-count">';
192
+ _e( 'N/A', self::DOMAIN );
193
+ echo '</td>';
194
+ }
195
+ }
196
+ }
197
+
198
+ }
199
+ ?>
200
+ </tr>
201
+ <?php
202
+ }
203
+
204
+ if ( $posts_query->have_posts() ) {
205
+ while ( $posts_query->have_posts() ) {
206
+ $posts_query->the_post();
207
+ ?>
208
+ <tr>
209
+ <td><?php echo $count; ?></td>
210
+ <td><a href="<?php echo esc_url( get_permalink( get_the_ID() ) ); ?>" target="_blank"><?php echo esc_html( get_the_title( get_the_ID() ) ); ?></a></td>
211
+ <?php
212
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( get_the_ID() );
213
+
214
+ if( ! $sort_mode && false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
215
+
216
+ foreach ( $share_base_cache_target as $sns => $active ) {
217
+ if ( $active ) {
218
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
219
+ echo '<td class="share-count">';
220
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
221
+ echo '</td>';
222
+ } else {
223
+ echo '<td class="not-cached share-count">';
224
+ _e( 'N/A', self::DOMAIN );
225
+ echo '</td>';
226
+ }
227
+ }
228
+ }
229
+
230
  } else {
231
+
232
+ foreach ( $share_base_cache_target as $sns => $active ) {
233
+ if( $active ){
234
+
235
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
236
+
237
+ $sns_counts[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
238
+
239
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 ) {
240
+ echo '<td class="share-count">';
241
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
242
+ echo '</td>';
243
+ } else {
244
+ echo '<td class="not-cached share-count">';
245
+ _e( 'N/A', self::DOMAIN );
246
+ echo '</td>';
247
+ }
248
+ }
249
+ }
250
  }
251
+
252
+ ?>
253
+ </tr>
254
+ <?php
255
+ ++$count;
256
+
257
  }
 
 
258
  }
259
  ?>
260
+ </tbody>
261
+ </table>
 
 
 
 
 
 
 
 
262
  <?php
263
+ $this->pagination( $posts_query->max_num_pages, '', $paged, true );
264
+ wp_reset_postdata();
 
265
  ?>
266
 
267
+ </div>
268
+ </div>
269
+ </div>
270
  </div>
271
  </div>
includes/class-cache-engine.php CHANGED
@@ -3,7 +3,6 @@
3
  class-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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -36,22 +35,13 @@ abstract class Cache_Engine extends Engine {
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.
49
- *
50
- */
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
  *
@@ -64,7 +54,7 @@ abstract class Cache_Engine extends Engine {
64
  *
65
  * @since 0.1.1
66
  */
67
- abstract public function cache( $post_ID, $target_sns, $cache_expiration );
68
 
69
  /**
70
  * Initialize cache
@@ -81,14 +71,25 @@ abstract class Cache_Engine extends Engine {
81
  abstract public function clear_cache();
82
 
83
  /**
84
- * Get share transient ID
85
  *
86
- * @since 0.1.1
87
  */
88
- protected function get_transient_ID( $suffix ) {
89
- return $this->transient_prefix . $suffix;
90
- }
91
-
 
 
 
 
 
 
 
 
 
 
 
92
  }
93
 
94
- ?>
3
  class-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
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
35
  /**
36
  * Prefix of cache ID
37
  */
38
+ protected $cache_prefix = NULL;
39
 
40
  /**
41
  * instance for delegation
42
  */
43
  protected $delegate = NULL;
44
+
 
 
 
 
 
 
 
 
 
45
  /**
46
  * Get cache expiration based on current number of total post and page
47
  *
54
  *
55
  * @since 0.1.1
56
  */
57
+ abstract public function cache( $options = array() );
58
 
59
  /**
60
  * Initialize cache
71
  abstract public function clear_cache();
72
 
73
  /**
74
+ * Get cache key
75
  *
76
+ * @since 0.6.0
77
  */
78
+ public function get_cache_key( $suffix ) {
79
+ return $this->cache_prefix . strtolower( $suffix );
80
+ }
81
+
82
+ /**
83
+ * Order cache
84
+ *
85
+ * @since 0.5.1
86
+ */
87
+ protected function delegate_cache( $options = array() ) {
88
+ if ( ! is_null( $this->delegate ) && method_exists( $this->delegate, 'order_cache' ) ) {
89
+ $this->delegate->order_cache( $this, $options );
90
+ }
91
+ }
92
+
93
  }
94
 
95
+ ?>
includes/class-common-data-export-engine.php CHANGED
@@ -3,7 +3,6 @@
3
  class-common-data-export.php
4
 
5
  Description: This class is a data export engine whitch exports cached 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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -102,16 +101,7 @@ class Common_Data_Export_Engine extends Export_Engine {
102
  * Cache target of follow count
103
  */
104
  private $follow_target_sns = array();
105
-
106
- /**
107
- * Class constarctor
108
- * Hook onto all of the actions and filters needed by the plugin.
109
- *
110
- */
111
- protected function __construct() {
112
- Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
113
- }
114
-
115
  /**
116
  * Initialization
117
  *
@@ -120,8 +110,8 @@ class Common_Data_Export_Engine extends Export_Engine {
120
  public function initialize( $options = array() ) {
121
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
122
 
123
- $this->share_meta_key_prefix = self::DEF_SHARE_META_KEY_PREFIX;
124
- $this->follow_meta_key_prefix = self::DEF_FOLLOW_META_KEY_PREFIX;
125
  $this->prime_cron = self::DEF_PRIME_CRON;
126
  $this->execute_cron = self::DEF_EXECUTE_CRON;
127
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
@@ -137,8 +127,8 @@ class Common_Data_Export_Engine extends Export_Engine {
137
  if ( isset( $options['export_exclude_keys'] ) ) $this->export_exclude_keys = $options['export_exclude_keys'];
138
  if ( isset( $options['export_file_name'] ) ) $this->export_file_name = $options['export_file_name'];
139
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
140
- if ( isset( $options['share_meta_key_prefix'] ) ) $this->share_meta_key_prefix = $options['share_meta_key_prefix'];
141
- if ( isset( $options['follow_meta_key_prefix'] ) ) $this->follow_meta_key_prefix = $options['follow_meta_key_prefix'];
142
  if ( isset( $options['share_target_sns'] ) ) $this->share_target_sns = $options['share_target_sns'];
143
  if ( isset( $options['follow_target_sns'] ) ) $this->follow_target_sns = $options['follow_target_sns'];
144
 
@@ -242,7 +232,32 @@ class Common_Data_Export_Engine extends Export_Engine {
242
  Common_Util::log( '[' . __METHOD__ . '] file exists: ' . $abs_path );
243
 
244
  $fp = fopen( $abs_path, 'a' );
245
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  $query_args = array(
247
  'post_type' => $this->post_types,
248
  'post_status' => 'publish',
@@ -252,7 +267,7 @@ class Common_Data_Export_Engine extends Export_Engine {
252
  );
253
 
254
  $posts_query = new WP_Query( $query_args );
255
-
256
  if ( $posts_query->have_posts() ) {
257
  while ( $posts_query->have_posts() ) {
258
  $posts_query->the_post();
@@ -261,21 +276,21 @@ class Common_Data_Export_Engine extends Export_Engine {
261
 
262
  $content = '"' . $current_date . '","' . $post_ID . '","' . get_post_type( $post_ID ) . '","' . get_the_title( $post_ID ) . '","' . get_permalink( $post_ID ) . '","' . get_post_time( 'Y/m/d H:i', false, $post_ID );
263
 
264
- foreach ( $this->share_target_sns as $key => $value ) {
265
 
266
- if ( ! in_array( $key, $this->export_exclude_keys ) ) {
267
 
268
- $meta_key = $this->share_meta_key_prefix . strtolower( $key );
269
 
270
- if ( $value ) {
271
 
272
  $data_value = get_post_meta( $post_ID, $meta_key, true );
273
 
274
- if ( $data_value == -1 ){
275
  $data_value = '';
276
  }
277
 
278
- $data = $content . '","' . $key . '","' . 'Share' . '","' . $data_value . '",' . "\r\n";
279
  }
280
  if ( fwrite( $fp, mb_convert_encoding( $data, "SJIS", "UTF-8" ) ) ) {
281
  Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' . $data );
@@ -287,7 +302,7 @@ class Common_Data_Export_Engine extends Export_Engine {
287
 
288
  /*
289
  foreach ( $this->follow_target_sns as $key => $value ) {
290
- $meta_key = $this->follow_meta_key_prefix . strtolower( $key );
291
 
292
  if ( $value ) {
293
 
3
  class-common-data-export.php
4
 
5
  Description: This class is a data export engine whitch exports cached data using wp-cron at regular intervals
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
101
  * Cache target of follow count
102
  */
103
  private $follow_target_sns = array();
104
+
 
 
 
 
 
 
 
 
 
105
  /**
106
  * Initialization
107
  *
110
  public function initialize( $options = array() ) {
111
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
112
 
113
+ $this->share_cache_key_prefix = self::DEF_SHARE_META_KEY_PREFIX;
114
+ $this->follow_cache_key_prefix = self::DEF_FOLLOW_META_KEY_PREFIX;
115
  $this->prime_cron = self::DEF_PRIME_CRON;
116
  $this->execute_cron = self::DEF_EXECUTE_CRON;
117
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
127
  if ( isset( $options['export_exclude_keys'] ) ) $this->export_exclude_keys = $options['export_exclude_keys'];
128
  if ( isset( $options['export_file_name'] ) ) $this->export_file_name = $options['export_file_name'];
129
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
130
+ if ( isset( $options['share_cache_key_prefix'] ) ) $this->share_cache_key_prefix = $options['share_cache_key_prefix'];
131
+ if ( isset( $options['follow_cache_key_prefix'] ) ) $this->follow_cache_key_prefix = $options['follow_cache_key_prefix'];
132
  if ( isset( $options['share_target_sns'] ) ) $this->share_target_sns = $options['share_target_sns'];
133
  if ( isset( $options['follow_target_sns'] ) ) $this->follow_target_sns = $options['follow_target_sns'];
134
 
232
  Common_Util::log( '[' . __METHOD__ . '] file exists: ' . $abs_path );
233
 
234
  $fp = fopen( $abs_path, 'a' );
235
+
236
+ $content = '"' . $current_date . '","' . 'home' . '","' . '-' . '","' . get_bloginfo('name') . '","' . home_url( '/' ) . '","' . '-';
237
+
238
+ $option_key = $this->share_cache_key_prefix . strtolower( 'home' );
239
+
240
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
241
+
242
+ foreach ( $this->share_target_sns as $sns => $active ) {
243
+ if ( ! in_array( $sns, $this->export_exclude_keys ) ) {
244
+ if( $active ){
245
+ if ( $sns_counts[$sns] >= 0 ) {
246
+ $data_value = $sns_counts[$sns];
247
+ } else {
248
+ $data_value = '';
249
+ }
250
+ $data = $content . '","' . $sns . '","' . 'Share' . '","' . $data_value . '",' . "\r\n";
251
+ }
252
+ if ( fwrite( $fp, mb_convert_encoding( $data, "SJIS", "UTF-8" ) ) ) {
253
+ Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' . $data );
254
+ } else {
255
+ Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' . $data );
256
+ }
257
+ }
258
+ }
259
+ }
260
+
261
  $query_args = array(
262
  'post_type' => $this->post_types,
263
  'post_status' => 'publish',
267
  );
268
 
269
  $posts_query = new WP_Query( $query_args );
270
+
271
  if ( $posts_query->have_posts() ) {
272
  while ( $posts_query->have_posts() ) {
273
  $posts_query->the_post();
276
 
277
  $content = '"' . $current_date . '","' . $post_ID . '","' . get_post_type( $post_ID ) . '","' . get_the_title( $post_ID ) . '","' . get_permalink( $post_ID ) . '","' . get_post_time( 'Y/m/d H:i', false, $post_ID );
278
 
279
+ foreach ( $this->share_target_sns as $sns => $active ) {
280
 
281
+ if ( ! in_array( $sns, $this->export_exclude_keys ) ) {
282
 
283
+ $meta_key = $this->share_cache_key_prefix . strtolower( $sns );
284
 
285
+ if ( $active ) {
286
 
287
  $data_value = get_post_meta( $post_ID, $meta_key, true );
288
 
289
+ if ( $data_value < 0 ){
290
  $data_value = '';
291
  }
292
 
293
+ $data = $content . '","' . $sns . '","' . 'Share' . '","' . $data_value . '",' . "\r\n";
294
  }
295
  if ( fwrite( $fp, mb_convert_encoding( $data, "SJIS", "UTF-8" ) ) ) {
296
  Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' . $data );
302
 
303
  /*
304
  foreach ( $this->follow_target_sns as $key => $value ) {
305
+ $meta_key = $this->follow_cache_key_prefix . strtolower( $key );
306
 
307
  if ( $value ) {
308
 
includes/class-common-job-reset-engine.php CHANGED
@@ -3,7 +3,6 @@
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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -72,16 +71,7 @@ class Common_Job_Reset_Engine extends Engine {
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
  *
3
  class-common-job-reset-engine.php
4
 
5
  Description: This class is a job reset engine whitch reset expired jobs
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
71
  * instance for delegation
72
  */
73
  private $delegate = NULL;
74
+
 
 
 
 
 
 
 
 
 
75
  /**
76
  * Initialization
77
  *
includes/class-common-util.php CHANGED
@@ -3,7 +3,6 @@
3
  class-common-util.php
4
 
5
  Description: This class is a common utility
6
- Version: 0.3.0
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -113,7 +112,7 @@ class Common_Util {
113
 
114
  $results = $wpdb->get_results( $sql );
115
 
116
- foreach ($results as $value) {
117
  $custom_post_types[] = $value->post_type;
118
  }
119
 
@@ -164,7 +163,7 @@ class Common_Util {
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;
@@ -178,12 +177,130 @@ class Common_Util {
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
 
3
  class-common-util.php
4
 
5
  Description: This class is a common utility
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
112
 
113
  $results = $wpdb->get_results( $sql );
114
 
115
+ foreach ( $results as $value ) {
116
  $custom_post_types[] = $value->post_type;
117
  }
118
 
163
  */
164
  public static function is_secure_url( $url ){
165
 
166
+ if ( preg_match( '/^(https)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $url ) ) {
167
  return true;
168
  } else {
169
  return false;
177
  */
178
  public static function is_normal_url( $url ){
179
 
180
+ if ( preg_match( '/^(http)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $url ) ) {
181
  return true;
182
  } else {
183
  return false;
184
  }
185
+ }
186
+
187
+ /**
188
+ * get cout data from SNS
189
+ *
190
+ * @since 0.5.1
191
+ */
192
+ public static function multi_remote_get( $urls, $timeout = 0, $sslverify = true, $curl = false ) {
193
+
194
+ global $wp_version;
195
+
196
+ $responses = array();
197
+
198
+ if ( empty( $urls ) ) {
199
+ return $responses;
200
+ }
201
+
202
+ if ( $curl ) {
203
+
204
+ Common_Util::log( '[' . __METHOD__ . '] cURL: On' );
205
+
206
+ $mh = curl_multi_init();
207
+ $ch = array();
208
+
209
+ foreach ( $urls as $sns => $url ) {
210
+ $ch[$sns] = curl_init();
211
+
212
+ curl_setopt( $ch[$sns], CURLOPT_URL, $url );
213
+ curl_setopt( $ch[$sns], CURLOPT_USERAGENT, 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
214
+ curl_setopt( $ch[$sns], CURLOPT_FOLLOWLOCATION, true );
215
+ curl_setopt( $ch[$sns], CURLOPT_RETURNTRANSFER, true );
216
+
217
+ if ( $sslverify ) {
218
+ curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYPEER, true );
219
+ curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYHOST, 2 );
220
+ } else {
221
+ curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYPEER, false );
222
+ curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYHOST, 0 );
223
+ }
224
+
225
+ if ( $timeout > 0 ) {
226
+ curl_setopt( $ch[$sns], CURLOPT_CONNECTTIMEOUT, $timeout );
227
+ curl_setopt( $ch[$sns], CURLOPT_TIMEOUT, $timeout );
228
+ }
229
+
230
+ curl_multi_add_handle( $mh, $ch[$sns] );
231
+ }
232
+
233
+ /*
234
+ $running = null;
235
+
236
+ do {
237
+ $mrc = curl_multi_exec( $mh, $running );
238
+ } while ( $mrc == CURLM_CALL_MULTI_PERFORM );
239
+
240
+ while ( $running && $mrc == CURLM_OK ) {
241
+ if ( curl_multi_select( $mh ) != -1 ) {
242
+ do {
243
+ $mrc = curl_multi_exec( $mh, $running );
244
+ } while ( $mrc == CURLM_CALL_MULTI_PERFORM );
245
+ }
246
+ }
247
+ */
248
+
249
+ $active = null;
250
+
251
+ do {
252
+ curl_multi_exec( $mh, $active );
253
+ curl_multi_select( $mh );
254
+ } while ( $active > 0);
255
+
256
+ foreach( $urls as $sns => $url ){
257
+ $responses[$sns]['error'] = curl_error( $ch[$sns] );
258
+
259
+ if( ! empty( $responses[$sns]['error'] ) ) {
260
+ $responses[$sns]['data'] = '';
261
+ } else {
262
+ $responses[$sns]['data'] = curl_multi_getcontent( $ch[$sns] );
263
+ }
264
+
265
+ curl_multi_remove_handle( $mh, $ch[$sns] );
266
+ curl_close( $ch[$sns] );
267
+ }
268
+
269
+ curl_multi_close( $mh );
270
+
271
+ return $responses;
272
+ } else {
273
+
274
+ Common_Util::log( '[' . __METHOD__ . '] cURL: Off' );
275
+
276
+ $options = array(
277
+ 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
278
+ );
279
+
280
+ if ( $sslverify ) {
281
+ $options['sslverify'] = true;
282
+ } else {
283
+ $options['sslverify'] = false;
284
+ }
285
+
286
+ if ( $timeout > 0 ) {
287
+ $options['timeout'] = $timeout;
288
+ }
289
+
290
+ foreach ( $urls as $sns => $url ) {
291
+ $response = wp_remote_get( $url, $options );
292
+
293
+ if ( ! is_wp_error( $response ) && $response['response']['code'] === 200 ) {
294
+ $responses[$sns]['data'] = $response['body'];
295
+ } else {
296
+ $responses[$sns]['data'] = '';
297
+ $responses[$sns]['error'] = $response->get_error_message();
298
+ }
299
+ }
300
+
301
+ return $responses;
302
+ }
303
+ }
304
 
305
  }
306
 
includes/class-data-crawler.php CHANGED
@@ -3,7 +3,6 @@
3
  class-data-crawler.php
4
 
5
  Description: This class is abstract class of a data crawler
6
- Version: 0.3.0
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -37,11 +36,36 @@ abstract class Data_Crawler {
37
  */
38
  protected $url = '';
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  /**
41
  * Instance
42
  */
43
  private static $instance = array();
44
 
 
 
 
 
 
 
 
 
 
 
45
  /**
46
  * Get instance
47
  *
@@ -53,29 +77,48 @@ abstract class Data_Crawler {
53
 
54
  if( ! isset( self::$instance[$class_name] ) ) {
55
  self::$instance[$class_name] = new $class_name();
56
- //self::$instance[ $c ]->init($crawler, $options=array());
57
  }
58
 
59
  return self::$instance[$class_name];
60
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
 
 
 
 
 
 
 
 
 
62
  /**
63
- * Set URL for data crawling
64
  *
65
- * @since 0.1.0
66
- */
67
- public function set_url( $url ) {
68
- $this->log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
69
-
70
- $this->url = rawurlencode( $url );
71
- }
72
 
73
  /**
74
  * Abstract method for data crawling
75
  *
76
  * @since 0.1.1
77
  */
78
- abstract public function get_data( $cache_target, $url );
79
 
80
  }
81
 
3
  class-data-crawler.php
4
 
5
  Description: This class is abstract class of a data crawler
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
36
  */
37
  protected $url = '';
38
 
39
+ /**
40
+ * method to crawl
41
+ */
42
+ protected $crawl_method = 1;
43
+
44
+ /**
45
+ * Timeout
46
+ */
47
+ protected $timeout = 10;
48
+
49
+ /**
50
+ * ssl verification
51
+ */
52
+ protected $ssl_verification = true;
53
+
54
  /**
55
  * Instance
56
  */
57
  private static $instance = array();
58
 
59
+ /**
60
+ * Class constarctor
61
+ * Hook onto all of the actions and filters needed by the plugin.
62
+ *
63
+ */
64
+ protected function __construct() {
65
+ Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
66
+ //$this->get_object_id();
67
+ }
68
+
69
  /**
70
  * Get instance
71
  *
77
 
78
  if( ! isset( self::$instance[$class_name] ) ) {
79
  self::$instance[$class_name] = new $class_name();
 
80
  }
81
 
82
  return self::$instance[$class_name];
83
  }
84
+
85
+ /**
86
+ * Return object ID
87
+ *
88
+ * @since 0.6.0
89
+ */
90
+ public function get_object_id() {
91
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
92
+
93
+ $object_id = spl_object_hash( $this );
94
+
95
+ Common_Util::log( '[' . __METHOD__ . '] object ID: ' . $object_id );
96
+
97
+ return $object_id;
98
+ }
99
 
100
+ /**
101
+ * Inhibit clone
102
+ *
103
+ * @since 0.6.0
104
+ */
105
+ final public function __clone() {
106
+ throw new Exception('Clone is not allowed against' . get_class( $this ) );
107
+ }
108
+
109
  /**
110
+ * Initialization
111
  *
112
+ * @since 0.6.0
113
+ */
114
+ abstract public function initialize( $options = array() );
 
 
 
 
115
 
116
  /**
117
  * Abstract method for data crawling
118
  *
119
  * @since 0.1.1
120
  */
121
+ abstract public function get_data( $target_sns, $url );
122
 
123
  }
124
 
includes/class-engine.php CHANGED
@@ -3,7 +3,6 @@
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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -65,6 +64,7 @@ abstract class Engine {
65
  */
66
  protected function __construct() {
67
  Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
 
68
  }
69
 
70
  /**
@@ -75,14 +75,38 @@ abstract class Engine {
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
  *
3
  class-engine.php
4
 
5
  Description: This class is a engine
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
64
  */
65
  protected function __construct() {
66
  Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
67
+ //$this->get_object_id();
68
  }
69
 
70
  /**
75
  public static function get_instance() {
76
 
77
  $class_name = get_called_class();
78
+
79
  if ( ! isset( self::$instance[$class_name] ) ) {
80
  self::$instance[$class_name] = new $class_name();
 
81
  }
82
 
83
  return self::$instance[$class_name];
84
  }
85
+
86
+ /**
87
+ * Return object ID
88
+ *
89
+ * @since 0.6.0
90
+ */
91
+ public function get_object_id() {
92
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
93
+
94
+ $object_id = spl_object_hash( $this );
95
+
96
+ Common_Util::log( '[' . __METHOD__ . '] object ID: ' . $object_id );
97
+
98
+ return $object_id;
99
+ }
100
+
101
+ /**
102
+ * Inhibit clone
103
+ *
104
+ * @since 0.6.0
105
+ */
106
+ final public function __clone() {
107
+ throw new Exception('Clone is not allowed against' . get_class( $this ) );
108
+ }
109
+
110
  /**
111
  * Register base schedule for this engine
112
  *
includes/class-export-engine.php CHANGED
@@ -3,7 +3,6 @@
3
  class-export-engine.php
4
 
5
  Description: This class is a data export engine whitch exports cached 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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -42,16 +41,7 @@ abstract class Export_Engine extends Engine {
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.
49
- *
50
- */
51
- protected function __construct() {
52
- Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
53
- }
54
-
55
  }
56
 
57
  ?>
3
  class-export-engine.php
4
 
5
  Description: This class is a data export engine whitch exports cached data using wp-cron at regular intervals
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
41
  * Meta key for follow second cache
42
  */
43
  protected $follow_meta_key_prefix = NULL;
44
+
 
 
 
 
 
 
 
 
 
45
  }
46
 
47
  ?>
includes/class-follow-base-cache-engine.php CHANGED
@@ -3,7 +3,6 @@
3
  class-follow-base-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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -67,16 +66,7 @@ class Follow_Base_Cache_Engine extends Follow_Cache_Engine {
67
  * Offset suffix
68
  */
69
  private $offset_suffix = 'follow_base_cache_offset';
70
-
71
- /**
72
- * Class constarctor
73
- * Hook onto all of the actions and filters needed by the plugin.
74
- *
75
- */
76
- protected function __construct() {
77
- Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
78
- }
79
-
80
  /**
81
  * Initialization
82
  *
@@ -85,7 +75,7 @@ class Follow_Base_Cache_Engine extends Follow_Cache_Engine {
85
  public function initialize( $options = array() ) {
86
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
87
 
88
- $this->transient_prefix = self::DEF_TRANSIENT_PREFIX;
89
  $this->prime_cron = self::DEF_PRIME_CRON;
90
  $this->execute_cron = self::DEF_EXECUTE_CRON;
91
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
@@ -95,13 +85,11 @@ class Follow_Base_Cache_Engine extends Follow_Cache_Engine {
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'];
98
- if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
99
- if ( isset( $options['transient_prefix'] ) ) $this->transient_prefix = $options['transient_prefix'];
100
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
101
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
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
 
@@ -156,13 +144,23 @@ class Follow_Base_Cache_Engine extends Follow_Cache_Engine {
156
  $cache_expiration = $this->get_cache_expiration();
157
 
158
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
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
  /**
@@ -174,10 +172,21 @@ class Follow_Base_Cache_Engine extends Follow_Cache_Engine {
174
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
175
 
176
  $cache_expiration = $this->get_cache_expiration();
177
-
178
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
179
-
180
- return $this->cache( $this->target_sns, $cache_expiration );
 
 
 
 
 
 
 
 
 
 
 
181
  }
182
 
183
  /**
@@ -209,9 +218,9 @@ class Follow_Base_Cache_Engine extends Follow_Cache_Engine {
209
  public function clear_cache() {
210
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
211
 
212
- $transient_ID = $this->get_transient_ID( 'follow' );
213
 
214
- delete_transient( $transient_ID );
215
  }
216
 
217
  }
3
  class-follow-base-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
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
66
  * Offset suffix
67
  */
68
  private $offset_suffix = 'follow_base_cache_offset';
69
+
 
 
 
 
 
 
 
 
 
70
  /**
71
  * Initialization
72
  *
75
  public function initialize( $options = array() ) {
76
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
77
 
78
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
79
  $this->prime_cron = self::DEF_PRIME_CRON;
80
  $this->execute_cron = self::DEF_EXECUTE_CRON;
81
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
85
  if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
86
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
87
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
88
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
 
89
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
90
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
91
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
92
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
 
93
  if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
94
  if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
95
 
144
  $cache_expiration = $this->get_cache_expiration();
145
 
146
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
 
 
147
 
148
+ $url = get_feed_link();
149
+
150
+ $transient_id = $this->get_cache_key( 'follow' );
151
+
152
+ $options = array(
153
+ 'cache_key' => $transient_id,
154
+ 'target_url' => $url,
155
+ 'target_sns' => $this->target_sns,
156
+ 'cache_expiration' => $cache_expiration
157
+ );
158
+
159
+ // Primary cache
160
+ $this->cache( $options );
161
 
162
+ // Secondary cache
163
+ $this->delegate_cache( $options );
164
  }
165
 
166
  /**
172
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
173
 
174
  $cache_expiration = $this->get_cache_expiration();
175
+
176
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
177
+
178
+ $url = get_feed_link();
179
+
180
+ $transient_id = $this->get_cache_key( 'follow' );
181
+
182
+ $options = array(
183
+ 'cache_key' => $transient_id,
184
+ 'target_url' => $url,
185
+ 'target_sns' => $this->target_sns,
186
+ 'cache_expiration' => $cache_expiration
187
+ );
188
+
189
+ return $this->cache( $options );
190
  }
191
 
192
  /**
218
  public function clear_cache() {
219
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
220
 
221
+ $transient_id = $this->get_cache_key( 'follow' );
222
 
223
+ delete_transient( $transient_id );
224
  }
225
 
226
  }
includes/class-follow-cache-engine.php CHANGED
@@ -3,7 +3,6 @@
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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -43,11 +42,6 @@ abstract class Follow_Cache_Engine extends Cache_Engine {
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
  */
@@ -63,44 +57,45 @@ abstract class Follow_Cache_Engine extends Cache_Engine {
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
  }
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
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
42
  */
43
  protected $target_sns = array();
44
 
 
 
 
 
 
45
  /**
46
  * migration between http and https
47
  */
57
  *
58
  * @since 0.4.0
59
  */
60
+ public function cache( $options = array() ) {
61
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
62
 
63
+ $cache_key = $options['cache_key'];
64
+ $target_url = $options['target_url'];
65
+ $target_sns = $options['target_sns'];
66
+ $cache_expiration = $options['cache_expiration'];
67
 
68
+ Common_Util::log( '[' . __METHOD__ . '] feed: ' . $target_url );
69
+
70
+ $data = $this->crawler->get_data( $target_sns, $target_url );
71
 
72
  Common_Util::log( $data );
73
 
74
+ if ( $this->scheme_migration_mode && Common_Util::is_secure_url( $target_url ) ) {
75
+ $target_url = Common_Util::get_normal_url( $target_url );
76
 
77
  $target_sns_migrated = $target_sns;
78
 
79
+ foreach ( $this->scheme_migration_exclude_keys as $sns ) {
80
+ unset( $target_sns_migrated[$sns] );
81
  }
82
 
83
+ Common_Util::log( '[' . __METHOD__ . '] feed: ' . $target_url );
84
 
85
+ $migrated_data = $this->crawler->get_data( $target_sns_migrated, $target_url );
86
 
87
  Common_Util::log( $migrated_data );
88
 
89
+ foreach ( $target_sns_migrated as $sns => $active ) {
90
+ if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
91
+ $data[$sns] = $data[$sns] + $migrated_data[$sns];
92
  }
93
  }
94
 
95
  }
96
 
97
  if ( $data ) {
98
+ $result = set_transient( $cache_key, $data, $cache_expiration );
99
 
100
  Common_Util::log( '[' . __METHOD__ . '] set_transient result: ' . $result );
101
  }
includes/class-follow-crawler.php CHANGED
@@ -3,7 +3,6 @@
3
  class-sns-follow-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
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -31,94 +30,109 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31
  */
32
 
33
  class Follow_Crawler extends Data_Crawler {
34
-
35
  /**
36
- * Timeout for cURL data retrieval
37
- */
38
- private $timeout = 10;
39
-
40
- protected function __construct( $url='', $timeout=10 ) {
41
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
42
-
43
- $this->url = rawurlencode( $url );
44
- $this->timeout = $timeout;
45
- }
46
-
47
- public function set_timeout( $timeout ) {
48
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
49
 
50
- $this->timeout = $timeout;
51
- }
 
 
52
 
53
  /**
54
  * Implementation of abstract method. this method gets each share count
55
  *
56
  * @since 0.1.1
57
  */
58
- public function get_data( $cache_target, $url ) {
59
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
60
 
 
 
61
  $url = rawurlencode( $url );
62
 
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;
 
 
 
 
70
  }
71
-
72
- /**
73
- * Get share count for Twitter
74
  *
75
- * @since 0.1.0
76
- */
77
- public function get_feedly_follow( $url ) {
78
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
79
-
80
- $query = 'http://cloud.feedly.com/v3/feeds/feed%2F' . $url;
81
 
82
- $json = $this->remote_get( $query );
83
-
84
- $feedly = json_decode( $json, true );
 
 
 
 
 
 
85
 
86
- return isset( $feedly['subscribers'] ) ? intval( $feedly['subscribers'] ) : null;
87
- }
88
 
89
  /**
90
- * Get content from given URL using cURL
91
  *
92
- * @since 0.1.0
93
- */
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 ) ) {
113
- Common_Util::log( '[' . __METHOD__ . '] curl_error: ' + curl_error( $curl ) );
114
- die( curl_error( $curl ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
116
 
117
- curl_close( $curl );
118
 
119
- return $curl_results;
120
- }
121
-
122
  }
123
 
124
  ?>
3
  class-sns-follow-crawler.php
4
 
5
  Description: This class is a data crawler whitch get share count using given API and cURL
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
30
  */
31
 
32
  class Follow_Crawler extends Data_Crawler {
33
+
34
  /**
35
+ * Initialization
36
+ *
37
+ * @since 0.5.1
38
+ */
39
+ public function initialize( $options = array() ) {
 
 
 
 
 
 
 
40
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
41
 
42
+ if ( isset( $options['crawl_method'] ) ) $this->crawl_method = $options['crawl_method'];
43
+ if ( isset( $options['timeout'] ) ) $this->timeout = $options['timeout'];
44
+ if ( isset( $options['ssl_verification'] ) ) $this->ssl_verification = $options['ssl_verification'];
45
+ }
46
 
47
  /**
48
  * Implementation of abstract method. this method gets each share count
49
  *
50
  * @since 0.1.1
51
  */
52
+ public function get_data( $target_sns, $url ) {
53
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
54
 
55
+ Common_Util::log( '[' . __METHOD__ . '] Feedly' );
56
+
57
  $url = rawurlencode( $url );
58
 
59
+ $query_urls = $this->build_query_urls( $target_sns, $url );
60
+
61
+ $data = array();
62
+
63
+ if ( $this->crawl_method == SNS_Count_Cache::OPT_COMMON_CRAWLER_METHOD_CURL ) {
64
+ $data = Common_Util::multi_remote_get( $query_urls, $this->timeout, $this->ssl_verification, true );
65
+ } else {
66
+ $data = Common_Util::multi_remote_get( $query_urls, $this->timeout, $this->ssl_verification, false );
67
+ }
68
+
69
+ return $this->extract_count( $target_sns, $data );
70
  }
71
+
72
+ /**
73
+ * build query
74
  *
75
+ * @since 0.5.1
76
+ */
77
+ private function build_query_urls( $target_sns, $url ) {
78
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
 
 
79
 
80
+ $query_urls = array();
81
+
82
+ if ( isset( $url ) ) {
83
+ if ( isset( $target_sns[SNS_Count_Cache::REF_FOLLOW_FEEDLY] ) && $target_sns[SNS_Count_Cache::REF_FOLLOW_FEEDLY] ) {
84
+ $query_urls[SNS_Count_Cache::REF_FOLLOW_FEEDLY] = 'http://cloud.feedly.com/v3/feeds/feed%2F' . $url;
85
+ }
86
+ }
87
+
88
+ return $query_urls;
89
 
90
+ }
 
91
 
92
  /**
93
+ * extract count data from retrieved content
94
  *
95
+ * @since 0.5.1
96
+ */
97
+ private function extract_count( $target_sns, $contents ) {
98
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
99
 
100
+ $sns_counts = array();
101
+
102
+ $extract_date = date_i18n( 'Y/m/d H:i:s' );
103
 
104
+ Common_Util::log( $contents );
105
+
106
+ foreach ( $contents as $sns => $content ) {
 
 
 
 
 
 
 
107
 
108
+ if ( $sns == SNS_Count_Cache::REF_FOLLOW_FEEDLY ) {
109
+
110
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
111
+ $json = json_decode( $content['data'], true );
112
+
113
+ if ( isset( $json['subscribers'] ) && is_numeric( $json['subscribers'] ) ) {
114
+ $count = ( int )$json['subscribers'];
115
+ } else {
116
+ $count = -1;
117
+ }
118
+ } else {
119
+ $count = -1;
120
+ }
121
+
122
+ $sns_counts[SNS_Count_Cache::REF_FOLLOW_FEEDLY] = $count;
123
+
124
+ }
125
+ }
126
+
127
+ if ( isset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) && $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) {
128
+ $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = $extract_date;
129
  }
130
 
131
+ return $sns_counts;
132
 
133
+ }
134
+
135
+
136
  }
137
 
138
  ?>
includes/class-follow-lazy-cache-engine.php CHANGED
@@ -3,7 +3,6 @@
3
  class-follow-lazy-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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -67,16 +66,7 @@ class Follow_Lazy_Cache_Engine extends Follow_Cache_Engine {
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.
74
- *
75
- */
76
- protected function __construct() {
77
- Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
78
- }
79
-
80
  /**
81
  * Initialization
82
  *
@@ -85,7 +75,7 @@ class Follow_Lazy_Cache_Engine extends Follow_Cache_Engine {
85
  public function initialize( $options = array() ) {
86
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
87
 
88
- $this->transient_prefix = self::DEF_TRANSIENT_PREFIX;
89
  $this->prime_cron = self::DEF_PRIME_CRON;
90
  $this->execute_cron = self::DEF_EXECUTE_CRON;
91
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
@@ -95,14 +85,13 @@ class Follow_Lazy_Cache_Engine extends Follow_Cache_Engine {
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'];
98
- if ( isset( $options['transient_prefix'] ) ) $this->transient_prefix = $options['transient_prefix'];
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
 
107
  }
108
 
@@ -129,7 +118,7 @@ class Follow_Lazy_Cache_Engine extends Follow_Cache_Engine {
129
  Common_Util::log( '[' . __METHOD__ . '] check_latency: ' . $this->check_latency );
130
  Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
131
 
132
- wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( Common_Util::short_hash( $next_exec_time ) ) );
133
  }
134
 
135
  /**
@@ -137,18 +126,29 @@ class Follow_Lazy_Cache_Engine extends Follow_Cache_Engine {
137
  *
138
  * @since 0.4.0
139
  */
140
- public function execute_cache( $hash ) {
141
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
142
 
143
  $cache_expiration = $this->get_cache_expiration();
144
 
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
  /**
@@ -184,4 +184,4 @@ class Follow_Lazy_Cache_Engine extends Follow_Cache_Engine {
184
 
185
  }
186
 
187
- ?>
3
  class-follow-lazy-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
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
66
  * Latency suffix
67
  */
68
  private $check_latency = 10;
69
+
 
 
 
 
 
 
 
 
 
70
  /**
71
  * Initialization
72
  *
75
  public function initialize( $options = array() ) {
76
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
77
 
78
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
79
  $this->prime_cron = self::DEF_PRIME_CRON;
80
  $this->execute_cron = self::DEF_EXECUTE_CRON;
81
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
85
  if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
86
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
87
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
88
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
89
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
90
  if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
 
91
  if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
92
  if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
93
 
94
+ add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 0 );
95
 
96
  }
97
 
118
  Common_Util::log( '[' . __METHOD__ . '] check_latency: ' . $this->check_latency );
119
  Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
120
 
121
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array() );
122
  }
123
 
124
  /**
126
  *
127
  * @since 0.4.0
128
  */
129
+ public function execute_cache() {
130
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
131
 
132
  $cache_expiration = $this->get_cache_expiration();
133
 
134
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
135
 
136
+ $url = get_feed_link();
137
+
138
+ $transient_id = $this->get_cache_key( 'follow' );
139
+
140
+ $options = array(
141
+ 'cache_key' => $transient_id,
142
+ 'target_url' => $url,
143
+ 'target_sns' => $this->target_sns,
144
+ 'cache_expiration' => $cache_expiration
145
+ );
146
 
147
+ // Primary cache
148
+ $this->cache( $options );
149
+
150
+ // Secondary cache
151
+ $this->delegate_cache( $options );
152
  }
153
 
154
  /**
184
 
185
  }
186
 
187
+ ?>
includes/class-follow-second-cache-engine.php CHANGED
@@ -3,7 +3,6 @@
3
  class-follow-second-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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -71,20 +70,6 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
71
  * Cache target
72
  */
73
  private $target_sns = array();
74
-
75
- /**
76
- * Cache post types
77
- */
78
- private $post_types = array( 'post', 'page' );
79
-
80
- /**
81
- * Class constarctor
82
- * Hook onto all of the actions and filters needed by the plugin.
83
- *
84
- */
85
- protected function __construct() {
86
- Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
87
- }
88
 
89
  /**
90
  * Initialization
@@ -94,7 +79,7 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
94
  public function initialize( $options = array() ) {
95
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
96
 
97
- $this->transient_prefix = self::DEF_TRANSIENT_PREFIX;
98
  $this->prime_cron = self::DEF_PRIME_CRON;
99
  $this->execute_cron = self::DEF_EXECUTE_CRON;
100
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
@@ -102,13 +87,12 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
102
 
103
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
104
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
105
- if ( isset( $options['transient_prefix'] ) ) $this->transient_prefix = $options['transient_prefix'];
106
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
107
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
108
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
109
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
110
  if ( isset( $options['meta_key_prefix'] ) ) $this->meta_key_prefix = $options['meta_key_prefix'];
111
- if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
112
 
113
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
114
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
@@ -155,8 +139,18 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
155
  */
156
  public function execute_cache() {
157
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
158
-
159
- $this->cache( NULL, $this->target_sns, NULL );
 
 
 
 
 
 
 
 
 
 
160
 
161
  }
162
 
@@ -165,25 +159,19 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
165
  *
166
  * @since 0.1.1
167
  */
168
- public function cache( $post_ID, $target_sns, $cache_expiration ) {
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 ) {
176
-
177
- $meta_key = $this->meta_key_prefix . strtolower( $key );
178
 
179
- if ( $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
  }
@@ -206,15 +194,18 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
206
  */
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
 
@@ -226,47 +217,21 @@ class Follow_Second_Cache_Engine extends Cache_Engine {
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',
242
- 'nopaging' => true,
243
- 'update_post_term_cache' => false,
244
- 'update_post_meta_cache' => false
245
- );
246
-
247
- $posts_query = new WP_Query( $query_args );
248
 
249
- if ( $posts_query->have_posts() ) {
250
- while ( $posts_query->have_posts() ) {
251
- $posts_query->the_post();
252
-
253
- $post_ID = get_the_ID();
254
-
255
- foreach ( $this->target_sns as $key => $value ) {
256
 
257
- $meta_key = $this->meta_key_prefix . strtolower( $key );
258
 
259
- if ( $value ) {
260
- delete_post_meta($post_ID, $meta_key);
261
- }
262
- }
263
  }
264
- }
265
- wp_reset_postdata();
266
-
267
-
268
 
269
- }
270
 
271
  }
272
 
3
  class-follow-second-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
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
70
  * Cache target
71
  */
72
  private $target_sns = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  /**
75
  * Initialization
79
  public function initialize( $options = array() ) {
80
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
81
 
82
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
83
  $this->prime_cron = self::DEF_PRIME_CRON;
84
  $this->execute_cron = self::DEF_EXECUTE_CRON;
85
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
87
 
88
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
89
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
90
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
91
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
92
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
93
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
94
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
95
  if ( isset( $options['meta_key_prefix'] ) ) $this->meta_key_prefix = $options['meta_key_prefix'];
 
96
 
97
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
98
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
139
  */
140
  public function execute_cache() {
141
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
142
+
143
+ $url = get_feed_link();
144
+
145
+ $transient_id = $this->get_cache_key( 'follow' );
146
+
147
+ $options = array(
148
+ 'cache_key' => $transient_id,
149
+ 'target_url' => $url,
150
+ 'target_sns' => $this->target_sns,
151
+ );
152
+
153
+ $this->cache( $options );
154
 
155
  }
156
 
159
  *
160
  * @since 0.1.1
161
  */
162
+ public function cache( $options = array() ) {
163
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
164
 
165
+ $transient_id = $options['cache_key'];
166
+ $target_url = $options['target_url'];
167
+ $target_sns = $options['target_sns'];
168
 
169
+ if ( false !== ( $sns_followers = get_transient( $transient_id ) ) ) {
170
+
171
+ $option_key = $this->get_cache_key( 'follow' );
172
+
173
+ update_option( $option_key, $sns_followers );
174
 
 
 
 
 
 
 
 
 
175
  }
176
 
177
  }
194
  */
195
  public function initialize_cache() {
196
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
197
+
198
+ $option_key = $this->get_cache_key( 'follow' );
199
 
200
+ $sns_followers = array();
201
+
202
+ foreach ( $this->target_sns as $sns => $active ) {
203
+ if ( $active ) {
204
+ $sns_followers[$sns] = -1;
 
205
  }
206
+ }
207
+
208
+ update_option( $option_key, $sns_followers );
209
 
210
  }
211
 
217
  public function clear_cache() {
218
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
219
 
220
+ $option_key = $this->get_cache_key( 'follow' );
221
+
222
+ delete_option( $option_key );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
 
224
+ // Compatibility for old version
225
+ foreach ( $this->target_sns as $sns => $active ) {
 
 
 
 
 
226
 
227
+ $option_key = $this->get_cache_key( $sns );
228
 
229
+ if ( $active ) {
230
+ delete_option( $option_key );
 
 
231
  }
232
+ }
 
 
 
233
 
234
+ }
235
 
236
  }
237
 
includes/class-share-base-cache-engine.php CHANGED
@@ -3,7 +3,6 @@
3
  class-share-base-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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -73,15 +72,6 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
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.
79
- *
80
- */
81
- protected function __construct() {
82
- Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
83
- }
84
-
85
  /**
86
  * Initialization
87
  *
@@ -90,7 +80,7 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
90
  public function initialize( $options = array() ) {
91
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
92
 
93
- $this->transient_prefix = self::DEF_TRANSIENT_PREFIX;
94
  $this->prime_cron = self::DEF_PRIME_CRON;
95
  $this->execute_cron = self::DEF_EXECUTE_CRON;
96
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
@@ -101,7 +91,7 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
101
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
102
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
103
  if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
104
- if ( isset( $options['transient_prefix'] ) ) $this->transient_prefix = $options['transient_prefix'];
105
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
106
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
107
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
@@ -148,15 +138,9 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
148
  Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
149
  Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
150
 
151
- $transient_ID = $this->get_transient_ID( $this->offset_suffix );
152
 
153
- /*
154
- if ( false === ( $posts_offset = get_transient( $transient_ID ) ) ) {
155
- $posts_offset = 0;
156
- }
157
- */
158
-
159
- if ( false === ( $posts_offset = get_option( $transient_ID ) ) ) {
160
  $posts_offset = 0;
161
  }
162
 
@@ -170,8 +154,7 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
170
  $posts_offset = 0;
171
  }
172
 
173
- //set_transient( $transient_ID, $posts_offset, $this->check_interval + $this->check_interval );
174
- update_option( $transient_ID, $posts_offset );
175
  }
176
 
177
  /**
@@ -190,15 +173,39 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
190
 
191
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  $query_args = array(
194
- 'post_type' => $this->post_types,
195
- 'post_status' => 'publish',
196
- 'offset' => $posts_offset,
197
- 'posts_per_page' => $this->posts_per_check,
198
- 'no_found_rows' => true,
199
- 'update_post_term_cache' => false,
200
- 'update_post_meta_cache' => false
201
- );
202
 
203
  $posts_query = new WP_Query( $query_args );
204
 
@@ -208,18 +215,29 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
208
 
209
  $post_ID = get_the_ID();
210
 
211
- Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
 
 
 
 
 
 
 
 
 
 
 
 
212
 
213
- $this->cache( $post_ID, $this->target_sns, $cache_expiration );
 
214
 
215
- if ( ! is_null( $this->delegate ) && method_exists( $this->delegate, 'order_cache' ) ) {
216
- $options = array( 'post_id' => $post_ID );
217
- $this->delegate->order_cache( $this, $options );
218
- }
219
  }
220
  }
221
- wp_reset_postdata();
222
-
223
  }
224
 
225
  /**
@@ -229,18 +247,33 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
229
  */
230
  public function direct_cache( $post_ID, $second_sync = false ) {
231
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
232
-
233
  $cache_expiration = $this->get_cache_expiration();
234
 
235
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
 
237
- $result = $this->cache( $post_ID, $this->target_sns, $cache_expiration );
 
238
 
239
  if ( $second_sync ) {
240
- if ( ! is_null( $this->delegate ) && method_exists( $this->delegate, 'order_cache' ) ) {
241
- $options = array( 'post_id' => $post_ID );
242
- $this->delegate->order_cache( $this, $options );
243
- }
244
  }
245
 
246
  return $result;
@@ -269,6 +302,10 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
269
  public function initialize_cache() {
270
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
271
 
 
 
 
 
272
  }
273
 
274
  /**
@@ -278,7 +315,11 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
278
  */
279
  public function clear_cache() {
280
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
281
-
 
 
 
 
282
  $query_args = array(
283
  'post_type' => $this->post_types,
284
  'post_status' => 'publish',
@@ -295,16 +336,16 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
295
 
296
  $post_ID = get_the_ID();
297
 
298
- $transient_ID = $this->get_transient_ID( $post_ID );
299
 
300
- delete_transient( $transient_ID );
301
  }
302
  }
303
  wp_reset_postdata();
304
 
305
- $transient_ID = $this->get_transient_ID( $this->offset_suffix );
306
 
307
- delete_option( $transient_ID );
308
 
309
  }
310
 
3
  class-share-base-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
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
72
  */
73
  private $offset_suffix = 'base_offset';
74
 
 
 
 
 
 
 
 
 
 
75
  /**
76
  * Initialization
77
  *
80
  public function initialize( $options = array() ) {
81
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
82
 
83
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
84
  $this->prime_cron = self::DEF_PRIME_CRON;
85
  $this->execute_cron = self::DEF_EXECUTE_CRON;
86
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
91
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
92
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
93
  if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
94
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
95
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
96
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
97
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
138
  Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
139
  Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
140
 
141
+ $option_key = $this->get_cache_key( $this->offset_suffix );
142
 
143
+ if ( false === ( $posts_offset = get_option( $option_key ) ) ) {
 
 
 
 
 
 
144
  $posts_offset = 0;
145
  }
146
 
154
  $posts_offset = 0;
155
  }
156
 
157
+ update_option( $option_key, $posts_offset );
 
158
  }
159
 
160
  /**
173
 
174
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
175
 
176
+ // Cache home url
177
+ if ( $posts_offset == 0 ) {
178
+
179
+ $post_ID = 'home';
180
+
181
+ $transient_id = $this->get_cache_key( $post_ID );
182
+ $url = home_url( '/' );
183
+
184
+ $options = array(
185
+ 'cache_key' => $transient_id,
186
+ 'post_id' => $post_ID,
187
+ 'target_url' => $url,
188
+ 'target_sns' => $this->target_sns,
189
+ 'cache_expiration' => $cache_expiration
190
+ );
191
+
192
+ // Primary cache
193
+ $this->cache( $options );
194
+
195
+ // Secondary cache
196
+ $this->delegate_cache( $options );
197
+
198
+ }
199
+
200
  $query_args = array(
201
+ 'post_type' => $this->post_types,
202
+ 'post_status' => 'publish',
203
+ 'offset' => $posts_offset,
204
+ 'posts_per_page' => $this->posts_per_check,
205
+ 'no_found_rows' => true,
206
+ 'update_post_term_cache' => false,
207
+ 'update_post_meta_cache' => false
208
+ );
209
 
210
  $posts_query = new WP_Query( $query_args );
211
 
215
 
216
  $post_ID = get_the_ID();
217
 
218
+ Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
219
+
220
+ $transient_id = $this->get_cache_key( $post_ID );
221
+
222
+ $url = get_permalink( $post_ID );
223
+
224
+ $options = array(
225
+ 'cache_key' => $transient_id,
226
+ 'post_id' => $post_ID,
227
+ 'target_url' => $url,
228
+ 'target_sns' => $this->target_sns,
229
+ 'cache_expiration' => $cache_expiration
230
+ );
231
 
232
+ // Primary cache
233
+ $this->cache( $options );
234
 
235
+ // Secondary cache
236
+ $this->delegate_cache( $options );
237
+
 
238
  }
239
  }
240
+ wp_reset_postdata();
 
241
  }
242
 
243
  /**
247
  */
248
  public function direct_cache( $post_ID, $second_sync = false ) {
249
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
250
+
251
  $cache_expiration = $this->get_cache_expiration();
252
 
253
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
254
+
255
+ $transient_id = $this->get_cache_key( $post_ID );
256
+
257
+ if ( $post_ID != 'home' ) {
258
+ $url = get_permalink( $post_ID );
259
+ } else {
260
+ $url = home_url( '/' );
261
+ }
262
+
263
+ $options = array(
264
+ 'cache_key' => $transient_id,
265
+ 'post_id' => $post_ID,
266
+ 'target_url' => $url,
267
+ 'target_sns' => $this->target_sns,
268
+ 'cache_expiration' => $cache_expiration
269
+ );
270
 
271
+ // Primary cache
272
+ $result = $this->cache( $options );
273
 
274
  if ( $second_sync ) {
275
+ // Secondary cache
276
+ $this->delegate_cache( $options );
 
 
277
  }
278
 
279
  return $result;
302
  public function initialize_cache() {
303
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
304
 
305
+ $option_key = $this->get_cache_key( $this->offset_suffix );
306
+
307
+ update_option( $option_key, 0 );
308
+
309
  }
310
 
311
  /**
315
  */
316
  public function clear_cache() {
317
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
318
+
319
+ $transient_id = $this->get_cache_key( 'home' );
320
+
321
+ delete_transient( $transient_id );
322
+
323
  $query_args = array(
324
  'post_type' => $this->post_types,
325
  'post_status' => 'publish',
336
 
337
  $post_ID = get_the_ID();
338
 
339
+ $transient_id = $this->get_cache_key( $post_ID );
340
 
341
+ delete_transient( $transient_id );
342
  }
343
  }
344
  wp_reset_postdata();
345
 
346
+ $option_key = $this->get_cache_key( $this->offset_suffix );
347
 
348
+ delete_option( $option_key );
349
 
350
  }
351
 
includes/class-share-cache-engine.php CHANGED
@@ -3,7 +3,6 @@
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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -62,50 +61,54 @@ abstract class Share_Cache_Engine extends Cache_Engine {
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
 
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
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
61
  *
62
  * @since 0.1.1
63
  */
64
+ public function cache( $options = array() ) {
65
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
 
 
 
 
66
 
67
+ $cache_key = $options['cache_key'];
68
+ $target_url = $options['target_url'];
69
+ $target_sns = $options['target_sns'];
70
+ $cache_expiration = $options['cache_expiration'];
71
 
72
+ Common_Util::log( '[' . __METHOD__ . '] current memory usage: ' . round( memory_get_usage( true )/1024/1024, 2 ) . ' MB' );
73
 
74
+ Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_url );
75
+
76
+ $data = $this->crawler->get_data( $target_sns, $target_url );
77
 
78
  Common_Util::log( $data );
79
 
80
+ if ( $this->scheme_migration_mode && Common_Util::is_secure_url( $target_url ) ) {
81
+ $target_url = Common_Util::get_normal_url( $target_url );
82
 
83
  $target_sns_migrated = $target_sns;
84
 
85
+ foreach ( $this->scheme_migration_exclude_keys as $sns ) {
86
+ unset( $target_sns_migrated[$sns] );
87
  }
88
 
89
+ Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_url );
90
 
91
+ $migrated_data = $this->crawler->get_data( $target_sns_migrated, $target_url );
92
 
93
  Common_Util::log( $migrated_data );
94
 
95
+ foreach ( $target_sns_migrated as $sns => $active ) {
96
+ if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
97
+ $data[$sns] = $data[$sns] + $migrated_data[$sns];
98
  }
99
  }
100
 
101
  }
102
 
103
  if ( $data ) {
104
+ $result = set_transient( $cache_key, $data, $cache_expiration );
105
 
106
  Common_Util::log( '[' . __METHOD__ . '] set_transient result: ' . $result );
107
  }
108
 
109
+ Common_Util::log( '[' . __METHOD__ . '] current memory usage: ' . round( memory_get_usage( true )/1024/1024, 2 ) . ' MB' );
110
+ Common_Util::log( '[' . __METHOD__ . '] max memory usage: ' . round( memory_get_peak_usage( true )/1024/1024, 2 ) . ' MB' );
111
+
112
  return $data;
113
  }
114
 
includes/class-share-crawler.php CHANGED
@@ -3,7 +3,6 @@
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
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -33,229 +32,196 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
33
  class Share_Crawler extends Data_Crawler {
34
 
35
  /**
36
- * Timeout for cURL data retrieval
37
- */
38
- private $timeout = 10;
39
-
40
- protected function __construct( $url='', $timeout=10 ) {
41
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
42
-
43
- $this->url = rawurlencode( $url );
44
- $this->timeout = $timeout;
45
- }
46
-
47
- public function set_timeout( $timeout ) {
48
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
49
 
50
- $this->timeout = $timeout;
51
- }
52
-
 
 
53
  /**
54
  * Implementation of abstract method. this method gets each share count
55
  *
56
  * @since 0.1.1
57
  */
58
- public function get_data( $cache_target, $url ) {
59
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
60
 
61
  $url = rawurlencode( $url );
62
 
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
- }
79
-
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
- }
92
- }
93
-
94
- if ( isset( $cache_target[SNS_Count_Cache::REF_SHARE_TOTAL] ) && $cache_target[SNS_Count_Cache::REF_SHARE_TOTAL] ) {
95
-
96
- $total = 0;
97
-
98
- foreach ( $sns_counts as $key => $value ) {
99
- if ( isset( $value) && $value >= 0 ) {
100
- $total = $total + $value;
101
- }
102
- }
103
-
104
- $sns_counts[SNS_Count_Cache::REF_SHARE_TOTAL] = $total;
105
- }
106
-
107
- if ( isset( $cache_target[SNS_Count_Cache::REF_CRAWL_DATE] ) && $cache_target[SNS_Count_Cache::REF_CRAWL_DATE] ) {
108
- $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = date_i18n( 'Y/m/d H:i:s' );
109
- }
110
-
111
- return $sns_counts;
112
- }
113
-
114
- /**
115
- * Get share count for Hatena Bookmark
116
- *
117
- * @since 0.1.0
118
- */
119
- public function get_hatebu_count( $url ) {
120
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
121
 
122
- $query = 'http://api.b.st-hatena.com/entry.count?url=' . $url;
123
 
124
- $hatebu = $this->remote_get( $query );
125
-
126
- return isset( $hatebu ) ? intval($hatebu) : -1;
127
- }
128
-
129
- /**
130
- * Get share count for Twitter
131
- *
132
- * @since 0.1.0
133
- */
134
- public function get_twitter_count( $url ) {
135
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
136
-
137
- $query = 'http://urls.api.twitter.com/1/urls/count.json?url=' . $url;
138
-
139
- $json = $this->remote_get( $query );
140
-
141
- $twitter = json_decode( $json, true );
142
-
143
- return isset( $twitter['count'] ) ? intval( $twitter['count'] ) : -1;
144
- }
145
-
146
- /**
147
- * Get share count for Facebook
148
- *
149
- * @since 0.1.0
150
- */
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
-
168
- $result = $xpath->query( '//*[@id="u_0_2"]' )->item(0);
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 {
176
- $count = 0;
177
  }
178
 
179
- return isset( $count ) ? intval( $count ) : -1;
180
-
181
- }
182
 
183
  /**
184
- * Get share count for Google Plus
185
  *
186
- * @since 0.1.0
187
- */
188
- public function get_gplus_count( $url ) {
189
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
190
-
191
- $query = 'https://apis.google.com/_/+1/fastbutton?url=' . $url;
192
 
193
- $html = $this->remote_get( $query );
194
-
195
- preg_match( '/\[2,([0-9.]+),\[/', $html, $count );
196
 
197
- return isset( $count[1] ) ? intval( $count[1] ) : -1;
198
- }
199
-
200
- /**
201
- * Get share count for Pocket
202
- *
203
- * @since 0.1.0
204
- */
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' );
213
- $dom->preserveWhiteSpace = false;
214
- $dom->formatOutput = true;
215
- $dom->loadXml( $html );
216
-
217
- $xpath = new DOMXPath( $dom );
218
 
219
- $result = $xpath->query( '//em[@id = "cnt"]' )->item(0);
 
 
220
 
221
- Common_Util::log( '[' . __METHOD__ . '] count: ' . $result->nodeValue );
 
 
 
222
 
223
- return isset( $result->nodeValue ) ? intval( $result->nodeValue ) : -1;
 
224
  }
225
 
226
  /**
227
- * Get content from given URL using cURL
228
  *
229
- * @since 0.1.0
230
- */
231
- private function remote_get( $url ) {
232
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
233
 
234
- global $wp_version;
235
-
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
 
249
- if ( curl_error( $curl ) ) {
250
- Common_Util::log( '[' . __METHOD__ . '] curl_error: ' + curl_error( $curl ) );
251
- die( curl_error( $curl ) );
 
 
 
 
 
 
 
 
 
 
 
 
252
  }
253
 
254
- curl_close( $curl );
255
 
256
- return $curl_results;
257
- }
258
 
 
259
  }
260
 
261
  ?>
3
  class-share-crawler.php
4
 
5
  Description: This class is a data crawler whitch get share count using given API and cURL
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
32
  class Share_Crawler extends Data_Crawler {
33
 
34
  /**
35
+ * Initialization
36
+ *
37
+ * @since 0.5.1
38
+ */
39
+ public function initialize( $options = array() ) {
 
 
 
 
 
 
 
40
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
41
 
42
+ if ( isset( $options['crawl_method'] ) ) $this->crawl_method = $options['crawl_method'];
43
+ if ( isset( $options['timeout'] ) ) $this->timeout = $options['timeout'];
44
+ if ( isset( $options['ssl_verification'] ) ) $this->ssl_verification = $options['ssl_verification'];
45
+ }
46
+
47
  /**
48
  * Implementation of abstract method. this method gets each share count
49
  *
50
  * @since 0.1.1
51
  */
52
+ public function get_data( $target_sns, $url ) {
53
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
54
 
55
  $url = rawurlencode( $url );
56
 
57
+ $query_urls = $this->build_query_urls( $target_sns, $url );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
+ $data = array();
60
 
61
+ if ( $this->crawl_method === SNS_Count_Cache::OPT_COMMON_CRAWLER_METHOD_CURL ) {
62
+ $data = Common_Util::multi_remote_get( $query_urls, $this->timeout, $this->ssl_verification, true );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  } else {
64
+ $data = Common_Util::multi_remote_get( $query_urls, $this->timeout, $this->ssl_verification, false );
65
  }
66
 
67
+ return $this->extract_count( $target_sns, $data );
68
+ }
 
69
 
70
  /**
71
+ * build query
72
  *
73
+ * @since 0.5.1
74
+ */
75
+ private function build_query_urls( $target_sns, $url ) {
76
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
 
 
77
 
78
+ $query_urls = array();
 
 
79
 
80
+ if ( isset( $url ) ) {
81
+ if ( isset( $target_sns[SNS_Count_Cache::REF_SHARE_HATEBU] ) && $target_sns[SNS_Count_Cache::REF_SHARE_HATEBU] ) {
82
+ $query_urls[SNS_Count_Cache::REF_SHARE_HATEBU] = 'http://api.b.st-hatena.com/entry.count?url=' . $url;
83
+ }
84
+
85
+ if ( isset( $target_sns[SNS_Count_Cache::REF_SHARE_TWITTER] ) && $target_sns[SNS_Count_Cache::REF_SHARE_TWITTER] ) {
86
+ $query_urls[SNS_Count_Cache::REF_SHARE_TWITTER] = 'http://urls.api.twitter.com/1/urls/count.json?url=' . $url;
87
+ }
 
 
 
 
88
 
89
+ if ( isset( $target_sns[SNS_Count_Cache::REF_SHARE_FACEBOOK] ) && $target_sns[SNS_Count_Cache::REF_SHARE_FACEBOOK] ) {
90
+ $query_urls[SNS_Count_Cache::REF_SHARE_FACEBOOK] = 'https://api.facebook.com/method/links.getStats?urls=' . $url . '&format=json';
91
+ }
 
 
 
 
 
92
 
93
+ if ( isset( $target_sns[SNS_Count_Cache::REF_SHARE_GPLUS] ) && $target_sns[SNS_Count_Cache::REF_SHARE_GPLUS] ) {
94
+ $query_urls[SNS_Count_Cache::REF_SHARE_GPLUS] = 'https://apis.google.com/_/+1/fastbutton?url=' . $url;
95
+ }
96
 
97
+ if ( isset( $target_sns[SNS_Count_Cache::REF_SHARE_POCKET] ) && $target_sns[SNS_Count_Cache::REF_SHARE_POCKET] ) {
98
+ $query_urls[SNS_Count_Cache::REF_SHARE_POCKET] = 'http://widgets.getpocket.com/v1/button?v=1&count=horizontal&url=' . $url;
99
+ }
100
+ }
101
 
102
+ return $query_urls;
103
+
104
  }
105
 
106
  /**
107
+ * extract count data from retrieved content
108
  *
109
+ * @since 0.5.1
110
+ */
111
+ private function extract_count( $target_sns, $contents ) {
112
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
113
 
114
+ $sns_counts = array();
115
+
116
+ $extract_date = date_i18n( 'Y/m/d H:i:s' );
 
 
 
 
 
 
 
 
 
117
 
118
+ Common_Util::log( $contents );
119
+
120
+ foreach ( $contents as $sns => $content ) {
121
+
122
+ switch ( $sns ) {
123
+ case SNS_Count_Cache::REF_SHARE_HATEBU:
124
+ if ( isset( $content['data'] ) && empty( $content['error'] ) && is_numeric( $content['data'] ) ) {
125
+ $count = ( int )$content['data'];
126
+ } else if ( empty( $content['data'] ) && empty( $content['error'] ) ) {
127
+ $count = 0;
128
+ } else {
129
+ $count = -1;
130
+ }
131
+
132
+ $sns_counts[SNS_Count_Cache::REF_SHARE_HATEBU] = $count;
133
+ break;
134
+ case SNS_Count_Cache::REF_SHARE_FACEBOOK:
135
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
136
+
137
+ $json = json_decode( $content['data'], true );
138
+
139
+ if ( isset( $json[0]['total_count'] ) && is_numeric( $json[0]['total_count'] ) ) {
140
+ $count = ( int )$json[0]['total_count'];
141
+ } else {
142
+ $count = -1;
143
+ }
144
+ } else {
145
+ $count = -1;
146
+ }
147
+
148
+ $sns_counts[SNS_Count_Cache::REF_SHARE_FACEBOOK] = $count;
149
+ break;
150
+ case SNS_Count_Cache::REF_SHARE_TWITTER:
151
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
152
+ $json = json_decode( $content['data'], true );
153
+
154
+ if ( isset( $json['count'] ) && is_numeric( $json['count'] ) ) {
155
+ $count = ( int )$json['count'];
156
+ } else {
157
+ $count = -1;
158
+ }
159
+ } else {
160
+ $count = -1;
161
+ }
162
+
163
+ $sns_counts[SNS_Count_Cache::REF_SHARE_TWITTER] = $count;
164
+ break;
165
+ case SNS_Count_Cache::REF_SHARE_GPLUS:
166
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
167
+
168
+ $return_code = preg_match( '/\[2,([0-9.]+),\[/', $content['data'], $matches );
169
+
170
+ if ( $return_code && isset( $matches[1] ) && is_numeric( $matches[1] ) ) {
171
+ $count = ( int )$matches[1];
172
+ } else {
173
+ $count = -1;
174
+ }
175
+ } else {
176
+ $count = -1;
177
+ }
178
+
179
+ $sns_counts[SNS_Count_Cache::REF_SHARE_GPLUS] = $count;
180
+ break;
181
+ case SNS_Count_Cache::REF_SHARE_POCKET:
182
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
183
+
184
+ $return_code = preg_match( '/<em\sid=\"cnt\">([0-9]+)<\/em>/i', $content['data'], $matches );
185
+
186
+ if ( $return_code && isset( $matches[1] ) && is_numeric( $matches[1] ) ) {
187
+ $count = ( int )$matches[1];
188
+ } else {
189
+ $count = -1;
190
+ }
191
+ } else {
192
+ $count = -1;
193
+ }
194
+
195
+ $sns_counts[SNS_Count_Cache::REF_SHARE_POCKET] = $count;
196
+ break;
197
+
198
+ }
199
+
200
+ }
201
 
202
+ if ( isset( $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] ) && $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] ) {
203
+
204
+ $total = 0;
205
+
206
+ foreach ( $sns_counts as $sns => $count ) {
207
+ if ( isset( $count ) && $count >= 0 ) {
208
+ $total = $total + $count;
209
+ }
210
+ }
211
+
212
+ $sns_counts[SNS_Count_Cache::REF_SHARE_TOTAL] = ( int )$total;
213
+ }
214
+
215
+ if ( isset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) && $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) {
216
+ $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = $extract_date;
217
  }
218
 
219
+ return $sns_counts;
220
 
221
+ }
222
+
223
 
224
+
225
  }
226
 
227
  ?>
includes/class-share-lazy-cache-engine.php CHANGED
@@ -3,7 +3,6 @@
3
  class-share-lazy-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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -73,15 +72,6 @@ class Share_Lazy_Cache_Engine extends Share_Cache_Engine {
73
  */
74
  private $check_latency = 10;
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
  *
@@ -90,7 +80,7 @@ class Share_Lazy_Cache_Engine extends Share_Cache_Engine {
90
  public function initialize( $options = array() ) {
91
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
92
 
93
- $this->transient_prefix = self::DEF_TRANSIENT_PREFIX;
94
  $this->prime_cron = self::DEF_PRIME_CRON;
95
  $this->execute_cron = self::DEF_EXECUTE_CRON;
96
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
@@ -101,7 +91,7 @@ class Share_Lazy_Cache_Engine extends Share_Cache_Engine {
101
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
102
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
103
  if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
104
- if ( isset( $options['transient_prefix'] ) ) $this->transient_prefix = $options['transient_prefix'];
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'];
@@ -161,12 +151,27 @@ class Share_Lazy_Cache_Engine extends Share_Cache_Engine {
161
 
162
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
163
 
164
- $this->cache( $post_ID, $this->target_sns, $cache_expiration );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
 
166
- if ( ! is_null( $this->delegate ) && method_exists( $this->delegate, 'order_cache' ) ) {
167
- $options = array( 'post_id' => $post_ID );
168
- $this->delegate->order_cache( $this, $options );
169
- }
170
  }
171
 
172
  /**
3
  class-share-lazy-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
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
72
  */
73
  private $check_latency = 10;
74
 
 
 
 
 
 
 
 
 
 
75
  /**
76
  * Initialization
77
  *
80
  public function initialize( $options = array() ) {
81
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
82
 
83
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
84
  $this->prime_cron = self::DEF_PRIME_CRON;
85
  $this->execute_cron = self::DEF_EXECUTE_CRON;
86
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
91
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
92
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
93
  if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
94
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
95
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
96
  if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
97
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
151
 
152
  Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
153
 
154
+ $transient_id = $this->get_cache_key( $post_ID );
155
+
156
+ if ( $post_ID != 'home' ) {
157
+ $url = get_permalink( $post_ID );
158
+ } else {
159
+ $url = home_url( '/' );
160
+ }
161
+
162
+ $options = array(
163
+ 'cache_key' => $transient_id,
164
+ 'post_id' => $post_ID,
165
+ 'target_url' => $url,
166
+ 'target_sns' => $this->target_sns,
167
+ 'cache_expiration' => $cache_expiration
168
+ );
169
+
170
+ // Primary cache
171
+ $this->cache( $options );
172
 
173
+ // Secondary cache
174
+ $this->delegate_cache( $options );
 
 
175
  }
176
 
177
  /**
includes/class-share-rescue-cache-engine.php CHANGED
@@ -3,7 +3,6 @@
3
  class-share-rescue-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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -73,15 +72,6 @@ class Share_Rescue_Cache_Engine extends Share_Cache_Engine {
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.
79
- *
80
- */
81
- protected function __construct() {
82
- Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
83
- }
84
-
85
  /**
86
  * Initialization
87
  *
@@ -90,7 +80,7 @@ class Share_Rescue_Cache_Engine extends Share_Cache_Engine {
90
  public function initialize( $options = array() ) {
91
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
92
 
93
- $this->transient_prefix = self::DEF_TRANSIENT_PREFIX;
94
  $this->prime_cron = self::DEF_PRIME_CRON;
95
  $this->execute_cron = self::DEF_EXECUTE_CRON;
96
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
@@ -101,7 +91,7 @@ class Share_Rescue_Cache_Engine extends Share_Cache_Engine {
101
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
102
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
103
  if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
104
- if ( isset( $options['transient_prefix'] ) ) $this->transient_prefix = $options['transient_prefix'];
105
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
106
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
107
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
@@ -207,11 +197,11 @@ class Share_Rescue_Cache_Engine extends Share_Cache_Engine {
207
  $full_cache_flag = true;
208
  $partial_cache_flag = false;
209
 
210
- foreach ( $this->target_sns as $key => $value ) {
211
 
212
- if ( $value ) {
213
-
214
- $meta_key = $this->meta_key_prefix . strtolower( $key );
215
 
216
  $sns_count = get_post_meta( get_the_ID(), $meta_key, true );
217
 
@@ -226,18 +216,18 @@ class Share_Rescue_Cache_Engine extends Share_Cache_Engine {
226
 
227
  if ( $partial_cache_flag && $full_cache_flag ) {
228
  //full cache
229
- $transient_ID = $this->get_transient_ID( $post_ID );
230
 
231
- if ( false === ( $sns_counts = get_transient( $transient_ID ) ) ) {
232
  if ( $post_ID < $check_range_min || $post_ID > $check_range_max ) {
233
  $no_cache_post_IDs[$post_ID] = 1;
234
  }
235
  }
236
  } else if ( $partial_cache_flag && ! $full_cache_flag ) {
237
  //partial cache
238
- $transient_ID = $this->get_transient_ID( $post_ID );
239
 
240
- if ( false === ( $sns_counts = get_transient( $transient_ID ) ) ) {
241
  if ( $post_ID < $check_range_min || $post_ID > $check_range_max ) {
242
  $no_cache_post_IDs[$post_ID] = 2;
243
  }
@@ -260,36 +250,34 @@ class Share_Rescue_Cache_Engine extends Share_Cache_Engine {
260
 
261
  $rescue_post_IDs = array_slice( $no_cache_post_IDs, 0, $this->posts_per_check, true );
262
 
 
 
263
  Common_Util::log( $rescue_post_IDs );
264
 
265
  foreach ( $rescue_post_IDs as $post_ID => $priority ) {
266
  Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
 
268
- $this->cache( $post_ID, $this->target_sns, $cache_expiration );
269
-
270
- if ( ! is_null( $this->delegate ) && method_exists( $this->delegate, 'order_cache' ) ) {
271
- $options = array( 'post_id' => $post_ID );
272
- $this->delegate->order_cache( $this, $options );
273
- }
274
  }
275
 
276
  }
277
-
278
- /**
279
- * Get and cache data for a given post
280
- *
281
- * @since 0.1.1
282
- */
283
- public function direct_cache( $post_ID ) {
284
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
285
-
286
- $cache_expiration = $this->get_cache_expiration();
287
-
288
- Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
289
-
290
- return $this->cache( $post_ID, $this->target_sns, $cache_expiration );
291
- }
292
-
293
  /**
294
  * Get cache expiration based on current number of total post and page
295
  *
3
  class-share-rescue-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
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
72
  */
73
  private $meta_key_prefix = 'scc_share_count_';
74
 
 
 
 
 
 
 
 
 
 
75
  /**
76
  * Initialization
77
  *
80
  public function initialize( $options = array() ) {
81
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
82
 
83
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
84
  $this->prime_cron = self::DEF_PRIME_CRON;
85
  $this->execute_cron = self::DEF_EXECUTE_CRON;
86
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
91
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
92
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
93
  if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
94
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
95
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
96
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
97
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
197
  $full_cache_flag = true;
198
  $partial_cache_flag = false;
199
 
200
+ foreach ( $this->target_sns as $sns => $active ) {
201
 
202
+ if ( $active ) {
203
+
204
+ $meta_key = $this->get_cache_key( $sns );
205
 
206
  $sns_count = get_post_meta( get_the_ID(), $meta_key, true );
207
 
216
 
217
  if ( $partial_cache_flag && $full_cache_flag ) {
218
  //full cache
219
+ $transient_id = $this->get_cache_key( $post_ID );
220
 
221
+ if ( false === ( $sns_counts = get_transient( $transient_id ) ) ) {
222
  if ( $post_ID < $check_range_min || $post_ID > $check_range_max ) {
223
  $no_cache_post_IDs[$post_ID] = 1;
224
  }
225
  }
226
  } else if ( $partial_cache_flag && ! $full_cache_flag ) {
227
  //partial cache
228
+ $transient_id = $this->get_cache_key( $post_ID );
229
 
230
+ if ( false === ( $sns_counts = get_transient( $transient_id ) ) ) {
231
  if ( $post_ID < $check_range_min || $post_ID > $check_range_max ) {
232
  $no_cache_post_IDs[$post_ID] = 2;
233
  }
250
 
251
  $rescue_post_IDs = array_slice( $no_cache_post_IDs, 0, $this->posts_per_check, true );
252
 
253
+ unset( $no_cache_post_IDs );
254
+
255
  Common_Util::log( $rescue_post_IDs );
256
 
257
  foreach ( $rescue_post_IDs as $post_ID => $priority ) {
258
  Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
259
+
260
+ $transient_id = $this->get_cache_key( $post_ID );
261
+
262
+ $url = get_permalink( $post_ID );
263
+
264
+ $options = array(
265
+ 'cache_key' => $transient_id,
266
+ 'post_id' => $post_ID,
267
+ 'target_url' => $url,
268
+ 'target_sns' => $this->target_sns,
269
+ 'cache_expiration' => $cache_expiration
270
+ );
271
+
272
+ // Primary cache
273
+ $this->cache( $options );
274
 
275
+ // Secondary cache
276
+ $this->delegate_cache( $options );
 
 
 
 
277
  }
278
 
279
  }
280
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  /**
282
  * Get cache expiration based on current number of total post and page
283
  *
includes/class-share-rush-cache-engine.php CHANGED
@@ -3,7 +3,6 @@
3
  class-share-rush-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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -77,16 +76,7 @@ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
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.
84
- *
85
- */
86
- protected function __construct() {
87
- Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
88
- }
89
-
90
  /**
91
  * Initialization
92
  *
@@ -95,7 +85,7 @@ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
95
  public function initialize( $options = array() ) {
96
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
97
 
98
- $this->transient_prefix = self::DEF_TRANSIENT_PREFIX;
99
  $this->prime_cron = self::DEF_PRIME_CRON;
100
  $this->execute_cron = self::DEF_EXECUTE_CRON;
101
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
@@ -106,7 +96,7 @@ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
106
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
107
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
108
  if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
109
- if ( isset( $options['transient_prefix'] ) ) $this->transient_prefix = $options['transient_prefix'];
110
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
111
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
112
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
@@ -154,15 +144,9 @@ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
154
  Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
155
  Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
156
 
157
- $transient_ID = $this->get_transient_ID($this->offset_suffix);
158
 
159
- /*
160
- if ( false === ( $posts_offset = get_transient( $transient_ID ) ) ) {
161
- $posts_offset = 0;
162
- }
163
- */
164
-
165
- if ( false === ( $posts_offset = get_option( $transient_ID ) ) ) {
166
  $posts_offset = 0;
167
  }
168
 
@@ -176,10 +160,8 @@ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
176
  $posts_offset = 0;
177
  }
178
 
179
- //set_transient( $transient_ID, $posts_offset, 3 * $this->check_interval );
180
- update_option( $transient_ID, $posts_offset );
181
 
182
-
183
  }
184
 
185
  /**
@@ -226,12 +208,23 @@ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
226
 
227
  Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
228
 
229
- $this->cache( $post_ID, $this->target_sns, $cache_expiration );
 
 
 
 
 
 
 
 
 
 
230
 
231
- if ( ! is_null( $this->delegate ) && method_exists( $this->delegate, 'order_cache' ) ) {
232
- $options = array( 'post_id' => $post_ID );
233
- $this->delegate->order_cache( $this, $options );
234
- }
 
235
  }
236
  }
237
  wp_reset_postdata();
@@ -307,6 +300,9 @@ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
307
  public function initialize_cache() {
308
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
309
 
 
 
 
310
  }
311
 
312
  /**
@@ -317,9 +313,9 @@ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
317
  public function clear_cache() {
318
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
319
 
320
- $transient_ID = $this->get_transient_ID( $this->offset_suffix );
321
 
322
- delete_option( $transient_ID );
323
 
324
  }
325
 
3
  class-share-rush-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
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
76
  * Term considered as new content
77
  */
78
  private $new_content_term = 3;
79
+
 
 
 
 
 
 
 
 
 
80
  /**
81
  * Initialization
82
  *
85
  public function initialize( $options = array() ) {
86
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
87
 
88
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
89
  $this->prime_cron = self::DEF_PRIME_CRON;
90
  $this->execute_cron = self::DEF_EXECUTE_CRON;
91
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
96
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
97
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
98
  if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
99
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
100
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
101
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
102
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
144
  Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
145
  Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
146
 
147
+ $option_key = $this->get_cache_key($this->offset_suffix);
148
 
149
+ if ( false === ( $posts_offset = get_option( $option_key ) ) ) {
 
 
 
 
 
 
150
  $posts_offset = 0;
151
  }
152
 
160
  $posts_offset = 0;
161
  }
162
 
163
+ update_option( $option_key, $posts_offset );
 
164
 
 
165
  }
166
 
167
  /**
208
 
209
  Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
210
 
211
+ $transient_id = $this->get_cache_key( $post_ID );
212
+
213
+ $url = get_permalink( $post_ID );
214
+
215
+ $options = array(
216
+ 'cache_key' => $transient_id,
217
+ 'post_id' => $post_ID,
218
+ 'target_url' => $url,
219
+ 'target_sns' => $this->target_sns,
220
+ 'cache_expiration' => $cache_expiration
221
+ );
222
 
223
+ // Primary cache
224
+ $this->cache( $options );
225
+
226
+ // Secondary cache
227
+ $this->delegate_cache( $options );
228
  }
229
  }
230
  wp_reset_postdata();
300
  public function initialize_cache() {
301
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
302
 
303
+ $option_key = $this->get_cache_key( $this->offset_suffix );
304
+
305
+ update_option( $option_key, 0 );
306
  }
307
 
308
  /**
313
  public function clear_cache() {
314
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
315
 
316
+ $option_key = $this->get_cache_key( $this->offset_suffix );
317
 
318
+ delete_option( $option_key );
319
 
320
  }
321
 
includes/class-share-second-cache-engine.php CHANGED
@@ -3,7 +3,6 @@
3
  class-share-second-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
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -83,15 +82,6 @@ class Share_Second_Cache_Engine extends Cache_Engine {
83
  */
84
  private $post_types = array( 'post', 'page' );
85
 
86
- /**
87
- * Class constarctor
88
- * Hook onto all of the actions and filters needed by the plugin.
89
- *
90
- */
91
- protected function __construct() {
92
- Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
93
- }
94
-
95
  /**
96
  * Initialization
97
  *
@@ -100,7 +90,7 @@ class Share_Second_Cache_Engine extends Cache_Engine {
100
  public function initialize( $options = array() ) {
101
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
102
 
103
- $this->transient_prefix = self::DEF_TRANSIENT_PREFIX;
104
  $this->prime_cron = self::DEF_PRIME_CRON;
105
  $this->execute_cron = self::DEF_EXECUTE_CRON;
106
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
@@ -109,7 +99,7 @@ class Share_Second_Cache_Engine extends Cache_Engine {
109
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
110
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
111
  if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
112
- if ( isset( $options['transient_prefix'] ) ) $this->transient_prefix = $options['transient_prefix'];
113
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
114
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
115
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
@@ -179,7 +169,17 @@ class Share_Second_Cache_Engine extends Cache_Engine {
179
 
180
  $post_ID = get_the_ID();
181
 
182
- $this->cache( $post_ID, $this->target_sns, 0 );
 
 
 
 
 
 
 
 
 
 
183
 
184
  }
185
  }
@@ -192,28 +192,36 @@ class Share_Second_Cache_Engine extends Cache_Engine {
192
  *
193
  * @since 0.1.1
194
  */
195
- public function cache( $post_ID, $target_sns, $cache_expiration ) {
196
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
197
-
198
- $transient_ID = $this->get_transient_ID( $post_ID );
199
-
200
- if ( false !== ( $sns_counts = get_transient( $transient_ID ) ) ) {
201
- foreach ( $target_sns as $key => $value ) {
 
 
 
202
 
203
- if ( $value ) {
204
-
205
- $meta_key = $this->meta_key_prefix . strtolower( $key );
206
 
207
- if ( ! is_null( $sns_counts[$key] ) && $sns_counts[$key] >= 0 ) {
208
- Common_Util::log( '[' . __METHOD__ . '] meta_key: ' . $meta_key . ' SNS: ' . $key . ' post_ID: ' . $post_ID . ' - ' . $sns_counts[$key] );
209
-
210
- update_post_meta($post_ID, $meta_key, $sns_counts[$key]);
211
- //$data[$key][$post_ID] = $sns_counts[$key];
212
  }
213
  }
214
- }
215
 
216
- }
 
 
 
 
 
 
 
 
217
 
218
  }
219
 
@@ -235,6 +243,18 @@ class Share_Second_Cache_Engine extends Cache_Engine {
235
  */
236
  public function initialize_cache() {
237
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
 
 
 
 
 
 
 
 
 
 
 
 
238
 
239
  $query_args = array(
240
  'post_type' => $this->post_types,
@@ -252,12 +272,12 @@ class Share_Second_Cache_Engine extends Cache_Engine {
252
 
253
  $post_ID = get_the_ID();
254
 
255
- foreach ( $this->target_sns as $key => $value ) {
256
 
257
- $meta_key = $this->meta_key_prefix . strtolower( $key );
258
 
259
- if ( $value ) {
260
- update_post_meta($post_ID, $meta_key, -1);
261
  }
262
  }
263
  }
@@ -272,7 +292,11 @@ class Share_Second_Cache_Engine extends Cache_Engine {
272
  */
273
  public function clear_cache() {
274
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
275
-
 
 
 
 
276
  $query_args = array(
277
  'post_type' => $this->post_types,
278
  'post_status' => 'publish',
@@ -289,18 +313,18 @@ class Share_Second_Cache_Engine extends Cache_Engine {
289
 
290
  $post_ID = get_the_ID();
291
 
292
- foreach ( $this->target_sns as $key => $value ) {
293
 
294
- $meta_key = $this->meta_key_prefix . strtolower( $key );
295
 
296
- if ( $value ) {
297
- delete_post_meta($post_ID, $meta_key);
298
  }
299
  }
300
  }
301
  }
302
  wp_reset_postdata();
303
- }
304
 
305
  }
306
 
3
  class-share-second-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
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
82
  */
83
  private $post_types = array( 'post', 'page' );
84
 
 
 
 
 
 
 
 
 
 
85
  /**
86
  * Initialization
87
  *
90
  public function initialize( $options = array() ) {
91
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
92
 
93
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
94
  $this->prime_cron = self::DEF_PRIME_CRON;
95
  $this->execute_cron = self::DEF_EXECUTE_CRON;
96
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
99
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
100
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
101
  if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
102
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
103
  if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
104
  if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
105
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
169
 
170
  $post_ID = get_the_ID();
171
 
172
+ $transient_id = $this->get_cache_key( $post_ID );
173
+
174
+ $url = get_permalink( $post_ID );
175
+
176
+ $options = array(
177
+ 'cache_key' => $transient_id,
178
+ 'post_id' => $post_ID,
179
+ 'target_sns' => $this->target_sns
180
+ );
181
+
182
+ $this->cache( $options );
183
 
184
  }
185
  }
192
  *
193
  * @since 0.1.1
194
  */
195
+ public function cache( $options = array() ) {
196
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
197
+
198
+ $transient_id = $options['cache_key'];
199
+ $target_sns = $options['target_sns'];
200
+ $post_ID = $options['post_id'];
201
+
202
+ if ( $post_ID != 'home' ) {
203
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
204
+ foreach ( $target_sns as $sns => $active ) {
205
 
206
+ if ( $active ) {
 
 
207
 
208
+ $meta_key = $this->get_cache_key( $sns );
209
+
210
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
211
+ update_post_meta( $post_ID, $meta_key, $sns_counts[$sns] );
212
+ }
213
  }
214
  }
 
215
 
216
+ }
217
+ } else {
218
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
219
+
220
+ $option_key = $this->get_cache_key( 'home' );
221
+
222
+ update_option( $option_key, $sns_counts );
223
+ }
224
+ }
225
 
226
  }
227
 
243
  */
244
  public function initialize_cache() {
245
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
246
+
247
+ $option_key = $this->get_cache_key( 'home' );
248
+
249
+ $sns_counts = array();
250
+
251
+ foreach ( $this->target_sns as $sns => $active ) {
252
+ if ( $active ) {
253
+ $sns_counts[$sns] = -1;
254
+ }
255
+ }
256
+
257
+ update_option( $option_key, $sns_counts );
258
 
259
  $query_args = array(
260
  'post_type' => $this->post_types,
272
 
273
  $post_ID = get_the_ID();
274
 
275
+ foreach ( $this->target_sns as $sns => $active ) {
276
 
277
+ $meta_key = $this->get_cache_key( $sns );
278
 
279
+ if ( $active ) {
280
+ update_post_meta( $post_ID, $meta_key, -1 );
281
  }
282
  }
283
  }
292
  */
293
  public function clear_cache() {
294
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
295
+
296
+ $option_key = $this->get_cache_key( 'home' );
297
+
298
+ delete_option( $option_key );
299
+
300
  $query_args = array(
301
  'post_type' => $this->post_types,
302
  'post_status' => 'publish',
313
 
314
  $post_ID = get_the_ID();
315
 
316
+ foreach ( $this->target_sns as $sns => $active ) {
317
 
318
+ $meta_key = $this->get_cache_key( $sns );
319
 
320
+ if ( $active ) {
321
+ delete_post_meta( $post_ID, $meta_key );
322
  }
323
  }
324
  }
325
  }
326
  wp_reset_postdata();
327
+ }
328
 
329
  }
330
 
includes/class-wp-cron-util.php CHANGED
@@ -3,7 +3,6 @@
3
  class-wp-cron-util.php
4
 
5
  Description: This class is a utility for WP-Cron
6
- Version: 0.3.0
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
3
  class-wp-cron-util.php
4
 
5
  Description: This class is a utility for WP-Cron
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
includes/download.php CHANGED
@@ -3,7 +3,6 @@
3
  download.php
4
 
5
  Description: Download page implementation
6
- Version: 0.4.0
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
@@ -34,44 +33,47 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
34
 
35
  $abs_path = WP_PLUGIN_DIR . '/sns-count-cache/data/sns-count-cache-data.csv';
36
 
37
- if ( isset( $_POST['_wpnonce'] ) && $_POST['_wpnonce'] ) {
38
- if ( check_admin_referer( 'mynonce', '_wpnonce' ) ) {
39
-
40
- if ( isset( $_POST["download_data"] ) && $_POST["download_data"] === 'Download' ) {
41
 
42
- if ( file_exists( $abs_path ) ) {
43
 
44
- $file_name = "sns-count-cache_data_" . date_i18n( 'YmdHis' ) . ".csv";
45
 
46
- header( 'Content-Type: application/octet-stream' );
47
- header( 'Content-Disposition: attachment; filename=' . $file_name );
48
 
49
- while ( ob_get_level() > 0 ) {
50
- ob_end_clean();
51
- }
52
 
53
- ob_start();
54
 
55
- if ( $fp = fopen( $abs_path, 'rb' ) ) {
56
 
57
- while( ! feof( $fp ) && ( connection_status() == 0 ) ) {
58
- echo fread( $fp, 8192 );
59
- ob_flush();
60
- }
61
 
62
- ob_flush();
63
- fclose($fp);
64
 
65
- }
66
 
67
- ob_end_clean();
68
- die();
69
-
70
- } else {
71
- echo 'There is no exported file.';
72
- }
73
  }
74
- }
75
- }
 
 
 
 
 
 
76
 
77
  ?>
3
  download.php
4
 
5
  Description: Download page implementation
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
33
 
34
  $abs_path = WP_PLUGIN_DIR . '/sns-count-cache/data/sns-count-cache-data.csv';
35
 
36
+ if ( isset( $_POST['_wpnonce'] ) && $_POST['_wpnonce'] && check_admin_referer( 'mynonce', '_wpnonce' ) ) {
37
+
38
+ if ( isset( $_POST["download_data"] ) && $_POST["download_data"] === __( 'Download', SNS_Count_Cache::DOMAIN ) ) {
 
39
 
40
+ if ( file_exists( $abs_path ) ) {
41
 
42
+ $file_name = "sns-count-cache_data_" . date_i18n( 'YmdHis' ) . ".csv";
43
 
44
+ header( 'Content-Type: application/octet-stream' );
45
+ header( 'Content-Disposition: attachment; filename=' . $file_name );
46
 
47
+ while ( ob_get_level() > 0 ) {
48
+ ob_end_clean();
49
+ }
50
 
51
+ ob_start();
52
 
53
+ if ( $fp = fopen( $abs_path, 'rb' ) ) {
54
 
55
+ while( ! feof( $fp ) && ( connection_status() == 0 ) ) {
56
+ echo fread( $fp, 8192 );
57
+ ob_flush();
58
+ }
59
 
60
+ ob_flush();
61
+ fclose( $fp );
62
 
63
+ }
64
 
65
+ ob_end_clean();
66
+
67
+ } else {
68
+ echo 'There is no exported file.';
 
 
69
  }
70
+ }
71
+
72
+ } else {
73
+ status_header( '403' );
74
+ echo 'Forbidden';
75
+ }
76
+
77
+ die();
78
 
79
  ?>
includes/interface-cache-order.php CHANGED
@@ -3,7 +3,6 @@
3
  interface-cache-order.php
4
 
5
  Description: This is a interface
6
- Version: 0.4.0
7
  Author: Daisuke Maruyama
8
  Author URI: http://marubon.info/
9
  License: GPL2 or later
@@ -12,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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
3
  interface-cache-order.php
4
 
5
  Description: This is a interface
 
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
js/jquery.scc-cache-info.js ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ jquery.scc-cache-info.js
3
+ Author: Daisuke Maruyama
4
+ Author URI: http://marubon.info/
5
+ License: GPL2 or later
6
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
7
+ */
8
+ ;jQuery(document).ready(function($){
9
+ return $('#scc-dashboard').each(function(){
10
+ $("span[data-scc]").css('display', 'none');
11
+ $.ajax({
12
+ url: scc.endpoint + '?action=' + scc.action + '&nonce=' + scc.nonce,
13
+ dataType: 'jsonp',
14
+ success: function(res){
15
+ if(res){
16
+
17
+ $("span[data-scc='pc']").text(res.post_count);
18
+ $("span[data-scc='pfcc']").text(res.primary.full_cache_count);
19
+ $("span[data-scc='ppcc']").text(res.primary.partial_cache_count);
20
+ $("span[data-scc='pncc']").text(res.primary.no_cache_count);
21
+ $("span[data-scc='pcs']").text(res.primary.cache_status);
22
+
23
+ $("span[data-scc='sfcc']").text(res.secondary.full_cache_count);
24
+ $("span[data-scc='spcc']").text(res.secondary.partial_cache_count);
25
+ $("span[data-scc='sncc']").text(res.secondary.no_cache_count);
26
+ $("span[data-scc='scs']").text(res.secondary.cache_status);
27
+
28
+ $("span[data-scc='twitter']").text(res.share_count.twitter);
29
+ $("span[data-scc='facebook']").text(res.share_count.facebook);
30
+ $("span[data-scc='gplus']").text(res.share_count.gplus);
31
+ $("span[data-scc='pocket']").text(res.share_count.pocket);
32
+ $("span[data-scc='hatebu']").text(res.share_count.hatebu);
33
+ $("span[data-scc='total']").text(res.share_count.total);
34
+
35
+ $(".loading").css('display', 'none');
36
+ $("span[data-scc]").fadeIn();
37
+ } else {
38
+ $("span[data-scc]").text('?');
39
+ }
40
+ },
41
+ error: function(res){
42
+ $("span[data-scc]").text('?');
43
+ }
44
+ });
45
+ });
46
+ });
js/jquery.scc-cache-info.min.js ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ ;jQuery(document).ready(function(a){return a("#scc-dashboard").each(function(){a("span[data-scc]").css("display","none");a.ajax({url:scc.endpoint+"?action="+scc.action+"&nonce="+scc.nonce,dataType:"jsonp",success:function(b){b?(a("span[data-scc='pc']").text(b.post_count),a("span[data-scc='pfcc']").text(b.primary.full_cache_count),a("span[data-scc='ppcc']").text(b.primary.partial_cache_count),a("span[data-scc='pncc']").text(b.primary.no_cache_count),a("span[data-scc='pcs']").text(b.primary.cache_status),
2
+ a("span[data-scc='sfcc']").text(b.secondary.full_cache_count),a("span[data-scc='spcc']").text(b.secondary.partial_cache_count),a("span[data-scc='sncc']").text(b.secondary.no_cache_count),a("span[data-scc='scs']").text(b.secondary.cache_status),a("span[data-scc='twitter']").text(b.share_count.twitter),a("span[data-scc='facebook']").text(b.share_count.facebook),a("span[data-scc='gplus']").text(b.share_count.gplus),a("span[data-scc='pocket']").text(b.share_count.pocket),a("span[data-scc='hatebu']").text(b.share_count.hatebu),
3
+ a("span[data-scc='total']").text(b.share_count.total),a(".loading").css("display","none"),a("span[data-scc]").fadeIn()):a("span[data-scc]").text("?")},error:function(b){a("span[data-scc]").text("?")}})})});
js/jquery.sns-count-cache.js DELETED
@@ -1,22 +0,0 @@
1
- jQuery(document).ready(function($) {
2
- //クリックしたときのファンクションをまとめて指定
3
- $('.tab li').click(function() {
4
-
5
- //.index()を使いクリックされたタブが何番目かを調べ、
6
- //indexという変数に代入します。
7
- var index = $('.tab li').index(this);
8
-
9
- //コンテンツを一度すべて非表示にし、
10
- $('.content li').css('display','none');
11
-
12
- //クリックされたタブと同じ順番のコンテンツを表示します。
13
- $('.content li').eq(index).css('display','block');
14
-
15
- //一度タブについているクラスselectを消し、
16
- $('.tab li').removeClass('select');
17
-
18
- //クリックされたタブのみにクラスselectをつけます。
19
- $(this).addClass('select')
20
- });
21
- return this;
22
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -3,12 +3,12 @@ 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
 
11
- This plugin gets and caches SNS share count in the background, and provides functions to access the cache.
12
 
13
  == Description ==
14
 
@@ -89,6 +89,13 @@ There are no questions.
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
 
@@ -98,6 +105,8 @@ The following functions are deprecated.
98
  * get_scc_pocket()
99
  * get_scc_hatebu()
100
 
 
 
101
  == Arbitrary section ==
102
 
103
 
3
  Donate link:
4
  Tags: performance, SNS, social, cache, share
5
  Requires at least: 3.7
6
+ Tested up to: 4.2.2
7
+ Stable tag: 0.6.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ This plugin gets and caches SNS share count in the background, and help you to shorten page loading time by application of the cache.
12
 
13
  == Description ==
14
 
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
+ = 0.6.0 =
93
+ * Added: function to cache share count for home page.
94
+ * Improved: Each retrieval time of SNS count is shortened.
95
+ * Improved: loading time of dashboard page is shortened using ajax loading technique.
96
+ * Fixed: SNS count of facebook can be 0.
97
+ * Fixed: "PHP Notice: has_cap..." is output.
98
+
99
  == Upgrade Notice ==
100
  The following functions are deprecated.
101
 
105
  * get_scc_pocket()
106
  * get_scc_hatebu()
107
 
108
+ Please reconfigure your parameter again because current setting is reset by this upgrade.
109
+
110
  == Arbitrary section ==
111
 
112
 
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
screenshot-3.png CHANGED
Binary file
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.5.0
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
@@ -11,7 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11
 
12
  /*
13
 
14
- Copyright (C) 2014 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
@@ -32,6 +32,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
 
@@ -40,13 +42,12 @@ require_once ( dirname( __FILE__ ) . '/includes/class-share-base-cache-engine.ph
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' );
@@ -59,7 +60,7 @@ require_once ( dirname( __FILE__ ) . '/includes/class-follow-crawler.php' );
59
 
60
  if ( ! class_exists( 'SNS_Count_Cache' ) ) {
61
 
62
- class SNS_Count_Cache implements Cache_Order {
63
 
64
  /**
65
  * Prefix of share cache ID
@@ -119,12 +120,12 @@ class SNS_Count_Cache implements Cache_Order {
119
  /**
120
  * Type of data export
121
  */
122
- const OPT_COMMON_DATA_EXPORT_MANUAL = 0;
123
 
124
  /**
125
  * Type of data export
126
  */
127
- const OPT_COMMON_DATA_EXPORT_AUTO = 1;
128
 
129
  /**
130
  * File name of data export
@@ -144,22 +145,22 @@ class SNS_Count_Cache implements Cache_Order {
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
@@ -170,66 +171,106 @@ class SNS_Count_Cache implements Cache_Order {
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
  */
177
- const DB_SHARE_CUSTOM_POST_TYPES = 'scc_custom_post_types';
178
 
179
  /**
180
  * Option key for check interval of share base cache
181
  */
182
- const DB_SHARE_CHECK_INTERVAL = 'scc_check_interval';
183
 
184
  /**
185
  * Option key for number of posts to check at a time for share base cache
186
  */
187
- const DB_SHARE_POSTS_PER_CHECK = 'scc_posts_per_check';
188
 
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
196
  */
197
- const DB_SHARE_NEW_CONTENT_TERM = 'scc_new_content_term';
198
 
199
  /**
200
  * Option key of cache target for share base cache
201
  */
202
- const DB_SHARE_CACHE_TARGET = 'scc_cache_target';
203
 
204
  /**
205
  * Option key of cache target for follow base cache
206
  */
207
- const DB_FOLLOW_CACHE_TARGET = 'scc_follow_cache_target';
208
 
209
  /**
210
  * Option key of checking interval for follow base cache
211
  */
212
- const DB_FOLLOW_CHECK_INTERVAL = 'scc_follow_check_interval';
213
 
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
@@ -339,7 +380,7 @@ class SNS_Count_Cache implements Cache_Order {
339
  /**
340
  * Plugin version, used for cache-busting of style and script file references.
341
  */
342
- private $version = '0.4.0';
343
 
344
  /**
345
  * Instances of crawler
@@ -409,22 +450,17 @@ class SNS_Count_Cache implements Cache_Order {
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
@@ -445,6 +481,26 @@ class SNS_Count_Cache implements Cache_Order {
445
  * Extended max execution time
446
  */
447
  private $extended_max_execution_time = 300;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
 
449
  /**
450
  * Instance
@@ -457,18 +513,24 @@ class SNS_Count_Cache implements Cache_Order {
457
  */
458
  private function __construct() {
459
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
460
-
461
  //load_plugin_textdomain(self::DOMAIN, false, basename(dirname( __FILE__ )) . '/languages');
462
 
463
  register_activation_hook( __FILE__, array( $this, 'activate_plugin' ) );
464
  register_deactivation_hook( __FILE__, array( $this, 'deactivate_plugin' ) );
465
 
466
- add_action( 'admin_menu', array($this, 'action_admin_menu' ) );
467
 
468
  add_action( 'admin_print_styles', array( $this, 'register_admin_styles' ) );
469
- add_action( 'admin_enqueue_scripts', array($this, 'register_admin_scripts' ) );
470
-
471
- add_action( 'plugins_loaded', array( $this, 'initialize' ) );
 
 
 
 
 
 
472
  }
473
 
474
  /**
@@ -477,14 +539,37 @@ class SNS_Count_Cache implements Cache_Order {
477
  * @since 0.1.1
478
  */
479
  public static function get_instance() {
480
-
481
- $class_name = get_called_class();
482
- if ( ! self::$instance ) {
483
- self::$instance = new $class_name();
484
- }
485
 
 
 
 
 
486
  return self::$instance;
487
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
 
489
  /**
490
  * Initialization
@@ -493,67 +578,112 @@ class SNS_Count_Cache implements Cache_Order {
493
  */
494
  public function initialize() {
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;
528
- $this->share_base_cache_target[self::REF_SHARE_GPLUS] = true;
529
- if ( Common_Util::extension_loaded_php_xml() ) {
530
- $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] = true;
531
- $this->share_base_cache_target[self::REF_SHARE_POCKET] = true;
532
- }
533
  $this->share_base_cache_target[self::REF_SHARE_HATEBU] = true;
534
  }
535
 
536
  $this->share_base_cache_target[self::REF_CRAWL_DATE] = true;
537
- $this->share_base_cache_target[self::REF_SHARE_TOTAL] = true;
538
-
539
- if ( ! $this->follow_base_cache_target ) {
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();
 
557
 
558
  // Share base cache engine
559
  $options = array(
@@ -606,7 +736,7 @@ class SNS_Count_Cache implements Cache_Order {
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
  );
@@ -614,6 +744,7 @@ class SNS_Count_Cache implements Cache_Order {
614
  $this->cache_engines[self::REF_SHARE_2ND] = Share_Second_Cache_Engine::get_instance();
615
  $this->cache_engines[self::REF_SHARE_2ND]->initialize( $options );
616
 
 
617
  // Share rescue cache engine
618
  $options = array(
619
  'delegate' => $this,
@@ -628,6 +759,7 @@ class SNS_Count_Cache implements Cache_Order {
628
 
629
  $this->cache_engines[self::REF_SHARE_RESCUE] = Share_Rescue_Cache_Engine::get_instance();
630
  $this->cache_engines[self::REF_SHARE_RESCUE]->initialize( $options );
 
631
 
632
  // Follow base cache engine
633
  $options = array(
@@ -635,8 +767,7 @@ class SNS_Count_Cache implements Cache_Order {
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();
@@ -659,7 +790,7 @@ class SNS_Count_Cache implements Cache_Order {
659
  'crawler' => $this->crawlers[self::REF_FOLLOW],
660
  'target_sns' => $this->follow_base_cache_target,
661
  'check_interval' => self::OPT_FOLLOW_2ND_CHECK_INTERVAL,
662
- 'meta_key_prefix' => self::OPT_FOLLOW_2ND_META_KEY_PREFIX
663
  );
664
 
665
  $this->cache_engines[self::REF_FOLLOW_2ND] = Follow_Second_Cache_Engine::get_instance();
@@ -668,7 +799,6 @@ class SNS_Count_Cache implements Cache_Order {
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,
@@ -704,12 +834,7 @@ class SNS_Count_Cache implements Cache_Order {
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 ) {
@@ -718,7 +843,15 @@ class SNS_Count_Cache implements Cache_Order {
718
  $this->original_max_execution_time = 30;
719
  }
720
 
721
- }
 
 
 
 
 
 
 
 
722
 
723
  /**
724
  * Registers and enqueues admin-specific styles.
@@ -735,8 +868,8 @@ class SNS_Count_Cache implements Cache_Order {
735
  $screen = get_current_screen();
736
 
737
  if ( in_array( $screen->id, $this->plugin_screen_hook_suffix ) ) {
738
- wp_enqueue_style( self::DOMAIN .'-admin-style-1' , plugins_url( ltrim( '/css/sns-count-cache.css', '/' ), __FILE__) );
739
- wp_enqueue_style( self::DOMAIN .'-admin-style-2' , plugins_url( ltrim( '/css/prettify.css', '/' ), __FILE__ ) );
740
  }
741
  }
742
 
@@ -755,8 +888,10 @@ class SNS_Count_Cache implements Cache_Order {
755
  $screen = get_current_screen();
756
 
757
  if ( in_array( $screen->id, $this->plugin_screen_hook_suffix ) ) {
758
- wp_enqueue_script( self::DOMAIN . '-admin-script-1' , plugins_url( ltrim( '/js/jquery.sns-count-cache.js', '/' ) , __FILE__ ), array( 'jquery' ) );
759
- wp_enqueue_script( self::DOMAIN . '-admin-script-2' , plugins_url( ltrim( '/js/prettify.js', '/' ) , __FILE__ ), array( 'jquery' ) );
 
 
760
  }
761
  }
762
 
@@ -765,7 +900,7 @@ class SNS_Count_Cache implements Cache_Order {
765
  *
766
  * @since 0.1.1
767
  */
768
- function activate_plugin() {
769
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
770
 
771
  $this->initialize();
@@ -803,7 +938,7 @@ class SNS_Count_Cache implements Cache_Order {
803
  *
804
  * @since 0.1.1
805
  */
806
- function deactivate_plugin() {
807
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
808
 
809
  set_time_limit( $this->extended_max_execution_time );
@@ -813,13 +948,42 @@ class SNS_Count_Cache implements Cache_Order {
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
 
@@ -843,17 +1007,42 @@ class SNS_Count_Cache implements Cache_Order {
843
  *
844
  * @since 0.1.0
845
  */
846
- public function action_admin_menu() {
847
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
848
 
849
- $this->plugin_screen_hook_suffix[] = add_menu_page( 'SNS Count Cache', 'SNS Count Cache', 8, 'scc-dashboard', array( $this, 'dashboard_page' ), 'dashicons-share' );
850
- $this->plugin_screen_hook_suffix[] = add_submenu_page( 'scc-dashboard', 'Dashboard', 'Dashboard', 8, 'scc-dashboard', array( $this, 'dashboard_page' ) );
851
- $this->plugin_screen_hook_suffix[] = add_submenu_page( 'scc-dashboard', 'Cache Status', 'Cache Status', 8, 'scc-cache-status', array( $this, 'cache_status_page' ) );
852
- $this->plugin_screen_hook_suffix[] = add_submenu_page( 'scc-dashboard', 'Share Count', 'Share Count', 8, 'scc-share-count', array( $this, 'share_count_page' ) );
853
- $this->plugin_screen_hook_suffix[] = add_submenu_page( 'scc-dashboard', 'Setting', 'Setting', 8, 'scc-setting', array( $this, 'setting_page' ) );
854
- $this->plugin_screen_hook_suffix[] = add_submenu_page( 'scc-dashboard', 'Help', 'Help', 8, 'scc-help', array( $this, 'help_page' ) );
 
855
  }
856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
857
  /**
858
  * Option page implementation
859
  *
@@ -899,24 +1088,22 @@ class SNS_Count_Cache implements Cache_Order {
899
  public function help_page() {
900
  include_once( dirname( __FILE__ ) . '/includes/admin-help.php' );
901
  }
902
-
903
- /**
904
- * Return type of dynamic cache processing
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
  /**
915
  * Cache share count for a given post ID
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 );
@@ -927,7 +1114,7 @@ class SNS_Count_Cache implements Cache_Order {
927
  *
928
  * @since 0.2.0
929
  */
930
- public function retrieve_follow_cache() {
931
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
932
 
933
  return $this->cache_engines[self::REF_FOLLOW_BASE]->direct_cache();
@@ -938,7 +1125,7 @@ class SNS_Count_Cache implements Cache_Order {
938
  *
939
  * @since 0.2.0
940
  */
941
- public function reserve_share_cache( $post_ID ) {
942
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
943
 
944
  $this->cache_engines[self::REF_SHARE_LAZY]->prime_cache( $post_ID );
@@ -949,34 +1136,12 @@ class SNS_Count_Cache implements Cache_Order {
949
  *
950
  * @since 0.4.0
951
  */
952
- public function reserve_follow_cache() {
953
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
954
 
955
  $this->cache_engines[self::REF_FOLLOW_LAZY]->prime_cache();
956
  }
957
 
958
- /**
959
- * Return cache target of share count
960
- *
961
- * @since 0.2.0
962
- */
963
- public function get_share_base_cache_target() {
964
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
965
-
966
- return $this->share_base_cache_target;
967
- }
968
-
969
- /**
970
- * Return cache target of follow count
971
- *
972
- * @since 0.4.0
973
- */
974
- public function get_follow_base_cache_target() {
975
- Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
976
-
977
- return $this->follow_base_cache_target;
978
- }
979
-
980
  /**
981
  * Method call between one cache engine and another
982
  *
@@ -987,34 +1152,40 @@ class SNS_Count_Cache implements Cache_Order {
987
 
988
  switch ( get_class( $engine ) ) {
989
  case 'Share_Lazy_Cache_Engine':
990
- $this->cache_engines[self::REF_SHARE_2ND]->cache( $options['post_id'], $this->share_base_cache_target, NULL );
991
  break;
992
  case 'Share_Rescue_Cache_Engine':
993
- $this->cache_engines[self::REF_SHARE_2ND]->cache( $options['post_id'], $this->share_base_cache_target, NULL );
994
  break;
995
  case 'Share_Base_Cache_Engine':
996
- $this->cache_engines[self::REF_SHARE_2ND]->cache( $options['post_id'], $this->share_base_cache_target, NULL );
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
  }
1010
-
 
 
 
 
 
1011
  private function pagination( $numpages = '', $pagerange = '', $paged='', $inherit_param = true ) {
 
1012
 
1013
  if ( empty( $pagerange ) ) {
1014
  $pagerange = 2;
1015
  }
1016
 
1017
- if ( $paged == '' ) {
1018
  global $paged;
1019
 
1020
  if ( empty( $paged ) ) {
@@ -1022,7 +1193,7 @@ class SNS_Count_Cache implements Cache_Order {
1022
  }
1023
  }
1024
 
1025
- if ( $numpages == '' ) {
1026
  global $wp_query;
1027
 
1028
  $numpages = $wp_query->max_num_pages;
@@ -1032,318 +1203,690 @@ class SNS_Count_Cache implements Cache_Order {
1032
  }
1033
  }
1034
 
1035
- if ( $inherit_param ) {
1036
- $pagination_args = array(
1037
- 'base' => get_pagenum_link(1) . '%_%',
1038
- 'format' => '&paged=%#%',
1039
- 'total' => $numpages,
1040
- 'current' => $paged,
1041
- 'show_all' => False,
1042
- 'end_size' => 1,
1043
- 'mid_size' => $pagerange,
1044
- 'prev_next' => True,
1045
- 'prev_text' => __('&laquo;'),
1046
- 'next_text' => __('&raquo;'),
1047
- 'type' => 'plain',
1048
- 'add_args' => false,
1049
- 'add_fragment' => ''
1050
- );
1051
- } else {
1052
-
1053
- $url = parse_url( get_pagenum_link(1) );
1054
- $base_url = $url['scheme'] . '://' . $url['host'] . $url['path'];
1055
 
1056
- parse_str ( $url['query'], $query );
 
 
1057
 
1058
- $base_url = $base_url . '?page=' . $query['page'];
1059
-
1060
- $pagination_args = array(
1061
- 'base' => $base_url . '%_%',
1062
- 'format' => '&paged=%#%',
1063
- 'total' => $numpages,
1064
- 'current' => $paged,
1065
- 'show_all' => False,
1066
- 'end_size' => 1,
1067
- 'mid_size' => $pagerange,
1068
- 'prev_next' => True,
1069
- 'prev_text' => __('&laquo;'),
1070
- 'next_text' => __('&raquo;'),
1071
- 'type' => 'plain',
1072
- 'add_args' => false,
1073
- 'add_fragment' => ''
1074
  );
1075
-
 
 
 
 
 
 
 
 
 
1076
  }
1077
-
1078
- $paginate_links = paginate_links($pagination_args);
1079
-
1080
  if ( $paginate_links ) {
1081
  echo "<nav class='pagination'>";
1082
  echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
1083
  echo $paginate_links;
1084
  echo "</nav>";
1085
  }
1086
-
1087
  }
1088
-
1089
- }
1090
 
1091
- SNS_Count_Cache::get_instance();
 
 
 
 
 
 
1092
 
1093
- /**
1094
- * Get share count from cache
1095
- *
1096
- * @since 0.4.0
1097
- */
1098
- function scc_get_share( $options = array( 'id' => '', 'url' => '', 'sns' => '' ) ) {
1099
- $transient_ID ='';
1100
- $sns_key = '';
1101
- $sns_counts = array();
1102
-
1103
- if ( $options['id'] ) {
1104
- $post_ID = $options['id'];
1105
- } else {
1106
- $post_ID = get_the_ID();
1107
- }
1108
-
1109
- if ( $options['sns'] ) {
1110
- $sns_key = $options['sns'];
1111
- }
1112
-
1113
- $transient_ID = SNS_Count_Cache::OPT_SHARE_BASE_TRANSIENT_PREFIX . $post_ID;
1114
-
1115
- if ( false !== ( $sns_counts = get_transient( $transient_ID ) ) ) {
1116
- if ( $sns_key ) {
1117
-
1118
- $sns_count = $sns_counts[$sns_key];
1119
-
1120
- if ( isset( $sns_count ) && $sns_count >= 0 ) {
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
-
1128
- foreach ( $sns_counts as $key => $value ) {
1129
- if ( isset( $value ) && $value >= 0 ) {
1130
- $sns_counts[$key] = $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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];
1145
  } else {
1146
- $base_cache_target = $sns_count_cache->get_share_base_cache_target();
1147
-
1148
- foreach ( $base_cache_target as $key => $value ) {
1149
- if ( $value ) {
1150
- $sns_counts[$key] = 0;
1151
  }
1152
  }
 
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;
 
1168
  return $sns_counts[$sns_key];
1169
- } else {
1170
- $base_cache_target = $sns_count_cache->get_share_base_cache_target();
1171
-
1172
- foreach ( $base_cache_target as $key => $value ) {
1173
- if ( $value ) {
1174
- $sns_counts[$key] = 0;
1175
  }
1176
  }
 
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 );
1184
-
1185
- $sns_count = get_post_meta( $post_ID, $meta_key, true );
1186
-
1187
- if ( isset( $sns_count ) && $sns_count >= 0) {
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();
1195
-
1196
- foreach ( $base_cache_target as $key => $value ) {
1197
- if ( $value ) {
1198
- $meta_key = SNS_Count_Cache::OPT_SHARE_2ND_META_KEY_PREFIX . strtolower( $key );
1199
-
1200
- $sns_count = get_post_meta( $post_ID, $meta_key, true );
1201
-
1202
- if ( isset( $sns_count ) && $sns_count >= 0 ) {
1203
- $sns_counts[$key] = $sns_count;
1204
- } else {
1205
- $sns_counts[$key] = 0;
 
 
1206
  }
1207
  }
1208
  }
1209
- return $sns_counts;
 
1210
  }
1211
  break;
1212
- }
1213
- }
1214
- }
1215
-
1216
-
1217
- /**
1218
- * Get follow count from cache
1219
- *
1220
- * @since 0.4.0
1221
- */
1222
- function scc_get_follow( $options = array( 'id' => '', 'sns' => '' ) ) {
1223
- $transient_ID ='';
1224
- $sns_key = '';
1225
- $sns_followers = array();
1226
-
1227
- if ( $options['id'] ) {
1228
- $post_ID = $options['id'];
1229
- } else {
1230
- $post_ID = get_the_ID();
1231
- }
1232
-
1233
- if ( $options['sns'] ) {
1234
- $sns_key = $options['sns'];
1235
- }
1236
-
1237
- $transient_ID = SNS_Count_Cache::OPT_FOLLOW_BASE_TRANSIENT_PREFIX . 'follow';
1238
-
1239
- if ( false !== ( $sns_followers = get_transient( $transient_ID ) ) ) {
1240
- if ( $sns_key ) {
1241
- $sns_follower = $sns_followers[$sns_key];
1242
-
1243
- if ( isset( $sns_follower ) && $sns_follower >= 0 ){
1244
- $sns_followers[$sns_key] = $sns_follower;
1245
- } else {
1246
- $sns_followers[$sns_key] = 0;
1247
- }
1248
-
1249
- return $sns_followers[$sns_key];
1250
- } else {
1251
- foreach ( $sns_followers as $key => $value ) {
1252
- if ( isset( $value ) && $value >= 0 ) {
1253
- $sns_followers[$key] = $value;
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];
1268
- } else {
1269
- $base_cache_target = $sns_count_cache->get_follow_base_cache_target();
1270
-
1271
- foreach ( $base_cache_target as $key => $value ) {
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];
1283
  } else {
 
 
 
 
 
 
 
 
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;
1291
- return $sns_followers[$sns_key];
1292
- } else {
1293
- $base_cache_target = $sns_count_cache->get_follow_base_cache_target();
1294
-
1295
- foreach ( $base_cache_target as $key => $value ) {
1296
- if ( $value ) {
1297
- $sns_followers[$key] = 0;
1298
- }
1299
- }
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();
1319
-
1320
- foreach ( $base_cache_target as $key => $value ) {
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 {
1329
- $sns_followers[$key] = 0;
1330
- }
1331
  }
1332
  }
1333
- return $sns_followers;
1334
- }
 
1335
  break;
1336
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1337
  }
1338
- }
1339
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1340
 
1341
  /**
1342
  * Get share count from cache (Hatena Bookmark).
1343
  *
1344
  * @since 0.4.0
1345
  */
1346
- function scc_get_share_hatebu( $options = array( 'id' => '', 'url' => '' ) ) {
1347
 
1348
  $options['sns'] = SNS_Count_Cache::REF_SHARE_HATEBU;
1349
  return scc_get_share( $options );
@@ -1354,7 +1897,7 @@ function scc_get_share_hatebu( $options = array( 'id' => '', 'url' => '' ) ) {
1354
  *
1355
  * @since 0.4.0
1356
  */
1357
- function scc_get_share_twitter( $options = array( 'id' => '', 'url' => '' ) ) {
1358
 
1359
  $options['sns'] = SNS_Count_Cache::REF_SHARE_TWITTER;
1360
  return scc_get_share( $options );
@@ -1365,7 +1908,7 @@ function scc_get_share_twitter( $options = array( 'id' => '', 'url' => '' ) ) {
1365
  *
1366
  * @since 0.4.0
1367
  */
1368
- function scc_get_share_facebook( $options = array( 'id' => '', 'url' => '' ) ) {
1369
 
1370
  $options['sns'] = SNS_Count_Cache::REF_SHARE_FACEBOOK;
1371
  return scc_get_share( $options );
@@ -1376,7 +1919,7 @@ function scc_get_share_facebook( $options = array( 'id' => '', 'url' => '' ) ) {
1376
  *
1377
  * @since 0.4.0
1378
  */
1379
- function scc_get_share_gplus( $options = array( 'id' => '', 'url' => '' ) ) {
1380
 
1381
  $options['sns'] = SNS_Count_Cache::REF_SHARE_GPLUS;
1382
  return scc_get_share( $options );
@@ -1387,7 +1930,7 @@ function scc_get_share_gplus( $options = array( 'id' => '', 'url' => '' ) ) {
1387
  *
1388
  * @since 0.4.0
1389
  */
1390
- function scc_get_share_pocket( $options = array( 'id' => '', 'url' => '' ) ) {
1391
 
1392
  $options['sns'] = SNS_Count_Cache::REF_SHARE_POCKET;
1393
  return scc_get_share( $options );
@@ -1399,7 +1942,7 @@ function scc_get_share_pocket( $options = array( 'id' => '', 'url' => '' ) ) {
1399
  *
1400
  * @since 0.4.0
1401
  */
1402
- function scc_get_share_total( $options = array( 'id' => '', 'url' => '' ) ) {
1403
 
1404
  $options['sns'] = SNS_Count_Cache::REF_SHARE_TOTAL;
1405
  return scc_get_share( $options );
@@ -1411,7 +1954,7 @@ function scc_get_share_total( $options = array( 'id' => '', 'url' => '' ) ) {
1411
  * @since 0.1.0
1412
  * @deprecated Function deprecated in Release 0.4.0
1413
  */
1414
- function get_scc_hatebu( $options = array( 'id' => '', 'url' => '' ) ) {
1415
 
1416
  return scc_get_share_hatebu( $options );
1417
  }
@@ -1422,7 +1965,7 @@ function get_scc_hatebu( $options = array( 'id' => '', 'url' => '' ) ) {
1422
  * @since 0.1.0
1423
  * @deprecated Function deprecated in Release 0.4.0
1424
  */
1425
- function get_scc_twitter( $options = array( 'id' => '', 'url' => '' ) ) {
1426
 
1427
  return scc_get_share_twitter( $options );
1428
  }
@@ -1433,7 +1976,7 @@ function get_scc_twitter( $options = array( 'id' => '', 'url' => '' ) ) {
1433
  * @since 0.1.0
1434
  * @deprecated Function deprecated in Release 0.4.0
1435
  */
1436
- function get_scc_facebook( $options = array( 'id' => '', 'url' => '' ) ) {
1437
 
1438
  return scc_get_share_facebook( $options );
1439
  }
@@ -1444,7 +1987,7 @@ function get_scc_facebook( $options = array( 'id' => '', 'url' => '' ) ) {
1444
  * @since 0.1.0
1445
  * @deprecated Function deprecated in Release 0.4.0
1446
  */
1447
- function get_scc_gplus( $options = array( 'id' => '', 'url' => '' ) ) {
1448
 
1449
  return scc_get_share_gplus( $options );
1450
  }
@@ -1455,7 +1998,7 @@ function get_scc_gplus( $options = array( 'id' => '', 'url' => '' ) ) {
1455
  * @since 0.2.1
1456
  * @deprecated Function deprecated in Release 0.4.0
1457
  */
1458
- function get_scc_pocket( $options = array( 'id' => '', 'url' => '' ) ) {
1459
 
1460
  return scc_get_share_pocket( $options );
1461
  }
@@ -1470,9 +2013,7 @@ function scc_get_follow_feedly() {
1470
  $options['sns'] = SNS_Count_Cache::REF_FOLLOW_FEEDLY;
1471
  return scc_get_follow( $options );
1472
  }
1473
-
1474
-
1475
-
1476
 
1477
  }
1478
 
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.6.0
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
11
 
12
  /*
13
 
14
+ Copyright (C) 2014 - 2015 Daisuke Maruyama
15
 
16
  This program is free software; you can redistribute it and/or
17
  modify it under the terms of the GNU General Public License
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/interface-cache-order.php' );
36
+
37
  require_once ( dirname( __FILE__ ) . '/includes/class-engine.php' );
38
  require_once ( dirname( __FILE__ ) . '/includes/class-cache-engine.php' );
39
 
42
  require_once ( dirname( __FILE__ ) . '/includes/class-share-rush-cache-engine.php' );
43
  require_once ( dirname( __FILE__ ) . '/includes/class-share-lazy-cache-engine.php' );
44
  require_once ( dirname( __FILE__ ) . '/includes/class-share-second-cache-engine.php' );
45
+ //require_once ( dirname( __FILE__ ) . '/includes/class-share-rescue-cache-engine.php' );
46
 
47
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-cache-engine.php' );
48
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-base-cache-engine.php' );
49
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-lazy-cache-engine.php' );
50
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-second-cache-engine.php' );
 
51
 
52
  require_once ( dirname( __FILE__ ) . '/includes/class-export-engine.php' );
53
  require_once ( dirname( __FILE__ ) . '/includes/class-common-data-export-engine.php' );
60
 
61
  if ( ! class_exists( 'SNS_Count_Cache' ) ) {
62
 
63
+ final class SNS_Count_Cache implements Cache_Order {
64
 
65
  /**
66
  * Prefix of share cache ID
120
  /**
121
  * Type of data export
122
  */
123
+ const OPT_COMMON_DATA_EXPORT_MANUAL = 1;
124
 
125
  /**
126
  * Type of data export
127
  */
128
+ const OPT_COMMON_DATA_EXPORT_AUTO = 2;
129
 
130
  /**
131
  * File name of data export
145
  /**
146
  * Type of dynamic cache processing
147
  */
148
+ const OPT_COMMON_ACCESS_BASED_CACHE_NONE = 1;
149
 
150
  /**
151
  * Type of dynamic cache processing
152
  */
153
+ const OPT_COMMON_ACCESS_BASED_SYNC_CACHE = 2;
154
 
155
  /**
156
  * Type of dynamic cache processing
157
  */
158
+ const OPT_COMMON_ACCESS_BASED_ASYNC_CACHE = 3;
159
 
160
  /**
161
  * Type of dynamic cache processing
162
  */
163
+ const OPT_COMMON_ACCESS_BASED_2ND_CACHE = 4;
164
 
165
  /**
166
  * Type of scheme migration mode
171
  * Type of scheme migration mode
172
  */
173
  const OPT_COMMON_SCHEME_MIGRATION_MODE_ON = true;
174
+
175
+ /**
176
+ * Error message
177
+ */
178
+ const OPT_COMMON_ERROR_MESSAGE = 'scc_error_message';
179
+
180
+ /**
181
+ * Update message
182
+ */
183
+ const OPT_COMMON_UPDATE_MESSAGE = 'scc_update_message';
184
+
185
+ /**
186
+ * Type of crawl method
187
+ */
188
+ const OPT_COMMON_CRAWLER_METHOD_NORMAL = 1;
189
+
190
+ /**
191
+ * Type of crawl method
192
+ */
193
+ const OPT_COMMON_CRAWLER_METHOD_CURL = 2;
194
+
195
+ /**
196
+ * Type of crawl ssl verification
197
+ */
198
+ const OPT_COMMON_CRAWLER_SSL_VERIFY_ON = true;
199
+
200
+ /**
201
+ * Type of crawl ssl verification
202
+ */
203
+ const OPT_COMMON_CRAWLER_SSL_VERIFY_OFF = false;
204
+
205
+ /**
206
+ * Capability for admin
207
+ */
208
+ const OPT_COMMON_CAPABILITY = 'manage_options';
209
 
210
  /**
211
  * Option key for custom post types for share base cache
212
  */
213
+ const DB_SHARE_CUSTOM_POST_TYPES = 'share_custom_post_types';
214
 
215
  /**
216
  * Option key for check interval of share base cache
217
  */
218
+ const DB_SHARE_CHECK_INTERVAL = 'share_check_interval';
219
 
220
  /**
221
  * Option key for number of posts to check at a time for share base cache
222
  */
223
+ const DB_SHARE_POSTS_PER_CHECK = 'share_posts_per_check';
224
 
225
  /**
226
  * Option key for dynamic cache
227
  */
228
+ const DB_COMMON_DYNAMIC_CACHE_MODE = 'common_dynamic_cache_mode';
229
 
230
  /**
231
  * Option key for new content term for share rush cache
232
  */
233
+ const DB_SHARE_NEW_CONTENT_TERM = 'share_new_content_term';
234
 
235
  /**
236
  * Option key of cache target for share base cache
237
  */
238
+ const DB_SHARE_CACHE_TARGET = 'share_cache_target';
239
 
240
  /**
241
  * Option key of cache target for follow base cache
242
  */
243
+ const DB_FOLLOW_CACHE_TARGET = 'follow_cache_target';
244
 
245
  /**
246
  * Option key of checking interval for follow base cache
247
  */
248
+ const DB_FOLLOW_CHECK_INTERVAL = 'follow_check_interval';
249
 
250
  /**
251
  * Option key of data export
252
  */
253
+ const DB_COMMON_DATA_EXPORT_MODE = 'common_data_export_mode';
254
 
255
  /**
256
+ * Option key of data export schedule
257
  */
258
+ const DB_COMMON_DATA_EXPORT_SCHEDULE = 'common_data_export_schedule';
259
+
260
+ /**
261
+ * Option key of http migration
262
+ */
263
+ const DB_COMMON_SCHEME_MIGRATION_MODE = 'common_scheme_migration_mode';
264
 
265
  /**
266
+ * Option key of crawl ssl verification
267
  */
268
+ const DB_COMMON_CRAWLER_SSL_VERIFICATION = 'common_crawler_ssl_verification';
269
 
270
  /**
271
+ * Option key of setting
272
  */
273
+ const DB_SETTINGS = 'scc_settings';
274
 
275
  /**
276
  * Slug of the plugin
380
  /**
381
  * Plugin version, used for cache-busting of style and script file references.
382
  */
383
+ private $version = '0.6.0';
384
 
385
  /**
386
  * Instances of crawler
450
  /**
451
  * Dynamic cache mode
452
  */
453
+ private $dynamic_cache_mode = 1;
454
 
455
  /**
456
  * Data export mode
457
  */
458
+ private $data_export_mode = 1;
 
 
 
 
 
459
 
460
  /**
461
  * Data export schedule
462
  */
463
+ private $data_export_schedule = '0 0 * * *';
464
 
465
  /**
466
  * Migration mode from http to https
481
  * Extended max execution time
482
  */
483
  private $extended_max_execution_time = 300;
484
+
485
+ /**
486
+ * URL of loding image
487
+ */
488
+ private $loading_img_url = '';
489
+
490
+ /**
491
+ * ajax action
492
+ */
493
+ private $ajax_action = 'scc_cache_info';
494
+
495
+ /**
496
+ * Cralwer method
497
+ */
498
+ private $crawler_method = 1;
499
+
500
+ /**
501
+ * Cralwer SSL verification
502
+ */
503
+ private $crawler_ssl_verification = true;
504
 
505
  /**
506
  * Instance
513
  */
514
  private function __construct() {
515
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
516
+
517
  //load_plugin_textdomain(self::DOMAIN, false, basename(dirname( __FILE__ )) . '/languages');
518
 
519
  register_activation_hook( __FILE__, array( $this, 'activate_plugin' ) );
520
  register_deactivation_hook( __FILE__, array( $this, 'deactivate_plugin' ) );
521
 
522
+ add_action( 'admin_menu', array( $this, 'register_admin_menu' ) );
523
 
524
  add_action( 'admin_print_styles', array( $this, 'register_admin_styles' ) );
525
+ add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ) );
526
+
527
+ //add_action( 'admin_notices', array( $this, 'notice_page' ) );
528
+
529
+ add_action( 'wp_ajax_' . $this->ajax_action, array( $this, 'get_cache_info' ) );
530
+
531
+ add_action( 'wp_dashboard_setup', array( $this, 'add_wp_dashboard_widget' ) );
532
+
533
+ add_action( 'plugins_loaded', array( $this, 'initialize' ) );
534
  }
535
 
536
  /**
539
  * @since 0.1.1
540
  */
541
  public static function get_instance() {
 
 
 
 
 
542
 
543
+ if ( ! isset( self::$instance ) ) {
544
+ self::$instance = new self;
545
+ }
546
+
547
  return self::$instance;
548
  }
549
+
550
+ /**
551
+ * Return object ID
552
+ *
553
+ * @since 0.6.0
554
+ */
555
+ public function get_object_id() {
556
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
557
+
558
+ $object_id = spl_object_hash( $this );
559
+
560
+ Common_Util::log( '[' . __METHOD__ . '] object ID: ' . $object_id );
561
+
562
+ return $object_id;
563
+ }
564
+
565
+ /**
566
+ * Inhibit clone
567
+ *
568
+ * @since 0.6.0
569
+ */
570
+ final public function __clone() {
571
+ throw new Exception('Clone is not allowed against' . get_class( $this ) );
572
+ }
573
 
574
  /**
575
  * Initialization
578
  */
579
  public function initialize() {
580
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
581
+
582
+ $settings = get_option( self::DB_SETTINGS );
583
 
584
+ if ( isset( $settings[self::DB_SHARE_CHECK_INTERVAL] ) && $settings[self::DB_SHARE_CHECK_INTERVAL] ) {
585
+ $this->share_base_check_interval = intval( $settings[self::DB_SHARE_CHECK_INTERVAL] );
586
+ } else {
587
+ $this->share_base_check_interval = self::OPT_SHARE_BASE_CHECK_INTERVAL;
588
+ }
589
 
590
+ if ( isset( $settings[self::DB_SHARE_POSTS_PER_CHECK] ) && $settings[self::DB_SHARE_POSTS_PER_CHECK] ) {
591
+ $this->share_base_posts_per_check = intval( $settings[self::DB_SHARE_POSTS_PER_CHECK] );
592
+ } else {
593
+ $this->share_base_posts_per_check = self::OPT_SHARE_BASE_POSTS_PER_CHECK;
594
+ }
 
 
 
595
 
596
+ if ( isset( $settings[self::DB_FOLLOW_CHECK_INTERVAL] ) && $settings[self::DB_FOLLOW_CHECK_INTERVAL] ) {
597
+ $this->follow_base_check_interval = intval( $settings[self::DB_FOLLOW_CHECK_INTERVAL] );
598
+ } else {
599
+ $this->follow_base_check_interval = self::OPT_FOLLOW_BASE_CHECK_INTERVAL;
600
+ }
601
 
602
+ if ( isset( $settings[self::DB_COMMON_DYNAMIC_CACHE_MODE] ) && $settings[self::DB_COMMON_DYNAMIC_CACHE_MODE] ) {
603
+ $this->dynamic_cache_mode = $settings[self::DB_COMMON_DYNAMIC_CACHE_MODE];
604
+ } else {
605
+ $this->dynamic_cache_mode = self::OPT_COMMON_ACCESS_BASED_2ND_CACHE;
606
+ }
607
+
608
+ if ( isset( $settings[self::DB_SHARE_NEW_CONTENT_TERM] ) && $settings[self::DB_SHARE_NEW_CONTENT_TERM] ) {
609
+ $this->share_rush_new_content_term = intval( $settings[self::DB_SHARE_NEW_CONTENT_TERM] );
610
+ } else {
611
+ $this->share_rush_new_content_term = self::OPT_SHARE_RUSH_NEW_CONTENT_TERM;
612
+ }
613
 
614
+ if ( isset( $settings[self::DB_COMMON_DATA_EXPORT_MODE] ) && $settings[self::DB_COMMON_DATA_EXPORT_MODE] ) {
615
+ $this->data_export_mode = intval( $settings[self::DB_COMMON_DATA_EXPORT_MODE] );
616
+ } else {
617
+ $this->data_export_mode = self::OPT_COMMON_DATA_EXPORT_MANUAL;
618
+ }
619
 
620
+ if ( isset( $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] ) && $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] ) {
621
+ $this->data_export_schedule = $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE];
622
+ } else {
623
+ $this->data_export_schedule = self::OPT_COMMON_DATA_EXPORT_SCHEDULE;
624
+ }
625
+
626
+ if ( isset( $settings[self::DB_COMMON_SCHEME_MIGRATION_MODE] ) ) {
627
+ $this->scheme_migration_mode = $settings[self::DB_COMMON_SCHEME_MIGRATION_MODE];
628
+ } else {
629
+ $this->scheme_migration_mode = self::OPT_COMMON_SCHEME_MIGRATION_MODE_OFF;
630
+ }
631
 
632
+ // Pocket and Google+ are excluded from migration target because they are migrated automatically.
633
  $this->scheme_migration_exclude_keys = array( self::REF_SHARE_POCKET, self::REF_SHARE_GPLUS );
634
+
635
+ if ( isset( $settings[self::DB_SHARE_CACHE_TARGET] ) && $settings[self::DB_SHARE_CACHE_TARGET] ) {
636
+ $this->share_base_cache_target = $settings[self::DB_SHARE_CACHE_TARGET];
637
+ } else {
638
  $this->share_base_cache_target[self::REF_SHARE_TWITTER] = true;
639
+ $this->share_base_cache_target[self::REF_SHARE_GPLUS] = true;
640
+ $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] = true;
641
+ $this->share_base_cache_target[self::REF_SHARE_POCKET] = true;
 
 
642
  $this->share_base_cache_target[self::REF_SHARE_HATEBU] = true;
643
  }
644
 
645
  $this->share_base_cache_target[self::REF_CRAWL_DATE] = true;
646
+ $this->share_base_cache_target[self::REF_SHARE_TOTAL] = true;
647
+
648
+ if ( isset( $settings[self::DB_FOLLOW_CACHE_TARGET] ) && $settings[self::DB_FOLLOW_CACHE_TARGET] ) {
649
+ $this->follow_base_cache_target = $settings[self::DB_FOLLOW_CACHE_TARGET];
650
+ } else {
651
+ $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = true;
652
+ }
653
+
654
+ if ( isset( $settings[self::DB_SHARE_CUSTOM_POST_TYPES] ) && $settings[self::DB_SHARE_CUSTOM_POST_TYPES] ) {
655
+ $this->share_base_custom_post_types = $settings[self::DB_SHARE_CUSTOM_POST_TYPES];
656
+ } else {
657
+ $this->share_base_custom_post_types = array();
658
  }
659
+
660
+ $this->share_base_cache_post_types = array_merge( $this->share_base_cache_post_types, $this->share_base_custom_post_types );
661
 
662
+
663
+ if ( extension_loaded( 'curl' ) ) {
664
+ $this->crawler_method = self::OPT_COMMON_CRAWLER_METHOD_CURL;
665
+ } else {
666
+ $this->crawler_method = self::OPT_COMMON_CRAWLER_METHOD_NORMAL;
667
  }
 
 
668
 
669
+ if ( isset( $settings[self::DB_COMMON_CRAWLER_SSL_VERIFICATION] ) ) {
670
+ $this->crawler_ssl_verification = $settings[self::DB_COMMON_CRAWLER_SSL_VERIFICATION];
671
+ } else {
672
+ $this->crawler_ssl_verification = self::OPT_COMMON_CRAWLER_SSL_VERIFY_ON;
673
+ }
674
 
675
  // Crawler
676
+ $options = array(
677
+ 'crawl_method' => $this->crawler_method,
678
+ 'timeout' => 10,
679
+ 'ssl_verification' => $this->crawler_ssl_verification
680
+ );
681
+
682
  $this->crawlers[self::REF_SHARE] = Share_Crawler::get_instance();
683
+ $this->crawlers[self::REF_SHARE]->initialize( $options );
684
+
685
  $this->crawlers[self::REF_FOLLOW] = Follow_Crawler::get_instance();
686
+ $this->crawlers[self::REF_FOLLOW]->initialize( $options );
687
 
688
  // Share base cache engine
689
  $options = array(
736
  'target_sns' => $this->share_base_cache_target,
737
  'check_interval' => self::OPT_SHARE_2ND_CHECK_INTERVAL,
738
  'post_types' => $this->share_base_cache_post_types,
739
+ 'cache_prefix' => self::OPT_SHARE_2ND_META_KEY_PREFIX,
740
  'scheme_migration_mode' => $this->scheme_migration_mode,
741
  'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
742
  );
744
  $this->cache_engines[self::REF_SHARE_2ND] = Share_Second_Cache_Engine::get_instance();
745
  $this->cache_engines[self::REF_SHARE_2ND]->initialize( $options );
746
 
747
+ /*
748
  // Share rescue cache engine
749
  $options = array(
750
  'delegate' => $this,
759
 
760
  $this->cache_engines[self::REF_SHARE_RESCUE] = Share_Rescue_Cache_Engine::get_instance();
761
  $this->cache_engines[self::REF_SHARE_RESCUE]->initialize( $options );
762
+ */
763
 
764
  // Follow base cache engine
765
  $options = array(
767
  'crawler' => $this->crawlers[self::REF_FOLLOW],
768
  'target_sns' => $this->follow_base_cache_target,
769
  'check_interval' => $this->follow_base_check_interval,
770
+ 'scheme_migration_mode' => $this->scheme_migration_mode
 
771
  );
772
 
773
  $this->cache_engines[self::REF_FOLLOW_BASE] = Follow_Base_Cache_Engine::get_instance();
790
  'crawler' => $this->crawlers[self::REF_FOLLOW],
791
  'target_sns' => $this->follow_base_cache_target,
792
  'check_interval' => self::OPT_FOLLOW_2ND_CHECK_INTERVAL,
793
+ 'cache_prefix' => self::OPT_FOLLOW_2ND_META_KEY_PREFIX
794
  );
795
 
796
  $this->cache_engines[self::REF_FOLLOW_2ND] = Follow_Second_Cache_Engine::get_instance();
799
  // Data export engine
800
  $options = array(
801
  'export_activation' => $this->data_export_mode,
 
802
  'export_schedule' => $this->data_export_schedule,
803
  'share_target_sns' => $this->share_base_cache_target,
804
  'follow_target_sns' => $this->follow_base_cache_target,
834
 
835
  $this->control_engines[self::REF_COMMON_CONTROL] = Common_Job_Reset_Engine::get_instance();
836
  $this->control_engines[self::REF_COMMON_CONTROL]->initialize( $options );
837
+
 
 
 
 
 
838
  $tmp_max_execution_time = ini_get( 'max_execution_time' );
839
 
840
  if ( isset( $tmp_max_execution_time ) && $tmp_max_execution_time > 0 ) {
843
  $this->original_max_execution_time = 30;
844
  }
845
 
846
+ $this->loading_img_url = plugins_url( '/images/loading.gif', __FILE__ );
847
+
848
+ // delete old hooks
849
+ WP_Cron_Util::clear_scheduled_hook( 'scc_basecache_prime' );
850
+ WP_Cron_Util::clear_scheduled_hook( 'scc_rushcache_prime' );
851
+ WP_Cron_Util::clear_scheduled_hook( 'scc_2ndcache_prime' );
852
+ WP_Cron_Util::clear_scheduled_hook( 'scc_share_rescuecache_prime' );
853
+
854
+ }
855
 
856
  /**
857
  * Registers and enqueues admin-specific styles.
868
  $screen = get_current_screen();
869
 
870
  if ( in_array( $screen->id, $this->plugin_screen_hook_suffix ) ) {
871
+ wp_enqueue_style( self::DOMAIN .'-admin-style-1', plugins_url( ltrim( '/css/sns-count-cache.css', '/' ), __FILE__) );
872
+ wp_enqueue_style( self::DOMAIN .'-admin-style-2', plugins_url( ltrim( '/css/prettify.css', '/' ), __FILE__ ) );
873
  }
874
  }
875
 
888
  $screen = get_current_screen();
889
 
890
  if ( in_array( $screen->id, $this->plugin_screen_hook_suffix ) ) {
891
+ wp_enqueue_script( self::DOMAIN . '-admin-script-1', plugins_url( ltrim( '/js/prettify.js', '/' ) , __FILE__ ), array( 'jquery' ) );
892
+
893
+ wp_enqueue_script( self::DOMAIN . '-admin-script-2', plugins_url( ltrim( '/js/jquery.scc-cache-info.min.js', '/' ), __FILE__ ), array( 'jquery' ) );
894
+ wp_localize_script( self::DOMAIN . '-admin-script-2', 'scc', array( 'endpoint' => admin_url( 'admin-ajax.php' ), 'action' => $this->ajax_action, 'nonce' => wp_create_nonce( $this->ajax_action ) ) );
895
  }
896
  }
897
 
900
  *
901
  * @since 0.1.1
902
  */
903
+ public function activate_plugin() {
904
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
905
 
906
  $this->initialize();
938
  *
939
  * @since 0.1.1
940
  */
941
+ public function deactivate_plugin() {
942
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
943
 
944
  set_time_limit( $this->extended_max_execution_time );
948
  $cache_engine->clear_cache();
949
  }
950
 
951
+ // compatibility for old version
952
+ $query_args = array(
953
+ 'post_type' => $this->share_base_cache_post_types,
954
+ 'post_status' => 'publish',
955
+ 'nopaging' => true,
956
+ 'update_post_term_cache' => false,
957
+ 'update_post_meta_cache' => false
958
+ );
959
+
960
+ $posts_query = new WP_Query( $query_args );
961
+
962
+ if ( $posts_query->have_posts() ) {
963
+ while ( $posts_query->have_posts() ) {
964
+ $posts_query->the_post();
965
+
966
+ $post_ID = get_the_ID();
967
+
968
+ foreach ( $this->follow_base_cache_target as $sns => $active ) {
969
+
970
+ if ( $active ) {
971
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
972
+
973
+ delete_post_meta( $post_ID, $meta_key );
974
+ }
975
+ }
976
+ }
977
+ }
978
+ wp_reset_postdata();
979
+
980
  foreach ( $this->control_engines as $key => $control_engine ) {
981
  $control_engine->unregister_schedule();
982
  }
983
+
984
  $this->export_engines[self::REF_COMMON_EXPORT]->unregister_schedule();
985
 
986
+ set_time_limit( $this->original_max_execution_time );
987
 
988
  }
989
 
1007
  *
1008
  * @since 0.1.0
1009
  */
1010
+ public function register_admin_menu() {
1011
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
1012
 
1013
+ $this->plugin_screen_hook_suffix[] = 'dashboard';
1014
+ $this->plugin_screen_hook_suffix[] = add_menu_page( __( 'SNS Count Cache', self::DOMAIN ), __( 'SNS Count Cache', self::DOMAIN ), self::OPT_COMMON_CAPABILITY, 'scc-dashboard', array( $this, 'dashboard_page' ), 'dashicons-share' );
1015
+ $this->plugin_screen_hook_suffix[] = add_submenu_page( 'scc-dashboard', __( 'Dashboard | SNS Count Cache', self::DOMAIN ), __( 'Dashboard', self::DOMAIN ), self::OPT_COMMON_CAPABILITY, 'scc-dashboard', array( $this, 'dashboard_page' ) );
1016
+ $this->plugin_screen_hook_suffix[] = add_submenu_page( 'scc-dashboard', __( 'Cache Status | SNS Count Cache', self::DOMAIN ), __( 'Cache Status', self::DOMAIN ), self::OPT_COMMON_CAPABILITY, 'scc-cache-status', array( $this, 'cache_status_page' ) );
1017
+ $this->plugin_screen_hook_suffix[] = add_submenu_page( 'scc-dashboard', __( 'Share Count | SNS Count Cache', self::DOMAIN ), __( 'Share Count', self::DOMAIN ), self::OPT_COMMON_CAPABILITY, 'scc-share-count', array( $this, 'share_count_page' ) );
1018
+ $this->plugin_screen_hook_suffix[] = add_submenu_page( 'scc-dashboard', __( 'Setting | SNS Count Cache', self::DOMAIN ), __( 'Setting', self::DOMAIN ), self::OPT_COMMON_CAPABILITY, 'scc-setting', array( $this, 'setting_page' ) );
1019
+ $this->plugin_screen_hook_suffix[] = add_submenu_page( 'scc-dashboard', __( 'Help | SNS Count Cache', self::DOMAIN ), __( 'Help', self::DOMAIN ), self::OPT_COMMON_CAPABILITY, 'scc-help', array( $this, 'help_page' ) );
1020
  }
1021
 
1022
+ /**
1023
+ * Add widget to wordpress dashboard
1024
+ *
1025
+ * @since 0.5.1
1026
+ */
1027
+ public function add_wp_dashboard_widget() {
1028
+
1029
+ if ( ! current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
1030
+ return false;
1031
+ }
1032
+
1033
+ wp_add_dashboard_widget( 'scc_dashboard', 'SNS Count Cache', array( $this, 'wp_dashboard_page' ) );
1034
+ }
1035
+
1036
+ /**
1037
+ * Option page implementation
1038
+ *
1039
+ * @since 0.5.1
1040
+ */
1041
+ public function wp_dashboard_page() {
1042
+ include_once( dirname( __FILE__ ) . '/includes/admin-dashboard-widget.php' );
1043
+ }
1044
+
1045
+
1046
  /**
1047
  * Option page implementation
1048
  *
1088
  public function help_page() {
1089
  include_once( dirname( __FILE__ ) . '/includes/admin-help.php' );
1090
  }
 
 
 
 
 
 
 
 
 
 
 
1091
 
1092
+ /**
1093
+ * Option page implementation
1094
+ *
1095
+ * @since 0.5.1
1096
+ */
1097
+ public function notice_page() {
1098
+ include_once( dirname( __FILE__ ) . '/includes/admin-notice.php' );
1099
+ }
1100
+
1101
  /**
1102
  * Cache share count for a given post ID
1103
  *
1104
  * @since 0.2.0
1105
  */
1106
+ private function retrieve_share_cache( $post_ID, $second_sync = false ) {
1107
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
1108
 
1109
  return $this->cache_engines[self::REF_SHARE_BASE]->direct_cache( $post_ID, $second_sync );
1114
  *
1115
  * @since 0.2.0
1116
  */
1117
+ private function retrieve_follow_cache() {
1118
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
1119
 
1120
  return $this->cache_engines[self::REF_FOLLOW_BASE]->direct_cache();
1125
  *
1126
  * @since 0.2.0
1127
  */
1128
+ private function reserve_share_cache( $post_ID ) {
1129
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
1130
 
1131
  $this->cache_engines[self::REF_SHARE_LAZY]->prime_cache( $post_ID );
1136
  *
1137
  * @since 0.4.0
1138
  */
1139
+ private function reserve_follow_cache() {
1140
  Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
1141
 
1142
  $this->cache_engines[self::REF_FOLLOW_LAZY]->prime_cache();
1143
  }
1144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1145
  /**
1146
  * Method call between one cache engine and another
1147
  *
1152
 
1153
  switch ( get_class( $engine ) ) {
1154
  case 'Share_Lazy_Cache_Engine':
1155
+ $this->cache_engines[self::REF_SHARE_2ND]->cache( $options );
1156
  break;
1157
  case 'Share_Rescue_Cache_Engine':
1158
+ $this->cache_engines[self::REF_SHARE_2ND]->cache( $options );
1159
  break;
1160
  case 'Share_Base_Cache_Engine':
1161
+ $this->cache_engines[self::REF_SHARE_2ND]->cache( $options );
1162
  break;
1163
  case 'Share_Rush_Cache_Engine':
1164
+ $this->cache_engines[self::REF_SHARE_2ND]->cache( $options );
1165
  break;
1166
  case 'Follow_Lazy_Cache_Engine':
1167
+ $this->cache_engines[self::REF_FOLLOW_2ND]->cache( $options );
1168
  break;
1169
  case 'Follow_Base_Cache_Engine':
1170
+ $this->cache_engines[self::REF_FOLLOW_2ND]->cache( $options );
1171
  break;
1172
  }
1173
 
1174
  }
1175
+
1176
+ /**
1177
+ * Return pagination
1178
+ *
1179
+ * @since 0.4.0
1180
+ */
1181
  private function pagination( $numpages = '', $pagerange = '', $paged='', $inherit_param = true ) {
1182
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
1183
 
1184
  if ( empty( $pagerange ) ) {
1185
  $pagerange = 2;
1186
  }
1187
 
1188
+ if ( $paged === '' ) {
1189
  global $paged;
1190
 
1191
  if ( empty( $paged ) ) {
1193
  }
1194
  }
1195
 
1196
+ if ( $numpages === '' ) {
1197
  global $wp_query;
1198
 
1199
  $numpages = $wp_query->max_num_pages;
1203
  }
1204
  }
1205
 
1206
+ $pagination_args = array();
1207
+
1208
+ $url = parse_url( get_pagenum_link(1) );
1209
+ $base_url = $url['scheme'] . '://' . $url['host'] . $url['path'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1210
 
1211
+ parse_str ( $url['query'], $query );
1212
+
1213
+ $base_url = $base_url . '?page=' . $query['page'];
1214
 
1215
+ Common_Util::log( '[' . __METHOD__ . '] base url: ' . $base_url );
1216
+
1217
+ $pagination_args = array(
1218
+ 'base' => $base_url . '%_%',
1219
+ 'format' => '&paged=%#%',
1220
+ 'total' => $numpages,
1221
+ 'current' => $paged,
1222
+ 'show_all' => false,
1223
+ 'end_size' => 1,
1224
+ 'mid_size' => $pagerange,
1225
+ 'prev_next' => true,
1226
+ 'prev_text' => __('&laquo;'),
1227
+ 'next_text' => __('&raquo;'),
1228
+ 'type' => 'plain',
1229
+ 'add_args' => '',
1230
+ 'add_fragment' => ''
1231
  );
1232
+
1233
+ $paginate_links = paginate_links( $pagination_args );
1234
+
1235
+ if ( $inherit_param ) {
1236
+ Common_Util::log( '[' . __METHOD__ . '] inherit param: true' );
1237
+ } else {
1238
+ Common_Util::log( '[' . __METHOD__ . '] inherit param: false' );
1239
+
1240
+ $pattern = '/(?:&#038;action=cache&#038;post_id=[0-9]+&#038;_wpnonce=.{10})/';
1241
+ $paginate_links = preg_replace( $pattern, '', $paginate_links );
1242
  }
1243
+
 
 
1244
  if ( $paginate_links ) {
1245
  echo "<nav class='pagination'>";
1246
  echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
1247
  echo $paginate_links;
1248
  echo "</nav>";
1249
  }
1250
+
1251
  }
 
 
1252
 
1253
+ /**
1254
+ * Return cache information through ajax interface
1255
+ *
1256
+ * @since 0.5.1
1257
+ */
1258
+ public function get_cache_info() {
1259
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
1260
 
1261
+ if ( isset( $_REQUEST['nonce'] ) && wp_verify_nonce( $_REQUEST['nonce'], $this->ajax_action ) ) {
1262
+ if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
1263
+
1264
+ $share_base_cache_target = $this->share_base_cache_target;
1265
+
1266
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
1267
+
1268
+ $posts_count = 0;
1269
+ $primary_full_cache_count = 0;
1270
+ $primary_partial_cache_count = 0;
1271
+ $primary_no_cache_count = 0;
1272
+
1273
+ $secondary_full_cache_count = 0;
1274
+ $secondary_partial_cache_count = 0;
1275
+ $secondary_no_cache_count = 0;
1276
+
1277
+ $sum = array();
1278
+ $return = array();
1279
+
1280
+ foreach ( $share_base_cache_target as $sns => $active ) {
1281
+ if( $active ){
1282
+ $sum[$sns] = 0;
1283
+ }
1284
+ }
1285
+
1286
+ $query_args = array(
1287
+ 'post_type' => $this->share_base_cache_post_types,
1288
+ 'post_status' => 'publish',
1289
+ 'nopaging' => true,
1290
+ 'update_post_term_cache' => false,
1291
+ 'update_post_meta_cache' => false
1292
+ );
1293
+
1294
+ set_time_limit( $this->extended_max_execution_time );
1295
+
1296
+ //home
1297
+ ++$posts_count;
1298
+
1299
+ $full_cache_flag = true;
1300
+ $partial_cache_flag = false;
1301
+
1302
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
1303
+
1304
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
1305
+
1306
+ foreach ( $share_base_cache_target as $sns => $active ) {
1307
+ if ( $active ) {
1308
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
1309
+ $sum[$sns] = $sum[$sns] + $sns_counts[$sns];
1310
+ $partial_cache_flag = true;
1311
+ } else {
1312
+ $full_cache_flag = false;
1313
+ }
1314
+ }
1315
+ }
1316
+
1317
+ if ( $partial_cache_flag && $full_cache_flag ) {
1318
+ ++$primary_full_cache_count;
1319
+ } else if ( $partial_cache_flag && ! $full_cache_flag ) {
1320
+ ++$primary_partial_cache_count;
1321
+ } else {
1322
+ ++$primary_no_cache_count;
1323
+ }
1324
+
1325
+ $full_cache_flag = true;
1326
+ $partial_cache_flag = false;
1327
+
1328
+ $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
1329
+
1330
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
1331
+
1332
+ foreach ( $share_base_cache_target as $sns => $active ) {
1333
+ if( $active ){
1334
+
1335
+ if ( $sns_counts[$sns] >= 0 ) {
1336
+ $partial_cache_flag = true;
1337
+ } else {
1338
+ $full_cache_flag = false;
1339
+ }
1340
+ }
1341
+ }
1342
+ } else {
1343
+ foreach ( $share_base_cache_target as $sns => $active ) {
1344
+ if( $active ){
1345
+ $full_cache_flag = false;
1346
+ }
1347
+ }
1348
+ }
1349
+
1350
+ if ( $partial_cache_flag && $full_cache_flag ) {
1351
+ ++$secondary_full_cache_count;
1352
+ } else if ( $partial_cache_flag && ! $full_cache_flag ) {
1353
+ ++$secondary_partial_cache_count;
1354
+ } else {
1355
+ ++$secondary_no_cache_count;
1356
+ }
1357
+
1358
  } else {
1359
+
1360
+ $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
1361
+
1362
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
1363
+
1364
+ foreach ( $share_base_cache_target as $sns => $active ) {
1365
+ if( $active ){
1366
+
1367
+ if ( $sns_counts[$sns] >= 0 ) {
1368
+ $sum[$sns] = $sum[$sns] + $sns_counts[$sns];
1369
+ $partial_cache_flag = true;
1370
+ } else {
1371
+ $full_cache_flag = false;
1372
+ }
1373
+ }
1374
+ }
1375
+ } else {
1376
+ foreach ( $share_base_cache_target as $sns => $active ) {
1377
+ if( $active ){
1378
+ $full_cache_flag = false;
1379
+ }
1380
+ }
1381
+ }
1382
+
1383
+ if ( $partial_cache_flag && $full_cache_flag ) {
1384
+ ++$secondary_full_cache_count;
1385
+ } else if ( $partial_cache_flag && ! $full_cache_flag ) {
1386
+ ++$secondary_partial_cache_count;
1387
+ } else {
1388
+ ++$secondary_no_cache_count;
1389
+ }
1390
+
1391
+ ++$primary_no_cache_count;
1392
+
1393
  }
1394
+
1395
+ //page, post
1396
+ $site_query = new WP_Query( $query_args );
1397
+
1398
+ if ( $site_query->have_posts() ) {
1399
+ while ( $site_query->have_posts() ) {
1400
+ $site_query->the_post();
1401
+
1402
+ ++$posts_count;
1403
+
1404
+ $full_cache_flag = true;
1405
+ $partial_cache_flag = false;
1406
+
1407
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( get_the_ID() );
1408
+
1409
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
1410
+
1411
+ foreach ( $share_base_cache_target as $sns => $active ) {
1412
+ if ( $active ) {
1413
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
1414
+ $sum[$sns] = $sum[$sns] + $sns_counts[$sns];
1415
+ $partial_cache_flag = true;
1416
+ } else {
1417
+ $full_cache_flag = false;
1418
+ }
1419
+ }
1420
+ }
1421
+
1422
+ if ( $partial_cache_flag && $full_cache_flag ) {
1423
+ ++$primary_full_cache_count;
1424
+ } else if ( $partial_cache_flag && ! $full_cache_flag ) {
1425
+ ++$primary_partial_cache_count;
1426
+ } else {
1427
+ ++$primary_no_cache_count;
1428
+ }
1429
+
1430
+ $full_cache_flag = true;
1431
+ $partial_cache_flag = false;
1432
+
1433
+ foreach ( $share_base_cache_target as $sns => $active ) {
1434
+
1435
+ if( $active ){
1436
+
1437
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
1438
+ $sns_counts[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
1439
+
1440
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 ) {
1441
+ $partial_cache_flag = true;
1442
+ } else {
1443
+ $full_cache_flag = false;
1444
+ }
1445
+ }
1446
+ }
1447
+
1448
+ if ( $partial_cache_flag && $full_cache_flag ) {
1449
+ ++$secondary_full_cache_count;
1450
+ } else if ( $partial_cache_flag && ! $full_cache_flag ) {
1451
+ ++$secondary_partial_cache_count;
1452
+ } else {
1453
+ ++$secondary_no_cache_count;
1454
+ }
1455
+
1456
+ } else {
1457
+
1458
+ foreach ( $share_base_cache_target as $sns => $active ) {
1459
+
1460
+ if( $active ){
1461
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
1462
+
1463
+ $sns_counts[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
1464
+
1465
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 ) {
1466
+ $sum[$sns] = $sum[$sns] + $sns_counts[$sns];
1467
+ $partial_cache_flag = true;
1468
+ } else {
1469
+ $full_cache_flag = false;
1470
+ }
1471
+ }
1472
+ }
1473
+
1474
+ if ( $partial_cache_flag && $full_cache_flag ) {
1475
+ ++$secondary_full_cache_count;
1476
+ } else if ( $partial_cache_flag && ! $full_cache_flag ) {
1477
+ ++$secondary_partial_cache_count;
1478
+ } else {
1479
+ ++$secondary_no_cache_count;
1480
+ }
1481
+
1482
+ ++$primary_no_cache_count;
1483
+
1484
+ }
1485
+ }
1486
+ wp_reset_postdata();
1487
+ }
1488
+
1489
+ set_time_limit( $this->original_max_execution_time );
1490
+
1491
+ foreach ( $share_base_cache_target as $sns => $active ) {
1492
+
1493
+ if ( $active && isset( $sum[$sns] ) ) {
1494
+ if ( $sns === self::REF_SHARE_GPLUS ){
1495
+ $return['share_count']['gplus'] = number_format( (int) $sum[$sns] );
1496
+ } else {
1497
+ $return['share_count'][strtolower( $sns )] = number_format( (int) $sum[$sns] );
1498
+ }
1499
+ }
1500
+ }
1501
+
1502
+ $return['post_count'] = $posts_count;
1503
+ $return['primary']['full_cache_count'] = $primary_full_cache_count;
1504
+ $return['primary']['partial_cache_count'] = $primary_partial_cache_count;
1505
+ $return['primary']['no_cache_count'] = $primary_no_cache_count;
1506
+ $return['secondary']['full_cache_count'] = $secondary_full_cache_count;
1507
+ $return['secondary']['partial_cache_count'] = $secondary_partial_cache_count;
1508
+ $return['secondary']['no_cache_count'] = $secondary_no_cache_count;
1509
+
1510
+ if ( $primary_full_cache_count === $posts_count ) {
1511
+ $return['primary']['cache_status'] = __( 'Completed', self::DOMAIN );
1512
+ } else if ( ( $primary_full_cache_count + $primary_partial_cache_count ) === $posts_count ) {
1513
+ $return['primary']['cache_status'] = __( 'Partially Completed', self::DOMAIN );
1514
+ } else {
1515
+ $return['primary']['cache_status'] = __( 'Ongoing', self::DOMAIN );
1516
+ }
1517
+
1518
+ if ( $secondary_full_cache_count === $posts_count ) {
1519
+ $return['secondary']['cache_status'] = __( 'Completed', self::DOMAIN );
1520
+ } else if ( ( $secondary_full_cache_count + $secondary_partial_cache_count ) === $posts_count ) {
1521
+ $return['secondary']['cache_status'] = __( 'Partially Completed', self::DOMAIN );
1522
+ } else {
1523
+ $return['secondary']['cache_status'] = __( 'Ongoing', self::DOMAIN );
1524
+ }
1525
+
1526
+ $callback = $_REQUEST["callback"];
1527
+
1528
+ header( 'Content-type: application/javascript; charset=utf-8' );
1529
 
1530
+ echo $callback . '(' . json_encode( $return ) . ')';
1531
+ } else {
1532
+ status_header( '403' );
1533
+ echo 'Forbidden';
1534
+ }
1535
+ } else {
1536
+ status_header( '403' );
1537
+ echo 'Forbidden';
1538
+ }
1539
+
1540
+ die();
1541
+ }
1542
+
1543
+ /**
1544
+ * Return share count
1545
+ *
1546
+ * @since 0.5.1
1547
+ */
1548
+ public function get_share_counts( $post_ID = '', $sns_key = '' ) {
1549
+
1550
+ $sns_counts = array();
1551
+
1552
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( $post_ID );
1553
+
1554
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
1555
+ if ( $sns_key ) {
1556
+ if ( ! isset( $sns_counts[$sns_key] ) || $sns_counts[$sns_key] < 0 ) {
1557
+ $sns_counts[$sns_key] = 0;
1558
+ }
1559
+
1560
+ return $sns_counts[$sns_key];
1561
+ } else {
1562
+ foreach ( $this->share_base_cache_target as $sns => $active ) {
1563
+ if ( $active ) {
1564
+ if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
1565
+ $sns_counts[$sns] = 0;
1566
+ }
1567
+ }
1568
+ }
1569
+
1570
+ return $sns_counts;
1571
+ }
1572
+ } else {
1573
+ switch ( $this->dynamic_cache_mode ) {
1574
+ case self::OPT_COMMON_ACCESS_BASED_2ND_CACHE:
1575
+ //$this->reserve_share_cache( $post_ID );
1576
+ $this->cache_engines[self::REF_SHARE_LAZY]->prime_cache( $post_ID );
1577
+
1578
+ if ( $sns_key ) {
1579
+
1580
+ if ( $post_ID !== 'home' ) {
1581
+
1582
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns_key );
1583
+
1584
+ $sns_count = get_post_meta( $post_ID, $meta_key, true );
1585
+
1586
+ if ( isset( $sns_count ) && $sns_count !== '' && $sns_count >= 0) {
1587
+ $sns_counts[$sns_key] = $sns_count;
1588
+ } else {
1589
+ $sns_counts[$sns_key] = 0;
1590
+ }
1591
+ } else {
1592
+ $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
1593
+
1594
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
1595
+ if ( ! isset( $sns_counts[$sns_key] ) || $sns_counts[$sns_key] < 0 ) {
1596
+ $sns_counts[$sns_key] = 0;
1597
+ }
1598
+ }else {
1599
+ $sns_counts[$sns_key] = 0;
1600
+ }
1601
+ }
1602
+
1603
+ return $sns_counts[$sns_key];
1604
+ } else {
1605
+ if ( $post_ID !== 'home' ) {
1606
+
1607
+ foreach ( $this->share_base_cache_target as $sns => $active ) {
1608
+ if ( $active ) {
1609
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
1610
+
1611
+ $sns_count = get_post_meta( $post_ID, $meta_key, true );
1612
+
1613
+ if ( isset( $sns_count ) && $sns_count !== '' && $sns_count >= 0 ) {
1614
+ $sns_counts[$sns] = $sns_count;
1615
+ } else {
1616
+ $sns_counts[$sns] = 0;
1617
+ }
1618
+ }
1619
+ }
1620
+ } else {
1621
+
1622
+ $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
1623
+
1624
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
1625
+
1626
+ foreach ( $this->share_base_cache_target as $sns => $active ) {
1627
+ if ( $active ) {
1628
+ if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
1629
+ $sns_counts[$sns] = 0;
1630
+ }
1631
+ }
1632
+ }
1633
+ } else {
1634
+ foreach ( $this->share_base_cache_target as $sns => $active ) {
1635
+ if ( $active ) {
1636
+ $sns_counts[$sns] = 0;
1637
+ }
1638
+ }
1639
+ }
1640
+ }
1641
+
1642
+ return $sns_counts;
1643
+ }
1644
+ break;
1645
+ case self::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE:
1646
+ //$this->reserve_share_cache( $post_ID );
1647
+ $this->cache_engines[self::REF_SHARE_LAZY]->prime_cache( $post_ID );
1648
+
1649
  if ( $sns_key ) {
1650
  $sns_counts[$sns_key] = 0;
1651
+
1652
  return $sns_counts[$sns_key];
1653
  } else {
1654
+ foreach ( $this->share_base_cache_target as $sns => $active ) {
1655
+ if ( $active ) {
1656
+ $sns_counts[$sns] = 0;
 
 
1657
  }
1658
  }
1659
+
1660
  return $sns_counts;
1661
+ }
1662
  break;
1663
+ case self::OPT_COMMON_ACCESS_BASED_SYNC_CACHE:
1664
+ //$sns_counts = $this->retrieve_share_cache( $post_ID, true );
1665
+ $sns_counts = $this->cache_engines[self::REF_SHARE_BASE]->direct_cache( $post_ID, true );
1666
+
1667
  if ( $sns_key ) {
1668
+ if ( ! isset( $sns_counts[$sns_key] ) || $sns_counts[$sns_key] < 0 ) {
1669
+ $sns_counts[$sns_key] = 0;
1670
+ }
1671
+
1672
  return $sns_counts[$sns_key];
1673
  } else {
1674
+ foreach ( $this->share_base_cache_target as $sns => $active ) {
1675
+ if ( $active ) {
1676
+ if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
1677
+ $sns_counts[$sns] = 0;
1678
+ }
1679
+ }
1680
+ }
1681
+
1682
  return $sns_counts;
1683
  }
1684
  break;
1685
+ case self::OPT_COMMON_ACCESS_BASED_CACHE_NONE:
 
1686
  if ( $sns_key ) {
1687
  $sns_counts[$sns_key] = 0;
1688
+
1689
  return $sns_counts[$sns_key];
1690
+ } else {
1691
+ foreach ( $this->share_base_cache_target as $sns => $active ) {
1692
+ if ( $active ) {
1693
+ $sns_counts[$sns] = 0;
 
 
1694
  }
1695
  }
1696
+
1697
  return $sns_counts;
1698
+ }
1699
  break;
1700
+ }
1701
+ }
1702
+ }
1703
+
1704
+ /**
1705
+ * Return follow count
1706
+ *
1707
+ * @since 0.5.1
1708
+ */
1709
+ public function get_follow_counts( $sns_key = '' ) {
1710
+
1711
+ $sns_followers = array();
1712
+
1713
+ $transient_id = $this->cache_engines[self::REF_FOLLOW_BASE]->get_cache_key( 'follow' );
1714
+
1715
+ if ( false !== ( $sns_followers = get_transient( $transient_id ) ) ) {
1716
+ if ( $sns_key ) {
1717
+ if ( ! isset( $sns_followers[$sns_key] ) || $sns_followers[$sns_key] < 0 ) {
1718
+ $sns_followers[$sns_key] = 0;
1719
+ }
1720
+
1721
+ return $sns_followers[$sns_key];
1722
+ } else {
1723
+ foreach ( $this->follow_base_cache_target as $sns => $active ) {
1724
+ if ( $active ) {
1725
+ if ( ! isset( $sns_followers[$sns] ) || $sns_followers[$sns] < 0 ) {
1726
+ $sns_followers[$sns] = 0;
1727
+ }
1728
+ }
1729
+ }
1730
+
1731
+ return $sns_followers;
1732
+ }
1733
+ } else {
1734
+ switch ( $this->dynamic_cache_mode ) {
1735
+ case self::OPT_COMMON_ACCESS_BASED_2ND_CACHE:
1736
+ //$this->reserve_follow_cache();
1737
+ $this->cache_engines[self::REF_FOLLOW_LAZY]->prime_cache();
1738
+
1739
+ $option_key = $this->cache_engines[self::REF_FOLLOW_2ND]->get_cache_key( 'follow' );
1740
+
1741
+ if ( $sns_key ) {
1742
+
1743
+ if ( false !== ( $sns_followers = get_option( $option_key ) ) ) {
1744
+ if ( ! isset( $sns_followers[$sns_key] ) || $sns_followers[$sns_key] < 0 ) {
1745
+ $sns_followers[$sns_key] = 0;
1746
+ }
1747
+ }else {
1748
+ $sns_followers[$sns_key] = 0;
1749
+ }
1750
+
1751
+ return $sns_followers[$sns_key];
1752
  } else {
1753
+
1754
+ if ( false !== ( $sns_followers = get_option( $option_key ) ) ) {
1755
+
1756
+ foreach ( $this->follow_base_cache_target as $sns => $active ) {
1757
+ if ( $active ) {
1758
+ if ( ! isset( $sns_followers[$sns] ) || $sns_followers[$sns] < 0 ) {
1759
+ $sns_followers[$sns] = 0;
1760
+ }
1761
+ }
1762
+ }
1763
+ } else {
1764
+ foreach ( $this->follow_base_cache_target as $sns => $active ) {
1765
+ if ( $active ) {
1766
+ $sns_followers[$sns] = 0;
1767
  }
1768
  }
1769
  }
1770
+
1771
+ return $sns_followers;
1772
  }
1773
  break;
1774
+ case self::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE:
1775
+ //$this->reserve_follow_cache();
1776
+ $this->cache_engines[self::REF_FOLLOW_LAZY]->prime_cache();
1777
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1778
  if ( $sns_key ) {
1779
  $sns_followers[$sns_key] = 0;
1780
+
1781
  return $sns_followers[$sns_key];
1782
+ } else {
1783
+ foreach ( $this->follow_base_cache_target as $sns => $active ) {
1784
+ if ( $active ) {
1785
+ $sns_followers[$sns] = 0;
 
 
1786
  }
1787
+ }
1788
+
1789
+ return $sns_followers;
1790
+ }
1791
  break;
1792
+ case self::OPT_COMMON_ACCESS_BASED_SYNC_CACHE:
1793
+ //$sns_followers = $this->retrieve_follow_cache();
1794
+ $sns_followers = $this->cache_engines[self::REF_FOLLOW_BASE]->direct_cache();
1795
+
1796
  if ( $sns_key ) {
1797
+ if ( ! isset( $sns_followers[$sns_key] ) || $sns_followers[$sns_key] < 0 ) {
1798
+ $sns_followers[$sns_key] = 0;
1799
+ }
1800
+
1801
  return $sns_followers[$sns_key];
1802
  } else {
1803
+ foreach ( $this->follow_base_cache_target as $sns => $active ) {
1804
+ if ( $active ) {
1805
+ if ( ! isset( $sns_followers[$sns] ) || $sns_followers[$sns] < 0 ) {
1806
+ $sns_followers[$sns] = 0;
1807
+ }
1808
+ }
1809
+ }
1810
+
1811
  return $sns_followers;
1812
  }
1813
  break;
1814
+ case self::OPT_COMMON_ACCESS_BASED_CACHE_NONE:
 
1815
  if ( $sns_key ) {
1816
  $sns_followers[$sns_key] = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1817
 
 
 
 
 
 
1818
  return $sns_followers[$sns_key];
1819
+ } else {
1820
+ foreach ( $this->follow_base_cache_target as $sns => $active ) {
1821
+ if ( $active ) {
1822
+ $sns_followers[$sns] = 0;
 
 
 
 
 
 
 
 
 
 
1823
  }
1824
  }
1825
+
1826
+ return $sns_followers;
1827
+ }
1828
  break;
1829
+ }
1830
+ }
1831
+ }
1832
+
1833
+
1834
+ }
1835
+
1836
+ SNS_Count_Cache::get_instance();
1837
+
1838
+ /**
1839
+ * Get share count from cache
1840
+ *
1841
+ * @since 0.4.0
1842
+ */
1843
+ function scc_get_share( $options = array( 'post_id' => '', 'url' => '', 'sns' => '' ) ) {
1844
+
1845
+ $post_ID = '';
1846
+ $sns_key = '';
1847
+
1848
+ if ( isset( $options['url'] ) && $options['url'] ) {
1849
+ $post_ID = url_to_postid( $options['url'] );
1850
+ } else if ( isset( $options['post_id'] ) && $options['post_id'] ) {
1851
+ $post_ID = $options['post_id'];
1852
+ } else {
1853
+ $post_ID = get_the_ID();
1854
  }
 
1855
 
1856
+ if ( isset( $options['sns'] ) && $options['sns'] ) {
1857
+ $sns_key = $options['sns'];
1858
+ }
1859
+
1860
+ $sns_count_cache = SNS_Count_Cache::get_instance();
1861
+
1862
+ return $sns_count_cache->get_share_counts( $post_ID, $sns_key );
1863
+ }
1864
+
1865
+ /**
1866
+ * Get follow count from cache
1867
+ *
1868
+ * @since 0.4.0
1869
+ */
1870
+ function scc_get_follow( $options = array( 'sns' => '' ) ) {
1871
+
1872
+ $sns_key = '';
1873
+
1874
+ if ( isset( $options['sns'] ) && $options['sns'] ) {
1875
+ $sns_key = $options['sns'];
1876
+ }
1877
+
1878
+ $sns_count_cache = SNS_Count_Cache::get_instance();
1879
+
1880
+ return $sns_count_cache->get_follow_counts( $sns_key );
1881
+
1882
+ }
1883
 
1884
  /**
1885
  * Get share count from cache (Hatena Bookmark).
1886
  *
1887
  * @since 0.4.0
1888
  */
1889
+ function scc_get_share_hatebu( $options = array( 'post_id' => '', 'url' => '' ) ) {
1890
 
1891
  $options['sns'] = SNS_Count_Cache::REF_SHARE_HATEBU;
1892
  return scc_get_share( $options );
1897
  *
1898
  * @since 0.4.0
1899
  */
1900
+ function scc_get_share_twitter( $options = array( 'post_id' => '', 'url' => '' ) ) {
1901
 
1902
  $options['sns'] = SNS_Count_Cache::REF_SHARE_TWITTER;
1903
  return scc_get_share( $options );
1908
  *
1909
  * @since 0.4.0
1910
  */
1911
+ function scc_get_share_facebook( $options = array( 'post_id' => '', 'url' => '' ) ) {
1912
 
1913
  $options['sns'] = SNS_Count_Cache::REF_SHARE_FACEBOOK;
1914
  return scc_get_share( $options );
1919
  *
1920
  * @since 0.4.0
1921
  */
1922
+ function scc_get_share_gplus( $options = array( 'post_id' => '', 'url' => '' ) ) {
1923
 
1924
  $options['sns'] = SNS_Count_Cache::REF_SHARE_GPLUS;
1925
  return scc_get_share( $options );
1930
  *
1931
  * @since 0.4.0
1932
  */
1933
+ function scc_get_share_pocket( $options = array( 'post_id' => '', 'url' => '' ) ) {
1934
 
1935
  $options['sns'] = SNS_Count_Cache::REF_SHARE_POCKET;
1936
  return scc_get_share( $options );
1942
  *
1943
  * @since 0.4.0
1944
  */
1945
+ function scc_get_share_total( $options = array( 'post_id' => '', 'url' => '' ) ) {
1946
 
1947
  $options['sns'] = SNS_Count_Cache::REF_SHARE_TOTAL;
1948
  return scc_get_share( $options );
1954
  * @since 0.1.0
1955
  * @deprecated Function deprecated in Release 0.4.0
1956
  */
1957
+ function get_scc_hatebu( $options = array( 'post_id' => '', 'url' => '' ) ) {
1958
 
1959
  return scc_get_share_hatebu( $options );
1960
  }
1965
  * @since 0.1.0
1966
  * @deprecated Function deprecated in Release 0.4.0
1967
  */
1968
+ function get_scc_twitter( $options = array( 'post_id' => '', 'url' => '' ) ) {
1969
 
1970
  return scc_get_share_twitter( $options );
1971
  }
1976
  * @since 0.1.0
1977
  * @deprecated Function deprecated in Release 0.4.0
1978
  */
1979
+ function get_scc_facebook( $options = array( 'post_id' => '', 'url' => '' ) ) {
1980
 
1981
  return scc_get_share_facebook( $options );
1982
  }
1987
  * @since 0.1.0
1988
  * @deprecated Function deprecated in Release 0.4.0
1989
  */
1990
+ function get_scc_gplus( $options = array( 'post_id' => '', 'url' => '' ) ) {
1991
 
1992
  return scc_get_share_gplus( $options );
1993
  }
1998
  * @since 0.2.1
1999
  * @deprecated Function deprecated in Release 0.4.0
2000
  */
2001
+ function get_scc_pocket( $options = array( 'post_id' => '', 'url' => '' ) ) {
2002
 
2003
  return scc_get_share_pocket( $options );
2004
  }
2013
  $options['sns'] = SNS_Count_Cache::REF_FOLLOW_FEEDLY;
2014
  return scc_get_follow( $options );
2015
  }
2016
+
 
 
2017
 
2018
  }
2019
 
uninstall.php CHANGED
@@ -17,6 +17,7 @@ $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() ) {
@@ -34,7 +35,8 @@ if( ! is_multisite() ) {
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 {
@@ -59,7 +61,8 @@ else {
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
  }
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
+ $db_settings = 'scc_settings';
21
 
22
  // For Single site
23
  if( ! is_multisite() ) {
35
  delete_option( $db_follow_cache_target );
36
  delete_option( $db_data_export_schedule );
37
  delete_option( $db_http_migration_mode );
38
+ delete_option( $db_scheme_migration_mode );
39
+ delete_option( $db_settings );
40
  }
41
  // For Multisite
42
  else {
61
  delete_option( $db_follow_cache_target );
62
  delete_option( $db_data_export_schedule );
63
  delete_option( $db_http_migration_mode );
64
+ delete_option( $db_scheme_migration_mode );
65
+ delete_option( $db_settings );
66
  }
67
  switch_to_blog( $original_blog_id );
68
  }