SNS Count Cache - Version 0.7.0

Version Description

  • Added: function to display variation of SNS count
  • Added: function to access variation of SNS count through custom filed
  • Fixed: custom filed used in this plugin is not deleted in a certain case.

=

Download this release

Release Info

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

Code changes from version 0.6.0 to 0.7.0

css/sns-count-cache.css CHANGED
@@ -78,7 +78,6 @@
78
  color: #ccc;
79
  }
80
 
81
-
82
  .sns-cnt-cache .not-cached {
83
  color: #ccc;
84
  }
@@ -150,4 +149,23 @@
150
  padding: 1px 5px;
151
  height: 20px;
152
  line-height: 15px;
153
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  color: #ccc;
79
  }
80
 
 
81
  .sns-cnt-cache .not-cached {
82
  color: #ccc;
83
  }
149
  padding: 1px 5px;
150
  height: 20px;
151
  line-height: 15px;
152
+ }
153
+
154
+ .sns-cnt-cache .delta-rise {
155
+ color: #FF6866;
156
+ text-decoration: underline;
157
+ background: #FFEFEF;
158
+ font-weight: bold;
159
+ font-size: 11px;
160
+ border-radius: 5%;
161
+ }
162
+
163
+ .sns-cnt-cache .delta-fall {
164
+ color: #f0ad4e;
165
+ text-decoration: underline;
166
+ /* background-color: #dff0d8 */;
167
+ }
168
+
169
+ .sns-cnt-cache .wpcron td {
170
+ border-top: 1px solid #dedede;
171
+ }
includes/admin-cache-status.php CHANGED
@@ -73,11 +73,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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">
@@ -135,7 +138,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>';
@@ -175,7 +178,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
175
  echo '<td class="full-cache">';
176
  _e( 'full cache', self::DOMAIN );
177
  echo '</td>';
178
- } else if ( $partial_cache_flag && ! $full_cache_flag ) {
179
  echo '<td class="partial-cache">';
180
  _e( 'partial cache', self::DOMAIN );
181
  echo '</td>';
@@ -235,7 +238,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>';
@@ -268,7 +271,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>';
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"><?php _e( 'Dashboard', self::DOMAIN ) ?></a>
77
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ) ?></a>
78
+ <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ) ?></a>
79
+ <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
80
+ <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ) ?></a>
81
+ <?php } ?>
82
+ <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ) ?></a>
83
+ <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ) ?></a>
84
  </h3>
85
  <div class="metabox-holder">
86
  <div id="share-site-summary" class="postbox">
138
  echo '<td class="full-cache">';
139
  _e( 'full cache', self::DOMAIN );
140
  echo '</td>';
141
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
142
  echo '<td class="partial-cache">';
143
  _e( 'partial cache', self::DOMAIN );
144
  echo '</td>';
178
  echo '<td class="full-cache">';
179
  _e( 'full cache', self::DOMAIN );
180
  echo '</td>';
181
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
182
  echo '<td class="partial-cache">';
183
  _e( 'partial cache', self::DOMAIN );
184
  echo '</td>';
238
  echo '<td class="full-cache">';
239
  _e( 'full cache', self::DOMAIN );
240
  echo '</td>';
241
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
242
  echo '<td class="partial-cache">';
243
  _e( 'partial cache', self::DOMAIN );
244
  echo '</td>';
271
  echo '<td class="full-cache">';
272
  _e( 'full cache', self::DOMAIN );
273
  echo '</td>';
274
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
275
  echo '<td class="partial-cache">';
276
  _e( 'partial cache', self::DOMAIN );
277
  echo '</td>';
includes/admin-dashboard.php CHANGED
@@ -48,6 +48,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
@@ -127,7 +130,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
 
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
+ <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
52
+ <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ) ?></a>
53
+ <?php } ?>
54
  <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ) ?></a>
55
  <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ) ?></a>
56
  </h3>
130
  echo '</td>';
131
  } else {
132
  echo '<td class="share-count">';
133
+ echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="' . strtolower( $sns ) . '"></span>';
134
  echo '</td>';
135
  }
136
 
includes/admin-help.php CHANGED
@@ -36,11 +36,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
36
  <div class="sns-cnt-cache">
37
 
38
  <h3 class="nav-tab-wrapper">
39
- <a class="nav-tab" href="admin.php?page=scc-dashboard">Dashboard</a>
40
- <a class="nav-tab" href="admin.php?page=scc-cache-status">Cache Status</a>
41
- <a class="nav-tab" href="admin.php?page=scc-share-count">Share Count</a>
42
- <a class="nav-tab" href="admin.php?page=scc-setting">Setting</a>
43
- <a class="nav-tab nav-tab-active" href="admin.php?page=scc-help">Help</a>
 
 
 
44
  </h3>
45
 
46
  <div class="metabox-holder">
@@ -131,7 +134,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
131
  wp_reset_postdata();
132
  ?&gt;</pre>
133
  <h4><?php _e( 'How can I access specific custom field containing each share count?', self::DOMAIN) ?></h4>
134
- <p><?php _e( 'The custom field including share count is accessed using the following meta keys.', self::DOMAIN ) ?></p>
135
  <table class="view-table">
136
  <thead>
137
  <tr>
@@ -147,6 +150,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
147
  <tr><td>scc_share_count_pocket</td><td><?php _e( 'A meta key for Pocket share count', self::DOMAIN ) ?></td></tr>
148
  <tr><td>scc_share_count_total</td><td><?php _e( 'A meta key for total share count', self::DOMAIN ) ?></td></tr>
149
  </tbody>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  </table>
151
  </div>
152
  </div>
36
  <div class="sns-cnt-cache">
37
 
38
  <h3 class="nav-tab-wrapper">
39
+ <a class="nav-tab" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ) ?></a>
40
+ <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ) ?></a>
41
+ <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ) ?></a>
42
+ <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
43
+ <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ) ?></a>
44
+ <?php } ?>
45
+ <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ) ?></a>
46
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ) ?></a>
47
  </h3>
48
 
49
  <div class="metabox-holder">
134
  wp_reset_postdata();
135
  ?&gt;</pre>
136
  <h4><?php _e( 'How can I access specific custom field containing each share count?', self::DOMAIN) ?></h4>
137
+ <p><?php _e( 'Custom fields including share count are accessed using the following meta keys.', self::DOMAIN ) ?></p>
138
  <table class="view-table">
139
  <thead>
140
  <tr>
150
  <tr><td>scc_share_count_pocket</td><td><?php _e( 'A meta key for Pocket share count', self::DOMAIN ) ?></td></tr>
151
  <tr><td>scc_share_count_total</td><td><?php _e( 'A meta key for total share count', self::DOMAIN ) ?></td></tr>
152
  </tbody>
153
+ </table>
154
+ <h4><?php _e( 'How can I access specific custom field containing each variation of share count?', self::DOMAIN) ?></h4>
155
+ <p><?php _e( 'Custom fields including variation of share count are accessed using the following meta keys.', self::DOMAIN ) ?></p>
156
+ <table class="view-table">
157
+ <thead>
158
+ <tr>
159
+ <th><?php _e( 'Meta Key', self::DOMAIN ) ?></th>
160
+ <th><?php _e( 'Description', self::DOMAIN ) ?></th>
161
+ </tr>
162
+ </thead>
163
+ <tbody>
164
+ <tr><td>scc_share_delta_twitter</td><td><?php _e( 'A meta key for variation of Twitter share count', self::DOMAIN ) ?></td></tr>
165
+ <tr><td>scc_share_delta_facebook</td><td><?php _e( 'A meta key for variation of Facebook share count', self::DOMAIN ) ?></td></tr>
166
+ <tr><td>scc_share_delta_google+</td><td><?php _e( 'A meta key for variation of Google Plus share count', self::DOMAIN ) ?></td></tr>
167
+ <tr><td>scc_share_delta_hatebu</td><td><?php _e( 'A meta key for variation of Hatena Bookmark share count', self::DOMAIN ) ?></td></tr>
168
+ <tr><td>scc_share_delta_pocket</td><td><?php _e( 'A meta key for variation of Pocket share count', self::DOMAIN ) ?></td></tr>
169
+ <tr><td>scc_share_delta_total</td><td><?php _e( 'A meta key for variation of total share count', self::DOMAIN ) ?></td></tr>
170
+ </tbody>
171
  </table>
172
  </div>
173
  </div>
includes/admin-hot-content.php ADDED
@@ -0,0 +1,329 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
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
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
+ $posts_per_page = 50;
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->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
51
+ $meta_key2 = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
52
+ }
53
+ }
54
+
55
+ }
56
+
57
+ $paged = 1;
58
+
59
+ if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 0 ) {
60
+ $paged = $_GET['paged'];
61
+ } else {
62
+ $paged = 1;
63
+ }
64
+
65
+ $share_base_cache_target = $this->share_base_cache_target ;
66
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
67
+
68
+ ?>
69
+ <div class="wrap">
70
+ <h2><a href="admin.php?page=scc-hot-content"><?php _e( 'SNS Count Cache', self::DOMAIN ) ?></a></h2>
71
+ <div class="sns-cnt-cache">
72
+ <h3 class="nav-tab-wrapper">
73
+ <a class="nav-tab" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ) ?></a>
74
+ <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ) ?></a>
75
+ <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ) ?></a>
76
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ) ?></a>
77
+ <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ) ?></a>
78
+ <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ) ?></a>
79
+ </h3>
80
+ <div class="metabox-holder">
81
+ <div id="share-each-content" class="postbox">
82
+ <div class="handlediv" title="Click to toggle"><br></div>
83
+ <h3 class="hndle"><span><?php _e( 'Hot Content', self::DOMAIN ) ?></span></h3>
84
+ <div class="inside">
85
+ <table class="view-table">
86
+ <thead>
87
+ <tr>
88
+ <th>No.</th>
89
+ <th><?php _e( 'Content', self::DOMAIN ) ?></th>
90
+ <?php
91
+
92
+ foreach ( $share_base_cache_target as $sns => $active ) {
93
+
94
+ if ( $active ) {
95
+
96
+ $sort_key = $sns;
97
+
98
+ if ( $sort_key === self::REF_SHARE_GPLUS ) {
99
+ $sort_key = str_replace( '+', '', $sort_key );
100
+ }
101
+
102
+ $sort_url = esc_url( 'admin.php?page=scc-hot-content&action=sort&key=' . $sort_key );
103
+
104
+ if ( $sns === $sort_exec_key ){
105
+ echo '<th><a class="sort-exec-key" href="' . $sort_url . '">' . esc_html( $sns ) . '</th>';
106
+ } else {
107
+ echo '<th><a href="' . $sort_url . '">' . esc_html( $sns ) . '</th>';
108
+ }
109
+ }
110
+ }
111
+ ?>
112
+ </tr>
113
+ </thead>
114
+ <tbody>
115
+
116
+ <?php
117
+
118
+ $meta_query = array();
119
+
120
+ if( $sort_mode ) {
121
+
122
+ if ( version_compare( get_bloginfo('version'), '4.2', '>=') ) {
123
+
124
+
125
+ $meta_query['relation'] = 'AND';
126
+
127
+ $meta_query[0]['relation'] = 'OR';
128
+
129
+ foreach ( $share_base_cache_target as $sns => $active ) {
130
+ if ( $active ) {
131
+ $meta_query[0][] = array(
132
+ 'key' => 'scc_share_delta_' . strtolower( $sns ),
133
+ 'value' => 0,
134
+ 'compare'=>'>',
135
+ 'type'=>'NUMERIC'
136
+ );
137
+ }
138
+ }
139
+
140
+ $meta_query['meta_primary'] = array(
141
+ 'key' => $meta_key,
142
+ 'type'=>'NUMERIC'
143
+ );
144
+
145
+ $meta_query['meta_secondary'] = array(
146
+ 'key' => $meta_key2,
147
+ 'type'=>'NUMERIC'
148
+ );
149
+
150
+ Common_Util::log( $meta_query );
151
+
152
+ Common_Util::log( 'version: ' . get_bloginfo( 'version') );
153
+
154
+ $query_args = array(
155
+ 'post_type' => $this->share_base_cache_post_types,
156
+ 'post_status' => 'publish',
157
+ 'posts_per_page' => $posts_per_page,
158
+ 'paged' => $paged,
159
+ 'update_post_term_cache' => false,
160
+ 'meta_query' => $meta_query,
161
+ 'orderby' => array(
162
+ 'meta_primary' => 'DESC',
163
+ 'meta_secondary' => 'DESC'
164
+ )
165
+ );
166
+
167
+ } else {
168
+
169
+ foreach ( $share_base_cache_target as $sns => $active ) {
170
+ if ( $active ) {
171
+ $meta_query[] = array(
172
+ 'key' => 'scc_share_delta_' . strtolower( $sns ),
173
+ 'value' => 0,
174
+ 'compare'=>'>',
175
+ 'type'=>'NUMERIC'
176
+ );
177
+
178
+ }
179
+ }
180
+
181
+ $meta_query['relation'] = 'OR';
182
+
183
+ $query_args = array(
184
+ 'post_type' => $this->share_base_cache_post_types,
185
+ 'post_status' => 'publish',
186
+ 'posts_per_page' => $posts_per_page,
187
+ 'paged' => $paged,
188
+ 'meta_key' => $meta_key,
189
+ 'orderby' => 'meta_value_num',
190
+ 'update_post_term_cache' => false,
191
+ 'order' => 'DESC',
192
+ 'meta_query' => $meta_query
193
+ );
194
+ }
195
+
196
+ } else {
197
+
198
+ foreach ( $share_base_cache_target as $sns => $active ) {
199
+ if ( $active ) {
200
+ $meta_query[] = array(
201
+ 'key' => 'scc_share_delta_' . strtolower( $sns ),
202
+ 'value' => 0,
203
+ 'compare'=>'>',
204
+ 'type'=>'NUMERIC'
205
+ );
206
+
207
+ }
208
+ }
209
+
210
+ $meta_query['relation'] = 'OR';
211
+
212
+ $query_args = array(
213
+ 'post_type' => $this->share_base_cache_post_types,
214
+ 'post_status' => 'publish',
215
+ 'posts_per_page' => $posts_per_page,
216
+ 'paged' => $paged,
217
+ 'meta_query' => $meta_query,
218
+ 'update_post_term_cache' => false
219
+ );
220
+ }
221
+
222
+ $posts_query = new WP_Query( $query_args );
223
+
224
+ $count = ( $paged - 1 ) * $posts_per_page + 1;
225
+
226
+ if ( $posts_query->have_posts() ) {
227
+ while ( $posts_query->have_posts() ) {
228
+ $posts_query->the_post();
229
+ ?>
230
+ <tr>
231
+ <td><?php echo $count; ?></td>
232
+ <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>
233
+ <?php
234
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( get_the_ID() );
235
+
236
+ if( ! $sort_mode && false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
237
+
238
+ foreach ( $share_base_cache_target as $sns => $active ) {
239
+ if ( $active ) {
240
+
241
+ //delta
242
+ $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
243
+ $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
244
+
245
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
246
+ echo '<td class="share-count">';
247
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
248
+
249
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
250
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
251
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
252
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
253
+ }
254
+
255
+ echo '</td>';
256
+ } else {
257
+ echo '<td class="not-cached share-count">';
258
+ _e( 'N/A', self::DOMAIN );
259
+ echo '</td>';
260
+ }
261
+ }
262
+ }
263
+
264
+ } else {
265
+
266
+ foreach ( $share_base_cache_target as $sns => $active ) {
267
+ if( $active ){
268
+
269
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
270
+
271
+ $sns_counts[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
272
+
273
+ //delta
274
+ $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
275
+ $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
276
+
277
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 ) {
278
+ echo '<td class="share-count">';
279
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
280
+
281
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
282
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
283
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
284
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
285
+ }
286
+
287
+ echo '</td>';
288
+ } else {
289
+ echo '<td class="not-cached share-count">';
290
+ _e( 'N/A', self::DOMAIN );
291
+ echo '</td>';
292
+ }
293
+ }
294
+ }
295
+
296
+ }
297
+
298
+ ?>
299
+ </tr>
300
+ <?php
301
+ ++$count;
302
+
303
+ }
304
+ } else {
305
+ echo '<tr>';
306
+ echo '<td>' . $count . '</td>';
307
+ echo '<td>' . __( 'No hot content.', self::DOMAIN ) . '</td>';
308
+ foreach ( $share_base_cache_target as $sns => $active ) {
309
+ if ( $active ) {
310
+ echo '<td class="not-cached share-count">';
311
+ _e( 'N/A', self::DOMAIN );
312
+ echo '</td>';
313
+ }
314
+ }
315
+ echo '</tr>';
316
+ }
317
+ ?>
318
+ </tbody>
319
+ </table>
320
+ <?php
321
+ $this->pagination( $posts_query->max_num_pages, '', $paged, true );
322
+ wp_reset_postdata();
323
+ ?>
324
+
325
+ </div>
326
+ </div>
327
+ </div>
328
+ </div>
329
+ </div>
includes/admin-setting.php CHANGED
@@ -49,7 +49,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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"] ) ) {
@@ -58,12 +58,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
  }
@@ -101,7 +109,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
101
  } else {
102
  $share_base_cache_target[self::REF_SHARE_HATEBU] = false;
103
  }
104
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  if ( ! empty( $share_base_cache_target ) ) {
106
  $settings[self::DB_SHARE_CACHE_TARGET] = $share_base_cache_target;
107
  }
@@ -126,23 +148,40 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 );
@@ -171,16 +210,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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();
179
- //$this->cache_engines[self::REF_SHARE_2ND]->clear_cache();
180
 
181
  set_time_limit( $this->extended_max_execution_time );
182
-
 
 
183
  $this->cache_engines[self::REF_SHARE_2ND]->initialize_cache();
 
184
 
185
  set_time_limit( $this->original_max_execution_time );
186
 
@@ -190,14 +238,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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();
194
- //$this->cache_engines[self::REF_FOLLOW_2ND]->clear_cache();
195
 
196
  set_time_limit( $this->extended_max_execution_time );
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
  }
@@ -227,14 +275,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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">
@@ -251,24 +302,32 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
256
  <?php
257
  $target_sns = array();
258
- if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) {
259
- $target_sns[] = 'Twitter';
260
- }
261
  if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) {
262
  $target_sns[] = 'Facebook';
263
  }
264
  if ( isset( $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) && $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) {
265
  $target_sns[] = 'Google+';
266
  }
 
 
 
 
 
 
 
 
 
 
 
267
  if ( isset( $this->share_base_cache_target[self::REF_SHARE_POCKET] ) && $this->share_base_cache_target[self::REF_SHARE_POCKET] ) {
268
  $target_sns[] = 'Pocket';
269
  }
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
  ?>
@@ -298,7 +357,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
298
  </tr>
299
  <tr>
300
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
301
- <td><?php _e( 'Migration mode from http to https', self::DOMAIN ) ?></td>
302
  <td>
303
  <?php
304
  if ( $this->scheme_migration_mode ) {
@@ -308,7 +367,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
308
  }
309
  ?>
310
  </td>
311
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
  <tr>
313
  <td><?php _e( 'Share Rush Cache', self::DOMAIN ) ?></td>
314
  <td><?php _e( 'Term considering posted content as new content', self::DOMAIN ) ?></td>
@@ -316,21 +390,60 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
324
  </tr>
325
  <tr>
326
- <td><?php _e( 'Follow Base Cache', self::DOMAIN) ?></td><td><?php _e('Target SNS', self::DOMAIN ) ?></td>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
  <td>
328
  <?php
329
  $target_sns = array();
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>
@@ -344,16 +457,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 );
351
  break;
352
  case self::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE:
353
- _e( 'enabled (Asynchronous Cache)', self::DOMAIN );
354
  break;
355
  case self::OPT_COMMON_ACCESS_BASED_2ND_CACHE:
356
- _e( 'enabled (Asynchronous 2nd Cache)', self::DOMAIN );
357
  break;
358
  }
359
  ?>
@@ -375,7 +488,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 ) {
@@ -385,22 +498,23 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 ) {
392
  case self::OPT_COMMON_DATA_EXPORT_MANUAL:
393
  _e( 'Manual', self::DOMAIN );
394
  break;
395
- case self::OPT_COMMON_DATA_EXPORT_AUTO:
396
- _e( 'Auto', self::DOMAIN );
397
  break;
398
  }
399
  ?>
400
  </td>
401
  </tr>
402
  <?php
403
- if ( $this->data_export_mode == self::OPT_COMMON_DATA_EXPORT_AUTO ) {
404
  ?>
405
  <tr>
406
  <td><?php _e( 'Data Export', self::DOMAIN ) ?></td>
@@ -426,10 +540,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
@@ -438,13 +548,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
@@ -471,15 +585,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 ) ?>" />
@@ -496,30 +626,199 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
@@ -557,12 +856,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
@@ -573,7 +872,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
@@ -595,10 +894,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
@@ -609,67 +908,53 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 ); ?>
@@ -686,25 +971,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
  } ?>
@@ -714,29 +999,29 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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>
@@ -745,20 +1030,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
  } ?>
@@ -768,13 +1053,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
  } ?>
@@ -792,7 +1077,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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">
@@ -812,7 +1097,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
812
  if ( isset( $file_size ) ) {
813
  echo $file_size;
814
  } else {
815
- _e('No exported file', self::DOMAIN);
816
  }
817
  ?>
818
  </td>
@@ -867,7 +1152,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
867
  </tbody>
868
  </table>
869
  </form>
870
- <?php
871
  }
872
  ?>
873
  </div>
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_BASE_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"] ) ) {
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_variation_analysis_mode"] ) && $_POST["share_variation_analysis_mode"] ) {
64
+ $settings[self::DB_SHARE_VARIATION_ANALYSIS_MODE] = $_POST["share_variation_analysis_mode"];
65
+ }
66
 
67
  if ( isset( $_POST["share_rush_new_content_term"] ) && $_POST["share_rush_new_content_term"] && is_numeric( $_POST["share_rush_new_content_term"] ) ) {
68
+ $settings[self::DB_SHARE_RUSH_NEW_CONTENT_TERM] = $_POST["share_rush_new_content_term"];
69
  }
70
+
71
+ if ( isset( $_POST["share_rush_check_interval"] ) && $_POST["share_rush_check_interval"] && is_numeric( $_POST["share_rush_check_interval"] ) ) {
72
+ $settings[self::DB_SHARE_RUSH_CHECK_INTERVAL] = $_POST["share_rush_check_interval"];
73
+ }
74
+
75
  if ( isset( $_POST["data_export_mode"] ) && $_POST["data_export_mode"] ) {
76
  $settings[self::DB_COMMON_DATA_EXPORT_MODE] = $_POST["data_export_mode"];
77
  }
109
  } else {
110
  $share_base_cache_target[self::REF_SHARE_HATEBU] = false;
111
  }
112
+
113
+ /*
114
+ if ( isset( $_POST["share_base_cache_target_pinterest"] ) && $_POST["share_base_cache_target_pinterest"] ) {
115
+ $share_base_cache_target[self::REF_SHARE_PINTEREST] = true;
116
+ } else {
117
+ $share_base_cache_target[self::REF_SHARE_PINTEREST] = false;
118
+ }
119
+
120
+ if ( isset( $_POST["share_base_cache_target_linkedin"] ) && $_POST["share_base_cache_target_linkedin"] ) {
121
+ $share_base_cache_target[self::REF_SHARE_LINKEDIN] = true;
122
+ } else {
123
+ $share_base_cache_target[self::REF_SHARE_LINKEDIN] = false;
124
+ }
125
+ */
126
+
127
  if ( ! empty( $share_base_cache_target ) ) {
128
  $settings[self::DB_SHARE_CACHE_TARGET] = $share_base_cache_target;
129
  }
148
  $settings[self::DB_COMMON_SCHEME_MIGRATION_MODE] = self::OPT_COMMON_SCHEME_MIGRATION_MODE_OFF;
149
  }
150
 
151
+ if ( isset( $_POST["scheme_migration_date"] ) && $_POST["scheme_migration_date"] && strptime( $_POST["scheme_migration_date"], '%Y/%m/%d' ) ) {
152
+ $settings[self::DB_COMMON_SCHEME_MIGRATION_DATE] = $_POST["scheme_migration_date"];
153
+ }
154
+
155
  if ( isset( $_POST["crawler_ssl_verification"] ) && $_POST["crawler_ssl_verification"] ) {
156
  $settings[self::DB_COMMON_CRAWLER_SSL_VERIFICATION] = self::OPT_COMMON_CRAWLER_SSL_VERIFY_ON;
157
  } else {
158
  $settings[self::DB_COMMON_CRAWLER_SSL_VERIFICATION] = self::OPT_COMMON_CRAWLER_SSL_VERIFY_OFF;
159
  }
160
+
161
+ if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'mon' ) {
162
+ $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_moncronminutes'] . ' ' . $_POST['a_moncronhours'] . ' ' . $_POST['a_moncronmday'] . ' * *';
163
+ }
164
+ if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'week' ) {
165
+ $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_weekcronminutes'] . ' ' . $_POST['a_weekcronhours'] . ' * * ' . $_POST['a_weekcronwday'];
166
+ }
167
+ if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'day' ) {
168
+ $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_daycronminutes'] . ' ' . $_POST['a_daycronhours'] . ' * * *';
169
+ }
170
+ if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'hour' ) {
171
+ $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_hourcronminutes'] . ' * * * *';
172
+ }
173
 
174
+ if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'mon' ) {
175
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_moncronminutes'] . ' ' . $_POST['e_moncronhours'] . ' ' . $_POST['e_moncronmday'] . ' * *';
176
  }
177
+ if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'week' ) {
178
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_weekcronminutes'] . ' ' . $_POST['e_weekcronhours'] . ' * * ' . $_POST['e_weekcronwday'];
179
  }
180
+ if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'day' ) {
181
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_daycronminutes'] . ' ' . $_POST['e_daycronhours'] . ' * * *';
182
  }
183
+ if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'hour' ) {
184
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_hourcronminutes'] . ' * * * *';
185
  }
186
 
187
  update_option( self::DB_SETTINGS, $settings );
210
 
211
  //wp_safe_redirect( menu_page_url('scc-setting', false ) );
212
  }
213
+
214
+ if( isset( $_POST["update_share_comparison_base"] ) && $_POST["update_share_comparison_base"] === __( 'Update Basis of Comparison', self::DOMAIN ) ) {
215
+ Common_Util::log( '[' . __METHOD__ . '] base' );
216
+
217
+ $this->analytical_engines[self::REF_SHARE_ANALYSIS]->execute_base( NULL );
218
+ //wp_safe_redirect( menu_page_url( 'scc-setting', false ) );
219
+
220
+ }
221
 
222
  if( isset( $_POST["clear_share_base_cache"] ) && $_POST["clear_share_base_cache"] === __( 'Clear Cache', self::DOMAIN ) ) {
223
  Common_Util::log( '[' . __METHOD__ . '] clear cache' );
224
 
 
 
225
 
226
  set_time_limit( $this->extended_max_execution_time );
227
+
228
+ $this->cache_engines[self::REF_SHARE_BASE]->clear_cache();
229
+ //$this->cache_engines[self::REF_SHARE_2ND]->clear_cache();
230
  $this->cache_engines[self::REF_SHARE_2ND]->initialize_cache();
231
+ $this->analytical_engines[self::REF_SHARE_ANALYSIS]->clear_base();
232
 
233
  set_time_limit( $this->original_max_execution_time );
234
 
238
  if( isset( $_POST["clear_follow_base_cache"] ) && $_POST["clear_follow_base_cache"] === __( 'Clear Cache', self::DOMAIN ) ) {
239
  Common_Util::log( '[' . __METHOD__ . '] clear cache' );
240
 
 
 
241
 
242
  set_time_limit( $this->extended_max_execution_time );
243
+
244
+ $this->cache_engines[self::REF_FOLLOW_BASE]->clear_cache();
245
+ //$this->cache_engines[self::REF_FOLLOW_2ND]->clear_cache();
246
  $this->cache_engines[self::REF_FOLLOW_2ND]->initialize_cache();
247
 
248
+ set_time_limit( $this->original_max_execution_time );
249
 
250
  //wp_safe_redirect( menu_page_url('scc-setting', false ) );
251
  }
275
  ?>
276
  <div class="sns-cnt-cache">
277
  <h3 class="nav-tab-wrapper">
278
+ <a class="nav-tab" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ) ?></a>
279
+ <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ) ?></a>
280
+ <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ) ?></a>
281
+ <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
282
+ <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ) ?></a>
283
+ <?php } ?>
284
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ) ?></a>
285
+ <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ) ?></a>
286
  </h3>
287
  <p id="options-menu">
288
+ <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="#share-variation-analysis"><?php _e( 'Share Variation Analysis', 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( 'Data 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>
289
  </p>
290
  <div class="metabox-holder">
291
  <div id="current-parameter" class="postbox">
302
  </thead>
303
  <tbody>
304
  <tr>
305
+ <td><?php _e( 'Share Base Cache', self::DOMAIN) ?></td><td><?php _e( 'Target SNS', self::DOMAIN ) ?></td>
306
  <td>
307
  <?php
308
  $target_sns = array();
 
 
 
309
  if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) {
310
  $target_sns[] = 'Facebook';
311
  }
312
  if ( isset( $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) && $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) {
313
  $target_sns[] = 'Google+';
314
  }
315
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) && $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) {
316
+ $target_sns[] = 'Hatena Bookmark';
317
+ }
318
+ /*
319
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_LINKEDIN] ) && $this->share_base_cache_target[self::REF_SHARE_LINKEDIN] ) {
320
+ $target_sns[] = 'Linkedin';
321
+ }
322
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_PINTEREST] ) && $this->share_base_cache_target[self::REF_SHARE_PINTEREST] ) {
323
+ $target_sns[] = 'Pinterest';
324
+ }
325
+ */
326
  if ( isset( $this->share_base_cache_target[self::REF_SHARE_POCKET] ) && $this->share_base_cache_target[self::REF_SHARE_POCKET] ) {
327
  $target_sns[] = 'Pocket';
328
  }
329
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) {
330
+ $target_sns[] = 'Twitter';
331
  }
332
  echo esc_html( implode( ", ", $target_sns ) );
333
  ?>
357
  </tr>
358
  <tr>
359
  <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
360
+ <td><?php _e( 'Scheme migration mode from http to https', self::DOMAIN ) ?></td>
361
  <td>
362
  <?php
363
  if ( $this->scheme_migration_mode ) {
367
  }
368
  ?>
369
  </td>
370
+ </tr>
371
+ <?php if ( $this->scheme_migration_mode ) { ?>
372
+ <tr>
373
+ <td><?php _e( 'Share Base Cache', self::DOMAIN ) ?></td>
374
+ <td><?php _e( 'Scheme migration date from http to https', self::DOMAIN ) ?></td>
375
+ <td>
376
+ <?php
377
+ if ( isset( $this->scheme_migration_date ) ) {
378
+ echo esc_html( $this->scheme_migration_date );
379
+ } else {
380
+ _e( 'N/A', self::DOMAIN );
381
+ }
382
+ ?>
383
+ </td>
384
+ </tr>
385
+ <?php } ?>
386
  <tr>
387
  <td><?php _e( 'Share Rush Cache', self::DOMAIN ) ?></td>
388
  <td><?php _e( 'Term considering posted content as new content', self::DOMAIN ) ?></td>
390
  <?php
391
  if ( $this->share_rush_new_content_term == 1 ) {
392
  echo esc_html( $this->share_rush_new_content_term ) . ' day';
393
+ } elseif ( $this->share_rush_new_content_term > 1 ) {
394
  echo esc_html( $this->share_rush_new_content_term ) . ' days';
395
  }
396
  ?>
397
  </td>
398
  </tr>
399
  <tr>
400
+ <td><?php _e( 'Share Rush Cache', self::DOMAIN ) ?></td>
401
+ <td><?php _e( 'Interval cheking and caching share count(sec)', self::DOMAIN ) ?></td>
402
+ <td>
403
+ <?php
404
+ echo esc_html( $this->share_rush_check_interval ) . ' seconds'
405
+ ?>
406
+ </td>
407
+ </tr>
408
+
409
+ <tr>
410
+ <td><?php _e( 'Share Variation Analysis', self::DOMAIN ) ?></td>
411
+ <td><?php _e( 'Method to update basis of comparison', self::DOMAIN ) ?></td><td>
412
+ <?php
413
+ switch ( $this->share_variation_analysis_mode ) {
414
+ case self::OPT_SHARE_VARIATION_ANALYSIS_NONE:
415
+ _e( 'Disabled (None)', self::DOMAIN );
416
+ break;
417
+ case self::OPT_SHARE_VARIATION_ANALYSIS_MANUAL:
418
+ _e( 'Enabled (Manual)', self::DOMAIN );
419
+ break;
420
+ case self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER:
421
+ _e( 'Enabled (Scheduler)', self::DOMAIN );
422
+ break;
423
+ }
424
+ ?>
425
+ </td>
426
+ </tr>
427
+ <?php
428
+ if ( $this->share_variation_analysis_mode === self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER ) {
429
+ ?>
430
+ <tr>
431
+ <td><?php _e( 'Share Variation Analysis', self::DOMAIN ) ?></td>
432
+ <td><?php _e( 'Schedule', self::DOMAIN ) ?></td>
433
+ <td><?php echo esc_html( $this->share_variation_analysis_schedule ); ?></td>
434
+ </tr>
435
+ <?php
436
+ }
437
+ ?>
438
+ <tr>
439
+ <td><?php _e( 'Follow Base Cache', self::DOMAIN) ?></td><td><?php _e( 'Target SNS', self::DOMAIN ) ?></td>
440
  <td>
441
  <?php
442
  $target_sns = array();
443
  if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) {
444
  $target_sns[] = 'Feedly';
445
  }
446
+ echo esc_html( implode( ', ', $target_sns ) );
447
  ?>
448
  </td>
449
  </tr>
457
  <?php
458
  switch ( $this->dynamic_cache_mode ) {
459
  case self::OPT_COMMON_ACCESS_BASED_CACHE_NONE:
460
+ _e( 'Disabled (None)', self::DOMAIN );
461
  break;
462
  case self::OPT_COMMON_ACCESS_BASED_SYNC_CACHE:
463
+ _e( 'Enabled (Synchronous Cache)', self::DOMAIN );
464
  break;
465
  case self::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE:
466
+ _e( 'Enabled (Asynchronous Cache)', self::DOMAIN );
467
  break;
468
  case self::OPT_COMMON_ACCESS_BASED_2ND_CACHE:
469
+ _e( 'Enabled (Asynchronous 2nd Cache)', self::DOMAIN );
470
  break;
471
  }
472
  ?>
488
  </td>
489
  </tr>
490
  <tr>
491
+ <td><?php _e( 'Data Crawler', self::DOMAIN ) ?></td><td><?php _e( 'SSL verification', self::DOMAIN ) ?></td>
492
  <td>
493
  <?php
494
  if ( $this->crawler_ssl_verification ) {
498
  }
499
  ?>
500
  </td>
501
+ </tr>
502
+ <tr>
503
+ <td><?php _e( 'Data Export', self::DOMAIN ) ?></td><td><?php _e( 'Method of data export', self::DOMAIN ) ?></td><td>
504
  <?php
505
  switch ( $this->data_export_mode ) {
506
  case self::OPT_COMMON_DATA_EXPORT_MANUAL:
507
  _e( 'Manual', self::DOMAIN );
508
  break;
509
+ case self::OPT_COMMON_DATA_EXPORT_SCHEDULER:
510
+ _e( 'Scheduler', self::DOMAIN );
511
  break;
512
  }
513
  ?>
514
  </td>
515
  </tr>
516
  <?php
517
+ if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_SCHEDULER ) {
518
  ?>
519
  <tr>
520
  <td><?php _e( 'Data Export', self::DOMAIN ) ?></td>
540
  <tr>
541
  <th><label><?php _e( 'Target SNS', self::DOMAIN ) ?></label></th>
542
  <td>
 
 
 
 
543
  <div class="sns-check">
544
  <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"'; ?> />
545
  <label><?php _e( 'Facebook', self::DOMAIN ) ?></label>
548
  <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"'; ?> />
549
  <label><?php _e( 'Google+', self::DOMAIN ) ?></label>
550
  </div>
551
+ <div class="sns-check">
552
+ <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"'; ?> />
553
+ <label><?php _e( 'Hatena Bookmark', self::DOMAIN ) ?></label>
554
+ </div>
555
  <div class="sns-check">
556
  <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"'; ?> />
557
  <label><?php _e( 'Pocket', self::DOMAIN ) ?></label>
558
  </div>
559
  <div class="sns-check">
560
+ <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"'; ?> />
561
+ <label><?php _e( 'Twitter', self::DOMAIN ) ?></label>
562
  </div>
563
  </td>
564
  </tr>
585
  </td>
586
  </tr>
587
  <tr>
588
+ <th><label><?php _e( 'Scheme migration mode from http to https', self::DOMAIN ) ?></label></th>
589
  <td>
590
  <select name="scheme_migration_mode">
591
+ <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>
592
+ <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>
593
  </select>
594
  <label><?php _e('Default: Off', self::DOMAIN) ?></label>
595
  </td>
596
+ </tr>
597
+ <?php if ( $this->scheme_migration_mode ) { ?>
598
+ <tr>
599
+ <th><label><?php _e( 'Scheme migration date from http to https', self::DOMAIN ) ?></label></th>
600
+ <td>
601
+ <input id="scheme-migration-date" type="text" class="text" name="scheme_migration_date" size="20" value="<?php echo esc_html( $this->scheme_migration_date ); ?>" />
602
+ <label><?php _e( 'Default: N/A', self::DOMAIN ) ?></label>
603
+ <script>
604
+ jQuery(document).ready(function() {
605
+ jQuery('#scheme-migration-date').datepicker({
606
+ dateFormat : 'yy/mm/dd'
607
+ });
608
+ });
609
+ </script>
610
+ </td>
611
+ </tr>
612
+ <?php } ?>
613
  </table>
614
  <div class="submit-button">
615
  <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
626
  <th><label><?php _e( 'Term considering posted content as new content', self::DOMAIN ) ?></label></th>
627
  <td>
628
  <select name="share_rush_new_content_term">
629
+ <option value="1"<?php if ( $this->share_rush_new_content_term === 1 ) echo ' selected="selected"'; ?>>1 day</option>
630
+ <option value="2"<?php if ( $this->share_rush_new_content_term === 2 ) echo ' selected="selected"'; ?>>2 days</option>
631
+ <option value="3"<?php if ( $this->share_rush_new_content_term === 3 ) echo ' selected="selected"'; ?>>3 days</option>
632
+ <option value="4"<?php if ( $this->share_rush_new_content_term === 4 ) echo ' selected="selected"'; ?>>4 days</option>
633
+ <option value="5"<?php if ( $this->share_rush_new_content_term === 5 ) echo ' selected="selected"'; ?>>5 days</option>
634
+ <option value="6"<?php if ( $this->share_rush_new_content_term === 6 ) echo ' selected="selected"'; ?>>6 days</option>
635
+ <option value="7"<?php if ( $this->share_rush_new_content_term === 7 ) echo ' selected="selected"'; ?>>7 days</option>
636
+ <option value="8"<?php if ( $this->share_rush_new_content_term === 8 ) echo ' selected="selected"'; ?>>8 days</option>
637
+ <option value="9"<?php if ( $this->share_rush_new_content_term === 9 ) echo ' selected="selected"'; ?>>9 days</option>
638
+ <option value="10"<?php if ( $this->share_rush_new_content_term === 10 ) echo ' selected="selected"'; ?>>10 days</option>
639
+ <option value="11"<?php if ( $this->share_rush_new_content_term === 11 ) echo ' selected="selected"'; ?>>11 days</option>
640
+ <option value="12"<?php if ( $this->share_rush_new_content_term === 12 ) echo ' selected="selected"'; ?>>12 days</option>
641
+ <option value="13"<?php if ( $this->share_rush_new_content_term === 13 ) echo ' selected="selected"'; ?>>13 days</option>
642
+ <option value="14"<?php if ( $this->share_rush_new_content_term === 14 ) echo ' selected="selected"'; ?>>14 days</option>
643
  </select>
644
  <label><?php _e( 'Default: 3 days', self::DOMAIN ) ?></label>
645
  </td>
646
  </tr>
647
+
648
+ <tr>
649
+ <th><label><?php _e( 'Interval cheking and caching share count(sec)', self::DOMAIN ) ?></label></th>
650
+ <td>
651
+ <?php
652
+ echo esc_html( $this->share_rush_check_interval ) . ' seconds'
653
+ ?>
654
+ </td>
655
+ </tr>
656
+
657
  </table>
658
  <div class="submit-button">
659
  <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
660
  </div>
661
  </div>
662
+ </div>
663
+ <div id="share-variation-analysis" class="postbox">
664
+ <div class="handlediv" title="Click to toggle"><br></div>
665
+ <h3 class="hndle"><span><?php _e('Share Variation Analysis', self::DOMAIN) ?></span></h3>
666
+ <div class="inside">
667
+ <table class="form-table">
668
+ <tr>
669
+ <th><label><?php _e( 'Method to update basis of comparison', self::DOMAIN ) ?></label></th>
670
+ <td>
671
+ <select name="share_variation_analysis_mode">
672
+ <option value="1"<?php if ( $this->share_variation_analysis_mode === self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) echo ' selected="selected"'; ?>><?php _e( 'Disabled (None)', self::DOMAIN ) ?></option>
673
+ <option value="2"<?php if ( $this->share_variation_analysis_mode === self::OPT_SHARE_VARIATION_ANALYSIS_MANUAL ) echo ' selected="selected"'; ?>><?php _e( 'Enabled (Manual)', self::DOMAIN ) ?></option>
674
+ <option value="3"<?php if ( $this->share_variation_analysis_mode === self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER ) echo ' selected="selected"'; ?>><?php _e( 'Enabled (Scheduler)', self::DOMAIN ) ?></option>
675
+ </select>
676
+ <label><?php _e( 'Default: None', self::DOMAIN ) ?></label>
677
+ </td>
678
+ </tr>
679
+
680
+ <?php
681
+ if ( $this->share_variation_analysis_mode === self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER ) {
682
+
683
+ list( $cronstr['minutes'], $cronstr['hours'], $cronstr['mday'], $cronstr['mon'], $cronstr['wday'] ) = explode( ' ', $this->share_variation_analysis_schedule, 5 );
684
+ if ( strstr( $cronstr['minutes'], '*/' ) ) {
685
+ $minutes = explode( '/', $cronstr['minutes'] );
686
+ } else {
687
+ $minutes = explode( ',', $cronstr['minutes'] );
688
+ }
689
+ if ( strstr( $cronstr['hours'], '*/' ) ) {
690
+ $hours = explode( '/', $cronstr['hours'] );
691
+ } else {
692
+ $hours = explode( ',', $cronstr['hours'] );
693
+ }
694
+ if ( strstr( $cronstr['mday'], '*/' ) ) {
695
+ $mday = explode( '/', $cronstr['mday'] );
696
+ } else {
697
+ $mday = explode( ',', $cronstr['mday'] );
698
+ }
699
+ if ( strstr( $cronstr['mon'], '*/' ) ) {
700
+ $mon = explode( '/', $cronstr['mon'] );
701
+ } else {
702
+ $mon = explode( ',', $cronstr['mon'] );
703
+ }
704
+ if ( strstr( $cronstr['wday'], '*/' ) ) {
705
+ $wday = explode( '/', $cronstr['wday'] );
706
+ } else {
707
+ $wday = explode( ',', $cronstr['wday'] );
708
+ }
709
+ ?>
710
+ <tr class="a_wpcron">
711
+ <th scope="row"><?php _e( 'Scheduler', self::DOMAIN ); ?></th>
712
+ <td>
713
+ <table class="wpcron">
714
+ <tr>
715
+ <th>
716
+ <?php _e( 'Type', self::DOMAIN ); ?>
717
+ </th>
718
+ <th>
719
+ </th>
720
+ <th>
721
+ <?php _e( 'Hour', self::DOMAIN ); ?>
722
+ </th>
723
+ <th>
724
+ <?php _e( 'Minute', self::DOMAIN ); ?>
725
+ </th>
726
+ </tr>
727
+ <tr>
728
+ <td>
729
+ <label for="idcronbtype-mon">
730
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $mday[0] ), FALSE ) . ' name="a_cronbtype" value="mon" /> ' . __( 'monthly', self::DOMAIN ); ?>
731
+ </label>
732
+ </td>
733
+ <td>
734
+ <select name="a_moncronmday">
735
+ <?php for ( $i = 1; $i <= 31; $i ++ ) {
736
+ echo '<option ' . selected( in_array( "$i", $mday, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . __( 'on', self::DOMAIN ) . ' ' . $i . '.</option>';
737
+ } ?>
738
+ </select>
739
+ </td>
740
+ <td>
741
+ <select name="a_moncronhours">
742
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
743
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
744
+ } ?>
745
+ </select>
746
+ </td>
747
+ <td>
748
+ <select name="a_moncronminutes">
749
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
750
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
751
+ } ?>
752
+ </select>
753
+ </td>
754
+ </tr>
755
+ <tr>
756
+ <td>
757
+ <label for="idcronbtype-week">
758
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $wday[0] ), FALSE ) . ' name="a_cronbtype" value="week" /> ' . __( 'weekly', self::DOMAIN ); ?>
759
+ </label>
760
+ </td>
761
+ <td>
762
+ <select name="a_weekcronwday">
763
+ <?php echo '<option ' . selected( in_array( '0', $wday, TRUE ), TRUE, FALSE ) . ' value="0" />' . __( 'Sunday', self::DOMAIN ) . '</option>';
764
+ echo '<option ' . selected( in_array( '1', $wday, TRUE ), TRUE, FALSE ) . ' value="1" />' . __( 'Monday', self::DOMAIN ) . '</option>';
765
+ echo '<option ' . selected( in_array( '2', $wday, TRUE ), TRUE, FALSE ) . ' value="2" />' . __( 'Tuesday', self::DOMAIN ) . '</option>';
766
+ echo '<option ' . selected( in_array( '3', $wday, TRUE ), TRUE, FALSE ) . ' value="3" />' . __( 'Wednesday', self::DOMAIN ) . '</option>';
767
+ echo '<option ' . selected( in_array( '4', $wday, TRUE ), TRUE, FALSE ) . ' value="4" />' . __( 'Thursday', self::DOMAIN ) . '</option>';
768
+ echo '<option ' . selected( in_array( '5', $wday, TRUE ), TRUE, FALSE ) . ' value="5" />' . __( 'Friday', self::DOMAIN ) . '</option>';
769
+ echo '<option ' . selected( in_array( '6', $wday, TRUE ), TRUE, FALSE ) . ' value="6" />' . __( 'Saturday', self::DOMAIN ) . '</option>'; ?>
770
+ </select>
771
+ </td>
772
+ <td>
773
+ <select name="a_weekcronhours">
774
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
775
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
776
+ } ?>
777
+ </select>
778
+ </td>
779
+ <td>
780
+ <select name="a_weekcronminutes">
781
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
782
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
783
+ } ?></select>
784
+ </td>
785
+ </tr>
786
+ <tr>
787
+ <td>
788
+ <label for="idcronbtype-day">
789
+ <?php echo '<input class="radio" type="radio"' . checked( "**", $mday[0] . $wday[0], FALSE ) . ' name="a_cronbtype" value="day" /> ' . __( 'daily', self::DOMAIN ); ?>
790
+ </label>
791
+ </td>
792
+ <td>
793
+ </td>
794
+ <td>
795
+ <select name="a_daycronhours">
796
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
797
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
798
+ } ?>
799
+ </select>
800
+ </td>
801
+ <td>
802
+ <select name="a_daycronminutes">
803
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
804
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
805
+ } ?>
806
+ </select>
807
+ </td>
808
+ </tr>
809
+ </table>
810
+ </td>
811
+ </tr>
812
+ <?php
813
+ }
814
+ ?>
815
+ </table>
816
+ <div class="submit-button">
817
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
818
+ <input type="submit" class="button" name="update_share_comparison_base" value="<?php _e( 'Update Basis of Comparison', self::DOMAIN ) ?>" />
819
+ </div>
820
+ </div>
821
+ </div>
822
  <div id="follow-base-cache" class="postbox">
823
  <div class="handlediv" title="Click to toggle"><br></div>
824
  <h3 class="hndle"><span><?php _e('Follow Base Cache', self::DOMAIN) ?></span></h3>
856
  <th><label><?php _e( 'Dynamic caching based on user access', self::DOMAIN ) ?></label></th>
857
  <td>
858
  <select name="dynamic_cache_mode">
859
+ <option value="1"<?php if ( $this->dynamic_cache_mode === self::OPT_COMMON_ACCESS_BASED_CACHE_NONE ) echo ' selected="selected"'; ?>><?php _e( 'Disabled (None)', self::DOMAIN ) ?></option>
860
+ <option value="2"<?php if ( $this->dynamic_cache_mode === self::OPT_COMMON_ACCESS_BASED_SYNC_CACHE ) echo ' selected="selected"'; ?>><?php _e( 'Enabled (Synchronous Cache)', self::DOMAIN ) ?></option>
861
+ <option value="3"<?php if ( $this->dynamic_cache_mode === self::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE ) echo ' selected="selected"'; ?>><?php _e( 'Enabled (Asynchronous Cache)', self::DOMAIN ) ?></option>
862
+ <option value="4"<?php if ( $this->dynamic_cache_mode === self::OPT_COMMON_ACCESS_BASED_2ND_CACHE ) echo ' selected="selected"'; ?>><?php _e( 'Enabled (Asynchronous 2nd Cache)', self::DOMAIN ) ?></option>
863
  </select>
864
+ <label><?php _e( 'Default: Enabled (Asynchronous 2nd Cache)', self::DOMAIN) ?></label>
865
  </td>
866
  </tr>
867
  </table>
872
  </div>
873
  <div id="common-data-crawler" class="postbox">
874
  <div class="handlediv" title="Click to toggle"><br></div>
875
+ <h3 class="hndle"><span><?php _e( 'Data Crawler', self::DOMAIN) ?></span></h3>
876
  <div class="inside">
877
  <table class="form-table">
878
  <tr>
894
  <th><label><?php _e( 'SSL verification', self::DOMAIN ) ?></label></th>
895
  <td>
896
  <select name="crawler_ssl_verification">
897
+ <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>
898
+ <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>
899
  </select>
900
+ <label><?php _e( 'Default: On', self::DOMAIN) ?></label>
901
  </td>
902
  </tr>
903
  </table>
908
  </div>
909
  <div id="common-data-export" class="postbox">
910
  <div class="handlediv" title="Click to toggle"><br></div>
911
+ <h3 class="hndle"><span><?php _e( 'Data Export', self::DOMAIN) ?></span></h3>
912
  <div class="inside">
913
  <table class="form-table">
914
  <tr>
915
  <th><label><?php _e( 'Method of data export', self::DOMAIN ) ?></label></th>
916
  <td>
917
  <select name="data_export_mode">
918
+ <option value="1"<?php if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_MANUAL ) echo ' selected="selected"'; ?>><?php _e( 'Manual', self::DOMAIN ) ?></option>
919
+ <option value="2"<?php if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_SCHEDULER ) echo ' selected="selected"'; ?> disabled="disabled"><?php _e( 'Scheduler', self::DOMAIN ) ?></option>
920
  </select>
921
+ <label><?php _e( 'Default: Manual', self::DOMAIN) ?></label>
922
  </td>
923
  </tr>
924
  <?php
925
+ if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_SCHEDULER ) {
926
+
927
+ list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ', $this->data_export_schedule, 5 );
928
+ if ( strstr( $cronstr[ 'minutes' ], '*/' ) ) {
929
+ $minutes = explode( '/', $cronstr[ 'minutes' ] );
930
+ } else {
931
+ $minutes = explode( ',', $cronstr[ 'minutes' ] );
932
+ }
933
+ if ( strstr( $cronstr[ 'hours' ], '*/' ) ) {
934
+ $hours = explode( '/', $cronstr[ 'hours' ] );
935
+ } else {
936
+ $hours = explode( ',', $cronstr[ 'hours' ] );
937
+ }
938
+ if ( strstr( $cronstr[ 'mday' ], '*/' ) ) {
939
+ $mday = explode( '/', $cronstr[ 'mday' ] );
940
+ } else {
941
+ $mday = explode( ',', $cronstr[ 'mday' ] );
942
+ }
943
+ if ( strstr( $cronstr[ 'mon' ], '*/' ) ) {
944
+ $mon = explode( '/', $cronstr[ 'mon' ] );
945
+ } else {
946
+ $mon = explode( ',', $cronstr[ 'mon' ] );
947
+ }
948
+ if ( strstr( $cronstr[ 'wday' ], '*/' ) ) {
949
+ $wday = explode( '/', $cronstr[ 'wday' ] );
950
+ } else {
951
+ $wday = explode( ',', $cronstr[ 'wday' ] );
952
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
953
  ?>
954
+ <tr class="e_wpcron">
955
  <th scope="row"><?php _e( 'Scheduler', self::DOMAIN ); ?></th>
956
  <td>
957
+ <table class="wpcron">
958
  <tr>
959
  <th>
960
  <?php _e( 'Type', self::DOMAIN ); ?>
971
  <tr>
972
  <td>
973
  <label for="idcronbtype-mon">
974
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $mday[0] ), FALSE ) . ' name="e_cronbtype" value="mon" /> ' . __( 'monthly', self::DOMAIN ); ?>
975
  </label>
976
  </td>
977
  <td>
978
+ <select name="e_moncronmday">
979
  <?php for ( $i = 1; $i <= 31; $i ++ ) {
980
  echo '<option ' . selected( in_array( "$i", $mday, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . __( 'on', self::DOMAIN ) . ' ' . $i . '.</option>';
981
  } ?>
982
  </select>
983
  </td>
984
  <td>
985
+ <select name="e_moncronhours">
986
  <?php for ( $i = 0; $i < 24; $i ++ ) {
987
  echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
988
  } ?>
989
  </select>
990
  </td>
991
  <td>
992
+ <select name="e_moncronminutes">
993
  <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
994
  echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
995
  } ?>
999
  <tr>
1000
  <td>
1001
  <label for="idcronbtype-week">
1002
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $wday[0] ), FALSE ) . ' name="e_cronbtype" value="week" /> ' . __( 'weekly', self::DOMAIN ); ?>
1003
  </label>
1004
  </td>
1005
  <td>
1006
+ <select name="e_weekcronwday">
1007
+ <?php echo '<option ' . selected( in_array( '0', $wday, TRUE ), TRUE, FALSE ) . ' value="0" />' . __( 'Sunday', self::DOMAIN ) . '</option>';
1008
+ echo '<option ' . selected( in_array( '1', $wday, TRUE ), TRUE, FALSE ) . ' value="1" />' . __( 'Monday', self::DOMAIN ) . '</option>';
1009
+ echo '<option ' . selected( in_array( '2', $wday, TRUE ), TRUE, FALSE ) . ' value="2" />' . __( 'Tuesday', self::DOMAIN ) . '</option>';
1010
+ echo '<option ' . selected( in_array( '3', $wday, TRUE ), TRUE, FALSE ) . ' value="3" />' . __( 'Wednesday', self::DOMAIN ) . '</option>';
1011
+ echo '<option ' . selected( in_array( '4', $wday, TRUE ), TRUE, FALSE ) . ' value="4" />' . __( 'Thursday', self::DOMAIN ) . '</option>';
1012
+ echo '<option ' . selected( in_array( '5', $wday, TRUE ), TRUE, FALSE ) . ' value="5" />' . __( 'Friday', self::DOMAIN ) . '</option>';
1013
+ echo '<option ' . selected( in_array( '6', $wday, TRUE ), TRUE, FALSE ) . ' value="6" />' . __( 'Saturday', self::DOMAIN ) . '</option>'; ?>
1014
  </select>
1015
  </td>
1016
  <td>
1017
+ <select name="e_weekcronhours">
1018
  <?php for ( $i = 0; $i < 24; $i ++ ) {
1019
  echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1020
  } ?>
1021
  </select>
1022
  </td>
1023
  <td>
1024
+ <select name="e_weekcronminutes">
1025
  <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
1026
  echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1027
  } ?></select>
1030
  <tr>
1031
  <td>
1032
  <label for="idcronbtype-day">
1033
+ <?php echo '<input class="radio" type="radio"' . checked( "**", $mday[0] . $wday[0], FALSE ) . ' name="e_cronbtype" value="day" /> ' . __( 'daily', self::DOMAIN ); ?>
1034
  </label>
1035
  </td>
1036
  <td>
1037
  </td>
1038
  <td>
1039
+ <select name="e_daycronhours">
1040
  <?php for ( $i = 0; $i < 24; $i ++ ) {
1041
  echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1042
  } ?>
1043
  </select>
1044
  </td>
1045
  <td>
1046
+ <select name="e_daycronminutes">
1047
  <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
1048
  echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1049
  } ?>
1053
  <tr>
1054
  <td>
1055
  <label for="idcronbtype-hour">
1056
+ <?php echo '<input class="radio" type="radio"' . checked( "*", $hours[0], FALSE, FALSE ) . ' name="e_cronbtype" value="hour" /> ' . __( 'hourly', self::DOMAIN ); ?>
1057
  </label>
1058
  </td>
1059
  <td></td>
1060
  <td></td>
1061
  <td>
1062
+ <select name="e_hourcronminutes">
1063
  <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
1064
  echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1065
  } ?>
1077
  <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ) ?>" />
1078
  </div>
1079
  </div>
1080
+ </div>
1081
  </form>
1082
  </div>
1083
  <div class="metabox-holder">
1097
  if ( isset( $file_size ) ) {
1098
  echo $file_size;
1099
  } else {
1100
+ _e( 'No exported file', self::DOMAIN);
1101
  }
1102
  ?>
1103
  </td>
1152
  </tbody>
1153
  </table>
1154
  </form>
1155
+ <?php
1156
  }
1157
  ?>
1158
  </div>
includes/admin-share-count.php CHANGED
@@ -69,11 +69,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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">
@@ -119,8 +122,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
  );
@@ -146,56 +149,219 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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
@@ -214,10 +380,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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">';
@@ -235,10 +415,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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">';
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"><?php _e( 'Dashboard', self::DOMAIN ) ?></a>
73
+ <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ) ?></a>
74
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ) ?></a>
75
+ <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
76
+ <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ) ?></a>
77
+ <?php } ?>
78
+ <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ) ?></a>
79
+ <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ) ?></a>
80
  </h3>
81
  <div class="metabox-holder">
82
  <div id="share-each-content" class="postbox">
122
  'post_status' => 'publish',
123
  'posts_per_page' => $posts_per_page,
124
  'paged' => $paged,
125
+ 'meta_key' => $meta_key,
126
+ 'orderby' => 'meta_value_num',
127
  'update_post_term_cache' => false,
128
  'order' => 'DESC'
129
  );
149
  <tr class="home">
150
  <td><?php echo '-'; ?></td>
151
  <td><a href="<?php echo esc_url( home_url( '/' ) ); ?>" target="_blank"><?php echo esc_html( bloginfo('name') ); ?></a></td>
152
+ <?php
153
+
154
+ if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
155
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
156
+
157
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
158
+
159
+ $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
160
+
161
+ if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
162
 
163
+ foreach ( $share_base_cache_target as $sns => $active ) {
164
+ if ( $active ) {
165
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
166
+ echo '<td class="share-count">';
167
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
168
+
169
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
170
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
171
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
172
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
173
+ }
174
+
175
+ echo '</td>';
176
+ } else {
177
+ echo '<td class="not-cached share-count">';
178
+ _e( 'N/A', self::DOMAIN );
179
+ echo '</td>';
180
+ }
181
+ }
182
+ }
183
+
184
+ } else {
185
+
186
+ foreach ( $share_base_cache_target as $sns => $active ) {
187
+ if ( $active ) {
188
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
189
+ echo '<td class="share-count">';
190
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
191
+ echo '</td>';
192
+ } else {
193
+ echo '<td class="not-cached share-count">';
194
+ _e( 'N/A', self::DOMAIN );
195
+ echo '</td>';
196
+ }
197
+ }
198
  }
199
+ }
200
+
201
+ } else {
 
202
 
203
+ $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
204
 
205
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
206
+
207
+ $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
208
+
209
+ if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
210
+ foreach ( $share_base_cache_target as $sns => $active ) {
211
+ if( $active ){
212
+
213
+ if ( $sns_counts[$sns] >= 0 ) {
214
+ echo '<td class="share-count">';
215
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
216
+
217
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
218
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
219
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
220
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
221
+ }
222
+
223
+ echo '</td>';
224
+ } else {
225
+ echo '<td class="not-cached share-count">';
226
+ _e( 'N/A', self::DOMAIN );
227
+ echo '</td>';
228
+ }
229
+ }
230
+ }
231
+ } else {
232
+ foreach ( $share_base_cache_target as $sns => $active ) {
233
+ if ( $active ) {
234
+
235
+ if ( $sns_counts[$sns] >= 0 ) {
236
+ echo '<td class="share-count">';
237
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
238
+ echo '</td>';
239
+ } else {
240
+ echo '<td class="not-cached share-count">';
241
+ _e( 'N/A', self::DOMAIN );
242
+ echo '</td>';
243
+ }
244
+ }
245
+ }
246
+ }
247
+ } else {
248
+ foreach ( $share_base_cache_target as $sns => $active ) {
249
+ if ( $active ) {
250
+ echo '<td class="not-cached share-count">';
251
+ _e( 'N/A', self::DOMAIN );
252
+ echo '</td>';
253
+ }
254
+ }
255
+ }
256
+
257
+ }
258
+ } else {
259
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
260
+
261
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
262
 
263
+ $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
 
264
 
265
+ if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
266
+
267
+ foreach ( $share_base_cache_target as $sns => $active ) {
268
+ if ( $active ) {
269
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
270
+ echo '<td class="share-count">';
271
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
272
+
273
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
274
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
275
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
276
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
277
+ }
278
+
279
+ echo '</td>';
280
+ } else {
281
+ echo '<td class="not-cached share-count">';
282
+ _e( 'N/A', self::DOMAIN );
283
+ echo '</td>';
284
+ }
285
+ }
286
+ }
287
+
288
+ } else {
289
+
290
+ foreach ( $share_base_cache_target as $sns => $active ) {
291
+ if ( $active ) {
292
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
293
+ echo '<td class="share-count">';
294
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
295
+ echo '</td>';
296
+ } else {
297
+ echo '<td class="not-cached share-count">';
298
+ _e( 'N/A', self::DOMAIN );
299
+ echo '</td>';
300
+ }
301
+ }
302
+ }
303
+ }
304
+
305
+
306
+ } else {
307
+
308
+ $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
309
+
310
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
311
+
312
+ $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
313
+
314
+ if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
315
+ foreach ( $share_base_cache_target as $sns => $active ) {
316
+ if( $active ){
317
+
318
+ if ( $sns_counts[$sns] >= 0 ) {
319
+ echo '<td class="share-count">';
320
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
321
+
322
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
323
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
324
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
325
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
326
+ }
327
+
328
+ echo '</td>';
329
+ } else {
330
+ echo '<td class="not-cached share-count">';
331
+ _e( 'N/A', self::DOMAIN );
332
+ echo '</td>';
333
+ }
334
+ }
335
+ }
336
+ } else {
337
+ foreach ( $share_base_cache_target as $sns => $active ) {
338
+ if ( $active ){
339
+
340
+ if ( $sns_counts[$sns] >= 0 ) {
341
+ echo '<td class="share-count">';
342
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
343
+ echo '</td>';
344
+ } else {
345
+ echo '<td class="not-cached share-count">';
346
+ _e( 'N/A', self::DOMAIN );
347
+ echo '</td>';
348
+ }
349
+ }
350
+ }
351
+ }
352
+ } else {
353
+ foreach ( $share_base_cache_target as $sns => $active ) {
354
+ if ( $active ) {
355
  echo '<td class="not-cached share-count">';
356
  _e( 'N/A', self::DOMAIN );
357
  echo '</td>';
358
  }
 
 
 
 
 
 
 
 
359
  }
360
+ }
361
  }
 
362
  }
363
+
364
+
365
  ?>
366
  </tr>
367
  <?php
380
  if( ! $sort_mode && false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
381
 
382
  foreach ( $share_base_cache_target as $sns => $active ) {
383
+ if ( $active ) {
384
+
385
  if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
386
  echo '<td class="share-count">';
387
  echo esc_html( number_format( (int) $sns_counts[$sns] ) );
388
+
389
+ if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
390
+ //delta
391
+ $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
392
+ $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
393
+
394
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
395
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
396
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
397
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
398
+ }
399
+ }
400
+
401
  echo '</td>';
402
  } else {
403
  echo '<td class="not-cached share-count">';
415
  $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
416
 
417
  $sns_counts[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
418
+
419
  if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 ) {
420
  echo '<td class="share-count">';
421
  echo esc_html( number_format( (int) $sns_counts[$sns] ) );
422
+
423
+ if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
424
+
425
+ //delta
426
+ $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
427
+ $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
428
+
429
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
430
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
431
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
432
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
433
+ }
434
+ }
435
+
436
  echo '</td>';
437
  } else {
438
  echo '<td class="not-cached share-count">';
includes/class-analytical-engline.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-analytical-engline.php
4
+
5
+ Description: This class is a data analytical engine.
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
+
33
+ abstract class Analytical_Engine extends Engine {
34
+
35
+ /**
36
+ * Prefix of cache ID
37
+ */
38
+ protected $cache_prefix = NULL;
39
+
40
+ /**
41
+ * Prefix of base ID
42
+ */
43
+ protected $base_prefix = NULL;
44
+
45
+ /**
46
+ * Prefix of base ID
47
+ */
48
+ protected $delta_prefix = NULL;
49
+
50
+ /**
51
+ * instance for delegation
52
+ */
53
+ protected $delegate = NULL;
54
+
55
+ /**
56
+ * Get and cache data for a given post
57
+ *
58
+ * @since 0.1.1
59
+ */
60
+ abstract public function analyze( $options = array() );
61
+
62
+ /**
63
+ * Initialize cache
64
+ *
65
+ * @since 0.3.0
66
+ */
67
+ abstract public function initialize_base();
68
+
69
+ /**
70
+ * Clear cache
71
+ *
72
+ * @since 0.3.0
73
+ */
74
+ abstract public function clear_base();
75
+
76
+ /**
77
+ * Get cache key
78
+ *
79
+ * @since 0.6.0
80
+ */
81
+ public function get_cache_key( $suffix ) {
82
+ return $this->cache_prefix . strtolower( $suffix );
83
+ }
84
+
85
+ /**
86
+ * Get base key
87
+ *
88
+ * @since 0.6.1
89
+ */
90
+ public function get_base_key( $suffix ) {
91
+ return $this->base_prefix . strtolower( $suffix );
92
+ }
93
+
94
+ /**
95
+ * Get delta key
96
+ *
97
+ * @since 0.6.1
98
+ */
99
+ public function get_delta_key( $suffix ) {
100
+ return $this->delta_prefix . strtolower( $suffix );
101
+ }
102
+
103
+ }
104
+
105
+ ?>
includes/class-cache-engine.php CHANGED
@@ -89,6 +89,17 @@ abstract class Cache_Engine extends Engine {
89
  $this->delegate->order_cache( $this, $options );
90
  }
91
  }
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  }
94
 
89
  $this->delegate->order_cache( $this, $options );
90
  }
91
  }
92
+
93
+ /**
94
+ * Order analysis
95
+ *
96
+ * @since 0.6.1
97
+ */
98
+ protected function delegate_analysis( $options = array() ) {
99
+ if ( ! is_null( $this->delegate ) && method_exists( $this->delegate, 'order_analysis' ) ) {
100
+ $this->delegate->order_analysis( $this, $options );
101
+ }
102
+ }
103
 
104
  }
105
 
includes/class-common-util.php CHANGED
@@ -302,6 +302,20 @@ class Common_Util {
302
  }
303
  }
304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  }
306
 
307
  ?>
302
  }
303
  }
304
 
305
+ public static function serialize_base64_encode( $array ) {
306
+ $data = serialize( $array );
307
+ $data = base64_encode( $data );
308
+
309
+ return $data;
310
+ }
311
+
312
+ public static function unserialize_base64_decode( $data ) {
313
+ $data = base64_decode( $data );
314
+ $array = unserialize( $data );
315
+
316
+ return $array;
317
+ }
318
+
319
  }
320
 
321
  ?>
includes/class-follow-crawler.php CHANGED
@@ -111,12 +111,12 @@ class Follow_Crawler extends Data_Crawler {
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;
@@ -126,6 +126,8 @@ class Follow_Crawler extends Data_Crawler {
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;
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 = (int) -1;
117
  }
118
  } else {
119
+ $count = (int) -1;
120
  }
121
 
122
  $sns_counts[SNS_Count_Cache::REF_FOLLOW_FEEDLY] = $count;
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
+ } else {
130
+ $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = '';
131
  }
132
 
133
  return $sns_counts;
includes/class-share-analytical-engine.php ADDED
@@ -0,0 +1,671 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-share-analytical-engine.php
4
+
5
+ Description: This class is a data analytical engine.
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
+
33
+ class Share_Analytical_Engine extends Analytical_Engine {
34
+
35
+ /**
36
+ * Prefix of cache ID
37
+ */
38
+ const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
39
+
40
+ /**
41
+ * Prefix of cache ID
42
+ */
43
+ const DEF_BASE_PREFIX = 'scc_share_base_';
44
+
45
+ /**
46
+ * Prefix of cache ID
47
+ */
48
+ const DEF_DELTA_PREFIX = 'scc_share_delta_';
49
+
50
+ /**
51
+ * Cron name to schedule cache processing
52
+ */
53
+ const DEF_PRIME_CRON = 'scc_share_updatebase_prime';
54
+
55
+ /**
56
+ * Cron name to execute cache processing
57
+ */
58
+ const DEF_EXECUTE_CRON = 'scc_share_updatebase_exec';
59
+
60
+ /**
61
+ * Schedule name for cache processing
62
+ */
63
+ const DEF_EVENT_SCHEDULE = 'share_update_base_event';
64
+
65
+ /**
66
+ * Schedule description for cache processing
67
+ */
68
+ const DEF_EVENT_DESCRIPTION = '[SCC] Share Update Base Interval';
69
+
70
+ /**
71
+ * Interval cheking and caching target data
72
+ */
73
+ private $check_interval = 600;
74
+
75
+ /**
76
+ * Offset suffix
77
+ */
78
+ private $base_schedule = '* * * 0 0';
79
+
80
+ /**
81
+ * Base directory
82
+ */
83
+ private $base_dir = NULL;
84
+
85
+ /**
86
+ * Crawl date key
87
+ */
88
+ private $crawl_date_key = NULL;
89
+
90
+
91
+ /**
92
+ * Initialization
93
+ *
94
+ * @since 0.1.1
95
+ */
96
+ public function initialize( $options = array() ) {
97
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
98
+
99
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
100
+ $this->base_prefix = self::DEF_BASE_PREFIX;
101
+ $this->delta_prefix = self::DEF_DELTA_PREFIX;
102
+ $this->prime_cron = self::DEF_PRIME_CRON;
103
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
104
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
105
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
106
+ $this->base_dir = WP_PLUGIN_DIR . '/sns-count-cache/data/';
107
+
108
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
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['base_schedule'] ) ) $this->base_schedule = $options['base_schedule'];
112
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
113
+ if ( isset( $options['base_prefix'] ) ) $this->base_prefix = $options['base_prefix'];
114
+ if ( isset( $options['delta_prefix'] ) ) $this->delta_prefix = $options['delta_prefix'];
115
+ if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
116
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
117
+ if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
118
+ if ( isset( $options['crawl_date_key'] ) ) $this->crawl_date_key = $options['crawl_date_key'];
119
+
120
+ add_action( $this->prime_cron, array( $this, 'prime_base' ) );
121
+ add_action( $this->execute_cron, array( $this, 'execute_base' ), 10, 1 );
122
+ add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
123
+ }
124
+
125
+ /**
126
+ * Register event schedule for this engine
127
+ *
128
+ * @since 0.1.0
129
+ */
130
+ public function schedule_check_interval( $schedules ) {
131
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
132
+
133
+ $schedules[$this->event_schedule] = array(
134
+ 'interval' => $this->check_interval,
135
+ 'display' => $this->event_description
136
+ );
137
+
138
+ return $schedules;
139
+ }
140
+
141
+ /**
142
+ * Schedule data retrieval and cache processing
143
+ *
144
+ * @since 0.1.0
145
+ */
146
+ public function prime_base() {
147
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
148
+
149
+ $next_exec_time = WP_Cron_Util::next_exec_time( $this->base_schedule );
150
+
151
+ Common_Util::log( '[' . __METHOD__ . '] next_exec_time (timesatamp): ' . $next_exec_time );
152
+ Common_Util::log( '[' . __METHOD__ . '] next_exec_time (date): ' . date_i18n( 'Y/m/d H:i:s', $next_exec_time ) );
153
+
154
+
155
+ if( ! WP_Cron_Util::is_scheduled_hook( $this->execute_cron ) ) {
156
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( Common_Util::short_hash( $next_exec_time ) ) );
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Get and cache data of each published post and page
162
+ *
163
+ * @since 0.1.0
164
+ */
165
+ public function execute_base( $hash ) {
166
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
167
+
168
+ $current_date = date_i18n( 'Y/m/d H:i:s' );
169
+
170
+ set_time_limit( $this->extended_max_execution_time );
171
+
172
+ if( file_exists( $this->base_dir ) ) {
173
+
174
+ $base_file = $this->base_dir . $this->get_base_key( 'home' );
175
+
176
+ if ( ! file_exists( $base_file ) ) {
177
+
178
+ if ( touch( $base_file ) ) {
179
+ Common_Util::log( '[' . __METHOD__ . '] file creation succeeded: ' . $base_file );
180
+ } else {
181
+ Common_Util::log( '[' . __METHOD__ . '] file creation failed: ' . $base_file );
182
+ }
183
+ }
184
+
185
+ if ( file_exists( $base_file ) ) {
186
+ Common_Util::log( '[' . __METHOD__ . '] file exists: ' . $base_file );
187
+
188
+ $option_key = $this->get_cache_key( 'home' );
189
+
190
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
191
+
192
+ foreach ( $this->target_sns as $sns => $active ) {
193
+
194
+ if ( $active ) {
195
+ if ( $sns !== $this->crawl_date_key ) {
196
+ if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
197
+ $sns_counts[$sns] = (int) -1;
198
+ }
199
+ } else {
200
+ if ( ! isset( $sns_counts[$sns] ) ) {
201
+ $sns_counts[$sns] = '';
202
+ }
203
+ }
204
+ }
205
+ }
206
+
207
+ if ( ! in_array( -1, $sns_counts, true ) ) {
208
+
209
+ $data = serialize( $sns_counts );
210
+
211
+ $fp = fopen( $base_file, 'w' );
212
+
213
+ if ( fwrite( $fp, $data ) ) {
214
+ Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ');
215
+ } else {
216
+ Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ');
217
+ }
218
+
219
+ if ( fclose( $fp ) ) {
220
+ Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
221
+ } else {
222
+ Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
223
+ }
224
+ }
225
+
226
+ }
227
+
228
+ }
229
+
230
+ $query_args = array(
231
+ 'post_type' => $this->post_types,
232
+ 'post_status' => 'publish',
233
+ 'nopaging' => true,
234
+ 'update_post_term_cache' => false,
235
+ 'update_post_meta_cache' => false
236
+ );
237
+
238
+ $posts_query = new WP_Query( $query_args );
239
+
240
+ if ( $posts_query->have_posts() ) {
241
+ while ( $posts_query->have_posts() ) {
242
+ $posts_query->the_post();
243
+
244
+ $post_id = get_the_ID();
245
+
246
+ $base_file = $this->base_dir . $this->get_base_key( $post_id );
247
+
248
+ if ( ! file_exists( $base_file ) ) {
249
+
250
+ if ( touch( $base_file ) ) {
251
+ Common_Util::log( '[' . __METHOD__ . '] export file creation succeeded: ' . $base_file );
252
+ } else {
253
+ Common_Util::log( '[' . __METHOD__ . '] export file creation failed: ' . $base_file );
254
+ }
255
+ }
256
+
257
+ if ( file_exists( $base_file ) ) {
258
+
259
+ $sns_counts = array();
260
+
261
+ foreach ( $this->target_sns as $sns => $active ) {
262
+
263
+ if ( $active ) {
264
+
265
+ if ( $sns !== $this->crawl_date_key ) {
266
+
267
+ $meta_key = $this->get_cache_key( $sns );
268
+
269
+ $sns_count = get_post_meta( $post_id, $meta_key, true );
270
+
271
+ if ( isset( $sns_count ) && $sns_count !== '' && $sns_count >= 0 ) {
272
+ $sns_counts[$sns] = (int) $sns_count;
273
+ } else {
274
+ $sns_counts[$sns] = (int) -1;
275
+ }
276
+ } else {
277
+
278
+ $meta_key = $this->get_cache_key( $sns );
279
+
280
+ $sns_count = get_post_meta( $post_id, $meta_key, true );
281
+
282
+ if ( isset( $sns_count ) && $sns_count !== '' ) {
283
+ $sns_counts[$sns] = $sns_count;
284
+ } else {
285
+ $sns_counts[$sns] = '';
286
+ }
287
+
288
+ }
289
+ }
290
+ }
291
+
292
+ if ( ! in_array( -1, $sns_counts, true ) ) {
293
+
294
+ $data = serialize( $sns_counts );
295
+
296
+ $fp = fopen( $base_file, 'w' );
297
+
298
+ if ( fwrite( $fp, $data ) ) {
299
+ Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' );
300
+ } else {
301
+ Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' );
302
+ }
303
+
304
+ if ( fclose( $fp ) ) {
305
+ Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
306
+ } else {
307
+ Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
308
+ }
309
+ }
310
+ }
311
+ }
312
+ }
313
+ wp_reset_postdata();
314
+ }
315
+
316
+ set_time_limit( $this->original_max_execution_time );
317
+ }
318
+
319
+ /**
320
+ * Initialize meta key for ranking
321
+ *
322
+ * @since 0.6.1
323
+ */
324
+ public function analyze( $options = array() ) {
325
+
326
+ $transient_id = $options['cache_key'];
327
+ $target_sns = $options['target_sns'];
328
+ $post_id = $options['post_id'];
329
+
330
+ $base_file = $this->base_dir . $this->get_base_key( $post_id );
331
+
332
+ $sns_counts = array();
333
+ $sns_base_counts = array();
334
+
335
+ if ( file_exists( $base_file ) ) {
336
+
337
+ $fp = fopen( $base_file, 'r' );
338
+
339
+ $data = fread( $fp, filesize( $base_file ) );
340
+
341
+ if ( fclose( $fp ) ) {
342
+ Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
343
+ } else {
344
+ Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
345
+ }
346
+
347
+ $sns_base_counts = unserialize( $data );
348
+
349
+ } else {
350
+ // if there is no base file.
351
+
352
+ if ( touch( $base_file ) ) {
353
+ Common_Util::log( '[' . __METHOD__ . '] file creation succeeded: ' . $base_file );
354
+ } else {
355
+ Common_Util::log( '[' . __METHOD__ . '] file creation failed: ' . $base_file );
356
+ }
357
+
358
+ if ( file_exists( $base_file ) ) {
359
+
360
+ $sns_counts = array();
361
+
362
+ if ( $post_id !== 'home' ) {
363
+
364
+ foreach ( $this->target_sns as $sns => $active ) {
365
+
366
+ if ( $active ) {
367
+
368
+ if ( $sns !== $this->crawl_date_key ) {
369
+
370
+ $meta_key = $this->get_cache_key( $sns );
371
+
372
+ $sns_count = get_post_meta( $post_id, $meta_key, true );
373
+
374
+ if ( isset( $sns_count ) && $sns_count !== '' && $sns_count >= 0 ) {
375
+ $sns_counts[$sns] = (int) $sns_count;
376
+ } else {
377
+ $sns_count[$sns] = (int) -1;
378
+ }
379
+ } else {
380
+
381
+ $meta_key = $this->get_cache_key( $sns );
382
+
383
+ $sns_count = get_post_meta( $post_id, $meta_key, true );
384
+
385
+ if ( isset( $sns_count ) && $sns_count !== '' ) {
386
+ $sns_counts[$sns] = $sns_count;
387
+ } else {
388
+ $sns_counts[$sns] = '';
389
+ }
390
+
391
+ }
392
+ }
393
+
394
+ }
395
+ } else {
396
+ $option_key = $this->get_cache_key( 'home' );
397
+
398
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
399
+
400
+ foreach ( $this->target_sns as $sns => $active ) {
401
+
402
+ if ( $active ) {
403
+ if ( $sns !== $this->crawl_date_key ) {
404
+ if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
405
+ $sns_counts[$sns] = (int) -1;
406
+ }
407
+ } else {
408
+ if ( ! isset( $sns_counts[$sns] ) ) {
409
+ $sns_counts[$sns] = '';
410
+ }
411
+ }
412
+ }
413
+ }
414
+ }
415
+
416
+ }
417
+
418
+ if ( ! in_array( -1, $sns_counts, true ) ) {
419
+
420
+ $data = serialize( $sns_counts );
421
+
422
+ $fp = fopen( $base_file, 'w' );
423
+
424
+ if ( fwrite( $fp, $data ) ) {
425
+ Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' );
426
+ } else {
427
+ Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' );
428
+ }
429
+
430
+ if ( fclose( $fp ) ) {
431
+ Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
432
+ } else {
433
+ Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
434
+ }
435
+ }
436
+ }
437
+
438
+ }
439
+
440
+ $sns_counts = array();
441
+ $diffs = array();
442
+
443
+ if ( $post_id !== 'home' ) {
444
+
445
+ foreach ( $this->target_sns as $sns => $active ) {
446
+ if( $active ){
447
+ $meta_key = $this->get_cache_key( $sns );
448
+ $sns_counts[$sns] = get_post_meta( $post_id, $meta_key, true );
449
+ }
450
+ }
451
+
452
+ if ( ! in_array( -1, $sns_counts, true ) ) {
453
+
454
+ foreach ( $this->target_sns as $sns => $active ) {
455
+
456
+ if( $active ){
457
+
458
+ if ( $sns !== $this->crawl_date_key ) {
459
+
460
+ $diff = 0;
461
+
462
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 && isset( $sns_base_counts[$sns] ) && $sns_base_counts[$sns] !== '' && $sns_base_counts[$sns] >= 0 ) {
463
+ $diff = $sns_counts[$sns] - $sns_base_counts[$sns];
464
+ } else {
465
+ $diff = 0;
466
+ }
467
+
468
+ $meta_key = $this->get_delta_key( $sns );
469
+
470
+ update_post_meta( $post_id, $meta_key, (int) $diff );
471
+
472
+ } else {
473
+
474
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && isset( $sns_base_counts[$sns] ) && $sns_base_counts[$sns] !== '' ) {
475
+ $crawl_date = $sns_base_counts[$sns] . ',' . $sns_counts[$sns];
476
+ } else {
477
+ $crawl_date = '';
478
+ }
479
+
480
+ $meta_key = $this->get_delta_key( $sns );
481
+
482
+ update_post_meta( $post_id, $meta_key, $crawl_date );
483
+
484
+ }
485
+ }
486
+ }
487
+ } else {
488
+
489
+ foreach ( $this->target_sns as $sns => $active ) {
490
+
491
+ if( $active ){
492
+
493
+ $meta_key = $this->get_delta_key( $sns );
494
+
495
+ if ( $sns !== $this->crawl_date_key ) {
496
+
497
+ $diff = 0;
498
+
499
+ update_post_meta( $post_id, $meta_key, (int) $diff );
500
+
501
+ } else {
502
+
503
+ $crawl_date = '';
504
+
505
+ update_post_meta( $post_id, $meta_key, $crawl_date );
506
+ }
507
+ }
508
+ }
509
+
510
+ }
511
+
512
+ } else {
513
+
514
+ $option_key = $this->get_cache_key( 'home' );
515
+
516
+ $diffs = array();
517
+
518
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
519
+
520
+ if ( ! in_array( -1, $sns_counts, true ) ) {
521
+ foreach ( $this->target_sns as $sns => $active ) {
522
+ if( $active ){
523
+ if ( $sns !== $this->crawl_date_key ) {
524
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 && isset( $sns_base_counts[$sns] ) && $sns_base_counts[$sns] !== '' && $sns_base_counts[$sns] >= 0 ) {
525
+ $diffs[$sns] = (int)( $sns_counts[$sns] - $sns_base_counts[$sns] );
526
+ } else {
527
+ $diffs[$sns] = 0;
528
+ }
529
+ } else {
530
+ if ( isset( $sns_counts[$sns] ) && isset( $sns_base_counts[$sns] ) && $sns_base_counts[$sns] !== '' ) {
531
+ $diffs[$sns] = $sns_base_counts[$sns] . ',' . $sns_counts[$sns];
532
+ } else {
533
+ $diffs[$sns] = '';
534
+ }
535
+ }
536
+ }
537
+ }
538
+
539
+ $option_key = $this->get_delta_key( 'home' );
540
+
541
+ update_option( $option_key, $diffs );
542
+
543
+ } else {
544
+ foreach ( $this->target_sns as $sns => $active ) {
545
+ if( $active ){
546
+ if ( $sns !== $this->crawl_date_key ) {
547
+ $diffs[$sns] = (int) 0;
548
+ } else {
549
+ $diffs[$sns] = '';
550
+ }
551
+ }
552
+ }
553
+
554
+ $option_key = $this->get_delta_key( 'home' );
555
+
556
+ update_option( $option_key, $diffs );
557
+ }
558
+
559
+ } else {
560
+
561
+ foreach ( $this->target_sns as $sns => $active ) {
562
+ if( $active ){
563
+ if ( $sns !== $this->crawl_date_key ) {
564
+ $diffs[$sns] = (int) 0;
565
+ } else {
566
+ $diffs[$sns] = '';
567
+ }
568
+ }
569
+ }
570
+
571
+ $option_key = $this->get_delta_key( 'home' );
572
+
573
+ update_option( $option_key, $diffs );
574
+
575
+ }
576
+
577
+ }
578
+
579
+ }
580
+
581
+ /**
582
+ * Initialize meta key for ranking
583
+ *
584
+ * @since 0.3.0
585
+ */
586
+ public function initialize_base() {
587
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
588
+
589
+ /*
590
+ $option_key = $this->get_cache_key( $this->offset_suffix );
591
+
592
+ update_option( $option_key, 0 );
593
+ */
594
+ }
595
+
596
+ /**
597
+ * Clear meta key for ranking
598
+ *
599
+ * @since 0.3.0
600
+ */
601
+ public function clear_base() {
602
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
603
+
604
+ $option_key = $this->get_delta_key( 'home' );
605
+
606
+ delete_option( $option_key );
607
+
608
+ /*
609
+ $query_args = array(
610
+ 'post_type' => $this->post_types,
611
+ 'post_status' => 'publish',
612
+ 'nopaging' => true,
613
+ 'update_post_term_cache' => false,
614
+ 'update_post_meta_cache' => false
615
+ );
616
+
617
+ $posts_query = new WP_Query( $query_args );
618
+
619
+ if ( $posts_query->have_posts() ) {
620
+ while ( $posts_query->have_posts() ) {
621
+ $posts_query->the_post();
622
+
623
+ $post_id = get_the_ID();
624
+
625
+ foreach ( $this->target_sns as $sns => $active ) {
626
+
627
+ if ( $active ) {
628
+ $meta_key = $this->get_delta_key( $sns );
629
+
630
+ delete_post_meta( $post_id, $meta_key );
631
+ }
632
+ }
633
+ }
634
+ }
635
+ wp_reset_postdata();
636
+ */
637
+
638
+ foreach ( $this->target_sns as $sns => $active ) {
639
+
640
+ if ( $active ) {
641
+ $meta_key = $this->get_delta_key( $sns );
642
+
643
+ delete_post_meta_by_key( $meta_key );
644
+ }
645
+ }
646
+
647
+ }
648
+
649
+ /**
650
+ * Clear meta key for ranking
651
+ *
652
+ * @since 0.7.0
653
+ */
654
+ public function clear_base_by_post_id( $post_id ) {
655
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
656
+
657
+ foreach ( $this->target_sns as $sns => $active ) {
658
+
659
+ if ( $active ) {
660
+ $meta_key = $this->get_delta_key( $sns );
661
+ delete_post_meta( $post_id, $meta_key );
662
+ }
663
+
664
+ }
665
+
666
+ }
667
+
668
+
669
+ }
670
+
671
+ ?>
includes/class-share-base-cache-engine.php CHANGED
@@ -98,6 +98,7 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
98
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
99
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
100
  if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
 
101
  if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
102
 
103
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
@@ -186,6 +187,7 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
186
  'post_id' => $post_ID,
187
  'target_url' => $url,
188
  'target_sns' => $this->target_sns,
 
189
  'cache_expiration' => $cache_expiration
190
  );
191
 
@@ -226,6 +228,7 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
226
  'post_id' => $post_ID,
227
  'target_url' => $url,
228
  'target_sns' => $this->target_sns,
 
229
  'cache_expiration' => $cache_expiration
230
  );
231
 
@@ -256,8 +259,10 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
256
 
257
  if ( $post_ID != 'home' ) {
258
  $url = get_permalink( $post_ID );
 
259
  } else {
260
  $url = home_url( '/' );
 
261
  }
262
 
263
  $options = array(
@@ -265,6 +270,7 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
265
  'post_id' => $post_ID,
266
  'target_url' => $url,
267
  'target_sns' => $this->target_sns,
 
268
  'cache_expiration' => $cache_expiration
269
  );
270
 
@@ -348,6 +354,21 @@ class Share_Base_Cache_Engine extends Share_Cache_Engine {
348
  delete_option( $option_key );
349
 
350
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
 
352
  /**
353
  * Get total count of current published post and page
98
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
99
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
100
  if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
101
+ if ( isset( $options['scheme_migration_date'] ) ) $this->scheme_migration_date = $options['scheme_migration_date'];
102
  if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
103
 
104
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
187
  'post_id' => $post_ID,
188
  'target_url' => $url,
189
  'target_sns' => $this->target_sns,
190
+ 'publish_date' => NULL,
191
  'cache_expiration' => $cache_expiration
192
  );
193
 
228
  'post_id' => $post_ID,
229
  'target_url' => $url,
230
  'target_sns' => $this->target_sns,
231
+ 'publish_date' => get_the_date( 'Y/m/d' ),
232
  'cache_expiration' => $cache_expiration
233
  );
234
 
259
 
260
  if ( $post_ID != 'home' ) {
261
  $url = get_permalink( $post_ID );
262
+ $publish_date = get_the_date( 'Y/m/d', $post_ID );
263
  } else {
264
  $url = home_url( '/' );
265
+ $publish_date = NULL;
266
  }
267
 
268
  $options = array(
270
  'post_id' => $post_ID,
271
  'target_url' => $url,
272
  'target_sns' => $this->target_sns,
273
+ 'publish_date' => $publish_date,
274
  'cache_expiration' => $cache_expiration
275
  );
276
 
354
  delete_option( $option_key );
355
 
356
  }
357
+
358
+
359
+ /**
360
+ * Clear meta key for ranking
361
+ *
362
+ * @since 0.7.0
363
+ */
364
+ public function clear_cache_by_post_id( $post_id ) {
365
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
366
+
367
+ $transient_id = $this->get_cache_key( $post_id );
368
+
369
+ delete_transient( $transient_id );
370
+
371
+ }
372
 
373
  /**
374
  * Get total count of current published post and page
includes/class-share-cache-engine.php CHANGED
@@ -47,10 +47,15 @@ abstract class Share_Cache_Engine extends Cache_Engine {
47
  protected $post_types = array( 'post', 'page' );
48
 
49
  /**
50
- * migration between http and https
51
  */
52
  protected $scheme_migration_mode = false;
53
 
 
 
 
 
 
54
  /**
55
  * excluded keys in scheme migration
56
  */
@@ -68,6 +73,7 @@ abstract class Share_Cache_Engine extends Cache_Engine {
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
 
@@ -76,8 +82,87 @@ abstract class Share_Cache_Engine extends Cache_Engine {
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;
@@ -98,7 +183,8 @@ abstract class Share_Cache_Engine extends Cache_Engine {
98
  }
99
  }
100
 
101
- }
 
102
 
103
  if ( $data ) {
104
  $result = set_transient( $cache_key, $data, $cache_expiration );
47
  protected $post_types = array( 'post', 'page' );
48
 
49
  /**
50
+ * migration mode from http to https
51
  */
52
  protected $scheme_migration_mode = false;
53
 
54
+ /**
55
+ * migration date from http to https
56
+ */
57
+ protected $scheme_migration_date = NULL;
58
+
59
  /**
60
  * excluded keys in scheme migration
61
  */
73
  $target_url = $options['target_url'];
74
  $target_sns = $options['target_sns'];
75
  $cache_expiration = $options['cache_expiration'];
76
+ $publish_date = $options['publish_date'];
77
 
78
  Common_Util::log( '[' . __METHOD__ . '] current memory usage: ' . round( memory_get_usage( true )/1024/1024, 2 ) . ' MB' );
79
 
82
  $data = $this->crawler->get_data( $target_sns, $target_url );
83
 
84
  Common_Util::log( $data );
85
+
86
+ Common_Util::log( '[' . __METHOD__ . '] scheme migration date: ' . $this->scheme_migration_date );
87
+ Common_Util::log( '[' . __METHOD__ . '] publish date: ' . $publish_date );
88
+
89
+ if ( $this->scheme_migration_mode && Common_Util::is_secure_url( $target_url ) ) {
90
+
91
+ if ( ! isset( $this->scheme_migration_date ) ) {
92
+ $target_url = Common_Util::get_normal_url( $target_url );
93
+
94
+ $target_sns_migrated = $target_sns;
95
+
96
+ foreach ( $this->scheme_migration_exclude_keys as $sns ) {
97
+ unset( $target_sns_migrated[$sns] );
98
+ }
99
+
100
+ Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_url );
101
+
102
+ $migrated_data = $this->crawler->get_data( $target_sns_migrated, $target_url );
103
 
104
+ Common_Util::log( $migrated_data );
105
+
106
+ foreach ( $target_sns_migrated as $sns => $active ) {
107
+ if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
108
+ $data[$sns] = $data[$sns] + $migrated_data[$sns];
109
+ }
110
+ }
111
+
112
+ } else {
113
+ if ( isset( $publish_date ) ) {
114
+ if ( strtotime( $publish_date ) <= strtotime( $this->scheme_migration_date ) ) {
115
+ Common_Util::log( '[' . __METHOD__ . '] oooooo: ' . $this->scheme_migration_date );
116
+
117
+ $target_url = Common_Util::get_normal_url( $target_url );
118
+
119
+ $target_sns_migrated = $target_sns;
120
+
121
+ foreach ( $this->scheme_migration_exclude_keys as $sns ) {
122
+ unset( $target_sns_migrated[$sns] );
123
+ }
124
+
125
+ Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_url );
126
+
127
+ $migrated_data = $this->crawler->get_data( $target_sns_migrated, $target_url );
128
+
129
+ Common_Util::log( $migrated_data );
130
+
131
+ foreach ( $target_sns_migrated as $sns => $active ) {
132
+ if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
133
+ $data[$sns] = $data[$sns] + $migrated_data[$sns];
134
+ }
135
+ }
136
+ }
137
+ } else {
138
+ $target_url = Common_Util::get_normal_url( $target_url );
139
+
140
+ $target_sns_migrated = $target_sns;
141
+
142
+ foreach ( $this->scheme_migration_exclude_keys as $sns ) {
143
+ unset( $target_sns_migrated[$sns] );
144
+ }
145
+
146
+ Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_url );
147
+
148
+ $migrated_data = $this->crawler->get_data( $target_sns_migrated, $target_url );
149
+
150
+ Common_Util::log( $migrated_data );
151
+
152
+ foreach ( $target_sns_migrated as $sns => $active ) {
153
+ if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
154
+ $data[$sns] = $data[$sns] + $migrated_data[$sns];
155
+ }
156
+ }
157
+ }
158
+
159
+ }
160
+
161
+ }
162
+
163
+ /*
164
  if ( $this->scheme_migration_mode && Common_Util::is_secure_url( $target_url ) ) {
165
+
166
  $target_url = Common_Util::get_normal_url( $target_url );
167
 
168
  $target_sns_migrated = $target_sns;
183
  }
184
  }
185
 
186
+ }
187
+ */
188
 
189
  if ( $data ) {
190
  $result = set_transient( $cache_key, $data, $cache_expiration );
includes/class-share-crawler.php CHANGED
@@ -97,6 +97,17 @@ class Share_Crawler extends Data_Crawler {
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;
@@ -122,11 +133,11 @@ class Share_Crawler extends Data_Crawler {
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;
@@ -137,12 +148,12 @@ class Share_Crawler extends Data_Crawler {
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;
@@ -152,12 +163,12 @@ class Share_Crawler extends Data_Crawler {
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;
@@ -168,12 +179,12 @@ class Share_Crawler extends Data_Crawler {
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;
@@ -184,16 +195,56 @@ class Share_Crawler extends Data_Crawler {
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
 
@@ -209,11 +260,13 @@ class Share_Crawler extends Data_Crawler {
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;
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
+ if ( isset( $target_sns[SNS_Count_Cache::REF_SHARE_PINTEREST] ) && $target_sns[SNS_Count_Cache::REF_SHARE_PINTEREST] ) {
103
+ $query_urls[SNS_Count_Cache::REF_SHARE_PINTEREST] = 'http://api.pinterest.com/v1/urls/count.json?url=' . $url;
104
+ }
105
+
106
+ if ( isset( $target_sns[SNS_Count_Cache::REF_SHARE_LINKEDIN] ) && $target_sns[SNS_Count_Cache::REF_SHARE_LINKEDIN] ) {
107
+ $query_urls[SNS_Count_Cache::REF_SHARE_LINKEDIN] = 'http://www.linkedin.com/countserv/count/share?url=' . $url;
108
+ }
109
+ */
110
+
111
  }
112
 
113
  return $query_urls;
133
  switch ( $sns ) {
134
  case SNS_Count_Cache::REF_SHARE_HATEBU:
135
  if ( isset( $content['data'] ) && empty( $content['error'] ) && is_numeric( $content['data'] ) ) {
136
+ $count = (int) $content['data'];
137
+ } elseif ( empty( $content['data'] ) && empty( $content['error'] ) ) {
138
+ $count = (int) 0;
139
  } else {
140
+ $count = (int) -1;
141
  }
142
 
143
  $sns_counts[SNS_Count_Cache::REF_SHARE_HATEBU] = $count;
148
  $json = json_decode( $content['data'], true );
149
 
150
  if ( isset( $json[0]['total_count'] ) && is_numeric( $json[0]['total_count'] ) ) {
151
+ $count = (int) $json[0]['total_count'];
152
  } else {
153
+ $count = (int) -1;
154
  }
155
  } else {
156
+ $count = (int) -1;
157
  }
158
 
159
  $sns_counts[SNS_Count_Cache::REF_SHARE_FACEBOOK] = $count;
163
  $json = json_decode( $content['data'], true );
164
 
165
  if ( isset( $json['count'] ) && is_numeric( $json['count'] ) ) {
166
+ $count = (int) $json['count'];
167
  } else {
168
+ $count = (int) -1;
169
  }
170
  } else {
171
+ $count = (int) -1;
172
  }
173
 
174
  $sns_counts[SNS_Count_Cache::REF_SHARE_TWITTER] = $count;
179
  $return_code = preg_match( '/\[2,([0-9.]+),\[/', $content['data'], $matches );
180
 
181
  if ( $return_code && isset( $matches[1] ) && is_numeric( $matches[1] ) ) {
182
+ $count = (int) $matches[1];
183
  } else {
184
+ $count = (int) -1;
185
  }
186
  } else {
187
+ $count = (int) -1;
188
  }
189
 
190
  $sns_counts[SNS_Count_Cache::REF_SHARE_GPLUS] = $count;
195
  $return_code = preg_match( '/<em\sid=\"cnt\">([0-9]+)<\/em>/i', $content['data'], $matches );
196
 
197
  if ( $return_code && isset( $matches[1] ) && is_numeric( $matches[1] ) ) {
198
+ $count = (int) $matches[1];
199
  } else {
200
+ $count = (int) -1;
201
  }
202
  } else {
203
+ $count = (int) -1;
204
  }
205
 
206
  $sns_counts[SNS_Count_Cache::REF_SHARE_POCKET] = $count;
207
  break;
208
+ /*
209
+ case SNS_Count_Cache::REF_SHARE_PINTEREST:
210
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
211
+
212
+ $json = rtrim( $content['data'], ')' );
213
+ $json = ltrim( $json, 'receiveCount(' );
214
+
215
+ $json = json_decode( $json, true );
216
+
217
+ if ( isset( $json['count'] ) && is_numeric( $json['count'] ) ) {
218
+ $count = (int) $json['count'];
219
+ } else {
220
+ $count = (int) -1;
221
+ }
222
+ } else {
223
+ $count = (int) -1;
224
+ }
225
+
226
+ $sns_counts[SNS_Count_Cache::REF_SHARE_PINTEREST] = $count;
227
+ break;
228
+ case SNS_Count_Cache::REF_SHARE_LINKEDIN:
229
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
230
+
231
+ $json = rtrim( $content['data'], ');' );
232
+ $json = ltrim( $json, 'IN.Tags.Share.handleCount(' );
233
+
234
+ $json = json_decode( $json, true );
235
+
236
+ if ( isset( $json['count'] ) && is_numeric( $json['count'] ) ) {
237
+ $count = (int) $json['count'];
238
+ } else {
239
+ $count = (int) -1;
240
+ }
241
+ } else {
242
+ $count = (int) -1;
243
+ }
244
+
245
+ $sns_counts[SNS_Count_Cache::REF_SHARE_LINKEDIN] = $count;
246
+ break;
247
+ */
248
 
249
  }
250
 
260
  }
261
  }
262
 
263
+ $sns_counts[SNS_Count_Cache::REF_SHARE_TOTAL] = (int) $total;
264
  }
265
 
266
  if ( isset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) && $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) {
267
  $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = $extract_date;
268
+ } else {
269
+ $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = '';
270
  }
271
 
272
  return $sns_counts;
includes/class-share-lazy-cache-engine.php CHANGED
@@ -96,6 +96,7 @@ class Share_Lazy_Cache_Engine extends Share_Cache_Engine {
96
  if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
97
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
98
  if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
 
99
  if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
100
 
101
  add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
@@ -155,8 +156,10 @@ class Share_Lazy_Cache_Engine extends Share_Cache_Engine {
155
 
156
  if ( $post_ID != 'home' ) {
157
  $url = get_permalink( $post_ID );
 
158
  } else {
159
  $url = home_url( '/' );
 
160
  }
161
 
162
  $options = array(
@@ -164,6 +167,7 @@ class Share_Lazy_Cache_Engine extends Share_Cache_Engine {
164
  'post_id' => $post_ID,
165
  'target_url' => $url,
166
  'target_sns' => $this->target_sns,
 
167
  'cache_expiration' => $cache_expiration
168
  );
169
 
96
  if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
97
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
98
  if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
99
+ if ( isset( $options['scheme_migration_date'] ) ) $this->scheme_migration_date = $options['scheme_migration_date'];
100
  if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
101
 
102
  add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
156
 
157
  if ( $post_ID != 'home' ) {
158
  $url = get_permalink( $post_ID );
159
+ $publish_date = get_the_date( 'Y/m/d', $post_ID );
160
  } else {
161
  $url = home_url( '/' );
162
+ $publish_date = NULL;
163
  }
164
 
165
  $options = array(
167
  'post_id' => $post_ID,
168
  'target_url' => $url,
169
  'target_sns' => $this->target_sns,
170
+ 'publish_date' => $publish_date,
171
  'cache_expiration' => $cache_expiration
172
  );
173
 
includes/class-share-rescue-cache-engine.php CHANGED
@@ -223,7 +223,7 @@ class Share_Rescue_Cache_Engine extends Share_Cache_Engine {
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
 
223
  $no_cache_post_IDs[$post_ID] = 1;
224
  }
225
  }
226
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
227
  //partial cache
228
  $transient_id = $this->get_cache_key( $post_ID );
229
 
includes/class-share-rush-cache-engine.php CHANGED
@@ -104,6 +104,7 @@ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
104
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
105
  if ( isset( $options['new_content_term'] ) ) $this->new_content_term = $options['new_content_term'];
106
  if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
 
107
  if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
108
 
109
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
@@ -217,6 +218,7 @@ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
217
  'post_id' => $post_ID,
218
  'target_url' => $url,
219
  'target_sns' => $this->target_sns,
 
220
  'cache_expiration' => $cache_expiration
221
  );
222
 
@@ -242,7 +244,7 @@ class Share_Rush_Cache_Engine extends Share_Cache_Engine {
242
 
243
  if ( $this->new_content_term > 1 ) {
244
  $term_threshold = $this->new_content_term . ' days ago';
245
- } else if ( $this->new_content_term == 1 ) {
246
  $term_threshold = $this->new_content_term . ' day ago';
247
  }
248
 
104
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
105
  if ( isset( $options['new_content_term'] ) ) $this->new_content_term = $options['new_content_term'];
106
  if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
107
+ if ( isset( $options['scheme_migration_date'] ) ) $this->scheme_migration_date = $options['scheme_migration_date'];
108
  if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
109
 
110
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
218
  'post_id' => $post_ID,
219
  'target_url' => $url,
220
  'target_sns' => $this->target_sns,
221
+ 'publish_date' => get_the_date( 'Y/m/d' ),
222
  'cache_expiration' => $cache_expiration
223
  );
224
 
244
 
245
  if ( $this->new_content_term > 1 ) {
246
  $term_threshold = $this->new_content_term . ' days ago';
247
+ } elseif ( $this->new_content_term == 1 ) {
248
  $term_threshold = $this->new_content_term . ' day ago';
249
  }
250
 
includes/class-share-second-cache-engine.php CHANGED
@@ -67,11 +67,6 @@ class Share_Second_Cache_Engine extends Cache_Engine {
67
  */
68
  private $posts_per_check = 20;
69
 
70
- /**
71
- * Prefix of cache ID
72
- */
73
- private $meta_key_prefix = 'scc_share_count_';
74
-
75
  /**
76
  * Cache target
77
  */
@@ -82,6 +77,11 @@ class Share_Second_Cache_Engine extends Cache_Engine {
82
  */
83
  private $post_types = array( 'post', 'page' );
84
 
 
 
 
 
 
85
  /**
86
  * Initialization
87
  *
@@ -95,7 +95,8 @@ class Share_Second_Cache_Engine extends Cache_Engine {
95
  $this->execute_cron = self::DEF_EXECUTE_CRON;
96
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
97
  $this->event_description = self::DEF_EVENT_DESCRIPTION;
98
-
 
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'];
@@ -105,8 +106,8 @@ class Share_Second_Cache_Engine extends Cache_Engine {
105
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
106
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
107
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
108
- if ( isset( $options['meta_key_prefix'] ) ) $this->meta_key_prefix = $options['meta_key_prefix'];
109
-
110
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
111
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
112
  add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 0 );
@@ -167,15 +168,15 @@ class Share_Second_Cache_Engine extends Cache_Engine {
167
  while ( $posts_query->have_posts() ) {
168
  $posts_query->the_post();
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
 
@@ -197,18 +198,31 @@ class Share_Second_Cache_Engine extends Cache_Engine {
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
  }
@@ -216,12 +230,33 @@ class Share_Second_Cache_Engine extends Cache_Engine {
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
 
@@ -250,7 +285,7 @@ class Share_Second_Cache_Engine extends Cache_Engine {
250
 
251
  foreach ( $this->target_sns as $sns => $active ) {
252
  if ( $active ) {
253
- $sns_counts[$sns] = -1;
254
  }
255
  }
256
 
@@ -270,14 +305,14 @@ class Share_Second_Cache_Engine extends Cache_Engine {
270
  while ( $posts_query->have_posts() ) {
271
  $posts_query->the_post();
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
  }
@@ -296,36 +331,36 @@ class Share_Second_Cache_Engine extends Cache_Engine {
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',
303
- 'nopaging' => true,
304
- 'update_post_term_cache' => false,
305
- 'update_post_meta_cache' => false
306
- );
307
-
308
- $posts_query = new WP_Query( $query_args );
309
-
310
- if ( $posts_query->have_posts() ) {
311
- while ( $posts_query->have_posts() ) {
312
- $posts_query->the_post();
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
 
331
  ?>
67
  */
68
  private $posts_per_check = 20;
69
 
 
 
 
 
 
70
  /**
71
  * Cache target
72
  */
77
  */
78
  private $post_types = array( 'post', 'page' );
79
 
80
+ /**
81
+ * Crawl date key
82
+ */
83
+ private $crawl_date_key = NULL;
84
+
85
  /**
86
  * Initialization
87
  *
95
  $this->execute_cron = self::DEF_EXECUTE_CRON;
96
  $this->event_schedule = self::DEF_EVENT_SCHEDULE;
97
  $this->event_description = self::DEF_EVENT_DESCRIPTION;
98
+
99
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
100
  if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
101
  if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
102
  if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
106
  if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
107
  if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
108
  if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
109
+ if ( isset( $options['crawl_date_key'] ) ) $this->crawl_date_key = $options['crawl_date_key'];
110
+
111
  add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
112
  add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
113
  add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 0 );
168
  while ( $posts_query->have_posts() ) {
169
  $posts_query->the_post();
170
 
171
+ $post_id = get_the_ID();
172
 
173
+ $transient_id = $this->get_cache_key( $post_id );
174
 
175
+ $url = get_permalink( $post_id );
176
 
177
  $options = array(
178
  'cache_key' => $transient_id,
179
+ 'post_id' => $post_id,
180
  'target_sns' => $this->target_sns
181
  );
182
 
198
 
199
  $transient_id = $options['cache_key'];
200
  $target_sns = $options['target_sns'];
201
+ $post_id = $options['post_id'];
202
+
203
+ $sns_counts = array();
204
 
205
+ if ( $post_id !== 'home' ) {
206
  if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
207
  foreach ( $target_sns as $sns => $active ) {
208
 
209
  if ( $active ) {
210
 
211
  $meta_key = $this->get_cache_key( $sns );
212
+
213
+ if ( $sns !== $this->crawl_date_key ) {
214
+
215
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
216
+ update_post_meta( $post_id, $meta_key, (int) $sns_counts[$sns] );
217
+ } else {
218
+ update_post_meta( $post_id, $meta_key, (int) -1 );
219
+ }
220
+ } else {
221
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' ) {
222
+ update_post_meta( $post_id, $meta_key, $sns_counts[$sns] );
223
+ } else {
224
+ update_post_meta( $post_id, $meta_key, '' );
225
+ }
226
  }
227
  }
228
  }
230
  }
231
  } else {
232
  if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
233
+
234
  $option_key = $this->get_cache_key( 'home' );
235
+
236
+ foreach ( $target_sns as $sns => $active ) {
237
+
238
+ if ( $active ) {
239
+
240
+ if ( $sns !== $this->crawl_date_key ) {
241
+
242
+ if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
243
+ $sns_counts[$sns] = (int) -1;
244
+ }
245
+
246
+ } else {
247
+ if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] === '' ) {
248
+ $sns_counts[$sns] = '';
249
+ }
250
+ }
251
+ }
252
+ }
253
+
254
  update_option( $option_key, $sns_counts );
255
  }
256
  }
257
+
258
+ // Analysis
259
+ $this->delegate_analysis( $options );
260
 
261
  }
262
 
285
 
286
  foreach ( $this->target_sns as $sns => $active ) {
287
  if ( $active ) {
288
+ $sns_counts[$sns] = (int) -1;
289
  }
290
  }
291
 
305
  while ( $posts_query->have_posts() ) {
306
  $posts_query->the_post();
307
 
308
+ $post_id = get_the_ID();
309
 
310
  foreach ( $this->target_sns as $sns => $active ) {
311
 
312
  $meta_key = $this->get_cache_key( $sns );
313
 
314
  if ( $active ) {
315
+ update_post_meta( $post_id, $meta_key, -1 );
316
  }
317
  }
318
  }
331
  $option_key = $this->get_cache_key( 'home' );
332
 
333
  delete_option( $option_key );
334
+
335
+ foreach ( $this->target_sns as $sns => $active ) {
336
+
337
+ if ( $active ) {
338
+ $meta_key = $this->get_cache_key( $sns );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
 
340
+ delete_post_meta_by_key( $meta_key );
 
 
 
341
  }
342
+ }
 
343
  }
344
 
345
+ /**
346
+ * Clear meta key for ranking
347
+ *
348
+ * @since 0.7.0
349
+ */
350
+ public function clear_cache_by_post_id( $post_id ) {
351
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
352
+
353
+ foreach ( $this->target_sns as $sns => $active ) {
354
+
355
+ if ( $active ) {
356
+ $meta_key = $this->get_cache_key( $sns );
357
+ delete_post_meta( $post_id, $meta_key );
358
+ }
359
+
360
+ }
361
+
362
+ }
363
+
364
  }
365
 
366
  ?>
includes/interface-order.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
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
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
+ interface Order {
33
+ public function order_cache( Cache_Engine $engine, $options = array() );
34
+ public function order_analysis( Cache_Engine $engine, $options = array() );
35
+ }
36
+
37
+ ?>
js/jquery.scc-cache-info.js CHANGED
@@ -11,6 +11,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11
  $.ajax({
12
  url: scc.endpoint + '?action=' + scc.action + '&nonce=' + scc.nonce,
13
  dataType: 'jsonp',
 
14
  success: function(res){
15
  if(res){
16
 
@@ -25,13 +26,53 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
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 {
11
  $.ajax({
12
  url: scc.endpoint + '?action=' + scc.action + '&nonce=' + scc.nonce,
13
  dataType: 'jsonp',
14
+ cache: false,
15
  success: function(res){
16
  if(res){
17
 
26
  $("span[data-scc='sncc']").text(res.secondary.no_cache_count);
27
  $("span[data-scc='scs']").text(res.secondary.cache_status);
28
 
29
+ if(res.share_delta.twitter > 0){
30
+ $("span[data-scc='twitter']").html(res.share_count.twitter + ' (<span class="delta-rise">+' + res.share_delta.twitter + '</span>)');
31
+ } else if(res.share_delta.twitter < 0){
32
+ $("span[data-scc='twitter']").html(res.share_count.twitter + ' (<span class="delta-fall">' + res.share_delta.twitter + '</span>)');
33
+ } else {
34
+ $("span[data-scc='twitter']").html(res.share_count.twitter);
35
+ }
36
+ if(res.share_delta.facebook > 0){
37
+ $("span[data-scc='facebook']").html(res.share_count.facebook + ' (<span class="delta-rise">+' + res.share_delta.facebook + '</span>)');
38
+ } else if(res.share_delta.facebook < 0){
39
+ $("span[data-scc='facebook']").html(res.share_count.facebook + ' (<span class="delta-fall">' + res.share_delta.facebook + '</span>)');
40
+ } else {
41
+ $("span[data-scc='facebook']").html(res.share_count.facebook);
42
+ }
43
+
44
+ if(res.share_delta.gplus > 0){
45
+ $("span[data-scc='gplus']").html(res.share_count.gplus + ' (<span class="delta-rise">+' + res.share_delta.gplus + '</span>)');
46
+ } else if(res.share_delta.gplus < 0){
47
+ $("span[data-scc='gplus']").html(res.share_count.gplus + ' (<span class="delta-fall">' + res.share_delta.gplus + '</span>)');
48
+ } else {
49
+ $("span[data-scc='gplus']").html(res.share_count.gplus);
50
+ }
51
+
52
+ if(res.share_delta.pocket > 0){
53
+ $("span[data-scc='pocket']").html(res.share_count.pocket + ' (<span class="delta-rise">+' + res.share_delta.pocket + '</span>)');
54
+ } else if(res.share_delta.pocket < 0){
55
+ $("span[data-scc='pocket']").html(res.share_count.pocket + ' (<span class="delta-fall">' + res.share_delta.pocket + '</span>)');
56
+ } else {
57
+ $("span[data-scc='pocket']").html(res.share_count.pocket);
58
+ }
59
+
60
+ if(res.share_delta.hatebu > 0){
61
+ $("span[data-scc='hatebu']").html(res.share_count.hatebu + ' (<span class="delta-rise">+' + res.share_delta.hatebu + '</span>)');
62
+ } else if(res.share_delta.hatebu < 0){
63
+ $("span[data-scc='hatebu']").html(res.share_count.hatebu + ' (<span class="delta-fall">' + res.share_delta.hatebu + '</span>)');
64
+ } else {
65
+ $("span[data-scc='hatebu']").html(res.share_count.hatebu);
66
+ }
67
+
68
+ if(res.share_delta.total > 0){
69
+ $("span[data-scc='total']").html(res.share_count.total + ' (<span class="delta-rise">+' + res.share_delta.total + '</span>)');
70
+ } else if(res.share_delta.total < 0){
71
+ $("span[data-scc='total']").html(res.share_count.total + ' (<span class="delta-fall">' + res.share_delta.total + '</span>)');
72
+ } else {
73
+ $("span[data-scc='total']").html(res.share_count.total);
74
+ }
75
+
76
  $(".loading").css('display', 'none');
77
  $("span[data-scc]").fadeIn();
78
  } else {
js/jquery.scc-cache-info.min.js CHANGED
@@ -1,3 +1,6 @@
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("?")}})})});
 
 
 
1
+ ;jQuery(document).ready(function(b){return b("#scc-dashboard").each(function(){b("span[data-scc]").css("display","none");b.ajax({url:scc.endpoint+"?action="+scc.action+"&nonce="+scc.nonce,dataType:"jsonp",cache:!1,success:function(a){a?(b("span[data-scc='pc']").text(a.post_count),b("span[data-scc='pfcc']").text(a.primary.full_cache_count),b("span[data-scc='ppcc']").text(a.primary.partial_cache_count),b("span[data-scc='pncc']").text(a.primary.no_cache_count),b("span[data-scc='pcs']").text(a.primary.cache_status),
2
+ b("span[data-scc='sfcc']").text(a.secondary.full_cache_count),b("span[data-scc='spcc']").text(a.secondary.partial_cache_count),b("span[data-scc='sncc']").text(a.secondary.no_cache_count),b("span[data-scc='scs']").text(a.secondary.cache_status),0<a.share_delta.twitter?b("span[data-scc='twitter']").html(a.share_count.twitter+' (<span class="delta-rise">+'+a.share_delta.twitter+"</span>)"):0>a.share_delta.twitter?b("span[data-scc='twitter']").html(a.share_count.twitter+' (<span class="delta-fall">'+
3
+ a.share_delta.twitter+"</span>)"):b("span[data-scc='twitter']").html(a.share_count.twitter),0<a.share_delta.facebook?b("span[data-scc='facebook']").html(a.share_count.facebook+' (<span class="delta-rise">+'+a.share_delta.facebook+"</span>)"):0>a.share_delta.facebook?b("span[data-scc='facebook']").html(a.share_count.facebook+' (<span class="delta-fall">'+a.share_delta.facebook+"</span>)"):b("span[data-scc='facebook']").html(a.share_count.facebook),0<a.share_delta.gplus?b("span[data-scc='gplus']").html(a.share_count.gplus+
4
+ ' (<span class="delta-rise">+'+a.share_delta.gplus+"</span>)"):0>a.share_delta.gplus?b("span[data-scc='gplus']").html(a.share_count.gplus+' (<span class="delta-fall">'+a.share_delta.gplus+"</span>)"):b("span[data-scc='gplus']").html(a.share_count.gplus),0<a.share_delta.pocket?b("span[data-scc='pocket']").html(a.share_count.pocket+' (<span class="delta-rise">+'+a.share_delta.pocket+"</span>)"):0>a.share_delta.pocket?b("span[data-scc='pocket']").html(a.share_count.pocket+' (<span class="delta-fall">'+
5
+ a.share_delta.pocket+"</span>)"):b("span[data-scc='pocket']").html(a.share_count.pocket),0<a.share_delta.hatebu?b("span[data-scc='hatebu']").html(a.share_count.hatebu+' (<span class="delta-rise">+'+a.share_delta.hatebu+"</span>)"):0>a.share_delta.hatebu?b("span[data-scc='hatebu']").html(a.share_count.hatebu+' (<span class="delta-fall">'+a.share_delta.hatebu+"</span>)"):b("span[data-scc='hatebu']").html(a.share_count.hatebu),0<a.share_delta.total?b("span[data-scc='total']").html(a.share_count.total+
6
+ ' (<span class="delta-rise">+'+a.share_delta.total+"</span>)"):0>a.share_delta.total?b("span[data-scc='total']").html(a.share_count.total+' (<span class="delta-fall">'+a.share_delta.total+"</span>)"):b("span[data-scc='total']").html(a.share_count.total),b(".loading").css("display","none"),b("span[data-scc]").fadeIn()):b("span[data-scc]").text("?")},error:function(a){b("span[data-scc]").text("?")}})})});
readme.txt CHANGED
@@ -4,11 +4,11 @@ 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
 
@@ -39,6 +39,16 @@ The following describes meta keys to get share count from custom field.
39
  * scc_share_count_hatebu
40
  * scc_share_count_total
41
 
 
 
 
 
 
 
 
 
 
 
42
  == Installation ==
43
 
44
  1. Download zip archive file from this repository.
@@ -56,9 +66,10 @@ There are no questions.
56
  == Screenshots ==
57
  1. Dashboard to overview cache status and share count
58
  2. Cache status is described in setting page
59
- 3. Share count for each post can be verviewed
60
  4. Described parameters can be modified in this page
61
- 5. Help page shows available functions to access the cache
 
62
 
63
  == Changelog ==
64
 
@@ -96,6 +107,11 @@ There are no questions.
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,8 +121,6 @@ The following functions are deprecated.
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
 
4
  Tags: performance, SNS, social, cache, share
5
  Requires at least: 3.7
6
  Tested up to: 4.2.2
7
+ Stable tag: 0.7.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.
12
 
13
  == Description ==
14
 
39
  * scc_share_count_hatebu
40
  * scc_share_count_total
41
 
42
+ The following describes meta keys to get delta of share count from custom field.
43
+
44
+ * scc_share_delta_twitter
45
+ * scc_share_delta_facebook
46
+ * scc_share_delta_google+
47
+ * scc_share_delta_pocket
48
+ * scc_share_delta_hatebu
49
+ * scc_share_delta_total
50
+
51
+
52
  == Installation ==
53
 
54
  1. Download zip archive file from this repository.
66
  == Screenshots ==
67
  1. Dashboard to overview cache status and share count
68
  2. Cache status is described in setting page
69
+ 3. Share count for each post can be viewed
70
  4. Described parameters can be modified in this page
71
+ 5. Help page shows available functions to access the cache
72
+ 6. Hot content can be viewd.
73
 
74
  == Changelog ==
75
 
107
  * Fixed: SNS count of facebook can be 0.
108
  * Fixed: "PHP Notice: has_cap..." is output.
109
 
110
+ = 0.7.0 =
111
+ * Added: function to display variation of SNS count
112
+ * Added: function to access variation of SNS count through custom filed
113
+ * Fixed: custom filed used in this plugin is not deleted in a certain case.
114
+
115
  == Upgrade Notice ==
116
  The following functions are deprecated.
117
 
121
  * get_scc_pocket()
122
  * get_scc_hatebu()
123
 
 
 
124
  == Arbitrary section ==
125
 
126
 
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
screenshot-3.png CHANGED
Binary file
screenshot-4.png CHANGED
Binary file
screenshot-5.png CHANGED
Binary file
screenshot-6.png ADDED
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.6.0
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
@@ -32,7 +32,7 @@ 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/interface-cache-order.php' );
36
 
37
  require_once ( dirname( __FILE__ ) . '/includes/class-engine.php' );
38
  require_once ( dirname( __FILE__ ) . '/includes/class-cache-engine.php' );
@@ -58,9 +58,12 @@ require_once ( dirname( __FILE__ ) . '/includes/class-data-crawler.php' );
58
  require_once ( dirname( __FILE__ ) . '/includes/class-share-crawler.php' );
59
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-crawler.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
@@ -125,17 +128,32 @@ final class SNS_Count_Cache implements Cache_Order {
125
  /**
126
  * Type of data export
127
  */
128
- const OPT_COMMON_DATA_EXPORT_AUTO = 2;
 
 
 
 
 
 
 
 
 
 
129
 
130
  /**
131
- * File name of data export
132
- */
133
- const OPT_COMMON_DATA_EXPORT_FILE_NAME = 'sns-count-cache-data.csv';
134
 
135
  /**
136
- * Data export interval
137
  */
138
- const OPT_COMMON_DATA_EXPORT_INTERVAL = 43200;
 
 
 
 
 
139
 
140
  /**
141
  * Data export schedule
@@ -177,7 +195,7 @@ final class SNS_Count_Cache implements Cache_Order {
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';
@@ -215,7 +233,7 @@ final class SNS_Count_Cache implements Cache_Order {
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
@@ -230,8 +248,13 @@ final class SNS_Count_Cache implements Cache_Order {
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
  */
@@ -262,11 +285,26 @@ final class SNS_Count_Cache implements Cache_Order {
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
  */
@@ -297,6 +335,11 @@ final class SNS_Count_Cache implements Cache_Order {
297
  */
298
  const REF_SHARE_2ND = 'share-second';
299
 
 
 
 
 
 
300
  /**
301
  * ID of share second cache
302
  */
@@ -361,6 +404,16 @@ final class SNS_Count_Cache implements Cache_Order {
361
  * ID of share count (Pocket)
362
  */
363
  const REF_SHARE_POCKET = 'Pocket';
 
 
 
 
 
 
 
 
 
 
364
 
365
  /**
366
  * ID of share count (Total)
@@ -380,7 +433,7 @@ final class SNS_Count_Cache implements Cache_Order {
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
@@ -401,6 +454,11 @@ final class SNS_Count_Cache implements Cache_Order {
401
  * Instance of control engine
402
  */
403
  private $control_engines = array();
 
 
 
 
 
404
 
405
  /**
406
  * Slug of the plugin screen
@@ -436,6 +494,11 @@ final class SNS_Count_Cache implements Cache_Order {
436
  * Term considering content as new one
437
  */
438
  private $share_rush_new_content_term = 3;
 
 
 
 
 
439
 
440
  /**
441
  * Cache target for follow base cache
@@ -460,13 +523,28 @@ final class SNS_Count_Cache implements Cache_Order {
460
  /**
461
  * Data export schedule
462
  */
463
- private $data_export_schedule = '0 0 * * *';
 
 
 
 
 
 
 
 
 
 
464
 
465
  /**
466
  * Migration mode from http to https
467
  */
468
  private $scheme_migration_mode = false;
469
 
 
 
 
 
 
470
  /**
471
  * Excluded key in migration from http to https
472
  */
@@ -480,7 +558,7 @@ final class SNS_Count_Cache implements Cache_Order {
480
  /**
481
  * Extended max execution time
482
  */
483
- private $extended_max_execution_time = 300;
484
 
485
  /**
486
  * URL of loding image
@@ -531,6 +609,9 @@ final class SNS_Count_Cache implements Cache_Order {
531
  add_action( 'wp_dashboard_setup', array( $this, 'add_wp_dashboard_widget' ) );
532
 
533
  add_action( 'plugins_loaded', array( $this, 'initialize' ) );
 
 
 
534
  }
535
 
536
  /**
@@ -570,7 +651,7 @@ final class SNS_Count_Cache implements Cache_Order {
570
  final public function __clone() {
571
  throw new Exception('Clone is not allowed against' . get_class( $this ) );
572
  }
573
-
574
  /**
575
  * Initialization
576
  *
@@ -581,38 +662,44 @@ final class SNS_Count_Cache implements Cache_Order {
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
  }
@@ -623,11 +710,27 @@ final class SNS_Count_Cache implements Cache_Order {
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 );
@@ -659,7 +762,6 @@ final class SNS_Count_Cache implements Cache_Order {
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 {
@@ -694,6 +796,7 @@ final class SNS_Count_Cache implements Cache_Order {
694
  'posts_per_check' => $this->share_base_posts_per_check,
695
  'post_types' => $this->share_base_cache_post_types,
696
  'scheme_migration_mode' => $this->scheme_migration_mode,
 
697
  'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
698
  );
699
 
@@ -705,11 +808,12 @@ final class SNS_Count_Cache implements Cache_Order {
705
  'delegate' => $this,
706
  'crawler' => $this->crawlers[self::REF_SHARE],
707
  'target_sns' => $this->share_base_cache_target,
708
- 'check_interval' => self::OPT_SHARE_RUSH_CHECK_INTERVAL,
709
- 'posts_per_check' => $this->share_base_posts_per_check,
710
  'new_content_term' => $this->share_rush_new_content_term,
711
  'post_types' => $this->share_base_cache_post_types,
712
  'scheme_migration_mode' => $this->scheme_migration_mode,
 
713
  'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
714
  );
715
 
@@ -725,6 +829,7 @@ final class SNS_Count_Cache implements Cache_Order {
725
  'posts_per_check' => $this->share_base_posts_per_check,
726
  'post_types' => $this->share_base_cache_post_types,
727
  'scheme_migration_mode' => $this->scheme_migration_mode,
 
728
  'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
729
  );
730
 
@@ -733,12 +838,14 @@ final class SNS_Count_Cache implements Cache_Order {
733
 
734
  // Share second cache engine
735
  $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
  );
743
 
744
  $this->cache_engines[self::REF_SHARE_2ND] = Share_Second_Cache_Engine::get_instance();
@@ -810,6 +917,19 @@ final class SNS_Count_Cache implements Cache_Order {
810
  $this->export_engines[self::REF_COMMON_EXPORT] = Common_Data_Export_Engine::get_instance();
811
  $this->export_engines[self::REF_COMMON_EXPORT]->initialize( $options );
812
 
 
 
 
 
 
 
 
 
 
 
 
 
 
813
  // Job reset engine
814
  $target_crons = array();
815
 
@@ -821,10 +941,14 @@ final class SNS_Count_Cache implements Cache_Order {
821
  $target_crons[] = $control_engine->get_excute_cron();
822
  }
823
 
824
- if ( $this->data_export_mode ) {
825
  $target_crons[] = $this->export_engines[self::REF_COMMON_EXPORT]->get_excute_cron();
826
  }
827
 
 
 
 
 
828
  $options = array(
829
  'delegate' => $this,
830
  'check_interval' => 600,
@@ -834,7 +958,7 @@ final class SNS_Count_Cache implements Cache_Order {
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 ) {
@@ -870,6 +994,7 @@ final class SNS_Count_Cache implements Cache_Order {
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
 
@@ -892,6 +1017,8 @@ final class SNS_Count_Cache implements Cache_Order {
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
 
@@ -924,8 +1051,12 @@ final class SNS_Count_Cache implements Cache_Order {
924
  foreach ( $this->control_engines as $key => $control_engine ) {
925
  $control_engine->register_schedule();
926
  }
927
-
928
- if ( $this->data_export_mode ) {
 
 
 
 
929
  $this->export_engines[self::REF_COMMON_EXPORT]->register_schedule();
930
  }
931
 
@@ -980,7 +1111,10 @@ final class SNS_Count_Cache implements Cache_Order {
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 );
@@ -999,6 +1133,20 @@ final class SNS_Count_Cache implements Cache_Order {
999
  $this->activate_plugin();
1000
 
1001
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1002
 
1003
  /**
1004
  * Adds options & management pages to the admin menu.
@@ -1015,7 +1163,12 @@ final class SNS_Count_Cache implements Cache_Order {
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
 
@@ -1039,6 +1192,11 @@ final class SNS_Count_Cache implements Cache_Order {
1039
  * @since 0.5.1
1040
  */
1041
  public function wp_dashboard_page() {
 
 
 
 
 
1042
  include_once( dirname( __FILE__ ) . '/includes/admin-dashboard-widget.php' );
1043
  }
1044
 
@@ -1049,6 +1207,11 @@ final class SNS_Count_Cache implements Cache_Order {
1049
  * @since 0.1.0
1050
  */
1051
  public function dashboard_page() {
 
 
 
 
 
1052
  include_once( dirname( __FILE__ ) . '/includes/admin-dashboard.php' );
1053
  }
1054
 
@@ -1059,6 +1222,11 @@ final class SNS_Count_Cache implements Cache_Order {
1059
  * @since 0.1.0
1060
  */
1061
  public function cache_status_page() {
 
 
 
 
 
1062
  include_once( dirname( __FILE__ ) . '/includes/admin-cache-status.php' );
1063
  }
1064
 
@@ -1068,7 +1236,12 @@ final class SNS_Count_Cache implements Cache_Order {
1068
  * @since 0.1.0
1069
  */
1070
  public function share_count_page() {
1071
- include_once( dirname( __FILE__ ) . '/includes/admin-share-count.php' );
 
 
 
 
 
1072
  }
1073
 
1074
  /**
@@ -1077,7 +1250,12 @@ final class SNS_Count_Cache implements Cache_Order {
1077
  * @since 0.1.0
1078
  */
1079
  public function setting_page() {
1080
- include_once( dirname( __FILE__ ) . '/includes/admin-setting.php' );
 
 
 
 
 
1081
  }
1082
 
1083
  /**
@@ -1086,7 +1264,12 @@ final class SNS_Count_Cache implements Cache_Order {
1086
  * @since 0.1.0
1087
  */
1088
  public function help_page() {
1089
- include_once( dirname( __FILE__ ) . '/includes/admin-help.php' );
 
 
 
 
 
1090
  }
1091
 
1092
  /**
@@ -1095,9 +1278,29 @@ final class SNS_Count_Cache implements Cache_Order {
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
  *
@@ -1173,6 +1376,24 @@ final class SNS_Count_Cache implements Cache_Order {
1173
 
1174
  }
1175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1176
  /**
1177
  * Return pagination
1178
  *
@@ -1275,11 +1496,13 @@ final class SNS_Count_Cache implements Cache_Order {
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
 
@@ -1300,7 +1523,7 @@ final class SNS_Count_Cache implements Cache_Order {
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 ) {
@@ -1316,7 +1539,7 @@ final class SNS_Count_Cache implements Cache_Order {
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;
@@ -1349,7 +1572,7 @@ final class SNS_Count_Cache implements Cache_Order {
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;
@@ -1382,7 +1605,7 @@ final class SNS_Count_Cache implements Cache_Order {
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;
@@ -1392,6 +1615,20 @@ final class SNS_Count_Cache implements Cache_Order {
1392
 
1393
  }
1394
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1395
  //page, post
1396
  $site_query = new WP_Query( $query_args );
1397
 
@@ -1405,11 +1642,12 @@ final class SNS_Count_Cache implements Cache_Order {
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;
@@ -1418,21 +1656,24 @@ final class SNS_Count_Cache implements Cache_Order {
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 );
@@ -1442,12 +1683,23 @@ final class SNS_Count_Cache implements Cache_Order {
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;
@@ -1455,6 +1707,9 @@ final class SNS_Count_Cache implements Cache_Order {
1455
 
1456
  } else {
1457
 
 
 
 
1458
  foreach ( $share_base_cache_target as $sns => $active ) {
1459
 
1460
  if( $active ){
@@ -1468,12 +1723,23 @@ final class SNS_Count_Cache implements Cache_Order {
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;
@@ -1493,8 +1759,10 @@ final class SNS_Count_Cache implements Cache_Order {
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
  }
@@ -1509,7 +1777,7 @@ final class SNS_Count_Cache implements Cache_Order {
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 );
@@ -1517,12 +1785,12 @@ final class SNS_Count_Cache implements Cache_Order {
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' );
@@ -1572,7 +1840,6 @@ final class SNS_Count_Cache implements Cache_Order {
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 ) {
@@ -1643,7 +1910,6 @@ final class SNS_Count_Cache implements Cache_Order {
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 ) {
@@ -1661,7 +1927,6 @@ final class SNS_Count_Cache implements Cache_Order {
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 ) {
@@ -1733,7 +1998,6 @@ final class SNS_Count_Cache implements Cache_Order {
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' );
@@ -1744,7 +2008,7 @@ final class SNS_Count_Cache implements Cache_Order {
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
 
@@ -1772,7 +2036,6 @@ final class SNS_Count_Cache implements Cache_Order {
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 ) {
@@ -1790,7 +2053,6 @@ final class SNS_Count_Cache implements Cache_Order {
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 ) {
@@ -1828,7 +2090,21 @@ final class SNS_Count_Cache implements Cache_Order {
1828
  break;
1829
  }
1830
  }
1831
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1832
 
1833
 
1834
  }
@@ -1847,7 +2123,7 @@ function scc_get_share( $options = array( 'post_id' => '', 'url' => '', 'sns' =>
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();
@@ -2014,6 +2290,16 @@ function scc_get_follow_feedly() {
2014
  return scc_get_follow( $options );
2015
  }
2016
 
 
 
 
 
 
 
 
 
 
 
2017
 
2018
  }
2019
 
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.7.0
6
  Author: Daisuke Maruyama
7
  Author URI: http://marubon.info/
8
  License: GPL2 or later
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-order.php' );
36
 
37
  require_once ( dirname( __FILE__ ) . '/includes/class-engine.php' );
38
  require_once ( dirname( __FILE__ ) . '/includes/class-cache-engine.php' );
58
  require_once ( dirname( __FILE__ ) . '/includes/class-share-crawler.php' );
59
  require_once ( dirname( __FILE__ ) . '/includes/class-follow-crawler.php' );
60
 
61
+ require_once ( dirname( __FILE__ ) . '/includes/class-analytical-engline.php' );
62
+ require_once ( dirname( __FILE__ ) . '/includes/class-share-analytical-engine.php' );
63
+
64
  if ( ! class_exists( 'SNS_Count_Cache' ) ) {
65
 
66
+ final class SNS_Count_Cache implements Order {
67
 
68
  /**
69
  * Prefix of share cache ID
128
  /**
129
  * Type of data export
130
  */
131
+ const OPT_COMMON_DATA_EXPORT_SCHEDULER = 2;
132
+
133
+ /**
134
+ * Type of share analysis
135
+ */
136
+ const OPT_SHARE_VARIATION_ANALYSIS_NONE = 1;
137
+
138
+ /**
139
+ * Type of share analysis
140
+ */
141
+ const OPT_SHARE_VARIATION_ANALYSIS_MANUAL = 2;
142
 
143
  /**
144
+ * Type of share analysis
145
+ */
146
+ const OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER = 3;
147
 
148
  /**
149
+ * Type of share analysis
150
  */
151
+ const OPT_SHARE_VARIATION_ANALYSIS_SCHEDULE = '0 0 * * *';
152
+
153
+ /**
154
+ * File name of data export
155
+ */
156
+ const OPT_COMMON_DATA_EXPORT_FILE_NAME = 'sns-count-cache-data.csv';
157
 
158
  /**
159
  * Data export schedule
195
  */
196
  const OPT_COMMON_ERROR_MESSAGE = 'scc_error_message';
197
 
198
+ /**
199
  * Update message
200
  */
201
  const OPT_COMMON_UPDATE_MESSAGE = 'scc_update_message';
233
  /**
234
  * Option key for check interval of share base cache
235
  */
236
+ const DB_SHARE_BASE_CHECK_INTERVAL = 'share_base_check_interval';
237
 
238
  /**
239
  * Option key for number of posts to check at a time for share base cache
248
  /**
249
  * Option key for new content term for share rush cache
250
  */
251
+ const DB_SHARE_RUSH_NEW_CONTENT_TERM = 'share_new_content_term';
252
 
253
+ /**
254
+ * Option key for check interval of share rush cache
255
+ */
256
+ const DB_SHARE_RUSH_CHECK_INTERVAL = 'share_rush_check_interval';
257
+
258
  /**
259
  * Option key of cache target for share base cache
260
  */
285
  */
286
  const DB_COMMON_SCHEME_MIGRATION_MODE = 'common_scheme_migration_mode';
287
 
288
+ /**
289
+ * Option key of http migration
290
+ */
291
+ const DB_COMMON_SCHEME_MIGRATION_DATE = 'common_scheme_migration_date';
292
+
293
  /**
294
  * Option key of crawl ssl verification
295
  */
296
  const DB_COMMON_CRAWLER_SSL_VERIFICATION = 'common_crawler_ssl_verification';
297
+
298
+ /**
299
+ * Option key of share variation analysis
300
+ */
301
+ const DB_SHARE_VARIATION_ANALYSIS_MODE = 'share_variation_analysis_mode';
302
+
303
+ /**
304
+ * Option key of share variation analysis
305
+ */
306
+ const DB_SHARE_VARIATION_ANALYSIS_SCHEDULE = 'share_variation_analysis_schedule';
307
+
308
  /**
309
  * Option key of setting
310
  */
335
  */
336
  const REF_SHARE_2ND = 'share-second';
337
 
338
+ /**
339
+ * ID of share second cache
340
+ */
341
+ const REF_SHARE_ANALYSIS = 'share-analysis';
342
+
343
  /**
344
  * ID of share second cache
345
  */
404
  * ID of share count (Pocket)
405
  */
406
  const REF_SHARE_POCKET = 'Pocket';
407
+
408
+ /**
409
+ * ID of share count (Pinterest)
410
+ */
411
+ const REF_SHARE_PINTEREST = 'Pinterest';
412
+
413
+ /**
414
+ * ID of share count (LinkedIn)
415
+ */
416
+ const REF_SHARE_LINKEDIN = 'Linkedin';
417
 
418
  /**
419
  * ID of share count (Total)
433
  /**
434
  * Plugin version, used for cache-busting of style and script file references.
435
  */
436
+ private $version = '0.7.0';
437
 
438
  /**
439
  * Instances of crawler
454
  * Instance of control engine
455
  */
456
  private $control_engines = array();
457
+
458
+ /**
459
+ * Instance of analytical engine
460
+ */
461
+ private $analytical_engines = array();
462
 
463
  /**
464
  * Slug of the plugin screen
494
  * Term considering content as new one
495
  */
496
  private $share_rush_new_content_term = 3;
497
+
498
+ /**
499
+ *Check interval for share rush cahce
500
+ */
501
+ private $share_rush_check_interval = 300;
502
 
503
  /**
504
  * Cache target for follow base cache
523
  /**
524
  * Data export schedule
525
  */
526
+ private $data_export_schedule = '0 0 * * *';
527
+
528
+ /**
529
+ * Share variation analysis mode
530
+ */
531
+ private $share_variation_analysis_mode = 1;
532
+
533
+ /**
534
+ * Share variation analysis schedule
535
+ */
536
+ private $share_variation_analysis_schedule = '0 0 * * *';
537
 
538
  /**
539
  * Migration mode from http to https
540
  */
541
  private $scheme_migration_mode = false;
542
 
543
+ /**
544
+ * Migration date from http to https
545
+ */
546
+ private $scheme_migration_date = NULL;
547
+
548
  /**
549
  * Excluded key in migration from http to https
550
  */
558
  /**
559
  * Extended max execution time
560
  */
561
+ private $extended_max_execution_time = 600;
562
 
563
  /**
564
  * URL of loding image
609
  add_action( 'wp_dashboard_setup', array( $this, 'add_wp_dashboard_widget' ) );
610
 
611
  add_action( 'plugins_loaded', array( $this, 'initialize' ) );
612
+
613
+ add_action( 'deleted_post' , array( $this, 'clear_cache_deleted_post' ) );
614
+
615
  }
616
 
617
  /**
651
  final public function __clone() {
652
  throw new Exception('Clone is not allowed against' . get_class( $this ) );
653
  }
654
+
655
  /**
656
  * Initialization
657
  *
662
 
663
  $settings = get_option( self::DB_SETTINGS );
664
 
665
+ if ( isset( $settings[self::DB_SHARE_BASE_CHECK_INTERVAL] ) && $settings[self::DB_SHARE_BASE_CHECK_INTERVAL] ) {
666
+ $this->share_base_check_interval = (int) $settings[self::DB_SHARE_BASE_CHECK_INTERVAL];
667
  } else {
668
  $this->share_base_check_interval = self::OPT_SHARE_BASE_CHECK_INTERVAL;
669
  }
670
 
671
  if ( isset( $settings[self::DB_SHARE_POSTS_PER_CHECK] ) && $settings[self::DB_SHARE_POSTS_PER_CHECK] ) {
672
+ $this->share_base_posts_per_check = (int) $settings[self::DB_SHARE_POSTS_PER_CHECK];
673
  } else {
674
  $this->share_base_posts_per_check = self::OPT_SHARE_BASE_POSTS_PER_CHECK;
675
  }
676
 
677
  if ( isset( $settings[self::DB_FOLLOW_CHECK_INTERVAL] ) && $settings[self::DB_FOLLOW_CHECK_INTERVAL] ) {
678
+ $this->follow_base_check_interval = (int) $settings[self::DB_FOLLOW_CHECK_INTERVAL];
679
  } else {
680
  $this->follow_base_check_interval = self::OPT_FOLLOW_BASE_CHECK_INTERVAL;
681
  }
682
 
683
  if ( isset( $settings[self::DB_COMMON_DYNAMIC_CACHE_MODE] ) && $settings[self::DB_COMMON_DYNAMIC_CACHE_MODE] ) {
684
+ $this->dynamic_cache_mode = (int) $settings[self::DB_COMMON_DYNAMIC_CACHE_MODE];
685
  } else {
686
  $this->dynamic_cache_mode = self::OPT_COMMON_ACCESS_BASED_2ND_CACHE;
687
  }
688
 
689
+ if ( isset( $settings[self::DB_SHARE_RUSH_CHECK_INTERVAL] ) && $settings[self::DB_SHARE_RUSH_CHECK_INTERVAL] ) {
690
+ $this->share_rush_check_interval = (int) $settings[self::DB_SHARE_RUSH_CHECK_INTERVAL];
691
+ } else {
692
+ $this->share_rush_check_interval = self::OPT_SHARE_RUSH_CHECK_INTERVAL;
693
+ }
694
+
695
+ if ( isset( $settings[self::DB_SHARE_RUSH_NEW_CONTENT_TERM] ) && $settings[self::DB_SHARE_RUSH_NEW_CONTENT_TERM] ) {
696
+ $this->share_rush_new_content_term = (int) $settings[self::DB_SHARE_RUSH_NEW_CONTENT_TERM];
697
  } else {
698
  $this->share_rush_new_content_term = self::OPT_SHARE_RUSH_NEW_CONTENT_TERM;
699
  }
700
 
701
  if ( isset( $settings[self::DB_COMMON_DATA_EXPORT_MODE] ) && $settings[self::DB_COMMON_DATA_EXPORT_MODE] ) {
702
+ $this->data_export_mode = (int) $settings[self::DB_COMMON_DATA_EXPORT_MODE];
703
  } else {
704
  $this->data_export_mode = self::OPT_COMMON_DATA_EXPORT_MANUAL;
705
  }
710
  $this->data_export_schedule = self::OPT_COMMON_DATA_EXPORT_SCHEDULE;
711
  }
712
 
713
+ if ( isset( $settings[self::DB_SHARE_VARIATION_ANALYSIS_MODE] ) && $settings[self::DB_SHARE_VARIATION_ANALYSIS_MODE] ) {
714
+ $this->share_variation_analysis_mode = (int) $settings[self::DB_SHARE_VARIATION_ANALYSIS_MODE];
715
+ } else {
716
+ $this->share_variation_analysis_mode = self::OPT_SHARE_VARIATION_ANALYSIS_NONE;
717
+ }
718
+
719
+ if ( isset( $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] ) && $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] ) {
720
+ $this->share_variation_analysis_schedule = $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE];
721
+ } else {
722
+ $this->share_variation_analysis_schedule = self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULE;
723
+ }
724
+
725
  if ( isset( $settings[self::DB_COMMON_SCHEME_MIGRATION_MODE] ) ) {
726
  $this->scheme_migration_mode = $settings[self::DB_COMMON_SCHEME_MIGRATION_MODE];
727
  } else {
728
  $this->scheme_migration_mode = self::OPT_COMMON_SCHEME_MIGRATION_MODE_OFF;
729
  }
730
+
731
+ if ( isset( $settings[self::DB_COMMON_SCHEME_MIGRATION_DATE] ) ) {
732
+ $this->scheme_migration_date = $settings[self::DB_COMMON_SCHEME_MIGRATION_DATE];
733
+ }
734
 
735
  // Pocket and Google+ are excluded from migration target because they are migrated automatically.
736
  $this->scheme_migration_exclude_keys = array( self::REF_SHARE_POCKET, self::REF_SHARE_GPLUS );
762
 
763
  $this->share_base_cache_post_types = array_merge( $this->share_base_cache_post_types, $this->share_base_custom_post_types );
764
 
 
765
  if ( extension_loaded( 'curl' ) ) {
766
  $this->crawler_method = self::OPT_COMMON_CRAWLER_METHOD_CURL;
767
  } else {
796
  'posts_per_check' => $this->share_base_posts_per_check,
797
  'post_types' => $this->share_base_cache_post_types,
798
  'scheme_migration_mode' => $this->scheme_migration_mode,
799
+ 'scheme_migration_date' => $this->scheme_migration_date,
800
  'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
801
  );
802
 
808
  'delegate' => $this,
809
  'crawler' => $this->crawlers[self::REF_SHARE],
810
  'target_sns' => $this->share_base_cache_target,
811
+ 'check_interval' => $this->share_rush_check_interval,
812
+ 'posts_per_check' => 30,
813
  'new_content_term' => $this->share_rush_new_content_term,
814
  'post_types' => $this->share_base_cache_post_types,
815
  'scheme_migration_mode' => $this->scheme_migration_mode,
816
+ 'scheme_migration_date' => $this->scheme_migration_date,
817
  'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
818
  );
819
 
829
  'posts_per_check' => $this->share_base_posts_per_check,
830
  'post_types' => $this->share_base_cache_post_types,
831
  'scheme_migration_mode' => $this->scheme_migration_mode,
832
+ 'scheme_migration_date' => $this->scheme_migration_date,
833
  'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys
834
  );
835
 
838
 
839
  // Share second cache engine
840
  $options = array(
841
+ 'delegate' => $this,
842
  'target_sns' => $this->share_base_cache_target,
843
  'check_interval' => self::OPT_SHARE_2ND_CHECK_INTERVAL,
844
  'post_types' => $this->share_base_cache_post_types,
845
  'cache_prefix' => self::OPT_SHARE_2ND_META_KEY_PREFIX,
846
  'scheme_migration_mode' => $this->scheme_migration_mode,
847
+ 'scheme_migration_exclude_keys' => $this->scheme_migration_exclude_keys,
848
+ 'crawl_date_key' => self::REF_CRAWL_DATE
849
  );
850
 
851
  $this->cache_engines[self::REF_SHARE_2ND] = Share_Second_Cache_Engine::get_instance();
917
  $this->export_engines[self::REF_COMMON_EXPORT] = Common_Data_Export_Engine::get_instance();
918
  $this->export_engines[self::REF_COMMON_EXPORT]->initialize( $options );
919
 
920
+ // Share analytical engine
921
+ $options = array(
922
+ 'delegate' => $this,
923
+ 'target_sns' => $this->share_base_cache_target,
924
+ 'check_interval' => $this->share_base_check_interval,
925
+ 'post_types' => $this->share_base_cache_post_types,
926
+ 'base_schedule' => $this->share_variation_analysis_schedule,
927
+ 'crawl_date_key' => self::REF_CRAWL_DATE
928
+ );
929
+
930
+ $this->analytical_engines[self::REF_SHARE_ANALYSIS] = Share_Analytical_Engine::get_instance();
931
+ $this->analytical_engines[self::REF_SHARE_ANALYSIS]->initialize( $options );
932
+
933
  // Job reset engine
934
  $target_crons = array();
935
 
941
  $target_crons[] = $control_engine->get_excute_cron();
942
  }
943
 
944
+ if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_SCHEDULER ) {
945
  $target_crons[] = $this->export_engines[self::REF_COMMON_EXPORT]->get_excute_cron();
946
  }
947
 
948
+ if ( $this->share_variation_analysis_mode === self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER ) {
949
+ $target_crons[] = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_excute_cron();
950
+ }
951
+
952
  $options = array(
953
  'delegate' => $this,
954
  'check_interval' => 600,
958
 
959
  $this->control_engines[self::REF_COMMON_CONTROL] = Common_Job_Reset_Engine::get_instance();
960
  $this->control_engines[self::REF_COMMON_CONTROL]->initialize( $options );
961
+
962
  $tmp_max_execution_time = ini_get( 'max_execution_time' );
963
 
964
  if ( isset( $tmp_max_execution_time ) && $tmp_max_execution_time > 0 ) {
994
  if ( in_array( $screen->id, $this->plugin_screen_hook_suffix ) ) {
995
  wp_enqueue_style( self::DOMAIN .'-admin-style-1', plugins_url( ltrim( '/css/sns-count-cache.css', '/' ), __FILE__) );
996
  wp_enqueue_style( self::DOMAIN .'-admin-style-2', plugins_url( ltrim( '/css/prettify.css', '/' ), __FILE__ ) );
997
+ wp_enqueue_style( 'jquery-ui-datepicker-style' , '//ajax.googleapis.com/ajax/libs/jqueryui/1/themes/smoothness/jquery-ui.css');
998
  }
999
  }
1000
 
1017
 
1018
  wp_enqueue_script( self::DOMAIN . '-admin-script-2', plugins_url( ltrim( '/js/jquery.scc-cache-info.min.js', '/' ), __FILE__ ), array( 'jquery' ) );
1019
  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 ) ) );
1020
+
1021
+ wp_enqueue_script( 'jquery-ui-datepicker' );
1022
  }
1023
  }
1024
 
1051
  foreach ( $this->control_engines as $key => $control_engine ) {
1052
  $control_engine->register_schedule();
1053
  }
1054
+
1055
+ if ( $this->share_variation_analysis_mode === self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER ) {
1056
+ $this->analytical_engines[self::REF_SHARE_ANALYSIS]->register_schedule();
1057
+ }
1058
+
1059
+ if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_SCHEDULER ) {
1060
  $this->export_engines[self::REF_COMMON_EXPORT]->register_schedule();
1061
  }
1062
 
1111
  foreach ( $this->control_engines as $key => $control_engine ) {
1112
  $control_engine->unregister_schedule();
1113
  }
1114
+
1115
+ $this->analytical_engines[self::REF_SHARE_ANALYSIS]->unregister_schedule();
1116
+ $this->analytical_engines[self::REF_SHARE_ANALYSIS]->clear_base();
1117
+
1118
  $this->export_engines[self::REF_COMMON_EXPORT]->unregister_schedule();
1119
 
1120
  set_time_limit( $this->original_max_execution_time );
1133
  $this->activate_plugin();
1134
 
1135
  }
1136
+
1137
+ /**
1138
+ * Delete related cache when the post was deleted.
1139
+ *
1140
+ * @since 0.7.0
1141
+ */
1142
+ public function clear_cache_deleted_post( $post_id ) {
1143
+
1144
+ if ( isset( $post_id ) ) {
1145
+ $this->cache_engines[self::REF_SHARE_BASE]->clear_cache_by_post_id( $post_id );
1146
+ $this->cache_engines[self::REF_SHARE_2ND]->clear_cache_by_post_id( $post_id );
1147
+ $this->analytical_engines[self::REF_SHARE_ANALYSIS]->clear_base_by_post_id( $post_id );
1148
+ }
1149
+ }
1150
 
1151
  /**
1152
  * Adds options & management pages to the admin menu.
1163
  $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' ) );
1164
  $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' ) );
1165
  $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' ) );
1166
+
1167
+ if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
1168
+ $this->plugin_screen_hook_suffix[] = add_submenu_page( 'scc-dashboard', __( 'Hot Content | SNS Count Cache', self::DOMAIN ), __( 'Hot Content', self::DOMAIN ), self::OPT_COMMON_CAPABILITY, 'scc-hot-content', array( $this, 'hot_content_page' ) );
1169
+ }
1170
+
1171
+ $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' ) );
1172
  $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' ) );
1173
  }
1174
 
1192
  * @since 0.5.1
1193
  */
1194
  public function wp_dashboard_page() {
1195
+
1196
+ if ( ! current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
1197
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1198
+ }
1199
+
1200
  include_once( dirname( __FILE__ ) . '/includes/admin-dashboard-widget.php' );
1201
  }
1202
 
1207
  * @since 0.1.0
1208
  */
1209
  public function dashboard_page() {
1210
+
1211
+ if ( ! current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
1212
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1213
+ }
1214
+
1215
  include_once( dirname( __FILE__ ) . '/includes/admin-dashboard.php' );
1216
  }
1217
 
1222
  * @since 0.1.0
1223
  */
1224
  public function cache_status_page() {
1225
+
1226
+ if ( ! current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
1227
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1228
+ }
1229
+
1230
  include_once( dirname( __FILE__ ) . '/includes/admin-cache-status.php' );
1231
  }
1232
 
1236
  * @since 0.1.0
1237
  */
1238
  public function share_count_page() {
1239
+
1240
+ if ( ! current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
1241
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1242
+ }
1243
+
1244
+ include_once( dirname( __FILE__ ) . '/includes/admin-share-count.php' );
1245
  }
1246
 
1247
  /**
1250
  * @since 0.1.0
1251
  */
1252
  public function setting_page() {
1253
+
1254
+ if ( ! current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
1255
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1256
+ }
1257
+
1258
+ include( dirname( __FILE__ ) . '/includes/admin-setting.php' );
1259
  }
1260
 
1261
  /**
1264
  * @since 0.1.0
1265
  */
1266
  public function help_page() {
1267
+
1268
+ if ( ! current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
1269
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1270
+ }
1271
+
1272
+ include_once( dirname( __FILE__ ) . '/includes/admin-help.php' );
1273
  }
1274
 
1275
  /**
1278
  * @since 0.5.1
1279
  */
1280
  public function notice_page() {
1281
+
1282
+ if ( ! current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
1283
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1284
+ }
1285
+
1286
+ include_once( dirname( __FILE__ ) . '/includes/admin-notice.php' );
1287
  }
1288
+
1289
+ /**
1290
+ * Option page implementation
1291
+ *
1292
+ * @since 0.6.1
1293
+ */
1294
+ public function hot_content_page() {
1295
+
1296
+ if ( ! current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
1297
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1298
+ }
1299
+
1300
+ include_once( dirname( __FILE__ ) . '/includes/admin-hot-content.php' );
1301
+ }
1302
+
1303
+
1304
  /**
1305
  * Cache share count for a given post ID
1306
  *
1376
 
1377
  }
1378
 
1379
+ /**
1380
+ * Method call between one cache engine and another
1381
+ *
1382
+ * @since 0.6.1
1383
+ */
1384
+ public function order_analysis( Cache_Engine $engine, $options = array() ) {
1385
+ Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
1386
+
1387
+ if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
1388
+ switch ( get_class( $engine ) ) {
1389
+ case 'Share_Second_Cache_Engine':
1390
+ $this->analytical_engines[self::REF_SHARE_ANALYSIS]->analyze( $options );
1391
+ break;
1392
+ }
1393
+ }
1394
+
1395
+ }
1396
+
1397
  /**
1398
  * Return pagination
1399
  *
1496
  $secondary_no_cache_count = 0;
1497
 
1498
  $sum = array();
1499
+ $delta = array();
1500
  $return = array();
1501
 
1502
  foreach ( $share_base_cache_target as $sns => $active ) {
1503
  if( $active ){
1504
  $sum[$sns] = 0;
1505
+ $delta[$sns] = 0;
1506
  }
1507
  }
1508
 
1523
  $partial_cache_flag = false;
1524
 
1525
  $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
1526
+
1527
  if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
1528
 
1529
  foreach ( $share_base_cache_target as $sns => $active ) {
1539
 
1540
  if ( $partial_cache_flag && $full_cache_flag ) {
1541
  ++$primary_full_cache_count;
1542
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
1543
  ++$primary_partial_cache_count;
1544
  } else {
1545
  ++$primary_no_cache_count;
1572
 
1573
  if ( $partial_cache_flag && $full_cache_flag ) {
1574
  ++$secondary_full_cache_count;
1575
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
1576
  ++$secondary_partial_cache_count;
1577
  } else {
1578
  ++$secondary_no_cache_count;
1605
 
1606
  if ( $partial_cache_flag && $full_cache_flag ) {
1607
  ++$secondary_full_cache_count;
1608
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
1609
  ++$secondary_partial_cache_count;
1610
  } else {
1611
  ++$secondary_no_cache_count;
1615
 
1616
  }
1617
 
1618
+ $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
1619
+
1620
+ if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
1621
+
1622
+ foreach ( $share_base_cache_target as $sns => $active ) {
1623
+ if( $active ){
1624
+
1625
+ if ( isset( $sns_deltas[$sns] ) ) {
1626
+ $delta[$sns] = $delta[$sns] + $sns_deltas[$sns];
1627
+ }
1628
+ }
1629
+ }
1630
+ }
1631
+
1632
  //page, post
1633
  $site_query = new WP_Query( $query_args );
1634
 
1642
  $partial_cache_flag = false;
1643
 
1644
  $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( get_the_ID() );
1645
+
1646
  if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
1647
 
1648
  foreach ( $share_base_cache_target as $sns => $active ) {
1649
+ if ( $active ) {
1650
+
1651
  if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
1652
  $sum[$sns] = $sum[$sns] + $sns_counts[$sns];
1653
  $partial_cache_flag = true;
1656
  }
1657
  }
1658
  }
1659
+
1660
  if ( $partial_cache_flag && $full_cache_flag ) {
1661
  ++$primary_full_cache_count;
1662
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
1663
  ++$primary_partial_cache_count;
1664
  } else {
1665
  ++$primary_no_cache_count;
1666
  }
1667
 
1668
  $full_cache_flag = true;
1669
+ $partial_cache_flag = false;
1670
+
1671
+ $sns_counts = array();
1672
+ $sns_deltas = array();
1673
 
1674
  foreach ( $share_base_cache_target as $sns => $active ) {
1675
 
1676
+ if ( $active ) {
1677
 
1678
  $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
1679
  $sns_counts[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
1683
  } else {
1684
  $full_cache_flag = false;
1685
  }
1686
+
1687
+ if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
1688
+ //delta
1689
+ $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
1690
+
1691
+ $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
1692
+
1693
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' ) {
1694
+ $delta[$sns] = $delta[$sns] + $sns_deltas[$sns];
1695
+ }
1696
+ }
1697
  }
1698
  }
1699
 
1700
  if ( $partial_cache_flag && $full_cache_flag ) {
1701
  ++$secondary_full_cache_count;
1702
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
1703
  ++$secondary_partial_cache_count;
1704
  } else {
1705
  ++$secondary_no_cache_count;
1707
 
1708
  } else {
1709
 
1710
+ $sns_deltas = array();
1711
+ $sns_counts = array();
1712
+
1713
  foreach ( $share_base_cache_target as $sns => $active ) {
1714
 
1715
  if( $active ){
1723
  } else {
1724
  $full_cache_flag = false;
1725
  }
1726
+
1727
+ if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
1728
+ //delta
1729
+ $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
1730
+
1731
+ $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
1732
+
1733
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' ) {
1734
+ $delta[$sns] = $delta[$sns] + $sns_deltas[$sns];
1735
+ }
1736
+ }
1737
  }
1738
  }
1739
 
1740
  if ( $partial_cache_flag && $full_cache_flag ) {
1741
  ++$secondary_full_cache_count;
1742
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
1743
  ++$secondary_partial_cache_count;
1744
  } else {
1745
  ++$secondary_no_cache_count;
1759
  if ( $active && isset( $sum[$sns] ) ) {
1760
  if ( $sns === self::REF_SHARE_GPLUS ){
1761
  $return['share_count']['gplus'] = number_format( (int) $sum[$sns] );
1762
+ $return['share_delta']['gplus'] = number_format( (int) $delta[$sns] );
1763
  } else {
1764
  $return['share_count'][strtolower( $sns )] = number_format( (int) $sum[$sns] );
1765
+ $return['share_delta'][strtolower( $sns )] = number_format( (int) $delta[$sns] );
1766
  }
1767
  }
1768
  }
1777
 
1778
  if ( $primary_full_cache_count === $posts_count ) {
1779
  $return['primary']['cache_status'] = __( 'Completed', self::DOMAIN );
1780
+ } elseif ( ( $primary_full_cache_count + $primary_partial_cache_count ) === $posts_count ) {
1781
  $return['primary']['cache_status'] = __( 'Partially Completed', self::DOMAIN );
1782
  } else {
1783
  $return['primary']['cache_status'] = __( 'Ongoing', self::DOMAIN );
1785
 
1786
  if ( $secondary_full_cache_count === $posts_count ) {
1787
  $return['secondary']['cache_status'] = __( 'Completed', self::DOMAIN );
1788
+ } elseif ( ( $secondary_full_cache_count + $secondary_partial_cache_count ) === $posts_count ) {
1789
  $return['secondary']['cache_status'] = __( 'Partially Completed', self::DOMAIN );
1790
  } else {
1791
  $return['secondary']['cache_status'] = __( 'Ongoing', self::DOMAIN );
1792
+ }
1793
+
1794
  $callback = $_REQUEST["callback"];
1795
 
1796
  header( 'Content-type: application/javascript; charset=utf-8' );
1840
  } else {
1841
  switch ( $this->dynamic_cache_mode ) {
1842
  case self::OPT_COMMON_ACCESS_BASED_2ND_CACHE:
 
1843
  $this->cache_engines[self::REF_SHARE_LAZY]->prime_cache( $post_ID );
1844
 
1845
  if ( $sns_key ) {
1910
  }
1911
  break;
1912
  case self::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE:
 
1913
  $this->cache_engines[self::REF_SHARE_LAZY]->prime_cache( $post_ID );
1914
 
1915
  if ( $sns_key ) {
1927
  }
1928
  break;
1929
  case self::OPT_COMMON_ACCESS_BASED_SYNC_CACHE:
 
1930
  $sns_counts = $this->cache_engines[self::REF_SHARE_BASE]->direct_cache( $post_ID, true );
1931
 
1932
  if ( $sns_key ) {
1998
  } else {
1999
  switch ( $this->dynamic_cache_mode ) {
2000
  case self::OPT_COMMON_ACCESS_BASED_2ND_CACHE:
 
2001
  $this->cache_engines[self::REF_FOLLOW_LAZY]->prime_cache();
2002
 
2003
  $option_key = $this->cache_engines[self::REF_FOLLOW_2ND]->get_cache_key( 'follow' );
2008
  if ( ! isset( $sns_followers[$sns_key] ) || $sns_followers[$sns_key] < 0 ) {
2009
  $sns_followers[$sns_key] = 0;
2010
  }
2011
+ } else {
2012
  $sns_followers[$sns_key] = 0;
2013
  }
2014
 
2036
  }
2037
  break;
2038
  case self::OPT_COMMON_ACCESS_BASED_ASYNC_CACHE:
 
2039
  $this->cache_engines[self::REF_FOLLOW_LAZY]->prime_cache();
2040
 
2041
  if ( $sns_key ) {
2053
  }
2054
  break;
2055
  case self::OPT_COMMON_ACCESS_BASED_SYNC_CACHE:
 
2056
  $sns_followers = $this->cache_engines[self::REF_FOLLOW_BASE]->direct_cache();
2057
 
2058
  if ( $sns_key ) {
2090
  break;
2091
  }
2092
  }
2093
+ }
2094
+
2095
+ /**
2096
+ * Return if variation alaysis is enabled or not.
2097
+ *
2098
+ * @since 0.7.0
2099
+ */
2100
+ public function is_variation_analysis_enabled() {
2101
+
2102
+ if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
2103
+ return true;
2104
+ } else {
2105
+ return false;
2106
+ }
2107
+ }
2108
 
2109
 
2110
  }
2123
 
2124
  if ( isset( $options['url'] ) && $options['url'] ) {
2125
  $post_ID = url_to_postid( $options['url'] );
2126
+ } elseif ( isset( $options['post_id'] ) && $options['post_id'] ) {
2127
  $post_ID = $options['post_id'];
2128
  } else {
2129
  $post_ID = get_the_ID();
2290
  return scc_get_follow( $options );
2291
  }
2292
 
2293
+ /**
2294
+ * Return if variation alaysis is enabled or not.
2295
+ *
2296
+ * @since 0.7.0
2297
+ */
2298
+ function scc_is_variation_analysis_enabled() {
2299
+ return SNS_Count_Cache::get_instance()->is_variation_analysis_enabled();
2300
+ }
2301
+
2302
+
2303
 
2304
  }
2305