SNS Count Cache - Version 0.11.0

Version Description

  • Fixed: Facebook share count is not retrieved and cached.
  • Fixed: Pocket share count is not retrieved and cached.
  • Added: function to display variation of follower count.
  • Added: NewShareCounts is included in selectable Twitter API alternatives.
  • Added: function to retrieve share count of Linkedin.

=

Download this release

Release Info

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

Code changes from version 0.10.0 to 0.11.0

Files changed (62) hide show
  1. css/monokai.css +70 -70
  2. css/sns-count-cache.css +206 -206
  3. data/.htaccess +13 -13
  4. data/index.php +4 -4
  5. includes/admin-cache-status.php +310 -310
  6. includes/admin-dashboard-widget.php +237 -234
  7. includes/admin-dashboard.php +259 -256
  8. includes/admin-help.php +211 -206
  9. includes/admin-hot-content.php +334 -331
  10. includes/admin-notice.php +48 -48
  11. includes/admin-setting.php +2567 -2113
  12. includes/admin-share-count.php +452 -449
  13. includes/class-crypt-blowfish.php +272 -272
  14. includes/class-default-key.php +319 -320
  15. includes/class-scc-analytical-engline.php +102 -102
  16. includes/class-scc-cache-engine.php +114 -107
  17. includes/class-scc-common-data-export-engine.php +341 -339
  18. includes/class-scc-common-job-reset-engine.php +147 -147
  19. includes/class-scc-common-util.php +663 -607
  20. includes/class-scc-crawl-strategy.php +229 -229
  21. includes/class-scc-crawler.php +199 -199
  22. includes/class-scc-engine.php +158 -158
  23. includes/class-scc-export-engine.php +44 -44
  24. includes/class-scc-follow-analytical-engine.php +371 -0
  25. includes/class-scc-follow-base-cache-engine.php +247 -229
  26. includes/class-scc-follow-cache-engine.php +201 -201
  27. includes/class-scc-follow-crawl-strategy-factory.php +66 -0
  28. includes/class-scc-follow-crawler.php +265 -297
  29. includes/class-scc-follow-facebook-strategy.php +138 -132
  30. includes/class-scc-follow-feedly-strategy.php +130 -124
  31. includes/class-scc-follow-instagram-strategy.php +132 -126
  32. includes/class-scc-follow-lazy-cache-engine.php +210 -192
  33. includes/class-scc-follow-push7-strategy.php +128 -124
  34. includes/class-scc-follow-restore-cache-engine.php +233 -208
  35. includes/class-scc-follow-second-cache-engine.php +253 -228
  36. includes/class-scc-follow-twitter-strategy.php +186 -180
  37. includes/class-scc-share-analytical-engine.php +550 -580
  38. includes/class-scc-share-base-cache-engine.php +422 -410
  39. includes/class-scc-share-cache-engine.php +308 -296
  40. includes/class-scc-share-crawl-strategy-factory.php +74 -0
  41. includes/class-scc-share-crawler.php +271 -307
  42. includes/class-scc-share-facebook-strategy.php +134 -135
  43. includes/class-scc-share-google-strategy.php +130 -124
  44. includes/class-scc-share-hatebu-strategy.php +126 -120
  45. includes/class-scc-share-lazy-cache-engine.php +264 -257
  46. includes/class-scc-share-linkedin-strategy.php +140 -0
  47. includes/class-scc-share-pinterest-strategy.php +134 -128
  48. includes/class-scc-share-pocket-strategy.php +138 -127
  49. includes/class-scc-share-restore-cache-engine.php +312 -267
  50. includes/class-scc-share-rush-cache-engine.php +352 -345
  51. includes/class-scc-share-second-cache-engine.php +370 -347
  52. includes/class-scc-share-twitter-strategy.php +194 -162
  53. includes/class-scc-sleep-throttle.php +124 -124
  54. includes/class-scc-wp-cron-util.php +317 -267
  55. includes/download.php +75 -75
  56. includes/interface-scc-order.php +41 -41
  57. index.php +62 -58
  58. js/highlight.pack.js +2 -2
  59. js/jquery.scc-cache-info.js +169 -161
  60. js/jquery.scc-cache-info.min.js +13 -12
  61. languages/sns-count-cache-ja.mo +0 -0
  62. languages/sns-count-cache-ja.po +0 -1198
css/monokai.css CHANGED
@@ -1,70 +1,70 @@
1
- /*
2
- Monokai style - ported by Luigi Maselli - http://grigio.org
3
- */
4
-
5
- .hljs {
6
- display: block;
7
- overflow-x: auto;
8
- padding: 0.5em;
9
- background: #272822; color: #ddd;
10
- }
11
-
12
- .hljs-tag,
13
- .hljs-keyword,
14
- .hljs-selector-tag,
15
- .hljs-literal,
16
- .hljs-strong,
17
- .hljs-name {
18
- color: #f92672;
19
- }
20
-
21
- .hljs-code {
22
- color: #66d9ef;
23
- }
24
-
25
- .hljs-class .hljs-title {
26
- color: white;
27
- }
28
-
29
- .hljs-attribute,
30
- .hljs-symbol,
31
- .hljs-regexp,
32
- .hljs-link {
33
- color: #bf79db;
34
- }
35
-
36
- .hljs-string,
37
- .hljs-bullet,
38
- .hljs-subst,
39
- .hljs-title,
40
- .hljs-section,
41
- .hljs-emphasis,
42
- .hljs-type,
43
- .hljs-built_in,
44
- .hljs-builtin-name,
45
- .hljs-selector-attr,
46
- .hljs-selector-pseudo,
47
- .hljs-addition,
48
- .hljs-variable,
49
- .hljs-template-tag,
50
- .hljs-template-variable {
51
- color: #a6e22e;
52
- }
53
-
54
- .hljs-comment,
55
- .hljs-quote,
56
- .hljs-deletion,
57
- .hljs-meta {
58
- color: #75715e;
59
- }
60
-
61
- .hljs-keyword,
62
- .hljs-selector-tag,
63
- .hljs-literal,
64
- .hljs-doctag,
65
- .hljs-title,
66
- .hljs-section,
67
- .hljs-type,
68
- .hljs-selector-id {
69
- font-weight: bold;
70
- }
1
+ /*
2
+ Monokai style - ported by Luigi Maselli - http://grigio.org
3
+ */
4
+
5
+ .hljs {
6
+ display: block;
7
+ overflow-x: auto;
8
+ padding: 0.5em;
9
+ background: #272822; color: #ddd;
10
+ }
11
+
12
+ .hljs-tag,
13
+ .hljs-keyword,
14
+ .hljs-selector-tag,
15
+ .hljs-literal,
16
+ .hljs-strong,
17
+ .hljs-name {
18
+ color: #f92672;
19
+ }
20
+
21
+ .hljs-code {
22
+ color: #66d9ef;
23
+ }
24
+
25
+ .hljs-class .hljs-title {
26
+ color: white;
27
+ }
28
+
29
+ .hljs-attribute,
30
+ .hljs-symbol,
31
+ .hljs-regexp,
32
+ .hljs-link {
33
+ color: #bf79db;
34
+ }
35
+
36
+ .hljs-string,
37
+ .hljs-bullet,
38
+ .hljs-subst,
39
+ .hljs-title,
40
+ .hljs-section,
41
+ .hljs-emphasis,
42
+ .hljs-type,
43
+ .hljs-built_in,
44
+ .hljs-builtin-name,
45
+ .hljs-selector-attr,
46
+ .hljs-selector-pseudo,
47
+ .hljs-addition,
48
+ .hljs-variable,
49
+ .hljs-template-tag,
50
+ .hljs-template-variable {
51
+ color: #a6e22e;
52
+ }
53
+
54
+ .hljs-comment,
55
+ .hljs-quote,
56
+ .hljs-deletion,
57
+ .hljs-meta {
58
+ color: #75715e;
59
+ }
60
+
61
+ .hljs-keyword,
62
+ .hljs-selector-tag,
63
+ .hljs-literal,
64
+ .hljs-doctag,
65
+ .hljs-title,
66
+ .hljs-section,
67
+ .hljs-type,
68
+ .hljs-selector-id {
69
+ font-weight: bold;
70
+ }
css/sns-count-cache.css CHANGED
@@ -1,206 +1,206 @@
1
- .wrap h2 a {
2
- color: #222;
3
- text-decoration: none;
4
- }
5
-
6
- .sns-cnt-cache h3.hndle {
7
- font-size: 16px !important;
8
- }
9
-
10
- .sns-cnt-cache h4 {
11
- font-size: 15px;
12
- font-weight: 700;
13
- }
14
-
15
- .sns-cnt-cache .postbox .inside {
16
- padding: 0 10px;
17
- }
18
-
19
- .sns-cnt-cache .view-table {
20
- border: 1px solid #000;
21
- margin: 10px 0;
22
- padding: 0;
23
- width: 100%;
24
- border-collapse: collapse;
25
- border-spacing: 0;
26
- word-break: break-word;
27
- font-size: 13px;
28
- }
29
-
30
- .sns-cnt-cache .view-table tr:nth-child(odd) {
31
- background-color: #ffffff;
32
- }
33
-
34
- .sns-cnt-cache .view-table tr:nth-child(even) {
35
- background-color: #f9f9f9;
36
- }
37
-
38
- .sns-cnt-cache .view-table tr.home {
39
- border-bottom: 1px solid #dbdbdb;
40
- }
41
-
42
- .sns-cnt-cache .view-table th {
43
- vertical-align: middle;
44
- padding: 3px;
45
- text-align: left;
46
- background-color: #4c4c4c;
47
- color: #fff;
48
- }
49
-
50
- .sns-cnt-cache .pagination {
51
- margin: 10px 0;
52
- }
53
-
54
- .sns-cnt-cache .form-table .section-label {
55
- font-weight: 600;
56
- font-size: 1.3em;
57
- }
58
-
59
- .sns-cnt-cache .view-table td {
60
- vertical-align: middle;
61
- padding: 2px 4px;
62
- border: 1px dotted #dfdfdf;
63
- }
64
-
65
- .sns-cnt-cache .full-cache {
66
- color: #468847;
67
- }
68
-
69
- .sns-cnt-cache .partial-cache {
70
- color: #f0ad4e;
71
- }
72
-
73
- .sns-cnt-cache .no-cache {
74
- color: #ccc;
75
- }
76
-
77
- .sns-cnt-cache .not-cached {
78
- color: #ccc;
79
- }
80
-
81
- .sns-cnt-cache .share-count {
82
- text-align: right;
83
- }
84
-
85
- .sns-cnt-cache .submit-button {
86
- margin: 20px 0;
87
- }
88
-
89
- .sns-cnt-cache a {
90
- text-decoration: none;
91
- color: #444;
92
- -webkit-transition-property: border,background,color;
93
- transition-property: border,background,color;
94
- -webkit-transition-duration: .05s;
95
- transition-duration: .05s;
96
- -webkit-transition-timing-function: ease-in-out;
97
- transition-timing-function: ease-in-out;
98
- text-decoration: none;
99
- }
100
-
101
- .sns-cnt-cache a:hover {
102
- color: #0074a2;
103
- }
104
-
105
- .sns-cnt-cache .view-table th a {
106
- color: #fff;
107
- }
108
-
109
- .sns-cnt-cache a.sort-exec-key {
110
- text-decoration: underline;
111
- }
112
-
113
- .pagination span, .pagination a {
114
- display: inline-block;
115
- padding: 2px 10px;
116
- }
117
-
118
- .pagination a {
119
- background: #555;
120
- color: #fff;
121
- }
122
-
123
- .pagination a:hover {
124
- background: #3279bb;
125
- color: #fff;
126
- }
127
-
128
- .pagination span.page-num {
129
- margin-right: 10px;
130
- padding: 0;
131
- }
132
-
133
- .pagination span.dots {
134
- padding: 0;
135
- color: gainsboro;
136
- }
137
-
138
- .pagination span.current {
139
- background-color: #ccc;
140
- color: #fff;
141
- }
142
-
143
- /*
144
- .sns-cnt-cache .button-small {
145
- font-size: 12px;
146
- padding: 1px 5px;
147
- height: 20px;
148
- line-height: 15px;
149
- }
150
- */
151
-
152
- .sns-cnt-cache .delta-rise {
153
- color: #FF6866;
154
- text-decoration: underline;
155
- background: #FFEFEF;
156
- font-weight: bold;
157
- font-size: 11px;
158
- border-radius: 5%;
159
- }
160
-
161
- .sns-cnt-cache .delta-fall {
162
- color: #f0ad4e;
163
- text-decoration: underline;
164
- }
165
-
166
- .sns-cnt-cache .wpcron td {
167
- border-top: 1px solid #dedede;
168
- }
169
-
170
- .sns-cnt-cache .at-mark {
171
- padding: 3px 5px;
172
- margin: 0 -5px 0 0;
173
- font-size: 14px;
174
- font-weight: normal;
175
- text-align: center;
176
- text-shadow: 0 1px 0 #ffffff;
177
- background-color: #eeeeee;
178
- border: 1px solid #ddd;
179
- }
180
-
181
- .sns-cnt-cache .button.button-small {
182
- height: 18px;
183
- line-height: 16px;
184
- padding: 0 4px;
185
- font-size: 11px;
186
- }
187
-
188
- @media screen and (max-width: 782px) {
189
-
190
- .sns-cnt-cache .at-mark {
191
- display: block;
192
- font-size: 14px;
193
- font-weight: normal;
194
- text-align: center;
195
- text-shadow: 0 1px 0 #ffffff;
196
- background-color: #eeeeee;
197
- border: 1px solid #ddd;
198
- padding: 7px 10px;
199
- width: 100%;
200
- max-width: none;
201
- -webkit-box-sizing: border-box;
202
- -moz-box-sizing: border-box;
203
- box-sizing: border-box;
204
- margin: 0 0 -1px 1px;
205
- }
206
- }
1
+ .wrap h2 a {
2
+ color: #222;
3
+ text-decoration: none;
4
+ }
5
+
6
+ .sns-cnt-cache h3.hndle {
7
+ font-size: 16px !important;
8
+ }
9
+
10
+ .sns-cnt-cache h4 {
11
+ font-size: 15px;
12
+ font-weight: 700;
13
+ }
14
+
15
+ .sns-cnt-cache .postbox .inside {
16
+ padding: 0 10px;
17
+ }
18
+
19
+ .sns-cnt-cache .view-table {
20
+ border: 1px solid #000;
21
+ margin: 10px 0;
22
+ padding: 0;
23
+ width: 100%;
24
+ border-collapse: collapse;
25
+ border-spacing: 0;
26
+ word-break: break-word;
27
+ font-size: 13px;
28
+ }
29
+
30
+ .sns-cnt-cache .view-table tr:nth-child(odd) {
31
+ background-color: #ffffff;
32
+ }
33
+
34
+ .sns-cnt-cache .view-table tr:nth-child(even) {
35
+ background-color: #f9f9f9;
36
+ }
37
+
38
+ .sns-cnt-cache .view-table tr.home {
39
+ border-bottom: 1px solid #dbdbdb;
40
+ }
41
+
42
+ .sns-cnt-cache .view-table th {
43
+ vertical-align: middle;
44
+ padding: 3px;
45
+ text-align: left;
46
+ background-color: #4c4c4c;
47
+ color: #fff;
48
+ }
49
+
50
+ .sns-cnt-cache .pagination {
51
+ margin: 10px 0;
52
+ }
53
+
54
+ .sns-cnt-cache .form-table .section-label {
55
+ font-weight: 600;
56
+ font-size: 1.3em;
57
+ }
58
+
59
+ .sns-cnt-cache .view-table td {
60
+ vertical-align: middle;
61
+ padding: 2px 4px;
62
+ border: 1px dotted #dfdfdf;
63
+ }
64
+
65
+ .sns-cnt-cache .full-cache {
66
+ color: #468847;
67
+ }
68
+
69
+ .sns-cnt-cache .partial-cache {
70
+ color: #f0ad4e;
71
+ }
72
+
73
+ .sns-cnt-cache .no-cache {
74
+ color: #ccc;
75
+ }
76
+
77
+ .sns-cnt-cache .not-cached {
78
+ color: #ccc;
79
+ }
80
+
81
+ .sns-cnt-cache .share-count {
82
+ text-align: right;
83
+ }
84
+
85
+ .sns-cnt-cache .submit-button {
86
+ margin: 20px 0;
87
+ }
88
+
89
+ .sns-cnt-cache a {
90
+ text-decoration: none;
91
+ color: #444;
92
+ -webkit-transition-property: border,background,color;
93
+ transition-property: border,background,color;
94
+ -webkit-transition-duration: .05s;
95
+ transition-duration: .05s;
96
+ -webkit-transition-timing-function: ease-in-out;
97
+ transition-timing-function: ease-in-out;
98
+ text-decoration: none;
99
+ }
100
+
101
+ .sns-cnt-cache a:hover {
102
+ color: #0074a2;
103
+ }
104
+
105
+ .sns-cnt-cache .view-table th a {
106
+ color: #fff;
107
+ }
108
+
109
+ .sns-cnt-cache a.sort-exec-key {
110
+ text-decoration: underline;
111
+ }
112
+
113
+ .pagination span, .pagination a {
114
+ display: inline-block;
115
+ padding: 2px 15px;
116
+ }
117
+
118
+ .pagination a {
119
+ background: #555;
120
+ color: #fff;
121
+ }
122
+
123
+ .pagination a:hover {
124
+ background: #3279bb;
125
+ color: #fff;
126
+ }
127
+
128
+ .pagination span.page-num {
129
+ margin-right: 10px;
130
+ padding: 0;
131
+ }
132
+
133
+ .pagination span.dots {
134
+ padding: 0;
135
+ color: gainsboro;
136
+ }
137
+
138
+ .pagination span.current {
139
+ background-color: #ccc;
140
+ color: #fff;
141
+ }
142
+
143
+ /*
144
+ .sns-cnt-cache .button-small {
145
+ font-size: 12px;
146
+ padding: 1px 5px;
147
+ height: 20px;
148
+ line-height: 15px;
149
+ }
150
+ */
151
+
152
+ .sns-cnt-cache .delta-rise {
153
+ color: #FF6866;
154
+ text-decoration: underline;
155
+ background: #FFEFEF;
156
+ font-weight: bold;
157
+ font-size: 11px;
158
+ border-radius: 5%;
159
+ }
160
+
161
+ .sns-cnt-cache .delta-fall {
162
+ color: #f0ad4e;
163
+ text-decoration: underline;
164
+ }
165
+
166
+ .sns-cnt-cache .wpcron td {
167
+ border-top: 1px solid #dedede;
168
+ }
169
+
170
+ .sns-cnt-cache .at-mark {
171
+ padding: 3px 5px;
172
+ margin: 0 -5px 0 0;
173
+ font-size: 14px;
174
+ font-weight: normal;
175
+ text-align: center;
176
+ text-shadow: 0 1px 0 #ffffff;
177
+ background-color: #eeeeee;
178
+ border: 1px solid #ddd;
179
+ }
180
+
181
+ .sns-cnt-cache .button.button-small {
182
+ height: 18px;
183
+ line-height: 16px;
184
+ padding: 0 4px;
185
+ font-size: 11px;
186
+ }
187
+
188
+ @media screen and (max-width: 782px) {
189
+
190
+ .sns-cnt-cache .at-mark {
191
+ display: block;
192
+ font-size: 14px;
193
+ font-weight: normal;
194
+ text-align: center;
195
+ text-shadow: 0 1px 0 #ffffff;
196
+ background-color: #eeeeee;
197
+ border: 1px solid #ddd;
198
+ padding: 7px 10px;
199
+ width: 100%;
200
+ max-width: none;
201
+ -webkit-box-sizing: border-box;
202
+ -moz-box-sizing: border-box;
203
+ box-sizing: border-box;
204
+ margin: 0 0 -1px 1px;
205
+ }
206
+ }
data/.htaccess CHANGED
@@ -1,13 +1,13 @@
1
- <Files "*">
2
- <IfModule mod_access.c>
3
- Deny from all
4
- </IfModule>
5
- <IfModule !mod_access_compat>
6
- <IfModule mod_authz_host.c>
7
- Deny from all
8
- </IfModule>
9
- </IfModule>
10
- <IfModule mod_access_compat>
11
- Deny from all
12
- </IfModule>
13
- </Files>
1
+ <Files "*">
2
+ <IfModule mod_access.c>
3
+ Deny from all
4
+ </IfModule>
5
+ <IfModule !mod_access_compat>
6
+ <IfModule mod_authz_host.c>
7
+ Deny from all
8
+ </IfModule>
9
+ </IfModule>
10
+ <IfModule mod_access_compat>
11
+ Deny from all
12
+ </IfModule>
13
+ </Files>
data/index.php CHANGED
@@ -1,4 +1,4 @@
1
- <?php
2
- header( $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found' );
3
- header( 'Status: 404 Not Found' );
4
- ?>
1
+ <?php
2
+ header( $_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found' );
3
+ header( 'Status: 404 Not Found' );
4
+ ?>
includes/admin-cache-status.php CHANGED
@@ -1,310 +1,310 @@
1
- <?php
2
- /*
3
- admin-cache-status.php
4
-
5
- Description: Option page implementation
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
-
32
- $posts_per_page = 50;
33
-
34
- $paged = 1;
35
-
36
- if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 0 ) {
37
- $paged = $_GET['paged'];
38
- } else {
39
- $paged = 1;
40
- }
41
-
42
- if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], __FILE__ ) ) {
43
- if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
44
- if ( isset( $_GET["action"] ) && $_GET["action"] === 'cache' ) {
45
- if ( isset( $_GET["post_id"] ) ) {
46
- $post_id = $_GET["post_id"];
47
- $this->cache_engines[self::REF_SHARE_BASE]->direct_cache( $post_id, true );
48
- //wp_safe_redirect( menu_page_url( 'scc-cache-status', false ) );
49
- }
50
- }
51
- }
52
- }
53
-
54
- $query_args = array(
55
- 'post_type' => $this->share_base_cache_post_types,
56
- 'post_status' => 'publish',
57
- 'posts_per_page' => $posts_per_page,
58
- 'paged' => $paged,
59
- 'update_post_term_cache' => false
60
- );
61
-
62
- $posts_query = new WP_Query( $query_args );
63
- ?>
64
- <div class="wrap">
65
- <h2><a href="admin.php?page=scc-cache-status"><?php _e( 'SNS Count Cache', self::DOMAIN ); ?></a></h2>
66
- <div class="sns-cnt-cache">
67
- <h3 class="nav-tab-wrapper">
68
- <a class="nav-tab" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ); ?></a>
69
- <a class="nav-tab nav-tab-active" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a>
70
- <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
71
- <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
72
- <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
73
- <?php } ?>
74
- <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ); ?></a>
75
- <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
76
- </h3>
77
- <div class="metabox-holder">
78
- <div id="share-site-summary" class="postbox">
79
- <div class="handlediv" title="Click to toggle"><br></div>
80
- <h3 class="hndle"><span><?php _e( 'Cache Status', self::DOMAIN ); ?></span></h3>
81
- <div class="inside">
82
- <table class="view-table">
83
- <thead>
84
- <tr>
85
- <th>No.</th>
86
- <th><?php _e( 'Content', self::DOMAIN ); ?></th>
87
- <th><?php _e( 'Primary Cache', self::DOMAIN ); ?></th>
88
- <th><?php _e( 'Secondary Cache', self::DOMAIN ); ?></th>
89
- <th><?php _e( 'Crawl Date', self::DOMAIN ); ?></th>
90
- <th></th>
91
- </tr>
92
- </thead>
93
- <tbody>
94
- <?php
95
- $count = ( $paged - 1 ) * $posts_per_page + 1;
96
-
97
- $share_base_cache_target = $this->share_base_cache_target ;
98
- unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
99
-
100
- if ( $paged === 1 ) {
101
- ?>
102
- <tr class="home">
103
- <td><?php echo '-'; ?></td>
104
- <td><a href="<?php echo esc_url( home_url( '/' ) ); ?>" target="_blank"><?php echo esc_html( home_url( '/' ) ); ?></a></td>
105
- <?php
106
- $share_base_cache_target = $this->share_base_cache_target ;
107
-
108
- unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
109
-
110
- $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
111
-
112
- if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
113
- $full_cache_flag = true;
114
- $partial_cache_flag = false;
115
-
116
- foreach ( $share_base_cache_target as $sns => $active ) {
117
- if ( $active ) {
118
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
119
- $partial_cache_flag = true;
120
- } else {
121
- $full_cache_flag = false;
122
- }
123
- }
124
- }
125
-
126
- if ( $partial_cache_flag && $full_cache_flag ) {
127
- echo '<td class="full-cache">';
128
- _e( 'full cache', self::DOMAIN );
129
- echo '</td>';
130
- } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
131
- echo '<td class="partial-cache">';
132
- _e( 'partial cache', self::DOMAIN );
133
- echo '</td>';
134
- } else {
135
- echo '<td class="no-cache">';
136
- _e( 'no cache', self::DOMAIN );
137
- echo '</td>';
138
- }
139
- } else {
140
- SCC_Common_Util::log( '[' . __METHOD__ . '] : no transient' );
141
- echo '<td class="no-cache">';
142
- _e( 'no cache', self::DOMAIN );
143
- echo '</td>';
144
- }
145
-
146
- $full_cache_flag = true;
147
- $partial_cache_flag = false;
148
-
149
- $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
150
-
151
- if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
152
- foreach ( $share_base_cache_target as $sns => $active ) {
153
- if ( $active ) {
154
- if ( $sns_counts[$sns] >= 0 ){
155
- $partial_cache_flag = true;
156
- } else {
157
- $full_cache_flag = false;
158
- }
159
- }
160
- }
161
- } else {
162
- $full_cache_flag = false;
163
- }
164
-
165
- if ( $partial_cache_flag && $full_cache_flag ) {
166
- echo '<td class="full-cache">';
167
- _e( 'full cache', self::DOMAIN );
168
- echo '</td>';
169
- } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
170
- echo '<td class="partial-cache">';
171
- _e( 'partial cache', self::DOMAIN );
172
- echo '</td>';
173
- } else {
174
- echo '<td class="no-cache">';
175
- _e( 'no cache', self::DOMAIN );
176
- echo '</td>';
177
- }
178
- if ( isset( $sns_counts[self::REF_CRAWL_DATE] ) && $sns_counts[self::REF_CRAWL_DATE] && $sns_counts[self::REF_CRAWL_DATE] !== -1 ) {
179
- echo '<td class="full-cache">';
180
- echo esc_html( $sns_counts[self::REF_CRAWL_DATE] );
181
- echo '</td>';
182
- } else {
183
- echo '<td class="no-cache">';
184
- _e( 'no data', self::DOMAIN );
185
- echo '</td>';
186
- }
187
-
188
- $nonce = wp_create_nonce( __FILE__ );
189
- $cache_url = esc_url( 'admin.php?page=scc-cache-status&action=cache&post_id=' . 'home' . '&_wpnonce=' . $nonce . '&paged=' . $paged );
190
- ?>
191
- <td><a class="button button-small" href="<?php echo $cache_url ?>"><?php _e( 'Cache', self::DOMAIN ); ?></a></td>
192
- </tr>
193
- <?php
194
- }
195
- if ( $posts_query->have_posts() ) {
196
- while ( $posts_query->have_posts() ) {
197
- $posts_query->the_post();
198
- ?>
199
- <tr>
200
- <td><?php echo $count; ?></td>
201
- <td><a href="<?php echo esc_url( get_permalink( get_the_ID() ) ); ?>" target="_blank"><?php echo esc_html( get_permalink( get_the_ID() ) ); ?></a></td>
202
- <?php
203
- $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( get_the_ID() );
204
-
205
- if ( false === ( $sns_counts = get_transient( $transient_id ) ) ) {
206
- echo '<td class="no-cache">';
207
- _e( 'no cache', self::DOMAIN );
208
- echo '</td>';
209
- } else {
210
- $full_cache_flag = true;
211
- $partial_cache_flag = false;
212
-
213
- foreach ( $share_base_cache_target as $sns => $active ) {
214
- if ( $active ) {
215
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
216
- $partial_cache_flag = true;
217
- } else {
218
- $full_cache_flag = false;
219
- }
220
- }
221
- }
222
-
223
- if ( $partial_cache_flag && $full_cache_flag ) {
224
- echo '<td class="full-cache">';
225
- _e( 'full cache', self::DOMAIN );
226
- echo '</td>';
227
- } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
228
- echo '<td class="partial-cache">';
229
- _e( 'partial cache', self::DOMAIN );
230
- echo '</td>';
231
- } else {
232
- echo '<td class="no-cache">';
233
- _e( 'no cache', self::DOMAIN );
234
- echo '</td>';
235
- }
236
- }
237
-
238
- $full_cache_flag = true;
239
- $partial_cache_flag = false;
240
-
241
- foreach ( $share_base_cache_target as $sns => $active ) {
242
- if ( $active ) {
243
- $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
244
-
245
- $sns_count = get_post_meta( get_the_ID(), $meta_key, true );
246
-
247
- if ( isset( $sns_count ) && $sns_count !== '' && $sns_count >= 0 ) {
248
- $partial_cache_flag = true;
249
- } else {
250
- $full_cache_flag = false;
251
- }
252
- }
253
- }
254
-
255
- if ( $partial_cache_flag && $full_cache_flag ) {
256
- echo '<td class="full-cache">';
257
- _e( 'full cache', self::DOMAIN );
258
- echo '</td>';
259
- } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
260
- echo '<td class="partial-cache">';
261
- _e( 'partial cache', self::DOMAIN );
262
- echo '</td>';
263
- } else {
264
- echo '<td class="no-cache">';
265
- _e( 'no cache', self::DOMAIN );
266
- echo '</td>';
267
- }
268
-
269
- if ( isset( $sns_counts[self::REF_CRAWL_DATE] ) ) {
270
- echo '<td class="full-cache">';
271
- echo esc_html( $sns_counts[self::REF_CRAWL_DATE] );
272
- echo '</td>';
273
- } else {
274
- $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( self::REF_CRAWL_DATE );
275
-
276
- $crawl_date = get_post_meta( get_the_ID(), $meta_key, true );
277
-
278
- if ( isset( $crawl_date ) && $crawl_date !== '' && $crawl_date !== '-1' ) {
279
- echo '<td class="full-cache">';
280
- echo esc_html( $crawl_date );
281
- echo '</td>';
282
- } else {
283
- echo '<td class="no-cache">';
284
- _e( 'no data', self::DOMAIN );
285
- echo '</td>';
286
- }
287
- }
288
-
289
- $nonce = wp_create_nonce( __FILE__ );
290
- $cache_url = esc_url( 'admin.php?page=scc-cache-status&action=cache&post_id=' . get_the_ID() . '&_wpnonce=' . $nonce . '&paged=' . $paged );
291
- ?>
292
- <td><a class="button button-small" href="<?php echo $cache_url ?>"><?php _e( 'Cache', self::DOMAIN ); ?></a></td>
293
- </tr>
294
- <?php
295
- ++$count;
296
- }
297
- }
298
- ?>
299
- </tbody>
300
- </table>
301
- <?php
302
- $this->pagination( $posts_query->max_num_pages, '', $paged, false );
303
-
304
- wp_reset_postdata();
305
- ?>
306
- </div>
307
- </div>
308
- </div>
309
- </div>
310
- </div>
1
+ <?php
2
+ /*
3
+ admin-cache-status.php
4
+
5
+ Description: Option page implementation
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
+
32
+ $posts_per_page = 50;
33
+
34
+ $paged = (int) 1;
35
+
36
+ if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 0 ) {
37
+ $paged = (int) $_GET['paged'];
38
+ } else {
39
+ $paged = (int) 1;
40
+ }
41
+
42
+ if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], __FILE__ ) ) {
43
+ if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
44
+ if ( isset( $_GET["action"] ) && $_GET["action"] === 'cache' ) {
45
+ if ( isset( $_GET["post_id"] ) ) {
46
+ $post_id = $_GET["post_id"];
47
+ $this->cache_engines[self::REF_SHARE_BASE]->direct_cache( $post_id, true );
48
+ //wp_safe_redirect( menu_page_url( 'scc-cache-status', false ) );
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ $query_args = array(
55
+ 'post_type' => $this->share_base_cache_post_types,
56
+ 'post_status' => 'publish',
57
+ 'posts_per_page' => $posts_per_page,
58
+ 'paged' => $paged,
59
+ 'update_post_term_cache' => false
60
+ );
61
+
62
+ $posts_query = new WP_Query( $query_args );
63
+ ?>
64
+ <div class="wrap">
65
+ <h2><a href="admin.php?page=scc-cache-status"><?php _e( 'SNS Count Cache', self::DOMAIN ); ?></a></h2>
66
+ <div class="sns-cnt-cache">
67
+ <h3 class="nav-tab-wrapper">
68
+ <a class="nav-tab" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ); ?></a>
69
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a>
70
+ <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
71
+ <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
72
+ <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
73
+ <?php } ?>
74
+ <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ); ?></a>
75
+ <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
76
+ </h3>
77
+ <div class="metabox-holder">
78
+ <div id="share-site-summary" class="postbox">
79
+ <div class="handlediv" title="Click to toggle"><br></div>
80
+ <h3 class="hndle"><span><?php _e( 'Cache Status', self::DOMAIN ); ?></span></h3>
81
+ <div class="inside">
82
+ <table class="view-table">
83
+ <thead>
84
+ <tr>
85
+ <th>No.</th>
86
+ <th><?php _e( 'Content', self::DOMAIN ); ?></th>
87
+ <th><?php _e( 'Primary Cache', self::DOMAIN ); ?></th>
88
+ <th><?php _e( 'Secondary Cache', self::DOMAIN ); ?></th>
89
+ <th><?php _e( 'Crawl Date', self::DOMAIN ); ?></th>
90
+ <th></th>
91
+ </tr>
92
+ </thead>
93
+ <tbody>
94
+ <?php
95
+ $count = ( $paged - 1 ) * $posts_per_page + 1;
96
+
97
+ $share_base_cache_target = $this->share_base_cache_target ;
98
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
99
+
100
+ if ( $paged === 1 ) {
101
+ ?>
102
+ <tr class="home">
103
+ <td><?php echo '-'; ?></td>
104
+ <td><a href="<?php echo esc_url( home_url( '/' ) ); ?>" target="_blank"><?php echo esc_html( home_url( '/' ) ); ?></a></td>
105
+ <?php
106
+ $share_base_cache_target = $this->share_base_cache_target ;
107
+
108
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
109
+
110
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
111
+
112
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
113
+ $full_cache_flag = true;
114
+ $partial_cache_flag = false;
115
+
116
+ foreach ( $share_base_cache_target as $sns => $active ) {
117
+ if ( $active ) {
118
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
119
+ $partial_cache_flag = true;
120
+ } else {
121
+ $full_cache_flag = false;
122
+ }
123
+ }
124
+ }
125
+
126
+ if ( $partial_cache_flag && $full_cache_flag ) {
127
+ echo '<td class="full-cache">';
128
+ _e( 'full cache', self::DOMAIN );
129
+ echo '</td>';
130
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
131
+ echo '<td class="partial-cache">';
132
+ _e( 'partial cache', self::DOMAIN );
133
+ echo '</td>';
134
+ } else {
135
+ echo '<td class="no-cache">';
136
+ _e( 'no cache', self::DOMAIN );
137
+ echo '</td>';
138
+ }
139
+ } else {
140
+ SCC_Common_Util::log( '[' . __METHOD__ . '] : no transient' );
141
+ echo '<td class="no-cache">';
142
+ _e( 'no cache', self::DOMAIN );
143
+ echo '</td>';
144
+ }
145
+
146
+ $full_cache_flag = true;
147
+ $partial_cache_flag = false;
148
+
149
+ $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
150
+
151
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
152
+ foreach ( $share_base_cache_target as $sns => $active ) {
153
+ if ( $active ) {
154
+ if ( $sns_counts[$sns] >= 0 ){
155
+ $partial_cache_flag = true;
156
+ } else {
157
+ $full_cache_flag = false;
158
+ }
159
+ }
160
+ }
161
+ } else {
162
+ $full_cache_flag = false;
163
+ }
164
+
165
+ if ( $partial_cache_flag && $full_cache_flag ) {
166
+ echo '<td class="full-cache">';
167
+ _e( 'full cache', self::DOMAIN );
168
+ echo '</td>';
169
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
170
+ echo '<td class="partial-cache">';
171
+ _e( 'partial cache', self::DOMAIN );
172
+ echo '</td>';
173
+ } else {
174
+ echo '<td class="no-cache">';
175
+ _e( 'no cache', self::DOMAIN );
176
+ echo '</td>';
177
+ }
178
+ if ( isset( $sns_counts[self::REF_CRAWL_DATE] ) && $sns_counts[self::REF_CRAWL_DATE] && $sns_counts[self::REF_CRAWL_DATE] !== -1 ) {
179
+ echo '<td class="full-cache">';
180
+ echo esc_html( $sns_counts[self::REF_CRAWL_DATE] );
181
+ echo '</td>';
182
+ } else {
183
+ echo '<td class="no-cache">';
184
+ _e( 'no data', self::DOMAIN );
185
+ echo '</td>';
186
+ }
187
+
188
+ $nonce = wp_create_nonce( __FILE__ );
189
+ $cache_url = esc_url( 'admin.php?page=scc-cache-status&action=cache&post_id=' . 'home' . '&_wpnonce=' . $nonce . '&paged=' . $paged );
190
+ ?>
191
+ <td><a class="button button-small" href="<?php echo $cache_url ?>"><?php _e( 'Cache', self::DOMAIN ); ?></a></td>
192
+ </tr>
193
+ <?php
194
+ }
195
+ if ( $posts_query->have_posts() ) {
196
+ while ( $posts_query->have_posts() ) {
197
+ $posts_query->the_post();
198
+ ?>
199
+ <tr>
200
+ <td><?php echo $count; ?></td>
201
+ <td><a href="<?php echo esc_url( get_permalink( get_the_ID() ) ); ?>" target="_blank"><?php echo esc_html( get_permalink( get_the_ID() ) ); ?></a></td>
202
+ <?php
203
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( get_the_ID() );
204
+
205
+ if ( false === ( $sns_counts = get_transient( $transient_id ) ) ) {
206
+ echo '<td class="no-cache">';
207
+ _e( 'no cache', self::DOMAIN );
208
+ echo '</td>';
209
+ } else {
210
+ $full_cache_flag = true;
211
+ $partial_cache_flag = false;
212
+
213
+ foreach ( $share_base_cache_target as $sns => $active ) {
214
+ if ( $active ) {
215
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
216
+ $partial_cache_flag = true;
217
+ } else {
218
+ $full_cache_flag = false;
219
+ }
220
+ }
221
+ }
222
+
223
+ if ( $partial_cache_flag && $full_cache_flag ) {
224
+ echo '<td class="full-cache">';
225
+ _e( 'full cache', self::DOMAIN );
226
+ echo '</td>';
227
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
228
+ echo '<td class="partial-cache">';
229
+ _e( 'partial cache', self::DOMAIN );
230
+ echo '</td>';
231
+ } else {
232
+ echo '<td class="no-cache">';
233
+ _e( 'no cache', self::DOMAIN );
234
+ echo '</td>';
235
+ }
236
+ }
237
+
238
+ $full_cache_flag = true;
239
+ $partial_cache_flag = false;
240
+
241
+ foreach ( $share_base_cache_target as $sns => $active ) {
242
+ if ( $active ) {
243
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
244
+
245
+ $sns_count = get_post_meta( get_the_ID(), $meta_key, true );
246
+
247
+ if ( isset( $sns_count ) && $sns_count !== '' && $sns_count >= 0 ) {
248
+ $partial_cache_flag = true;
249
+ } else {
250
+ $full_cache_flag = false;
251
+ }
252
+ }
253
+ }
254
+
255
+ if ( $partial_cache_flag && $full_cache_flag ) {
256
+ echo '<td class="full-cache">';
257
+ _e( 'full cache', self::DOMAIN );
258
+ echo '</td>';
259
+ } elseif ( $partial_cache_flag && ! $full_cache_flag ) {
260
+ echo '<td class="partial-cache">';
261
+ _e( 'partial cache', self::DOMAIN );
262
+ echo '</td>';
263
+ } else {
264
+ echo '<td class="no-cache">';
265
+ _e( 'no cache', self::DOMAIN );
266
+ echo '</td>';
267
+ }
268
+
269
+ if ( isset( $sns_counts[self::REF_CRAWL_DATE] ) ) {
270
+ echo '<td class="full-cache">';
271
+ echo esc_html( $sns_counts[self::REF_CRAWL_DATE] );
272
+ echo '</td>';
273
+ } else {
274
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( self::REF_CRAWL_DATE );
275
+
276
+ $crawl_date = get_post_meta( get_the_ID(), $meta_key, true );
277
+
278
+ if ( isset( $crawl_date ) && $crawl_date !== '' && $crawl_date !== '-1' ) {
279
+ echo '<td class="full-cache">';
280
+ echo esc_html( $crawl_date );
281
+ echo '</td>';
282
+ } else {
283
+ echo '<td class="no-cache">';
284
+ _e( 'no data', self::DOMAIN );
285
+ echo '</td>';
286
+ }
287
+ }
288
+
289
+ $nonce = wp_create_nonce( __FILE__ );
290
+ $cache_url = esc_url( 'admin.php?page=scc-cache-status&action=cache&post_id=' . get_the_ID() . '&_wpnonce=' . $nonce . '&paged=' . $paged );
291
+ ?>
292
+ <td><a class="button button-small" href="<?php echo $cache_url ?>"><?php _e( 'Cache', self::DOMAIN ); ?></a></td>
293
+ </tr>
294
+ <?php
295
+ ++$count;
296
+ }
297
+ }
298
+ ?>
299
+ </tbody>
300
+ </table>
301
+ <?php
302
+ $this->pagination( $posts_query->max_num_pages, '', $paged, false );
303
+
304
+ wp_reset_postdata();
305
+ ?>
306
+ </div>
307
+ </div>
308
+ </div>
309
+ </div>
310
+ </div>
includes/admin-dashboard-widget.php CHANGED
@@ -1,234 +1,237 @@
1
- <?php
2
- /*
3
- admin-dashboard-widget.php
4
-
5
- Description: Option page implementation
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
-
32
- $query_args = array(
33
- 'post_type' => $this->share_base_cache_post_types,
34
- 'post_status' => 'publish',
35
- 'nopaging' => true,
36
- 'update_post_term_cache' => false,
37
- 'update_post_meta_cache' => false
38
- );
39
-
40
- $site_query = new WP_Query( $query_args );
41
-
42
- ?>
43
- <div class="sns-cnt-cache">
44
- <div id="scc-dashboard-widget">
45
- <div id="site-summary-share-cache" class="site-summary activity-block">
46
- <h3><?php _e( 'Share', self::DOMAIN ); ?></h3>
47
- <h4><a href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a></h4>
48
- <table class="view-table">
49
- <thead>
50
- <tr>
51
- <th><?php _e( 'Cache Type', self::DOMAIN ); ?></th>
52
- <th><?php _e( 'Cache Progress', self::DOMAIN ); ?></th>
53
- <th><?php _e( 'Total Content', self::DOMAIN ); ?></th>
54
- <th><?php _e( 'State - Full Cache', self::DOMAIN ); ?></th>
55
- <th><?php _e( 'State - Partial Cache', self::DOMAIN ); ?></th>
56
- <th><?php _e( 'State - No Cache', self::DOMAIN ); ?></th>
57
- </tr>
58
- </thead>
59
- <tbody>
60
- <tr>
61
- <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
62
- <td>
63
- <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="spcs"></span>
64
- </td>
65
- <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spc'></span></td>
66
- <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spfcc'></span></td>
67
- <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sppcc'></span></td>
68
- <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spncc'></span></td>
69
- </tr>
70
- <tr>
71
- <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
72
- <td>
73
- <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="sscs"></span>
74
- </td>
75
- <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spc'></span></td>
76
- <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='ssfcc'></span></td>
77
- <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sspcc'></span></td>
78
- <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='ssncc'></span></td>
79
- </tr>
80
- </tbody>
81
- </table>
82
- <h4><a href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a></h4>
83
- <table class="view-table">
84
- <thead>
85
- <tr>
86
- <?php
87
- $share_base_cache_target = $this->share_base_cache_target ;
88
- unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
89
-
90
- foreach ( $share_base_cache_target as $sns => $active ){
91
- if ( $active ) {
92
- $sns_name = '';
93
-
94
- switch ( $sns ) {
95
- case self::REF_SHARE_TWITTER:
96
- $sns_name = __( 'Twitter', self::DOMAIN );
97
- break;
98
- case self::REF_SHARE_FACEBOOK:
99
- $sns_name = __( 'Facebook', self::DOMAIN );
100
- break;
101
- case self::REF_SHARE_GPLUS:
102
- $sns_name = __( 'Google+', self::DOMAIN );
103
- break;
104
- case self::REF_SHARE_POCKET:
105
- $sns_name = __( 'Pocket', self::DOMAIN );
106
- break;
107
- case self::REF_SHARE_HATEBU:
108
- $sns_name = __( 'Hatebu', self::DOMAIN );
109
- break;
110
- case self::REF_SHARE_PINTEREST:
111
- $sns_name = __( 'Pinterest', self::DOMAIN );
112
- break;
113
- case self::REF_SHARE_TOTAL:
114
- $sns_name = __( 'Total', self::DOMAIN );
115
- break;
116
- }
117
-
118
- echo '<th>' . esc_html( $sns_name ) . '</th>';
119
- }
120
- }
121
- ?>
122
- </tr>
123
- </thead>
124
- <tbody>
125
- <tr>
126
- <?php
127
- foreach ( $share_base_cache_target as $sns => $active ) {
128
- if ( $active ) {
129
- if ( $sns === self::REF_SHARE_GPLUS ){
130
- echo '<td class="share-count">';
131
- echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="sgplus"></span>';
132
- echo '</td>';
133
- } else {
134
- echo '<td class="share-count">';
135
- echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="s' . strtolower( $sns ) . '"></span>';
136
- echo '</td>';
137
- }
138
- }
139
- }
140
- ?>
141
- </tr>
142
- </tbody>
143
- </table>
144
- </div>
145
- <div id="site-summary-follow-cache" class="site-summary activity-block">
146
- <h3><?php _e( 'Follow', self::DOMAIN ); ?></h3>
147
- <h4><?php _e( 'Cache Status', self::DOMAIN ); ?></h4>
148
- <table class="view-table">
149
- <thead>
150
- <tr>
151
- <th><?php _e( 'Cache Type', self::DOMAIN ); ?></th>
152
- <th><?php _e( 'Cache Progress', self::DOMAIN ); ?></th>
153
- <th><?php _e( 'Total Content', self::DOMAIN ); ?></th>
154
- <th><?php _e( 'State - Full Cache', self::DOMAIN ); ?></th>
155
- <th><?php _e( 'State - Partial Cache', self::DOMAIN ); ?></th>
156
- <th><?php _e( 'State - No Cache', self::DOMAIN ); ?></th>
157
- </tr>
158
- </thead>
159
- <tbody>
160
- <tr>
161
- <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
162
- <td>
163
- <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="fpcs"></span>
164
- </td>
165
- <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpc'></span></td>
166
- <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpfcc'></span></td>
167
- <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fppcc'></span></td>
168
- <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpncc'></span></td>
169
- </tr>
170
- <tr>
171
- <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
172
- <td>
173
- <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="fscs"></span>
174
- </td>
175
- <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpc'></span></td>
176
- <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fsfcc'></span></td>
177
- <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fspcc'></span></td>
178
- <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fsncc'></span></td>
179
- </tr>
180
- </tbody>
181
- </table>
182
- <h4><?php _e( 'Follower Count', self::DOMAIN ); ?></h4>
183
- <table class="view-table">
184
- <thead>
185
- <tr>
186
- <?php
187
- $follow_base_cache_target = $this->follow_base_cache_target ;
188
- unset( $follow_base_cache_target[self::REF_CRAWL_DATE] );
189
-
190
- foreach ( $follow_base_cache_target as $sns => $active ){
191
- if ( $active ) {
192
- $sns_name = '';
193
-
194
- switch ( $sns ) {
195
- case self::REF_FOLLOW_TWITTER:
196
- $sns_name = __( 'Twitter', self::DOMAIN );
197
- break;
198
- case self::REF_FOLLOW_FACEBOOK:
199
- $sns_name = __( 'Facebook', self::DOMAIN );
200
- break;
201
- case self::REF_FOLLOW_FEEDLY:
202
- $sns_name = __( 'Feedly', self::DOMAIN );
203
- break;
204
- case self::REF_FOLLOW_INSTAGRAM:
205
- $sns_name = __( 'Instagram', self::DOMAIN );
206
- break;
207
- case self::REF_FOLLOW_PUSH7:
208
- $sns_name = __( 'Push7', self::DOMAIN );
209
- break;
210
- }
211
-
212
- echo '<th>' . esc_html( $sns_name ) . '</th>';
213
- }
214
- }
215
- ?>
216
- </tr>
217
- </thead>
218
- <tbody>
219
- <tr>
220
- <?php
221
- foreach ( $follow_base_cache_target as $sns => $active ) {
222
- if ( $active ) {
223
- echo '<td class="share-count">';
224
- echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="f' . strtolower( $sns ) . '"></span>';
225
- echo '</td>';
226
- }
227
- }
228
- ?>
229
- </tr>
230
- </tbody>
231
- </table>
232
- </div>
233
- </div>
234
- </div>
 
 
 
1
+ <?php
2
+ /*
3
+ admin-dashboard-widget.php
4
+
5
+ Description: Option page implementation
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
+
32
+ $query_args = array(
33
+ 'post_type' => $this->share_base_cache_post_types,
34
+ 'post_status' => 'publish',
35
+ 'nopaging' => true,
36
+ 'update_post_term_cache' => false,
37
+ 'update_post_meta_cache' => false
38
+ );
39
+
40
+ $site_query = new WP_Query( $query_args );
41
+
42
+ ?>
43
+ <div class="sns-cnt-cache">
44
+ <div id="scc-dashboard-widget">
45
+ <div id="site-summary-share-cache" class="site-summary activity-block">
46
+ <h3><?php _e( 'Share', self::DOMAIN ); ?></h3>
47
+ <h4><a href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a></h4>
48
+ <table class="view-table">
49
+ <thead>
50
+ <tr>
51
+ <th><?php _e( 'Cache Type', self::DOMAIN ); ?></th>
52
+ <th><?php _e( 'Cache Progress', self::DOMAIN ); ?></th>
53
+ <th><?php _e( 'Total Content', self::DOMAIN ); ?></th>
54
+ <th><?php _e( 'State - Full Cache', self::DOMAIN ); ?></th>
55
+ <th><?php _e( 'State - Partial Cache', self::DOMAIN ); ?></th>
56
+ <th><?php _e( 'State - No Cache', self::DOMAIN ); ?></th>
57
+ </tr>
58
+ </thead>
59
+ <tbody>
60
+ <tr>
61
+ <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
62
+ <td>
63
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="spcs"></span>
64
+ </td>
65
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spc'></span></td>
66
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spfcc'></span></td>
67
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sppcc'></span></td>
68
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spncc'></span></td>
69
+ </tr>
70
+ <tr>
71
+ <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
72
+ <td>
73
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="sscs"></span>
74
+ </td>
75
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spc'></span></td>
76
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='ssfcc'></span></td>
77
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sspcc'></span></td>
78
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='ssncc'></span></td>
79
+ </tr>
80
+ </tbody>
81
+ </table>
82
+ <h4><a href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a></h4>
83
+ <table class="view-table">
84
+ <thead>
85
+ <tr>
86
+ <?php
87
+ $share_base_cache_target = $this->share_base_cache_target ;
88
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
89
+
90
+ foreach ( $share_base_cache_target as $sns => $active ){
91
+ if ( $active ) {
92
+ $sns_name = '';
93
+
94
+ switch ( $sns ) {
95
+ case self::REF_SHARE_TWITTER:
96
+ $sns_name = __( 'Twitter', self::DOMAIN );
97
+ break;
98
+ case self::REF_SHARE_FACEBOOK:
99
+ $sns_name = __( 'Facebook', self::DOMAIN );
100
+ break;
101
+ case self::REF_SHARE_GPLUS:
102
+ $sns_name = __( 'Google+', self::DOMAIN );
103
+ break;
104
+ case self::REF_SHARE_POCKET:
105
+ $sns_name = __( 'Pocket', self::DOMAIN );
106
+ break;
107
+ case self::REF_SHARE_HATEBU:
108
+ $sns_name = __( 'Hatebu', self::DOMAIN );
109
+ break;
110
+ case self::REF_SHARE_PINTEREST:
111
+ $sns_name = __( 'Pinterest', self::DOMAIN );
112
+ break;
113
+ case self::REF_SHARE_LINKEDIN:
114
+ $sns_name = __( 'Linkedin', self::DOMAIN );
115
+ break;
116
+ case self::REF_SHARE_TOTAL:
117
+ $sns_name = __( 'Total', self::DOMAIN );
118
+ break;
119
+ }
120
+
121
+ echo '<th>' . esc_html( $sns_name ) . '</th>';
122
+ }
123
+ }
124
+ ?>
125
+ </tr>
126
+ </thead>
127
+ <tbody>
128
+ <tr>
129
+ <?php
130
+ foreach ( $share_base_cache_target as $sns => $active ) {
131
+ if ( $active ) {
132
+ if ( $sns === self::REF_SHARE_GPLUS ){
133
+ echo '<td class="share-count">';
134
+ echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="sgplus"></span>';
135
+ echo '</td>';
136
+ } else {
137
+ echo '<td class="share-count">';
138
+ echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="s' . strtolower( $sns ) . '"></span>';
139
+ echo '</td>';
140
+ }
141
+ }
142
+ }
143
+ ?>
144
+ </tr>
145
+ </tbody>
146
+ </table>
147
+ </div>
148
+ <div id="site-summary-follow-cache" class="site-summary activity-block">
149
+ <h3><?php _e( 'Follow', self::DOMAIN ); ?></h3>
150
+ <h4><?php _e( 'Cache Status', self::DOMAIN ); ?></h4>
151
+ <table class="view-table">
152
+ <thead>
153
+ <tr>
154
+ <th><?php _e( 'Cache Type', self::DOMAIN ); ?></th>
155
+ <th><?php _e( 'Cache Progress', self::DOMAIN ); ?></th>
156
+ <th><?php _e( 'Total Content', self::DOMAIN ); ?></th>
157
+ <th><?php _e( 'State - Full Cache', self::DOMAIN ); ?></th>
158
+ <th><?php _e( 'State - Partial Cache', self::DOMAIN ); ?></th>
159
+ <th><?php _e( 'State - No Cache', self::DOMAIN ); ?></th>
160
+ </tr>
161
+ </thead>
162
+ <tbody>
163
+ <tr>
164
+ <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
165
+ <td>
166
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="fpcs"></span>
167
+ </td>
168
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpc'></span></td>
169
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpfcc'></span></td>
170
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fppcc'></span></td>
171
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpncc'></span></td>
172
+ </tr>
173
+ <tr>
174
+ <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
175
+ <td>
176
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="fscs"></span>
177
+ </td>
178
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpc'></span></td>
179
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fsfcc'></span></td>
180
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fspcc'></span></td>
181
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fsncc'></span></td>
182
+ </tr>
183
+ </tbody>
184
+ </table>
185
+ <h4><?php _e( 'Follower Count', self::DOMAIN ); ?></h4>
186
+ <table class="view-table">
187
+ <thead>
188
+ <tr>
189
+ <?php
190
+ $follow_base_cache_target = $this->follow_base_cache_target ;
191
+ unset( $follow_base_cache_target[self::REF_CRAWL_DATE] );
192
+
193
+ foreach ( $follow_base_cache_target as $sns => $active ){
194
+ if ( $active ) {
195
+ $sns_name = '';
196
+
197
+ switch ( $sns ) {
198
+ case self::REF_FOLLOW_TWITTER:
199
+ $sns_name = __( 'Twitter', self::DOMAIN );
200
+ break;
201
+ case self::REF_FOLLOW_FACEBOOK:
202
+ $sns_name = __( 'Facebook', self::DOMAIN );
203
+ break;
204
+ case self::REF_FOLLOW_FEEDLY:
205
+ $sns_name = __( 'Feedly', self::DOMAIN );
206
+ break;
207
+ case self::REF_FOLLOW_INSTAGRAM:
208
+ $sns_name = __( 'Instagram', self::DOMAIN );
209
+ break;
210
+ case self::REF_FOLLOW_PUSH7:
211
+ $sns_name = __( 'Push7', self::DOMAIN );
212
+ break;
213
+ }
214
+
215
+ echo '<th>' . esc_html( $sns_name ) . '</th>';
216
+ }
217
+ }
218
+ ?>
219
+ </tr>
220
+ </thead>
221
+ <tbody>
222
+ <tr>
223
+ <?php
224
+ foreach ( $follow_base_cache_target as $sns => $active ) {
225
+ if ( $active ) {
226
+ echo '<td class="share-count">';
227
+ echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="f' . strtolower( $sns ) . '"></span>';
228
+ echo '</td>';
229
+ }
230
+ }
231
+ ?>
232
+ </tr>
233
+ </tbody>
234
+ </table>
235
+ </div>
236
+ </div>
237
+ </div>
includes/admin-dashboard.php CHANGED
@@ -1,256 +1,259 @@
1
- <?php
2
- /*
3
- admin-dashboard.php
4
-
5
- Description: Option page implementation
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
-
32
- $query_args = array(
33
- 'post_type' => $this->share_base_cache_post_types,
34
- 'post_status' => 'publish',
35
- 'nopaging' => true,
36
- 'update_post_term_cache' => false,
37
- 'update_post_meta_cache' => false
38
- );
39
-
40
- $site_query = new WP_Query( $query_args );
41
- ?>
42
- <div class="wrap">
43
- <h2><a href="admin.php?page=scc-dashboard"><?php _e( 'SNS Count Cache', self::DOMAIN ); ?></a></h2>
44
- <div class="sns-cnt-cache">
45
- <div id="scc-dashboard">
46
- <h3 class="nav-tab-wrapper">
47
- <a class="nav-tab nav-tab-active" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ); ?></a>
48
- <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a>
49
- <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
50
- <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
51
- <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
52
- <?php } ?>
53
- <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ); ?></a>
54
- <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
55
- </h3>
56
- <div class="metabox-holder">
57
- <div id="site-summary-share-cache" class="site-summary postbox">
58
- <div class="handlediv" title="Click to toggle"><br></div>
59
- <h3 class="hndle"><span><?php _e( 'Share', self::DOMAIN ); ?></span></h3>
60
- <div class="inside">
61
- <h4><a href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a></h4>
62
- <table class="view-table">
63
- <thead>
64
- <tr>
65
- <th><?php _e( 'Cache Type', self::DOMAIN ); ?></th>
66
- <th><?php _e( 'Cache Progress', self::DOMAIN ); ?></th>
67
- <th><?php _e( 'Total Content', self::DOMAIN ); ?></th>
68
- <th><?php _e( 'State - Full Cache', self::DOMAIN ); ?></th>
69
- <th><?php _e( 'State - Partial Cache', self::DOMAIN ); ?></th>
70
- <th><?php _e( 'State - No Cache', self::DOMAIN ); ?></th>
71
- </tr>
72
- </thead>
73
- <tbody>
74
- <tr>
75
- <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
76
- <td>
77
- <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="spcs"></span>
78
- </td>
79
- <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spc'></span></td>
80
- <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spfcc'></span></td>
81
- <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sppcc'></span></td>
82
- <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spncc'></span></td>
83
- </tr>
84
- <tr>
85
- <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
86
- <td>
87
- <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="sscs"></span>
88
- </td>
89
- <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spc'></span></td>
90
- <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='ssfcc'></span></td>
91
- <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sspcc'></span></td>
92
- <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='ssncc'></span></td>
93
- </tr>
94
- </tbody>
95
- </table>
96
- <h4><a href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a></h4>
97
- <table class="view-table">
98
- <thead>
99
- <tr>
100
- <?php
101
- $share_base_cache_target = $this->share_base_cache_target ;
102
- unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
103
-
104
- foreach ( $share_base_cache_target as $sns => $active ){
105
- if ( $active ) {
106
- $sns_name = '';
107
-
108
- switch ( $sns ) {
109
- case self::REF_SHARE_TWITTER:
110
- $sns_name = __( 'Twitter', self::DOMAIN );
111
- break;
112
- case self::REF_SHARE_FACEBOOK:
113
- $sns_name = __( 'Facebook', self::DOMAIN );
114
- break;
115
- case self::REF_SHARE_GPLUS:
116
- $sns_name = __( 'Google+', self::DOMAIN );
117
- break;
118
- case self::REF_SHARE_POCKET:
119
- $sns_name = __( 'Pocket', self::DOMAIN );
120
- break;
121
- case self::REF_SHARE_HATEBU:
122
- $sns_name = __( 'Hatebu', self::DOMAIN );
123
- break;
124
- case self::REF_SHARE_PINTEREST:
125
- $sns_name = __( 'Pinterest', self::DOMAIN );
126
- break;
127
- case self::REF_SHARE_TOTAL:
128
- $sns_name = __( 'Total', self::DOMAIN );
129
- break;
130
- }
131
-
132
- echo '<th>' . esc_html( $sns_name ) . '</th>';
133
- }
134
- }
135
- ?>
136
- </tr>
137
- </thead>
138
- <tbody>
139
- <tr>
140
- <?php
141
- foreach ( $share_base_cache_target as $sns => $active ) {
142
- if ( $active ) {
143
- if ( $sns === self::REF_SHARE_GPLUS ){
144
- echo '<td class="share-count">';
145
- echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="sgplus"></span>';
146
- echo '</td>';
147
- } else {
148
- echo '<td class="share-count">';
149
- echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="s' . strtolower( $sns ) . '"></span>';
150
- echo '</td>';
151
- }
152
- }
153
- }
154
- ?>
155
- </tr>
156
- </tbody>
157
- </table>
158
- </div>
159
- </div>
160
- </div>
161
- <div class="metabox-holder">
162
- <div id="site-summary-follow-cache" class="site-summary postbox">
163
- <div class="handlediv" title="Click to toggle"><br></div>
164
- <h3 class="hndle"><span><?php _e( 'Follow', self::DOMAIN ); ?></span></h3>
165
- <div class="inside">
166
- <h4><?php _e( 'Cache Status', self::DOMAIN ); ?></h4>
167
- <table class="view-table">
168
- <thead>
169
- <tr>
170
- <th><?php _e( 'Cache Type', self::DOMAIN ); ?></th>
171
- <th><?php _e( 'Cache Progress', self::DOMAIN ); ?></th>
172
- <th><?php _e( 'Total Content', self::DOMAIN ); ?></th>
173
- <th><?php _e( 'State - Full Cache', self::DOMAIN ); ?></th>
174
- <th><?php _e( 'State - Partial Cache', self::DOMAIN ); ?></th>
175
- <th><?php _e( 'State - No Cache', self::DOMAIN ); ?></th>
176
- </tr>
177
- </thead>
178
- <tbody>
179
- <tr>
180
- <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
181
- <td>
182
- <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="fpcs"></span>
183
- </td>
184
- <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpc'></span></td>
185
- <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpfcc'></span></td>
186
- <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fppcc'></span></td>
187
- <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpncc'></span></td>
188
- </tr>
189
- <tr>
190
- <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
191
- <td>
192
- <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="fscs"></span>
193
- </td>
194
- <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpc'></span></td>
195
- <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fsfcc'></span></td>
196
- <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fspcc'></span></td>
197
- <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fsncc'></span></td>
198
- </tr>
199
- </tbody>
200
- </table>
201
- <h4><?php _e( 'Follow Count', self::DOMAIN ); ?></h4>
202
- <table class="view-table">
203
- <thead>
204
- <tr>
205
- <?php
206
- $follow_base_cache_target = $this->follow_base_cache_target ;
207
- unset( $follow_base_cache_target[self::REF_CRAWL_DATE] );
208
-
209
- foreach ( $follow_base_cache_target as $sns => $active ){
210
- if ( $active ) {
211
- $sns_name = '';
212
-
213
- switch ( $sns ) {
214
- case self::REF_FOLLOW_TWITTER:
215
- $sns_name = __( 'Twitter', self::DOMAIN );
216
- break;
217
- case self::REF_FOLLOW_FACEBOOK:
218
- $sns_name = __( 'Facebook', self::DOMAIN );
219
- break;
220
- case self::REF_FOLLOW_FEEDLY:
221
- $sns_name = __( 'Feedly', self::DOMAIN );
222
- break;
223
- case self::REF_FOLLOW_INSTAGRAM:
224
- $sns_name = __( 'Instagram', self::DOMAIN );
225
- break;
226
- case self::REF_FOLLOW_PUSH7:
227
- $sns_name = __( 'Push7', self::DOMAIN );
228
- break;
229
- }
230
-
231
- echo '<th>' . esc_html( $sns_name ) . '</th>';
232
- }
233
- }
234
- ?>
235
- </tr>
236
- </thead>
237
- <tbody>
238
- <tr>
239
- <?php
240
- foreach ( $follow_base_cache_target as $sns => $active ) {
241
- if ( $active ) {
242
- echo '<td class="share-count">';
243
- echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="f' . strtolower( $sns ) . '"></span>';
244
- echo '</td>';
245
- }
246
- }
247
- ?>
248
- </tr>
249
- </tbody>
250
- </table>
251
- </div>
252
- </div>
253
- </div>
254
- </div>
255
- </div>
256
- </div>
 
 
 
1
+ <?php
2
+ /*
3
+ admin-dashboard.php
4
+
5
+ Description: Option page implementation
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
+
32
+ $query_args = array(
33
+ 'post_type' => $this->share_base_cache_post_types,
34
+ 'post_status' => 'publish',
35
+ 'nopaging' => true,
36
+ 'update_post_term_cache' => false,
37
+ 'update_post_meta_cache' => false
38
+ );
39
+
40
+ $site_query = new WP_Query( $query_args );
41
+ ?>
42
+ <div class="wrap">
43
+ <h2><a href="admin.php?page=scc-dashboard"><?php _e( 'SNS Count Cache', self::DOMAIN ); ?></a></h2>
44
+ <div class="sns-cnt-cache">
45
+ <div id="scc-dashboard">
46
+ <h3 class="nav-tab-wrapper">
47
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ); ?></a>
48
+ <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a>
49
+ <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
50
+ <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
51
+ <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
52
+ <?php } ?>
53
+ <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ); ?></a>
54
+ <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
55
+ </h3>
56
+ <div class="metabox-holder">
57
+ <div id="site-summary-share-cache" class="site-summary postbox">
58
+ <div class="handlediv" title="Click to toggle"><br></div>
59
+ <h3 class="hndle"><span><?php _e( 'Share', self::DOMAIN ); ?></span></h3>
60
+ <div class="inside">
61
+ <h4><a href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a></h4>
62
+ <table class="view-table">
63
+ <thead>
64
+ <tr>
65
+ <th><?php _e( 'Cache Type', self::DOMAIN ); ?></th>
66
+ <th><?php _e( 'Cache Progress', self::DOMAIN ); ?></th>
67
+ <th><?php _e( 'Total Content', self::DOMAIN ); ?></th>
68
+ <th><?php _e( 'State - Full Cache', self::DOMAIN ); ?></th>
69
+ <th><?php _e( 'State - Partial Cache', self::DOMAIN ); ?></th>
70
+ <th><?php _e( 'State - No Cache', self::DOMAIN ); ?></th>
71
+ </tr>
72
+ </thead>
73
+ <tbody>
74
+ <tr>
75
+ <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
76
+ <td>
77
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="spcs"></span>
78
+ </td>
79
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spc'></span></td>
80
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spfcc'></span></td>
81
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sppcc'></span></td>
82
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spncc'></span></td>
83
+ </tr>
84
+ <tr>
85
+ <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
86
+ <td>
87
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="sscs"></span>
88
+ </td>
89
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='spc'></span></td>
90
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='ssfcc'></span></td>
91
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='sspcc'></span></td>
92
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='ssncc'></span></td>
93
+ </tr>
94
+ </tbody>
95
+ </table>
96
+ <h4><a href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a></h4>
97
+ <table class="view-table">
98
+ <thead>
99
+ <tr>
100
+ <?php
101
+ $share_base_cache_target = $this->share_base_cache_target ;
102
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
103
+
104
+ foreach ( $share_base_cache_target as $sns => $active ){
105
+ if ( $active ) {
106
+ $sns_name = '';
107
+
108
+ switch ( $sns ) {
109
+ case self::REF_SHARE_TWITTER:
110
+ $sns_name = __( 'Twitter', self::DOMAIN );
111
+ break;
112
+ case self::REF_SHARE_FACEBOOK:
113
+ $sns_name = __( 'Facebook', self::DOMAIN );
114
+ break;
115
+ case self::REF_SHARE_GPLUS:
116
+ $sns_name = __( 'Google+', self::DOMAIN );
117
+ break;
118
+ case self::REF_SHARE_POCKET:
119
+ $sns_name = __( 'Pocket', self::DOMAIN );
120
+ break;
121
+ case self::REF_SHARE_HATEBU:
122
+ $sns_name = __( 'Hatebu', self::DOMAIN );
123
+ break;
124
+ case self::REF_SHARE_PINTEREST:
125
+ $sns_name = __( 'Pinterest', self::DOMAIN );
126
+ break;
127
+ case self::REF_SHARE_LINKEDIN:
128
+ $sns_name = __( 'Linkedin', self::DOMAIN );
129
+ break;
130
+ case self::REF_SHARE_TOTAL:
131
+ $sns_name = __( 'Total', self::DOMAIN );
132
+ break;
133
+ }
134
+
135
+ echo '<th>' . esc_html( $sns_name ) . '</th>';
136
+ }
137
+ }
138
+ ?>
139
+ </tr>
140
+ </thead>
141
+ <tbody>
142
+ <tr>
143
+ <?php
144
+ foreach ( $share_base_cache_target as $sns => $active ) {
145
+ if ( $active ) {
146
+ if ( $sns === self::REF_SHARE_GPLUS ){
147
+ echo '<td class="share-count">';
148
+ echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="sgplus"></span>';
149
+ echo '</td>';
150
+ } else {
151
+ echo '<td class="share-count">';
152
+ echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="s' . strtolower( $sns ) . '"></span>';
153
+ echo '</td>';
154
+ }
155
+ }
156
+ }
157
+ ?>
158
+ </tr>
159
+ </tbody>
160
+ </table>
161
+ </div>
162
+ </div>
163
+ </div>
164
+ <div class="metabox-holder">
165
+ <div id="site-summary-follow-cache" class="site-summary postbox">
166
+ <div class="handlediv" title="Click to toggle"><br></div>
167
+ <h3 class="hndle"><span><?php _e( 'Follow', self::DOMAIN ); ?></span></h3>
168
+ <div class="inside">
169
+ <h4><?php _e( 'Cache Status', self::DOMAIN ); ?></h4>
170
+ <table class="view-table">
171
+ <thead>
172
+ <tr>
173
+ <th><?php _e( 'Cache Type', self::DOMAIN ); ?></th>
174
+ <th><?php _e( 'Cache Progress', self::DOMAIN ); ?></th>
175
+ <th><?php _e( 'Total Content', self::DOMAIN ); ?></th>
176
+ <th><?php _e( 'State - Full Cache', self::DOMAIN ); ?></th>
177
+ <th><?php _e( 'State - Partial Cache', self::DOMAIN ); ?></th>
178
+ <th><?php _e( 'State - No Cache', self::DOMAIN ); ?></th>
179
+ </tr>
180
+ </thead>
181
+ <tbody>
182
+ <tr>
183
+ <td><?php _e( 'Primary Cache', self::DOMAIN ); ?></td>
184
+ <td>
185
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="fpcs"></span>
186
+ </td>
187
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpc'></span></td>
188
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpfcc'></span></td>
189
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fppcc'></span></td>
190
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpncc'></span></td>
191
+ </tr>
192
+ <tr>
193
+ <td><?php _e( 'Secondary Cache', self::DOMAIN ); ?></td>
194
+ <td>
195
+ <img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc="fscs"></span>
196
+ </td>
197
+ <td class="share-count"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fpc'></span></td>
198
+ <td class="share-count full-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fsfcc'></span></td>
199
+ <td class="share-count partial-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fspcc'></span></td>
200
+ <td class="share-count no-cache"><img class="loading" src="<?php echo $this->loading_img_url; ?>" /><span data-scc='fsncc'></span></td>
201
+ </tr>
202
+ </tbody>
203
+ </table>
204
+ <h4><?php _e( 'Follower Count', self::DOMAIN ); ?></h4>
205
+ <table class="view-table">
206
+ <thead>
207
+ <tr>
208
+ <?php
209
+ $follow_base_cache_target = $this->follow_base_cache_target ;
210
+ unset( $follow_base_cache_target[self::REF_CRAWL_DATE] );
211
+
212
+ foreach ( $follow_base_cache_target as $sns => $active ){
213
+ if ( $active ) {
214
+ $sns_name = '';
215
+
216
+ switch ( $sns ) {
217
+ case self::REF_FOLLOW_TWITTER:
218
+ $sns_name = __( 'Twitter', self::DOMAIN );
219
+ break;
220
+ case self::REF_FOLLOW_FACEBOOK:
221
+ $sns_name = __( 'Facebook', self::DOMAIN );
222
+ break;
223
+ case self::REF_FOLLOW_FEEDLY:
224
+ $sns_name = __( 'Feedly', self::DOMAIN );
225
+ break;
226
+ case self::REF_FOLLOW_INSTAGRAM:
227
+ $sns_name = __( 'Instagram', self::DOMAIN );
228
+ break;
229
+ case self::REF_FOLLOW_PUSH7:
230
+ $sns_name = __( 'Push7', self::DOMAIN );
231
+ break;
232
+ }
233
+
234
+ echo '<th>' . esc_html( $sns_name ) . '</th>';
235
+ }
236
+ }
237
+ ?>
238
+ </tr>
239
+ </thead>
240
+ <tbody>
241
+ <tr>
242
+ <?php
243
+ foreach ( $follow_base_cache_target as $sns => $active ) {
244
+ if ( $active ) {
245
+ echo '<td class="share-count">';
246
+ echo '<img class="loading" src="' . $this->loading_img_url . '" /><span data-scc="f' . strtolower( $sns ) . '"></span>';
247
+ echo '</td>';
248
+ }
249
+ }
250
+ ?>
251
+ </tr>
252
+ </tbody>
253
+ </table>
254
+ </div>
255
+ </div>
256
+ </div>
257
+ </div>
258
+ </div>
259
+ </div>
includes/admin-help.php CHANGED
@@ -1,206 +1,211 @@
1
- <?php
2
- /*
3
- admin-help.php
4
-
5
- Description: Option page implementation
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
- ?>
32
-
33
- <div class="wrap">
34
- <h2><a href="admin.php?page=scc-help"><?php _e( 'SNS Count Cache', self::DOMAIN ); ?></a></h2>
35
- <div class="sns-cnt-cache">
36
- <h3 class="nav-tab-wrapper">
37
- <a class="nav-tab" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ); ?></a>
38
- <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a>
39
- <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
40
- <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
41
- <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
42
- <?php } ?>
43
- <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ) ?></a>
44
- <a class="nav-tab nav-tab-active" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
45
- </h3>
46
- <div class="metabox-holder">
47
- <div id="share-site-summary" class="postbox">
48
- <div class="handlediv" title="Click to toggle"><br></div>
49
- <h3 class="hndle"><span><?php _e( 'Help', self::DOMAIN ); ?></span></h3>
50
- <div class="inside">
51
- <h4><?php _e( 'What is WordPress plugin SNS Cout Cache?', self::DOMAIN ); ?></h4>
52
- <p><?php _e( 'WordPress plugin SNS Count Cache is a plugin which helps you to shorten page loading time when your site displays share and follower counts. This plugin gets share counts such as Twitter and Facebook, Google+, Pocket, Pinterest and caches these counts in the background. This plugin alse caches follower counts such as Twitter and Facebook, Feedly, Instagram, Push7 in the same way. The share and follower counts can be retrieved quickly not through network but through the cache using given functions.', self::DOMAIN ); ?></p>
53
- <h4><?php _e( 'How often does this plugin get and cache share counts?', self::DOMAIN ); ?></h4>
54
- <p><?php _e( 'Although this plugin gets share count of 20 posts at a time every 10 minutes by default, you can modify the setting in the "Setting" tab in the administration page.', self::DOMAIN ); ?></p>
55
- <h4><?php _e( 'How can I know whether share count of each post is cached or not?', self::DOMAIN ); ?></h4>
56
- <p><?php _e( 'Cache status is described in the "Cache Status" tab in the administration page.', self::DOMAIN ); ?></p>
57
- <h4><?php _e( 'How often does this plugin get and cache follower counts?', self::DOMAIN ); ?></h4>
58
- <p><?php _e( 'Although this plugin gets follower count once a day by default, you can modify the setting in the "Setting" tab in the administration page.', self::DOMAIN ); ?></p>
59
- <h4><?php _e( 'What is cache status such as "full cache", "partial cache" and "no cache"?', self::DOMAIN ); ?></h4>
60
- <p><?php _e( 'The following is the explanation of the cache status.', self::DOMAIN ); ?></p>
61
- <table class="view-table">
62
- <thead>
63
- <tr>
64
- <th><?php _e( 'Cache Status', self::DOMAIN ); ?></th>
65
- <th><?php _e( 'Description', self::DOMAIN ); ?></th>
66
- </tr>
67
- </thead>
68
- <tbody>
69
- <tr><td><?php _e( 'full cache', self::DOMAIN ); ?></td><td><?php _e( 'Counts for selected all SNS are cached.', self::DOMAIN ); ?></td></tr>
70
- <tr><td><?php _e( 'partial cache', self::DOMAIN ); ?></td><td><?php _e( 'A subset of counts for selected SNS are cached.', self::DOMAIN ); ?></td></tr>
71
- <tr><td><?php _e( 'no cache', self::DOMAIN ); ?></td><td><?php _e( 'Count for selected SNS are not cached at all.', self::DOMAIN ); ?></td></tr>
72
- </tbody>
73
- </table>
74
- <h4><?php _e( 'How can I get share count from the cache?', self::DOMAIN ); ?></h4>
75
- <p><?php _e( 'The share count is retrieved from the cache using the following functions in the WordPress loop such as query_posts(), get_posts() and WP_Query().', self::DOMAIN ); ?></p>
76
- <table class="view-table">
77
- <thead>
78
- <tr>
79
- <th><?php _e( 'Function', self::DOMAIN ); ?></th>
80
- <th><?php _e( 'Description', self::DOMAIN ); ?></th>
81
- </tr>
82
- </thead>
83
- <tbody>
84
- <tr><td>scc_get_share_twitter()</td><td><?php _e( 'Twitter share count is returned from cache.', self::DOMAIN ); ?></td></tr>
85
- <tr><td>scc_get_share_facebook()</td><td><?php _e( 'Facebook share count is returned from cache.', self::DOMAIN ); ?></td></tr>
86
- <tr><td>scc_get_share_gplus()</td><td><?php _e( 'Google Plus share count is returned from cache.', self::DOMAIN ); ?></td></tr>
87
- <tr><td>scc_get_share_hatebu()</td><td><?php _e( 'Hatena Bookmark share count is returned from cache.', self::DOMAIN ); ?></td></tr>
88
- <tr><td>scc_get_share_pocket()</td><td><?php _e( 'Pocket share count is returned from cache.', self::DOMAIN ); ?></td></tr>
89
- <tr><td>scc_get_share_pinterest()</td><td><?php _e( 'Pinterest share count is returned from cache.', self::DOMAIN ); ?></td></tr>
90
- <tr><td>scc_get_share_total()</td><td><?php _e( 'Total share count of selected SNS is returned from cache.', self::DOMAIN ); ?></td></tr>
91
- </tbody>
92
- </table>
93
- <h4><?php _e( 'How can I get follower count from the cache?', self::DOMAIN ); ?></h4>
94
- <p><?php _e( 'The follower count is retrieved from the cache using the following functions.', self::DOMAIN ); ?></p>
95
- <table class="view-table">
96
- <thead>
97
- <tr>
98
- <th><?php _e( 'Function', self::DOMAIN ); ?></th>
99
- <th><?php _e( 'Description', self::DOMAIN ); ?></th>
100
- </tr>
101
- </thead>
102
- <tbody>
103
- <tr><td>scc_get_follow_feedly()</td><td><?php _e( 'Feedly follower count is returned from cache.', self::DOMAIN ); ?></td></tr>
104
- <tr><td>scc_get_follow_twitter()</td><td><?php _e( 'Twitter follower count is returned from cache.', self::DOMAIN ); ?></td></tr>
105
- <tr><td>scc_get_follow_facebook()</td><td><?php _e( 'Facebook follower count is returned from cache.', self::DOMAIN ); ?></td></tr>
106
- <tr><td>scc_get_follow_instagram()</td><td><?php _e( 'Instagram follower count is returned from cache.', self::DOMAIN ); ?></td></tr>
107
- <tr><td>scc_get_follow_push7()</td><td><?php _e( 'Push7 follower count is returned from cache.', self::DOMAIN ); ?></td></tr>
108
- </tbody>
109
- </table>
110
- <h4><?php _e( 'Example Code', self::DOMAIN ); ?></h4>
111
- <?php _e( 'The code below describes a simple example which displays share count and follower count using the above functions.', self::DOMAIN ); ?>
112
- <pre><code class="php">
113
- &lt;?php
114
- $query_args = array(
115
- &#039;post_type&#039; =&gt; &#039;post&#039;,
116
- &#039;post_status&#039; =&gt; &#039;publish&#039;,
117
- &#039;posts_per_page&#039; =&gt; 5
118
- );
119
-
120
- $posts_query = new WP_Query( $query_args );
121
-
122
- if ( $posts_query-&gt;have_posts() ) {
123
- while ( $posts_query-&gt;have_posts() ){
124
- $posts_query-&gt;the_post();
125
-
126
- echo &#039;&lt;div&gt;Article Title: &#039; . esc_html( get_the_title( $posts_query-&gt;ID ) ) . &#039;&lt;/div&gt;&#039;;
127
-
128
- if ( function_exists( &#039;scc_get_share_twitter&#039; ) &amp;&amp;
129
- function_exists( &#039;scc_get_share_facebook&#039; ) &amp;&amp;
130
- function_exists( &#039;scc_get_share_gplus&#039; ) &amp;&amp;
131
- function_exists( &#039;scc_get_share_pocket&#039; ) &amp;&amp;
132
- function_exists( &#039;scc_get_share_pinterest&#039; ) &amp;&amp;
133
- function_exists( &#039;scc_get_share_total&#039; )
134
- ) {
135
- // In WordPress loop, you can use the given function
136
- // in order to get share count for current post and follower count.
137
- echo &#039;&lt;div&gt;Twitter share count: &#039; . scc_get_share_twitter() . &#039;&lt;/div&gt;&#039;;
138
- echo &#039;&lt;div&gt;Facebook share count: &#039; . scc_get_share_facebook() . &#039;&lt;/div&gt;&#039;;
139
- echo &#039;&lt;div&gt;Google+ share count: &#039; . scc_get_share_gplus() . &#039;&lt;/div&gt;&#039;;
140
- echo &#039;&lt;div&gt;Pocket share count: &#039; . scc_get_share_pocket() . &#039;&lt;/div&gt;&#039;;
141
- echo &#039;&lt;div&gt;Pinterest share count: &#039; . scc_get_share_pinterest() . &#039;&lt;/div&gt;&#039;;
142
- echo &#039;&lt;div&gt;Total of share count: &#039; . scc_get_share_total() . &#039;&lt;/div&gt;&#039;;
143
- }
144
- }
145
- wp_reset_postdata();
146
- }
147
-
148
- if ( function_exists( &#039;scc_get_follow_feedly&#039; ) &amp;&amp;
149
- function_exists( &#039;scc_get_follow_twitter&#039; ) &amp;&amp;
150
- function_exists( &#039;scc_get_follow_facebook&#039; ) &amp;&amp;
151
- function_exists( &#039;scc_get_follow_instagram&#039; ) &amp;&amp;
152
- function_exists( &#039;scc_get_follow_push7&#039; )
153
- ) {
154
- // You can use the given function in order to get follower count.
155
- echo &#039;&lt;div&gt;Feedly follower count: &#039; . scc_get_follow_feedly() . &#039;&lt;/div&gt;&#039;;
156
- echo &#039;&lt;div&gt;Twitter follower count: &#039; . scc_get_follow_twitter() . &#039;&lt;/div&gt;&#039;;
157
- echo &#039;&lt;div&gt;Facebook follower count: &#039; . scc_get_follow_facebook() . &#039;&lt;/div&gt;&#039;;
158
- echo &#039;&lt;div&gt;Instagram follower count: &#039; . scc_get_follow_instagram() . &#039;&lt;/div&gt;&#039;;
159
- echo &#039;&lt;div&gt;Push7 follower count: &#039; . scc_get_follow_push7() . &#039;&lt;/div&gt;&#039;;
160
- }
161
- ?&gt;
162
- </code></pre>
163
- <script>hljs.initHighlightingOnLoad();</script>
164
- <h4><?php _e( 'How can I access specific custom field containing each share count?', self::DOMAIN ); ?></h4>
165
- <p><?php _e( 'Custom fields including share count are accessed using the following meta keys.', self::DOMAIN ); ?></p>
166
- <table class="view-table">
167
- <thead>
168
- <tr>
169
- <th><?php _e( 'Meta Key', self::DOMAIN ); ?></th>
170
- <th><?php _e( 'Description', self::DOMAIN ); ?></th>
171
- </tr>
172
- </thead>
173
- <tbody>
174
- <tr><td>scc_share_count_twitter</td><td><?php _e( 'A meta key to access Twitter share count', self::DOMAIN ); ?></td></tr>
175
- <tr><td>scc_share_count_facebook</td><td><?php _e( 'A meta key to access Facebook share count', self::DOMAIN ); ?></td></tr>
176
- <tr><td>scc_share_count_google+</td><td><?php _e( 'A meta key to access Google+ share count', self::DOMAIN ); ?></td></tr>
177
- <tr><td>scc_share_count_hatebu</td><td><?php _e( 'A meta key to access Hatena Bookmark share count', self::DOMAIN ); ?></td></tr>
178
- <tr><td>scc_share_count_pocket</td><td><?php _e( 'A meta key to access Pocket share count', self::DOMAIN ); ?></td></tr>
179
- <tr><td>scc_share_count_pinterest</td><td><?php _e( 'A meta key to access Pinterest share count', self::DOMAIN ); ?></td></tr>
180
- <tr><td>scc_share_count_total</td><td><?php _e( 'A meta key to access total share count', self::DOMAIN ); ?></td></tr>
181
- </tbody>
182
- </table>
183
- <h4><?php _e( 'How can I access specific custom field containing each variation of share count?', self::DOMAIN ); ?></h4>
184
- <p><?php _e( 'Custom fields including variation of share count are accessed using the following meta keys.', self::DOMAIN ); ?></p>
185
- <table class="view-table">
186
- <thead>
187
- <tr>
188
- <th><?php _e( 'Meta Key', self::DOMAIN ); ?></th>
189
- <th><?php _e( 'Description', self::DOMAIN ); ?></th>
190
- </tr>
191
- </thead>
192
- <tbody>
193
- <tr><td>scc_share_delta_twitter</td><td><?php _e( 'A meta key to access variation of Twitter share count', self::DOMAIN ); ?></td></tr>
194
- <tr><td>scc_share_delta_facebook</td><td><?php _e( 'A meta key to access variation of Facebook share count', self::DOMAIN ); ?></td></tr>
195
- <tr><td>scc_share_delta_google+</td><td><?php _e( 'A meta key to access variation of Google+ share count', self::DOMAIN ); ?></td></tr>
196
- <tr><td>scc_share_delta_hatebu</td><td><?php _e( 'A meta key to access variation of Hatena Bookmark share count', self::DOMAIN ); ?></td></tr>
197
- <tr><td>scc_share_delta_pocket</td><td><?php _e( 'A meta key to access variation of Pocket share count', self::DOMAIN ); ?></td></tr>
198
- <tr><td>scc_share_delta_pinterest</td><td><?php _e( 'A meta key to access variation of Pinterest share count', self::DOMAIN ); ?></td></tr>
199
- <tr><td>scc_share_delta_total</td><td><?php _e( 'A meta key to access variation of total share count', self::DOMAIN ); ?></td></tr>
200
- </tbody>
201
- </table>
202
- </div>
203
- </div>
204
- </div>
205
- </div>
206
- </div>
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ admin-help.php
4
+
5
+ Description: Option page implementation
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
+ ?>
32
+
33
+ <div class="wrap">
34
+ <h2><a href="admin.php?page=scc-help"><?php _e( 'SNS Count Cache', self::DOMAIN ); ?></a></h2>
35
+ <div class="sns-cnt-cache">
36
+ <h3 class="nav-tab-wrapper">
37
+ <a class="nav-tab" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ); ?></a>
38
+ <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a>
39
+ <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
40
+ <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
41
+ <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
42
+ <?php } ?>
43
+ <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ) ?></a>
44
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
45
+ </h3>
46
+ <div class="metabox-holder">
47
+ <div id="share-site-summary" class="postbox">
48
+ <div class="handlediv" title="Click to toggle"><br></div>
49
+ <h3 class="hndle"><span><?php _e( 'Help', self::DOMAIN ); ?></span></h3>
50
+ <div class="inside">
51
+ <h4><?php _e( 'What is WordPress plugin SNS Cout Cache?', self::DOMAIN ); ?></h4>
52
+ <p><?php _e( 'WordPress plugin SNS Count Cache is a plugin which helps you to shorten page loading time when your site displays share and follower counts. This plugin gets share counts such as Twitter and Facebook, Google+, Pocket, Pinterest, Linkedin and caches these counts in the background. This plugin alse caches follower counts such as Twitter and Facebook, Feedly, Instagram, Push7 in the same way. The share and follower counts can be retrieved quickly not through network but through the cache using given functions.', self::DOMAIN ); ?></p>
53
+ <h4><?php _e( 'How often does this plugin get and cache share counts?', self::DOMAIN ); ?></h4>
54
+ <p><?php _e( 'Although this plugin gets share count of 20 posts at a time every 10 minutes by default, you can modify the setting in the "Setting" tab in the administration page.', self::DOMAIN ); ?></p>
55
+ <h4><?php _e( 'How can I know whether share count of each post is cached or not?', self::DOMAIN ); ?></h4>
56
+ <p><?php _e( 'Cache status is described in the "Cache Status" tab in the administration page.', self::DOMAIN ); ?></p>
57
+ <h4><?php _e( 'How often does this plugin get and cache follower counts?', self::DOMAIN ); ?></h4>
58
+ <p><?php _e( 'Although this plugin gets follower count once a day by default, you can modify the setting in the "Setting" tab in the administration page.', self::DOMAIN ); ?></p>
59
+ <h4><?php _e( 'What is cache status such as "full cache", "partial cache" and "no cache"?', self::DOMAIN ); ?></h4>
60
+ <p><?php _e( 'The following is the explanation of the cache status.', self::DOMAIN ); ?></p>
61
+ <table class="view-table">
62
+ <thead>
63
+ <tr>
64
+ <th><?php _e( 'Cache Status', self::DOMAIN ); ?></th>
65
+ <th><?php _e( 'Description', self::DOMAIN ); ?></th>
66
+ </tr>
67
+ </thead>
68
+ <tbody>
69
+ <tr><td><?php _e( 'full cache', self::DOMAIN ); ?></td><td><?php _e( 'Counts for selected all SNS are cached.', self::DOMAIN ); ?></td></tr>
70
+ <tr><td><?php _e( 'partial cache', self::DOMAIN ); ?></td><td><?php _e( 'A subset of counts for selected SNS are cached.', self::DOMAIN ); ?></td></tr>
71
+ <tr><td><?php _e( 'no cache', self::DOMAIN ); ?></td><td><?php _e( 'Count for selected SNS are not cached at all.', self::DOMAIN ); ?></td></tr>
72
+ </tbody>
73
+ </table>
74
+ <h4><?php _e( 'How can I get share count from the cache?', self::DOMAIN ); ?></h4>
75
+ <p><?php _e( 'The share count is retrieved from the cache using the following functions in the WordPress loop such as query_posts(), get_posts() and WP_Query().', self::DOMAIN ); ?></p>
76
+ <table class="view-table">
77
+ <thead>
78
+ <tr>
79
+ <th><?php _e( 'Function', self::DOMAIN ); ?></th>
80
+ <th><?php _e( 'Description', self::DOMAIN ); ?></th>
81
+ </tr>
82
+ </thead>
83
+ <tbody>
84
+ <tr><td>scc_get_share_twitter()</td><td><?php _e( 'Twitter share count is returned from cache.', self::DOMAIN ); ?></td></tr>
85
+ <tr><td>scc_get_share_facebook()</td><td><?php _e( 'Facebook share count is returned from cache.', self::DOMAIN ); ?></td></tr>
86
+ <tr><td>scc_get_share_gplus()</td><td><?php _e( 'Google Plus share count is returned from cache.', self::DOMAIN ); ?></td></tr>
87
+ <tr><td>scc_get_share_hatebu()</td><td><?php _e( 'Hatena Bookmark share count is returned from cache.', self::DOMAIN ); ?></td></tr>
88
+ <tr><td>scc_get_share_pocket()</td><td><?php _e( 'Pocket share count is returned from cache.', self::DOMAIN ); ?></td></tr>
89
+ <tr><td>scc_get_share_pinterest()</td><td><?php _e( 'Pinterest share count is returned from cache.', self::DOMAIN ); ?></td></tr>
90
+ <tr><td>scc_get_share_linkedin()</td><td><?php _e( 'Linkedin share count is returned from cache.', self::DOMAIN ); ?></td></tr>
91
+ <tr><td>scc_get_share_total()</td><td><?php _e( 'Total share count of selected SNS is returned from cache.', self::DOMAIN ); ?></td></tr>
92
+ </tbody>
93
+ </table>
94
+ <h4><?php _e( 'How can I get follower count from the cache?', self::DOMAIN ); ?></h4>
95
+ <p><?php _e( 'The follower count is retrieved from the cache using the following functions.', self::DOMAIN ); ?></p>
96
+ <table class="view-table">
97
+ <thead>
98
+ <tr>
99
+ <th><?php _e( 'Function', self::DOMAIN ); ?></th>
100
+ <th><?php _e( 'Description', self::DOMAIN ); ?></th>
101
+ </tr>
102
+ </thead>
103
+ <tbody>
104
+ <tr><td>scc_get_follow_feedly()</td><td><?php _e( 'Feedly follower count is returned from cache.', self::DOMAIN ); ?></td></tr>
105
+ <tr><td>scc_get_follow_twitter()</td><td><?php _e( 'Twitter follower count is returned from cache.', self::DOMAIN ); ?></td></tr>
106
+ <tr><td>scc_get_follow_facebook()</td><td><?php _e( 'Facebook follower count is returned from cache.', self::DOMAIN ); ?></td></tr>
107
+ <tr><td>scc_get_follow_instagram()</td><td><?php _e( 'Instagram follower count is returned from cache.', self::DOMAIN ); ?></td></tr>
108
+ <tr><td>scc_get_follow_push7()</td><td><?php _e( 'Push7 follower count is returned from cache.', self::DOMAIN ); ?></td></tr>
109
+ </tbody>
110
+ </table>
111
+ <h4><?php _e( 'Example Code', self::DOMAIN ); ?></h4>
112
+ <?php _e( 'The code below describes a simple example which displays share count and follower count using the above functions.', self::DOMAIN ); ?>
113
+ <pre><code class="php">
114
+ &lt;?php
115
+ $query_args = array(
116
+ &#039;post_type&#039; =&gt; &#039;post&#039;,
117
+ &#039;post_status&#039; =&gt; &#039;publish&#039;,
118
+ &#039;posts_per_page&#039; =&gt; 5
119
+ );
120
+
121
+ $posts_query = new WP_Query( $query_args );
122
+
123
+ if ( $posts_query-&gt;have_posts() ) {
124
+ while ( $posts_query-&gt;have_posts() ){
125
+ $posts_query-&gt;the_post();
126
+
127
+ echo &#039;&lt;div&gt;Article Title: &#039; . esc_html( get_the_title( $posts_query-&gt;ID ) ) . &#039;&lt;/div&gt;&#039;;
128
+
129
+ if ( function_exists( &#039;scc_get_share_twitter&#039; ) &amp;&amp;
130
+ function_exists( &#039;scc_get_share_facebook&#039; ) &amp;&amp;
131
+ function_exists( &#039;scc_get_share_gplus&#039; ) &amp;&amp;
132
+ function_exists( &#039;scc_get_share_pocket&#039; ) &amp;&amp;
133
+ function_exists( &#039;scc_get_share_pinterest&#039; ) &amp;&amp;
134
+ function_exists( &#039;scc_get_share_linkedin&#039; ) &amp;&amp;
135
+ function_exists( &#039;scc_get_share_total&#039; )
136
+ ) {
137
+ // In WordPress loop, you can use the given function
138
+ // in order to get share count for current post and follower count.
139
+ echo &#039;&lt;div&gt;Twitter share count: &#039; . scc_get_share_twitter() . &#039;&lt;/div&gt;&#039;;
140
+ echo &#039;&lt;div&gt;Facebook share count: &#039; . scc_get_share_facebook() . &#039;&lt;/div&gt;&#039;;
141
+ echo &#039;&lt;div&gt;Google+ share count: &#039; . scc_get_share_gplus() . &#039;&lt;/div&gt;&#039;;
142
+ echo &#039;&lt;div&gt;Pocket share count: &#039; . scc_get_share_pocket() . &#039;&lt;/div&gt;&#039;;
143
+ echo &#039;&lt;div&gt;Pinterest share count: &#039; . scc_get_share_pinterest() . &#039;&lt;/div&gt;&#039;;
144
+ echo &#039;&lt;div&gt;Linkedin share count: &#039; . scc_get_share_linkedin() . &#039;&lt;/div&gt;&#039;;
145
+ echo &#039;&lt;div&gt;Total of share count: &#039; . scc_get_share_total() . &#039;&lt;/div&gt;&#039;;
146
+ }
147
+ }
148
+ wp_reset_postdata();
149
+ }
150
+
151
+ if ( function_exists( &#039;scc_get_follow_feedly&#039; ) &amp;&amp;
152
+ function_exists( &#039;scc_get_follow_twitter&#039; ) &amp;&amp;
153
+ function_exists( &#039;scc_get_follow_facebook&#039; ) &amp;&amp;
154
+ function_exists( &#039;scc_get_follow_instagram&#039; ) &amp;&amp;
155
+ function_exists( &#039;scc_get_follow_push7&#039; )
156
+ ) {
157
+ // You can use the given function in order to get follower count.
158
+ echo &#039;&lt;div&gt;Feedly follower count: &#039; . scc_get_follow_feedly() . &#039;&lt;/div&gt;&#039;;
159
+ echo &#039;&lt;div&gt;Twitter follower count: &#039; . scc_get_follow_twitter() . &#039;&lt;/div&gt;&#039;;
160
+ echo &#039;&lt;div&gt;Facebook follower count: &#039; . scc_get_follow_facebook() . &#039;&lt;/div&gt;&#039;;
161
+ echo &#039;&lt;div&gt;Instagram follower count: &#039; . scc_get_follow_instagram() . &#039;&lt;/div&gt;&#039;;
162
+ echo &#039;&lt;div&gt;Push7 follower count: &#039; . scc_get_follow_push7() . &#039;&lt;/div&gt;&#039;;
163
+ }
164
+ ?&gt;
165
+ </code></pre>
166
+ <script>hljs.initHighlightingOnLoad();</script>
167
+ <h4><?php _e( 'How can I access specific custom field containing each share count?', self::DOMAIN ); ?></h4>
168
+ <p><?php _e( 'Custom fields including share count are accessed using the following meta keys.', self::DOMAIN ); ?></p>
169
+ <table class="view-table">
170
+ <thead>
171
+ <tr>
172
+ <th><?php _e( 'Meta Key', self::DOMAIN ); ?></th>
173
+ <th><?php _e( 'Description', self::DOMAIN ); ?></th>
174
+ </tr>
175
+ </thead>
176
+ <tbody>
177
+ <tr><td>scc_share_count_twitter</td><td><?php _e( 'A meta key to access Twitter share count', self::DOMAIN ); ?></td></tr>
178
+ <tr><td>scc_share_count_facebook</td><td><?php _e( 'A meta key to access Facebook share count', self::DOMAIN ); ?></td></tr>
179
+ <tr><td>scc_share_count_google+</td><td><?php _e( 'A meta key to access Google+ share count', self::DOMAIN ); ?></td></tr>
180
+ <tr><td>scc_share_count_hatebu</td><td><?php _e( 'A meta key to access Hatena Bookmark share count', self::DOMAIN ); ?></td></tr>
181
+ <tr><td>scc_share_count_pocket</td><td><?php _e( 'A meta key to access Pocket share count', self::DOMAIN ); ?></td></tr>
182
+ <tr><td>scc_share_count_pinterest</td><td><?php _e( 'A meta key to access Pinterest share count', self::DOMAIN ); ?></td></tr>
183
+ <tr><td>scc_share_count_linkedin</td><td><?php _e( 'A meta key to access Linkedin share count', self::DOMAIN ); ?></td></tr>
184
+ <tr><td>scc_share_count_total</td><td><?php _e( 'A meta key to access total share count', self::DOMAIN ); ?></td></tr>
185
+ </tbody>
186
+ </table>
187
+ <h4><?php _e( 'How can I access specific custom field containing each variation of share count?', self::DOMAIN ); ?></h4>
188
+ <p><?php _e( 'Custom fields including variation of share count are accessed using the following meta keys.', self::DOMAIN ); ?></p>
189
+ <table class="view-table">
190
+ <thead>
191
+ <tr>
192
+ <th><?php _e( 'Meta Key', self::DOMAIN ); ?></th>
193
+ <th><?php _e( 'Description', self::DOMAIN ); ?></th>
194
+ </tr>
195
+ </thead>
196
+ <tbody>
197
+ <tr><td>scc_share_delta_twitter</td><td><?php _e( 'A meta key to access variation of Twitter share count', self::DOMAIN ); ?></td></tr>
198
+ <tr><td>scc_share_delta_facebook</td><td><?php _e( 'A meta key to access variation of Facebook share count', self::DOMAIN ); ?></td></tr>
199
+ <tr><td>scc_share_delta_google+</td><td><?php _e( 'A meta key to access variation of Google+ share count', self::DOMAIN ); ?></td></tr>
200
+ <tr><td>scc_share_delta_hatebu</td><td><?php _e( 'A meta key to access variation of Hatena Bookmark share count', self::DOMAIN ); ?></td></tr>
201
+ <tr><td>scc_share_delta_pocket</td><td><?php _e( 'A meta key to access variation of Pocket share count', self::DOMAIN ); ?></td></tr>
202
+ <tr><td>scc_share_delta_pinterest</td><td><?php _e( 'A meta key to access variation of Pinterest share count', self::DOMAIN ); ?></td></tr>
203
+ <tr><td>scc_share_delta_linkedin</td><td><?php _e( 'A meta key to access variation of Linkedin share count', self::DOMAIN ); ?></td></tr>
204
+ <tr><td>scc_share_delta_total</td><td><?php _e( 'A meta key to access variation of total share count', self::DOMAIN ); ?></td></tr>
205
+ </tbody>
206
+ </table>
207
+ </div>
208
+ </div>
209
+ </div>
210
+ </div>
211
+ </div>
includes/admin-hot-content.php CHANGED
@@ -1,331 +1,334 @@
1
- <?php
2
- /*
3
- admin-hot-content.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
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
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
- if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
39
- if ( isset( $_GET["key"] ) ) {
40
- $sort_mode = true;
41
- $sns = $_GET["key"];
42
-
43
- if ( $sns === 'Google' ) {
44
- $sns = $sns . '+';
45
- }
46
-
47
- $sort_exec_key = $sns;
48
-
49
- $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
50
- $meta_key2 = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
51
- }
52
- }
53
-
54
- }
55
-
56
- $paged = 1;
57
-
58
- if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 0 ) {
59
- $paged = $_GET['paged'];
60
- } else {
61
- $paged = 1;
62
- }
63
-
64
- $share_base_cache_target = $this->share_base_cache_target ;
65
- unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
66
-
67
- ?>
68
- <div class="wrap">
69
- <h2><a href="admin.php?page=scc-hot-content"><?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" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
75
- <a class="nav-tab nav-tab-active" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
76
- <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ); ?></a>
77
- <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
78
- </h3>
79
- <div class="metabox-holder">
80
- <div id="share-each-content" class="postbox">
81
- <div class="handlediv" title="Click to toggle"><br></div>
82
- <h3 class="hndle"><span><?php _e( 'Hot Content', self::DOMAIN ); ?></span></h3>
83
- <div class="inside">
84
- <table class="view-table">
85
- <thead>
86
- <tr>
87
- <th>No.</th>
88
- <th><?php _e( 'Content', self::DOMAIN ); ?></th>
89
- <?php
90
- foreach ( $share_base_cache_target as $sns => $active ) {
91
- if ( $active ) {
92
- $sort_key = $sns;
93
-
94
- if ( $sort_key === self::REF_SHARE_GPLUS ) {
95
- $sort_key = str_replace( '+', '', $sort_key );
96
- }
97
-
98
- $sort_url = esc_url( 'admin.php?page=scc-hot-content&action=sort&key=' . $sort_key );
99
-
100
- $sns_name = '';
101
-
102
- switch ( $sns ) {
103
- case self::REF_SHARE_TWITTER:
104
- $sns_name = __( 'Twitter', self::DOMAIN );
105
- break;
106
- case self::REF_SHARE_FACEBOOK:
107
- $sns_name = __( 'Facebook', self::DOMAIN );
108
- break;
109
- case self::REF_SHARE_GPLUS:
110
- $sns_name = __( 'Google+', self::DOMAIN );
111
- break;
112
- case self::REF_SHARE_POCKET:
113
- $sns_name = __( 'Pocket', self::DOMAIN );
114
- break;
115
- case self::REF_SHARE_HATEBU:
116
- $sns_name = __( 'Hatebu', self::DOMAIN );
117
- break;
118
- case self::REF_SHARE_PINTEREST:
119
- $sns_name = __( 'Pinterest', self::DOMAIN );
120
- break;
121
- case self::REF_SHARE_TOTAL:
122
- $sns_name = __( 'Total', self::DOMAIN );
123
- break;
124
- }
125
-
126
- if ( $sns === $sort_exec_key ){
127
- echo '<th><a class="sort-exec-key" href="' . $sort_url . '">' . esc_html( $sns_name ) . '</th>';
128
- } else {
129
- echo '<th><a href="' . $sort_url . '">' . esc_html( $sns_name ) . '</th>';
130
- }
131
- }
132
- }
133
- ?>
134
- </tr>
135
- </thead>
136
- <tbody>
137
- <?php
138
- $meta_query = array();
139
-
140
- if ( $sort_mode ) {
141
- if ( version_compare( get_bloginfo('version'), '4.2', '>=') ) {
142
- $meta_query['relation'] = 'AND';
143
-
144
- $meta_query[0]['relation'] = 'OR';
145
-
146
- foreach ( $share_base_cache_target as $sns => $active ) {
147
- if ( $active ) {
148
- $meta_query[0][] = array(
149
- 'key' => 'scc_share_delta_' . strtolower( $sns ),
150
- 'value' => 0,
151
- 'compare'=>'>',
152
- 'type'=>'NUMERIC'
153
- );
154
- }
155
- }
156
-
157
- $meta_query['meta_primary'] = array(
158
- 'key' => $meta_key,
159
- 'type'=>'NUMERIC'
160
- );
161
-
162
- $meta_query['meta_secondary'] = array(
163
- 'key' => $meta_key2,
164
- 'type'=>'NUMERIC'
165
- );
166
-
167
- SCC_Common_Util::log( $meta_query );
168
-
169
- SCC_Common_Util::log( 'version: ' . get_bloginfo( 'version') );
170
-
171
- $query_args = array(
172
- 'post_type' => $this->share_base_cache_post_types,
173
- 'post_status' => 'publish',
174
- 'posts_per_page' => $posts_per_page,
175
- 'paged' => $paged,
176
- 'update_post_term_cache' => false,
177
- 'meta_query' => $meta_query,
178
- 'orderby' => array(
179
- 'meta_primary' => 'DESC',
180
- 'meta_secondary' => 'DESC'
181
- )
182
- );
183
- } else {
184
- foreach ( $share_base_cache_target as $sns => $active ) {
185
- if ( $active ) {
186
- $meta_query[] = array(
187
- 'key' => 'scc_share_delta_' . strtolower( $sns ),
188
- 'value' => 0,
189
- 'compare'=>'>',
190
- 'type'=>'NUMERIC'
191
- );
192
- }
193
- }
194
-
195
- $meta_query['relation'] = 'OR';
196
-
197
- $query_args = array(
198
- 'post_type' => $this->share_base_cache_post_types,
199
- 'post_status' => 'publish',
200
- 'posts_per_page' => $posts_per_page,
201
- 'paged' => $paged,
202
- 'meta_key' => $meta_key,
203
- 'orderby' => 'meta_value_num',
204
- 'update_post_term_cache' => false,
205
- 'order' => 'DESC',
206
- 'meta_query' => $meta_query
207
- );
208
- }
209
- } else {
210
- foreach ( $share_base_cache_target as $sns => $active ) {
211
- if ( $active ) {
212
- $meta_query[] = array(
213
- 'key' => 'scc_share_delta_' . strtolower( $sns ),
214
- 'value' => 0,
215
- 'compare'=>'>',
216
- 'type'=>'NUMERIC'
217
- );
218
- }
219
- }
220
-
221
- $meta_query['relation'] = 'OR';
222
-
223
- $query_args = array(
224
- 'post_type' => $this->share_base_cache_post_types,
225
- 'post_status' => 'publish',
226
- 'posts_per_page' => $posts_per_page,
227
- 'paged' => $paged,
228
- 'meta_query' => $meta_query,
229
- 'update_post_term_cache' => false
230
- );
231
- }
232
-
233
- $posts_query = new WP_Query( $query_args );
234
-
235
- $count = ( $paged - 1 ) * $posts_per_page + 1;
236
-
237
- if ( $posts_query->have_posts() ) {
238
- while ( $posts_query->have_posts() ) {
239
- $posts_query->the_post();
240
- ?>
241
- <tr>
242
- <td><?php echo $count; ?></td>
243
- <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>
244
- <?php
245
- $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( get_the_ID() );
246
-
247
- if ( ! $sort_mode && false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
248
- foreach ( $share_base_cache_target as $sns => $active ) {
249
- if ( $active ) {
250
- //delta
251
- $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
252
- $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
253
-
254
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
255
- echo '<td class="share-count">';
256
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
257
-
258
- if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
259
- echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
260
- } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
261
- echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
262
- }
263
-
264
- echo '</td>';
265
- } else {
266
- echo '<td class="not-cached share-count">';
267
- _e( 'N/A', self::DOMAIN );
268
- echo '</td>';
269
- }
270
- }
271
- }
272
- } else {
273
- foreach ( $share_base_cache_target as $sns => $active ) {
274
- if ( $active ){
275
- $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
276
-
277
- $sns_counts[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
278
-
279
- //delta
280
- $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
281
- $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
282
-
283
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 ) {
284
- echo '<td class="share-count">';
285
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
286
-
287
- if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
288
- echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
289
- } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
290
- echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
291
- }
292
-
293
- echo '</td>';
294
- } else {
295
- echo '<td class="not-cached share-count">';
296
- _e( 'N/A', self::DOMAIN );
297
- echo '</td>';
298
- }
299
- }
300
- }
301
- }
302
- ?>
303
- </tr>
304
- <?php
305
- ++$count;
306
- }
307
- } else {
308
- echo '<tr>';
309
- echo '<td>' . $count . '</td>';
310
- echo '<td>' . __( 'No hot content.', self::DOMAIN ) . '</td>';
311
- foreach ( $share_base_cache_target as $sns => $active ) {
312
- if ( $active ) {
313
- echo '<td class="not-cached share-count">';
314
- _e( 'N/A', self::DOMAIN );
315
- echo '</td>';
316
- }
317
- }
318
- echo '</tr>';
319
- }
320
- ?>
321
- </tbody>
322
- </table>
323
- <?php
324
- $this->pagination( $posts_query->max_num_pages, '', $paged, true );
325
- wp_reset_postdata();
326
- ?>
327
- </div>
328
- </div>
329
- </div>
330
- </div>
331
- </div>
 
 
 
1
+ <?php
2
+ /*
3
+ admin-hot-content.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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
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
+ if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
39
+ if ( isset( $_GET["key"] ) ) {
40
+ $sort_mode = true;
41
+ $sns = $_GET["key"];
42
+
43
+ if ( $sns === 'Google' ) {
44
+ $sns = $sns . '+';
45
+ }
46
+
47
+ $sort_exec_key = $sns;
48
+
49
+ $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
50
+ $meta_key2 = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
51
+ }
52
+ }
53
+
54
+ }
55
+
56
+ $paged = 1;
57
+
58
+ if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 0 ) {
59
+ $paged = $_GET['paged'];
60
+ } else {
61
+ $paged = 1;
62
+ }
63
+
64
+ $share_base_cache_target = $this->share_base_cache_target ;
65
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
66
+
67
+ ?>
68
+ <div class="wrap">
69
+ <h2><a href="admin.php?page=scc-hot-content"><?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" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
75
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
76
+ <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ); ?></a>
77
+ <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
78
+ </h3>
79
+ <div class="metabox-holder">
80
+ <div id="share-each-content" class="postbox">
81
+ <div class="handlediv" title="Click to toggle"><br></div>
82
+ <h3 class="hndle"><span><?php _e( 'Hot Content', self::DOMAIN ); ?></span></h3>
83
+ <div class="inside">
84
+ <table class="view-table">
85
+ <thead>
86
+ <tr>
87
+ <th>No.</th>
88
+ <th><?php _e( 'Content', self::DOMAIN ); ?></th>
89
+ <?php
90
+ foreach ( $share_base_cache_target as $sns => $active ) {
91
+ if ( $active ) {
92
+ $sort_key = $sns;
93
+
94
+ if ( $sort_key === self::REF_SHARE_GPLUS ) {
95
+ $sort_key = str_replace( '+', '', $sort_key );
96
+ }
97
+
98
+ $sort_url = esc_url( 'admin.php?page=scc-hot-content&action=sort&key=' . $sort_key );
99
+
100
+ $sns_name = '';
101
+
102
+ switch ( $sns ) {
103
+ case self::REF_SHARE_TWITTER:
104
+ $sns_name = __( 'Twitter', self::DOMAIN );
105
+ break;
106
+ case self::REF_SHARE_FACEBOOK:
107
+ $sns_name = __( 'Facebook', self::DOMAIN );
108
+ break;
109
+ case self::REF_SHARE_GPLUS:
110
+ $sns_name = __( 'Google+', self::DOMAIN );
111
+ break;
112
+ case self::REF_SHARE_POCKET:
113
+ $sns_name = __( 'Pocket', self::DOMAIN );
114
+ break;
115
+ case self::REF_SHARE_HATEBU:
116
+ $sns_name = __( 'Hatebu', self::DOMAIN );
117
+ break;
118
+ case self::REF_SHARE_PINTEREST:
119
+ $sns_name = __( 'Pinterest', self::DOMAIN );
120
+ break;
121
+ case self::REF_SHARE_LINKEDIN:
122
+ $sns_name = __( 'Linkedin', self::DOMAIN );
123
+ break;
124
+ case self::REF_SHARE_TOTAL:
125
+ $sns_name = __( 'Total', self::DOMAIN );
126
+ break;
127
+ }
128
+
129
+ if ( $sns === $sort_exec_key ){
130
+ echo '<th><a class="sort-exec-key" href="' . $sort_url . '">' . esc_html( $sns_name ) . '</th>';
131
+ } else {
132
+ echo '<th><a href="' . $sort_url . '">' . esc_html( $sns_name ) . '</th>';
133
+ }
134
+ }
135
+ }
136
+ ?>
137
+ </tr>
138
+ </thead>
139
+ <tbody>
140
+ <?php
141
+ $meta_query = array();
142
+
143
+ if ( $sort_mode ) {
144
+ if ( version_compare( get_bloginfo('version'), '4.2', '>=') ) {
145
+ $meta_query['relation'] = 'AND';
146
+
147
+ $meta_query[0]['relation'] = 'OR';
148
+
149
+ foreach ( $share_base_cache_target as $sns => $active ) {
150
+ if ( $active ) {
151
+ $meta_query[0][] = array(
152
+ 'key' => 'scc_share_delta_' . strtolower( $sns ),
153
+ 'value' => 0,
154
+ 'compare'=>'>',
155
+ 'type'=>'NUMERIC'
156
+ );
157
+ }
158
+ }
159
+
160
+ $meta_query['meta_primary'] = array(
161
+ 'key' => $meta_key,
162
+ 'type'=>'NUMERIC'
163
+ );
164
+
165
+ $meta_query['meta_secondary'] = array(
166
+ 'key' => $meta_key2,
167
+ 'type'=>'NUMERIC'
168
+ );
169
+
170
+ SCC_Common_Util::log( $meta_query );
171
+
172
+ SCC_Common_Util::log( 'version: ' . get_bloginfo( 'version') );
173
+
174
+ $query_args = array(
175
+ 'post_type' => $this->share_base_cache_post_types,
176
+ 'post_status' => 'publish',
177
+ 'posts_per_page' => $posts_per_page,
178
+ 'paged' => $paged,
179
+ 'update_post_term_cache' => false,
180
+ 'meta_query' => $meta_query,
181
+ 'orderby' => array(
182
+ 'meta_primary' => 'DESC',
183
+ 'meta_secondary' => 'DESC'
184
+ )
185
+ );
186
+ } else {
187
+ foreach ( $share_base_cache_target as $sns => $active ) {
188
+ if ( $active ) {
189
+ $meta_query[] = array(
190
+ 'key' => 'scc_share_delta_' . strtolower( $sns ),
191
+ 'value' => 0,
192
+ 'compare'=>'>',
193
+ 'type'=>'NUMERIC'
194
+ );
195
+ }
196
+ }
197
+
198
+ $meta_query['relation'] = 'OR';
199
+
200
+ $query_args = array(
201
+ 'post_type' => $this->share_base_cache_post_types,
202
+ 'post_status' => 'publish',
203
+ 'posts_per_page' => $posts_per_page,
204
+ 'paged' => $paged,
205
+ 'meta_key' => $meta_key,
206
+ 'orderby' => 'meta_value_num',
207
+ 'update_post_term_cache' => false,
208
+ 'order' => 'DESC',
209
+ 'meta_query' => $meta_query
210
+ );
211
+ }
212
+ } else {
213
+ foreach ( $share_base_cache_target as $sns => $active ) {
214
+ if ( $active ) {
215
+ $meta_query[] = array(
216
+ 'key' => 'scc_share_delta_' . strtolower( $sns ),
217
+ 'value' => 0,
218
+ 'compare'=>'>',
219
+ 'type'=>'NUMERIC'
220
+ );
221
+ }
222
+ }
223
+
224
+ $meta_query['relation'] = 'OR';
225
+
226
+ $query_args = array(
227
+ 'post_type' => $this->share_base_cache_post_types,
228
+ 'post_status' => 'publish',
229
+ 'posts_per_page' => $posts_per_page,
230
+ 'paged' => $paged,
231
+ 'meta_query' => $meta_query,
232
+ 'update_post_term_cache' => false
233
+ );
234
+ }
235
+
236
+ $posts_query = new WP_Query( $query_args );
237
+
238
+ $count = ( $paged - 1 ) * $posts_per_page + 1;
239
+
240
+ if ( $posts_query->have_posts() ) {
241
+ while ( $posts_query->have_posts() ) {
242
+ $posts_query->the_post();
243
+ ?>
244
+ <tr>
245
+ <td><?php echo $count; ?></td>
246
+ <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>
247
+ <?php
248
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( get_the_ID() );
249
+
250
+ if ( ! $sort_mode && false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
251
+ foreach ( $share_base_cache_target as $sns => $active ) {
252
+ if ( $active ) {
253
+ //delta
254
+ $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
255
+ $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
256
+
257
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
258
+ echo '<td class="share-count">';
259
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
260
+
261
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
262
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
263
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
264
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
265
+ }
266
+
267
+ echo '</td>';
268
+ } else {
269
+ echo '<td class="not-cached share-count">';
270
+ _e( 'N/A', self::DOMAIN );
271
+ echo '</td>';
272
+ }
273
+ }
274
+ }
275
+ } else {
276
+ foreach ( $share_base_cache_target as $sns => $active ) {
277
+ if ( $active ){
278
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
279
+
280
+ $sns_counts[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
281
+
282
+ //delta
283
+ $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
284
+ $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
285
+
286
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 ) {
287
+ echo '<td class="share-count">';
288
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
289
+
290
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
291
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
292
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
293
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
294
+ }
295
+
296
+ echo '</td>';
297
+ } else {
298
+ echo '<td class="not-cached share-count">';
299
+ _e( 'N/A', self::DOMAIN );
300
+ echo '</td>';
301
+ }
302
+ }
303
+ }
304
+ }
305
+ ?>
306
+ </tr>
307
+ <?php
308
+ ++$count;
309
+ }
310
+ } else {
311
+ echo '<tr>';
312
+ echo '<td>' . $count . '</td>';
313
+ echo '<td>' . __( 'No hot content.', self::DOMAIN ) . '</td>';
314
+ foreach ( $share_base_cache_target as $sns => $active ) {
315
+ if ( $active ) {
316
+ echo '<td class="not-cached share-count">';
317
+ _e( 'N/A', self::DOMAIN );
318
+ echo '</td>';
319
+ }
320
+ }
321
+ echo '</tr>';
322
+ }
323
+ ?>
324
+ </tbody>
325
+ </table>
326
+ <?php
327
+ $this->pagination( $posts_query->max_num_pages, '', $paged, true );
328
+ wp_reset_postdata();
329
+ ?>
330
+ </div>
331
+ </div>
332
+ </div>
333
+ </div>
334
+ </div>
includes/admin-notice.php CHANGED
@@ -1,48 +1,48 @@
1
- <?php
2
- /*
3
- admin-notice.php
4
-
5
- Description:
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
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
-
32
- if ( $messages = get_option( self::OPT_COMMON_ERROR_MESSAGE ) ) {
33
- ?>
34
- <div class="error">
35
- <ul>
36
- <?php
37
- foreach( $messages as $message ) {
38
- ?>
39
- <li><?php echo esc_html( $message ); ?></li>
40
- <?php
41
- }
42
- ?>
43
- </ul>
44
- </div>
45
- <?php
46
- delete_option( self::OPT_COMMON_ERROR_MESSAGE );
47
- }
48
- ?>
1
+ <?php
2
+ /*
3
+ admin-notice.php
4
+
5
+ Description:
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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
+
32
+ if ( $messages = get_option( self::OPT_COMMON_ERROR_MESSAGE ) ) {
33
+ ?>
34
+ <div class="error">
35
+ <ul>
36
+ <?php
37
+ foreach( $messages as $message ) {
38
+ ?>
39
+ <li><?php echo esc_html( $message ); ?></li>
40
+ <?php
41
+ }
42
+ ?>
43
+ </ul>
44
+ </div>
45
+ <?php
46
+ delete_option( self::OPT_COMMON_ERROR_MESSAGE );
47
+ }
48
+ ?>
includes/admin-setting.php CHANGED
@@ -1,2113 +1,2567 @@
1
- <?php
2
- /*
3
- admin-setting.php
4
-
5
- Description: Option page implementation
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
-
32
- $tmp_instagram_access_token = '';
33
- $tmp_facebook_access_token = '';
34
- $tmp_twitter_bearer_token = '';
35
-
36
- if ( isset( $_POST['_wpnonce'] ) && $_POST['_wpnonce'] && check_admin_referer( __FILE__, '_wpnonce' ) ) {
37
- if ( isset( $_POST["update_all_options"] ) && $_POST["update_all_options"] === __( 'Update All Options', self::DOMAIN ) ) {
38
-
39
- $wp_error = new WP_Error();
40
-
41
- //$settings = array();
42
- $settings = get_option( self::DB_SETTINGS );
43
-
44
- $share_base_cache_target = array();
45
- $follow_base_cache_target = array();
46
-
47
- if ( isset( $_POST["share_base_custom_post_types"] ) && $_POST["share_base_custom_post_types"] ) {
48
- $share_base_custom_post_types = explode( ',', $_POST["share_base_custom_post_types"] );
49
- $settings[self::DB_SHARE_CUSTOM_POST_TYPES] = $share_base_custom_post_types;
50
- } else {
51
- $settings[self::DB_SHARE_CUSTOM_POST_TYPES] = array();
52
- }
53
-
54
- if ( isset( $_POST["share_base_check_interval"] ) && $_POST["share_base_check_interval"] && is_numeric( $_POST["share_base_check_interval"] ) ) {
55
- $settings[self::DB_SHARE_BASE_CHECK_INTERVAL] = $_POST["share_base_check_interval"];
56
- }
57
-
58
- if ( isset( $_POST["share_base_posts_per_check"] ) && $_POST["share_base_posts_per_check"] && is_numeric( $_POST["share_base_posts_per_check"] ) ) {
59
- $settings[self::DB_SHARE_BASE_POSTS_PER_CHECK] = $_POST["share_base_posts_per_check"];
60
- }
61
-
62
- if ( isset( $_POST["dynamic_cache_mode"] ) && $_POST["dynamic_cache_mode"] ) {
63
- $settings[self::DB_COMMON_DYNAMIC_CACHE_MODE] = $_POST["dynamic_cache_mode"];
64
- }
65
-
66
- if ( isset( $_POST["fault_tolerance_mode"] ) && $_POST["fault_tolerance_mode"] ) {
67
- $settings[self::DB_COMMON_FAULT_TOLERANCE_MODE] = $_POST["fault_tolerance_mode"];
68
- }
69
-
70
- if ( isset( $_POST["share_variation_analysis_mode"] ) && $_POST["share_variation_analysis_mode"] ) {
71
- $settings[self::DB_SHARE_VARIATION_ANALYSIS_MODE] = $_POST["share_variation_analysis_mode"];
72
- }
73
-
74
- if ( isset( $_POST["share_rush_new_content_term"] ) && $_POST["share_rush_new_content_term"] && is_numeric( $_POST["share_rush_new_content_term"] ) ) {
75
- $settings[self::DB_SHARE_RUSH_NEW_CONTENT_TERM] = $_POST["share_rush_new_content_term"];
76
- }
77
-
78
- if ( isset( $_POST["share_rush_check_interval"] ) && $_POST["share_rush_check_interval"] && is_numeric( $_POST["share_rush_check_interval"] ) ) {
79
- $settings[self::DB_SHARE_RUSH_CHECK_INTERVAL] = $_POST["share_rush_check_interval"];
80
- }
81
-
82
- if ( isset( $_POST["share_rush_posts_per_check"] ) && $_POST["share_rush_posts_per_check"] && is_numeric( $_POST["share_rush_posts_per_check"] ) ) {
83
- $settings[self::DB_SHARE_RUSH_POSTS_PER_CHECK] = $_POST["share_rush_posts_per_check"];
84
- }
85
-
86
- if ( isset( $_POST["data_export_mode"] ) && $_POST["data_export_mode"] ) {
87
- $settings[self::DB_COMMON_DATA_EXPORT_MODE] = $_POST["data_export_mode"];
88
- }
89
-
90
- if ( isset( $_POST["data_export_interval"] ) && $_POST["data_export_interval"] && is_numeric( $_POST["data_export_interval"] ) ) {
91
- $settings[self::DB_COMMON_DATA_EXPORT_INTERVAL] = $_POST["data_export_interval"];
92
- }
93
-
94
- if ( isset( $_POST["share_base_cache_target_twitter"] ) && $_POST["share_base_cache_target_twitter"] ) {
95
- $share_base_cache_target[self::REF_SHARE_TWITTER] = true;
96
- } else {
97
- $share_base_cache_target[self::REF_SHARE_TWITTER] = false;
98
- }
99
-
100
- if ( isset( $_POST["share_alternative_twitter_api"] ) && $_POST["share_alternative_twitter_api"] ) {
101
- $settings[self::DB_SHARE_BASE_TWITTER_API] = $_POST["share_alternative_twitter_api"];
102
- }
103
-
104
- if ( isset( $_POST["share_base_cache_target_facebook"] ) && $_POST["share_base_cache_target_facebook"] ) {
105
- $share_base_cache_target[self::REF_SHARE_FACEBOOK] = true;
106
- } else {
107
- $share_base_cache_target[self::REF_SHARE_FACEBOOK] = false;
108
- }
109
-
110
- if ( isset( $_POST["share_base_cache_target_gplus"] ) && $_POST["share_base_cache_target_gplus"] ) {
111
- $share_base_cache_target[self::REF_SHARE_GPLUS] = true;
112
- } else {
113
- $share_base_cache_target[self::REF_SHARE_GPLUS] = false;
114
- }
115
-
116
- if ( isset( $_POST["share_base_cache_target_pocket"] ) && $_POST["share_base_cache_target_pocket"] ) {
117
- $share_base_cache_target[self::REF_SHARE_POCKET] = true;
118
- } else {
119
- $share_base_cache_target[self::REF_SHARE_POCKET] = false;
120
- }
121
-
122
- if ( isset( $_POST["share_base_cache_target_hatebu"] ) && $_POST["share_base_cache_target_hatebu"] ) {
123
- $share_base_cache_target[self::REF_SHARE_HATEBU] = true;
124
- } else {
125
- $share_base_cache_target[self::REF_SHARE_HATEBU] = false;
126
- }
127
-
128
- if ( isset( $_POST["share_base_cache_target_pinterest"] ) && $_POST["share_base_cache_target_pinterest"] ) {
129
- $share_base_cache_target[self::REF_SHARE_PINTEREST] = true;
130
- } else {
131
- $share_base_cache_target[self::REF_SHARE_PINTEREST] = false;
132
- }
133
-
134
- /*
135
- if ( isset( $_POST["share_base_cache_target_linkedin"] ) && $_POST["share_base_cache_target_linkedin"] ) {
136
- $share_base_cache_target[self::REF_SHARE_LINKEDIN] = true;
137
- } else {
138
- $share_base_cache_target[self::REF_SHARE_LINKEDIN] = false;
139
- }
140
- */
141
-
142
- if ( ! empty( $share_base_cache_target ) ) {
143
- $settings[self::DB_SHARE_CACHE_TARGET] = $share_base_cache_target;
144
- }
145
-
146
- if ( isset( $_POST["follow_base_check_interval"] ) && $_POST["follow_base_check_interval"] && is_numeric( $_POST["follow_base_check_interval"] ) ) {
147
- if ( $_POST["follow_base_check_interval"] >= self::OPT_FOLLOW_BASE_CHECK_INTERVAL_MIN ) {
148
- $settings[self::DB_FOLLOW_CHECK_INTERVAL] = $_POST["follow_base_check_interval"];
149
- } else {
150
- $settings[self::DB_FOLLOW_CHECK_INTERVAL] = self::OPT_FOLLOW_BASE_CHECK_INTERVAL_MIN;
151
- }
152
- }
153
-
154
- if ( isset( $_POST["follow_base_cache_target_feedly"] ) && $_POST["follow_base_cache_target_feedly"] ) {
155
- $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = true;
156
- } else {
157
- $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = false;
158
- }
159
-
160
- if ( isset( $_POST["follow_base_cache_target_twitter"] ) && $_POST["follow_base_cache_target_twitter"] ) {
161
- $follow_base_cache_target[self::REF_FOLLOW_TWITTER] = true;
162
- } else {
163
- $follow_base_cache_target[self::REF_FOLLOW_TWITTER] = false;
164
- }
165
-
166
- if ( isset( $_POST["follow_base_cache_target_facebook"] ) && $_POST["follow_base_cache_target_facebook"] ) {
167
- $follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] = true;
168
- } else {
169
- $follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] = false;
170
- }
171
-
172
- if ( isset( $_POST["follow_base_cache_target_push7"] ) && $_POST["follow_base_cache_target_push7"] ) {
173
- $follow_base_cache_target[self::REF_FOLLOW_PUSH7] = true;
174
- } else {
175
- $follow_base_cache_target[self::REF_FOLLOW_PUSH7] = false;
176
- }
177
-
178
- if ( isset( $_POST["follow_base_cache_target_instagram"] ) && $_POST["follow_base_cache_target_instagram"] ) {
179
- $follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] = true;
180
- } else {
181
- $follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] = false;
182
- }
183
-
184
- if ( ! empty( $follow_base_cache_target ) ) {
185
- $settings[self::DB_FOLLOW_CACHE_TARGET] = $follow_base_cache_target;
186
- }
187
-
188
- $follow_twitter_preparation_flag = true;
189
-
190
- if ( isset( $_POST["share_facebook_app_id"] ) && $_POST["share_facebook_app_id"] ) {
191
- $settings[self::DB_SHARE_FACEBOOK_APP_ID] = SCC_Common_Util::encrypt_data( $_POST["share_facebook_app_id"], AUTH_KEY );
192
- }
193
-
194
- if ( isset( $_POST["share_facebook_app_secret"] ) && $_POST["share_facebook_app_secret"] ) {
195
- $settings[self::DB_SHARE_FACEBOOK_APP_SECRET] = SCC_Common_Util::encrypt_data( $_POST["share_facebook_app_secret"], AUTH_KEY );
196
- }
197
-
198
- if ( isset( $_POST["follow_twitter_screen_name"] ) && $_POST["follow_twitter_screen_name"] ) {
199
- $settings[self::DB_FOLLOW_TWITTER_SCREEN_NAME] = $_POST["follow_twitter_screen_name"];
200
- }
201
-
202
- if ( isset( $_POST["follow_twitter_consumer_key"] ) && $_POST["follow_twitter_consumer_key"] ) {
203
- $settings[self::DB_FOLLOW_TWITTER_CONSUMER_KEY] = SCC_Common_Util::encrypt_data( $_POST["follow_twitter_consumer_key"], AUTH_KEY );
204
- } else {
205
- $follow_twitter_preparation_flag = false;
206
- }
207
-
208
- if ( isset( $_POST["follow_twitter_consumer_secret"] ) && $_POST["follow_twitter_consumer_secret"] ) {
209
- $settings[self::DB_FOLLOW_TWITTER_CONSUMER_SECRET] = SCC_Common_Util::encrypt_data( $_POST["follow_twitter_consumer_secret"], AUTH_KEY );
210
- } else {
211
- $follow_twitter_preparation_flag = false;
212
- }
213
-
214
- if ( isset( $_POST["follow_twitter_bearer_token"] ) && $_POST["follow_twitter_bearer_token"] ) {
215
- $settings[self::DB_FOLLOW_TWITTER_BEARER_TOKEN] = SCC_Common_Util::encrypt_data( $_POST["follow_twitter_bearer_token"], AUTH_KEY );
216
- }
217
-
218
- /*
219
- if ( isset( $_POST["follow_twitter_access_token"] ) && $_POST["follow_twitter_access_token"] ) {
220
- $settings[self::DB_FOLLOW_TWITTER_ACCESS_TOKEN] = SCC_Common_Util::encrypt_data( $_POST["follow_twitter_access_token"], AUTH_KEY );
221
- }
222
-
223
- if ( isset( $_POST["follow_twitter_access_token_secret"] ) && $_POST["follow_twitter_access_token_secret"] ) {
224
- $settings[self::DB_FOLLOW_TWITTER_ACCESS_TOKEN_SECRET] = SCC_Common_Util::encrypt_data( $_POST["follow_twitter_access_token_secret"], AUTH_KEY );
225
- }
226
- */
227
-
228
- if ( isset( $_POST["follow_facebook_page_id"] ) && $_POST["follow_facebook_page_id"] ) {
229
- $settings[self::DB_FOLLOW_FACEBOOK_PAGE_ID] = $_POST["follow_facebook_page_id"];
230
- }
231
-
232
- if ( isset( $_POST["follow_facebook_app_id"] ) && $_POST["follow_facebook_app_id"] ) {
233
- $settings[self::DB_FOLLOW_FACEBOOK_APP_ID] = SCC_Common_Util::encrypt_data( $_POST["follow_facebook_app_id"], AUTH_KEY );
234
- }
235
-
236
- if ( isset( $_POST["follow_facebook_app_secret"] ) && $_POST["follow_facebook_app_secret"] ) {
237
- $settings[self::DB_FOLLOW_FACEBOOK_APP_SECRET] = SCC_Common_Util::encrypt_data( $_POST["follow_facebook_app_secret"], AUTH_KEY );
238
- }
239
-
240
- if ( isset( $_POST["follow_facebook_access_token"] ) && $_POST["follow_facebook_access_token"] ) {
241
- $settings[self::DB_FOLLOW_FACEBOOK_ACCESS_TOKEN] = SCC_Common_Util::encrypt_data( $_POST["follow_facebook_access_token"], AUTH_KEY );
242
- }
243
-
244
- if ( isset( $_POST["follow_push7_appno"] ) && $_POST["follow_push7_appno"] ) {
245
- $settings[self::DB_FOLLOW_PUSH7_APPNO] = SCC_Common_Util::encrypt_data( $_POST["follow_push7_appno"], AUTH_KEY );
246
- }
247
-
248
- if ( isset( $_POST["follow_instagram_access_token"] ) && $_POST["follow_instagram_access_token"] ) {
249
- $settings[self::DB_FOLLOW_INSTAGRAM_ACCESS_TOKEN] = SCC_Common_Util::encrypt_data( $_POST["follow_instagram_access_token"], AUTH_KEY );
250
- }
251
-
252
- if ( isset( $_POST["follow_instagram_client_id"] ) && $_POST["follow_instagram_client_id"] ) {
253
- $settings[self::DB_FOLLOW_INSTAGRAM_CLIENT_ID] = SCC_Common_Util::encrypt_data( $_POST["follow_instagram_client_id"], AUTH_KEY );
254
- }
255
-
256
- if ( isset( $_POST["follow_instagram_client_secret"] ) && $_POST["follow_instagram_client_secret"] ) {
257
- $settings[self::DB_FOLLOW_INSTAGRAM_CLIENT_SECRET] = SCC_Common_Util::encrypt_data( $_POST["follow_instagram_client_secret"], AUTH_KEY );
258
- }
259
-
260
- if ( isset( $_POST["follow_feed_type"] ) && $_POST["follow_feed_type"] ) {
261
- switch ( $_POST["follow_feed_type"] ) {
262
- case 'default':
263
- $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_DEFAULT;
264
- break;
265
- case 'rss2':
266
- $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_RSS2;
267
- break;
268
- case 'rss':
269
- $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_RSS;
270
- break;
271
- case 'rdf':
272
- $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_RDF;
273
- break;
274
- case 'atom':
275
- $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_ATOM;
276
- break;
277
- default:
278
- $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_DEFAULT;
279
- }
280
- } else {
281
- $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_DEFAULT;
282
- }
283
-
284
- if ( isset( $_POST["scheme_migration_mode"] ) && $_POST["scheme_migration_mode"] ) {
285
- $settings[self::DB_COMMON_SCHEME_MIGRATION_MODE] = self::OPT_COMMON_SCHEME_MIGRATION_MODE_ON;
286
- } else {
287
- $settings[self::DB_COMMON_SCHEME_MIGRATION_MODE] = self::OPT_COMMON_SCHEME_MIGRATION_MODE_OFF;
288
- }
289
-
290
- if ( isset( $_POST["scheme_migration_date"] ) && $_POST["scheme_migration_date"] && strptime( $_POST["scheme_migration_date"], '%Y/%m/%d' ) ) {
291
- $settings[self::DB_COMMON_SCHEME_MIGRATION_DATE] = $_POST["scheme_migration_date"];
292
- }
293
-
294
- if ( isset( $_POST["crawler_ssl_verification"] ) && $_POST["crawler_ssl_verification"] ) {
295
- $settings[self::DB_COMMON_CRAWLER_SSL_VERIFICATION] = self::OPT_COMMON_CRAWLER_SSL_VERIFY_ON;
296
- } else {
297
- $settings[self::DB_COMMON_CRAWLER_SSL_VERIFICATION] = self::OPT_COMMON_CRAWLER_SSL_VERIFY_OFF;
298
- }
299
-
300
- if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'mon' ) {
301
- $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_moncronminutes'] . ' ' . $_POST['a_moncronhours'] . ' ' . $_POST['a_moncronmday'] . ' * *';
302
- }
303
-
304
- if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'week' ) {
305
- $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_weekcronminutes'] . ' ' . $_POST['a_weekcronhours'] . ' * * ' . $_POST['a_weekcronwday'];
306
- }
307
-
308
- if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'day' ) {
309
- $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_daycronminutes'] . ' ' . $_POST['a_daycronhours'] . ' * * *';
310
- }
311
-
312
- if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'hour' ) {
313
- $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_hourcronminutes'] . ' * * * *';
314
- }
315
-
316
- if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'mon' ) {
317
- $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_moncronminutes'] . ' ' . $_POST['e_moncronhours'] . ' ' . $_POST['e_moncronmday'] . ' * *';
318
- }
319
-
320
- if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'week' ) {
321
- $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_weekcronminutes'] . ' ' . $_POST['e_weekcronhours'] . ' * * ' . $_POST['e_weekcronwday'];
322
- }
323
-
324
- if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'day' ) {
325
- $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_daycronminutes'] . ' ' . $_POST['e_daycronhours'] . ' * * *';
326
- }
327
-
328
- if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'hour' ) {
329
- $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_hourcronminutes'] . ' * * * *';
330
- }
331
-
332
- update_option( self::DB_SETTINGS, $settings );
333
-
334
- $this->reactivate_plugin();
335
-
336
- set_transient( self::OPT_COMMON_ERROR_MESSAGE, $wp_error->get_error_messages(), 10 );
337
-
338
- //wp_safe_redirect( menu_page_url( 'scc-setting', false ) );
339
- }
340
-
341
- if ( isset( $_POST["reset_data"] ) && $_POST["reset_data"] === __( 'Reset', self::DOMAIN ) ) {
342
- SCC_Common_Util::log( '[' . __METHOD__ . '] reset' );
343
-
344
- $this->export_engines[self::REF_COMMON_EXPORT]->reset_export();
345
-
346
- //wp_safe_redirect( menu_page_url( 'scc-setting', false ) );
347
- }
348
-
349
- if ( isset( $_POST["export_data"] ) && $_POST["export_data"] === __( 'Export', self::DOMAIN ) ) {
350
- SCC_Common_Util::log( '[' . __METHOD__ . '] export' );
351
-
352
- set_time_limit( $this->extended_max_execution_time );
353
-
354
- $this->export_engines[self::REF_COMMON_EXPORT]->execute_export( NULL );
355
-
356
- set_time_limit( $this->original_max_execution_time );
357
-
358
- //wp_safe_redirect( menu_page_url('scc-setting', false ) );
359
- }
360
-
361
- if ( isset( $_POST["update_share_comparison_base"] ) && $_POST["update_share_comparison_base"] === __( 'Update Basis of Comparison', self::DOMAIN ) ) {
362
- SCC_Common_Util::log( '[' . __METHOD__ . '] base' );
363
-
364
- set_time_limit( $this->extended_max_execution_time );
365
-
366
- $this->analytical_engines[self::REF_SHARE_ANALYSIS]->execute_base( NULL );
367
-
368
- set_time_limit( $this->original_max_execution_time );
369
-
370
- //wp_safe_redirect( menu_page_url( 'scc-setting', false ) );
371
- }
372
-
373
- if ( isset( $_POST["clear_share_base_cache"] ) && $_POST["clear_share_base_cache"] === __( 'Clear Cache', self::DOMAIN ) ) {
374
- SCC_Common_Util::log( '[' . __METHOD__ . '] clear cache' );
375
-
376
- set_time_limit( $this->extended_max_execution_time );
377
-
378
- $this->cache_engines[self::REF_SHARE_BASE]->clear_cache();
379
- //$this->cache_engines[self::REF_SHARE_2ND]->clear_cache();
380
- $this->cache_engines[self::REF_SHARE_2ND]->initialize_cache();
381
- $this->analytical_engines[self::REF_SHARE_ANALYSIS]->clear_base();
382
-
383
- set_time_limit( $this->original_max_execution_time );
384
-
385
- //wp_safe_redirect( menu_page_url('scc-setting', false ) );
386
- }
387
-
388
- if ( isset( $_POST["clear_follow_base_cache"] ) && $_POST["clear_follow_base_cache"] === __( 'Clear Cache', self::DOMAIN ) ) {
389
- SCC_Common_Util::log( '[' . __METHOD__ . '] clear cache' );
390
-
391
- set_time_limit( $this->extended_max_execution_time );
392
-
393
- $this->cache_engines[self::REF_FOLLOW_BASE]->clear_cache();
394
- //$this->cache_engines[self::REF_FOLLOW_2ND]->clear_cache();
395
- $this->cache_engines[self::REF_FOLLOW_2ND]->initialize_cache();
396
-
397
- set_time_limit( $this->original_max_execution_time );
398
-
399
- //wp_safe_redirect( menu_page_url('scc-setting', false ) );
400
- }
401
-
402
- if ( isset( $_POST["direct_follow_base_cache"] ) && $_POST["direct_follow_base_cache"] === __( 'Cache', self::DOMAIN ) ) {
403
- SCC_Common_Util::log( '[' . __METHOD__ . '] cache' );
404
-
405
- set_time_limit( $this->extended_max_execution_time );
406
-
407
- $this->cache_engines[self::REF_FOLLOW_BASE]->direct_cache( true );
408
-
409
- set_time_limit( $this->original_max_execution_time );
410
-
411
- //wp_safe_redirect( menu_page_url('scc-setting', false ) );
412
- }
413
-
414
- if ( isset( $_POST["get_tiwtter_bearer_token"] ) && $_POST["get_tiwtter_bearer_token"] === __( 'Get Bearer Token', self::DOMAIN ) ) {
415
- $tmp_twitter_bearer_token = SCC_Common_Util::get_twitter_bearer_token( $this->follow_twitter_consumer_key, $this->follow_twitter_consumer_secret );
416
- }
417
-
418
- } elseif( isset( $_GET['_wpnonce'] ) && $_GET['_wpnonce'] && isset( $_GET['action'] ) && $_GET['action'] && isset( $_GET['code'] ) && $_GET['code'] ) {
419
- if ( $_GET['action'] === 'instagram-auth' ) {
420
- if ( check_admin_referer( 'instagram-auth', '_wpnonce' ) ) {
421
- if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
422
- $redirect_uri = plugins_url() . '/sns-count-cache/?action=instagram-auth';
423
- $tmp_instagram_access_token = SCC_Common_Util::get_instagram_access_token( $this->follow_instagram_client_id, $this->follow_instagram_client_secret, $redirect_uri, $_GET['code'] );
424
- }
425
- }
426
- } elseif ( $_GET['action'] === 'facebook-auth' ) {
427
- if ( check_admin_referer( 'facebook-auth', '_wpnonce' ) ) {
428
- if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
429
- $redirect_uri = plugins_url() . '/sns-count-cache/?action=facebook-auth';
430
- $tmp_facebook_access_token = SCC_Common_Util::get_facebook_access_token( $this->follow_facebook_app_id, $this->follow_facebook_app_secret, $redirect_uri, $_GET['code'] );
431
- }
432
- }
433
- }
434
- }
435
- ?>
436
- <div class="wrap">
437
- <h2><a href="admin.php?page=scc-setting"><?php _e( 'SNS Count Cache', self::DOMAIN ); ?></a></h2>
438
- <?php
439
- if ( $messages = get_transient( self::OPT_COMMON_ERROR_MESSAGE ) ) {
440
- ?>
441
- <div class="error">
442
- <ul>
443
- <?php
444
- foreach( $messages as $message ) {
445
- ?>
446
- <li><?php echo esc_html( $message ); ?></li>
447
- <?php
448
- }
449
- ?>
450
- </ul>
451
- </div>
452
- <?php
453
- delete_transient( self::OPT_COMMON_ERROR_MESSAGE );
454
- }
455
- ?>
456
-
457
- <?php
458
- $status = $this->test_cron_capability();
459
-
460
- if ( is_wp_error( $status ) ) {
461
- echo '<div class="error"><p>';
462
- _e( 'There was a problem spawning a call to the WP-Cron system on your site. This means WP-Cron jobs on your site may not work. The problem was: ', self::DOMAIN );
463
- echo '<br><strong>' . esc_html( $status->get_error_message() ) . '</strong>';
464
- echo '.</p></div>';
465
- }
466
-
467
- if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) {
468
- $configuration_check = $this->crawlers[self::REF_SHARE]->check_crawl_strategy_configurations( self::REF_SHARE_FACEBOOK );
469
-
470
- if ( ! $configuration_check ) {
471
- echo '<div class="error"><p>';
472
- _e( 'Configuratin is not enough to get share count. Please set required parameters at ', self::DOMAIN );
473
- echo '<a href="#share-base-cache-facebook">' . __( 'Share Base Cache - Facebook', self::DOMAIN ) . '</a>';
474
- echo '.</p></div>';
475
- }
476
- }
477
-
478
- if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) && $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) {
479
- $configuration_check = $this->crawlers[self::REF_FOLLOW]->check_crawl_strategy_configurations( self::REF_FOLLOW_INSTAGRAM);
480
-
481
- if ( ! $configuration_check ) {
482
- echo '<div class="error"><p>';
483
- _e( 'Configuratin is not enough to get follower count. Please set required parameters at ', self::DOMAIN );
484
- echo '<a href="#follow-base-cache-instagram">' . __( 'Follow Base Cache - Instagram', self::DOMAIN ) . '</a>';
485
- echo '.</p></div>';
486
- }
487
- }
488
-
489
- if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) {
490
- $configuration_check = $this->crawlers[self::REF_FOLLOW]->check_crawl_strategy_configurations( self::REF_FOLLOW_FACEBOOK );
491
-
492
- if ( ! $configuration_check ) {
493
- echo '<div class="error"><p>';
494
- _e( 'Configuratin is not enough to get follower count. Please set required parameters at ', self::DOMAIN );
495
- echo '<a href="#follow-base-cache-facebook">' . __( 'Follow Base Cache - Facebook', self::DOMAIN ) . '</a>';
496
- echo '.</p></div>';
497
- }
498
- }
499
-
500
- if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) && $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) {
501
- $configuration_check = $this->crawlers[self::REF_FOLLOW]->check_crawl_strategy_configurations( self::REF_FOLLOW_PUSH7 );
502
-
503
- if ( ! $configuration_check ) {
504
- echo '<div class="error"><p>';
505
- _e( 'Configuratin is not enough to get follower count. Please set required parameters at ', self::DOMAIN );
506
- echo '<a href="#follow-base-cache-push7">' . __( 'Follow Base Cache - Push7', self::DOMAIN ) . '</a>';
507
- echo '.</p></div>';
508
- }
509
- }
510
-
511
- if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) && $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) {
512
- $configuration_check = $this->crawlers[self::REF_FOLLOW]->check_crawl_strategy_configurations( self::REF_FOLLOW_TWITTER );
513
-
514
- if ( ! $configuration_check ) {
515
- echo '<div class="error"><p>';
516
- _e( 'Configuratin is not enough to get follower count. Please set required parameters at ', self::DOMAIN );
517
- echo '<a href="#follow-base-cache-twitter">' . __( 'Follow Base Cache - Twitter', self::DOMAIN ) . '</a>';
518
- echo '.</p></div>';
519
- }
520
- }
521
-
522
- ?>
523
-
524
- <div class="sns-cnt-cache">
525
- <h3 class="nav-tab-wrapper">
526
- <a class="nav-tab" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ); ?></a>
527
- <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a>
528
- <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
529
- <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
530
- <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
531
- <?php } ?>
532
- <a class="nav-tab nav-tab-active" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ); ?></a>
533
- <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
534
- </h3>
535
- <p id="options-menu">
536
- <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-fault-tolerance"><?php _e( 'Fault Tolerance', 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>
537
- </p>
538
- <div class="metabox-holder">
539
- <div id="current-parameter" class="postbox">
540
- <div class="handlediv" title="Click to toggle"><br></div>
541
- <h3 class="hndle"><span><?php _e( 'Current Setting', self::DOMAIN ); ?></span></h3>
542
- <div class="inside">
543
- <table class="view-table">
544
- <thead>
545
- <tr>
546
- <th><?php _e( 'Capability', self::DOMAIN ); ?></th>
547
- <th><?php _e( 'Parameter', self::DOMAIN ); ?></th>
548
- <th><?php _e( 'Value', self::DOMAIN ); ?></th>
549
- </tr>
550
- </thead>
551
- <tbody>
552
- <tr>
553
- <td><?php _e( 'Share Base Cache', self::DOMAIN); ?></td>
554
- <td><?php _e( 'Target SNS', self::DOMAIN ); ?></td>
555
- <td>
556
- <?php
557
- $target_sns = array();
558
-
559
- if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) {
560
- $target_sns[] = 'Facebook';
561
- }
562
- if ( isset( $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) && $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) {
563
- $target_sns[] = 'Google+';
564
- }
565
- if ( isset( $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) && $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) {
566
- $target_sns[] = __( 'Hatena Bookmark', self::DOMAIN );
567
- }
568
- /*
569
- if ( isset( $this->share_base_cache_target[self::REF_SHARE_LINKEDIN] ) && $this->share_base_cache_target[self::REF_SHARE_LINKEDIN] ) {
570
- $target_sns[] = 'Linkedin';
571
- }
572
- */
573
- if ( isset( $this->share_base_cache_target[self::REF_SHARE_PINTEREST] ) && $this->share_base_cache_target[self::REF_SHARE_PINTEREST] ) {
574
- $target_sns[] = 'Pinterest';
575
- }
576
- if ( isset( $this->share_base_cache_target[self::REF_SHARE_POCKET] ) && $this->share_base_cache_target[self::REF_SHARE_POCKET] ) {
577
- $target_sns[] = 'Pocket';
578
- }
579
- if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) {
580
- $target_sns[] = 'Twitter';
581
- }
582
- echo esc_html( implode( ", ", $target_sns ) );
583
- ?>
584
- </td>
585
- </tr>
586
- <tr>
587
- <td><?php _e( 'Share Base Cache', self::DOMAIN ); ?></td>
588
- <td><?php _e( 'Custom post types', self::DOMAIN ); ?></td>
589
- <td>
590
- <?php
591
- if ( ! empty( $this->share_base_custom_post_types ) && $this->share_base_custom_post_types ) {
592
- echo esc_html( implode( ',', $this->share_base_custom_post_types ) );
593
- } else {
594
- _e( 'N/A', self::DOMAIN );
595
- }
596
- ?>
597
- </td>
598
- </tr>
599
- <tr>
600
- <td><?php _e( 'Share Base Cache', self::DOMAIN ); ?></td>
601
- <td><?php _e( 'Interval cheking share count (sec)', self::DOMAIN ); ?></td>
602
- <td><?php echo esc_html( $this->share_base_check_interval ) . ' ' . __( 'seconds', self::DOMAIN ); ?></td>
603
- </tr>
604
- <tr>
605
- <td><?php _e( 'Share Base Cache', self::DOMAIN ); ?></td>
606
- <td><?php _e( 'Number of contents to check at a time', self::DOMAIN ) ?></td>
607
- <td><?php echo esc_html( $this->share_base_posts_per_check ) . ' ' . __( 'contents', self::DOMAIN ); ?></td>
608
- </tr>
609
- <tr>
610
- <td><?php _e( 'Share Base Cache', self::DOMAIN ); ?></td>
611
- <td><?php _e( 'Scheme migration mode from http to https', self::DOMAIN ); ?></td>
612
- <td>
613
- <?php
614
- if ( $this->scheme_migration_mode ) {
615
- _e( 'On', self::DOMAIN );
616
- } else {
617
- _e( 'Off', self::DOMAIN );
618
- }
619
- ?>
620
- </td>
621
- </tr>
622
- <?php if ( $this->scheme_migration_mode ) { ?>
623
- <tr>
624
- <td><?php _e( 'Share Base Cache', self::DOMAIN ); ?></td>
625
- <td><?php _e( 'Scheme migration date from http to https', self::DOMAIN ); ?></td>
626
- <td>
627
- <?php
628
- if ( isset( $this->scheme_migration_date ) ) {
629
- echo esc_html( $this->scheme_migration_date );
630
- } else {
631
- _e( 'N/A', self::DOMAIN );
632
- }
633
- ?>
634
- </td>
635
- </tr>
636
- <?php } ?>
637
-
638
- <?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) { ?>
639
- <tr>
640
- <td><?php _e( 'Share Base Cache - Twitter', self::DOMAIN ); ?></td>
641
- <td><?php _e( 'Alternative Twitter API', self::DOMAIN ); ?></td>
642
- <td>
643
- <?php
644
- if ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_JSOON ) {
645
- echo '<a href="' . esc_url( 'https://jsoon.digitiminimi.com/' ) . '" target="_blank">' . esc_html( 'widgetoon.js & count.jsoon' ) . '</a>';
646
- } elseif ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_OPENSHARECOUNT ) {
647
- echo '<a href="' . esc_url( 'https://opensharecount.com/' ) . '" target="_blank">' . esc_html( 'OpenShareCount' ) . '</a>';
648
- } elseif ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_TWITCOUNT ) {
649
- echo '<a href="' . esc_url( 'http://twitcount.com/' ) . '" target="_blank">' . esc_html( 'TwitCount' ) . '</a>';
650
- }
651
- ?>
652
- </td>
653
- </tr>
654
- <?php } ?>
655
- <tr>
656
- <td><?php _e( 'Share Rush Cache', self::DOMAIN ); ?></td>
657
- <td><?php _e( 'Term considering posted content as new content', self::DOMAIN ); ?></td>
658
- <td>
659
- <?php
660
- if ( $this->share_rush_new_content_term == 1 ) {
661
- echo esc_html( $this->share_rush_new_content_term ) . ' ' . __( 'day', self::DOMAIN );
662
- } elseif ( $this->share_rush_new_content_term > 1 ) {
663
- echo esc_html( $this->share_rush_new_content_term ) . ' ' . __( 'days', self::DOMAIN );
664
- }
665
- ?>
666
- </td>
667
- </tr>
668
- <tr>
669
- <td><?php _e( 'Share Rush Cache', self::DOMAIN ); ?></td>
670
- <td><?php _e( 'Interval cheking share count (sec)', self::DOMAIN ); ?></td>
671
- <td>
672
- <?php
673
- echo esc_html( $this->share_rush_check_interval ) . ' ' . __( 'seconds', self::DOMAIN );
674
- ?>
675
- </td>
676
- <tr>
677
- <td><?php _e( 'Share Rush Cache', self::DOMAIN ); ?></td>
678
- <td><?php _e( 'Number of contents to check at a time', self::DOMAIN ) ?></td>
679
- <td><?php echo esc_html( $this->share_rush_posts_per_check ) . ' ' . __( 'contents', self::DOMAIN ); ?></td>
680
- </tr>
681
- </tr>
682
- <tr>
683
- <td><?php _e( 'Share Variation Analysis', self::DOMAIN ); ?></td>
684
- <td><?php _e( 'Method to update basis of comparison', self::DOMAIN ); ?></td><td>
685
- <?php
686
- switch ( $this->share_variation_analysis_mode ) {
687
- case self::OPT_SHARE_VARIATION_ANALYSIS_NONE:
688
- _e( 'Disabled (None)', self::DOMAIN );
689
- break;
690
- case self::OPT_SHARE_VARIATION_ANALYSIS_MANUAL:
691
- _e( 'Enabled (Manual)', self::DOMAIN );
692
- break;
693
- case self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER:
694
- _e( 'Enabled (Scheduler)', self::DOMAIN );
695
- break;
696
- }
697
- ?>
698
- </td>
699
- </tr>
700
- <?php
701
- if ( $this->share_variation_analysis_mode === self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER ) {
702
- ?>
703
- <tr>
704
- <td><?php _e( 'Share Variation Analysis', self::DOMAIN ); ?></td>
705
- <td><?php _e( 'Schedule', self::DOMAIN ); ?></td>
706
- <td><?php echo esc_html( $this->share_variation_analysis_schedule ); ?></td>
707
- </tr>
708
- <?php
709
- }
710
- ?>
711
- <tr>
712
- <td><?php _e( 'Follow Base Cache', self::DOMAIN); ?></td>
713
- <td><?php _e( 'Target SNS', self::DOMAIN ); ?></td>
714
- <td>
715
- <?php
716
- $target_sns = array();
717
- if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) && $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) {
718
- $target_sns[] = 'Instagram';
719
- }
720
- if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) {
721
- $target_sns[] = 'Facebook';
722
- }
723
- if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) {
724
- $target_sns[] = 'Feedly';
725
- }
726
- if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) && $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) {
727
- $target_sns[] = 'Push7';
728
- }
729
- if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) && $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) {
730
- $target_sns[] = 'Twitter';
731
- }
732
- echo esc_html( implode( ', ', $target_sns ) );
733
- ?>
734
- </td>
735
- </tr>
736
- <tr>
737
- <td><?php _e( 'Follow Base Cache', self::DOMAIN ); ?></td>
738
- <td><?php _e( 'Interval cheking follower count (sec)', self::DOMAIN ); ?></td>
739
- <td><?php echo esc_html( $this->follow_base_check_interval ) . ' ' . __( 'seconds', self::DOMAIN ); ?></td>
740
- </tr>
741
- <?php if ( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) { ?>
742
- <tr>
743
- <td><?php _e( 'Follow Base Cache - Feedly', self::DOMAIN ); ?></td>
744
- <td><?php _e( 'Target feed type', self::DOMAIN ); ?></td>
745
- <td>
746
- <?php
747
- switch ( $this->follow_feed_type ) {
748
- case self::OPT_FEED_TYPE_DEFAULT:
749
- _e( 'Default', self::DOMAIN );
750
- break;
751
- case self::OPT_FEED_TYPE_RSS:
752
- _e( 'RSS', self::DOMAIN );
753
- break;
754
- case self::OPT_FEED_TYPE_RSS2:
755
- _e( 'RSS2', self::DOMAIN );
756
- break;
757
- case self::OPT_FEED_TYPE_RDF:
758
- _e( 'RDF', self::DOMAIN );
759
- break;
760
- case self::OPT_FEED_TYPE_ATOM:
761
- _e( 'ATOM', self::DOMAIN );
762
- break;
763
- default:
764
- _e( 'Default', self::DOMAIN );
765
- }
766
- ?>
767
- </td>
768
- </tr>
769
- <tr>
770
- <td><?php _e( 'Follow Base Cache - Feedly', self::DOMAIN ); ?></td>
771
- <td><?php _e( 'Target feed', self::DOMAIN ); ?></td>
772
- <td><a href="<?php echo esc_url( get_feed_link( $this->follow_feed_type ) ); ?>" target="_blank"><?php echo esc_html( get_feed_link( $this->follow_feed_type ) ); ?></a></td>
773
- </tr>
774
- <?php } ?>
775
- <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) && $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) { ?>
776
- <tr>
777
- <td><?php _e( 'Follow Base Cache - Twitter', self::DOMAIN ); ?></td>
778
- <td><?php _e( 'Target screen name', self::DOMAIN ); ?></td>
779
- <td>
780
- <?php
781
- if ( isset( $this->follow_twitter_screen_name ) ) {
782
- echo '@' . esc_html( $this->follow_twitter_screen_name );
783
- } else {
784
- _e( 'N/A', self::DOMAIN );
785
- }
786
- ?>
787
- </td>
788
- </tr>
789
- <?php } ?>
790
- <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) { ?>
791
- <tr>
792
- <td><?php _e( 'Follow Base Cache - Facebook', self::DOMAIN ); ?></td>
793
- <td><?php _e( 'Page ID', self::DOMAIN ); ?></td>
794
- <td>
795
- <?php
796
- if ( isset( $this->follow_facebook_page_id ) ) {
797
- echo esc_html( $this->follow_facebook_page_id );
798
- } else {
799
- _e( 'N/A', self::DOMAIN );
800
- }
801
- ?>
802
- </td>
803
- </tr>
804
- <?php } ?>
805
- <tr>
806
- <td><?php _e( 'Dynamic Cache', self::DOMAIN); ?></td>
807
- <td><?php _e( 'Dynamic caching based on user access', self::DOMAIN ); ?></td><td>
808
- <?php
809
- switch ( $this->dynamic_cache_mode ) {
810
- case self::OPT_COMMON_ACCESS_BASED_CACHE_OFF:
811
- _e( 'Disabled', self::DOMAIN );
812
- break;
813
- case self::OPT_COMMON_ACCESS_BASED_CACHE_ON:
814
- _e( 'Enabled', self::DOMAIN );
815
- break;
816
- default:
817
- _e( 'Disabled', self::DOMAIN );
818
- break;
819
- }
820
- ?>
821
- </td>
822
- </tr>
823
- <tr>
824
- <td><?php _e( 'Fault Tolerance', self::DOMAIN); ?></td>
825
- <td><?php _e( 'Fault tolerance of count retrieval', self::DOMAIN ); ?></td><td>
826
- <?php
827
- switch ( $this->fault_tolerance_mode ) {
828
- case self::OPT_COMMON_FAULT_TOLERANCE_OFF:
829
- _e( 'Disabled', self::DOMAIN );
830
- break;
831
- case self::OPT_COMMON_FAULT_TOLERANCE_ON:
832
- _e( 'Enabled', self::DOMAIN );
833
- break;
834
- default:
835
- _e( 'Disabled', self::DOMAIN );
836
- break;
837
- }
838
- ?>
839
- </td>
840
- </tr>
841
- <tr>
842
- <td><?php _e( 'Data Crawler', self::DOMAIN ); ?></td>
843
- <td><?php _e( 'Crawl method', self::DOMAIN ); ?></td>
844
- <td>
845
- <?php
846
- switch ( $this->crawler_method ) {
847
- case self::OPT_COMMON_CRAWLER_METHOD_NORMAL:
848
- _e( 'Normal (Sequential Retrieval)', self::DOMAIN );
849
- break;
850
- case self::OPT_COMMON_CRAWLER_METHOD_CURL:
851
- _e( 'Extended (Parallel Retrieval)', self::DOMAIN );
852
- break;
853
- }
854
- ?>
855
- </td>
856
- </tr>
857
- <tr>
858
- <td><?php _e( 'Data Crawler', self::DOMAIN ); ?></td>
859
- <td><?php _e( 'SSL verification', self::DOMAIN ); ?></td>
860
- <td>
861
- <?php
862
- if ( $this->crawler_ssl_verification ) {
863
- _e( 'On', self::DOMAIN );
864
- } else {
865
- _e( 'Off', self::DOMAIN );
866
- }
867
- ?>
868
- </td>
869
- </tr>
870
- <tr>
871
- <td><?php _e( 'Data Export', self::DOMAIN ); ?></td>
872
- <td><?php _e( 'Method of data export', self::DOMAIN ); ?></td><td>
873
- <?php
874
- switch ( $this->data_export_mode ) {
875
- case self::OPT_COMMON_DATA_EXPORT_MANUAL:
876
- _e( 'Manual', self::DOMAIN );
877
- break;
878
- case self::OPT_COMMON_DATA_EXPORT_SCHEDULER:
879
- _e( 'Scheduler', self::DOMAIN );
880
- break;
881
- }
882
- ?>
883
- </td>
884
- </tr>
885
- <?php
886
- if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_SCHEDULER ) {
887
- ?>
888
- <tr>
889
- <td><?php _e( 'Data Export', self::DOMAIN ); ?></td>
890
- <td><?php _e( 'Interval exporting share count to a csv file', self::DOMAIN ); ?></td>
891
- <td><?php echo esc_html( $this->data_export_interval / 3600 ) . ' ' . __( 'hours', self::DOMAIN ); ?></td>
892
- </tr>
893
- <?php
894
- }
895
- ?>
896
- </tbody>
897
- </table>
898
- </div>
899
- </div>
900
- </div>
901
- <div class="metabox-holder">
902
- <form action="admin.php?page=scc-setting" method="post">
903
- <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
904
- <div id="share-base-cache" class="postbox">
905
- <div class="handlediv" title="Click to toggle"><br></div>
906
- <h3 class="hndle"><span><?php _e('Share Base Cache', self::DOMAIN); ?></span></h3>
907
- <div class="inside">
908
- <table class="form-table">
909
- <tr>
910
- <th><label><?php _e( 'Target SNS', self::DOMAIN ); ?></label></th>
911
- <td>
912
- <div class="sns-check">
913
- <input type="checkbox" value="1" name="share_base_cache_target_facebook"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) echo ' checked="checked"'; ?> />
914
- <label><?php _e( 'Facebook', self::DOMAIN ); ?></label>
915
- </div>
916
- <div class="sns-check">
917
- <input type="checkbox" value="1" name="share_base_cache_target_gplus"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) && $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) echo ' checked="checked"'; ?> />
918
- <label><?php _e( 'Google+', self::DOMAIN ); ?></label>
919
- </div>
920
- <div class="sns-check">
921
- <input type="checkbox" value="1" name="share_base_cache_target_hatebu"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) && $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) echo ' checked="checked"'; ?> />
922
- <label><?php _e( 'Hatena Bookmark', self::DOMAIN ); ?></label>
923
- </div>
924
- <div class="sns-check">
925
- <input type="checkbox" value="1" name="share_base_cache_target_pinterest"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_PINTEREST] ) && $this->share_base_cache_target[self::REF_SHARE_PINTEREST] ) echo ' checked="checked"'; ?> />
926
- <label><?php _e( 'Pinterest', self::DOMAIN ); ?></label>
927
- </div>
928
- <div class="sns-check">
929
- <input type="checkbox" value="1" name="share_base_cache_target_pocket"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_POCKET] ) && $this->share_base_cache_target[self::REF_SHARE_POCKET] ) echo ' checked="checked"'; ?> />
930
- <label><?php _e( 'Pocket', self::DOMAIN ); ?></label>
931
- </div>
932
- <div class="sns-check">
933
- <input type="checkbox" value="1" name="share_base_cache_target_twitter"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) echo ' checked="checked"'; ?> />
934
- <label><?php _e( 'Twitter', self::DOMAIN ); ?></label>
935
- </div>
936
- </td>
937
- </tr>
938
- <tr>
939
- <th><label><?php _e( 'Custom post types', self::DOMAIN ); ?></label></th>
940
- <td>
941
- <input type="text" class="text" name="share_base_custom_post_types" size="60" value="<?php echo esc_attr( implode( ',', $this->share_base_custom_post_types ) ); ?>" />
942
- <br>
943
- <label><?php _e( 'e.g. aaa, bbb, ccc (comma-delimited)', self::DOMAIN ); ?></label>
944
- </td>
945
- </tr>
946
- <tr>
947
- <th><label><?php _e( 'Interval cheking share count (sec)', self::DOMAIN ); ?></label></th>
948
- <td>
949
- <input type="text" class="text" name="share_base_check_interval" size="20" value="<?php echo esc_attr( $this->share_base_check_interval ); ?>" />
950
- <label><?php _e( 'Default: 600', self::DOMAIN ); ?></label>
951
- </td>
952
- </tr>
953
- <tr>
954
- <th><label><?php _e( 'Number of contents to check at a time', self::DOMAIN ); ?></label></th>
955
- <td>
956
- <input type="text" class="text" name="share_base_posts_per_check" size="20" value="<?php echo esc_attr( $this->share_base_posts_per_check ); ?>" />
957
- <label><?php _e( 'Default: 20', self::DOMAIN ); ?></label>
958
- </td>
959
- </tr>
960
- <tr>
961
- <th><label><?php _e( 'Scheme migration mode from http to https', self::DOMAIN ); ?></label></th>
962
- <td>
963
- <select name="scheme_migration_mode">
964
- <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>
965
- <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>
966
- </select>
967
- <label><?php _e('Default: Off', self::DOMAIN ); ?></label>
968
- </td>
969
- </tr>
970
- <?php if ( $this->scheme_migration_mode ) { ?>
971
- <tr>
972
- <th><label><?php _e( 'Scheme migration date from http to https', self::DOMAIN ); ?></label></th>
973
- <td>
974
- <input id="scheme-migration-date" type="text" class="text" name="scheme_migration_date" size="20" value="<?php echo esc_attr( $this->scheme_migration_date ); ?>" />
975
- <label><?php _e( 'Default: N/A', self::DOMAIN ); ?></label>
976
- <script>
977
- jQuery(document).ready(function() {
978
- jQuery('#scheme-migration-date').datepicker({
979
- dateFormat : 'yy/mm/dd'
980
- });
981
- });
982
- </script>
983
- </td>
984
- </tr>
985
- <?php } ?>
986
- </table>
987
- <div class="submit-button">
988
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
989
- <input type="submit" class="button button-secondary" name="clear_share_base_cache" value="<?php _e( 'Clear Cache', self::DOMAIN ); ?>">
990
- </div>
991
- </div>
992
- </div>
993
- <?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) { ?>
994
- <div id="share-base-cache-facebook" class="postbox">
995
- <div class="handlediv" title="Click to toggle"><br></div>
996
- <h3 class="hndle"><span><?php _e( 'Share Base Cache - Facebook', self::DOMAIN ); ?></span></h3>
997
- <div class="inside">
998
- <table class="form-table">
999
- <tr>
1000
- <th><label><?php _e( 'App ID (Client ID)', self::DOMAIN ); ?></label></th>
1001
- <td>
1002
- <input type="password" class="text" name="share_facebook_app_id" size="60" value="<?php echo esc_attr( $this->share_facebook_app_id ); ?>" />
1003
- <br>
1004
- <label><?php _e( 'Facebook app ID for OAuth', self::DOMAIN ); ?></label>
1005
- </td>
1006
- </tr>
1007
- <tr>
1008
- <th><label><?php _e( 'App secret (Client secret)', self::DOMAIN ); ?></label></th>
1009
- <td>
1010
- <input type="password" class="text" name="share_facebook_app_secret" size="60" value="<?php echo esc_attr( $this->share_facebook_app_secret ); ?>" />
1011
- <br>
1012
- <label><?php _e( 'Facebook app secret for OAuth', self::DOMAIN ); ?></label>
1013
- </td>
1014
- </tr>
1015
- <?php if ( isset( $this->share_facebook_app_id ) && $this->share_facebook_app_id && isset( $this->share_facebook_app_secret ) && $this->share_facebook_app_secret ) { ?>
1016
- <tr>
1017
- <th><label><?php _e( 'Access token', self::DOMAIN ); ?></label></th>
1018
- <td>
1019
- <input type="password" class="text" name="tmp_share_facebook_access_token" size="60" value="<?php echo esc_attr( $this->share_facebook_access_token ); ?>" readonly />
1020
- <br>
1021
- <label><?php _e( 'Facebook access token for OAuth', self::DOMAIN ); ?></label>
1022
- </td>
1023
- </tr>
1024
- <?php } ?>
1025
- </table>
1026
- <div class="submit-button">
1027
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1028
- </div>
1029
- </div>
1030
- </div>
1031
- <?php } ?>
1032
- <?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) { ?>
1033
- <div id="share-base-cache-twitter" class="postbox">
1034
- <div class="handlediv" title="Click to toggle"><br></div>
1035
- <h3 class="hndle"><span><?php _e( 'Share Base Cache - Twitter', self::DOMAIN ); ?></span></h3>
1036
- <div class="inside">
1037
- <table class="form-table">
1038
- <tr>
1039
- <th><label><?php _e( 'Alternative Twitter API', self::DOMAIN ); ?></label></th>
1040
- <td>
1041
- <select name="share_alternative_twitter_api">
1042
- <option value="1"<?php if ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_JSOON ) echo ' selected="selected"'; ?>><?php echo esc_html( 'widgetoon.js & count.jsoon' ); ?></option>
1043
- <option value="2"<?php if ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_OPENSHARECOUNT ) echo ' selected="selected"'; ?>><?php echo esc_html( 'OpenShareCount' ); ?></option>
1044
- <option value="3"<?php if ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_TWITCOUNT ) echo ' selected="selected"'; ?>><?php echo esc_html( 'TwitCount' ); ?></option>
1045
- </select>
1046
- <label><?php _e( 'Default: ', self::DOMAIN ); echo esc_html( 'widgetoon.js & count.jsoon' ); ?></label>
1047
- </td>
1048
- </tr>
1049
- <tr>
1050
- <th><label><?php _e( 'Registration destination', self::DOMAIN ); ?></label></th>
1051
- <td>
1052
- <?php
1053
- if ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_JSOON ) {
1054
- echo '<a href="' . esc_url( 'https://jsoon.digitiminimi.com/' ) . '" target="_blank">' . esc_html( 'https://jsoon.digitiminimi.com/' ) . '</a>';
1055
- } elseif ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_OPENSHARECOUNT ) {
1056
- echo '<a href="' . esc_url( 'https://opensharecount.com/' ) . '" target="_blank">' . esc_html( 'https://opensharecount.com/' ) . '</a>';
1057
- } elseif ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_TWITCOUNT ) {
1058
- echo '<a href="' . esc_url( 'http://twitcount.com/' ) . '" target="_blank">' . esc_html( 'http://twitcount.com/' ) . '</a>';
1059
- }
1060
- ?>
1061
- <br />
1062
- <label><?php _e( 'You need to register information such as your domain with the above site in order to start counting.', self::DOMAIN ); ?></label>
1063
- </td>
1064
- </tr>
1065
- </table>
1066
- <div class="submit-button">
1067
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1068
- </div>
1069
- </div>
1070
- </div>
1071
- <?php } ?>
1072
- <div id="share-rush-cache" class="postbox">
1073
- <div class="handlediv" title="Click to toggle"><br></div>
1074
- <h3 class="hndle"><span><?php _e( 'Share Rush Cache', self::DOMAIN); ?></span></h3>
1075
- <div class="inside">
1076
- <table class="form-table">
1077
- <tr>
1078
- <th><label><?php _e( 'Term considering posted content as new content', self::DOMAIN ); ?></label></th>
1079
- <td>
1080
- <select name="share_rush_new_content_term">
1081
- <option value="1"<?php if ( $this->share_rush_new_content_term === 1 ) echo ' selected="selected"'; ?>><?php _e( '1 day', self::DOMAIN ); ?></option>
1082
- <option value="2"<?php if ( $this->share_rush_new_content_term === 2 ) echo ' selected="selected"'; ?>><?php _e( '2 days', self::DOMAIN ); ?></option>
1083
- <option value="3"<?php if ( $this->share_rush_new_content_term === 3 ) echo ' selected="selected"'; ?>><?php _e( '3 days', self::DOMAIN ); ?></option>
1084
- <option value="4"<?php if ( $this->share_rush_new_content_term === 4 ) echo ' selected="selected"'; ?>><?php _e( '4 days', self::DOMAIN ); ?></option>
1085
- <option value="5"<?php if ( $this->share_rush_new_content_term === 5 ) echo ' selected="selected"'; ?>><?php _e( '5 days', self::DOMAIN ); ?></option>
1086
- <option value="6"<?php if ( $this->share_rush_new_content_term === 6 ) echo ' selected="selected"'; ?>><?php _e( '6 days', self::DOMAIN ); ?></option>
1087
- <option value="7"<?php if ( $this->share_rush_new_content_term === 7 ) echo ' selected="selected"'; ?>><?php _e( '7 days', self::DOMAIN ); ?></option>
1088
- <option value="8"<?php if ( $this->share_rush_new_content_term === 8 ) echo ' selected="selected"'; ?>><?php _e( '8 days', self::DOMAIN ); ?></option>
1089
- <option value="9"<?php if ( $this->share_rush_new_content_term === 9 ) echo ' selected="selected"'; ?>><?php _e( '9 days', self::DOMAIN ); ?></option>
1090
- <option value="10"<?php if ( $this->share_rush_new_content_term === 10 ) echo ' selected="selected"'; ?>><?php _e( '10 days', self::DOMAIN ); ?></option>
1091
- <option value="11"<?php if ( $this->share_rush_new_content_term === 11 ) echo ' selected="selected"'; ?>><?php _e( '11 days', self::DOMAIN ); ?></option>
1092
- <option value="12"<?php if ( $this->share_rush_new_content_term === 12 ) echo ' selected="selected"'; ?>><?php _e( '12 days', self::DOMAIN ); ?></option>
1093
- <option value="13"<?php if ( $this->share_rush_new_content_term === 13 ) echo ' selected="selected"'; ?>><?php _e( '13 days', self::DOMAIN ); ?></option>
1094
- <option value="14"<?php if ( $this->share_rush_new_content_term === 14 ) echo ' selected="selected"'; ?>><?php _e( '14 days', self::DOMAIN ); ?></option>
1095
- </select>
1096
- <label><?php _e( 'Default: 3 days', self::DOMAIN ); ?></label>
1097
- </td>
1098
- </tr>
1099
- <tr>
1100
- <th><label><?php _e( 'Interval cheking share count (sec)', self::DOMAIN ); ?></label></th>
1101
- <td>
1102
- <input type="text" class="text" name="share_rush_check_interval" size="20" value="<?php echo esc_attr( $this->share_rush_check_interval ); ?>" />
1103
- <label><?php _e( 'Default: 600', self::DOMAIN ); ?></label>
1104
- </td>
1105
- </tr>
1106
- <tr>
1107
- <th><label><?php _e( 'Number of contents to check at a time', self::DOMAIN ); ?></label></th>
1108
- <td>
1109
- <input type="text" class="text" name="share_rush_posts_per_check" size="20" value="<?php echo esc_attr( $this->share_rush_posts_per_check ); ?>" />
1110
- <label><?php _e( 'Default: 20', self::DOMAIN ); ?></label>
1111
- </td>
1112
- </tr>
1113
- </table>
1114
- <div class="submit-button">
1115
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1116
- </div>
1117
- </div>
1118
- </div>
1119
- <div id="share-variation-analysis" class="postbox">
1120
- <div class="handlediv" title="Click to toggle"><br></div>
1121
- <h3 class="hndle"><span><?php _e( 'Share Variation Analysis', self::DOMAIN ); ?></span></h3>
1122
- <div class="inside">
1123
- <table class="form-table">
1124
- <tr>
1125
- <th><label><?php _e( 'Method to update basis of comparison', self::DOMAIN ); ?></label></th>
1126
- <td>
1127
- <select name="share_variation_analysis_mode">
1128
- <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>
1129
- <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>
1130
- <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>
1131
- </select>
1132
- <label><?php _e( 'Default: None', self::DOMAIN ); ?></label>
1133
- </td>
1134
- </tr>
1135
- <?php
1136
- if ( $this->share_variation_analysis_mode === self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER ) {
1137
- list( $cronstr['minutes'], $cronstr['hours'], $cronstr['mday'], $cronstr['mon'], $cronstr['wday'] ) = explode( ' ', $this->share_variation_analysis_schedule, 5 );
1138
- if ( strstr( $cronstr['minutes'], '*/' ) ) {
1139
- $minutes = explode( '/', $cronstr['minutes'] );
1140
- } else {
1141
- $minutes = explode( ',', $cronstr['minutes'] );
1142
- }
1143
- if ( strstr( $cronstr['hours'], '*/' ) ) {
1144
- $hours = explode( '/', $cronstr['hours'] );
1145
- } else {
1146
- $hours = explode( ',', $cronstr['hours'] );
1147
- }
1148
- if ( strstr( $cronstr['mday'], '*/' ) ) {
1149
- $mday = explode( '/', $cronstr['mday'] );
1150
- } else {
1151
- $mday = explode( ',', $cronstr['mday'] );
1152
- }
1153
- if ( strstr( $cronstr['mon'], '*/' ) ) {
1154
- $mon = explode( '/', $cronstr['mon'] );
1155
- } else {
1156
- $mon = explode( ',', $cronstr['mon'] );
1157
- }
1158
- if ( strstr( $cronstr['wday'], '*/' ) ) {
1159
- $wday = explode( '/', $cronstr['wday'] );
1160
- } else {
1161
- $wday = explode( ',', $cronstr['wday'] );
1162
- }
1163
- ?>
1164
- <tr class="a_wpcron">
1165
- <th scope="row"><?php _e( 'Scheduler', self::DOMAIN ); ?></th>
1166
- <td>
1167
- <table class="wpcron">
1168
- <tr>
1169
- <th>
1170
- <?php _e( 'Type', self::DOMAIN ); ?>
1171
- </th>
1172
- <th>
1173
- </th>
1174
- <th>
1175
- <?php _e( 'Hour', self::DOMAIN ); ?>
1176
- </th>
1177
- <th>
1178
- <?php _e( 'Minute', self::DOMAIN ); ?>
1179
- </th>
1180
- </tr>
1181
- <tr>
1182
- <td>
1183
- <label for="idcronbtype-mon">
1184
- <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $mday[0] ), FALSE ) . ' name="a_cronbtype" value="mon" /> ' . __( 'monthly', self::DOMAIN ); ?>
1185
- </label>
1186
- </td>
1187
- <td>
1188
- <select name="a_moncronmday">
1189
- <?php
1190
- for ( $i = 1; $i <= 31; $i ++ ) {
1191
- $on_day = '';
1192
-
1193
- switch ( $i ) {
1194
- case 1:
1195
- $on_day = __( 'on 1.', self::DOMAIN );
1196
- break;
1197
- case 2:
1198
- $on_day = __( 'on 2.', self::DOMAIN );
1199
- break;
1200
- case 3:
1201
- $on_day = __( 'on 3.', self::DOMAIN );
1202
- break;
1203
- case 4:
1204
- $on_day = __( 'on 4.', self::DOMAIN );
1205
- break;
1206
- case 5:
1207
- $on_day = __( 'on 5.', self::DOMAIN );
1208
- break;
1209
- case 6:
1210
- $on_day = __( 'on 6.', self::DOMAIN );
1211
- break;
1212
- case 7:
1213
- $on_day = __( 'on 7.', self::DOMAIN );
1214
- break;
1215
- case 8:
1216
- $on_day = __( 'on 8.', self::DOMAIN );
1217
- break;
1218
- case 9:
1219
- $on_day = __( 'on 9.', self::DOMAIN );
1220
- break;
1221
- case 10:
1222
- $on_day = __( 'on 10.', self::DOMAIN );
1223
- break;
1224
- case 11:
1225
- $on_day = __( 'on 11.', self::DOMAIN );
1226
- break;
1227
- case 12:
1228
- $on_day = __( 'on 12.', self::DOMAIN );
1229
- break;
1230
- case 13:
1231
- $on_day = __( 'on 13.', self::DOMAIN );
1232
- break;
1233
- case 14:
1234
- $on_day = __( 'on 14.', self::DOMAIN );
1235
- break;
1236
- case 15:
1237
- $on_day = __( 'on 15.', self::DOMAIN );
1238
- break;
1239
- case 16:
1240
- $on_day = __( 'on 16.', self::DOMAIN );
1241
- break;
1242
- case 17:
1243
- $on_day = __( 'on 17.', self::DOMAIN );
1244
- break;
1245
- case 18:
1246
- $on_day = __( 'on 18.', self::DOMAIN );
1247
- break;
1248
- case 19:
1249
- $on_day = __( 'on 19.', self::DOMAIN );
1250
- break;
1251
- case 20:
1252
- $on_day = __( 'on 20.', self::DOMAIN );
1253
- break;
1254
- case 21:
1255
- $on_day = __( 'on 21.', self::DOMAIN );
1256
- break;
1257
- case 22:
1258
- $on_day = __( 'on 22.', self::DOMAIN );
1259
- break;
1260
- case 23:
1261
- $on_day = __( 'on 23.', self::DOMAIN );
1262
- break;
1263
- case 24:
1264
- $on_day = __( 'on 24.', self::DOMAIN );
1265
- break;
1266
- case 25:
1267
- $on_day = __( 'on 25.', self::DOMAIN );
1268
- break;
1269
- case 26:
1270
- $on_day = __( 'on 26.', self::DOMAIN );
1271
- break;
1272
- case 27:
1273
- $on_day = __( 'on 27.', self::DOMAIN );
1274
- break;
1275
- case 28:
1276
- $on_day = __( 'on 28.', self::DOMAIN );
1277
- break;
1278
- case 29:
1279
- $on_day = __( 'on 29.', self::DOMAIN );
1280
- break;
1281
- case 30:
1282
- $on_day = __( 'on 30.', self::DOMAIN );
1283
- break;
1284
- case 31:
1285
- $on_day = __( 'on 31.', self::DOMAIN );
1286
- break;
1287
- }
1288
-
1289
- echo '<option ' . selected( in_array( "$i", $mday, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $on_day . '</option>';
1290
- }
1291
- ?>
1292
- </select>
1293
- </td>
1294
- <td>
1295
- <select name="a_moncronhours">
1296
- <?php for ( $i = 0; $i < 24; $i ++ ) {
1297
- echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1298
- } ?>
1299
- </select>
1300
- </td>
1301
- <td>
1302
- <select name="a_moncronminutes">
1303
- <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
1304
- echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1305
- } ?>
1306
- </select>
1307
- </td>
1308
- </tr>
1309
- <tr>
1310
- <td>
1311
- <label for="idcronbtype-week">
1312
- <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $wday[0] ), FALSE ) . ' name="a_cronbtype" value="week" /> ' . __( 'weekly', self::DOMAIN ); ?>
1313
- </label>
1314
- </td>
1315
- <td>
1316
- <select name="a_weekcronwday">
1317
- <?php
1318
- echo '<option ' . selected( in_array( '0', $wday, TRUE ), TRUE, FALSE ) . ' value="0" />' . __( 'Sunday', self::DOMAIN ) . '</option>';
1319
- echo '<option ' . selected( in_array( '1', $wday, TRUE ), TRUE, FALSE ) . ' value="1" />' . __( 'Monday', self::DOMAIN ) . '</option>';
1320
- echo '<option ' . selected( in_array( '2', $wday, TRUE ), TRUE, FALSE ) . ' value="2" />' . __( 'Tuesday', self::DOMAIN ) . '</option>';
1321
- echo '<option ' . selected( in_array( '3', $wday, TRUE ), TRUE, FALSE ) . ' value="3" />' . __( 'Wednesday', self::DOMAIN ) . '</option>';
1322
- echo '<option ' . selected( in_array( '4', $wday, TRUE ), TRUE, FALSE ) . ' value="4" />' . __( 'Thursday', self::DOMAIN ) . '</option>';
1323
- echo '<option ' . selected( in_array( '5', $wday, TRUE ), TRUE, FALSE ) . ' value="5" />' . __( 'Friday', self::DOMAIN ) . '</option>';
1324
- echo '<option ' . selected( in_array( '6', $wday, TRUE ), TRUE, FALSE ) . ' value="6" />' . __( 'Saturday', self::DOMAIN ) . '</option>';
1325
- ?>
1326
- </select>
1327
- </td>
1328
- <td>
1329
- <select name="a_weekcronhours">
1330
- <?php for ( $i = 0; $i < 24; $i ++ ) {
1331
- echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1332
- } ?>
1333
- </select>
1334
- </td>
1335
- <td>
1336
- <select name="a_weekcronminutes">
1337
- <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
1338
- echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1339
- } ?>
1340
- </select>
1341
- </td>
1342
- </tr>
1343
- <tr>
1344
- <td>
1345
- <label for="idcronbtype-day">
1346
- <?php echo '<input class="radio" type="radio"' . checked( "**", $mday[0] . $wday[0], FALSE ) . ' name="a_cronbtype" value="day" /> ' . __( 'daily', self::DOMAIN ); ?>
1347
- </label>
1348
- </td>
1349
- <td>
1350
- </td>
1351
- <td>
1352
- <select name="a_daycronhours">
1353
- <?php
1354
- for ( $i = 0; $i < 24; $i ++ ) {
1355
- echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1356
- }
1357
- ?>
1358
- </select>
1359
- </td>
1360
- <td>
1361
- <select name="a_daycronminutes">
1362
- <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
1363
- echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1364
- } ?>
1365
- </select>
1366
- </td>
1367
- </tr>
1368
- </table>
1369
- </td>
1370
- </tr>
1371
- <?php
1372
- }
1373
- ?>
1374
- </table>
1375
- <div class="submit-button">
1376
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1377
- <input type="submit" class="button button-secondary" name="update_share_comparison_base" value="<?php _e( 'Update Basis of Comparison', self::DOMAIN ); ?>" />
1378
- </div>
1379
- </div>
1380
- </div>
1381
- <div id="follow-base-cache" class="postbox">
1382
- <div class="handlediv" title="Click to toggle"><br></div>
1383
- <h3 class="hndle"><span><?php _e( 'Follow Base Cache', self::DOMAIN ); ?></span></h3>
1384
- <div class="inside">
1385
- <table class="form-table">
1386
- <tr>
1387
- <th><label><?php _e( 'Target SNS', self::DOMAIN ); ?></label></th>
1388
- <td>
1389
- <div class="sns-check">
1390
- <input type="checkbox" value="1" name="follow_base_cache_target_instagram"<?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) && $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) echo ' checked="checked"'; ?> />
1391
- <label><?php _e( 'Instagram', self::DOMAIN ); ?></label>
1392
- </div>
1393
- <div class="sns-check">
1394
- <input type="checkbox" value="1" name="follow_base_cache_target_facebook"<?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) echo ' checked="checked"'; ?> />
1395
- <label><?php _e( 'Facebook', self::DOMAIN ); ?></label>
1396
- </div>
1397
- <div class="sns-check">
1398
- <input type="checkbox" value="1" name="follow_base_cache_target_feedly"<?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) echo ' checked="checked"'; ?> />
1399
- <label><?php _e( 'Feedly', self::DOMAIN ); ?></label>
1400
- </div>
1401
- <div class="sns-check">
1402
- <input type="checkbox" value="1" name="follow_base_cache_target_push7"<?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) && $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) echo ' checked="checked"'; ?> />
1403
- <label><?php _e( 'Push7', self::DOMAIN ); ?></label>
1404
- </div>
1405
- <div class="sns-check">
1406
- <input type="checkbox" value="1" name="follow_base_cache_target_twitter"<?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) && $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) echo ' checked="checked"'; ?> />
1407
- <label><?php _e( 'Twitter', self::DOMAIN ); ?></label>
1408
- </div>
1409
- </td>
1410
- </tr>
1411
- <tr>
1412
- <th><label><?php _e( 'Interval cheking follower count (sec)', self::DOMAIN ); ?></label></th>
1413
- <td>
1414
- <input type="text" class="text" name="follow_base_check_interval" size="20" value="<?php echo esc_attr( $this->follow_base_check_interval); ?>" />
1415
- <label><?php _e( 'Default: 86400 Minimum: 3600', self::DOMAIN ); ?></label>
1416
- </td>
1417
- </tr>
1418
- </table>
1419
- <div class="submit-button">
1420
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1421
- <input type="submit" class="button button-secondary" name="direct_follow_base_cache" value="<?php _e( 'Cache', self::DOMAIN ); ?>">
1422
- <input type="submit" class="button button-secondary" name="clear_follow_base_cache" value="<?php _e( 'Clear Cache', self::DOMAIN ); ?>">
1423
- </div>
1424
- </div>
1425
- </div>
1426
- <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) && $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) { ?>
1427
- <div id="follow-base-cache-instagram" class="postbox">
1428
- <div class="handlediv" title="Click to toggle"><br></div>
1429
- <h3 class="hndle"><span><?php _e( 'Follow Base Cache - Instagram', self::DOMAIN ); ?></span></h3>
1430
- <div class="inside">
1431
- <table class="form-table">
1432
- <tr>
1433
- <th><label><?php _e( 'Client ID', self::DOMAIN ); ?></label></th>
1434
- <td>
1435
- <input type="password" class="text" name="follow_instagram_client_id" size="60" value="<?php echo esc_attr( $this->follow_instagram_client_id ); ?>" />
1436
- <br>
1437
- <label><?php _e( 'Instagram client ID for OAuth', self::DOMAIN ); ?></label>
1438
- </td>
1439
- </tr>
1440
- <tr>
1441
- <th><label><?php _e( 'Client secret', self::DOMAIN ); ?></label></th>
1442
- <td>
1443
- <input type="password" class="text" name="follow_instagram_client_secret" size="60" value="<?php echo esc_attr( $this->follow_instagram_client_secret ); ?>" />
1444
- <br>
1445
- <label><?php _e( 'Instagram client secret for OAuth', self::DOMAIN ); ?></label>
1446
- </td>
1447
- </tr>
1448
- <tr>
1449
- <th><label><?php _e( 'Redirect URI', self::DOMAIN ); ?></label></th>
1450
- <td>
1451
- <input type="text" class="text" name="tmp_follow_instagram_redirect_uri" size="60" value="<?php echo esc_url( plugins_url() . '/sns-count-cache/' ); ?>" onclick="this.focus();this.select()" title="<?php _e( 'To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac).', self::DOMAIN ); ?>" readonly />
1452
- <br>
1453
- <label><?php _e( 'Copy and set this to the field of "Valid redirect URIs" in the client management page of Instagram developer page.', self::DOMAIN ); ?></label>
1454
- </td>
1455
- </tr>
1456
- <?php if ( isset( $_GET['action'] ) && $_GET['action'] && $_GET['action'] === 'instagram-auth' ) { ?>
1457
- <tr>
1458
- <th><label><?php _e( 'Access token', self::DOMAIN ); ?></label></th>
1459
- <td>
1460
- <input type="text" class="text" name="tmp_follow_instagram_access_token" size="60" value="<?php echo esc_attr( $tmp_instagram_access_token ); ?>" onclick="this.focus();this.select()" title="<?php _e( 'To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac).', self::DOMAIN ); ?>" readonly />
1461
- <br>
1462
- <label><?php _e( 'Copy and pase this into the fields below.', self::DOMAIN ); ?></label>
1463
- </td>
1464
- </tr>
1465
- <?php } ?>
1466
- <?php if ( isset( $this->follow_instagram_client_id ) && $this->follow_instagram_client_id && isset( $this->follow_instagram_client_secret ) && $this->follow_instagram_client_secret ) { ?>
1467
- <tr>
1468
- <th><label><?php _e( 'Access token', self::DOMAIN ); ?></label></th>
1469
- <td>
1470
- <input type="password" class="text" name="follow_instagram_access_token" size="60" value="<?php echo esc_attr( $this->follow_instagram_access_token ); ?>" />
1471
- <br>
1472
- <label><?php _e( 'Instagram access token for OAuth', self::DOMAIN ); ?></label>
1473
- </td>
1474
- </tr>
1475
- <?php } ?>
1476
- </table>
1477
- <div class="submit-button">
1478
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1479
- <?php if ( isset( $this->follow_instagram_client_id ) && $this->follow_instagram_client_id && isset( $this->follow_instagram_client_secret ) && $this->follow_instagram_client_secret ) { ?>
1480
- <a href="https://api.instagram.com/oauth/authorize/?client_id=<?php echo esc_attr( $this->follow_instagram_client_id ); ?>&response_type=code&state=<?php echo wp_create_nonce( 'instagram-auth' ); ?>&redirect_uri=<?php echo plugins_url() . '/sns-count-cache/'; ?>?action=instagram-auth" class="button button-secondary"><?php _e( 'Get Access Token', self::DOMAIN ); ?></a>
1481
- <?php } ?>
1482
- </div>
1483
- </div>
1484
- </div>
1485
- <?php } ?>
1486
- <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) { ?>
1487
- <div id="follow-base-cache-facebook" class="postbox">
1488
- <div class="handlediv" title="Click to toggle"><br></div>
1489
- <h3 class="hndle"><span><?php _e( 'Follow Base Cache - Facebook', self::DOMAIN ); ?></span></h3>
1490
- <div class="inside">
1491
- <table class="form-table">
1492
- <tr>
1493
- <th><label><?php _e( 'Page ID', self::DOMAIN ); ?></label></th>
1494
- <td>
1495
- <input type="text" class="text" name="follow_facebook_page_id" size="30" value="<?php echo esc_attr( $this->follow_facebook_page_id ); ?>" />
1496
- <br>
1497
- <label><?php _e( 'Facebook page ID that you want to get follower count', self::DOMAIN ); ?></label>
1498
- </td>
1499
- </tr>
1500
- <tr>
1501
- <th><label><?php _e( 'App ID (Client ID)', self::DOMAIN ); ?></label></th>
1502
- <td>
1503
- <input type="password" class="text" name="follow_facebook_app_id" size="60" value="<?php echo esc_attr( $this->follow_facebook_app_id ); ?>" />
1504
- <br>
1505
- <label><?php _e( 'Facebook app ID for OAuth', self::DOMAIN ); ?></label>
1506
- </td>
1507
- </tr>
1508
- <tr>
1509
- <th><label><?php _e( 'App secret (Client secret)', self::DOMAIN ); ?></label></th>
1510
- <td>
1511
- <input type="password" class="text" name="follow_facebook_app_secret" size="60" value="<?php echo esc_attr( $this->follow_facebook_app_secret ); ?>" />
1512
- <br>
1513
- <label><?php _e( 'Facebook app secret for OAuth', self::DOMAIN ); ?></label>
1514
- </td>
1515
- </tr>
1516
- <tr>
1517
- <th><label><?php _e( 'Redirect URI', self::DOMAIN ); ?></label></th>
1518
- <td>
1519
- <input type="text" class="text" name="tmp_follow_facebook_redirect_uri" size="60" value="<?php echo esc_url( plugins_url() . '/sns-count-cache/' ); ?>" onclick="this.focus();this.select()" title="<?php _e( 'To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac).', self::DOMAIN ); ?>" readonly />
1520
- <br>
1521
- <label><?php _e( 'Copy and set this to the field of "Valid OAuth redirect URIs" in client management page of Facebook developer page', self::DOMAIN ); ?></label>
1522
- </td>
1523
- </tr>
1524
- <?php if ( isset( $_GET['action'] ) && $_GET['action'] && $_GET['action'] === 'facebook-auth' ) { ?>
1525
- <tr>
1526
- <th><label><?php _e( 'Access token', self::DOMAIN ); ?></label></th>
1527
- <td>
1528
- <input type="text" class="text" name="tmp_follow_facebook_access_token" size="60" value="<?php echo esc_attr( $tmp_facebook_access_token ); ?>" onclick="this.focus();this.select()" title="<?php _e( 'To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac).', self::DOMAIN ); ?>" readonly />
1529
- <br>
1530
- <label><?php _e( 'Copy and pase this into the fields below.', self::DOMAIN ); ?></label>
1531
- </td>
1532
- </tr>
1533
- <?php } ?>
1534
- <?php if ( isset( $this->follow_facebook_app_id ) && $this->follow_facebook_app_id && isset( $this->follow_facebook_app_secret ) && $this->follow_facebook_app_secret ) { ?>
1535
- <tr>
1536
- <th><label><?php _e( 'Access token', self::DOMAIN ); ?></label></th>
1537
- <td>
1538
- <input type="password" class="text" name="follow_facebook_access_token" size="60" value="<?php echo esc_attr( $this->follow_facebook_access_token ); ?>" />
1539
- <br>
1540
- <label><?php _e( 'Facebook access token for OAuth', self::DOMAIN ); ?></label>
1541
- </td>
1542
- </tr>
1543
- <?php } ?>
1544
- </table>
1545
- <div class="submit-button">
1546
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1547
- <?php if ( isset( $this->follow_facebook_app_id ) && $this->follow_facebook_app_id && isset( $this->follow_facebook_app_secret ) && $this->follow_facebook_app_secret ) { ?>
1548
- <a href="https://www.facebook.com/dialog/oauth?client_id=<?php echo esc_attr( $this->follow_facebook_app_id ); ?>&scope=manage_pages&state=<?php echo wp_create_nonce( 'facebook-auth' ); ?>&redirect_uri=<?php echo plugins_url() . '/sns-count-cache/'; ?>?action=facebook-auth" class="button button-secondary"><?php _e( 'Get Access Token', self::DOMAIN ); ?></a>
1549
- <?php } ?>
1550
- </div>
1551
- </div>
1552
- </div>
1553
- <?php } ?>
1554
- <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) { ?>
1555
- <div id="follow-base-cache-feedly" class="postbox">
1556
- <div class="handlediv" title="Click to toggle"><br></div>
1557
- <h3 class="hndle"><span><?php _e( 'Follow Base Cache - Feedly', self::DOMAIN ); ?></span></h3>
1558
- <div class="inside">
1559
- <table class="form-table">
1560
- <tr>
1561
- <th><label><?php _e( 'Target feed type', self::DOMAIN ); ?></label></th>
1562
- <td>
1563
- <select name="follow_feed_type">
1564
- <option value="default"<?php if ( $this->follow_feed_type === self::OPT_FEED_TYPE_DEFAULT ) echo ' selected="selected"'; ?>><?php _e( 'Default', self::DOMAIN ) ?></option>
1565
- <option value="rss"<?php if ( $this->follow_feed_type === self::OPT_FEED_TYPE_RSS ) echo ' selected="selected"'; ?>><?php _e( 'RSS', self::DOMAIN ); ?></option>
1566
- <option value="rss2"<?php if ( $this->follow_feed_type === self::OPT_FEED_TYPE_RSS2 ) echo ' selected="selected"'; ?>><?php _e( 'RSS2', self::DOMAIN ); ?></option>
1567
- <option value="rdf"<?php if ( $this->follow_feed_type === self::OPT_FEED_TYPE_RDF ) echo ' selected="selected"'; ?>><?php _e( 'RDF', self::DOMAIN ); ?></option>
1568
- <option value="atom"<?php if ( $this->follow_feed_type === self::OPT_FEED_TYPE_ATOM ) echo ' selected="selected"'; ?>><?php _e( 'ATOM', self::DOMAIN ); ?></option>
1569
- </select>
1570
- <label><?php _e( 'Default: Default', self::DOMAIN ); ?></label>
1571
- </td>
1572
- </tr>
1573
- <tr>
1574
- <th><label><?php _e( 'Target feed', self::DOMAIN ); ?></label></th>
1575
- <td><a href="<?php echo esc_url( get_feed_link( $this->follow_feed_type ) ); ?>" target="_blank"><?php echo esc_html( get_feed_link( $this->follow_feed_type ) ); ?></a></td>
1576
- </tr>
1577
- </table>
1578
- <div class="submit-button">
1579
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1580
- </div>
1581
- </div>
1582
- </div>
1583
- <?php } ?>
1584
- <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) && $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) { ?>
1585
- <div id="follow-base-cache-push7" class="postbox">
1586
- <div class="handlediv" title="Click to toggle"><br></div>
1587
- <h3 class="hndle"><span><?php _e( 'Follow Base Cache - Push7', self::DOMAIN ); ?></span></h3>
1588
- <div class="inside">
1589
- <table class="form-table">
1590
- <tr>
1591
- <th><label><?php _e( 'AppNo', self::DOMAIN ); ?></label></th>
1592
- <td>
1593
- <input type="password" class="text" name="follow_push7_appno" size="60" value="<?php echo esc_attr( $this->follow_push7_appno ); ?>" />
1594
- <br>
1595
- <label><?php _e( 'Push7 appno to access Push7 API', self::DOMAIN ); ?></label>
1596
- </td>
1597
- </tr>
1598
- </table>
1599
- <div class="submit-button">
1600
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1601
- </div>
1602
- </div>
1603
- </div>
1604
- <?php } ?>
1605
- <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) && $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) { ?>
1606
- <div id="follow-base-cache-twitter" class="postbox">
1607
- <div class="handlediv" title="Click to toggle"><br></div>
1608
- <h3 class="hndle"><span><?php _e( 'Follow Base Cache - Twitter', self::DOMAIN ); ?></span></h3>
1609
- <div class="inside">
1610
- <table class="form-table">
1611
- <tr>
1612
- <th><label><?php _e( 'Screen name', self::DOMAIN ); ?></label></th>
1613
- <td>
1614
- <span class="at-mark">@</span>
1615
- <input type="text" class="text" name="follow_twitter_screen_name" size="30" value="<?php echo esc_attr( $this->follow_twitter_screen_name ); ?>" />
1616
- <br>
1617
- <label><?php _e( 'Twitter screen name that you want to get follower count', self::DOMAIN ); ?></label>
1618
- </td>
1619
- </tr>
1620
- <tr>
1621
- <th><label><?php _e( 'Consumer key (API Key)', self::DOMAIN ); ?></label></th>
1622
- <td>
1623
- <input type="password" class="text" name="follow_twitter_consumer_key" size="60" value="<?php echo esc_attr( $this->follow_twitter_consumer_key ); ?>" />
1624
- <br>
1625
- <label><?php _e( 'Twitter consumer key for OAuth', self::DOMAIN ); ?></label>
1626
- </td>
1627
- </tr>
1628
- <tr>
1629
- <th><label><?php _e( 'Consumer secret (API Secret)', self::DOMAIN ); ?></label></th>
1630
- <td>
1631
- <input type="password" class="text" name="follow_twitter_consumer_secret" size="60" value="<?php echo esc_attr( $this->follow_twitter_consumer_secret ); ?>" />
1632
- <br>
1633
- <label><?php _e( 'Twitter consumer secret for OAuth', self::DOMAIN ); ?></label>
1634
- </td>
1635
- </tr>
1636
- <?php if ( isset( $_POST["get_tiwtter_bearer_token"] ) && $_POST["get_tiwtter_bearer_token"] === __( 'Get Bearer Token', self::DOMAIN ) ) { ?>
1637
- <tr>
1638
- <th><label><?php _e( 'Bearer token', self::DOMAIN ); ?></label></th>
1639
- <td>
1640
- <input type="text" class="text" name="tmp_follow_twitter_bearer_token" size="60" value="<?php echo esc_attr( $tmp_twitter_bearer_token ); ?>" onclick="this.focus();this.select()" title="<?php _e( 'To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac).', self::DOMAIN ); ?>" readonly />
1641
- <br>
1642
- <label><?php _e( 'Copy and pase this into the fields below.', self::DOMAIN ); ?></label>
1643
- </td>
1644
- </tr>
1645
- <?php } ?>
1646
- <?php if ( isset( $this->follow_twitter_consumer_key ) && $this->follow_twitter_consumer_key && isset( $this->follow_twitter_consumer_secret ) && $this->follow_twitter_consumer_secret ) { ?>
1647
- <tr>
1648
- <th><label><?php _e( 'Bearer token', self::DOMAIN ); ?></label></th>
1649
- <td>
1650
- <input type="password" class="text" name="follow_twitter_bearer_token" size="60" value="<?php echo esc_attr( $this->follow_twitter_bearer_token ); ?>" />
1651
- <br>
1652
- <label><?php _e( 'Twitter bearer token for OAuth', self::DOMAIN ); ?></label>
1653
- </td>
1654
- </tr>
1655
- <?php } ?>
1656
- </table>
1657
- <div class="submit-button">
1658
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1659
- <?php if ( isset( $this->follow_twitter_consumer_key ) && $this->follow_twitter_consumer_key && isset( $this->follow_twitter_consumer_secret ) && $this->follow_twitter_consumer_secret ) { ?>
1660
- <input type="submit" class="button button-secondary" name="get_tiwtter_bearer_token" value="<?php _e( 'Get Bearer Token', self::DOMAIN ); ?>" />
1661
- <?php } ?>
1662
- </div>
1663
- </div>
1664
- </div>
1665
- <?php } ?>
1666
- <div id="common-dynamic-cache" class="postbox">
1667
- <div class="handlediv" title="Click to toggle"><br></div>
1668
- <h3 class="hndle"><span><?php _e( 'Dynamic Cache', self::DOMAIN ); ?></span></h3>
1669
- <div class="inside">
1670
- <table class="form-table">
1671
- <tr>
1672
- <th><label><?php _e( 'Dynamic caching based on user access', self::DOMAIN ); ?></label></th>
1673
- <td>
1674
- <select name="dynamic_cache_mode">
1675
- <option value="1"<?php if ( $this->dynamic_cache_mode === self::OPT_COMMON_ACCESS_BASED_CACHE_OFF ) echo ' selected="selected"'; ?>><?php _e( 'Disabled', self::DOMAIN ); ?></option>
1676
- <option value="5"<?php if ( $this->dynamic_cache_mode === self::OPT_COMMON_ACCESS_BASED_CACHE_ON ) echo ' selected="selected"'; ?>><?php _e( 'Enabled', self::DOMAIN ); ?></option>
1677
- </select>
1678
- <label><?php _e( 'Default: Disabled', self::DOMAIN ); ?></label>
1679
- </td>
1680
- </tr>
1681
- </table>
1682
- <div class="submit-button">
1683
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1684
- </div>
1685
- </div>
1686
- </div>
1687
- <div id="common-fault-tolerance" class="postbox">
1688
- <div class="handlediv" title="Click to toggle"><br></div>
1689
- <h3 class="hndle"><span><?php _e( 'Fault Tolerance', self::DOMAIN ); ?></span></h3>
1690
- <div class="inside">
1691
- <table class="form-table">
1692
- <tr>
1693
- <th><label><?php _e( 'Fault tolerant mode of count retrieval', self::DOMAIN ); ?></label></th>
1694
- <td>
1695
- <select name="fault_tolerance_mode">
1696
- <option value="1"<?php if ( $this->fault_tolerance_mode === self::OPT_COMMON_FAULT_TOLERANCE_OFF ) echo ' selected="selected"'; ?>><?php _e( 'Disabled', self::DOMAIN ); ?></option>
1697
- <option value="2"<?php if ( $this->fault_tolerance_mode === self::OPT_COMMON_FAULT_TOLERANCE_ON ) echo ' selected="selected"'; ?>><?php _e( 'Enabled', self::DOMAIN ); ?></option>
1698
- </select>
1699
- <label><?php _e( 'Default: Disabled', self::DOMAIN ); ?></label>
1700
- </td>
1701
- </tr>
1702
- </table>
1703
- <div class="submit-button">
1704
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1705
- </div>
1706
- </div>
1707
- </div>
1708
- <div id="common-data-crawler" class="postbox">
1709
- <div class="handlediv" title="Click to toggle"><br></div>
1710
- <h3 class="hndle"><span><?php _e( 'Data Crawler', self::DOMAIN ); ?></span></h3>
1711
- <div class="inside">
1712
- <table class="form-table">
1713
- <tr>
1714
- <th><label><?php _e( 'Crawl method', self::DOMAIN ); ?></label></th>
1715
- <td>
1716
- <?php
1717
- switch ( $this->crawler_method ) {
1718
- case self::OPT_COMMON_CRAWLER_METHOD_NORMAL:
1719
- _e( 'Normal (Sequential Retrieval)', self::DOMAIN );
1720
- break;
1721
- case self::OPT_COMMON_CRAWLER_METHOD_CURL:
1722
- _e( 'Extended (Parallel Retrieval)', self::DOMAIN );
1723
- break;
1724
- }
1725
- ?>
1726
- </td>
1727
- </tr>
1728
- <tr>
1729
- <th><label><?php _e( 'SSL verification', self::DOMAIN ); ?></label></th>
1730
- <td>
1731
- <select name="crawler_ssl_verification">
1732
- <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>
1733
- <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>
1734
- </select>
1735
- <label><?php _e( 'Default: On', self::DOMAIN ); ?></label>
1736
- </td>
1737
- </tr>
1738
- </table>
1739
- <div class="submit-button">
1740
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1741
- </div>
1742
- </div>
1743
- </div>
1744
- <div id="common-data-export" class="postbox">
1745
- <div class="handlediv" title="Click to toggle"><br></div>
1746
- <h3 class="hndle"><span><?php _e( 'Data Export', self::DOMAIN ); ?></span></h3>
1747
- <div class="inside">
1748
- <table class="form-table">
1749
- <tr>
1750
- <th><label><?php _e( 'Method of data export', self::DOMAIN ); ?></label></th>
1751
- <td>
1752
- <select name="data_export_mode">
1753
- <option value="1"<?php if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_MANUAL ) echo ' selected="selected"'; ?>><?php _e( 'Manual', self::DOMAIN ); ?></option>
1754
- <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>
1755
- </select>
1756
- <label><?php _e( 'Default: Manual', self::DOMAIN ); ?></label>
1757
- </td>
1758
- </tr>
1759
- <?php
1760
- if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_SCHEDULER ) {
1761
- list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ', $this->data_export_schedule, 5 );
1762
- if ( strstr( $cronstr[ 'minutes' ], '*/' ) ) {
1763
- $minutes = explode( '/', $cronstr[ 'minutes' ] );
1764
- } else {
1765
- $minutes = explode( ',', $cronstr[ 'minutes' ] );
1766
- }
1767
- if ( strstr( $cronstr[ 'hours' ], '*/' ) ) {
1768
- $hours = explode( '/', $cronstr[ 'hours' ] );
1769
- } else {
1770
- $hours = explode( ',', $cronstr[ 'hours' ] );
1771
- }
1772
- if ( strstr( $cronstr[ 'mday' ], '*/' ) ) {
1773
- $mday = explode( '/', $cronstr[ 'mday' ] );
1774
- } else {
1775
- $mday = explode( ',', $cronstr[ 'mday' ] );
1776
- }
1777
- if ( strstr( $cronstr[ 'mon' ], '*/' ) ) {
1778
- $mon = explode( '/', $cronstr[ 'mon' ] );
1779
- } else {
1780
- $mon = explode( ',', $cronstr[ 'mon' ] );
1781
- }
1782
- if ( strstr( $cronstr[ 'wday' ], '*/' ) ) {
1783
- $wday = explode( '/', $cronstr[ 'wday' ] );
1784
- } else {
1785
- $wday = explode( ',', $cronstr[ 'wday' ] );
1786
- }
1787
- ?>
1788
- <tr class="e_wpcron">
1789
- <th scope="row"><?php _e( 'Scheduler', self::DOMAIN ); ?></th>
1790
- <td>
1791
- <table class="wpcron">
1792
- <tr>
1793
- <th>
1794
- <?php _e( 'Type', self::DOMAIN ); ?>
1795
- </th>
1796
- <th>
1797
- </th>
1798
- <th>
1799
- <?php _e( 'Hour', self::DOMAIN ); ?>
1800
- </th>
1801
- <th>
1802
- <?php _e( 'Minute', self::DOMAIN ); ?>
1803
- </th>
1804
- </tr>
1805
- <tr>
1806
- <td>
1807
- <label for="idcronbtype-mon">
1808
- <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $mday[0] ), FALSE ) . ' name="e_cronbtype" value="mon" /> ' . __( 'monthly', self::DOMAIN ); ?>
1809
- </label>
1810
- </td>
1811
- <td>
1812
- <select name="e_moncronmday">
1813
- <?php
1814
- for ( $i = 1; $i <= 31; $i ++ ) {
1815
- $on_day = '';
1816
-
1817
- switch ( $i ) {
1818
- case 1:
1819
- $on_day = __( 'on 1.', self::DOMAIN );
1820
- break;
1821
- case 2:
1822
- $on_day = __( 'on 2.', self::DOMAIN );
1823
- break;
1824
- case 3:
1825
- $on_day = __( 'on 3.', self::DOMAIN );
1826
- break;
1827
- case 4:
1828
- $on_day = __( 'on 4.', self::DOMAIN );
1829
- break;
1830
- case 5:
1831
- $on_day = __( 'on 5.', self::DOMAIN );
1832
- break;
1833
- case 6:
1834
- $on_day = __( 'on 6.', self::DOMAIN );
1835
- break;
1836
- case 7:
1837
- $on_day = __( 'on 7.', self::DOMAIN );
1838
- break;
1839
- case 8:
1840
- $on_day = __( 'on 8.', self::DOMAIN );
1841
- break;
1842
- case 9:
1843
- $on_day = __( 'on 9.', self::DOMAIN );
1844
- break;
1845
- case 10:
1846
- $on_day = __( 'on 10.', self::DOMAIN );
1847
- break;
1848
- case 11:
1849
- $on_day = __( 'on 11.', self::DOMAIN );
1850
- break;
1851
- case 12:
1852
- $on_day = __( 'on 12.', self::DOMAIN );
1853
- break;
1854
- case 13:
1855
- $on_day = __( 'on 13.', self::DOMAIN );
1856
- break;
1857
- case 14:
1858
- $on_day = __( 'on 14.', self::DOMAIN );
1859
- break;
1860
- case 15:
1861
- $on_day = __( 'on 15.', self::DOMAIN );
1862
- break;
1863
- case 16:
1864
- $on_day = __( 'on 16.', self::DOMAIN );
1865
- break;
1866
- case 17:
1867
- $on_day = __( 'on 17.', self::DOMAIN );
1868
- break;
1869
- case 18:
1870
- $on_day = __( 'on 18.', self::DOMAIN );
1871
- break;
1872
- case 19:
1873
- $on_day = __( 'on 19.', self::DOMAIN );
1874
- break;
1875
- case 20:
1876
- $on_day = __( 'on 20.', self::DOMAIN );
1877
- break;
1878
- case 21:
1879
- $on_day = __( 'on 21.', self::DOMAIN );
1880
- break;
1881
- case 22:
1882
- $on_day = __( 'on 22.', self::DOMAIN );
1883
- break;
1884
- case 23:
1885
- $on_day = __( 'on 23.', self::DOMAIN );
1886
- break;
1887
- case 24:
1888
- $on_day = __( 'on 24.', self::DOMAIN );
1889
- break;
1890
- case 25:
1891
- $on_day = __( 'on 25.', self::DOMAIN );
1892
- break;
1893
- case 26:
1894
- $on_day = __( 'on 26.', self::DOMAIN );
1895
- break;
1896
- case 27:
1897
- $on_day = __( 'on 27.', self::DOMAIN );
1898
- break;
1899
- case 28:
1900
- $on_day = __( 'on 28.', self::DOMAIN );
1901
- break;
1902
- case 29:
1903
- $on_day = __( 'on 29.', self::DOMAIN );
1904
- break;
1905
- case 30:
1906
- $on_day = __( 'on 30.', self::DOMAIN );
1907
- break;
1908
- case 31:
1909
- $on_day = __( 'on 31.', self::DOMAIN );
1910
- break;
1911
- }
1912
-
1913
- echo '<option ' . selected( in_array( "$i", $mday, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $on_day . '</option>';
1914
- }
1915
- ?>
1916
- </select>
1917
- </td>
1918
- <td>
1919
- <select name="e_moncronhours">
1920
- <?php
1921
- for ( $i = 0; $i < 24; $i ++ ) {
1922
- echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1923
- }
1924
- ?>
1925
- </select>
1926
- </td>
1927
- <td>
1928
- <select name="e_moncronminutes">
1929
- <?php
1930
- for ( $i = 0; $i < 60; $i = $i + 5 ) {
1931
- echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1932
- }
1933
- ?>
1934
- </select>
1935
- </td>
1936
- </tr>
1937
- <tr>
1938
- <td>
1939
- <label for="idcronbtype-week">
1940
- <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $wday[0] ), FALSE ) . ' name="e_cronbtype" value="week" /> ' . __( 'weekly', self::DOMAIN ); ?>
1941
- </label>
1942
- </td>
1943
- <td>
1944
- <select name="e_weekcronwday">
1945
- <?php
1946
- echo '<option ' . selected( in_array( '0', $wday, TRUE ), TRUE, FALSE ) . ' value="0" />' . __( 'Sunday', self::DOMAIN ) . '</option>';
1947
- echo '<option ' . selected( in_array( '1', $wday, TRUE ), TRUE, FALSE ) . ' value="1" />' . __( 'Monday', self::DOMAIN ) . '</option>';
1948
- echo '<option ' . selected( in_array( '2', $wday, TRUE ), TRUE, FALSE ) . ' value="2" />' . __( 'Tuesday', self::DOMAIN ) . '</option>';
1949
- echo '<option ' . selected( in_array( '3', $wday, TRUE ), TRUE, FALSE ) . ' value="3" />' . __( 'Wednesday', self::DOMAIN ) . '</option>';
1950
- echo '<option ' . selected( in_array( '4', $wday, TRUE ), TRUE, FALSE ) . ' value="4" />' . __( 'Thursday', self::DOMAIN ) . '</option>';
1951
- echo '<option ' . selected( in_array( '5', $wday, TRUE ), TRUE, FALSE ) . ' value="5" />' . __( 'Friday', self::DOMAIN ) . '</option>';
1952
- echo '<option ' . selected( in_array( '6', $wday, TRUE ), TRUE, FALSE ) . ' value="6" />' . __( 'Saturday', self::DOMAIN ) . '</option>';
1953
- ?>
1954
- </select>
1955
- </td>
1956
- <td>
1957
- <select name="e_weekcronhours">
1958
- <?php
1959
- for ( $i = 0; $i < 24; $i ++ ) {
1960
- echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1961
- }
1962
- ?>
1963
- </select>
1964
- </td>
1965
- <td>
1966
- <select name="e_weekcronminutes">
1967
- <?php
1968
- for ( $i = 0; $i < 60; $i = $i + 5 ) {
1969
- echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1970
- }
1971
- ?>
1972
- </select>
1973
- </td>
1974
- </tr>
1975
- <tr>
1976
- <td>
1977
- <label for="idcronbtype-day">
1978
- <?php echo '<input class="radio" type="radio"' . checked( "**", $mday[0] . $wday[0], FALSE ) . ' name="e_cronbtype" value="day" /> ' . __( 'daily', self::DOMAIN ); ?>
1979
- </label>
1980
- </td>
1981
- <td>
1982
- </td>
1983
- <td>
1984
- <select name="e_daycronhours">
1985
- <?php
1986
- for ( $i = 0; $i < 24; $i ++ ) {
1987
- echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1988
- }
1989
- ?>
1990
- </select>
1991
- </td>
1992
- <td>
1993
- <select name="e_daycronminutes">
1994
- <?php
1995
- for ( $i = 0; $i < 60; $i = $i + 5 ) {
1996
- echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1997
- }
1998
- ?>
1999
- </select>
2000
- </td>
2001
- </tr>
2002
- <tr>
2003
- <td>
2004
- <label for="idcronbtype-hour">
2005
- <?php echo '<input class="radio" type="radio"' . checked( "*", $hours[0], FALSE, FALSE ) . ' name="e_cronbtype" value="hour" /> ' . __( 'hourly', self::DOMAIN ); ?>
2006
- </label>
2007
- </td>
2008
- <td></td>
2009
- <td></td>
2010
- <td>
2011
- <select name="e_hourcronminutes">
2012
- <?php
2013
- for ( $i = 0; $i < 60; $i = $i + 5 ) {
2014
- echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2015
- }
2016
- ?>
2017
- </select>
2018
- </td>
2019
- </tr>
2020
- </table>
2021
- </td>
2022
- </tr>
2023
- <?php
2024
- }
2025
- ?>
2026
- </table>
2027
- <div class="submit-button">
2028
- <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
2029
- </div>
2030
- </div>
2031
- </div>
2032
- </form>
2033
- </div>
2034
- <div class="metabox-holder">
2035
- <div id="common-exported-file" class="postbox">
2036
- <div class="handlediv" title="Click to toggle"><br></div>
2037
- <h3 class="hndle"><span><?php _e( 'Exported File', self::DOMAIN ); ?></span></h3>
2038
- <div class="inside">
2039
- <table class="form-table">
2040
- <tbody>
2041
- <tr>
2042
- <th><?php _e( 'Disk usage of exported file', self::DOMAIN ); ?></th>
2043
- <td>
2044
- <?php
2045
- $abs_path = WP_PLUGIN_DIR . '/sns-count-cache/data/sns-count-cache-data.csv';
2046
- $file_size = SCC_Common_Util::get_file_size( $abs_path );
2047
-
2048
- if ( isset( $file_size ) ) {
2049
- echo $file_size;
2050
- } else {
2051
- _e( 'No exported file', self::DOMAIN );
2052
- }
2053
- ?>
2054
- </td>
2055
- </tr>
2056
- </tbody>
2057
- </table>
2058
- <form action="admin.php?page=scc-setting" method="post">
2059
- <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
2060
- <table class="form-table">
2061
- <tbody>
2062
- <tr>
2063
- <th><?php _e( 'Manual export', self::DOMAIN ); ?></th>
2064
- <td>
2065
- <input type="submit" class="button button-secondary" name="export_data" value="<?php _e( 'Export', self::DOMAIN ); ?>" />
2066
- <br>
2067
- <span class="description"><?php _e( 'Export share count to a csv file.', self::DOMAIN ); ?></span>
2068
- </td>
2069
- </tr>
2070
- </tbody>
2071
- </table>
2072
- </form>
2073
- <?php
2074
- if ( file_exists( $abs_path ) ) {
2075
- ?>
2076
- <form action="admin.php?page=scc-setting" method="post">
2077
- <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
2078
- <table class="form-table">
2079
- <tbody>
2080
- <tr>
2081
- <th><?php _e( 'Reset of exported file', self::DOMAIN ); ?></th>
2082
- <td>
2083
- <input type="submit" class="button button-secondary" name="reset_data" value="<?php _e( 'Reset', self::DOMAIN ); ?>" />
2084
- <br>
2085
- <span class="description"><?php _e( 'Clear exported csv file.', self::DOMAIN ); ?></span>
2086
- </td>
2087
- </tr>
2088
- </tbody>
2089
- </table>
2090
- </form>
2091
- <form action="<?php echo plugins_url(); ?>/sns-count-cache/includes/download.php" method="post">
2092
- <?php wp_nonce_field( 'download', '_wpnonce' ); ?>
2093
- <table class="form-table">
2094
- <tbody>
2095
- <tr>
2096
- <th><?php _e( 'Download of exported file', self::DOMAIN ); ?></th>
2097
- <td>
2098
- <input type="submit" class="button button-secondary" name="download_data" value="<?php _e( 'Download', self::DOMAIN ); ?>" />
2099
- <br>
2100
- <span class="description"><?php _e( 'Download the exported csv file.', self::DOMAIN ); ?></span>
2101
- </td>
2102
- </tr>
2103
- </tbody>
2104
- </table>
2105
- </form>
2106
- <?php
2107
- }
2108
- ?>
2109
- </div>
2110
- </div>
2111
- </div>
2112
- </div>
2113
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ admin-setting.php
4
+
5
+ Description: Option page implementation
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
31
+
32
+ $tmp_instagram_access_token = '';
33
+ $tmp_facebook_access_token = '';
34
+ $tmp_twitter_bearer_token = '';
35
+
36
+ if ( isset( $_POST['_wpnonce'] ) && $_POST['_wpnonce'] && check_admin_referer( __FILE__, '_wpnonce' ) ) {
37
+ if ( isset( $_POST["update_all_options"] ) && $_POST["update_all_options"] === __( 'Update All Options', self::DOMAIN ) ) {
38
+
39
+ $wp_error = new WP_Error();
40
+
41
+ //$settings = array();
42
+ $settings = get_option( self::DB_SETTINGS );
43
+
44
+ $share_base_cache_target = array();
45
+ $follow_base_cache_target = array();
46
+
47
+ if ( isset( $_POST["share_base_custom_post_types"] ) && $_POST["share_base_custom_post_types"] ) {
48
+ $settings[self::DB_SHARE_CUSTOM_POST_TYPES] = explode( ',', sanitize_text_field( $_POST["share_base_custom_post_types"] ) );
49
+ } else {
50
+ $settings[self::DB_SHARE_CUSTOM_POST_TYPES] = array();
51
+ }
52
+
53
+ if ( isset( $_POST["share_base_check_interval"] ) && $_POST["share_base_check_interval"] ) {
54
+ $tmp_share_base_check_interval = sanitize_text_field( $_POST["share_base_check_interval"] );
55
+ if ( is_numeric( $tmp_share_base_check_interval ) ) {
56
+ $settings[self::DB_SHARE_BASE_CHECK_INTERVAL] = $tmp_share_base_check_interval;
57
+ }
58
+ }
59
+
60
+ if ( isset( $_POST["share_base_posts_per_check"] ) && $_POST["share_base_posts_per_check"] ) {
61
+ $tmp_share_base_posts_per_check = sanitize_text_field( $_POST["share_base_posts_per_check"] );
62
+ if ( is_numeric( $tmp_share_base_posts_per_check ) ) {
63
+ $settings[self::DB_SHARE_BASE_POSTS_PER_CHECK] = $tmp_share_base_posts_per_check;
64
+ }
65
+ }
66
+
67
+ if ( isset( $_POST["dynamic_cache_mode"] ) && $_POST["dynamic_cache_mode"] ) {
68
+ $settings[self::DB_COMMON_DYNAMIC_CACHE_MODE] = sanitize_text_field( $_POST["dynamic_cache_mode"] );
69
+ }
70
+
71
+ if ( isset( $_POST["fault_tolerance_mode"] ) && $_POST["fault_tolerance_mode"] ) {
72
+ $settings[self::DB_COMMON_FAULT_TOLERANCE_MODE] = sanitize_text_field( $_POST["fault_tolerance_mode"] );
73
+ }
74
+
75
+ if ( isset( $_POST["share_variation_analysis_mode"] ) && $_POST["share_variation_analysis_mode"] ) {
76
+ $settings[self::DB_SHARE_VARIATION_ANALYSIS_MODE] = sanitize_text_field( $_POST["share_variation_analysis_mode"] );
77
+ }
78
+
79
+ if ( isset( $_POST["follow_variation_analysis_mode"] ) && $_POST["follow_variation_analysis_mode"] ) {
80
+ $settings[self::DB_FOLLOW_VARIATION_ANALYSIS_MODE] = sanitize_text_field( $_POST["follow_variation_analysis_mode"] );
81
+ }
82
+
83
+ if ( isset( $_POST["share_rush_new_content_term"] ) && $_POST["share_rush_new_content_term"] ) {
84
+ $tmp_share_rush_new_content_term = sanitize_text_field( $_POST["share_rush_new_content_term"] );
85
+ if ( is_numeric( $tmp_share_rush_new_content_term ) ) {
86
+ $settings[self::DB_SHARE_RUSH_NEW_CONTENT_TERM] = $tmp_share_rush_new_content_term;
87
+ }
88
+ }
89
+
90
+ if ( isset( $_POST["share_rush_check_interval"] ) && $_POST["share_rush_check_interval"] ) {
91
+ $tmp_share_rush_check_interval = sanitize_text_field( $_POST["share_rush_check_interval"] );
92
+ if ( is_numeric( $tmp_share_rush_check_interval ) ) {
93
+ $settings[self::DB_SHARE_RUSH_CHECK_INTERVAL] = $tmp_share_rush_check_interval;
94
+ }
95
+ }
96
+
97
+ if ( isset( $_POST["share_rush_posts_per_check"] ) && $_POST["share_rush_posts_per_check"] ) {
98
+ $tmp_share_rush_posts_per_check = sanitize_text_field( $_POST["share_rush_posts_per_check"] );
99
+ if ( is_numeric( $tmp_share_rush_posts_per_check ) ) {
100
+ $settings[self::DB_SHARE_RUSH_POSTS_PER_CHECK] = $tmp_share_rush_posts_per_check;
101
+ }
102
+ }
103
+
104
+ if ( isset( $_POST["data_export_mode"] ) && $_POST["data_export_mode"] ) {
105
+ $settings[self::DB_COMMON_DATA_EXPORT_MODE] = sanitize_text_field( $_POST["data_export_mode"] );
106
+ }
107
+
108
+ if ( isset( $_POST["data_export_interval"] ) && $_POST["data_export_interval"] ) {
109
+ $tmp_data_export_interval = sanitize_text_field( $_POST["data_export_interval"] );
110
+ if ( is_numeric( $tmp_data_export_interval ) ) {
111
+ $settings[self::DB_COMMON_DATA_EXPORT_INTERVAL] = $tmp_data_export_interval;
112
+ }
113
+ }
114
+
115
+ if ( isset( $_POST["common_data_crawler_retry_limit"] ) && $_POST["common_data_crawler_retry_limit"] ) {
116
+ $tmp_common_data_crawler_retry_limit = sanitize_text_field( $_POST["common_data_crawler_retry_limit"] );
117
+ if ( is_numeric( $tmp_common_data_crawler_retry_limit ) ) {
118
+ $settings[self::DB_COMMON_CRAWLER_RETRY_LIMIT] = $tmp_common_data_crawler_retry_limit;
119
+ }
120
+ }
121
+
122
+ if ( isset( $_POST["share_base_cache_target_twitter"] ) && $_POST["share_base_cache_target_twitter"] ) {
123
+ $share_base_cache_target[self::REF_SHARE_TWITTER] = true;
124
+ } else {
125
+ $share_base_cache_target[self::REF_SHARE_TWITTER] = false;
126
+ }
127
+
128
+ if ( isset( $_POST["share_alternative_twitter_api"] ) && $_POST["share_alternative_twitter_api"] ) {
129
+ $settings[self::DB_SHARE_BASE_TWITTER_API] = sanitize_text_field( $_POST["share_alternative_twitter_api"] );
130
+ }
131
+
132
+ if ( isset( $_POST["share_base_cache_target_facebook"] ) && $_POST["share_base_cache_target_facebook"] ) {
133
+ $share_base_cache_target[self::REF_SHARE_FACEBOOK] = true;
134
+ } else {
135
+ $share_base_cache_target[self::REF_SHARE_FACEBOOK] = false;
136
+ }
137
+
138
+ if ( isset( $_POST["share_base_cache_target_gplus"] ) && $_POST["share_base_cache_target_gplus"] ) {
139
+ $share_base_cache_target[self::REF_SHARE_GPLUS] = true;
140
+ } else {
141
+ $share_base_cache_target[self::REF_SHARE_GPLUS] = false;
142
+ }
143
+
144
+ if ( isset( $_POST["share_base_cache_target_pocket"] ) && $_POST["share_base_cache_target_pocket"] ) {
145
+ $share_base_cache_target[self::REF_SHARE_POCKET] = true;
146
+ } else {
147
+ $share_base_cache_target[self::REF_SHARE_POCKET] = false;
148
+ }
149
+
150
+ if ( isset( $_POST["share_base_cache_target_hatebu"] ) && $_POST["share_base_cache_target_hatebu"] ) {
151
+ $share_base_cache_target[self::REF_SHARE_HATEBU] = true;
152
+ } else {
153
+ $share_base_cache_target[self::REF_SHARE_HATEBU] = false;
154
+ }
155
+
156
+ if ( isset( $_POST["share_base_cache_target_pinterest"] ) && $_POST["share_base_cache_target_pinterest"] ) {
157
+ $share_base_cache_target[self::REF_SHARE_PINTEREST] = true;
158
+ } else {
159
+ $share_base_cache_target[self::REF_SHARE_PINTEREST] = false;
160
+ }
161
+
162
+ if ( isset( $_POST["share_base_cache_target_linkedin"] ) && $_POST["share_base_cache_target_linkedin"] ) {
163
+ $share_base_cache_target[self::REF_SHARE_LINKEDIN] = true;
164
+ } else {
165
+ $share_base_cache_target[self::REF_SHARE_LINKEDIN] = false;
166
+ }
167
+
168
+ if ( ! empty( $share_base_cache_target ) ) {
169
+ $settings[self::DB_SHARE_CACHE_TARGET] = $share_base_cache_target;
170
+ }
171
+
172
+ if ( isset( $_POST["follow_base_check_interval"] ) && $_POST["follow_base_check_interval"] ) {
173
+ $tmp_follow_base_check_interval = sanitize_text_field( $_POST["follow_base_check_interval"] );
174
+ if ( is_numeric( $tmp_follow_base_check_interval ) ) {
175
+ if ( $tmp_follow_base_check_interval >= self::OPT_FOLLOW_BASE_CHECK_INTERVAL_MIN ) {
176
+ $settings[self::DB_FOLLOW_CHECK_INTERVAL] = $tmp_follow_base_check_interval;
177
+ } else {
178
+ $settings[self::DB_FOLLOW_CHECK_INTERVAL] = self::OPT_FOLLOW_BASE_CHECK_INTERVAL_MIN;
179
+ }
180
+ }
181
+ }
182
+
183
+ if ( isset( $_POST["follow_base_cache_target_feedly"] ) && $_POST["follow_base_cache_target_feedly"] ) {
184
+ $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = true;
185
+ } else {
186
+ $follow_base_cache_target[self::REF_FOLLOW_FEEDLY] = false;
187
+ }
188
+
189
+ if ( isset( $_POST["follow_base_cache_target_twitter"] ) && $_POST["follow_base_cache_target_twitter"] ) {
190
+ $follow_base_cache_target[self::REF_FOLLOW_TWITTER] = true;
191
+ } else {
192
+ $follow_base_cache_target[self::REF_FOLLOW_TWITTER] = false;
193
+ }
194
+
195
+ if ( isset( $_POST["follow_base_cache_target_facebook"] ) && $_POST["follow_base_cache_target_facebook"] ) {
196
+ $follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] = true;
197
+ } else {
198
+ $follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] = false;
199
+ }
200
+
201
+ if ( isset( $_POST["follow_base_cache_target_push7"] ) && $_POST["follow_base_cache_target_push7"] ) {
202
+ $follow_base_cache_target[self::REF_FOLLOW_PUSH7] = true;
203
+ } else {
204
+ $follow_base_cache_target[self::REF_FOLLOW_PUSH7] = false;
205
+ }
206
+
207
+ if ( isset( $_POST["follow_base_cache_target_instagram"] ) && $_POST["follow_base_cache_target_instagram"] ) {
208
+ $follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] = true;
209
+ } else {
210
+ $follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] = false;
211
+ }
212
+
213
+ if ( ! empty( $follow_base_cache_target ) ) {
214
+ $settings[self::DB_FOLLOW_CACHE_TARGET] = $follow_base_cache_target;
215
+ }
216
+
217
+ $follow_twitter_preparation_flag = true;
218
+
219
+ if ( isset( $_POST["share_facebook_app_id"] ) && $_POST["share_facebook_app_id"] ) {
220
+ $settings[self::DB_SHARE_FACEBOOK_APP_ID] = SCC_Common_Util::encrypt_data( SCC_Common_Util::sanitize( $_POST["share_facebook_app_id"] ), AUTH_KEY );
221
+ }
222
+
223
+ if ( isset( $_POST["share_facebook_app_secret"] ) && $_POST["share_facebook_app_secret"] ) {
224
+ $settings[self::DB_SHARE_FACEBOOK_APP_SECRET] = SCC_Common_Util::encrypt_data( SCC_Common_Util::sanitize( $_POST["share_facebook_app_secret"] ), AUTH_KEY );
225
+ }
226
+
227
+ if ( isset( $_POST["follow_twitter_screen_name"] ) && $_POST["follow_twitter_screen_name"] ) {
228
+ $settings[self::DB_FOLLOW_TWITTER_SCREEN_NAME] = sanitize_text_field( $_POST["follow_twitter_screen_name"] );
229
+ }
230
+
231
+ if ( isset( $_POST["follow_twitter_consumer_key"] ) && $_POST["follow_twitter_consumer_key"] ) {
232
+ $settings[self::DB_FOLLOW_TWITTER_CONSUMER_KEY] = SCC_Common_Util::encrypt_data( SCC_Common_Util::sanitize( $_POST["follow_twitter_consumer_key"] ), AUTH_KEY );
233
+ } else {
234
+ $follow_twitter_preparation_flag = false;
235
+ }
236
+
237
+ if ( isset( $_POST["follow_twitter_consumer_secret"] ) && $_POST["follow_twitter_consumer_secret"] ) {
238
+ $settings[self::DB_FOLLOW_TWITTER_CONSUMER_SECRET] = SCC_Common_Util::encrypt_data( SCC_Common_Util::sanitize( $_POST["follow_twitter_consumer_secret"] ), AUTH_KEY );
239
+ } else {
240
+ $follow_twitter_preparation_flag = false;
241
+ }
242
+
243
+ if ( isset( $_POST["follow_twitter_bearer_token"] ) && $_POST["follow_twitter_bearer_token"] ) {
244
+ $settings[self::DB_FOLLOW_TWITTER_BEARER_TOKEN] = SCC_Common_Util::encrypt_data( SCC_Common_Util::sanitize( $_POST["follow_twitter_bearer_token"] ), AUTH_KEY );
245
+ }
246
+
247
+ /*
248
+ if ( isset( $_POST["follow_twitter_access_token"] ) && $_POST["follow_twitter_access_token"] ) {
249
+ $settings[self::DB_FOLLOW_TWITTER_ACCESS_TOKEN] = SCC_Common_Util::encrypt_data( $_POST["follow_twitter_access_token"], AUTH_KEY );
250
+ }
251
+
252
+ if ( isset( $_POST["follow_twitter_access_token_secret"] ) && $_POST["follow_twitter_access_token_secret"] ) {
253
+ $settings[self::DB_FOLLOW_TWITTER_ACCESS_TOKEN_SECRET] = SCC_Common_Util::encrypt_data( $_POST["follow_twitter_access_token_secret"], AUTH_KEY );
254
+ }
255
+ */
256
+
257
+ if ( isset( $_POST["follow_facebook_page_id"] ) && $_POST["follow_facebook_page_id"] ) {
258
+ $settings[self::DB_FOLLOW_FACEBOOK_PAGE_ID] = sanitize_text_field( $_POST["follow_facebook_page_id"] );
259
+ }
260
+
261
+ if ( isset( $_POST["follow_facebook_app_id"] ) && $_POST["follow_facebook_app_id"] ) {
262
+ $settings[self::DB_FOLLOW_FACEBOOK_APP_ID] = SCC_Common_Util::encrypt_data( SCC_Common_Util::sanitize( $_POST["follow_facebook_app_id"] ), AUTH_KEY );
263
+ }
264
+
265
+ if ( isset( $_POST["follow_facebook_app_secret"] ) && $_POST["follow_facebook_app_secret"] ) {
266
+ $settings[self::DB_FOLLOW_FACEBOOK_APP_SECRET] = SCC_Common_Util::encrypt_data( SCC_Common_Util::sanitize( $_POST["follow_facebook_app_secret"] ), AUTH_KEY );
267
+ }
268
+
269
+ if ( isset( $_POST["follow_facebook_access_token"] ) && $_POST["follow_facebook_access_token"] ) {
270
+ $settings[self::DB_FOLLOW_FACEBOOK_ACCESS_TOKEN] = SCC_Common_Util::encrypt_data( SCC_Common_Util::sanitize( $_POST["follow_facebook_access_token"] ), AUTH_KEY );
271
+ }
272
+
273
+ if ( isset( $_POST["follow_push7_appno"] ) && $_POST["follow_push7_appno"] ) {
274
+ $settings[self::DB_FOLLOW_PUSH7_APPNO] = SCC_Common_Util::encrypt_data( sanitize_text_field( $_POST["follow_push7_appno"] ), AUTH_KEY );
275
+ }
276
+
277
+ if ( isset( $_POST["follow_instagram_access_token"] ) && $_POST["follow_instagram_access_token"] ) {
278
+ $settings[self::DB_FOLLOW_INSTAGRAM_ACCESS_TOKEN] = SCC_Common_Util::encrypt_data( SCC_Common_Util::sanitize( $_POST["follow_instagram_access_token"] ), AUTH_KEY );
279
+ }
280
+
281
+ if ( isset( $_POST["follow_instagram_client_id"] ) && $_POST["follow_instagram_client_id"] ) {
282
+ $settings[self::DB_FOLLOW_INSTAGRAM_CLIENT_ID] = SCC_Common_Util::encrypt_data( SCC_Common_Util::sanitize( $_POST["follow_instagram_client_id"] ), AUTH_KEY );
283
+ }
284
+
285
+ if ( isset( $_POST["follow_instagram_client_secret"] ) && $_POST["follow_instagram_client_secret"] ) {
286
+ $settings[self::DB_FOLLOW_INSTAGRAM_CLIENT_SECRET] = SCC_Common_Util::encrypt_data( SCC_Common_Util::sanitize( $_POST["follow_instagram_client_secret"] ), AUTH_KEY );
287
+ }
288
+
289
+ if ( isset( $_POST["follow_feed_type"] ) && $_POST["follow_feed_type"] ) {
290
+ switch ( $_POST["follow_feed_type"] ) {
291
+ case 'default':
292
+ $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_DEFAULT;
293
+ break;
294
+ case 'rss2':
295
+ $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_RSS2;
296
+ break;
297
+ case 'rss':
298
+ $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_RSS;
299
+ break;
300
+ case 'rdf':
301
+ $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_RDF;
302
+ break;
303
+ case 'atom':
304
+ $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_ATOM;
305
+ break;
306
+ default:
307
+ $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_DEFAULT;
308
+ }
309
+ } else {
310
+ $settings[self::DB_FOLLOW_FEED_TYPE] = self::OPT_FEED_TYPE_DEFAULT;
311
+ }
312
+
313
+ if ( isset( $_POST["scheme_migration_mode"] ) && $_POST["scheme_migration_mode"] ) {
314
+ $settings[self::DB_COMMON_SCHEME_MIGRATION_MODE] = self::OPT_COMMON_SCHEME_MIGRATION_MODE_ON;
315
+ } else {
316
+ $settings[self::DB_COMMON_SCHEME_MIGRATION_MODE] = self::OPT_COMMON_SCHEME_MIGRATION_MODE_OFF;
317
+ }
318
+
319
+ if ( isset( $_POST["scheme_migration_date"] ) && $_POST["scheme_migration_date"] ) {
320
+ $tmp_scheme_migration_date = sanitize_text_field( $_POST["scheme_migration_date"] );
321
+ if ( strptime( $tmp_scheme_migration_date, '%Y/%m/%d' ) ) {
322
+ $settings[self::DB_COMMON_SCHEME_MIGRATION_DATE] = $tmp_scheme_migration_date;
323
+ }
324
+ }
325
+
326
+ if ( isset( $_POST["crawler_ssl_verification"] ) && $_POST["crawler_ssl_verification"] ) {
327
+ $settings[self::DB_COMMON_CRAWLER_SSL_VERIFICATION] = self::OPT_COMMON_CRAWLER_SSL_VERIFY_ON;
328
+ } else {
329
+ $settings[self::DB_COMMON_CRAWLER_SSL_VERIFICATION] = self::OPT_COMMON_CRAWLER_SSL_VERIFY_OFF;
330
+ }
331
+
332
+ if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'mon' ) {
333
+ $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_moncronminutes'] . ' ' . $_POST['a_moncronhours'] . ' ' . $_POST['a_moncronmday'] . ' * *';
334
+ }
335
+
336
+ if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'week' ) {
337
+ $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_weekcronminutes'] . ' ' . $_POST['a_weekcronhours'] . ' * * ' . $_POST['a_weekcronwday'];
338
+ }
339
+
340
+ if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'day' ) {
341
+ $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_daycronminutes'] . ' ' . $_POST['a_daycronhours'] . ' * * *';
342
+ }
343
+
344
+ if ( isset( $_POST['a_cronbtype'] ) && $_POST['a_cronbtype'] === 'hour' ) {
345
+ $settings[self::DB_SHARE_VARIATION_ANALYSIS_SCHEDULE] = $_POST['a_hourcronminutes'] . ' * * * *';
346
+ }
347
+
348
+ if ( isset( $_POST['b_cronbtype'] ) && $_POST['b_cronbtype'] === 'mon' ) {
349
+ $settings[self::DB_FOLLOW_VARIATION_ANALYSIS_SCHEDULE] = $_POST['b_moncronminutes'] . ' ' . $_POST['b_moncronhours'] . ' ' . $_POST['b_moncronmday'] . ' * *';
350
+ }
351
+
352
+ if ( isset( $_POST['b_cronbtype'] ) && $_POST['b_cronbtype'] === 'week' ) {
353
+ $settings[self::DB_FOLLOW_VARIATION_ANALYSIS_SCHEDULE] = $_POST['b_weekcronminutes'] . ' ' . $_POST['b_weekcronhours'] . ' * * ' . $_POST['b_weekcronwday'];
354
+ }
355
+
356
+ if ( isset( $_POST['b_cronbtype'] ) && $_POST['b_cronbtype'] === 'day' ) {
357
+ $settings[self::DB_FOLLOW_VARIATION_ANALYSIS_SCHEDULE] = $_POST['b_daycronminutes'] . ' ' . $_POST['b_daycronhours'] . ' * * *';
358
+ }
359
+
360
+ if ( isset( $_POST['b_cronbtype'] ) && $_POST['b_cronbtype'] === 'hour' ) {
361
+ $settings[self::DB_FOLLOW_VARIATION_ANALYSIS_SCHEDULE] = $_POST['b_hourcronminutes'] . ' * * * *';
362
+ }
363
+
364
+ if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'mon' ) {
365
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_moncronminutes'] . ' ' . $_POST['e_moncronhours'] . ' ' . $_POST['e_moncronmday'] . ' * *';
366
+ }
367
+
368
+ if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'week' ) {
369
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_weekcronminutes'] . ' ' . $_POST['e_weekcronhours'] . ' * * ' . $_POST['e_weekcronwday'];
370
+ }
371
+
372
+ if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'day' ) {
373
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_daycronminutes'] . ' ' . $_POST['e_daycronhours'] . ' * * *';
374
+ }
375
+
376
+ if ( isset( $_POST['e_cronbtype'] ) && $_POST['e_cronbtype'] === 'hour' ) {
377
+ $settings[self::DB_COMMON_DATA_EXPORT_SCHEDULE] = $_POST['e_hourcronminutes'] . ' * * * *';
378
+ }
379
+
380
+ update_option( self::DB_SETTINGS, $settings );
381
+
382
+ $this->reactivate_plugin();
383
+
384
+ set_transient( self::OPT_COMMON_ERROR_MESSAGE, $wp_error->get_error_messages(), 10 );
385
+
386
+ //wp_safe_redirect( menu_page_url( 'scc-setting', false ) );
387
+ }
388
+
389
+ if ( isset( $_POST["reset_data"] ) && $_POST["reset_data"] === __( 'Reset', self::DOMAIN ) ) {
390
+ SCC_Common_Util::log( '[' . __METHOD__ . '] reset' );
391
+
392
+ $this->export_engines[self::REF_COMMON_EXPORT]->reset_export();
393
+
394
+ //wp_safe_redirect( menu_page_url( 'scc-setting', false ) );
395
+ }
396
+
397
+ if ( isset( $_POST["export_data"] ) && $_POST["export_data"] === __( 'Export', self::DOMAIN ) ) {
398
+ SCC_Common_Util::log( '[' . __METHOD__ . '] export' );
399
+
400
+ set_time_limit( $this->extended_max_execution_time );
401
+
402
+ $this->export_engines[self::REF_COMMON_EXPORT]->execute_export( NULL );
403
+
404
+ set_time_limit( $this->original_max_execution_time );
405
+
406
+ //wp_safe_redirect( menu_page_url('scc-setting', false ) );
407
+ }
408
+
409
+ if ( isset( $_POST["update_share_comparison_base"] ) && $_POST["update_share_comparison_base"] === __( 'Update Basis of Comparison', self::DOMAIN ) ) {
410
+ SCC_Common_Util::log( '[' . __METHOD__ . '] base' );
411
+
412
+ set_time_limit( $this->extended_max_execution_time );
413
+
414
+ $this->analytical_engines[self::REF_SHARE_ANALYSIS]->execute_base( NULL );
415
+
416
+ set_time_limit( $this->original_max_execution_time );
417
+
418
+ //wp_safe_redirect( menu_page_url( 'scc-setting', false ) );
419
+ }
420
+
421
+ if ( isset( $_POST["update_follow_comparison_base"] ) && $_POST["update_follow_comparison_base"] === __( 'Update Basis of Comparison', self::DOMAIN ) ) {
422
+ SCC_Common_Util::log( '[' . __METHOD__ . '] base' );
423
+
424
+ set_time_limit( $this->extended_max_execution_time );
425
+
426
+ $this->analytical_engines[self::REF_FOLLOW_ANALYSIS]->execute_base( NULL );
427
+
428
+ set_time_limit( $this->original_max_execution_time );
429
+
430
+ //wp_safe_redirect( menu_page_url( 'scc-setting', false ) );
431
+ }
432
+
433
+ if ( isset( $_POST["clear_share_base_cache"] ) && $_POST["clear_share_base_cache"] === __( 'Clear Cache', self::DOMAIN ) ) {
434
+ SCC_Common_Util::log( '[' . __METHOD__ . '] clear cache' );
435
+
436
+ set_time_limit( $this->extended_max_execution_time );
437
+
438
+ $this->cache_engines[self::REF_SHARE_BASE]->clear_cache();
439
+ //$this->cache_engines[self::REF_SHARE_2ND]->clear_cache();
440
+ $this->cache_engines[self::REF_SHARE_2ND]->initialize_cache();
441
+ $this->analytical_engines[self::REF_SHARE_ANALYSIS]->clear_base();
442
+
443
+ set_time_limit( $this->original_max_execution_time );
444
+
445
+ //wp_safe_redirect( menu_page_url('scc-setting', false ) );
446
+ }
447
+
448
+ if ( isset( $_POST["clear_follow_base_cache"] ) && $_POST["clear_follow_base_cache"] === __( 'Clear Cache', self::DOMAIN ) ) {
449
+ SCC_Common_Util::log( '[' . __METHOD__ . '] clear cache' );
450
+
451
+ set_time_limit( $this->extended_max_execution_time );
452
+
453
+ $this->cache_engines[self::REF_FOLLOW_BASE]->clear_cache();
454
+ //$this->cache_engines[self::REF_FOLLOW_2ND]->clear_cache();
455
+ $this->cache_engines[self::REF_FOLLOW_2ND]->initialize_cache();
456
+
457
+ set_time_limit( $this->original_max_execution_time );
458
+
459
+ //wp_safe_redirect( menu_page_url('scc-setting', false ) );
460
+ }
461
+
462
+ if ( isset( $_POST["direct_follow_base_cache"] ) && $_POST["direct_follow_base_cache"] === __( 'Cache', self::DOMAIN ) ) {
463
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cache' );
464
+
465
+ set_time_limit( $this->extended_max_execution_time );
466
+
467
+ $this->cache_engines[self::REF_FOLLOW_BASE]->direct_cache( true );
468
+
469
+ set_time_limit( $this->original_max_execution_time );
470
+
471
+ //wp_safe_redirect( menu_page_url('scc-setting', false ) );
472
+ }
473
+
474
+ if ( isset( $_POST["get_tiwtter_bearer_token"] ) && $_POST["get_tiwtter_bearer_token"] === __( 'Get Bearer Token', self::DOMAIN ) ) {
475
+ $tmp_twitter_bearer_token = SCC_Common_Util::get_twitter_bearer_token( $this->follow_twitter_consumer_key, $this->follow_twitter_consumer_secret );
476
+ }
477
+
478
+ } elseif( isset( $_GET['_wpnonce'] ) && $_GET['_wpnonce'] && isset( $_GET['action'] ) && $_GET['action'] && isset( $_GET['code'] ) && $_GET['code'] ) {
479
+ if ( $_GET['action'] === 'instagram-auth' ) {
480
+ if ( check_admin_referer( 'instagram-auth', '_wpnonce' ) ) {
481
+ if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
482
+ $redirect_uri = plugins_url() . '/sns-count-cache/?action=instagram-auth';
483
+ $tmp_instagram_access_token = SCC_Common_Util::get_instagram_access_token( $this->follow_instagram_client_id, $this->follow_instagram_client_secret, $redirect_uri, $_GET['code'] );
484
+ }
485
+ }
486
+ } elseif ( $_GET['action'] === 'facebook-auth' ) {
487
+ if ( check_admin_referer( 'facebook-auth', '_wpnonce' ) ) {
488
+ if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
489
+ $redirect_uri = plugins_url() . '/sns-count-cache/?action=facebook-auth';
490
+ $tmp_facebook_access_token = SCC_Common_Util::get_facebook_access_token( $this->follow_facebook_app_id, $this->follow_facebook_app_secret, $redirect_uri, $_GET['code'], $this->follow_facebook_page_id );
491
+ }
492
+ }
493
+ }
494
+ }
495
+ ?>
496
+ <div class="wrap">
497
+ <h2><a href="admin.php?page=scc-setting"><?php _e( 'SNS Count Cache', self::DOMAIN ); ?></a></h2>
498
+ <?php
499
+ if ( $messages = get_transient( self::OPT_COMMON_ERROR_MESSAGE ) ) {
500
+ ?>
501
+ <div class="error">
502
+ <ul>
503
+ <?php
504
+ foreach( $messages as $message ) {
505
+ ?>
506
+ <li><?php echo esc_html( $message ); ?></li>
507
+ <?php
508
+ }
509
+ ?>
510
+ </ul>
511
+ </div>
512
+ <?php
513
+ delete_transient( self::OPT_COMMON_ERROR_MESSAGE );
514
+ }
515
+ ?>
516
+
517
+ <?php
518
+ $status = SCC_WP_Cron_Util::test_cron_spawn();
519
+
520
+ if ( is_wp_error( $status ) ) {
521
+ echo '<div class="notice notice-error"><p>';
522
+ _e( 'There was a problem spawning a call to the WP-Cron system on your site. This means WP-Cron jobs on your site may not work. The problem was: ', self::DOMAIN );
523
+ echo '<br><strong>' . esc_html( $status->get_error_message() ) . '</strong>';
524
+ echo '.</p></div>';
525
+ }
526
+
527
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) {
528
+ $configuration_check = $this->crawlers[self::REF_SHARE]->check_crawl_strategy_configurations( self::REF_SHARE_FACEBOOK );
529
+
530
+ if ( ! $configuration_check ) {
531
+ echo '<div class="notice notice-warning"><p>';
532
+ _e( 'Configuratin is not enough to get share count. Please set required parameters at ', self::DOMAIN );
533
+ echo '<a href="#share-base-cache-facebook">' . __( 'Share Base Cache - Facebook', self::DOMAIN ) . '</a>';
534
+ echo '.</p></div>';
535
+ }
536
+ }
537
+
538
+ if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) && $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) {
539
+ $configuration_check = $this->crawlers[self::REF_FOLLOW]->check_crawl_strategy_configurations( self::REF_FOLLOW_INSTAGRAM);
540
+
541
+ if ( ! $configuration_check ) {
542
+ echo '<div class="notice notice-warning"><p>';
543
+ _e( 'Configuratin is not enough to get follower count. Please set required parameters at ', self::DOMAIN );
544
+ echo '<a href="#follow-base-cache-instagram">' . __( 'Follow Base Cache - Instagram', self::DOMAIN ) . '</a>';
545
+ echo '.</p></div>';
546
+ }
547
+ }
548
+
549
+ if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) {
550
+ $configuration_check = $this->crawlers[self::REF_FOLLOW]->check_crawl_strategy_configurations( self::REF_FOLLOW_FACEBOOK );
551
+
552
+ if ( ! $configuration_check ) {
553
+ echo '<div class="notice notice-warning"><p>';
554
+ _e( 'Configuratin is not enough to get follower count. Please set required parameters at ', self::DOMAIN );
555
+ echo '<a href="#follow-base-cache-facebook">' . __( 'Follow Base Cache - Facebook', self::DOMAIN ) . '</a>';
556
+ echo '.</p></div>';
557
+ }
558
+ }
559
+
560
+ if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) && $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) {
561
+ $configuration_check = $this->crawlers[self::REF_FOLLOW]->check_crawl_strategy_configurations( self::REF_FOLLOW_PUSH7 );
562
+
563
+ if ( ! $configuration_check ) {
564
+ echo '<div class="notice notice-warning"><p>';
565
+ _e( 'Configuratin is not enough to get follower count. Please set required parameters at ', self::DOMAIN );
566
+ echo '<a href="#follow-base-cache-push7">' . __( 'Follow Base Cache - Push7', self::DOMAIN ) . '</a>';
567
+ echo '.</p></div>';
568
+ }
569
+ }
570
+
571
+ if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) && $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) {
572
+ $configuration_check = $this->crawlers[self::REF_FOLLOW]->check_crawl_strategy_configurations( self::REF_FOLLOW_TWITTER );
573
+
574
+ if ( ! $configuration_check ) {
575
+ echo '<div class="notice notice-warning"><p>';
576
+ _e( 'Configuratin is not enough to get follower count. Please set required parameters at ', self::DOMAIN );
577
+ echo '<a href="#follow-base-cache-twitter">' . __( 'Follow Base Cache - Twitter', self::DOMAIN ) . '</a>';
578
+ echo '.</p></div>';
579
+ }
580
+ }
581
+
582
+ ?>
583
+
584
+ <div class="sns-cnt-cache">
585
+ <h3 class="nav-tab-wrapper">
586
+ <a class="nav-tab" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ); ?></a>
587
+ <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a>
588
+ <a class="nav-tab" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
589
+ <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
590
+ <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
591
+ <?php } ?>
592
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ); ?></a>
593
+ <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
594
+ </h3>
595
+ <p id="options-menu">
596
+ <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="#follow-variation-analysis"><?php _e( 'Follow Variation Analysis', self::DOMAIN ); ?></a> | <a href="#common-dynamic-cache"><?php _e( 'Dynamic Cache', self::DOMAIN ); ?></a> | <a href="#common-fault-tolerance"><?php _e( 'Fault Tolerance', 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>
597
+ </p>
598
+ <div class="metabox-holder">
599
+ <div id="current-parameter" class="postbox">
600
+ <div class="handlediv" title="Click to toggle"><br></div>
601
+ <h3 class="hndle"><span><?php _e( 'Current Setting', self::DOMAIN ); ?></span></h3>
602
+ <div class="inside">
603
+ <table class="view-table">
604
+ <thead>
605
+ <tr>
606
+ <th><?php _e( 'Capability', self::DOMAIN ); ?></th>
607
+ <th><?php _e( 'Parameter', self::DOMAIN ); ?></th>
608
+ <th><?php _e( 'Value', self::DOMAIN ); ?></th>
609
+ </tr>
610
+ </thead>
611
+ <tbody>
612
+ <tr>
613
+ <td><?php _e( 'Share Base Cache', self::DOMAIN); ?></td>
614
+ <td><?php _e( 'Target SNS', self::DOMAIN ); ?></td>
615
+ <td>
616
+ <?php
617
+ $target_sns = array();
618
+
619
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) {
620
+ $target_sns[] = __( 'Facebook', self::DOMAIN );
621
+ }
622
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) && $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) {
623
+ $target_sns[] = __( 'Google+', self::DOMAIN );
624
+ }
625
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) && $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) {
626
+ $target_sns[] = __( 'Hatena Bookmark', self::DOMAIN );
627
+ }
628
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_LINKEDIN] ) && $this->share_base_cache_target[self::REF_SHARE_LINKEDIN] ) {
629
+ $target_sns[] = __( 'Linkedin', self::DOMAIN );
630
+ }
631
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_PINTEREST] ) && $this->share_base_cache_target[self::REF_SHARE_PINTEREST] ) {
632
+ $target_sns[] = __( 'Pinterest', self::DOMAIN );
633
+ }
634
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_POCKET] ) && $this->share_base_cache_target[self::REF_SHARE_POCKET] ) {
635
+ $target_sns[] = __( 'Pocket', self::DOMAIN );
636
+ }
637
+ if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) {
638
+ $target_sns[] = __( 'Twitter', self::DOMAIN );
639
+ }
640
+ echo esc_html( implode( ", ", $target_sns ) );
641
+ ?>
642
+ </td>
643
+ </tr>
644
+ <tr>
645
+ <td><?php _e( 'Share Base Cache', self::DOMAIN ); ?></td>
646
+ <td><?php _e( 'Custom post types', self::DOMAIN ); ?></td>
647
+ <td>
648
+ <?php
649
+ if ( ! empty( $this->share_base_custom_post_types ) && $this->share_base_custom_post_types ) {
650
+ echo esc_html( implode( ',', $this->share_base_custom_post_types ) );
651
+ } else {
652
+ _e( 'N/A', self::DOMAIN );
653
+ }
654
+ ?>
655
+ </td>
656
+ </tr>
657
+ <tr>
658
+ <td><?php _e( 'Share Base Cache', self::DOMAIN ); ?></td>
659
+ <td><?php _e( 'Interval cheking share count (sec)', self::DOMAIN ); ?></td>
660
+ <td><?php echo esc_html( $this->share_base_check_interval ) . ' ' . __( 'seconds', self::DOMAIN ); ?></td>
661
+ </tr>
662
+ <tr>
663
+ <td><?php _e( 'Share Base Cache', self::DOMAIN ); ?></td>
664
+ <td><?php _e( 'Number of contents to check at a time', self::DOMAIN ) ?></td>
665
+ <td><?php echo esc_html( $this->share_base_posts_per_check ) . ' ' . __( 'contents', self::DOMAIN ); ?></td>
666
+ </tr>
667
+ <tr>
668
+ <td><?php _e( 'Share Base Cache', self::DOMAIN ); ?></td>
669
+ <td><?php _e( 'Scheme migration mode from http to https', self::DOMAIN ); ?></td>
670
+ <td>
671
+ <?php
672
+ if ( $this->scheme_migration_mode ) {
673
+ _e( 'On', self::DOMAIN );
674
+ } else {
675
+ _e( 'Off', self::DOMAIN );
676
+ }
677
+ ?>
678
+ </td>
679
+ </tr>
680
+ <?php if ( $this->scheme_migration_mode ) { ?>
681
+ <tr>
682
+ <td><?php _e( 'Share Base Cache', self::DOMAIN ); ?></td>
683
+ <td><?php _e( 'Scheme migration date from http to https', self::DOMAIN ); ?></td>
684
+ <td>
685
+ <?php
686
+ if ( isset( $this->scheme_migration_date ) ) {
687
+ echo esc_html( $this->scheme_migration_date );
688
+ } else {
689
+ _e( 'N/A', self::DOMAIN );
690
+ }
691
+ ?>
692
+ </td>
693
+ </tr>
694
+ <?php } ?>
695
+
696
+ <?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) { ?>
697
+ <tr>
698
+ <td><?php _e( 'Share Base Cache - Twitter', self::DOMAIN ); ?></td>
699
+ <td><?php _e( 'Alternative Twitter API', self::DOMAIN ); ?></td>
700
+ <td>
701
+ <?php
702
+ if ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_JSOON ) {
703
+ echo '<a href="' . esc_url( 'https://jsoon.digitiminimi.com/' ) . '" target="_blank">' . esc_html( 'widgetoon.js & count.jsoon' ) . '</a>';
704
+ } elseif ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_OPENSHARECOUNT ) {
705
+ echo '<a href="' . esc_url( 'https://opensharecount.com/' ) . '" target="_blank">' . esc_html( 'OpenShareCount' ) . '</a>';
706
+ } elseif ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_TWITCOUNT ) {
707
+ echo '<a href="' . esc_url( 'http://twitcount.com/' ) . '" target="_blank">' . esc_html( 'TwitCount' ) . '</a>';
708
+ } elseif( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_NEWSHARECOUNTS ) {
709
+ echo '<a href="' . esc_url( 'http://newsharecounts.com/' ) . '" target="_blank">' . esc_html( 'NewShareCounts' ) . '</a>';
710
+ }
711
+ ?>
712
+ </td>
713
+ </tr>
714
+ <?php } ?>
715
+ <tr>
716
+ <td><?php _e( 'Share Rush Cache', self::DOMAIN ); ?></td>
717
+ <td><?php _e( 'Term considering posted content as new content', self::DOMAIN ); ?></td>
718
+ <td>
719
+ <?php
720
+ if ( $this->share_rush_new_content_term == 1 ) {
721
+ echo esc_html( $this->share_rush_new_content_term ) . ' ' . __( 'day', self::DOMAIN );
722
+ } elseif ( $this->share_rush_new_content_term > 1 ) {
723
+ echo esc_html( $this->share_rush_new_content_term ) . ' ' . __( 'days', self::DOMAIN );
724
+ }
725
+ ?>
726
+ </td>
727
+ </tr>
728
+ <tr>
729
+ <td><?php _e( 'Share Rush Cache', self::DOMAIN ); ?></td>
730
+ <td><?php _e( 'Interval cheking share count (sec)', self::DOMAIN ); ?></td>
731
+ <td>
732
+ <?php
733
+ echo esc_html( $this->share_rush_check_interval ) . ' ' . __( 'seconds', self::DOMAIN );
734
+ ?>
735
+ </td>
736
+ <tr>
737
+ <td><?php _e( 'Share Rush Cache', self::DOMAIN ); ?></td>
738
+ <td><?php _e( 'Number of contents to check at a time', self::DOMAIN ) ?></td>
739
+ <td><?php echo esc_html( $this->share_rush_posts_per_check ) . ' ' . __( 'contents', self::DOMAIN ); ?></td>
740
+ </tr>
741
+ </tr>
742
+ <tr>
743
+ <td><?php _e( 'Share Variation Analysis', self::DOMAIN ); ?></td>
744
+ <td><?php _e( 'Method to update basis of comparison', self::DOMAIN ); ?></td><td>
745
+ <?php
746
+ switch ( $this->share_variation_analysis_mode ) {
747
+ case self::OPT_SHARE_VARIATION_ANALYSIS_NONE:
748
+ _e( 'Disabled (None)', self::DOMAIN );
749
+ break;
750
+ case self::OPT_SHARE_VARIATION_ANALYSIS_MANUAL:
751
+ _e( 'Enabled (Manual)', self::DOMAIN );
752
+ break;
753
+ case self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER:
754
+ _e( 'Enabled (Scheduler)', self::DOMAIN );
755
+ break;
756
+ default:
757
+ _e( 'Disabled (None)', self::DOMAIN );
758
+ }
759
+ ?>
760
+ </td>
761
+ </tr>
762
+ <?php
763
+ if ( $this->share_variation_analysis_mode === self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER ) {
764
+ ?>
765
+ <tr>
766
+ <td><?php _e( 'Share Variation Analysis', self::DOMAIN ); ?></td>
767
+ <td><?php _e( 'Schedule', self::DOMAIN ); ?></td>
768
+ <td><?php echo esc_html( $this->share_variation_analysis_schedule ); ?></td>
769
+ </tr>
770
+ <?php
771
+ }
772
+ ?>
773
+ <tr>
774
+ <td><?php _e( 'Follow Base Cache', self::DOMAIN); ?></td>
775
+ <td><?php _e( 'Target SNS', self::DOMAIN ); ?></td>
776
+ <td>
777
+ <?php
778
+ $target_sns = array();
779
+ if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) {
780
+ $target_sns[] = 'Facebook';
781
+ }
782
+ if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) {
783
+ $target_sns[] = 'Feedly';
784
+ }
785
+ if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) && $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) {
786
+ $target_sns[] = 'Instagram';
787
+ }
788
+ if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) && $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) {
789
+ $target_sns[] = 'Push7';
790
+ }
791
+ if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) && $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) {
792
+ $target_sns[] = 'Twitter';
793
+ }
794
+ echo esc_html( implode( ', ', $target_sns ) );
795
+ ?>
796
+ </td>
797
+ </tr>
798
+ <tr>
799
+ <td><?php _e( 'Follow Base Cache', self::DOMAIN ); ?></td>
800
+ <td><?php _e( 'Interval cheking follower count (sec)', self::DOMAIN ); ?></td>
801
+ <td><?php echo esc_html( $this->follow_base_check_interval ) . ' ' . __( 'seconds', self::DOMAIN ); ?></td>
802
+ </tr>
803
+ <?php if ( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) { ?>
804
+ <tr>
805
+ <td><?php _e( 'Follow Base Cache - Feedly', self::DOMAIN ); ?></td>
806
+ <td><?php _e( 'Target feed type', self::DOMAIN ); ?></td>
807
+ <td>
808
+ <?php
809
+ switch ( $this->follow_feed_type ) {
810
+ case self::OPT_FEED_TYPE_DEFAULT:
811
+ _e( 'Default', self::DOMAIN );
812
+ break;
813
+ case self::OPT_FEED_TYPE_RSS:
814
+ _e( 'RSS', self::DOMAIN );
815
+ break;
816
+ case self::OPT_FEED_TYPE_RSS2:
817
+ _e( 'RSS2', self::DOMAIN );
818
+ break;
819
+ case self::OPT_FEED_TYPE_RDF:
820
+ _e( 'RDF', self::DOMAIN );
821
+ break;
822
+ case self::OPT_FEED_TYPE_ATOM:
823
+ _e( 'ATOM', self::DOMAIN );
824
+ break;
825
+ default:
826
+ _e( 'Default', self::DOMAIN );
827
+ }
828
+ ?>
829
+ </td>
830
+ </tr>
831
+ <tr>
832
+ <td><?php _e( 'Follow Base Cache - Feedly', self::DOMAIN ); ?></td>
833
+ <td><?php _e( 'Target feed', self::DOMAIN ); ?></td>
834
+ <td><a href="<?php echo esc_url( get_feed_link( $this->follow_feed_type ) ); ?>" target="_blank"><?php echo esc_html( get_feed_link( $this->follow_feed_type ) ); ?></a></td>
835
+ </tr>
836
+ <?php } ?>
837
+ <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) && $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) { ?>
838
+ <tr>
839
+ <td><?php _e( 'Follow Base Cache - Twitter', self::DOMAIN ); ?></td>
840
+ <td><?php _e( 'Target screen name', self::DOMAIN ); ?></td>
841
+ <td>
842
+ <?php
843
+ if ( isset( $this->follow_twitter_screen_name ) && $this->follow_twitter_screen_name ) {
844
+ echo '@' . esc_html( $this->follow_twitter_screen_name );
845
+ } else {
846
+ _e( 'N/A', self::DOMAIN );
847
+ }
848
+ ?>
849
+ </td>
850
+ </tr>
851
+ <?php } ?>
852
+ <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) { ?>
853
+ <tr>
854
+ <td><?php _e( 'Follow Base Cache - Facebook', self::DOMAIN ); ?></td>
855
+ <td><?php _e( 'Page ID', self::DOMAIN ); ?></td>
856
+ <td>
857
+ <?php
858
+ if ( isset( $this->follow_facebook_page_id ) ) {
859
+ echo esc_html( $this->follow_facebook_page_id );
860
+ } else {
861
+ _e( 'N/A', self::DOMAIN );
862
+ }
863
+ ?>
864
+ </td>
865
+ </tr>
866
+ <?php } ?>
867
+ <tr>
868
+ <td><?php _e( 'Follow Variation Analysis', self::DOMAIN ); ?></td>
869
+ <td><?php _e( 'Method to update basis of comparison', self::DOMAIN ); ?></td><td>
870
+ <?php
871
+ switch ( $this->follow_variation_analysis_mode ) {
872
+ case self::OPT_FOLLOW_VARIATION_ANALYSIS_NONE:
873
+ _e( 'Disabled (None)', self::DOMAIN );
874
+ break;
875
+ case self::OPT_FOLLOW_VARIATION_ANALYSIS_MANUAL:
876
+ _e( 'Enabled (Manual)', self::DOMAIN );
877
+ break;
878
+ case self::OPT_FOLLOW_VARIATION_ANALYSIS_SCHEDULER:
879
+ _e( 'Enabled (Scheduler)', self::DOMAIN );
880
+ break;
881
+ default:
882
+ _e( 'Disabled (None)', self::DOMAIN );
883
+ }
884
+ ?>
885
+ </td>
886
+ </tr>
887
+ <?php
888
+ if ( $this->follow_variation_analysis_mode === self::OPT_FOLLOW_VARIATION_ANALYSIS_SCHEDULER ) {
889
+ ?>
890
+ <tr>
891
+ <td><?php _e( 'Follow Variation Analysis', self::DOMAIN ); ?></td>
892
+ <td><?php _e( 'Schedule', self::DOMAIN ); ?></td>
893
+ <td><?php echo esc_html( $this->follow_variation_analysis_schedule ); ?></td>
894
+ </tr>
895
+ <?php
896
+ }
897
+ ?>
898
+ <tr>
899
+ <td><?php _e( 'Dynamic Cache', self::DOMAIN); ?></td>
900
+ <td><?php _e( 'Dynamic caching based on user access', self::DOMAIN ); ?></td><td>
901
+ <?php
902
+ switch ( $this->dynamic_cache_mode ) {
903
+ case self::OPT_COMMON_ACCESS_BASED_CACHE_OFF:
904
+ _e( 'Disabled', self::DOMAIN );
905
+ break;
906
+ case self::OPT_COMMON_ACCESS_BASED_CACHE_ON:
907
+ _e( 'Enabled', self::DOMAIN );
908
+ break;
909
+ default:
910
+ _e( 'Disabled', self::DOMAIN );
911
+ }
912
+ ?>
913
+ </td>
914
+ </tr>
915
+ <tr>
916
+ <td><?php _e( 'Fault Tolerance', self::DOMAIN); ?></td>
917
+ <td><?php _e( 'Fault tolerance of count retrieval', self::DOMAIN ); ?></td><td>
918
+ <?php
919
+ switch ( $this->fault_tolerance_mode ) {
920
+ case self::OPT_COMMON_FAULT_TOLERANCE_OFF:
921
+ _e( 'Disabled', self::DOMAIN );
922
+ break;
923
+ case self::OPT_COMMON_FAULT_TOLERANCE_ON:
924
+ _e( 'Enabled', self::DOMAIN );
925
+ break;
926
+ default:
927
+ _e( 'Disabled', self::DOMAIN );
928
+ }
929
+ ?>
930
+ </td>
931
+ </tr>
932
+ <tr>
933
+ <td><?php _e( 'Data Crawler', self::DOMAIN ); ?></td>
934
+ <td><?php _e( 'Crawl method', self::DOMAIN ); ?></td>
935
+ <td>
936
+ <?php
937
+ switch ( $this->crawler_method ) {
938
+ case self::OPT_COMMON_CRAWLER_METHOD_NORMAL:
939
+ _e( 'Normal (Sequential Retrieval)', self::DOMAIN );
940
+ break;
941
+ case self::OPT_COMMON_CRAWLER_METHOD_CURL:
942
+ _e( 'Extended (Parallel Retrieval)', self::DOMAIN );
943
+ break;
944
+ }
945
+ ?>
946
+ </td>
947
+ </tr>
948
+ <tr>
949
+ <td><?php _e( 'Data Crawler', self::DOMAIN ); ?></td>
950
+ <td><?php _e( 'Crawl retry limit', self::DOMAIN ); ?></td>
951
+ <td>
952
+ <?php
953
+ switch ( $this->crawler_retry_limit ) {
954
+ case -1:
955
+ _e( 'no retry', self::DOMAIN );
956
+ break;
957
+ case 1:
958
+ _e( '1 time', self::DOMAIN );
959
+ break;
960
+ case 2:
961
+ _e( '2 times', self::DOMAIN );
962
+ break;
963
+ case 3:
964
+ _e( '3 times', self::DOMAIN );
965
+ break;
966
+ case 4:
967
+ _e( '2 times', self::DOMAIN );
968
+ break;
969
+ case 5:
970
+ _e( '5 times', self::DOMAIN );
971
+ break;
972
+ }
973
+ ?>
974
+ </td>
975
+ </tr>
976
+ <tr>
977
+ <td><?php _e( 'Data Crawler', self::DOMAIN ); ?></td>
978
+ <td><?php _e( 'SSL verification', self::DOMAIN ); ?></td>
979
+ <td>
980
+ <?php
981
+ if ( $this->crawler_ssl_verification ) {
982
+ _e( 'On', self::DOMAIN );
983
+ } else {
984
+ _e( 'Off', self::DOMAIN );
985
+ }
986
+ ?>
987
+ </td>
988
+ </tr>
989
+ <tr>
990
+ <td><?php _e( 'Data Export', self::DOMAIN ); ?></td>
991
+ <td><?php _e( 'Method of data export', self::DOMAIN ); ?></td><td>
992
+ <?php
993
+ switch ( $this->data_export_mode ) {
994
+ case self::OPT_COMMON_DATA_EXPORT_MANUAL:
995
+ _e( 'Manual', self::DOMAIN );
996
+ break;
997
+ case self::OPT_COMMON_DATA_EXPORT_SCHEDULER:
998
+ _e( 'Scheduler', self::DOMAIN );
999
+ break;
1000
+ }
1001
+ ?>
1002
+ </td>
1003
+ </tr>
1004
+ <?php
1005
+ if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_SCHEDULER ) {
1006
+ ?>
1007
+ <tr>
1008
+ <td><?php _e( 'Data Export', self::DOMAIN ); ?></td>
1009
+ <td><?php _e( 'Interval exporting share count to a csv file', self::DOMAIN ); ?></td>
1010
+ <td><?php echo esc_html( $this->data_export_interval / 3600 ) . ' ' . __( 'hours', self::DOMAIN ); ?></td>
1011
+ </tr>
1012
+ <?php
1013
+ }
1014
+ ?>
1015
+ </tbody>
1016
+ </table>
1017
+ </div>
1018
+ </div>
1019
+ </div>
1020
+ <div class="metabox-holder">
1021
+ <form action="admin.php?page=scc-setting" method="post">
1022
+ <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
1023
+ <div id="share-base-cache" class="postbox">
1024
+ <div class="handlediv" title="Click to toggle"><br></div>
1025
+ <h3 class="hndle"><span><?php _e('Share Base Cache', self::DOMAIN); ?></span></h3>
1026
+ <div class="inside">
1027
+ <table class="form-table">
1028
+ <tr>
1029
+ <th><label><?php _e( 'Target SNS', self::DOMAIN ); ?></label></th>
1030
+ <td>
1031
+ <div class="sns-check">
1032
+ <input type="checkbox" value="1" id="share_base_cache_target_facebook" name="share_base_cache_target_facebook"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) echo ' checked="checked"'; ?> />
1033
+ <label for="share_base_cache_target_facebook"><?php _e( 'Facebook', self::DOMAIN ); ?></label>
1034
+ </div>
1035
+ <div class="sns-check">
1036
+ <input type="checkbox" value="1" id="share_base_cache_target_gplus" name="share_base_cache_target_gplus"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) && $this->share_base_cache_target[self::REF_SHARE_GPLUS] ) echo ' checked="checked"'; ?> />
1037
+ <label for="share_base_cache_target_gplus"><?php _e( 'Google+', self::DOMAIN ); ?></label>
1038
+ </div>
1039
+ <div class="sns-check">
1040
+ <input type="checkbox" value="1" id="share_base_cache_target_hatebu" name="share_base_cache_target_hatebu"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) && $this->share_base_cache_target[self::REF_SHARE_HATEBU] ) echo ' checked="checked"'; ?> />
1041
+ <label for="share_base_cache_target_hatebu"><?php _e( 'Hatena Bookmark', self::DOMAIN ); ?></label>
1042
+ </div>
1043
+ <div class="sns-check">
1044
+ <input type="checkbox" value="1" id="share_base_cache_target_linkedin" name="share_base_cache_target_linkedin"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_LINKEDIN] ) && $this->share_base_cache_target[self::REF_SHARE_LINKEDIN] ) echo ' checked="checked"'; ?> />
1045
+ <label for="share_base_cache_target_linkedin"><?php _e( 'Linkedin', self::DOMAIN ); ?></label>
1046
+ </div>
1047
+ <div class="sns-check">
1048
+ <input type="checkbox" value="1" id="share_base_cache_target_pinterest" name="share_base_cache_target_pinterest"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_PINTEREST] ) && $this->share_base_cache_target[self::REF_SHARE_PINTEREST] ) echo ' checked="checked"'; ?> />
1049
+ <label for="share_base_cache_target_pinterest"><?php _e( 'Pinterest', self::DOMAIN ); ?></label>
1050
+ </div>
1051
+ <div class="sns-check">
1052
+ <input type="checkbox" value="1" id="share_base_cache_target_pocket" name="share_base_cache_target_pocket"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_POCKET] ) && $this->share_base_cache_target[self::REF_SHARE_POCKET] ) echo ' checked="checked"'; ?> />
1053
+ <label for="share_base_cache_target_pocket"><?php _e( 'Pocket', self::DOMAIN ); ?></label>
1054
+ </div>
1055
+ <div class="sns-check">
1056
+ <input type="checkbox" value="1" id="share_base_cache_target_twitter" name="share_base_cache_target_twitter"<?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) echo ' checked="checked"'; ?> />
1057
+ <label for="share_base_cache_target_twitter"><?php _e( 'Twitter', self::DOMAIN ); ?></label>
1058
+ </div>
1059
+ </td>
1060
+ </tr>
1061
+ <tr>
1062
+ <th><label for="share_base_custom_post_types"><?php _e( 'Custom post types', self::DOMAIN ); ?></label></th>
1063
+ <td>
1064
+ <input type="text" class="text" id="share_base_custom_post_types" name="share_base_custom_post_types" size="60" value="<?php echo esc_attr( implode( ',', $this->share_base_custom_post_types ) ); ?>" />
1065
+ <br>
1066
+ <span class="description"><?php _e( 'e.g. aaa, bbb, ccc (comma-delimited)', self::DOMAIN ); ?></span>
1067
+ </td>
1068
+ </tr>
1069
+ <tr>
1070
+ <th><label for="share_base_check_interval"><?php _e( 'Interval cheking share count (sec)', self::DOMAIN ); ?></label></th>
1071
+ <td>
1072
+ <input type="text" class="text" id="share_base_check_interval" name="share_base_check_interval" size="20" value="<?php echo esc_attr( $this->share_base_check_interval ); ?>" />
1073
+ <span class="description"><?php _e( 'Default: 600', self::DOMAIN ); ?></span>
1074
+ </td>
1075
+ </tr>
1076
+ <tr>
1077
+ <th><label for="share_base_posts_per_check"><?php _e( 'Number of contents to check at a time', self::DOMAIN ); ?></label></th>
1078
+ <td>
1079
+ <input type="text" class="text" id="share_base_posts_per_check" name="share_base_posts_per_check" size="20" value="<?php echo esc_attr( $this->share_base_posts_per_check ); ?>" />
1080
+ <span class="description"><?php _e( 'Default: 20', self::DOMAIN ); ?></span>
1081
+ </td>
1082
+ </tr>
1083
+ <tr>
1084
+ <th><label for="scheme_migration_mode"><?php _e( 'Scheme migration mode from http to https', self::DOMAIN ); ?></label></th>
1085
+ <td>
1086
+ <select id="scheme_migration_mode" name="scheme_migration_mode">
1087
+ <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>
1088
+ <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>
1089
+ </select>
1090
+ <span class="description"><?php _e('Default: Off', self::DOMAIN ); ?></span>
1091
+ </td>
1092
+ </tr>
1093
+ <?php if ( $this->scheme_migration_mode ) { ?>
1094
+ <tr>
1095
+ <th><label for="scheme-migration-date"><?php _e( 'Scheme migration date from http to https', self::DOMAIN ); ?></label></th>
1096
+ <td>
1097
+ <input id="scheme-migration-date" type="text" class="text" name="scheme_migration_date" size="20" value="<?php echo esc_attr( $this->scheme_migration_date ); ?>" />
1098
+ <span class="description"><?php _e( 'Default: N/A', self::DOMAIN ); ?></span>
1099
+ <script>
1100
+ jQuery(document).ready(function() {
1101
+ jQuery('#scheme-migration-date').datepicker({
1102
+ dateFormat : 'yy/mm/dd'
1103
+ });
1104
+ });
1105
+ </script>
1106
+ </td>
1107
+ </tr>
1108
+ <?php } ?>
1109
+ </table>
1110
+ <div class="submit-button">
1111
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1112
+ <input type="submit" class="button button-secondary" name="clear_share_base_cache" value="<?php _e( 'Clear Cache', self::DOMAIN ); ?>">
1113
+ </div>
1114
+ </div>
1115
+ </div>
1116
+ <?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) && $this->share_base_cache_target[self::REF_SHARE_FACEBOOK] ) { ?>
1117
+ <div id="share-base-cache-facebook" class="postbox">
1118
+ <div class="handlediv" title="Click to toggle"><br></div>
1119
+ <h3 class="hndle"><span><?php _e( 'Share Base Cache - Facebook', self::DOMAIN ); ?></span></h3>
1120
+ <div class="inside">
1121
+ <table class="form-table">
1122
+ <tr>
1123
+ <th><label><?php _e( 'Developer page', self::DOMAIN ); ?></label></th>
1124
+ <td>
1125
+ <a href="https://developers.facebook.com/" target="_blank">https://developers.facebook.com/</a>
1126
+ <br>
1127
+ <span class="description"><?php _e( 'Register a application in Facebook developer page to get the following App ID and App Secret.', self::DOMAIN ); ?></span>
1128
+ </td>
1129
+ </tr>
1130
+ <tr>
1131
+ <th><label for="share_facebook_app_id"><?php _e( 'App ID (Client ID)', self::DOMAIN ); ?></label></th>
1132
+ <td>
1133
+ <input type="password" id="share_facebook_app_id" class="text" name="share_facebook_app_id" size="60" value="<?php echo esc_attr( $this->share_facebook_app_id ); ?>" />
1134
+ <br>
1135
+ <span class="description"><?php _e( 'App ID for Facebook API', self::DOMAIN ); ?></span>
1136
+ </td>
1137
+ </tr>
1138
+ <tr>
1139
+ <th><label for="share_facebook_app_secret"><?php _e( 'App Secret (Client Secret)', self::DOMAIN ); ?></label></th>
1140
+ <td>
1141
+ <input type="password" id="share_facebook_app_secret" class="text" name="share_facebook_app_secret" size="60" value="<?php echo esc_attr( $this->share_facebook_app_secret ); ?>" />
1142
+ <br>
1143
+ <span class="description"><?php _e( 'App Secret for Facebook API', self::DOMAIN ); ?></span>
1144
+ </td>
1145
+ </tr>
1146
+ <?php if ( isset( $this->share_facebook_app_id ) && $this->share_facebook_app_id && isset( $this->share_facebook_app_secret ) && $this->share_facebook_app_secret ) { ?>
1147
+ <tr>
1148
+ <th><label for="tmp_share_facebook_access_token"><?php _e( 'Access Token', self::DOMAIN ); ?></label></th>
1149
+ <td>
1150
+ <input type="password" id="tmp_share_facebook_access_token" class="text" name="tmp_share_facebook_access_token" size="60" value="<?php echo esc_attr( $this->share_facebook_access_token ); ?>" readonly />
1151
+ <br>
1152
+ <span class="description"><?php _e( 'Access Token for Facebook API', self::DOMAIN ); ?></span>
1153
+ </td>
1154
+ </tr>
1155
+ <?php } ?>
1156
+ </table>
1157
+ <div class="submit-button">
1158
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1159
+ </div>
1160
+ </div>
1161
+ </div>
1162
+ <?php } ?>
1163
+ <?php if ( isset( $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) && $this->share_base_cache_target[self::REF_SHARE_TWITTER] ) { ?>
1164
+ <div id="share-base-cache-twitter" class="postbox">
1165
+ <div class="handlediv" title="Click to toggle"><br></div>
1166
+ <h3 class="hndle"><span><?php _e( 'Share Base Cache - Twitter', self::DOMAIN ); ?></span></h3>
1167
+ <div class="inside">
1168
+ <table class="form-table">
1169
+ <tr>
1170
+ <th><label for="share_alternative_twitter_api"><?php _e( 'Alternative Twitter API', self::DOMAIN ); ?></label></th>
1171
+ <td>
1172
+ <select id="share_alternative_twitter_api" name="share_alternative_twitter_api">
1173
+ <option value="1"<?php if ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_JSOON ) echo ' selected="selected"'; ?>><?php echo esc_html( 'widgetoon.js & count.jsoon' ); ?></option>
1174
+ <option value="2"<?php if ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_OPENSHARECOUNT ) echo ' selected="selected"'; ?>><?php echo esc_html( 'OpenShareCount' ); ?></option>
1175
+ <option value="3"<?php if ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_TWITCOUNT ) echo ' selected="selected"'; ?>><?php echo esc_html( 'TwitCount' ); ?></option>
1176
+ <option value="4"<?php if ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_NEWSHARECOUNTS ) echo ' selected="selected"'; ?>><?php echo esc_html( 'NewShareCounts' ); ?></option>
1177
+ </select>
1178
+ <span class="description"><?php _e( 'Default: ', self::DOMAIN ); echo esc_html( 'widgetoon.js & count.jsoon' ); ?></span>
1179
+ </td>
1180
+ </tr>
1181
+ <tr>
1182
+ <th><label><?php _e( 'Registration destination', self::DOMAIN ); ?></label></th>
1183
+ <td>
1184
+ <?php
1185
+ if ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_JSOON ) {
1186
+ echo '<a href="' . esc_url( 'https://jsoon.digitiminimi.com/' ) . '" target="_blank">' . esc_html( 'https://jsoon.digitiminimi.com/' ) . '</a>';
1187
+ } elseif ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_OPENSHARECOUNT ) {
1188
+ echo '<a href="' . esc_url( 'https://opensharecount.com/' ) . '" target="_blank">' . esc_html( 'https://opensharecount.com/' ) . '</a>';
1189
+ } elseif ( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_TWITCOUNT ) {
1190
+ echo '<a href="' . esc_url( 'http://twitcount.com/' ) . '" target="_blank">' . esc_html( 'http://twitcount.com/' ) . '</a>';
1191
+ } elseif( $this->share_base_twitter_api === self::OPT_SHARE_TWITTER_API_NEWSHARECOUNTS ) {
1192
+ echo '<a href="' . esc_url( 'http://newsharecounts.com/' ) . '" target="_blank">' . esc_html( 'http://newsharecounts.com/' ) . '</a>';
1193
+ }
1194
+ ?>
1195
+ <br />
1196
+ <span class="description"><?php _e( 'You need to register information such as your domain with the above site in order to start counting.', self::DOMAIN ); ?></span>
1197
+ </td>
1198
+ </tr>
1199
+ </table>
1200
+ <div class="submit-button">
1201
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1202
+ </div>
1203
+ </div>
1204
+ </div>
1205
+ <?php } ?>
1206
+ <div id="share-rush-cache" class="postbox">
1207
+ <div class="handlediv" title="Click to toggle"><br></div>
1208
+ <h3 class="hndle"><span><?php _e( 'Share Rush Cache', self::DOMAIN); ?></span></h3>
1209
+ <div class="inside">
1210
+ <table class="form-table">
1211
+ <tr>
1212
+ <th><label for="share_rush_new_content_term"><?php _e( 'Term considering posted content as new content', self::DOMAIN ); ?></label></th>
1213
+ <td>
1214
+ <select id="share_rush_new_content_term" name="share_rush_new_content_term">
1215
+ <option value="1"<?php if ( $this->share_rush_new_content_term === 1 ) echo ' selected="selected"'; ?>><?php _e( '1 day', self::DOMAIN ); ?></option>
1216
+ <option value="2"<?php if ( $this->share_rush_new_content_term === 2 ) echo ' selected="selected"'; ?>><?php _e( '2 days', self::DOMAIN ); ?></option>
1217
+ <option value="3"<?php if ( $this->share_rush_new_content_term === 3 ) echo ' selected="selected"'; ?>><?php _e( '3 days', self::DOMAIN ); ?></option>
1218
+ <option value="4"<?php if ( $this->share_rush_new_content_term === 4 ) echo ' selected="selected"'; ?>><?php _e( '4 days', self::DOMAIN ); ?></option>
1219
+ <option value="5"<?php if ( $this->share_rush_new_content_term === 5 ) echo ' selected="selected"'; ?>><?php _e( '5 days', self::DOMAIN ); ?></option>
1220
+ <option value="6"<?php if ( $this->share_rush_new_content_term === 6 ) echo ' selected="selected"'; ?>><?php _e( '6 days', self::DOMAIN ); ?></option>
1221
+ <option value="7"<?php if ( $this->share_rush_new_content_term === 7 ) echo ' selected="selected"'; ?>><?php _e( '7 days', self::DOMAIN ); ?></option>
1222
+ <option value="8"<?php if ( $this->share_rush_new_content_term === 8 ) echo ' selected="selected"'; ?>><?php _e( '8 days', self::DOMAIN ); ?></option>
1223
+ <option value="9"<?php if ( $this->share_rush_new_content_term === 9 ) echo ' selected="selected"'; ?>><?php _e( '9 days', self::DOMAIN ); ?></option>
1224
+ <option value="10"<?php if ( $this->share_rush_new_content_term === 10 ) echo ' selected="selected"'; ?>><?php _e( '10 days', self::DOMAIN ); ?></option>
1225
+ <option value="11"<?php if ( $this->share_rush_new_content_term === 11 ) echo ' selected="selected"'; ?>><?php _e( '11 days', self::DOMAIN ); ?></option>
1226
+ <option value="12"<?php if ( $this->share_rush_new_content_term === 12 ) echo ' selected="selected"'; ?>><?php _e( '12 days', self::DOMAIN ); ?></option>
1227
+ <option value="13"<?php if ( $this->share_rush_new_content_term === 13 ) echo ' selected="selected"'; ?>><?php _e( '13 days', self::DOMAIN ); ?></option>
1228
+ <option value="14"<?php if ( $this->share_rush_new_content_term === 14 ) echo ' selected="selected"'; ?>><?php _e( '14 days', self::DOMAIN ); ?></option>
1229
+ </select>
1230
+ <span class="description"><?php _e( 'Default: 3 days', self::DOMAIN ); ?></span>
1231
+ </td>
1232
+ </tr>
1233
+ <tr>
1234
+ <th><label for="share_rush_check_interval"><?php _e( 'Interval cheking share count (sec)', self::DOMAIN ); ?></label></th>
1235
+ <td>
1236
+ <input type="text" id="share_rush_check_interval" class="text" name="share_rush_check_interval" size="20" value="<?php echo esc_attr( $this->share_rush_check_interval ); ?>" />
1237
+ <span class="description"><?php _e( 'Default: 600', self::DOMAIN ); ?></span>
1238
+ </td>
1239
+ </tr>
1240
+ <tr>
1241
+ <th><label for="share_rush_posts_per_check"><?php _e( 'Number of contents to check at a time', self::DOMAIN ); ?></label></th>
1242
+ <td>
1243
+ <input type="text" id="share_rush_posts_per_check" class="text" name="share_rush_posts_per_check" size="20" value="<?php echo esc_attr( $this->share_rush_posts_per_check ); ?>" />
1244
+ <span class="description"><?php _e( 'Default: 20', self::DOMAIN ); ?></span>
1245
+ </td>
1246
+ </tr>
1247
+ </table>
1248
+ <div class="submit-button">
1249
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1250
+ </div>
1251
+ </div>
1252
+ </div>
1253
+ <div id="share-variation-analysis" class="postbox">
1254
+ <div class="handlediv" title="Click to toggle"><br></div>
1255
+ <h3 class="hndle"><span><?php _e( 'Share Variation Analysis', self::DOMAIN ); ?></span></h3>
1256
+ <div class="inside">
1257
+ <table class="form-table">
1258
+ <tr>
1259
+ <th><label for="share_variation_analysis_mode"><?php _e( 'Method to update basis of comparison', self::DOMAIN ); ?></label></th>
1260
+ <td>
1261
+ <select id="share_variation_analysis_mode" name="share_variation_analysis_mode">
1262
+ <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>
1263
+ <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>
1264
+ <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>
1265
+ </select>
1266
+ <span class="description"><?php _e( 'Disabled (None)', self::DOMAIN ); ?></span>
1267
+ </td>
1268
+ </tr>
1269
+ <?php
1270
+ if ( $this->share_variation_analysis_mode === self::OPT_SHARE_VARIATION_ANALYSIS_SCHEDULER ) {
1271
+ list( $cronstr['minutes'], $cronstr['hours'], $cronstr['mday'], $cronstr['mon'], $cronstr['wday'] ) = explode( ' ', $this->share_variation_analysis_schedule, 5 );
1272
+ if ( strstr( $cronstr['minutes'], '*/' ) ) {
1273
+ $minutes = explode( '/', $cronstr['minutes'] );
1274
+ } else {
1275
+ $minutes = explode( ',', $cronstr['minutes'] );
1276
+ }
1277
+ if ( strstr( $cronstr['hours'], '*/' ) ) {
1278
+ $hours = explode( '/', $cronstr['hours'] );
1279
+ } else {
1280
+ $hours = explode( ',', $cronstr['hours'] );
1281
+ }
1282
+ if ( strstr( $cronstr['mday'], '*/' ) ) {
1283
+ $mday = explode( '/', $cronstr['mday'] );
1284
+ } else {
1285
+ $mday = explode( ',', $cronstr['mday'] );
1286
+ }
1287
+ if ( strstr( $cronstr['mon'], '*/' ) ) {
1288
+ $mon = explode( '/', $cronstr['mon'] );
1289
+ } else {
1290
+ $mon = explode( ',', $cronstr['mon'] );
1291
+ }
1292
+ if ( strstr( $cronstr['wday'], '*/' ) ) {
1293
+ $wday = explode( '/', $cronstr['wday'] );
1294
+ } else {
1295
+ $wday = explode( ',', $cronstr['wday'] );
1296
+ }
1297
+ ?>
1298
+ <tr class="a_wpcron">
1299
+ <th scope="row"><?php _e( 'Scheduler', self::DOMAIN ); ?></th>
1300
+ <td>
1301
+ <table class="wpcron">
1302
+ <tr>
1303
+ <th>
1304
+ <?php _e( 'Type', self::DOMAIN ); ?>
1305
+ </th>
1306
+ <th>
1307
+ </th>
1308
+ <th>
1309
+ <?php _e( 'Hour', self::DOMAIN ); ?>
1310
+ </th>
1311
+ <th>
1312
+ <?php _e( 'Minute', self::DOMAIN ); ?>
1313
+ </th>
1314
+ </tr>
1315
+ <tr>
1316
+ <td>
1317
+ <label for="idcronbtype-mon">
1318
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $mday[0] ), FALSE ) . ' name="a_cronbtype" value="mon" /> ' . __( 'monthly', self::DOMAIN ); ?>
1319
+ </label>
1320
+ </td>
1321
+ <td>
1322
+ <select name="a_moncronmday">
1323
+ <?php
1324
+ for ( $i = 1; $i <= 31; $i ++ ) {
1325
+ $on_day = '';
1326
+
1327
+ switch ( $i ) {
1328
+ case 1:
1329
+ $on_day = __( 'on 1.', self::DOMAIN );
1330
+ break;
1331
+ case 2:
1332
+ $on_day = __( 'on 2.', self::DOMAIN );
1333
+ break;
1334
+ case 3:
1335
+ $on_day = __( 'on 3.', self::DOMAIN );
1336
+ break;
1337
+ case 4:
1338
+ $on_day = __( 'on 4.', self::DOMAIN );
1339
+ break;
1340
+ case 5:
1341
+ $on_day = __( 'on 5.', self::DOMAIN );
1342
+ break;
1343
+ case 6:
1344
+ $on_day = __( 'on 6.', self::DOMAIN );
1345
+ break;
1346
+ case 7:
1347
+ $on_day = __( 'on 7.', self::DOMAIN );
1348
+ break;
1349
+ case 8:
1350
+ $on_day = __( 'on 8.', self::DOMAIN );
1351
+ break;
1352
+ case 9:
1353
+ $on_day = __( 'on 9.', self::DOMAIN );
1354
+ break;
1355
+ case 10:
1356
+ $on_day = __( 'on 10.', self::DOMAIN );
1357
+ break;
1358
+ case 11:
1359
+ $on_day = __( 'on 11.', self::DOMAIN );
1360
+ break;
1361
+ case 12:
1362
+ $on_day = __( 'on 12.', self::DOMAIN );
1363
+ break;
1364
+ case 13:
1365
+ $on_day = __( 'on 13.', self::DOMAIN );
1366
+ break;
1367
+ case 14:
1368
+ $on_day = __( 'on 14.', self::DOMAIN );
1369
+ break;
1370
+ case 15:
1371
+ $on_day = __( 'on 15.', self::DOMAIN );
1372
+ break;
1373
+ case 16:
1374
+ $on_day = __( 'on 16.', self::DOMAIN );
1375
+ break;
1376
+ case 17:
1377
+ $on_day = __( 'on 17.', self::DOMAIN );
1378
+ break;
1379
+ case 18:
1380
+ $on_day = __( 'on 18.', self::DOMAIN );
1381
+ break;
1382
+ case 19:
1383
+ $on_day = __( 'on 19.', self::DOMAIN );
1384
+ break;
1385
+ case 20:
1386
+ $on_day = __( 'on 20.', self::DOMAIN );
1387
+ break;
1388
+ case 21:
1389
+ $on_day = __( 'on 21.', self::DOMAIN );
1390
+ break;
1391
+ case 22:
1392
+ $on_day = __( 'on 22.', self::DOMAIN );
1393
+ break;
1394
+ case 23:
1395
+ $on_day = __( 'on 23.', self::DOMAIN );
1396
+ break;
1397
+ case 24:
1398
+ $on_day = __( 'on 24.', self::DOMAIN );
1399
+ break;
1400
+ case 25:
1401
+ $on_day = __( 'on 25.', self::DOMAIN );
1402
+ break;
1403
+ case 26:
1404
+ $on_day = __( 'on 26.', self::DOMAIN );
1405
+ break;
1406
+ case 27:
1407
+ $on_day = __( 'on 27.', self::DOMAIN );
1408
+ break;
1409
+ case 28:
1410
+ $on_day = __( 'on 28.', self::DOMAIN );
1411
+ break;
1412
+ case 29:
1413
+ $on_day = __( 'on 29.', self::DOMAIN );
1414
+ break;
1415
+ case 30:
1416
+ $on_day = __( 'on 30.', self::DOMAIN );
1417
+ break;
1418
+ case 31:
1419
+ $on_day = __( 'on 31.', self::DOMAIN );
1420
+ break;
1421
+ }
1422
+
1423
+ echo '<option ' . selected( in_array( "$i", $mday, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $on_day . '</option>';
1424
+ }
1425
+ ?>
1426
+ </select>
1427
+ </td>
1428
+ <td>
1429
+ <select name="a_moncronhours">
1430
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
1431
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1432
+ } ?>
1433
+ </select>
1434
+ </td>
1435
+ <td>
1436
+ <select name="a_moncronminutes">
1437
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
1438
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1439
+ } ?>
1440
+ </select>
1441
+ </td>
1442
+ </tr>
1443
+ <tr>
1444
+ <td>
1445
+ <label for="idcronbtype-week">
1446
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $wday[0] ), FALSE ) . ' name="a_cronbtype" value="week" /> ' . __( 'weekly', self::DOMAIN ); ?>
1447
+ </label>
1448
+ </td>
1449
+ <td>
1450
+ <select name="a_weekcronwday">
1451
+ <?php
1452
+ echo '<option ' . selected( in_array( '0', $wday, TRUE ), TRUE, FALSE ) . ' value="0" />' . __( 'Sunday', self::DOMAIN ) . '</option>';
1453
+ echo '<option ' . selected( in_array( '1', $wday, TRUE ), TRUE, FALSE ) . ' value="1" />' . __( 'Monday', self::DOMAIN ) . '</option>';
1454
+ echo '<option ' . selected( in_array( '2', $wday, TRUE ), TRUE, FALSE ) . ' value="2" />' . __( 'Tuesday', self::DOMAIN ) . '</option>';
1455
+ echo '<option ' . selected( in_array( '3', $wday, TRUE ), TRUE, FALSE ) . ' value="3" />' . __( 'Wednesday', self::DOMAIN ) . '</option>';
1456
+ echo '<option ' . selected( in_array( '4', $wday, TRUE ), TRUE, FALSE ) . ' value="4" />' . __( 'Thursday', self::DOMAIN ) . '</option>';
1457
+ echo '<option ' . selected( in_array( '5', $wday, TRUE ), TRUE, FALSE ) . ' value="5" />' . __( 'Friday', self::DOMAIN ) . '</option>';
1458
+ echo '<option ' . selected( in_array( '6', $wday, TRUE ), TRUE, FALSE ) . ' value="6" />' . __( 'Saturday', self::DOMAIN ) . '</option>';
1459
+ ?>
1460
+ </select>
1461
+ </td>
1462
+ <td>
1463
+ <select name="a_weekcronhours">
1464
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
1465
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1466
+ } ?>
1467
+ </select>
1468
+ </td>
1469
+ <td>
1470
+ <select name="a_weekcronminutes">
1471
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
1472
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1473
+ } ?>
1474
+ </select>
1475
+ </td>
1476
+ </tr>
1477
+ <tr>
1478
+ <td>
1479
+ <label for="idcronbtype-day">
1480
+ <?php echo '<input class="radio" type="radio"' . checked( "**", $mday[0] . $wday[0], FALSE ) . ' name="a_cronbtype" value="day" /> ' . __( 'daily', self::DOMAIN ); ?>
1481
+ </label>
1482
+ </td>
1483
+ <td>
1484
+ </td>
1485
+ <td>
1486
+ <select name="a_daycronhours">
1487
+ <?php
1488
+ for ( $i = 0; $i < 24; $i ++ ) {
1489
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1490
+ }
1491
+ ?>
1492
+ </select>
1493
+ </td>
1494
+ <td>
1495
+ <select name="a_daycronminutes">
1496
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
1497
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
1498
+ } ?>
1499
+ </select>
1500
+ </td>
1501
+ </tr>
1502
+ </table>
1503
+ </td>
1504
+ </tr>
1505
+ <?php
1506
+ }
1507
+ ?>
1508
+ </table>
1509
+ <div class="submit-button">
1510
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1511
+ <input type="submit" class="button button-secondary" name="update_share_comparison_base" value="<?php _e( 'Update Basis of Comparison', self::DOMAIN ); ?>" />
1512
+ </div>
1513
+ </div>
1514
+ </div>
1515
+ <div id="follow-base-cache" class="postbox">
1516
+ <div class="handlediv" title="Click to toggle"><br></div>
1517
+ <h3 class="hndle"><span><?php _e( 'Follow Base Cache', self::DOMAIN ); ?></span></h3>
1518
+ <div class="inside">
1519
+ <table class="form-table">
1520
+ <tr>
1521
+ <th><label><?php _e( 'Target SNS', self::DOMAIN ); ?></label></th>
1522
+ <td>
1523
+ <div class="sns-check">
1524
+ <input type="checkbox" value="1" id="follow_base_cache_target_facebook" name="follow_base_cache_target_facebook"<?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) echo ' checked="checked"'; ?> />
1525
+ <label for="follow_base_cache_target_facebook"><?php _e( 'Facebook', self::DOMAIN ); ?></label>
1526
+ </div>
1527
+ <div class="sns-check">
1528
+ <input type="checkbox" value="1" id="follow_base_cache_target_feedly" name="follow_base_cache_target_feedly"<?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) echo ' checked="checked"'; ?> />
1529
+ <label for="follow_base_cache_target_feedly"><?php _e( 'Feedly', self::DOMAIN ); ?></label>
1530
+ </div>
1531
+ <div class="sns-check">
1532
+ <input type="checkbox" value="1" id="follow_base_cache_target_instagram" name="follow_base_cache_target_instagram"<?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) && $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) echo ' checked="checked"'; ?> />
1533
+ <label for="follow_base_cache_target_instagram"><?php _e( 'Instagram', self::DOMAIN ); ?></label>
1534
+ </div>
1535
+ <div class="sns-check">
1536
+ <input type="checkbox" value="1" id="follow_base_cache_target_push7" name="follow_base_cache_target_push7"<?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) && $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) echo ' checked="checked"'; ?> />
1537
+ <label for="follow_base_cache_target_push7"><?php _e( 'Push7', self::DOMAIN ); ?></label>
1538
+ </div>
1539
+ <div class="sns-check">
1540
+ <input type="checkbox" value="1" id="follow_base_cache_target_twitter" name="follow_base_cache_target_twitter"<?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) && $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) echo ' checked="checked"'; ?> />
1541
+ <label for="follow_base_cache_target_twitter"><?php _e( 'Twitter', self::DOMAIN ); ?></label>
1542
+ </div>
1543
+ </td>
1544
+ </tr>
1545
+ <tr>
1546
+ <th><label for="follow_base_check_interval"><?php _e( 'Interval cheking follower count (sec)', self::DOMAIN ); ?></label></th>
1547
+ <td>
1548
+ <input type="text" class="text" id="follow_base_check_interval" name="follow_base_check_interval" size="20" value="<?php echo esc_attr( $this->follow_base_check_interval); ?>" />
1549
+ <span class="description"><?php _e( 'Default: 86400 Minimum: 3600', self::DOMAIN ); ?></span>
1550
+ </td>
1551
+ </tr>
1552
+ </table>
1553
+ <div class="submit-button">
1554
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1555
+ <input type="submit" class="button button-secondary" name="direct_follow_base_cache" value="<?php _e( 'Cache', self::DOMAIN ); ?>">
1556
+ <input type="submit" class="button button-secondary" name="clear_follow_base_cache" value="<?php _e( 'Clear Cache', self::DOMAIN ); ?>">
1557
+ </div>
1558
+ </div>
1559
+ </div>
1560
+ <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FACEBOOK] ) { ?>
1561
+ <div id="follow-base-cache-facebook" class="postbox">
1562
+ <div class="handlediv" title="Click to toggle"><br></div>
1563
+ <h3 class="hndle"><span><?php _e( 'Follow Base Cache - Facebook', self::DOMAIN ); ?></span></h3>
1564
+ <div class="inside">
1565
+ <table class="form-table">
1566
+ <tr>
1567
+ <th><label for="follow_facebook_page_id"><?php _e( 'Page ID', self::DOMAIN ); ?></label></th>
1568
+ <td>
1569
+ <input type="text" class="text" id="follow_facebook_page_id" name="follow_facebook_page_id" size="30" value="<?php echo esc_attr( $this->follow_facebook_page_id ); ?>" />
1570
+ <br>
1571
+ <span class="description"><?php _e( 'Facebook page ID that you want to get follower count', self::DOMAIN ); ?></span>
1572
+ </td>
1573
+ </tr>
1574
+ <tr>
1575
+ <th><label><?php _e( 'Developer page', self::DOMAIN ); ?></label></th>
1576
+ <td>
1577
+ <a href="https://developers.facebook.com/" target="_blank">https://developers.facebook.com/</a>
1578
+ <br>
1579
+ <span class="description"><?php _e( 'Register a application in Facebook developer page to get the following App ID and App Secret.', self::DOMAIN ); ?></span>
1580
+ </td>
1581
+ </tr>
1582
+ <tr>
1583
+ <th><label for="follow_facebook_app_id"><?php _e( 'App ID (Client ID)', self::DOMAIN ); ?></label></th>
1584
+ <td>
1585
+ <input type="password" id="follow_facebook_app_id" class="text" name="follow_facebook_app_id" size="60" value="<?php echo esc_attr( $this->follow_facebook_app_id ); ?>" />
1586
+ <br>
1587
+ <span class="description"><?php _e( 'App ID for Facebook API', self::DOMAIN ); ?></span>
1588
+ </td>
1589
+ </tr>
1590
+ <tr>
1591
+ <th><label for="follow_facebook_app_secret"><?php _e( 'App Secret (Client Secret)', self::DOMAIN ); ?></label></th>
1592
+ <td>
1593
+ <input type="password" id="follow_facebook_app_secret" class="text" name="follow_facebook_app_secret" size="60" value="<?php echo esc_attr( $this->follow_facebook_app_secret ); ?>" />
1594
+ <br>
1595
+ <span class="description"><?php _e( 'App Secret for Facebook API', self::DOMAIN ); ?></span>
1596
+ </td>
1597
+ </tr>
1598
+ <tr>
1599
+ <th><label for="tmp_follow_facebook_redirect_uri"><?php _e( 'Redirect URI', self::DOMAIN ); ?></label></th>
1600
+ <td>
1601
+ <input type="text" id="tmp_follow_facebook_redirect_uri" class="text" name="tmp_follow_facebook_redirect_uri" size="60" value="<?php echo esc_url( plugins_url() . '/sns-count-cache/' ); ?>" onclick="this.focus();this.select()" title="<?php _e( 'To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac).', self::DOMAIN ); ?>" readonly />
1602
+ <br>
1603
+ <span class="description"><?php _e( 'Copy and set this to the field of "Valid OAuth redirect URIs" in application management page of Facebook developer page.', self::DOMAIN ); ?></span>
1604
+ </td>
1605
+ </tr>
1606
+ <?php if ( isset( $_GET['action'] ) && $_GET['action'] && $_GET['action'] === 'facebook-auth' ) { ?>
1607
+ <tr>
1608
+ <th><label for="tmp_follow_facebook_access_token"><?php _e( 'Access Token', self::DOMAIN ); ?></label></th>
1609
+ <td>
1610
+ <?php if ( ! is_wp_error( $tmp_facebook_access_token ) ) { ?>
1611
+ <input type="text" id="tmp_follow_facebook_access_token" class="text" name="tmp_follow_facebook_access_token" size="60" value="<?php echo esc_attr( $tmp_facebook_access_token ); ?>" onclick="this.focus();this.select()" title="<?php _e( 'To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac).', self::DOMAIN ); ?>" readonly />
1612
+ <br>
1613
+ <span class="description"><?php _e( 'Copy and pase this into the fields below.', self::DOMAIN ); ?></span>
1614
+ <?php } else { ?>
1615
+ <span class="update-message notice-error"><p><?php echo esc_html( $tmp_facebook_access_token->get_error_message() ); ?></p></span>
1616
+ <?php } ?>
1617
+ </td>
1618
+ </tr>
1619
+ <?php } ?>
1620
+ <?php if ( isset( $this->follow_facebook_page_id ) && $this->follow_facebook_page_id && isset( $this->follow_facebook_app_id ) && $this->follow_facebook_app_id && isset( $this->follow_facebook_app_secret ) && $this->follow_facebook_app_secret ) { ?>
1621
+ <tr>
1622
+ <th><label for="follow_facebook_access_token"><?php _e( 'Access Token', self::DOMAIN ); ?></label></th>
1623
+ <td>
1624
+ <input type="password" id="follow_facebook_access_token" class="text" name="follow_facebook_access_token" size="60" value="<?php echo esc_attr( $this->follow_facebook_access_token ); ?>" />
1625
+ <br>
1626
+ <span class="description"><?php _e( 'Access Token for Facebook API', self::DOMAIN ); ?></span>
1627
+ </td>
1628
+ </tr>
1629
+ <?php } ?>
1630
+ </table>
1631
+ <div class="submit-button">
1632
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1633
+ <?php if ( isset( $this->follow_facebook_page_id ) && $this->follow_facebook_page_id && isset( $this->follow_facebook_app_id ) && $this->follow_facebook_app_id && isset( $this->follow_facebook_app_secret ) && $this->follow_facebook_app_secret ) { ?>
1634
+ <a href="https://www.facebook.com/dialog/oauth?client_id=<?php echo esc_attr( $this->follow_facebook_app_id ); ?>&scope=manage_pages,read_insights&state=<?php echo wp_create_nonce( 'facebook-auth' ); ?>&redirect_uri=<?php echo plugins_url() . '/sns-count-cache/'; ?>?action=facebook-auth" class="button button-secondary"><?php _e( 'Get Access Token', self::DOMAIN ); ?></a>
1635
+ <?php } ?>
1636
+ </div>
1637
+ </div>
1638
+ </div>
1639
+ <?php } ?>
1640
+ <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) && $this->follow_base_cache_target[self::REF_FOLLOW_FEEDLY] ) { ?>
1641
+ <div id="follow-base-cache-feedly" class="postbox">
1642
+ <div class="handlediv" title="Click to toggle"><br></div>
1643
+ <h3 class="hndle"><span><?php _e( 'Follow Base Cache - Feedly', self::DOMAIN ); ?></span></h3>
1644
+ <div class="inside">
1645
+ <table class="form-table">
1646
+ <tr>
1647
+ <th><label for="follow_feed_type"><?php _e( 'Target feed type', self::DOMAIN ); ?></label></th>
1648
+ <td>
1649
+ <select id="follow_feed_type" name="follow_feed_type">
1650
+ <option value="default"<?php if ( $this->follow_feed_type === self::OPT_FEED_TYPE_DEFAULT ) echo ' selected="selected"'; ?>><?php _e( 'Default', self::DOMAIN ) ?></option>
1651
+ <option value="rss"<?php if ( $this->follow_feed_type === self::OPT_FEED_TYPE_RSS ) echo ' selected="selected"'; ?>><?php _e( 'RSS', self::DOMAIN ); ?></option>
1652
+ <option value="rss2"<?php if ( $this->follow_feed_type === self::OPT_FEED_TYPE_RSS2 ) echo ' selected="selected"'; ?>><?php _e( 'RSS2', self::DOMAIN ); ?></option>
1653
+ <option value="rdf"<?php if ( $this->follow_feed_type === self::OPT_FEED_TYPE_RDF ) echo ' selected="selected"'; ?>><?php _e( 'RDF', self::DOMAIN ); ?></option>
1654
+ <option value="atom"<?php if ( $this->follow_feed_type === self::OPT_FEED_TYPE_ATOM ) echo ' selected="selected"'; ?>><?php _e( 'ATOM', self::DOMAIN ); ?></option>
1655
+ </select>
1656
+ <span class="description"><?php _e( 'Default: Default', self::DOMAIN ); ?></span>
1657
+ </td>
1658
+ </tr>
1659
+ <tr>
1660
+ <th><label><?php _e( 'Target feed', self::DOMAIN ); ?></label></th>
1661
+ <td><a href="<?php echo esc_url( get_feed_link( $this->follow_feed_type ) ); ?>" target="_blank"><?php echo esc_html( get_feed_link( $this->follow_feed_type ) ); ?></a></td>
1662
+ </tr>
1663
+ </table>
1664
+ <div class="submit-button">
1665
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1666
+ </div>
1667
+ </div>
1668
+ </div>
1669
+ <?php } ?>
1670
+ <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) && $this->follow_base_cache_target[self::REF_FOLLOW_INSTAGRAM] ) { ?>
1671
+ <div id="follow-base-cache-instagram" class="postbox">
1672
+ <div class="handlediv" title="Click to toggle"><br></div>
1673
+ <h3 class="hndle"><span><?php _e( 'Follow Base Cache - Instagram', self::DOMAIN ); ?></span></h3>
1674
+ <div class="inside">
1675
+ <table class="form-table">
1676
+ <tr>
1677
+ <th><label><?php _e( 'Developer page', self::DOMAIN ); ?></label></th>
1678
+ <td>
1679
+ <a href="https://www.instagram.com/developer/" target="_blank">https://www.instagram.com/developer/</a>
1680
+ <br>
1681
+ <span class="description"><?php _e( 'Register a client in Instagram developer page to get the following Client ID and Client Secret.', self::DOMAIN ); ?></span>
1682
+ </td>
1683
+ </tr>
1684
+ <tr>
1685
+ <th><label for="follow_instagram_client_id"><?php _e( 'Client ID', self::DOMAIN ); ?></label></th>
1686
+ <td>
1687
+ <input type="password" id="follow_instagram_client_id" class="text" name="follow_instagram_client_id" size="60" value="<?php echo esc_attr( $this->follow_instagram_client_id ); ?>" />
1688
+ <br>
1689
+ <span class="description"><?php _e( 'Client ID for Instagram API', self::DOMAIN ); ?></span>
1690
+ </td>
1691
+ </tr>
1692
+ <tr>
1693
+ <th><label for="follow_instagram_client_secret"><?php _e( 'Client Secret', self::DOMAIN ); ?></label></th>
1694
+ <td>
1695
+ <input type="password" id="follow_instagram_client_secret" class="text" name="follow_instagram_client_secret" size="60" value="<?php echo esc_attr( $this->follow_instagram_client_secret ); ?>" />
1696
+ <br>
1697
+ <span class="description"><?php _e( 'Client Secret for Instagram API', self::DOMAIN ); ?></span>
1698
+ </td>
1699
+ </tr>
1700
+ <tr>
1701
+ <th><label for="tmp_follow_instagram_redirect_uri"><?php _e( 'Redirect URI', self::DOMAIN ); ?></label></th>
1702
+ <td>
1703
+ <input type="text" id="tmp_follow_instagram_redirect_uri" class="text" name="tmp_follow_instagram_redirect_uri" size="60" value="<?php echo esc_url( plugins_url() . '/sns-count-cache/' ); ?>" onclick="this.focus();this.select()" title="<?php _e( 'To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac).', self::DOMAIN ); ?>" readonly />
1704
+ <br>
1705
+ <span class="description"><?php _e( 'Copy and set this to the field of "Valid redirect URIs" in the client management page of Instagram developer page.', self::DOMAIN ); ?></span>
1706
+ </td>
1707
+ </tr>
1708
+ <?php if ( isset( $_GET['action'] ) && $_GET['action'] && $_GET['action'] === 'instagram-auth' ) { ?>
1709
+ <tr>
1710
+ <th><label for="tmp_follow_instagram_access_token"><?php _e( 'Access Token', self::DOMAIN ); ?></label></th>
1711
+ <td>
1712
+ <?php if ( ! is_wp_error( $tmp_instagram_access_token ) ) { ?>
1713
+ <input type="text" id="tmp_follow_instagram_access_token" class="text" name="tmp_follow_instagram_access_token" size="60" value="<?php echo esc_attr( $tmp_instagram_access_token ); ?>" onclick="this.focus();this.select()" title="<?php _e( 'To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac).', self::DOMAIN ); ?>" readonly />
1714
+ <br>
1715
+ <span class="description"><?php _e( 'Copy and pase this into the fields below.', self::DOMAIN ); ?></span>
1716
+ <?php } else { ?>
1717
+ <span class="update-message notice-error"><p><?php echo esc_html( $tmp_instagram_access_token->get_error_message() ); ?></p></span>
1718
+ <?php } ?>
1719
+ </td>
1720
+ </tr>
1721
+ <?php } ?>
1722
+ <?php if ( isset( $this->follow_instagram_client_id ) && $this->follow_instagram_client_id && isset( $this->follow_instagram_client_secret ) && $this->follow_instagram_client_secret ) { ?>
1723
+ <tr>
1724
+ <th><label for="follow_instagram_access_token"><?php _e( 'Access Token', self::DOMAIN ); ?></label></th>
1725
+ <td>
1726
+ <input type="password" id="follow_instagram_access_token" class="text" name="follow_instagram_access_token" size="60" value="<?php echo esc_attr( $this->follow_instagram_access_token ); ?>" />
1727
+ <br>
1728
+ <span class="description"><?php _e( 'Access Token for Instagram API', self::DOMAIN ); ?></span>
1729
+ </td>
1730
+ </tr>
1731
+ <?php } ?>
1732
+ </table>
1733
+ <div class="submit-button">
1734
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1735
+ <?php if ( isset( $this->follow_instagram_client_id ) && $this->follow_instagram_client_id && isset( $this->follow_instagram_client_secret ) && $this->follow_instagram_client_secret ) { ?>
1736
+ <a href="https://api.instagram.com/oauth/authorize/?client_id=<?php echo esc_attr( $this->follow_instagram_client_id ); ?>&response_type=code&state=<?php echo wp_create_nonce( 'instagram-auth' ); ?>&redirect_uri=<?php echo plugins_url() . '/sns-count-cache/'; ?>?action=instagram-auth" class="button button-secondary"><?php _e( 'Get Access Token', self::DOMAIN ); ?></a>
1737
+ <?php } ?>
1738
+ </div>
1739
+ </div>
1740
+ </div>
1741
+ <?php } ?>
1742
+ <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) && $this->follow_base_cache_target[self::REF_FOLLOW_PUSH7] ) { ?>
1743
+ <div id="follow-base-cache-push7" class="postbox">
1744
+ <div class="handlediv" title="Click to toggle"><br></div>
1745
+ <h3 class="hndle"><span><?php _e( 'Follow Base Cache - Push7', self::DOMAIN ); ?></span></h3>
1746
+ <div class="inside">
1747
+ <table class="form-table">
1748
+ <tr>
1749
+ <th><label><?php _e( 'Push7 page', self::DOMAIN ); ?></label></th>
1750
+ <td>
1751
+ <a href="https://push7.jp/" target="_blank">https://push7.jp/</a>
1752
+ <br>
1753
+ <span class="description"><?php _e( 'Register a application in Push7 page to get the following AppNo.', self::DOMAIN ); ?></span>
1754
+ </td>
1755
+ </tr>
1756
+ <tr>
1757
+ <th><label for="follow_push7_appno"><?php _e( 'AppNo', self::DOMAIN ); ?></label></th>
1758
+ <td>
1759
+ <input type="password" id="follow_push7_appno" class="text" name="follow_push7_appno" size="60" value="<?php echo esc_attr( $this->follow_push7_appno ); ?>" />
1760
+ <br>
1761
+ <span class="description"><?php _e( 'AppNo for Push7 API', self::DOMAIN ); ?></span>
1762
+ </td>
1763
+ </tr>
1764
+ </table>
1765
+ <div class="submit-button">
1766
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1767
+ </div>
1768
+ </div>
1769
+ </div>
1770
+ <?php } ?>
1771
+ <?php if ( isset( $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) && $this->follow_base_cache_target[self::REF_FOLLOW_TWITTER] ) { ?>
1772
+ <div id="follow-base-cache-twitter" class="postbox">
1773
+ <div class="handlediv" title="Click to toggle"><br></div>
1774
+ <h3 class="hndle"><span><?php _e( 'Follow Base Cache - Twitter', self::DOMAIN ); ?></span></h3>
1775
+ <div class="inside">
1776
+ <table class="form-table">
1777
+ <tr>
1778
+ <th><label for="follow_twitter_screen_name"><?php _e( 'Screen Name', self::DOMAIN ); ?></label></th>
1779
+ <td>
1780
+ <span class="at-mark">@</span>
1781
+ <input type="text" id="follow_twitter_screen_name" class="text" name="follow_twitter_screen_name" size="30" value="<?php echo esc_attr( $this->follow_twitter_screen_name ); ?>" />
1782
+ <br>
1783
+ <span class="description"><?php _e( 'Twitter screen name that you want to get follower count', self::DOMAIN ); ?></span>
1784
+ </td>
1785
+ </tr>
1786
+ <tr>
1787
+ <th><label><?php _e( 'Developer page', self::DOMAIN ); ?></label></th>
1788
+ <td>
1789
+ <a href="https://dev.twitter.com/" target="_blank">https://dev.twitter.com/</a>
1790
+ <br>
1791
+ <span class="description"><?php _e( 'Register a application in Twitter developer page to get the following Consumer Key and Consumer Secret.', self::DOMAIN ); ?></span>
1792
+ </td>
1793
+ </tr>
1794
+ <tr>
1795
+ <th><label for="follow_twitter_consumer_key"><?php _e( 'Consumer Key (API Key)', self::DOMAIN ); ?></label></th>
1796
+ <td>
1797
+ <input type="password" id="follow_twitter_consumer_key" class="text" name="follow_twitter_consumer_key" size="60" value="<?php echo esc_attr( $this->follow_twitter_consumer_key ); ?>" />
1798
+ <br>
1799
+ <span class="description"><?php _e( 'Cconsumer Key for Twitter API', self::DOMAIN ); ?></span>
1800
+ </td>
1801
+ </tr>
1802
+ <tr>
1803
+ <th><label for="follow_twitter_consumer_secret"><?php _e( 'Consumer Secret (API Secret)', self::DOMAIN ); ?></label></th>
1804
+ <td>
1805
+ <input type="password" id="follow_twitter_consumer_secret" class="text" name="follow_twitter_consumer_secret" size="60" value="<?php echo esc_attr( $this->follow_twitter_consumer_secret ); ?>" />
1806
+ <br>
1807
+ <span class="description"><?php _e( 'Consumer Secret for Twitter API', self::DOMAIN ); ?></span>
1808
+ </td>
1809
+ </tr>
1810
+ <?php if ( isset( $_POST["get_tiwtter_bearer_token"] ) && $_POST["get_tiwtter_bearer_token"] === __( 'Get Bearer Token', self::DOMAIN ) ) { ?>
1811
+ <tr>
1812
+ <th><label for="tmp_follow_twitter_bearer_token"><?php _e( 'Bearer Token', self::DOMAIN ); ?></label></th>
1813
+ <td>
1814
+ <?php if ( ! is_wp_error( $tmp_twitter_bearer_token ) ) { ?>
1815
+ <input type="text" id="tmp_follow_twitter_bearer_token" class="text" name="tmp_follow_twitter_bearer_token" size="60" value="<?php echo esc_attr( $tmp_twitter_bearer_token ); ?>" onclick="this.focus();this.select()" title="<?php _e( 'To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac).', self::DOMAIN ); ?>" readonly />
1816
+ <br>
1817
+ <span class="description"><?php _e( 'Copy and pase this into the fields below.', self::DOMAIN ); ?></span>
1818
+ <?php } else { ?>
1819
+ <span class="update-message notice-error"><p><?php echo esc_html( $tmp_twitter_bearer_token->get_error_message() ); ?></p></span>
1820
+ <?php } ?>
1821
+ </td>
1822
+ </tr>
1823
+ <?php } ?>
1824
+ <?php if ( isset( $this->follow_twitter_consumer_key ) && $this->follow_twitter_consumer_key && isset( $this->follow_twitter_consumer_secret ) && $this->follow_twitter_consumer_secret ) { ?>
1825
+ <tr>
1826
+ <th><label for="follow_twitter_bearer_token"><?php _e( 'Bearer Token', self::DOMAIN ); ?></label></th>
1827
+ <td>
1828
+ <input type="password" id="follow_twitter_bearer_token" class="text" name="follow_twitter_bearer_token" size="60" value="<?php echo esc_attr( $this->follow_twitter_bearer_token ); ?>" />
1829
+ <br>
1830
+ <span class="description"><?php _e( 'Bearer Token for Twitter API', self::DOMAIN ); ?></span>
1831
+ </td>
1832
+ </tr>
1833
+ <?php } ?>
1834
+ </table>
1835
+ <div class="submit-button">
1836
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
1837
+ <?php if ( isset( $this->follow_twitter_consumer_key ) && $this->follow_twitter_consumer_key && isset( $this->follow_twitter_consumer_secret ) && $this->follow_twitter_consumer_secret ) { ?>
1838
+ <input type="submit" class="button button-secondary" name="get_tiwtter_bearer_token" value="<?php _e( 'Get Bearer Token', self::DOMAIN ); ?>" />
1839
+ <?php } ?>
1840
+ </div>
1841
+ </div>
1842
+ </div>
1843
+ <?php } ?>
1844
+ <div id="follow-variation-analysis" class="postbox">
1845
+ <div class="handlediv" title="Click to toggle"><br></div>
1846
+ <h3 class="hndle"><span><?php _e( 'Follow Variation Analysis', self::DOMAIN ); ?></span></h3>
1847
+ <div class="inside">
1848
+ <table class="form-table">
1849
+ <tr>
1850
+ <th><label for="follow_variation_analysis_mode"><?php _e( 'Method to update basis of comparison', self::DOMAIN ); ?></label></th>
1851
+ <td>
1852
+ <select id="follow_variation_analysis_mode" name="follow_variation_analysis_mode">
1853
+ <option value="1"<?php if ( $this->follow_variation_analysis_mode === self::OPT_FOLLOW_VARIATION_ANALYSIS_NONE ) echo ' selected="selected"'; ?>><?php _e( 'Disabled (None)', self::DOMAIN ); ?></option>
1854
+ <option value="2"<?php if ( $this->follow_variation_analysis_mode === self::OPT_FOLLOW_VARIATION_ANALYSIS_MANUAL ) echo ' selected="selected"'; ?>><?php _e( 'Enabled (Manual)', self::DOMAIN ); ?></option>
1855
+ <option value="3"<?php if ( $this->follow_variation_analysis_mode === self::OPT_FOLLOW_VARIATION_ANALYSIS_SCHEDULER ) echo ' selected="selected"'; ?>><?php _e( 'Enabled (Scheduler)', self::DOMAIN ); ?></option>
1856
+ </select>
1857
+ <span class="description"><?php _e( 'Disabled (None)', self::DOMAIN ); ?></span>
1858
+ </td>
1859
+ </tr>
1860
+ <?php
1861
+ if ( $this->follow_variation_analysis_mode === self::OPT_FOLLOW_VARIATION_ANALYSIS_SCHEDULER ) {
1862
+ list( $cronstr['minutes'], $cronstr['hours'], $cronstr['mday'], $cronstr['mon'], $cronstr['wday'] ) = explode( ' ', $this->follow_variation_analysis_schedule, 5 );
1863
+ if ( strstr( $cronstr['minutes'], '*/' ) ) {
1864
+ $minutes = explode( '/', $cronstr['minutes'] );
1865
+ } else {
1866
+ $minutes = explode( ',', $cronstr['minutes'] );
1867
+ }
1868
+ if ( strstr( $cronstr['hours'], '*/' ) ) {
1869
+ $hours = explode( '/', $cronstr['hours'] );
1870
+ } else {
1871
+ $hours = explode( ',', $cronstr['hours'] );
1872
+ }
1873
+ if ( strstr( $cronstr['mday'], '*/' ) ) {
1874
+ $mday = explode( '/', $cronstr['mday'] );
1875
+ } else {
1876
+ $mday = explode( ',', $cronstr['mday'] );
1877
+ }
1878
+ if ( strstr( $cronstr['mon'], '*/' ) ) {
1879
+ $mon = explode( '/', $cronstr['mon'] );
1880
+ } else {
1881
+ $mon = explode( ',', $cronstr['mon'] );
1882
+ }
1883
+ if ( strstr( $cronstr['wday'], '*/' ) ) {
1884
+ $wday = explode( '/', $cronstr['wday'] );
1885
+ } else {
1886
+ $wday = explode( ',', $cronstr['wday'] );
1887
+ }
1888
+ ?>
1889
+ <tr class="a_wpcron">
1890
+ <th scope="row"><?php _e( 'Scheduler', self::DOMAIN ); ?></th>
1891
+ <td>
1892
+ <table class="wpcron">
1893
+ <tr>
1894
+ <th>
1895
+ <?php _e( 'Type', self::DOMAIN ); ?>
1896
+ </th>
1897
+ <th>
1898
+ </th>
1899
+ <th>
1900
+ <?php _e( 'Hour', self::DOMAIN ); ?>
1901
+ </th>
1902
+ <th>
1903
+ <?php _e( 'Minute', self::DOMAIN ); ?>
1904
+ </th>
1905
+ </tr>
1906
+ <tr>
1907
+ <td>
1908
+ <label for="idcronbtype-mon">
1909
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $mday[0] ), FALSE ) . ' name="b_cronbtype" value="mon" /> ' . __( 'monthly', self::DOMAIN ); ?>
1910
+ </label>
1911
+ </td>
1912
+ <td>
1913
+ <select name="b_moncronmday">
1914
+ <?php
1915
+ for ( $i = 1; $i <= 31; $i ++ ) {
1916
+ $on_day = '';
1917
+
1918
+ switch ( $i ) {
1919
+ case 1:
1920
+ $on_day = __( 'on 1.', self::DOMAIN );
1921
+ break;
1922
+ case 2:
1923
+ $on_day = __( 'on 2.', self::DOMAIN );
1924
+ break;
1925
+ case 3:
1926
+ $on_day = __( 'on 3.', self::DOMAIN );
1927
+ break;
1928
+ case 4:
1929
+ $on_day = __( 'on 4.', self::DOMAIN );
1930
+ break;
1931
+ case 5:
1932
+ $on_day = __( 'on 5.', self::DOMAIN );
1933
+ break;
1934
+ case 6:
1935
+ $on_day = __( 'on 6.', self::DOMAIN );
1936
+ break;
1937
+ case 7:
1938
+ $on_day = __( 'on 7.', self::DOMAIN );
1939
+ break;
1940
+ case 8:
1941
+ $on_day = __( 'on 8.', self::DOMAIN );
1942
+ break;
1943
+ case 9:
1944
+ $on_day = __( 'on 9.', self::DOMAIN );
1945
+ break;
1946
+ case 10:
1947
+ $on_day = __( 'on 10.', self::DOMAIN );
1948
+ break;
1949
+ case 11:
1950
+ $on_day = __( 'on 11.', self::DOMAIN );
1951
+ break;
1952
+ case 12:
1953
+ $on_day = __( 'on 12.', self::DOMAIN );
1954
+ break;
1955
+ case 13:
1956
+ $on_day = __( 'on 13.', self::DOMAIN );
1957
+ break;
1958
+ case 14:
1959
+ $on_day = __( 'on 14.', self::DOMAIN );
1960
+ break;
1961
+ case 15:
1962
+ $on_day = __( 'on 15.', self::DOMAIN );
1963
+ break;
1964
+ case 16:
1965
+ $on_day = __( 'on 16.', self::DOMAIN );
1966
+ break;
1967
+ case 17:
1968
+ $on_day = __( 'on 17.', self::DOMAIN );
1969
+ break;
1970
+ case 18:
1971
+ $on_day = __( 'on 18.', self::DOMAIN );
1972
+ break;
1973
+ case 19:
1974
+ $on_day = __( 'on 19.', self::DOMAIN );
1975
+ break;
1976
+ case 20:
1977
+ $on_day = __( 'on 20.', self::DOMAIN );
1978
+ break;
1979
+ case 21:
1980
+ $on_day = __( 'on 21.', self::DOMAIN );
1981
+ break;
1982
+ case 22:
1983
+ $on_day = __( 'on 22.', self::DOMAIN );
1984
+ break;
1985
+ case 23:
1986
+ $on_day = __( 'on 23.', self::DOMAIN );
1987
+ break;
1988
+ case 24:
1989
+ $on_day = __( 'on 24.', self::DOMAIN );
1990
+ break;
1991
+ case 25:
1992
+ $on_day = __( 'on 25.', self::DOMAIN );
1993
+ break;
1994
+ case 26:
1995
+ $on_day = __( 'on 26.', self::DOMAIN );
1996
+ break;
1997
+ case 27:
1998
+ $on_day = __( 'on 27.', self::DOMAIN );
1999
+ break;
2000
+ case 28:
2001
+ $on_day = __( 'on 28.', self::DOMAIN );
2002
+ break;
2003
+ case 29:
2004
+ $on_day = __( 'on 29.', self::DOMAIN );
2005
+ break;
2006
+ case 30:
2007
+ $on_day = __( 'on 30.', self::DOMAIN );
2008
+ break;
2009
+ case 31:
2010
+ $on_day = __( 'on 31.', self::DOMAIN );
2011
+ break;
2012
+ }
2013
+
2014
+ echo '<option ' . selected( in_array( "$i", $mday, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $on_day . '</option>';
2015
+ }
2016
+ ?>
2017
+ </select>
2018
+ </td>
2019
+ <td>
2020
+ <select name="b_moncronhours">
2021
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
2022
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2023
+ } ?>
2024
+ </select>
2025
+ </td>
2026
+ <td>
2027
+ <select name="b_moncronminutes">
2028
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
2029
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2030
+ } ?>
2031
+ </select>
2032
+ </td>
2033
+ </tr>
2034
+ <tr>
2035
+ <td>
2036
+ <label for="idcronbtype-week">
2037
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $wday[0] ), FALSE ) . ' name="a_cronbtype" value="week" /> ' . __( 'weekly', self::DOMAIN ); ?>
2038
+ </label>
2039
+ </td>
2040
+ <td>
2041
+ <select name="b_weekcronwday">
2042
+ <?php
2043
+ echo '<option ' . selected( in_array( '0', $wday, TRUE ), TRUE, FALSE ) . ' value="0" />' . __( 'Sunday', self::DOMAIN ) . '</option>';
2044
+ echo '<option ' . selected( in_array( '1', $wday, TRUE ), TRUE, FALSE ) . ' value="1" />' . __( 'Monday', self::DOMAIN ) . '</option>';
2045
+ echo '<option ' . selected( in_array( '2', $wday, TRUE ), TRUE, FALSE ) . ' value="2" />' . __( 'Tuesday', self::DOMAIN ) . '</option>';
2046
+ echo '<option ' . selected( in_array( '3', $wday, TRUE ), TRUE, FALSE ) . ' value="3" />' . __( 'Wednesday', self::DOMAIN ) . '</option>';
2047
+ echo '<option ' . selected( in_array( '4', $wday, TRUE ), TRUE, FALSE ) . ' value="4" />' . __( 'Thursday', self::DOMAIN ) . '</option>';
2048
+ echo '<option ' . selected( in_array( '5', $wday, TRUE ), TRUE, FALSE ) . ' value="5" />' . __( 'Friday', self::DOMAIN ) . '</option>';
2049
+ echo '<option ' . selected( in_array( '6', $wday, TRUE ), TRUE, FALSE ) . ' value="6" />' . __( 'Saturday', self::DOMAIN ) . '</option>';
2050
+ ?>
2051
+ </select>
2052
+ </td>
2053
+ <td>
2054
+ <select name="b_weekcronhours">
2055
+ <?php for ( $i = 0; $i < 24; $i ++ ) {
2056
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2057
+ } ?>
2058
+ </select>
2059
+ </td>
2060
+ <td>
2061
+ <select name="b_weekcronminutes">
2062
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
2063
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2064
+ } ?>
2065
+ </select>
2066
+ </td>
2067
+ </tr>
2068
+ <tr>
2069
+ <td>
2070
+ <label for="idcronbtype-day">
2071
+ <?php echo '<input class="radio" type="radio"' . checked( "**", $mday[0] . $wday[0], FALSE ) . ' name="b_cronbtype" value="day" /> ' . __( 'daily', self::DOMAIN ); ?>
2072
+ </label>
2073
+ </td>
2074
+ <td>
2075
+ </td>
2076
+ <td>
2077
+ <select name="b_daycronhours">
2078
+ <?php
2079
+ for ( $i = 0; $i < 24; $i ++ ) {
2080
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2081
+ }
2082
+ ?>
2083
+ </select>
2084
+ </td>
2085
+ <td>
2086
+ <select name="b_daycronminutes">
2087
+ <?php for ( $i = 0; $i < 60; $i = $i + 5 ) {
2088
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2089
+ } ?>
2090
+ </select>
2091
+ </td>
2092
+ </tr>
2093
+ </table>
2094
+ </td>
2095
+ </tr>
2096
+ <?php
2097
+ }
2098
+ ?>
2099
+ </table>
2100
+ <div class="submit-button">
2101
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
2102
+ <input type="submit" class="button button-secondary" name="update_follow_comparison_base" value="<?php _e( 'Update Basis of Comparison', self::DOMAIN ); ?>" />
2103
+ </div>
2104
+ </div>
2105
+ </div>
2106
+ <div id="common-dynamic-cache" class="postbox">
2107
+ <div class="handlediv" title="Click to toggle"><br></div>
2108
+ <h3 class="hndle"><span><?php _e( 'Dynamic Cache', self::DOMAIN ); ?></span></h3>
2109
+ <div class="inside">
2110
+ <table class="form-table">
2111
+ <tr>
2112
+ <th><label for="dynamic_cache_mode"><?php _e( 'Dynamic caching based on user access', self::DOMAIN ); ?></label></th>
2113
+ <td>
2114
+ <select id="dynamic_cache_mode" name="dynamic_cache_mode">
2115
+ <option value="1"<?php if ( $this->dynamic_cache_mode === self::OPT_COMMON_ACCESS_BASED_CACHE_OFF ) echo ' selected="selected"'; ?>><?php _e( 'Disabled', self::DOMAIN ); ?></option>
2116
+ <option value="5"<?php if ( $this->dynamic_cache_mode === self::OPT_COMMON_ACCESS_BASED_CACHE_ON ) echo ' selected="selected"'; ?>><?php _e( 'Enabled', self::DOMAIN ); ?></option>
2117
+ </select>
2118
+ <span class="description"><?php _e( 'Default: Disabled', self::DOMAIN ); ?></span>
2119
+ </td>
2120
+ </tr>
2121
+ </table>
2122
+ <div class="submit-button">
2123
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
2124
+ </div>
2125
+ </div>
2126
+ </div>
2127
+ <div id="common-fault-tolerance" class="postbox">
2128
+ <div class="handlediv" title="Click to toggle"><br></div>
2129
+ <h3 class="hndle"><span><?php _e( 'Fault Tolerance', self::DOMAIN ); ?></span></h3>
2130
+ <div class="inside">
2131
+ <table class="form-table">
2132
+ <tr>
2133
+ <th><label for="fault_tolerance_mode"><?php _e( 'Fault tolerant mode of count retrieval', self::DOMAIN ); ?></label></th>
2134
+ <td>
2135
+ <select id="fault_tolerance_mode" name="fault_tolerance_mode">
2136
+ <option value="1"<?php if ( $this->fault_tolerance_mode === self::OPT_COMMON_FAULT_TOLERANCE_OFF ) echo ' selected="selected"'; ?>><?php _e( 'Disabled', self::DOMAIN ); ?></option>
2137
+ <option value="2"<?php if ( $this->fault_tolerance_mode === self::OPT_COMMON_FAULT_TOLERANCE_ON ) echo ' selected="selected"'; ?>><?php _e( 'Enabled', self::DOMAIN ); ?></option>
2138
+ </select>
2139
+ <span class="description"><?php _e( 'Default: Disabled', self::DOMAIN ); ?></span>
2140
+ </td>
2141
+ </tr>
2142
+ </table>
2143
+ <div class="submit-button">
2144
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
2145
+ </div>
2146
+ </div>
2147
+ </div>
2148
+ <div id="common-data-crawler" class="postbox">
2149
+ <div class="handlediv" title="Click to toggle"><br></div>
2150
+ <h3 class="hndle"><span><?php _e( 'Data Crawler', self::DOMAIN ); ?></span></h3>
2151
+ <div class="inside">
2152
+ <table class="form-table">
2153
+ <tr>
2154
+ <th><label><?php _e( 'Crawl method', self::DOMAIN ); ?></label></th>
2155
+ <td>
2156
+ <?php
2157
+ switch ( $this->crawler_method ) {
2158
+ case self::OPT_COMMON_CRAWLER_METHOD_NORMAL:
2159
+ _e( 'Normal (Sequential Retrieval)', self::DOMAIN );
2160
+ break;
2161
+ case self::OPT_COMMON_CRAWLER_METHOD_CURL:
2162
+ _e( 'Extended (Parallel Retrieval)', self::DOMAIN );
2163
+ break;
2164
+ }
2165
+ ?>
2166
+ </td>
2167
+ </tr>
2168
+ <tr>
2169
+ <th><label for="common_data_crawler_retry_limit"><?php _e( 'Crawl retry limit', self::DOMAIN ); ?></label></th>
2170
+ <td>
2171
+ <select id="common_data_crawler_retry_limit" name="common_data_crawler_retry_limit">
2172
+ <option value="-1"<?php if ( $this->crawler_retry_limit === -1 ) echo ' selected="selected"'; ?>><?php _e( 'no retry', self::DOMAIN ); ?></option>
2173
+ <option value="1"<?php if ( $this->crawler_retry_limit === 1 ) echo ' selected="selected"'; ?>><?php _e( '1 time', self::DOMAIN ); ?></option>
2174
+ <option value="2"<?php if ( $this->crawler_retry_limit === 2 ) echo ' selected="selected"'; ?>><?php _e( '2 times', self::DOMAIN ); ?></option>
2175
+ <option value="3"<?php if ( $this->crawler_retry_limit === 3 ) echo ' selected="selected"'; ?>><?php _e( '3 times', self::DOMAIN ); ?></option>
2176
+ <option value="4"<?php if ( $this->crawler_retry_limit === 4 ) echo ' selected="selected"'; ?>><?php _e( '4 times', self::DOMAIN ); ?></option>
2177
+ <option value="5"<?php if ( $this->crawler_retry_limit === 5 ) echo ' selected="selected"'; ?>><?php _e( '5 times', self::DOMAIN ); ?></option>
2178
+ </select>
2179
+ <span class="description"><?php _e( 'Default: 1 time', self::DOMAIN ); ?></span>
2180
+ </td>
2181
+ </tr>
2182
+ <tr>
2183
+ <th><label for="crawler_ssl_verification"><?php _e( 'SSL verification', self::DOMAIN ); ?></label></th>
2184
+ <td>
2185
+ <select id="crawler_ssl_verification" name="crawler_ssl_verification">
2186
+ <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>
2187
+ <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>
2188
+ </select>
2189
+ <span class="description"><?php _e( 'Default: On', self::DOMAIN ); ?></span>
2190
+ </td>
2191
+ </tr>
2192
+ </table>
2193
+ <div class="submit-button">
2194
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
2195
+ </div>
2196
+ </div>
2197
+ </div>
2198
+ <div id="common-data-export" class="postbox">
2199
+ <div class="handlediv" title="Click to toggle"><br></div>
2200
+ <h3 class="hndle"><span><?php _e( 'Data Export', self::DOMAIN ); ?></span></h3>
2201
+ <div class="inside">
2202
+ <table class="form-table">
2203
+ <tr>
2204
+ <th><label for="data_export_mode"><?php _e( 'Method of data export', self::DOMAIN ); ?></label></th>
2205
+ <td>
2206
+ <select id="data_export_mode" name="data_export_mode">
2207
+ <option value="1"<?php if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_MANUAL ) echo ' selected="selected"'; ?>><?php _e( 'Manual', self::DOMAIN ); ?></option>
2208
+ <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>
2209
+ </select>
2210
+ <span class="description"><?php _e( 'Default: Manual', self::DOMAIN ); ?></span>
2211
+ </td>
2212
+ </tr>
2213
+ <?php
2214
+ if ( $this->data_export_mode === self::OPT_COMMON_DATA_EXPORT_SCHEDULER ) {
2215
+ list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ', $this->data_export_schedule, 5 );
2216
+ if ( strstr( $cronstr[ 'minutes' ], '*/' ) ) {
2217
+ $minutes = explode( '/', $cronstr[ 'minutes' ] );
2218
+ } else {
2219
+ $minutes = explode( ',', $cronstr[ 'minutes' ] );
2220
+ }
2221
+ if ( strstr( $cronstr[ 'hours' ], '*/' ) ) {
2222
+ $hours = explode( '/', $cronstr[ 'hours' ] );
2223
+ } else {
2224
+ $hours = explode( ',', $cronstr[ 'hours' ] );
2225
+ }
2226
+ if ( strstr( $cronstr[ 'mday' ], '*/' ) ) {
2227
+ $mday = explode( '/', $cronstr[ 'mday' ] );
2228
+ } else {
2229
+ $mday = explode( ',', $cronstr[ 'mday' ] );
2230
+ }
2231
+ if ( strstr( $cronstr[ 'mon' ], '*/' ) ) {
2232
+ $mon = explode( '/', $cronstr[ 'mon' ] );
2233
+ } else {
2234
+ $mon = explode( ',', $cronstr[ 'mon' ] );
2235
+ }
2236
+ if ( strstr( $cronstr[ 'wday' ], '*/' ) ) {
2237
+ $wday = explode( '/', $cronstr[ 'wday' ] );
2238
+ } else {
2239
+ $wday = explode( ',', $cronstr[ 'wday' ] );
2240
+ }
2241
+ ?>
2242
+ <tr class="e_wpcron">
2243
+ <th scope="row"><?php _e( 'Scheduler', self::DOMAIN ); ?></th>
2244
+ <td>
2245
+ <table class="wpcron">
2246
+ <tr>
2247
+ <th>
2248
+ <?php _e( 'Type', self::DOMAIN ); ?>
2249
+ </th>
2250
+ <th>
2251
+ </th>
2252
+ <th>
2253
+ <?php _e( 'Hour', self::DOMAIN ); ?>
2254
+ </th>
2255
+ <th>
2256
+ <?php _e( 'Minute', self::DOMAIN ); ?>
2257
+ </th>
2258
+ </tr>
2259
+ <tr>
2260
+ <td>
2261
+ <label for="idcronbtype-mon">
2262
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $mday[0] ), FALSE ) . ' name="e_cronbtype" value="mon" /> ' . __( 'monthly', self::DOMAIN ); ?>
2263
+ </label>
2264
+ </td>
2265
+ <td>
2266
+ <select name="e_moncronmday">
2267
+ <?php
2268
+ for ( $i = 1; $i <= 31; $i ++ ) {
2269
+ $on_day = '';
2270
+
2271
+ switch ( $i ) {
2272
+ case 1:
2273
+ $on_day = __( 'on 1.', self::DOMAIN );
2274
+ break;
2275
+ case 2:
2276
+ $on_day = __( 'on 2.', self::DOMAIN );
2277
+ break;
2278
+ case 3:
2279
+ $on_day = __( 'on 3.', self::DOMAIN );
2280
+ break;
2281
+ case 4:
2282
+ $on_day = __( 'on 4.', self::DOMAIN );
2283
+ break;
2284
+ case 5:
2285
+ $on_day = __( 'on 5.', self::DOMAIN );
2286
+ break;
2287
+ case 6:
2288
+ $on_day = __( 'on 6.', self::DOMAIN );
2289
+ break;
2290
+ case 7:
2291
+ $on_day = __( 'on 7.', self::DOMAIN );
2292
+ break;
2293
+ case 8:
2294
+ $on_day = __( 'on 8.', self::DOMAIN );
2295
+ break;
2296
+ case 9:
2297
+ $on_day = __( 'on 9.', self::DOMAIN );
2298
+ break;
2299
+ case 10:
2300
+ $on_day = __( 'on 10.', self::DOMAIN );
2301
+ break;
2302
+ case 11:
2303
+ $on_day = __( 'on 11.', self::DOMAIN );
2304
+ break;
2305
+ case 12:
2306
+ $on_day = __( 'on 12.', self::DOMAIN );
2307
+ break;
2308
+ case 13:
2309
+ $on_day = __( 'on 13.', self::DOMAIN );
2310
+ break;
2311
+ case 14:
2312
+ $on_day = __( 'on 14.', self::DOMAIN );
2313
+ break;
2314
+ case 15:
2315
+ $on_day = __( 'on 15.', self::DOMAIN );
2316
+ break;
2317
+ case 16:
2318
+ $on_day = __( 'on 16.', self::DOMAIN );
2319
+ break;
2320
+ case 17:
2321
+ $on_day = __( 'on 17.', self::DOMAIN );
2322
+ break;
2323
+ case 18:
2324
+ $on_day = __( 'on 18.', self::DOMAIN );
2325
+ break;
2326
+ case 19:
2327
+ $on_day = __( 'on 19.', self::DOMAIN );
2328
+ break;
2329
+ case 20:
2330
+ $on_day = __( 'on 20.', self::DOMAIN );
2331
+ break;
2332
+ case 21:
2333
+ $on_day = __( 'on 21.', self::DOMAIN );
2334
+ break;
2335
+ case 22:
2336
+ $on_day = __( 'on 22.', self::DOMAIN );
2337
+ break;
2338
+ case 23:
2339
+ $on_day = __( 'on 23.', self::DOMAIN );
2340
+ break;
2341
+ case 24:
2342
+ $on_day = __( 'on 24.', self::DOMAIN );
2343
+ break;
2344
+ case 25:
2345
+ $on_day = __( 'on 25.', self::DOMAIN );
2346
+ break;
2347
+ case 26:
2348
+ $on_day = __( 'on 26.', self::DOMAIN );
2349
+ break;
2350
+ case 27:
2351
+ $on_day = __( 'on 27.', self::DOMAIN );
2352
+ break;
2353
+ case 28:
2354
+ $on_day = __( 'on 28.', self::DOMAIN );
2355
+ break;
2356
+ case 29:
2357
+ $on_day = __( 'on 29.', self::DOMAIN );
2358
+ break;
2359
+ case 30:
2360
+ $on_day = __( 'on 30.', self::DOMAIN );
2361
+ break;
2362
+ case 31:
2363
+ $on_day = __( 'on 31.', self::DOMAIN );
2364
+ break;
2365
+ }
2366
+
2367
+ echo '<option ' . selected( in_array( "$i", $mday, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $on_day . '</option>';
2368
+ }
2369
+ ?>
2370
+ </select>
2371
+ </td>
2372
+ <td>
2373
+ <select name="e_moncronhours">
2374
+ <?php
2375
+ for ( $i = 0; $i < 24; $i ++ ) {
2376
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2377
+ }
2378
+ ?>
2379
+ </select>
2380
+ </td>
2381
+ <td>
2382
+ <select name="e_moncronminutes">
2383
+ <?php
2384
+ for ( $i = 0; $i < 60; $i = $i + 5 ) {
2385
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2386
+ }
2387
+ ?>
2388
+ </select>
2389
+ </td>
2390
+ </tr>
2391
+ <tr>
2392
+ <td>
2393
+ <label for="idcronbtype-week">
2394
+ <?php echo '<input class="radio" type="radio"' . checked( TRUE, is_numeric( $wday[0] ), FALSE ) . ' name="e_cronbtype" value="week" /> ' . __( 'weekly', self::DOMAIN ); ?>
2395
+ </label>
2396
+ </td>
2397
+ <td>
2398
+ <select name="e_weekcronwday">
2399
+ <?php
2400
+ echo '<option ' . selected( in_array( '0', $wday, TRUE ), TRUE, FALSE ) . ' value="0" />' . __( 'Sunday', self::DOMAIN ) . '</option>';
2401
+ echo '<option ' . selected( in_array( '1', $wday, TRUE ), TRUE, FALSE ) . ' value="1" />' . __( 'Monday', self::DOMAIN ) . '</option>';
2402
+ echo '<option ' . selected( in_array( '2', $wday, TRUE ), TRUE, FALSE ) . ' value="2" />' . __( 'Tuesday', self::DOMAIN ) . '</option>';
2403
+ echo '<option ' . selected( in_array( '3', $wday, TRUE ), TRUE, FALSE ) . ' value="3" />' . __( 'Wednesday', self::DOMAIN ) . '</option>';
2404
+ echo '<option ' . selected( in_array( '4', $wday, TRUE ), TRUE, FALSE ) . ' value="4" />' . __( 'Thursday', self::DOMAIN ) . '</option>';
2405
+ echo '<option ' . selected( in_array( '5', $wday, TRUE ), TRUE, FALSE ) . ' value="5" />' . __( 'Friday', self::DOMAIN ) . '</option>';
2406
+ echo '<option ' . selected( in_array( '6', $wday, TRUE ), TRUE, FALSE ) . ' value="6" />' . __( 'Saturday', self::DOMAIN ) . '</option>';
2407
+ ?>
2408
+ </select>
2409
+ </td>
2410
+ <td>
2411
+ <select name="e_weekcronhours">
2412
+ <?php
2413
+ for ( $i = 0; $i < 24; $i ++ ) {
2414
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2415
+ }
2416
+ ?>
2417
+ </select>
2418
+ </td>
2419
+ <td>
2420
+ <select name="e_weekcronminutes">
2421
+ <?php
2422
+ for ( $i = 0; $i < 60; $i = $i + 5 ) {
2423
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2424
+ }
2425
+ ?>
2426
+ </select>
2427
+ </td>
2428
+ </tr>
2429
+ <tr>
2430
+ <td>
2431
+ <label for="idcronbtype-day">
2432
+ <?php echo '<input class="radio" type="radio"' . checked( "**", $mday[0] . $wday[0], FALSE ) . ' name="e_cronbtype" value="day" /> ' . __( 'daily', self::DOMAIN ); ?>
2433
+ </label>
2434
+ </td>
2435
+ <td>
2436
+ </td>
2437
+ <td>
2438
+ <select name="e_daycronhours">
2439
+ <?php
2440
+ for ( $i = 0; $i < 24; $i ++ ) {
2441
+ echo '<option ' . selected( in_array( "$i", $hours, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2442
+ }
2443
+ ?>
2444
+ </select>
2445
+ </td>
2446
+ <td>
2447
+ <select name="e_daycronminutes">
2448
+ <?php
2449
+ for ( $i = 0; $i < 60; $i = $i + 5 ) {
2450
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2451
+ }
2452
+ ?>
2453
+ </select>
2454
+ </td>
2455
+ </tr>
2456
+ <tr>
2457
+ <td>
2458
+ <label for="idcronbtype-hour">
2459
+ <?php echo '<input class="radio" type="radio"' . checked( "*", $hours[0], FALSE, FALSE ) . ' name="e_cronbtype" value="hour" /> ' . __( 'hourly', self::DOMAIN ); ?>
2460
+ </label>
2461
+ </td>
2462
+ <td></td>
2463
+ <td></td>
2464
+ <td>
2465
+ <select name="e_hourcronminutes">
2466
+ <?php
2467
+ for ( $i = 0; $i < 60; $i = $i + 5 ) {
2468
+ echo '<option ' . selected( in_array( "$i", $minutes, TRUE ), TRUE, FALSE ) . ' value="' . $i . '" />' . $i . '</option>';
2469
+ }
2470
+ ?>
2471
+ </select>
2472
+ </td>
2473
+ </tr>
2474
+ </table>
2475
+ </td>
2476
+ </tr>
2477
+ <?php
2478
+ }
2479
+ ?>
2480
+ </table>
2481
+ <div class="submit-button">
2482
+ <input type="submit" class="button button-primary" name="update_all_options" value="<?php _e( 'Update All Options', self::DOMAIN ); ?>" />
2483
+ </div>
2484
+ </div>
2485
+ </div>
2486
+ </form>
2487
+ </div>
2488
+ <div class="metabox-holder">
2489
+ <div id="common-exported-file" class="postbox">
2490
+ <div class="handlediv" title="Click to toggle"><br></div>
2491
+ <h3 class="hndle"><span><?php _e( 'Exported File', self::DOMAIN ); ?></span></h3>
2492
+ <div class="inside">
2493
+ <table class="form-table">
2494
+ <tbody>
2495
+ <tr>
2496
+ <th><?php _e( 'Disk usage of exported file', self::DOMAIN ); ?></th>
2497
+ <td>
2498
+ <?php
2499
+ $abs_path = WP_PLUGIN_DIR . '/sns-count-cache/data/sns-count-cache-data.csv';
2500
+ $file_size = SCC_Common_Util::get_file_size( $abs_path );
2501
+
2502
+ if ( isset( $file_size ) ) {
2503
+ echo $file_size;
2504
+ } else {
2505
+ _e( 'No exported file', self::DOMAIN );
2506
+ }
2507
+ ?>
2508
+ </td>
2509
+ </tr>
2510
+ </tbody>
2511
+ </table>
2512
+ <form action="admin.php?page=scc-setting" method="post">
2513
+ <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
2514
+ <table class="form-table">
2515
+ <tbody>
2516
+ <tr>
2517
+ <th><?php _e( 'Manual export', self::DOMAIN ); ?></th>
2518
+ <td>
2519
+ <input type="submit" class="button button-secondary" name="export_data" value="<?php _e( 'Export', self::DOMAIN ); ?>" />
2520
+ <br>
2521
+ <span class="description"><?php _e( 'Export share count to a csv file.', self::DOMAIN ); ?></span>
2522
+ </td>
2523
+ </tr>
2524
+ </tbody>
2525
+ </table>
2526
+ </form>
2527
+ <?php
2528
+ if ( file_exists( $abs_path ) ) {
2529
+ ?>
2530
+ <form action="admin.php?page=scc-setting" method="post">
2531
+ <?php wp_nonce_field( __FILE__, '_wpnonce' ); ?>
2532
+ <table class="form-table">
2533
+ <tbody>
2534
+ <tr>
2535
+ <th><?php _e( 'Reset of exported file', self::DOMAIN ); ?></th>
2536
+ <td>
2537
+ <input type="submit" class="button button-secondary" name="reset_data" value="<?php _e( 'Reset', self::DOMAIN ); ?>" />
2538
+ <br>
2539
+ <span class="description"><?php _e( 'Clear exported csv file.', self::DOMAIN ); ?></span>
2540
+ </td>
2541
+ </tr>
2542
+ </tbody>
2543
+ </table>
2544
+ </form>
2545
+ <form action="<?php echo plugins_url(); ?>/sns-count-cache/includes/download.php" method="post">
2546
+ <?php wp_nonce_field( 'download', '_wpnonce' ); ?>
2547
+ <table class="form-table">
2548
+ <tbody>
2549
+ <tr>
2550
+ <th><?php _e( 'Download of exported file', self::DOMAIN ); ?></th>
2551
+ <td>
2552
+ <input type="submit" class="button button-secondary" name="download_data" value="<?php _e( 'Download', self::DOMAIN ); ?>" />
2553
+ <br>
2554
+ <span class="description"><?php _e( 'Download the exported csv file.', self::DOMAIN ); ?></span>
2555
+ </td>
2556
+ </tr>
2557
+ </tbody>
2558
+ </table>
2559
+ </form>
2560
+ <?php
2561
+ }
2562
+ ?>
2563
+ </div>
2564
+ </div>
2565
+ </div>
2566
+ </div>
2567
+ </div>
includes/admin-share-count.php CHANGED
@@ -1,449 +1,452 @@
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
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
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
- if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
39
- if( isset( $_GET["key"] ) ) {
40
- $sort_mode = true;
41
- $sns = $_GET["key"];
42
-
43
- if ( $sns === 'Google' ) {
44
- $sns = $sns . '+';
45
- }
46
-
47
- $sort_exec_key = $sns;
48
-
49
- $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
50
- }
51
- }
52
- }
53
-
54
- $paged = 1;
55
-
56
- if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 0 ) {
57
- $paged = $_GET['paged'];
58
- } else {
59
- $paged = 1;
60
- }
61
-
62
- $share_base_cache_target = $this->share_base_cache_target ;
63
- unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
64
-
65
- ?>
66
- <div class="wrap">
67
- <h2><a href="admin.php?page=scc-share-count"><?php _e( 'SNS Count Cache', self::DOMAIN ); ?></a></h2>
68
- <div class="sns-cnt-cache">
69
- <h3 class="nav-tab-wrapper">
70
- <a class="nav-tab" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ); ?></a>
71
- <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a>
72
- <a class="nav-tab nav-tab-active" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
73
- <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
74
- <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
75
- <?php } ?>
76
- <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ); ?></a>
77
- <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
78
- </h3>
79
- <div class="metabox-holder">
80
- <div id="share-each-content" class="postbox">
81
- <div class="handlediv" title="Click to toggle"><br></div>
82
- <h3 class="hndle"><span><?php _e( 'Share Count', self::DOMAIN ); ?></span></h3>
83
- <div class="inside">
84
- <table class="view-table">
85
- <thead>
86
- <tr>
87
- <th>No.</th>
88
- <th><?php _e( 'Content', self::DOMAIN ); ?></th>
89
- <?php
90
- foreach ( $share_base_cache_target as $sns => $active ) {
91
- if ( $active ) {
92
- $sort_key = $sns;
93
-
94
- if ( $sort_key === self::REF_SHARE_GPLUS ) {
95
- $sort_key = str_replace( '+', '', $sort_key );
96
- }
97
-
98
- $sort_url = esc_url( 'admin.php?page=scc-share-count&action=sort&key=' . $sort_key );
99
-
100
- $sns_name = '';
101
-
102
- switch ( $sns ) {
103
- case self::REF_SHARE_TWITTER:
104
- $sns_name = __( 'Twitter', self::DOMAIN );
105
- break;
106
- case self::REF_SHARE_FACEBOOK:
107
- $sns_name = __( 'Facebook', self::DOMAIN );
108
- break;
109
- case self::REF_SHARE_GPLUS:
110
- $sns_name = __( 'Google+', self::DOMAIN );
111
- break;
112
- case self::REF_SHARE_POCKET:
113
- $sns_name = __( 'Pocket', self::DOMAIN );
114
- break;
115
- case self::REF_SHARE_HATEBU:
116
- $sns_name = __( 'Hatebu', self::DOMAIN );
117
- break;
118
- case self::REF_SHARE_PINTEREST:
119
- $sns_name = __( 'Pinterest', self::DOMAIN );
120
- break;
121
- case self::REF_SHARE_TOTAL:
122
- $sns_name = __( 'Total', self::DOMAIN );
123
- break;
124
- }
125
-
126
- if ( $sns === $sort_exec_key ) {
127
- echo '<th><a class="sort-exec-key" href="' . $sort_url . '">' . esc_html( $sns_name ) . '</th>';
128
- } else {
129
- echo '<th><a href="' . $sort_url . '">' . esc_html( $sns_name ) . '</th>';
130
- }
131
- }
132
- }
133
- ?>
134
- </tr>
135
- </thead>
136
- <tbody>
137
- <?php
138
- if ( $sort_mode ) {
139
- $query_args = array(
140
- 'post_type' => $this->share_base_cache_post_types,
141
- 'post_status' => 'publish',
142
- 'posts_per_page' => $posts_per_page,
143
- 'paged' => $paged,
144
- 'meta_key' => $meta_key,
145
- 'orderby' => 'meta_value_num',
146
- 'update_post_term_cache' => false,
147
- 'order' => 'DESC'
148
- );
149
- } else {
150
- $query_args = array(
151
- 'post_type' => $this->share_base_cache_post_types,
152
- 'post_status' => 'publish',
153
- 'posts_per_page' => $posts_per_page,
154
- 'paged' => $paged,
155
- 'update_post_term_cache' => false
156
- );
157
- }
158
-
159
- $posts_query = new WP_Query( $query_args );
160
-
161
- $count = ( $paged - 1 ) * $posts_per_page + 1;
162
-
163
- if ( $paged === 1 ) {
164
- ?>
165
- <tr class="home">
166
- <td><?php echo '-'; ?></td>
167
- <td><a href="<?php echo esc_url( home_url( '/' ) ); ?>" target="_blank"><?php echo esc_html( bloginfo('name') ); ?></a></td>
168
- <?php
169
- if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
170
- $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
171
-
172
- if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
173
- $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
174
-
175
- if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
176
- foreach ( $share_base_cache_target as $sns => $active ) {
177
- if ( $active ) {
178
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
179
- echo '<td class="share-count">';
180
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
181
-
182
- if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
183
- echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
184
- } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
185
- echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
186
- }
187
-
188
- echo '</td>';
189
- } else {
190
- echo '<td class="not-cached share-count">';
191
- _e( 'N/A', self::DOMAIN );
192
- echo '</td>';
193
- }
194
- }
195
- }
196
- } else {
197
- foreach ( $share_base_cache_target as $sns => $active ) {
198
- if ( $active ) {
199
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
200
- echo '<td class="share-count">';
201
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
202
- echo '</td>';
203
- } else {
204
- echo '<td class="not-cached share-count">';
205
- _e( 'N/A', self::DOMAIN );
206
- echo '</td>';
207
- }
208
- }
209
- }
210
- }
211
- } else {
212
- $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
213
-
214
- if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
215
- $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
216
-
217
- if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
218
- foreach ( $share_base_cache_target as $sns => $active ) {
219
- if ( $active ) {
220
- if ( $sns_counts[$sns] >= 0 ) {
221
- echo '<td class="share-count">';
222
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
223
-
224
- if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
225
- echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
226
- } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
227
- echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
228
- }
229
-
230
- echo '</td>';
231
- } else {
232
- echo '<td class="not-cached share-count">';
233
- _e( 'N/A', self::DOMAIN );
234
- echo '</td>';
235
- }
236
- }
237
- }
238
- } else {
239
- foreach ( $share_base_cache_target as $sns => $active ) {
240
- if ( $active ) {
241
- if ( $sns_counts[$sns] >= 0 ) {
242
- echo '<td class="share-count">';
243
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
244
- echo '</td>';
245
- } else {
246
- echo '<td class="not-cached share-count">';
247
- _e( 'N/A', self::DOMAIN );
248
- echo '</td>';
249
- }
250
- }
251
- }
252
- }
253
- } else {
254
- foreach ( $share_base_cache_target as $sns => $active ) {
255
- if ( $active ) {
256
- echo '<td class="not-cached share-count">';
257
- _e( 'N/A', self::DOMAIN );
258
- echo '</td>';
259
- }
260
- }
261
- }
262
- }
263
- } else {
264
- $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
265
-
266
- if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
267
- $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
268
-
269
- if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
270
- foreach ( $share_base_cache_target as $sns => $active ) {
271
- if ( $active ) {
272
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
273
- echo '<td class="share-count">';
274
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
275
-
276
- if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
277
- echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
278
- } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
279
- echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
280
- }
281
-
282
- echo '</td>';
283
- } else {
284
- echo '<td class="not-cached share-count">';
285
- _e( 'N/A', self::DOMAIN );
286
- echo '</td>';
287
- }
288
- }
289
- }
290
- } else {
291
- foreach ( $share_base_cache_target as $sns => $active ) {
292
- if ( $active ) {
293
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
294
- echo '<td class="share-count">';
295
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
296
- echo '</td>';
297
- } else {
298
- echo '<td class="not-cached share-count">';
299
- _e( 'N/A', self::DOMAIN );
300
- echo '</td>';
301
- }
302
- }
303
- }
304
- }
305
- } else {
306
- $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
307
-
308
- if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
309
- $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
310
-
311
- if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
312
- foreach ( $share_base_cache_target as $sns => $active ) {
313
- if ( $active ){
314
- if ( $sns_counts[$sns] >= 0 ) {
315
- echo '<td class="share-count">';
316
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
317
-
318
- if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
319
- echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
320
- } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
321
- echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
322
- }
323
-
324
- echo '</td>';
325
- } else {
326
- echo '<td class="not-cached share-count">';
327
- _e( 'N/A', self::DOMAIN );
328
- echo '</td>';
329
- }
330
- }
331
- }
332
- } else {
333
- foreach ( $share_base_cache_target as $sns => $active ) {
334
- if ( $active ){
335
- if ( $sns_counts[$sns] >= 0 ) {
336
- echo '<td class="share-count">';
337
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
338
- echo '</td>';
339
- } else {
340
- echo '<td class="not-cached share-count">';
341
- _e( 'N/A', self::DOMAIN );
342
- echo '</td>';
343
- }
344
- }
345
- }
346
- }
347
- } else {
348
- foreach ( $share_base_cache_target as $sns => $active ) {
349
- if ( $active ) {
350
- echo '<td class="not-cached share-count">';
351
- _e( 'N/A', self::DOMAIN );
352
- echo '</td>';
353
- }
354
- }
355
- }
356
- }
357
- }
358
- ?>
359
- </tr>
360
- <?php
361
- }
362
- if ( $posts_query->have_posts() ) {
363
- while ( $posts_query->have_posts() ) {
364
- $posts_query->the_post();
365
- ?>
366
- <tr>
367
- <td><?php echo $count; ?></td>
368
- <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>
369
- <?php
370
- $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( get_the_ID() );
371
-
372
- if ( ! $sort_mode && false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
373
- foreach ( $share_base_cache_target as $sns => $active ) {
374
- if ( $active ) {
375
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
376
- echo '<td class="share-count">';
377
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
378
-
379
- if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
380
- //delta
381
- $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
382
- $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
383
-
384
- if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
385
- echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
386
- } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
387
- echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
388
- }
389
- }
390
-
391
- echo '</td>';
392
- } else {
393
- echo '<td class="not-cached share-count">';
394
- _e( 'N/A', self::DOMAIN );
395
- echo '</td>';
396
- }
397
- }
398
- }
399
- } else {
400
- foreach ( $share_base_cache_target as $sns => $active ) {
401
- if( $active ){
402
- $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
403
-
404
- $sns_counts[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
405
-
406
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 ) {
407
- echo '<td class="share-count">';
408
- echo esc_html( number_format( (int) $sns_counts[$sns] ) );
409
-
410
- if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
411
- //delta
412
- $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
413
- $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
414
-
415
- if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
416
- echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
417
- } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
418
- echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
419
- }
420
- }
421
-
422
- echo '</td>';
423
- } else {
424
- echo '<td class="not-cached share-count">';
425
- _e( 'N/A', self::DOMAIN );
426
- echo '</td>';
427
- }
428
- }
429
- }
430
- }
431
- ?>
432
- </tr>
433
- <?php
434
- ++$count;
435
-
436
- }
437
- }
438
- ?>
439
- </tbody>
440
- </table>
441
- <?php
442
- $this->pagination( $posts_query->max_num_pages, '', $paged, true );
443
- wp_reset_postdata();
444
- ?>
445
- </div>
446
- </div>
447
- </div>
448
- </div>
449
- </div>
 
 
 
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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
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
+ if ( current_user_can( self::OPT_COMMON_CAPABILITY ) ) {
39
+ if( isset( $_GET["key"] ) ) {
40
+ $sort_mode = true;
41
+ $sns = $_GET["key"];
42
+
43
+ if ( $sns === 'Google' ) {
44
+ $sns = $sns . '+';
45
+ }
46
+
47
+ $sort_exec_key = $sns;
48
+
49
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
50
+ }
51
+ }
52
+ }
53
+
54
+ $paged = 1;
55
+
56
+ if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 0 ) {
57
+ $paged = $_GET['paged'];
58
+ } else {
59
+ $paged = 1;
60
+ }
61
+
62
+ $share_base_cache_target = $this->share_base_cache_target ;
63
+ unset( $share_base_cache_target[self::REF_CRAWL_DATE] );
64
+
65
+ ?>
66
+ <div class="wrap">
67
+ <h2><a href="admin.php?page=scc-share-count"><?php _e( 'SNS Count Cache', self::DOMAIN ); ?></a></h2>
68
+ <div class="sns-cnt-cache">
69
+ <h3 class="nav-tab-wrapper">
70
+ <a class="nav-tab" href="admin.php?page=scc-dashboard"><?php _e( 'Dashboard', self::DOMAIN ); ?></a>
71
+ <a class="nav-tab" href="admin.php?page=scc-cache-status"><?php _e( 'Cache Status', self::DOMAIN ); ?></a>
72
+ <a class="nav-tab nav-tab-active" href="admin.php?page=scc-share-count"><?php _e( 'Share Count', self::DOMAIN ); ?></a>
73
+ <?php if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) { ?>
74
+ <a class="nav-tab" href="admin.php?page=scc-hot-content"><?php _e( 'Hot Content', self::DOMAIN ); ?></a>
75
+ <?php } ?>
76
+ <a class="nav-tab" href="admin.php?page=scc-setting"><?php _e( 'Setting', self::DOMAIN ); ?></a>
77
+ <a class="nav-tab" href="admin.php?page=scc-help"><?php _e( 'Help', self::DOMAIN ); ?></a>
78
+ </h3>
79
+ <div class="metabox-holder">
80
+ <div id="share-each-content" class="postbox">
81
+ <div class="handlediv" title="Click to toggle"><br></div>
82
+ <h3 class="hndle"><span><?php _e( 'Share Count', self::DOMAIN ); ?></span></h3>
83
+ <div class="inside">
84
+ <table class="view-table">
85
+ <thead>
86
+ <tr>
87
+ <th>No.</th>
88
+ <th><?php _e( 'Content', self::DOMAIN ); ?></th>
89
+ <?php
90
+ foreach ( $share_base_cache_target as $sns => $active ) {
91
+ if ( $active ) {
92
+ $sort_key = $sns;
93
+
94
+ if ( $sort_key === self::REF_SHARE_GPLUS ) {
95
+ $sort_key = str_replace( '+', '', $sort_key );
96
+ }
97
+
98
+ $sort_url = esc_url( 'admin.php?page=scc-share-count&action=sort&key=' . $sort_key );
99
+
100
+ $sns_name = '';
101
+
102
+ switch ( $sns ) {
103
+ case self::REF_SHARE_TWITTER:
104
+ $sns_name = __( 'Twitter', self::DOMAIN );
105
+ break;
106
+ case self::REF_SHARE_FACEBOOK:
107
+ $sns_name = __( 'Facebook', self::DOMAIN );
108
+ break;
109
+ case self::REF_SHARE_GPLUS:
110
+ $sns_name = __( 'Google+', self::DOMAIN );
111
+ break;
112
+ case self::REF_SHARE_POCKET:
113
+ $sns_name = __( 'Pocket', self::DOMAIN );
114
+ break;
115
+ case self::REF_SHARE_HATEBU:
116
+ $sns_name = __( 'Hatebu', self::DOMAIN );
117
+ break;
118
+ case self::REF_SHARE_PINTEREST:
119
+ $sns_name = __( 'Pinterest', self::DOMAIN );
120
+ break;
121
+ case self::REF_SHARE_LINKEDIN:
122
+ $sns_name = __( 'Linkedin', self::DOMAIN );
123
+ break;
124
+ case self::REF_SHARE_TOTAL:
125
+ $sns_name = __( 'Total', self::DOMAIN );
126
+ break;
127
+ }
128
+
129
+ if ( $sns === $sort_exec_key ) {
130
+ echo '<th><a class="sort-exec-key" href="' . $sort_url . '">' . esc_html( $sns_name ) . '</th>';
131
+ } else {
132
+ echo '<th><a href="' . $sort_url . '">' . esc_html( $sns_name ) . '</th>';
133
+ }
134
+ }
135
+ }
136
+ ?>
137
+ </tr>
138
+ </thead>
139
+ <tbody>
140
+ <?php
141
+ if ( $sort_mode ) {
142
+ $query_args = array(
143
+ 'post_type' => $this->share_base_cache_post_types,
144
+ 'post_status' => 'publish',
145
+ 'posts_per_page' => $posts_per_page,
146
+ 'paged' => $paged,
147
+ 'meta_key' => $meta_key,
148
+ 'orderby' => 'meta_value_num',
149
+ 'update_post_term_cache' => false,
150
+ 'order' => 'DESC'
151
+ );
152
+ } else {
153
+ $query_args = array(
154
+ 'post_type' => $this->share_base_cache_post_types,
155
+ 'post_status' => 'publish',
156
+ 'posts_per_page' => $posts_per_page,
157
+ 'paged' => $paged,
158
+ 'update_post_term_cache' => false
159
+ );
160
+ }
161
+
162
+ $posts_query = new WP_Query( $query_args );
163
+
164
+ $count = ( $paged - 1 ) * $posts_per_page + 1;
165
+
166
+ if ( $paged === 1 ) {
167
+ ?>
168
+ <tr class="home">
169
+ <td><?php echo '-'; ?></td>
170
+ <td><a href="<?php echo esc_url( home_url( '/' ) ); ?>" target="_blank"><?php echo esc_html( bloginfo('name') ); ?></a></td>
171
+ <?php
172
+ if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
173
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
174
+
175
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
176
+ $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
177
+
178
+ if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
179
+ foreach ( $share_base_cache_target as $sns => $active ) {
180
+ if ( $active ) {
181
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
182
+ echo '<td class="share-count">';
183
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
184
+
185
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
186
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
187
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
188
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
189
+ }
190
+
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
+ } else {
200
+ foreach ( $share_base_cache_target as $sns => $active ) {
201
+ if ( $active ) {
202
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
203
+ echo '<td class="share-count">';
204
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
205
+ echo '</td>';
206
+ } else {
207
+ echo '<td class="not-cached share-count">';
208
+ _e( 'N/A', self::DOMAIN );
209
+ echo '</td>';
210
+ }
211
+ }
212
+ }
213
+ }
214
+ } else {
215
+ $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
216
+
217
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
218
+ $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
219
+
220
+ if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
221
+ foreach ( $share_base_cache_target as $sns => $active ) {
222
+ if ( $active ) {
223
+ if ( $sns_counts[$sns] >= 0 ) {
224
+ echo '<td class="share-count">';
225
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
226
+
227
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
228
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
229
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
230
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
231
+ }
232
+
233
+ echo '</td>';
234
+ } else {
235
+ echo '<td class="not-cached share-count">';
236
+ _e( 'N/A', self::DOMAIN );
237
+ echo '</td>';
238
+ }
239
+ }
240
+ }
241
+ } else {
242
+ foreach ( $share_base_cache_target as $sns => $active ) {
243
+ if ( $active ) {
244
+ if ( $sns_counts[$sns] >= 0 ) {
245
+ echo '<td class="share-count">';
246
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
247
+ echo '</td>';
248
+ } else {
249
+ echo '<td class="not-cached share-count">';
250
+ _e( 'N/A', self::DOMAIN );
251
+ echo '</td>';
252
+ }
253
+ }
254
+ }
255
+ }
256
+ } else {
257
+ foreach ( $share_base_cache_target as $sns => $active ) {
258
+ if ( $active ) {
259
+ echo '<td class="not-cached share-count">';
260
+ _e( 'N/A', self::DOMAIN );
261
+ echo '</td>';
262
+ }
263
+ }
264
+ }
265
+ }
266
+ } else {
267
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( 'home' );
268
+
269
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
270
+ $option_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( 'home' );
271
+
272
+ if ( false !== ( $sns_deltas = get_option( $option_key ) ) ) {
273
+ foreach ( $share_base_cache_target as $sns => $active ) {
274
+ if ( $active ) {
275
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
276
+ echo '<td class="share-count">';
277
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
278
+
279
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
280
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
281
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
282
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
283
+ }
284
+
285
+ echo '</td>';
286
+ } else {
287
+ echo '<td class="not-cached share-count">';
288
+ _e( 'N/A', self::DOMAIN );
289
+ echo '</td>';
290
+ }
291
+ }
292
+ }
293
+ } else {
294
+ foreach ( $share_base_cache_target as $sns => $active ) {
295
+ if ( $active ) {
296
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
297
+ echo '<td class="share-count">';
298
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
299
+ echo '</td>';
300
+ } else {
301
+ echo '<td class="not-cached share-count">';
302
+ _e( 'N/A', self::DOMAIN );
303
+ echo '</td>';
304
+ }
305
+ }
306
+ }
307
+ }
308
+ } else {
309
+ $option_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( 'home' );
310
+
311
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
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
+ if ( $sns_counts[$sns] >= 0 ) {
318
+ echo '<td class="share-count">';
319
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
320
+
321
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
322
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
323
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
324
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
325
+ }
326
+
327
+ echo '</td>';
328
+ } else {
329
+ echo '<td class="not-cached share-count">';
330
+ _e( 'N/A', self::DOMAIN );
331
+ echo '</td>';
332
+ }
333
+ }
334
+ }
335
+ } else {
336
+ foreach ( $share_base_cache_target as $sns => $active ) {
337
+ if ( $active ){
338
+ if ( $sns_counts[$sns] >= 0 ) {
339
+ echo '<td class="share-count">';
340
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
341
+ echo '</td>';
342
+ } else {
343
+ echo '<td class="not-cached share-count">';
344
+ _e( 'N/A', self::DOMAIN );
345
+ echo '</td>';
346
+ }
347
+ }
348
+ }
349
+ }
350
+ } else {
351
+ foreach ( $share_base_cache_target as $sns => $active ) {
352
+ if ( $active ) {
353
+ echo '<td class="not-cached share-count">';
354
+ _e( 'N/A', self::DOMAIN );
355
+ echo '</td>';
356
+ }
357
+ }
358
+ }
359
+ }
360
+ }
361
+ ?>
362
+ </tr>
363
+ <?php
364
+ }
365
+ if ( $posts_query->have_posts() ) {
366
+ while ( $posts_query->have_posts() ) {
367
+ $posts_query->the_post();
368
+ ?>
369
+ <tr>
370
+ <td><?php echo $count; ?></td>
371
+ <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>
372
+ <?php
373
+ $transient_id = $this->cache_engines[self::REF_SHARE_BASE]->get_cache_key( get_the_ID() );
374
+
375
+ if ( ! $sort_mode && false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
376
+ foreach ( $share_base_cache_target as $sns => $active ) {
377
+ if ( $active ) {
378
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
379
+ echo '<td class="share-count">';
380
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
381
+
382
+ if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
383
+ //delta
384
+ $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
385
+ $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
386
+
387
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
388
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
389
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
390
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
391
+ }
392
+ }
393
+
394
+ echo '</td>';
395
+ } else {
396
+ echo '<td class="not-cached share-count">';
397
+ _e( 'N/A', self::DOMAIN );
398
+ echo '</td>';
399
+ }
400
+ }
401
+ }
402
+ } else {
403
+ foreach ( $share_base_cache_target as $sns => $active ) {
404
+ if( $active ){
405
+ $meta_key = $this->cache_engines[self::REF_SHARE_2ND]->get_cache_key( $sns );
406
+
407
+ $sns_counts[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
408
+
409
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 ) {
410
+ echo '<td class="share-count">';
411
+ echo esc_html( number_format( (int) $sns_counts[$sns] ) );
412
+
413
+ if ( $this->share_variation_analysis_mode !== self::OPT_SHARE_VARIATION_ANALYSIS_NONE ) {
414
+ //delta
415
+ $meta_key = $this->analytical_engines[self::REF_SHARE_ANALYSIS]->get_delta_key( $sns );
416
+ $sns_deltas[$sns] = get_post_meta( get_the_ID(), $meta_key, true );
417
+
418
+ if ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] > 0 ) {
419
+ echo ' (<span class="delta-rise">+' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
420
+ } elseif ( isset( $sns_deltas[$sns] ) && $sns_deltas[$sns] !== '' && $sns_deltas[$sns] < 0 ) {
421
+ echo ' (<span class="delta-fall">' . esc_html( number_format( (int) $sns_deltas[$sns] ) ) . '</span>)';
422
+ }
423
+ }
424
+
425
+ echo '</td>';
426
+ } else {
427
+ echo '<td class="not-cached share-count">';
428
+ _e( 'N/A', self::DOMAIN );
429
+ echo '</td>';
430
+ }
431
+ }
432
+ }
433
+ }
434
+ ?>
435
+ </tr>
436
+ <?php
437
+ ++$count;
438
+
439
+ }
440
+ }
441
+ ?>
442
+ </tbody>
443
+ </table>
444
+ <?php
445
+ $this->pagination( $posts_query->max_num_pages, '', $paged, true );
446
+ wp_reset_postdata();
447
+ ?>
448
+ </div>
449
+ </div>
450
+ </div>
451
+ </div>
452
+ </div>
includes/class-crypt-blowfish.php CHANGED
@@ -1,272 +1,272 @@
1
- <?php
2
- /**
3
- * Crypt_Blowfish allows for encryption and decryption on the fly using
4
- * the Blowfish algorithm. Crypt_Blowfish does not require the mcrypt
5
- * PHP extension, it uses only PHP.
6
- * Crypt_Blowfish support encryption/decryption with or without a secret key.
7
- *
8
- * PHP versions 4 and 5
9
- *
10
- * @category Encryption
11
- * @package Crypt_Blowfish
12
- * @author Matthew Fonda <mfonda@php.net>
13
- * @copyright 2005 Matthew Fonda
14
- * @license http://www.opensource.org/licenses/mit-license.html MIT License
15
- * @version CVS: $Id: Blowfish.php,v 1.81 2005/05/30 18:40:36 mfonda Exp $
16
- * @link http://pear.php.net/package/Crypt_Blowfish
17
- */
18
-
19
- /**
20
- *
21
- * Example usage:
22
- * $bf = new Crypt_Blowfish('some secret key!');
23
- * $encrypted = $bf->encrypt('this is some example plain text');
24
- * $plaintext = $bf->decrypt($encrypted);
25
- * echo "plain text: $plaintext";
26
- *
27
- *
28
- * @category Encryption
29
- * @package Crypt_Blowfish
30
- * @author Matthew Fonda <mfonda@php.net>
31
- * @copyright 2005 Matthew Fonda
32
- * @license http://www.opensource.org/licenses/mit-license.html MIT License
33
- * @link http://pear.php.net/package/Crypt_Blowfish
34
- * @version @package_version@
35
- * @access public
36
- */
37
-
38
- class Crypt_Blowfish {
39
-
40
- /**
41
- * P-Array contains 18 32-bit subkeys
42
- *
43
- * @var array
44
- * @access private
45
- */
46
- private $_P = array();
47
-
48
- /**
49
- * Array of four S-Blocks each containing 256 32-bit entries
50
- *
51
- * @var array
52
- * @access private
53
- */
54
- private $_S = array();
55
-
56
- /**
57
- * Crypt_Blowfish Constructor
58
- * Initializes the Crypt_Blowfish object, and gives a sets
59
- * the secret key
60
- *
61
- * @param string $key
62
- * @access public
63
- */
64
- public function __construct( $key ) {
65
- $this->setKey( $key );
66
- }
67
-
68
- /**
69
- * Deprecated isReady method
70
- *
71
- * @return bool
72
- * @access public
73
- * @deprecated
74
- */
75
- public function isReady() {
76
- return true;
77
- }
78
-
79
- /**
80
- * Deprecated init method - init is now a private
81
- * method and has been replaced with _init
82
- *
83
- * @return bool
84
- * @access public
85
- * @deprecated
86
- * @see Crypt_Blowfish::_init()
87
- */
88
- public function init() {
89
- $this->_init();
90
- }
91
-
92
- /**
93
- * Initializes the Crypt_Blowfish object
94
- *
95
- * @access private
96
- */
97
- private function _init() {
98
- $defaults = new Crypt_Blowfish_DefaultKey();
99
- $this->_P = $defaults->P;
100
- $this->_S = $defaults->S;
101
- }
102
-
103
- /**
104
- * Enciphers a single 64 bit block
105
- *
106
- * @param int &$Xl
107
- * @param int &$Xr
108
- * @access private
109
- */
110
- private function _encipher( &$Xl, &$Xr ) {
111
- for ( $i = 0; $i < 16; $i++ ) {
112
- $temp = $Xl ^ $this->_P[$i];
113
- $Xl = ((($this->_S[0][($temp>>24) & 255] +
114
- $this->_S[1][($temp>>16) & 255]) ^
115
- $this->_S[2][($temp>>8) & 255]) +
116
- $this->_S[3][$temp & 255]) ^ $Xr;
117
- $Xr = $temp;
118
- }
119
- $Xr = $Xl ^ $this->_P[16];
120
- $Xl = $temp ^ $this->_P[17];
121
- }
122
-
123
- /**
124
- * Deciphers a single 64 bit block
125
- *
126
- * @param int &$Xl
127
- * @param int &$Xr
128
- * @access private
129
- */
130
- private function _decipher( &$Xl, &$Xr ) {
131
- for ( $i = 17; $i > 1; $i-- ) {
132
- $temp = $Xl ^ $this->_P[$i];
133
- $Xl = ((($this->_S[0][($temp>>24) & 255] +
134
- $this->_S[1][($temp>>16) & 255]) ^
135
- $this->_S[2][($temp>>8) & 255]) +
136
- $this->_S[3][$temp & 255]) ^ $Xr;
137
- $Xr = $temp;
138
- }
139
- $Xr = $Xl ^ $this->_P[1];
140
- $Xl = $temp ^ $this->_P[0];
141
- }
142
-
143
-
144
- /**
145
- * Encrypts a string
146
- *
147
- * @param string $plainText
148
- * @return string Returns cipher text on success, PEAR_Error on failure
149
- * @access public
150
- */
151
- public function encrypt( $plainText ) {
152
- if ( ! is_string( $plainText ) ) {
153
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ') : Plain text must be a string' );
154
- //PEAR::raiseError('Plain text must be a string', 0, PEAR_ERROR_DIE);
155
- die();
156
- }
157
-
158
- $cipherText = '';
159
- $len = strlen( $plainText );
160
- $plainText .= str_repeat(chr(0),(8 - ($len%8))%8);
161
- for ( $i = 0; $i < $len; $i += 8 ) {
162
- list( , $Xl, $Xr ) = unpack( "N2",substr( $plainText,$i, 8 ) );
163
- $this->_encipher( $Xl, $Xr );
164
- $cipherText .= pack( "N2", $Xl, $Xr );
165
- }
166
- return base64_encode( $cipherText) ;
167
- }
168
-
169
-
170
- /**
171
- * Decrypts an encrypted string
172
- *
173
- * @param string $cipherText
174
- * @return string Returns plain text on success, PEAR_Error on failure
175
- * @access public
176
- */
177
- public function decrypt( $cipherText ) {
178
- if ( ! is_string( $cipherText ) ) {
179
- //PEAR::raiseError('Chiper text must be a string', 1, PEAR_ERROR_DIE);
180
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ') : Chiper text must be a string' );
181
- die();
182
- }
183
-
184
- $cipherText = base64_decode( $cipherText );
185
-
186
- $plainText = '';
187
- $len = strlen( $cipherText );
188
- $cipherText .= str_repeat( chr(0), (8 - ($len%8))%8 );
189
- for ( $i = 0; $i < $len; $i += 8 ) {
190
- list( , $Xl, $Xr ) = unpack( "N2", substr( $cipherText, $i, 8 ) );
191
- $this->_decipher( $Xl, $Xr );
192
- $plainText .= pack( "N2", $Xl, $Xr );
193
- }
194
- return $plainText;
195
- }
196
-
197
-
198
- /**
199
- * Sets the secret key
200
- * The key must be non-zero, and less than or equal to
201
- * 56 characters in length.
202
- *
203
- * @param string $key
204
- * @return bool Returns true on success, PEAR_Error on failure
205
- * @access public
206
- */
207
- public function setKey( $key ) {
208
- if ( ! is_string( $key ) ) {
209
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ') : Key must be a string' );
210
- //PEAR::raiseError('Key must be a string', 2, PEAR_ERROR_DIE);
211
- die();
212
- }
213
-
214
- $key = substr( md5( $key ), 0, 55 );
215
-
216
- $len = strlen( $key );
217
-
218
- if ( $len > 56 || $len == 0 ) {
219
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ') : Key must be less than 56 characters and non-zero' );
220
- //PEAR::raiseError('Key must be less than 56 characters and non-zero. Supplied key length: ' . $len, 3, PEAR_ERROR_DIE);
221
- die();
222
- }
223
-
224
- require_once 'class-default-key.php';
225
- $this->_init();
226
-
227
- $k = 0;
228
- $data = 0;
229
- $datal = 0;
230
- $datar = 0;
231
-
232
- for ( $i = 0; $i < 18; $i++ ) {
233
- $data = 0;
234
- for ( $j = 4; $j > 0; $j-- ) {
235
- $data = $data << 8 | ord($key{$k});
236
- $k = ($k+1) % $len;
237
- }
238
- $this->_P[$i] ^= $data;
239
- }
240
-
241
- for ( $i = 0; $i <= 16; $i += 2 ) {
242
- $this->_encipher($datal, $datar);
243
- $this->_P[$i] = $datal;
244
- $this->_P[$i+1] = $datar;
245
- }
246
- for ( $i = 0; $i < 256; $i += 2 ) {
247
- $this->_encipher($datal, $datar);
248
- $this->_S[0][$i] = $datal;
249
- $this->_S[0][$i+1] = $datar;
250
- }
251
- for ( $i = 0; $i < 256; $i += 2 ) {
252
- $this->_encipher($datal, $datar);
253
- $this->_S[1][$i] = $datal;
254
- $this->_S[1][$i+1] = $datar;
255
- }
256
- for ($i = 0; $i < 256; $i += 2) {
257
- $this->_encipher($datal, $datar);
258
- $this->_S[2][$i] = $datal;
259
- $this->_S[2][$i+1] = $datar;
260
- }
261
- for ( $i = 0; $i < 256; $i += 2 ) {
262
- $this->_encipher($datal, $datar);
263
- $this->_S[3][$i] = $datal;
264
- $this->_S[3][$i+1] = $datar;
265
- }
266
-
267
- return true;
268
- }
269
-
270
- }
271
-
272
- ?>
1
+ <?php
2
+ /**
3
+ * Crypt_Blowfish allows for encryption and decryption on the fly using
4
+ * the Blowfish algorithm. Crypt_Blowfish does not require the mcrypt
5
+ * PHP extension, it uses only PHP.
6
+ * Crypt_Blowfish support encryption/decryption with or without a secret key.
7
+ *
8
+ * PHP versions 4 and 5
9
+ *
10
+ * @category Encryption
11
+ * @package Crypt_Blowfish
12
+ * @author Matthew Fonda <mfonda@php.net>
13
+ * @copyright 2005 Matthew Fonda
14
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
15
+ * @version CVS: $Id: Blowfish.php,v 1.81 2005/05/30 18:40:36 mfonda Exp $
16
+ * @link http://pear.php.net/package/Crypt_Blowfish
17
+ */
18
+
19
+ /**
20
+ *
21
+ * Example usage:
22
+ * $bf = new Crypt_Blowfish('some secret key!');
23
+ * $encrypted = $bf->encrypt('this is some example plain text');
24
+ * $plaintext = $bf->decrypt($encrypted);
25
+ * echo "plain text: $plaintext";
26
+ *
27
+ *
28
+ * @category Encryption
29
+ * @package Crypt_Blowfish
30
+ * @author Matthew Fonda <mfonda@php.net>
31
+ * @copyright 2005 Matthew Fonda
32
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
33
+ * @link http://pear.php.net/package/Crypt_Blowfish
34
+ * @version @package_version@
35
+ * @access public
36
+ */
37
+
38
+ class Crypt_Blowfish {
39
+
40
+ /**
41
+ * P-Array contains 18 32-bit subkeys
42
+ *
43
+ * @var array
44
+ * @access private
45
+ */
46
+ private $_P = array();
47
+
48
+ /**
49
+ * Array of four S-Blocks each containing 256 32-bit entries
50
+ *
51
+ * @var array
52
+ * @access private
53
+ */
54
+ private $_S = array();
55
+
56
+ /**
57
+ * Crypt_Blowfish Constructor
58
+ * Initializes the Crypt_Blowfish object, and gives a sets
59
+ * the secret key
60
+ *
61
+ * @param string $key
62
+ * @access public
63
+ */
64
+ public function __construct( $key ) {
65
+ $this->setKey( $key );
66
+ }
67
+
68
+ /**
69
+ * Deprecated isReady method
70
+ *
71
+ * @return bool
72
+ * @access public
73
+ * @deprecated
74
+ */
75
+ public function isReady() {
76
+ return true;
77
+ }
78
+
79
+ /**
80
+ * Deprecated init method - init is now a private
81
+ * method and has been replaced with _init
82
+ *
83
+ * @return bool
84
+ * @access public
85
+ * @deprecated
86
+ * @see Crypt_Blowfish::_init()
87
+ */
88
+ public function init() {
89
+ $this->_init();
90
+ }
91
+
92
+ /**
93
+ * Initializes the Crypt_Blowfish object
94
+ *
95
+ * @access private
96
+ */
97
+ private function _init() {
98
+ $defaults = new Crypt_Blowfish_DefaultKey();
99
+ $this->_P = $defaults->P;
100
+ $this->_S = $defaults->S;
101
+ }
102
+
103
+ /**
104
+ * Enciphers a single 64 bit block
105
+ *
106
+ * @param int &$Xl
107
+ * @param int &$Xr
108
+ * @access private
109
+ */
110
+ private function _encipher( &$Xl, &$Xr ) {
111
+ for ( $i = 0; $i < 16; $i++ ) {
112
+ $temp = $Xl ^ $this->_P[$i];
113
+ $Xl = ((($this->_S[0][($temp>>24) & 255] +
114
+ $this->_S[1][($temp>>16) & 255]) ^
115
+ $this->_S[2][($temp>>8) & 255]) +
116
+ $this->_S[3][$temp & 255]) ^ $Xr;
117
+ $Xr = $temp;
118
+ }
119
+ $Xr = $Xl ^ $this->_P[16];
120
+ $Xl = $temp ^ $this->_P[17];
121
+ }
122
+
123
+ /**
124
+ * Deciphers a single 64 bit block
125
+ *
126
+ * @param int &$Xl
127
+ * @param int &$Xr
128
+ * @access private
129
+ */
130
+ private function _decipher( &$Xl, &$Xr ) {
131
+ for ( $i = 17; $i > 1; $i-- ) {
132
+ $temp = $Xl ^ $this->_P[$i];
133
+ $Xl = ((($this->_S[0][($temp>>24) & 255] +
134
+ $this->_S[1][($temp>>16) & 255]) ^
135
+ $this->_S[2][($temp>>8) & 255]) +
136
+ $this->_S[3][$temp & 255]) ^ $Xr;
137
+ $Xr = $temp;
138
+ }
139
+ $Xr = $Xl ^ $this->_P[1];
140
+ $Xl = $temp ^ $this->_P[0];
141
+ }
142
+
143
+
144
+ /**
145
+ * Encrypts a string
146
+ *
147
+ * @param string $plainText
148
+ * @return string Returns cipher text on success, PEAR_Error on failure
149
+ * @access public
150
+ */
151
+ public function encrypt( $plainText ) {
152
+ if ( ! is_string( $plainText ) ) {
153
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ') : Plain text must be a string' );
154
+ //PEAR::raiseError('Plain text must be a string', 0, PEAR_ERROR_DIE);
155
+ die();
156
+ }
157
+
158
+ $cipherText = '';
159
+ $len = strlen( $plainText );
160
+ $plainText .= str_repeat(chr(0),(8 - ($len%8))%8);
161
+ for ( $i = 0; $i < $len; $i += 8 ) {
162
+ list( , $Xl, $Xr ) = unpack( "N2",substr( $plainText,$i, 8 ) );
163
+ $this->_encipher( $Xl, $Xr );
164
+ $cipherText .= pack( "N2", $Xl, $Xr );
165
+ }
166
+ return base64_encode( $cipherText) ;
167
+ }
168
+
169
+
170
+ /**
171
+ * Decrypts an encrypted string
172
+ *
173
+ * @param string $cipherText
174
+ * @return string Returns plain text on success, PEAR_Error on failure
175
+ * @access public
176
+ */
177
+ public function decrypt( $cipherText ) {
178
+ if ( ! is_string( $cipherText ) ) {
179
+ //PEAR::raiseError('Chiper text must be a string', 1, PEAR_ERROR_DIE);
180
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ') : Chiper text must be a string' );
181
+ die();
182
+ }
183
+
184
+ $cipherText = base64_decode( $cipherText );
185
+
186
+ $plainText = '';
187
+ $len = strlen( $cipherText );
188
+ $cipherText .= str_repeat( chr(0), (8 - ($len%8))%8 );
189
+ for ( $i = 0; $i < $len; $i += 8 ) {
190
+ list( , $Xl, $Xr ) = unpack( "N2", substr( $cipherText, $i, 8 ) );
191
+ $this->_decipher( $Xl, $Xr );
192
+ $plainText .= pack( "N2", $Xl, $Xr );
193
+ }
194
+ return $plainText;
195
+ }
196
+
197
+
198
+ /**
199
+ * Sets the secret key
200
+ * The key must be non-zero, and less than or equal to
201
+ * 56 characters in length.
202
+ *
203
+ * @param string $key
204
+ * @return bool Returns true on success, PEAR_Error on failure
205
+ * @access public
206
+ */
207
+ public function setKey( $key ) {
208
+ if ( ! is_string( $key ) ) {
209
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ') : Key must be a string' );
210
+ //PEAR::raiseError('Key must be a string', 2, PEAR_ERROR_DIE);
211
+ die();
212
+ }
213
+
214
+ $key = substr( md5( $key ), 0, 55 );
215
+
216
+ $len = strlen( $key );
217
+
218
+ if ( $len > 56 || $len == 0 ) {
219
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ') : Key must be less than 56 characters and non-zero' );
220
+ //PEAR::raiseError('Key must be less than 56 characters and non-zero. Supplied key length: ' . $len, 3, PEAR_ERROR_DIE);
221
+ die();
222
+ }
223
+
224
+ require_once 'class-default-key.php';
225
+ $this->_init();
226
+
227
+ $k = 0;
228
+ $data = 0;
229
+ $datal = 0;
230
+ $datar = 0;
231
+
232
+ for ( $i = 0; $i < 18; $i++ ) {
233
+ $data = 0;
234
+ for ( $j = 4; $j > 0; $j-- ) {
235
+ $data = $data << 8 | ord($key{$k});
236
+ $k = ($k+1) % $len;
237
+ }
238
+ $this->_P[$i] ^= $data;
239
+ }
240
+
241
+ for ( $i = 0; $i <= 16; $i += 2 ) {
242
+ $this->_encipher($datal, $datar);
243
+ $this->_P[$i] = $datal;
244
+ $this->_P[$i+1] = $datar;
245
+ }
246
+ for ( $i = 0; $i < 256; $i += 2 ) {
247
+ $this->_encipher($datal, $datar);
248
+ $this->_S[0][$i] = $datal;
249
+ $this->_S[0][$i+1] = $datar;
250
+ }
251
+ for ( $i = 0; $i < 256; $i += 2 ) {
252
+ $this->_encipher($datal, $datar);
253
+ $this->_S[1][$i] = $datal;
254
+ $this->_S[1][$i+1] = $datar;
255
+ }
256
+ for ($i = 0; $i < 256; $i += 2) {
257
+ $this->_encipher($datal, $datar);
258
+ $this->_S[2][$i] = $datal;
259
+ $this->_S[2][$i+1] = $datar;
260
+ }
261
+ for ( $i = 0; $i < 256; $i += 2 ) {
262
+ $this->_encipher($datal, $datar);
263
+ $this->_S[3][$i] = $datal;
264
+ $this->_S[3][$i+1] = $datar;
265
+ }
266
+
267
+ return true;
268
+ }
269
+
270
+ }
271
+
272
+ ?>
includes/class-default-key.php CHANGED
@@ -1,320 +1,319 @@
1
- <?php
2
- /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
-
4
- /**
5
- * Crypt_Blowfish allows for encryption and decryption on the fly using
6
- * the Blowfish algorithm. Crypt_Blowfish does not require the mcrypt
7
- * PHP extension, it uses only PHP.
8
- * Crypt_Blowfish support encryption/decryption with or without a secret key.
9
- *
10
- *
11
- * PHP versions 4 and 5
12
- *
13
- *
14
- * @category Encryption
15
- * @package Crypt_Blowfish
16
- * @author Matthew Fonda <mfonda@php.net>
17
- * @copyright 2005 Matthew Fonda
18
- * @license http://www.opensource.org/licenses/mit-license.html MIT License
19
- * @version CVS: $Id: DefaultKey.php,v 1.81 2005/05/30 18:40:37 mfonda Exp $
20
- * @link http://pear.php.net/package/Crypt_Blowfish
21
- */
22
-
23
-
24
- /**
25
- * Class containing default key
26
- *
27
- * @category Encryption
28
- * @package Crypt_Blowfish
29
- * @author Matthew Fonda <mfonda@php.net>
30
- * @copyright 2005 Matthew Fonda
31
- * @license http://www.opensource.org/licenses/mit-license.html MIT License
32
- * @link http://pear.php.net/package/Crypt_Blowfish
33
- * @version @package_version@
34
- * @access public
35
- */
36
- class Crypt_Blowfish_DefaultKey {
37
- public $P = array();
38
-
39
- public $S = array();
40
-
41
- public function __construct() {
42
- $this->P = array(
43
- 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
44
- 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
45
- 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
46
- 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917,
47
- 0x9216D5D9, 0x8979FB1B
48
- );
49
-
50
- $this->S = array(
51
- array(
52
- 0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7,
53
- 0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99,
54
- 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
55
- 0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E,
56
- 0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE,
57
- 0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013,
58
- 0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF,
59
- 0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E,
60
- 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60,
61
- 0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440,
62
- 0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE,
63
- 0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
64
- 0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E,
65
- 0xAFD6BA33, 0x6C24CF5C, 0x7A325381, 0x28958677,
66
- 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193,
67
- 0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032,
68
- 0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88,
69
- 0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239,
70
- 0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E,
71
- 0x21C66842, 0xF6E96C9A, 0x670C9C61, 0xABD388F0,
72
- 0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3,
73
- 0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98,
74
- 0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88,
75
- 0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE,
76
- 0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6,
77
- 0x4ED3AA62, 0x363F7706, 0x1BFEDF72, 0x429B023D,
78
- 0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B,
79
- 0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7,
80
- 0xE3FE501A, 0xB6794C3B, 0x976CE0BD, 0x04C006BA,
81
- 0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463,
82
- 0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F,
83
- 0x6DFC511F, 0x9B30952C, 0xCC814544, 0xAF5EBD09,
84
- 0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3,
85
- 0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB,
86
- 0x5579C0BD, 0x1A60320A, 0xD6A100C6, 0x402C7279,
87
- 0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8,
88
- 0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB,
89
- 0x323DB5FA, 0xFD238760, 0x53317B48, 0x3E00DF82,
90
- 0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB,
91
- 0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573,
92
- 0x695B27B0, 0xBBCA58C8, 0xE1FFA35D, 0xB8F011A0,
93
- 0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B,
94
- 0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790,
95
- 0xE1DDF2DA, 0xA4CB7E33, 0x62FB1341, 0xCEE4C6E8,
96
- 0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4,
97
- 0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0,
98
- 0xD08ED1D0, 0xAFC725E0, 0x8E3C5B2F, 0x8E7594B7,
99
- 0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C,
100
- 0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD,
101
- 0x2F2F2218, 0xBE0E1777, 0xEA752DFE, 0x8B021FA1,
102
- 0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299,
103
- 0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9,
104
- 0x165FA266, 0x80957705, 0x93CC7314, 0x211A1477,
105
- 0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF,
106
- 0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49,
107
- 0x00250E2D, 0x2071B35E, 0x226800BB, 0x57B8E0AF,
108
- 0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA,
109
- 0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5,
110
- 0x83260376, 0x6295CFA9, 0x11C81968, 0x4E734A41,
111
- 0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915,
112
- 0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400,
113
- 0x08BA6FB5, 0x571BE91F, 0xF296EC6B, 0x2A0DD915,
114
- 0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664,
115
- 0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A
116
- ),
117
- array(
118
- 0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623,
119
- 0xAD6EA6B0, 0x49A7DF7D, 0x9CEE60B8, 0x8FEDB266,
120
- 0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1,
121
- 0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E,
122
- 0x3F54989A, 0x5B429D65, 0x6B8FE4D6, 0x99F73FD6,
123
- 0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1,
124
- 0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E,
125
- 0x09686B3F, 0x3EBAEFC9, 0x3C971814, 0x6B6A70A1,
126
- 0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737,
127
- 0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8,
128
- 0xB03ADA37, 0xF0500C0D, 0xF01C1F04, 0x0200B3FF,
129
- 0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD,
130
- 0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701,
131
- 0x3AE5E581, 0x37C2DADC, 0xC8B57634, 0x9AF3DDA7,
132
- 0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41,
133
- 0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331,
134
- 0x4E548B38, 0x4F6DB908, 0x6F420D03, 0xF60A04BF,
135
- 0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF,
136
- 0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E,
137
- 0x5512721F, 0x2E6B7124, 0x501ADDE6, 0x9F84CD87,
138
- 0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C,
139
- 0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2,
140
- 0xEF1C1847, 0x3215D908, 0xDD433B37, 0x24C2BA16,
141
- 0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD,
142
- 0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B,
143
- 0x043556F1, 0xD7A3C76B, 0x3C11183B, 0x5924A509,
144
- 0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E,
145
- 0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3,
146
- 0x771FE71C, 0x4E3D06FA, 0x2965DCB9, 0x99E71D0F,
147
- 0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A,
148
- 0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4,
149
- 0xF2F74EA7, 0x361D2B3D, 0x1939260F, 0x19C27960,
150
- 0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66,
151
- 0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28,
152
- 0xC332DDEF, 0xBE6C5AA5, 0x65582185, 0x68AB9802,
153
- 0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84,
154
- 0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510,
155
- 0x13CCA830, 0xEB61BD96, 0x0334FE1E, 0xAA0363CF,
156
- 0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14,
157
- 0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E,
158
- 0x648B1EAF, 0x19BDF0CA, 0xA02369B9, 0x655ABB50,
159
- 0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7,
160
- 0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8,
161
- 0xF837889A, 0x97E32D77, 0x11ED935F, 0x16681281,
162
- 0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99,
163
- 0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696,
164
- 0xCDB30AEB, 0x532E3054, 0x8FD948E4, 0x6DBC3128,
165
- 0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73,
166
- 0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0,
167
- 0x45EEE2B6, 0xA3AAABEA, 0xDB6C4F15, 0xFACB4FD0,
168
- 0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105,
169
- 0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250,
170
- 0xCF62A1F2, 0x5B8D2646, 0xFC8883A0, 0xC1C7B6A3,
171
- 0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285,
172
- 0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00,
173
- 0x58428D2A, 0x0C55F5EA, 0x1DADF43E, 0x233F7061,
174
- 0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB,
175
- 0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E,
176
- 0xA6078084, 0x19F8509E, 0xE8EFD855, 0x61D99735,
177
- 0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC,
178
- 0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9,
179
- 0xDB73DBD3, 0x105588CD, 0x675FDA79, 0xE3674340,
180
- 0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20,
181
- 0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7
182
- ),
183
- array(
184
- 0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934,
185
- 0x411520F7, 0x7602D4F7, 0xBCF46B2E, 0xD4A20068,
186
- 0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF,
187
- 0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840,
188
- 0x4D95FC1D, 0x96B591AF, 0x70F4DDD3, 0x66A02F45,
189
- 0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504,
190
- 0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A,
191
- 0x28507825, 0x530429F4, 0x0A2C86DA, 0xE9B66DFB,
192
- 0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE,
193
- 0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6,
194
- 0xAACE1E7C, 0xD3375FEC, 0xCE78A399, 0x406B2A42,
195
- 0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B,
196
- 0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2,
197
- 0x3A6EFA74, 0xDD5B4332, 0x6841E7F7, 0xCA7820FB,
198
- 0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527,
199
- 0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B,
200
- 0x55A867BC, 0xA1159A58, 0xCCA92963, 0x99E1DB33,
201
- 0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C,
202
- 0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3,
203
- 0x95C11548, 0xE4C66D22, 0x48C1133F, 0xC70F86DC,
204
- 0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17,
205
- 0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564,
206
- 0x257B7834, 0x602A9C60, 0xDFF8E8A3, 0x1F636C1B,
207
- 0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115,
208
- 0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922,
209
- 0x85B2A20E, 0xE6BA0D99, 0xDE720C8C, 0x2DA2F728,
210
- 0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0,
211
- 0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E,
212
- 0x0A476341, 0x992EFF74, 0x3A6F6EAB, 0xF4F8FD37,
213
- 0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D,
214
- 0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804,
215
- 0xF1290DC7, 0xCC00FFA3, 0xB5390F92, 0x690FED0B,
216
- 0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3,
217
- 0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB,
218
- 0x37392EB3, 0xCC115979, 0x8026E297, 0xF42E312D,
219
- 0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C,
220
- 0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350,
221
- 0x1A6B1018, 0x11CAEDFA, 0x3D25BDD8, 0xE2E1C3C9,
222
- 0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A,
223
- 0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE,
224
- 0x9DBC8057, 0xF0F7C086, 0x60787BF8, 0x6003604D,
225
- 0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC,
226
- 0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F,
227
- 0x77A057BE, 0xBDE8AE24, 0x55464299, 0xBF582E61,
228
- 0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2,
229
- 0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9,
230
- 0x7AEB2661, 0x8B1DDF84, 0x846A0E79, 0x915F95E2,
231
- 0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C,
232
- 0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E,
233
- 0xB77F19B6, 0xE0A9DC09, 0x662D09A1, 0xC4324633,
234
- 0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10,
235
- 0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169,
236
- 0xDCB7DA83, 0x573906FE, 0xA1E2CE9B, 0x4FCD7F52,
237
- 0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027,
238
- 0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5,
239
- 0xF0177A28, 0xC0F586E0, 0x006058AA, 0x30DC7D62,
240
- 0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634,
241
- 0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76,
242
- 0x6F05E409, 0x4B7C0188, 0x39720A3D, 0x7C927C24,
243
- 0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC,
244
- 0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4,
245
- 0x1E50EF5E, 0xB161E6F8, 0xA28514D9, 0x6C51133C,
246
- 0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837,
247
- 0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0
248
- ),
249
- array(
250
- 0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B,
251
- 0x5CB0679E, 0x4FA33742, 0xD3822740, 0x99BC9BBE,
252
- 0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B,
253
- 0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4,
254
- 0x5748AB2F, 0xBC946E79, 0xC6A376D2, 0x6549C2C8,
255
- 0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6,
256
- 0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304,
257
- 0xA1FAD5F0, 0x6A2D519A, 0x63EF8CE2, 0x9A86EE22,
258
- 0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4,
259
- 0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6,
260
- 0x2826A2F9, 0xA73A3AE1, 0x4BA99586, 0xEF5562E9,
261
- 0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59,
262
- 0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593,
263
- 0xE990FD5A, 0x9E34D797, 0x2CF0B7D9, 0x022B8B51,
264
- 0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28,
265
- 0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C,
266
- 0xE029AC71, 0xE019A5E6, 0x47B0ACFD, 0xED93FA9B,
267
- 0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28,
268
- 0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C,
269
- 0x15056DD4, 0x88F46DBA, 0x03A16125, 0x0564F0BD,
270
- 0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A,
271
- 0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319,
272
- 0x7533D928, 0xB155FDF5, 0x03563482, 0x8ABA3CBB,
273
- 0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F,
274
- 0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991,
275
- 0xEA7A90C2, 0xFB3E7BCE, 0x5121CE64, 0x774FBE32,
276
- 0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680,
277
- 0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166,
278
- 0xB39A460A, 0x6445C0DD, 0x586CDECF, 0x1C20C8AE,
279
- 0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB,
280
- 0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5,
281
- 0x72EACEA8, 0xFA6484BB, 0x8D6612AE, 0xBF3C6F47,
282
- 0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370,
283
- 0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D,
284
- 0x4040CB08, 0x4EB4E2CC, 0x34D2466A, 0x0115AF84,
285
- 0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048,
286
- 0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8,
287
- 0x611560B1, 0xE7933FDC, 0xBB3A792B, 0x344525BD,
288
- 0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9,
289
- 0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7,
290
- 0x1A908749, 0xD44FBD9A, 0xD0DADECB, 0xD50ADA38,
291
- 0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F,
292
- 0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C,
293
- 0xBF97222C, 0x15E6FC2A, 0x0F91FC71, 0x9B941525,
294
- 0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1,
295
- 0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442,
296
- 0xE0EC6E0E, 0x1698DB3B, 0x4C98A0BE, 0x3278E964,
297
- 0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E,
298
- 0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8,
299
- 0xDF359F8D, 0x9B992F2E, 0xE60B6F47, 0x0FE3F11D,
300
- 0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F,
301
- 0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299,
302
- 0xF523F357, 0xA6327623, 0x93A83531, 0x56CCCD02,
303
- 0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC,
304
- 0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614,
305
- 0xE6C6C7BD, 0x327A140A, 0x45E1D006, 0xC3F27B9A,
306
- 0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6,
307
- 0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B,
308
- 0x53113EC0, 0x1640E3D3, 0x38ABBD60, 0x2547ADF0,
309
- 0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060,
310
- 0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E,
311
- 0x1948C25C, 0x02FB8A8C, 0x01C36AE4, 0xD6EBE1F9,
312
- 0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F,
313
- 0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6
314
- )
315
- );
316
- }
317
-
318
- }
319
-
320
- ?>
1
+ <?php
2
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
+
4
+ /**
5
+ * Crypt_Blowfish allows for encryption and decryption on the fly using
6
+ * the Blowfish algorithm. Crypt_Blowfish does not require the mcrypt
7
+ * PHP extension, it uses only PHP.
8
+ * Crypt_Blowfish support encryption/decryption with or without a secret key.
9
+ *
10
+ *
11
+ * PHP versions 4 and 5
12
+ *
13
+ *
14
+ * @category Encryption
15
+ * @package Crypt_Blowfish
16
+ * @author Matthew Fonda <mfonda@php.net>
17
+ * @copyright 2005 Matthew Fonda
18
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
19
+ * @version CVS: $Id: DefaultKey.php,v 1.81 2005/05/30 18:40:37 mfonda Exp $
20
+ * @link http://pear.php.net/package/Crypt_Blowfish
21
+ */
22
+
23
+ /**
24
+ * Class containing default key
25
+ *
26
+ * @category Encryption
27
+ * @package Crypt_Blowfish
28
+ * @author Matthew Fonda <mfonda@php.net>
29
+ * @copyright 2005 Matthew Fonda
30
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
31
+ * @link http://pear.php.net/package/Crypt_Blowfish
32
+ * @version @package_version@
33
+ * @access public
34
+ */
35
+ class Crypt_Blowfish_DefaultKey {
36
+ public $P = array();
37
+
38
+ public $S = array();
39
+
40
+ public function __construct() {
41
+ $this->P = array(
42
+ 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
43
+ 0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
44
+ 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
45
+ 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917,
46
+ 0x9216D5D9, 0x8979FB1B
47
+ );
48
+
49
+ $this->S = array(
50
+ array(
51
+ 0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7,
52
+ 0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99,
53
+ 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
54
+ 0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E,
55
+ 0x0D95748F, 0x728EB658, 0x718BCD58, 0x82154AEE,
56
+ 0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013,
57
+ 0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF,
58
+ 0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E,
59
+ 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60,
60
+ 0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440,
61
+ 0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE,
62
+ 0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
63
+ 0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E,
64
+ 0xAFD6BA33, 0x6C24CF5C, 0x7A325381, 0x28958677,
65
+ 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193,
66
+ 0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032,
67
+ 0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88,
68
+ 0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239,
69
+ 0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E,
70
+ 0x21C66842, 0xF6E96C9A, 0x670C9C61, 0xABD388F0,
71
+ 0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3,
72
+ 0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98,
73
+ 0xA1F1651D, 0x39AF0176, 0x66CA593E, 0x82430E88,
74
+ 0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE,
75
+ 0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6,
76
+ 0x4ED3AA62, 0x363F7706, 0x1BFEDF72, 0x429B023D,
77
+ 0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B,
78
+ 0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7,
79
+ 0xE3FE501A, 0xB6794C3B, 0x976CE0BD, 0x04C006BA,
80
+ 0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463,
81
+ 0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F,
82
+ 0x6DFC511F, 0x9B30952C, 0xCC814544, 0xAF5EBD09,
83
+ 0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3,
84
+ 0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB,
85
+ 0x5579C0BD, 0x1A60320A, 0xD6A100C6, 0x402C7279,
86
+ 0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8,
87
+ 0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB,
88
+ 0x323DB5FA, 0xFD238760, 0x53317B48, 0x3E00DF82,
89
+ 0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB,
90
+ 0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573,
91
+ 0x695B27B0, 0xBBCA58C8, 0xE1FFA35D, 0xB8F011A0,
92
+ 0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B,
93
+ 0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790,
94
+ 0xE1DDF2DA, 0xA4CB7E33, 0x62FB1341, 0xCEE4C6E8,
95
+ 0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4,
96
+ 0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0,
97
+ 0xD08ED1D0, 0xAFC725E0, 0x8E3C5B2F, 0x8E7594B7,
98
+ 0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C,
99
+ 0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD,
100
+ 0x2F2F2218, 0xBE0E1777, 0xEA752DFE, 0x8B021FA1,
101
+ 0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299,
102
+ 0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9,
103
+ 0x165FA266, 0x80957705, 0x93CC7314, 0x211A1477,
104
+ 0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF,
105
+ 0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49,
106
+ 0x00250E2D, 0x2071B35E, 0x226800BB, 0x57B8E0AF,
107
+ 0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA,
108
+ 0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5,
109
+ 0x83260376, 0x6295CFA9, 0x11C81968, 0x4E734A41,
110
+ 0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915,
111
+ 0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400,
112
+ 0x08BA6FB5, 0x571BE91F, 0xF296EC6B, 0x2A0DD915,
113
+ 0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664,
114
+ 0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A
115
+ ),
116
+ array(
117
+ 0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623,
118
+ 0xAD6EA6B0, 0x49A7DF7D, 0x9CEE60B8, 0x8FEDB266,
119
+ 0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1,
120
+ 0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E,
121
+ 0x3F54989A, 0x5B429D65, 0x6B8FE4D6, 0x99F73FD6,
122
+ 0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1,
123
+ 0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E,
124
+ 0x09686B3F, 0x3EBAEFC9, 0x3C971814, 0x6B6A70A1,
125
+ 0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737,
126
+ 0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8,
127
+ 0xB03ADA37, 0xF0500C0D, 0xF01C1F04, 0x0200B3FF,
128
+ 0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD,
129
+ 0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701,
130
+ 0x3AE5E581, 0x37C2DADC, 0xC8B57634, 0x9AF3DDA7,
131
+ 0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41,
132
+ 0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331,
133
+ 0x4E548B38, 0x4F6DB908, 0x6F420D03, 0xF60A04BF,
134
+ 0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF,
135
+ 0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E,
136
+ 0x5512721F, 0x2E6B7124, 0x501ADDE6, 0x9F84CD87,
137
+ 0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C,
138
+ 0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2,
139
+ 0xEF1C1847, 0x3215D908, 0xDD433B37, 0x24C2BA16,
140
+ 0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD,
141
+ 0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B,
142
+ 0x043556F1, 0xD7A3C76B, 0x3C11183B, 0x5924A509,
143
+ 0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E,
144
+ 0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3,
145
+ 0x771FE71C, 0x4E3D06FA, 0x2965DCB9, 0x99E71D0F,
146
+ 0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A,
147
+ 0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4,
148
+ 0xF2F74EA7, 0x361D2B3D, 0x1939260F, 0x19C27960,
149
+ 0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66,
150
+ 0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28,
151
+ 0xC332DDEF, 0xBE6C5AA5, 0x65582185, 0x68AB9802,
152
+ 0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84,
153
+ 0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510,
154
+ 0x13CCA830, 0xEB61BD96, 0x0334FE1E, 0xAA0363CF,
155
+ 0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14,
156
+ 0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E,
157
+ 0x648B1EAF, 0x19BDF0CA, 0xA02369B9, 0x655ABB50,
158
+ 0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7,
159
+ 0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8,
160
+ 0xF837889A, 0x97E32D77, 0x11ED935F, 0x16681281,
161
+ 0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99,
162
+ 0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696,
163
+ 0xCDB30AEB, 0x532E3054, 0x8FD948E4, 0x6DBC3128,
164
+ 0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73,
165
+ 0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0,
166
+ 0x45EEE2B6, 0xA3AAABEA, 0xDB6C4F15, 0xFACB4FD0,
167
+ 0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105,
168
+ 0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250,
169
+ 0xCF62A1F2, 0x5B8D2646, 0xFC8883A0, 0xC1C7B6A3,
170
+ 0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285,
171
+ 0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00,
172
+ 0x58428D2A, 0x0C55F5EA, 0x1DADF43E, 0x233F7061,
173
+ 0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB,
174
+ 0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E,
175
+ 0xA6078084, 0x19F8509E, 0xE8EFD855, 0x61D99735,
176
+ 0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC,
177
+ 0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9,
178
+ 0xDB73DBD3, 0x105588CD, 0x675FDA79, 0xE3674340,
179
+ 0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20,
180
+ 0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7
181
+ ),
182
+ array(
183
+ 0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934,
184
+ 0x411520F7, 0x7602D4F7, 0xBCF46B2E, 0xD4A20068,
185
+ 0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF,
186
+ 0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840,
187
+ 0x4D95FC1D, 0x96B591AF, 0x70F4DDD3, 0x66A02F45,
188
+ 0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504,
189
+ 0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A,
190
+ 0x28507825, 0x530429F4, 0x0A2C86DA, 0xE9B66DFB,
191
+ 0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE,
192
+ 0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6,
193
+ 0xAACE1E7C, 0xD3375FEC, 0xCE78A399, 0x406B2A42,
194
+ 0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B,
195
+ 0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2,
196
+ 0x3A6EFA74, 0xDD5B4332, 0x6841E7F7, 0xCA7820FB,
197
+ 0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527,
198
+ 0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B,
199
+ 0x55A867BC, 0xA1159A58, 0xCCA92963, 0x99E1DB33,
200
+ 0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C,
201
+ 0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3,
202
+ 0x95C11548, 0xE4C66D22, 0x48C1133F, 0xC70F86DC,
203
+ 0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17,
204
+ 0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564,
205
+ 0x257B7834, 0x602A9C60, 0xDFF8E8A3, 0x1F636C1B,
206
+ 0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115,
207
+ 0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922,
208
+ 0x85B2A20E, 0xE6BA0D99, 0xDE720C8C, 0x2DA2F728,
209
+ 0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0,
210
+ 0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E,
211
+ 0x0A476341, 0x992EFF74, 0x3A6F6EAB, 0xF4F8FD37,
212
+ 0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D,
213
+ 0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804,
214
+ 0xF1290DC7, 0xCC00FFA3, 0xB5390F92, 0x690FED0B,
215
+ 0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3,
216
+ 0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB,
217
+ 0x37392EB3, 0xCC115979, 0x8026E297, 0xF42E312D,
218
+ 0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C,
219
+ 0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350,
220
+ 0x1A6B1018, 0x11CAEDFA, 0x3D25BDD8, 0xE2E1C3C9,
221
+ 0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A,
222
+ 0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE,
223
+ 0x9DBC8057, 0xF0F7C086, 0x60787BF8, 0x6003604D,
224
+ 0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC,
225
+ 0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F,
226
+ 0x77A057BE, 0xBDE8AE24, 0x55464299, 0xBF582E61,
227
+ 0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2,
228
+ 0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9,
229
+ 0x7AEB2661, 0x8B1DDF84, 0x846A0E79, 0x915F95E2,
230
+ 0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C,
231
+ 0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E,
232
+ 0xB77F19B6, 0xE0A9DC09, 0x662D09A1, 0xC4324633,
233
+ 0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10,
234
+ 0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169,
235
+ 0xDCB7DA83, 0x573906FE, 0xA1E2CE9B, 0x4FCD7F52,
236
+ 0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027,
237
+ 0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5,
238
+ 0xF0177A28, 0xC0F586E0, 0x006058AA, 0x30DC7D62,
239
+ 0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634,
240
+ 0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76,
241
+ 0x6F05E409, 0x4B7C0188, 0x39720A3D, 0x7C927C24,
242
+ 0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC,
243
+ 0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4,
244
+ 0x1E50EF5E, 0xB161E6F8, 0xA28514D9, 0x6C51133C,
245
+ 0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837,
246
+ 0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0
247
+ ),
248
+ array(
249
+ 0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B,
250
+ 0x5CB0679E, 0x4FA33742, 0xD3822740, 0x99BC9BBE,
251
+ 0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B,
252
+ 0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4,
253
+ 0x5748AB2F, 0xBC946E79, 0xC6A376D2, 0x6549C2C8,
254
+ 0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6,
255
+ 0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304,
256
+ 0xA1FAD5F0, 0x6A2D519A, 0x63EF8CE2, 0x9A86EE22,
257
+ 0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4,
258
+ 0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6,
259
+ 0x2826A2F9, 0xA73A3AE1, 0x4BA99586, 0xEF5562E9,
260
+ 0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59,
261
+ 0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593,
262
+ 0xE990FD5A, 0x9E34D797, 0x2CF0B7D9, 0x022B8B51,
263
+ 0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28,
264
+ 0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C,
265
+ 0xE029AC71, 0xE019A5E6, 0x47B0ACFD, 0xED93FA9B,
266
+ 0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28,
267
+ 0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C,
268
+ 0x15056DD4, 0x88F46DBA, 0x03A16125, 0x0564F0BD,
269
+ 0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A,
270
+ 0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319,
271
+ 0x7533D928, 0xB155FDF5, 0x03563482, 0x8ABA3CBB,
272
+ 0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F,
273
+ 0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991,
274
+ 0xEA7A90C2, 0xFB3E7BCE, 0x5121CE64, 0x774FBE32,
275
+ 0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680,
276
+ 0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166,
277
+ 0xB39A460A, 0x6445C0DD, 0x586CDECF, 0x1C20C8AE,
278
+ 0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB,
279
+ 0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5,
280
+ 0x72EACEA8, 0xFA6484BB, 0x8D6612AE, 0xBF3C6F47,
281
+ 0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370,
282
+ 0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D,
283
+ 0x4040CB08, 0x4EB4E2CC, 0x34D2466A, 0x0115AF84,
284
+ 0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048,
285
+ 0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8,
286
+ 0x611560B1, 0xE7933FDC, 0xBB3A792B, 0x344525BD,
287
+ 0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9,
288
+ 0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7,
289
+ 0x1A908749, 0xD44FBD9A, 0xD0DADECB, 0xD50ADA38,
290
+ 0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F,
291
+ 0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C,
292
+ 0xBF97222C, 0x15E6FC2A, 0x0F91FC71, 0x9B941525,
293
+ 0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1,
294
+ 0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442,
295
+ 0xE0EC6E0E, 0x1698DB3B, 0x4C98A0BE, 0x3278E964,
296
+ 0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E,
297
+ 0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8,
298
+ 0xDF359F8D, 0x9B992F2E, 0xE60B6F47, 0x0FE3F11D,
299
+ 0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F,
300
+ 0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299,
301
+ 0xF523F357, 0xA6327623, 0x93A83531, 0x56CCCD02,
302
+ 0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC,
303
+ 0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614,
304
+ 0xE6C6C7BD, 0x327A140A, 0x45E1D006, 0xC3F27B9A,
305
+ 0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6,
306
+ 0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B,
307
+ 0x53113EC0, 0x1640E3D3, 0x38ABBD60, 0x2547ADF0,
308
+ 0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060,
309
+ 0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E,
310
+ 0x1948C25C, 0x02FB8A8C, 0x01C36AE4, 0xD6EBE1F9,
311
+ 0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F,
312
+ 0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6
313
+ )
314
+ );
315
+ }
316
+
317
+ }
318
+
319
+ ?>
 
includes/class-scc-analytical-engline.php CHANGED
@@ -1,102 +1,102 @@
1
- <?php
2
- /*
3
- class-scc-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
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- abstract class SCC_Analytical_Engine extends SCC_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- protected $cache_prefix = NULL;
36
-
37
- /**
38
- * Prefix of base ID
39
- */
40
- protected $base_prefix = NULL;
41
-
42
- /**
43
- * Prefix of base ID
44
- */
45
- protected $delta_prefix = NULL;
46
-
47
- /**
48
- * instance for delegation
49
- */
50
- protected $delegate = NULL;
51
-
52
- /**
53
- * Get and cache data for a given post
54
- *
55
- * @since 0.1.1
56
- */
57
- abstract public function analyze( $options = array() );
58
-
59
- /**
60
- * Initialize cache
61
- *
62
- * @since 0.3.0
63
- */
64
- abstract public function initialize_base();
65
-
66
- /**
67
- * Clear cache
68
- *
69
- * @since 0.3.0
70
- */
71
- abstract public function clear_base();
72
-
73
- /**
74
- * Get cache key
75
- *
76
- * @since 0.6.0
77
- */
78
- public function get_cache_key( $suffix ) {
79
- return $this->cache_prefix . strtolower( $suffix );
80
- }
81
-
82
- /**
83
- * Get base key
84
- *
85
- * @since 0.6.1
86
- */
87
- public function get_base_key( $suffix ) {
88
- return $this->base_prefix . strtolower( $suffix );
89
- }
90
-
91
- /**
92
- * Get delta key
93
- *
94
- * @since 0.6.1
95
- */
96
- public function get_delta_key( $suffix ) {
97
- return $this->delta_prefix . strtolower( $suffix );
98
- }
99
-
100
- }
101
-
102
- ?>
1
+ <?php
2
+ /*
3
+ class-scc-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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ abstract class SCC_Analytical_Engine extends SCC_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ protected $cache_prefix = NULL;
36
+
37
+ /**
38
+ * Prefix of base ID
39
+ */
40
+ protected $base_prefix = NULL;
41
+
42
+ /**
43
+ * Prefix of base ID
44
+ */
45
+ protected $delta_prefix = NULL;
46
+
47
+ /**
48
+ * instance for delegation
49
+ */
50
+ protected $delegate = NULL;
51
+
52
+ /**
53
+ * Get and cache data for a given post
54
+ *
55
+ * @since 0.1.1
56
+ */
57
+ abstract public function analyze( $options = array() );
58
+
59
+ /**
60
+ * Initialize cache
61
+ *
62
+ * @since 0.3.0
63
+ */
64
+ abstract public function initialize_base();
65
+
66
+ /**
67
+ * Clear cache
68
+ *
69
+ * @since 0.3.0
70
+ */
71
+ abstract public function clear_base();
72
+
73
+ /**
74
+ * Get cache key
75
+ *
76
+ * @since 0.6.0
77
+ */
78
+ public function get_cache_key( $suffix ) {
79
+ return $this->cache_prefix . strtolower( $suffix );
80
+ }
81
+
82
+ /**
83
+ * Get base key
84
+ *
85
+ * @since 0.6.1
86
+ */
87
+ public function get_base_key( $suffix ) {
88
+ return $this->base_prefix . strtolower( $suffix );
89
+ }
90
+
91
+ /**
92
+ * Get delta key
93
+ *
94
+ * @since 0.6.1
95
+ */
96
+ public function get_delta_key( $suffix ) {
97
+ return $this->delta_prefix . strtolower( $suffix );
98
+ }
99
+
100
+ }
101
+
102
+ ?>
includes/class-scc-cache-engine.php CHANGED
@@ -1,107 +1,114 @@
1
- <?php
2
- /*
3
- class-scc-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- abstract class SCC_Cache_Engine extends SCC_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- protected $cache_prefix = NULL;
36
-
37
- /**
38
- * instance for delegation
39
- */
40
- protected $delegate = NULL;
41
-
42
- /**
43
- * retry of cache processing
44
- */
45
- protected $cache_retry = false;
46
-
47
- /**
48
- * limit of cache retry
49
- */
50
- protected $retry_limit = 3;
51
-
52
- /**
53
- * fault tolerance mode
54
- */
55
- protected $fault_tolerance = 1;
56
-
57
- /**
58
- * Get cache expiration based on current number of total post and page
59
- *
60
- * @since 0.1.1
61
- */
62
- abstract protected function get_cache_expiration();
63
-
64
- /**
65
- * Get and cache data for a given post
66
- *
67
- * @since 0.1.1
68
- */
69
- abstract public function cache( $options = array() );
70
-
71
- /**
72
- * Initialize cache
73
- *
74
- * @since 0.3.0
75
- */
76
- abstract public function initialize_cache();
77
-
78
- /**
79
- * Clear cache
80
- *
81
- * @since 0.3.0
82
- */
83
- abstract public function clear_cache();
84
-
85
- /**
86
- * Get cache key
87
- *
88
- * @since 0.6.0
89
- */
90
- public function get_cache_key( $suffix ) {
91
- return $this->cache_prefix . strtolower( $suffix );
92
- }
93
-
94
- /**
95
- * Order
96
- *
97
- * @since 0.6.1
98
- */
99
- protected function delegate_order( $order, $options = array() ) {
100
- if ( ! is_null( $this->delegate ) && method_exists( $this->delegate, 'order' ) ) {
101
- $this->delegate->order( $this, $order, $options );
102
- }
103
- }
104
-
105
- }
106
-
107
- ?>
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ abstract class SCC_Cache_Engine extends SCC_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ protected $cache_prefix = NULL;
36
+
37
+ /**
38
+ * instance for delegation
39
+ */
40
+ protected $delegate = NULL;
41
+
42
+ /**
43
+ * retry of cache processing
44
+ */
45
+ protected $cache_retry = false;
46
+
47
+ /**
48
+ * limit of cache retry
49
+ */
50
+ protected $retry_limit = 3;
51
+
52
+ /**
53
+ * fault tolerance mode
54
+ */
55
+ protected $fault_tolerance = 1;
56
+
57
+ /**
58
+ * Get cache expiration based on current number of total post and page
59
+ *
60
+ * @since 0.1.1
61
+ */
62
+ abstract protected function get_cache_expiration();
63
+
64
+ /**
65
+ * Get and cache data for a given post
66
+ *
67
+ * @since 0.1.1
68
+ */
69
+ abstract public function cache( $options = array() );
70
+
71
+ /**
72
+ * Initialize cache
73
+ *
74
+ * @since 0.3.0
75
+ */
76
+ abstract public function initialize_cache();
77
+
78
+ /**
79
+ * Clear cache
80
+ *
81
+ * @since 0.3.0
82
+ */
83
+ abstract public function clear_cache();
84
+
85
+ /**
86
+ * Get cache
87
+ *
88
+ * @since 0.10.1
89
+ */
90
+ abstract public function get_cache( $options = array() );
91
+
92
+ /**
93
+ * Get cache key
94
+ *
95
+ * @since 0.6.0
96
+ */
97
+ public function get_cache_key( $suffix ) {
98
+ return $this->cache_prefix . strtolower( $suffix );
99
+ }
100
+
101
+ /**
102
+ * Order
103
+ *
104
+ * @since 0.6.1
105
+ */
106
+ protected function delegate_order( $order, $options = array() ) {
107
+ if ( ! is_null( $this->delegate ) && ( $this->delegate instanceof SCC_Order ) && method_exists( $this->delegate, 'order' ) ) {
108
+ $this->delegate->order( $this, $order, $options );
109
+ }
110
+ }
111
+
112
+ }
113
+
114
+ ?>
includes/class-scc-common-data-export-engine.php CHANGED
@@ -1,339 +1,341 @@
1
- <?php
2
- /*
3
- class-scc-common-data-export.php
4
-
5
- Description: This class is a data export engine whitch exports cached data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Common_Data_Export_Engine extends SCC_Export_Engine {
31
-
32
- /**
33
- * Meta key for share second cache
34
- */
35
- const DEF_SHARE_META_KEY_PREFIX = 'scc_share_count_';
36
-
37
- /**
38
- * Meta key for follow second cache
39
- */
40
- const DEF_FOLLOW_META_KEY_PREFIX = 'scc_follow_count_';
41
-
42
- /**
43
- * Cron name to schedule cache processing
44
- */
45
- const DEF_PRIME_CRON = 'scc_common_dataexport_prime';
46
-
47
- /**
48
- * Cron name to execute cache processing
49
- */
50
- const DEF_EXECUTE_CRON = 'scc_common_dataexport_exec';
51
-
52
- /**
53
- * Schedule name for cache processing
54
- */
55
- const DEF_EVENT_SCHEDULE = 'common_data_export_event';
56
-
57
- /**
58
- * Schedule description for cache processing
59
- */
60
- const DEF_EVENT_DESCRIPTION = '[SCC] Common Data Export Interval';
61
-
62
- /**
63
- * Option flag of data export
64
- */
65
- private $export_activation = 0;
66
-
67
- /**
68
- * Interval for data export
69
- */
70
- private $export_interval = 43200;
71
-
72
- /**
73
- * Schedule for data export
74
- */
75
- private $export_schedule = '0 0 * * *';
76
-
77
- /**
78
- * Excluded keys of data export
79
- */
80
- private $export_exclude_keys = array();
81
-
82
- /**
83
- * File name of data export
84
- */
85
- private $export_file_name = 'sns-count-cache-data.csv';
86
-
87
- /**
88
- * Cache post types
89
- */
90
- private $post_types = array( 'post', 'page' );
91
-
92
- /**
93
- * Cache target of share count
94
- */
95
- private $share_target_sns = array();
96
-
97
- /**
98
- * Cache target of follow count
99
- */
100
- private $follow_target_sns = array();
101
-
102
- /**
103
- * Initialization
104
- *
105
- * @since 0.1.1
106
- */
107
- public function initialize( $options = array() ) {
108
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
109
-
110
- $this->share_cache_key_prefix = self::DEF_SHARE_META_KEY_PREFIX;
111
- $this->follow_cache_key_prefix = self::DEF_FOLLOW_META_KEY_PREFIX;
112
- $this->prime_cron = self::DEF_PRIME_CRON;
113
- $this->execute_cron = self::DEF_EXECUTE_CRON;
114
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
115
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
116
-
117
- if ( isset( $options['export_activation'] ) ) $this->export_activation = $options['export_activation'];
118
- if ( isset( $options['export_interval'] ) ) $this->export_interval = $options['export_interval'];
119
- if ( isset( $options['export_schedule'] ) ) $this->export_schedule = $options['export_schedule'];
120
- if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
121
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
122
- if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
123
- if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
124
- if ( isset( $options['export_exclude_keys'] ) ) $this->export_exclude_keys = $options['export_exclude_keys'];
125
- if ( isset( $options['export_file_name'] ) ) $this->export_file_name = $options['export_file_name'];
126
- if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
127
- if ( isset( $options['share_cache_key_prefix'] ) ) $this->share_cache_key_prefix = $options['share_cache_key_prefix'];
128
- if ( isset( $options['follow_cache_key_prefix'] ) ) $this->follow_cache_key_prefix = $options['follow_cache_key_prefix'];
129
- if ( isset( $options['share_target_sns'] ) ) $this->share_target_sns = $options['share_target_sns'];
130
- if ( isset( $options['follow_target_sns'] ) ) $this->follow_target_sns = $options['follow_target_sns'];
131
-
132
- add_filter( 'cron_schedules', array( $this, 'schedule_export_interval' ) );
133
- add_action( $this->prime_cron, array( $this, 'prime_export' ) );
134
- add_action( $this->execute_cron, array( $this, 'execute_export' ), 10, 1 );
135
- }
136
-
137
- /**
138
- * Register event schedule for this engine
139
- *
140
- * @since 0.1.0
141
- */
142
- public function schedule_export_interval( $schedules ) {
143
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
144
-
145
- $schedules[$this->event_schedule] = array(
146
- 'interval' => $this->export_interval,
147
- 'display' => $this->event_description
148
- );
149
-
150
- return $schedules;
151
- }
152
-
153
- /**
154
- * Prime data export
155
- *
156
- * @since 0.4.0
157
- */
158
- public function prime_export() {
159
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
160
-
161
- //$next_exec_time = time() + $this->export_interval;
162
-
163
- //$next_exec_time = time() + 5;
164
-
165
- $next_exec_time = SCC_WP_Cron_Util::next_exec_time( $this->export_schedule );
166
-
167
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->export_interval );
168
-
169
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time (timesatamp): ' . $next_exec_time );
170
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time (date): ' . date_i18n( 'Y/m/d H:i:s', $next_exec_time ) );
171
-
172
- if ( ! SCC_WP_Cron_Util::is_scheduled_hook( $this->execute_cron ) ) {
173
- wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( SCC_Common_Util::short_hash( $next_exec_time ) ) );
174
- }
175
-
176
- //wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( SCC_Common_Util::short_hash( $next_exec_time ) ) );
177
- }
178
-
179
-
180
- /**
181
- * Execute data export
182
- *
183
- * @since 0.4.0
184
- */
185
- public function execute_export( $hash ) {
186
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
187
-
188
- $base_dir = WP_PLUGIN_DIR . '/sns-count-cache/data/';
189
-
190
- $current_date = date_i18n( 'Y/m/d H:i:s' );
191
-
192
- if ( file_exists( $base_dir ) ) {
193
- $abs_path = $base_dir . $this->export_file_name;
194
-
195
- if ( ! file_exists( $abs_path ) ) {
196
- if ( touch( $abs_path ) ) {
197
- SCC_Common_Util::log( '[' . __METHOD__ . '] export file creation succeeded: ' . $abs_path );
198
- } else {
199
- SCC_Common_Util::log( '[' . __METHOD__ . '] export file creation failed: ' . $abs_path );
200
- }
201
- if ( file_exists( $abs_path ) ) {
202
- SCC_Common_Util::log( '[' . __METHOD__ . '] file exists: ' . $abs_path );
203
- $fp = fopen( $abs_path, 'a' );
204
-
205
- $header = '"Retrieval Date","Post ID","Post Type","Post Title","Permalink","Post Date","SNS","Data Type","Data Value",' . "\r\n";
206
-
207
- if ( fwrite( $fp, mb_convert_encoding( $header, "SJIS", "UTF-8" ) ) ) {
208
- SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' . $header );
209
- } else {
210
- SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' . $header );
211
- }
212
- if ( fclose( $fp ) ) {
213
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $abs_path );
214
- } else {
215
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $abs_path );
216
- }
217
- }
218
- }
219
-
220
- if ( file_exists( $abs_path ) ) {
221
- SCC_Common_Util::log( '[' . __METHOD__ . '] file exists: ' . $abs_path );
222
-
223
- $fp = fopen( $abs_path, 'a' );
224
-
225
- $content = '"' . $current_date . '","' . 'home' . '","' . '-' . '","' . get_bloginfo('name') . '","' . home_url( '/' ) . '","' . '-';
226
-
227
- $option_key = $this->share_cache_key_prefix . strtolower( 'home' );
228
-
229
- if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
230
-
231
- foreach ( $this->share_target_sns as $sns => $active ) {
232
- if ( ! in_array( $sns, $this->export_exclude_keys ) ) {
233
- if( $active ){
234
- if ( $sns_counts[$sns] >= 0 ) {
235
- $data_value = $sns_counts[$sns];
236
- } else {
237
- $data_value = '';
238
- }
239
- $data = $content . '","' . $sns . '","' . 'Share' . '","' . $data_value . '",' . "\r\n";
240
- }
241
- if ( fwrite( $fp, mb_convert_encoding( $data, "SJIS", "UTF-8" ) ) ) {
242
- SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' . $data );
243
- } else {
244
- SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' . $data );
245
- }
246
- }
247
- }
248
- }
249
-
250
- $query_args = array(
251
- 'post_type' => $this->post_types,
252
- 'post_status' => 'publish',
253
- 'nopaging' => true,
254
- 'update_post_term_cache' => false,
255
- 'update_post_meta_cache' => false
256
- );
257
-
258
- $posts_query = new WP_Query( $query_args );
259
-
260
- if ( $posts_query->have_posts() ) {
261
- while ( $posts_query->have_posts() ) {
262
- $posts_query->the_post();
263
-
264
- $post_ID = get_the_ID();
265
-
266
- $content = '"' . $current_date . '","' . $post_ID . '","' . get_post_type( $post_ID ) . '","' . get_the_title( $post_ID ) . '","' . get_permalink( $post_ID ) . '","' . get_post_time( 'Y/m/d H:i', false, $post_ID );
267
-
268
- foreach ( $this->share_target_sns as $sns => $active ) {
269
- if ( ! in_array( $sns, $this->export_exclude_keys ) ) {
270
- $meta_key = $this->share_cache_key_prefix . strtolower( $sns );
271
-
272
- if ( $active ) {
273
- $data_value = get_post_meta( $post_ID, $meta_key, true );
274
-
275
- if ( $data_value < 0 ){
276
- $data_value = '';
277
- }
278
-
279
- $data = $content . '","' . $sns . '","' . 'Share' . '","' . $data_value . '",' . "\r\n";
280
- }
281
- if ( fwrite( $fp, mb_convert_encoding( $data, "SJIS", "UTF-8" ) ) ) {
282
- SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' . $data );
283
- } else {
284
- SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' . $data );
285
- }
286
- }
287
- }
288
-
289
- /*
290
- foreach ( $this->follow_target_sns as $key => $value ) {
291
- $meta_key = $this->follow_cache_key_prefix . strtolower( $key );
292
- if ( $value ) {
293
- $data_value = get_post_meta( $post_ID, $meta_key, true );
294
-
295
- if ( $data_value == -1 ){
296
- $data_value = '';
297
- }
298
-
299
- $data = $content . '","' . $key . '","' . 'Follow' . '","' . $data_value . '",' . "\r\n";
300
- }
301
- if ( fwrite( $fp, mb_convert_encoding( $data, "SJIS", "UTF-8" ) ) ) {
302
- SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' . $data );
303
- } else {
304
- SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' . $data );
305
- }
306
- }
307
- */
308
-
309
- }
310
- }
311
- wp_reset_postdata();
312
-
313
- if ( fclose($fp) ) {
314
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $abs_path );
315
- } else {
316
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $abs_path );
317
- }
318
- }
319
- }
320
- }
321
-
322
- /**
323
- * Reset exported file
324
- *
325
- * @since 0.4.0
326
- */
327
- public function reset_export() {
328
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
329
-
330
- $base_dir = WP_PLUGIN_DIR . '/sns-count-cache/data/';
331
- $abs_path = $base_dir . $this->export_file_name;
332
-
333
- if ( file_exists( $abs_path ) ) {
334
- unlink( $abs_path );
335
- }
336
- }
337
- }
338
-
339
- ?>
 
 
1
+ <?php
2
+ /*
3
+ class-scc-common-data-export.php
4
+
5
+ Description: This class is a data export engine whitch exports cached data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Common_Data_Export_Engine extends SCC_Export_Engine {
31
+
32
+ /**
33
+ * Meta key for share second cache
34
+ */
35
+ const DEF_SHARE_META_KEY_PREFIX = 'scc_share_count_';
36
+
37
+ /**
38
+ * Meta key for follow second cache
39
+ */
40
+ const DEF_FOLLOW_META_KEY_PREFIX = 'scc_follow_count_';
41
+
42
+ /**
43
+ * Cron name to schedule cache processing
44
+ */
45
+ const DEF_PRIME_CRON = 'scc_common_dataexport_prime';
46
+
47
+ /**
48
+ * Cron name to execute cache processing
49
+ */
50
+ const DEF_EXECUTE_CRON = 'scc_common_dataexport_exec';
51
+
52
+ /**
53
+ * Schedule name for cache processing
54
+ */
55
+ const DEF_EVENT_SCHEDULE = 'common_data_export_event';
56
+
57
+ /**
58
+ * Schedule description for cache processing
59
+ */
60
+ const DEF_EVENT_DESCRIPTION = '[SCC] Common Data Export Interval';
61
+
62
+ /**
63
+ * Option flag of data export
64
+ */
65
+ private $export_activation = 0;
66
+
67
+ /**
68
+ * Interval for data export
69
+ */
70
+ private $export_interval = 43200;
71
+
72
+ /**
73
+ * Schedule for data export
74
+ */
75
+ private $export_schedule = '0 0 * * *';
76
+
77
+ /**
78
+ * Excluded keys of data export
79
+ */
80
+ private $export_exclude_keys = array();
81
+
82
+ /**
83
+ * File name of data export
84
+ */
85
+ private $export_file_name = 'sns-count-cache-data.csv';
86
+
87
+ /**
88
+ * Cache post types
89
+ */
90
+ private $post_types = array( 'post', 'page' );
91
+
92
+ /**
93
+ * Cache target of share count
94
+ */
95
+ private $share_target_sns = array();
96
+
97
+ /**
98
+ * Cache target of follow count
99
+ */
100
+ private $follow_target_sns = array();
101
+
102
+ /**
103
+ * Initialization
104
+ *
105
+ * @since 0.1.1
106
+ */
107
+ public function initialize( $options = array() ) {
108
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
109
+
110
+ $this->share_cache_key_prefix = self::DEF_SHARE_META_KEY_PREFIX;
111
+ $this->follow_cache_key_prefix = self::DEF_FOLLOW_META_KEY_PREFIX;
112
+ $this->prime_cron = self::DEF_PRIME_CRON;
113
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
114
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
115
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
116
+
117
+ if ( isset( $options['export_activation'] ) ) $this->export_activation = $options['export_activation'];
118
+ if ( isset( $options['export_interval'] ) ) $this->export_interval = $options['export_interval'];
119
+ if ( isset( $options['export_schedule'] ) ) $this->export_schedule = $options['export_schedule'];
120
+ if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
121
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
122
+ if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
123
+ if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
124
+ if ( isset( $options['export_exclude_keys'] ) ) $this->export_exclude_keys = $options['export_exclude_keys'];
125
+ if ( isset( $options['export_file_name'] ) ) $this->export_file_name = $options['export_file_name'];
126
+ if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
127
+ if ( isset( $options['share_cache_key_prefix'] ) ) $this->share_cache_key_prefix = $options['share_cache_key_prefix'];
128
+ if ( isset( $options['follow_cache_key_prefix'] ) ) $this->follow_cache_key_prefix = $options['follow_cache_key_prefix'];
129
+ if ( isset( $options['share_target_sns'] ) ) $this->share_target_sns = $options['share_target_sns'];
130
+ if ( isset( $options['follow_target_sns'] ) ) $this->follow_target_sns = $options['follow_target_sns'];
131
+
132
+ add_filter( 'cron_schedules', array( $this, 'schedule_export_interval' ) );
133
+ add_action( $this->prime_cron, array( $this, 'prime_export' ) );
134
+ add_action( $this->execute_cron, array( $this, 'execute_export' ), 10, 1 );
135
+ }
136
+
137
+ /**
138
+ * Register event schedule for this engine
139
+ *
140
+ * @since 0.1.0
141
+ */
142
+ public function schedule_export_interval( $schedules ) {
143
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
144
+
145
+ $schedules[$this->event_schedule] = array(
146
+ 'interval' => $this->export_interval,
147
+ 'display' => $this->event_description
148
+ );
149
+
150
+ return $schedules;
151
+ }
152
+
153
+ /**
154
+ * Prime data export
155
+ *
156
+ * @since 0.4.0
157
+ */
158
+ public function prime_export() {
159
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
160
+
161
+ //$next_exec_time = time() + $this->export_interval;
162
+
163
+ //$next_exec_time = time() + 5;
164
+
165
+ $next_exec_time = SCC_WP_Cron_Util::next_exec_time( $this->export_schedule );
166
+
167
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->export_interval );
168
+
169
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time (timesatamp): ' . $next_exec_time );
170
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time (date): ' . date_i18n( 'Y/m/d H:i:s', $next_exec_time ) );
171
+
172
+ if ( ! SCC_WP_Cron_Util::is_scheduled_hook( $this->execute_cron ) ) {
173
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( SCC_Common_Util::short_hash( $next_exec_time ) ) );
174
+ }
175
+
176
+ //wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( SCC_Common_Util::short_hash( $next_exec_time ) ) );
177
+ }
178
+
179
+
180
+ /**
181
+ * Execute data export
182
+ *
183
+ * @since 0.4.0
184
+ */
185
+ public function execute_export( $hash ) {
186
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
187
+
188
+ $base_dir = WP_PLUGIN_DIR . '/sns-count-cache/data/';
189
+
190
+ $current_date = date_i18n( 'Y/m/d H:i:s' );
191
+
192
+ if ( file_exists( $base_dir ) ) {
193
+ $abs_path = $base_dir . $this->export_file_name;
194
+
195
+ if ( ! file_exists( $abs_path ) ) {
196
+ if ( touch( $abs_path ) ) {
197
+ SCC_Common_Util::log( '[' . __METHOD__ . '] export file creation succeeded: ' . $abs_path );
198
+ } else {
199
+ SCC_Common_Util::log( '[' . __METHOD__ . '] export file creation failed: ' . $abs_path );
200
+ }
201
+ if ( file_exists( $abs_path ) ) {
202
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file exists: ' . $abs_path );
203
+ $fp = fopen( $abs_path, 'a' );
204
+
205
+ $header = '"Retrieval Date","Post ID","Post Type","Post Title","Permalink","Post Date","SNS","Data Type","Data Value",' . "\r\n";
206
+
207
+ if ( fwrite( $fp, mb_convert_encoding( $header, "SJIS", "UTF-8" ) ) ) {
208
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' . $header );
209
+ } else {
210
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' . $header );
211
+ }
212
+ if ( fclose( $fp ) ) {
213
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $abs_path );
214
+ } else {
215
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $abs_path );
216
+ }
217
+ }
218
+ }
219
+
220
+ if ( file_exists( $abs_path ) ) {
221
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file exists: ' . $abs_path );
222
+
223
+ $fp = fopen( $abs_path, 'a' );
224
+
225
+ $content = '"' . $current_date . '","' . 'home' . '","' . '-' . '","' . get_bloginfo('name') . '","' . home_url( '/' ) . '","' . '-';
226
+
227
+ $option_key = $this->share_cache_key_prefix . strtolower( 'home' );
228
+
229
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
230
+
231
+ foreach ( $this->share_target_sns as $sns => $active ) {
232
+ if ( ! in_array( $sns, $this->export_exclude_keys ) ) {
233
+ if ( $active ){
234
+ if ( $sns_counts[$sns] >= 0 ) {
235
+ $data_value = $sns_counts[$sns];
236
+ } else {
237
+ $data_value = '';
238
+ }
239
+ $data = $content . '","' . $sns . '","' . 'Share' . '","' . $data_value . '",' . "\r\n";
240
+
241
+ if ( fwrite( $fp, mb_convert_encoding( $data, "SJIS", "UTF-8" ) ) ) {
242
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' . $data );
243
+ } else {
244
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' . $data );
245
+ }
246
+ }
247
+ }
248
+ }
249
+ }
250
+
251
+ $query_args = array(
252
+ 'post_type' => $this->post_types,
253
+ 'post_status' => 'publish',
254
+ 'nopaging' => true,
255
+ 'update_post_term_cache' => false,
256
+ 'update_post_meta_cache' => false
257
+ );
258
+
259
+ $posts_query = new WP_Query( $query_args );
260
+
261
+ if ( $posts_query->have_posts() ) {
262
+ while ( $posts_query->have_posts() ) {
263
+ $posts_query->the_post();
264
+
265
+ $post_ID = get_the_ID();
266
+
267
+ $content = '"' . $current_date . '","' . $post_ID . '","' . get_post_type( $post_ID ) . '","' . get_the_title( $post_ID ) . '","' . get_permalink( $post_ID ) . '","' . get_post_time( 'Y/m/d H:i', false, $post_ID );
268
+
269
+ foreach ( $this->share_target_sns as $sns => $active ) {
270
+ if ( ! in_array( $sns, $this->export_exclude_keys ) ) {
271
+ $meta_key = $this->share_cache_key_prefix . strtolower( $sns );
272
+
273
+ if ( $active ) {
274
+ $data_value = get_post_meta( $post_ID, $meta_key, true );
275
+
276
+ if ( $data_value < 0 ){
277
+ $data_value = '';
278
+ }
279
+
280
+ $data = $content . '","' . $sns . '","' . 'Share' . '","' . $data_value . '",' . "\r\n";
281
+
282
+ if ( fwrite( $fp, mb_convert_encoding( $data, "SJIS", "UTF-8" ) ) ) {
283
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' . $data );
284
+ } else {
285
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' . $data );
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ /*
292
+ foreach ( $this->follow_target_sns as $key => $value ) {
293
+ $meta_key = $this->follow_cache_key_prefix . strtolower( $key );
294
+ if ( $value ) {
295
+ $data_value = get_post_meta( $post_ID, $meta_key, true );
296
+
297
+ if ( $data_value == -1 ){
298
+ $data_value = '';
299
+ }
300
+
301
+ $data = $content . '","' . $key . '","' . 'Follow' . '","' . $data_value . '",' . "\r\n";
302
+ }
303
+ if ( fwrite( $fp, mb_convert_encoding( $data, "SJIS", "UTF-8" ) ) ) {
304
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' . $data );
305
+ } else {
306
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' . $data );
307
+ }
308
+ }
309
+ */
310
+
311
+ }
312
+ }
313
+ wp_reset_postdata();
314
+
315
+ if ( fclose( $fp ) ) {
316
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $abs_path );
317
+ } else {
318
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $abs_path );
319
+ }
320
+ }
321
+ }
322
+ }
323
+
324
+ /**
325
+ * Reset exported file
326
+ *
327
+ * @since 0.4.0
328
+ */
329
+ public function reset_export() {
330
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
331
+
332
+ $base_dir = WP_PLUGIN_DIR . '/sns-count-cache/data/';
333
+ $abs_path = $base_dir . $this->export_file_name;
334
+
335
+ if ( file_exists( $abs_path ) ) {
336
+ unlink( $abs_path );
337
+ }
338
+ }
339
+ }
340
+
341
+ ?>
includes/class-scc-common-job-reset-engine.php CHANGED
@@ -1,147 +1,147 @@
1
- <?php
2
- /*
3
- class-scc-common-job-reset-engine.php
4
-
5
- Description: This class is a job reset engine whitch reset expired jobs
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Common_Job_Reset_Engine extends SCC_Engine {
31
-
32
- /**
33
- * Cron name to schedule reset processing
34
- */
35
- const DEF_PRIME_CRON = 'scc_common_jobreset_prime';
36
-
37
- /**
38
- * Cron name to execute reset processing
39
- */
40
- const DEF_EXECUTE_CRON = 'scc_common_jobreset_exec';
41
-
42
- /**
43
- * Schedule name for reset processing
44
- */
45
- const DEF_EVENT_SCHEDULE = 'common_job_reset_event';
46
-
47
- /**
48
- * Schedule description for reset processing
49
- */
50
- const DEF_EVENT_DESCRIPTION = '[SCC] Common Job Reset Interval';
51
-
52
- /**
53
- * Interval cheking and caching target data
54
- */
55
- private $check_interval = 600;
56
-
57
- /**
58
- * Time expired
59
- */
60
- private $expiration_time = 1800;
61
-
62
- /**
63
- * Cache target
64
- */
65
- private $target_cron = array();
66
-
67
- /**
68
- * instance for delegation
69
- */
70
- private $delegate = NULL;
71
-
72
- /**
73
- * Initialization
74
- *
75
- * @since 0.1.1
76
- */
77
- public function initialize( $options = array() ) {
78
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
79
-
80
- $this->prime_cron = self::DEF_PRIME_CRON;
81
- $this->execute_cron = self::DEF_EXECUTE_CRON;
82
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
83
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
84
-
85
- if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
86
- if ( isset( $options['target_cron'] ) ) $this->target_cron = $options['target_cron'];
87
- if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
88
- if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
89
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
90
- if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
91
- if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
92
- if ( isset( $options['expiration_time'] ) ) $this->expiration_time = $options['expiration_time'];
93
-
94
- add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
95
- add_action( $this->prime_cron, array( $this, 'prime_reset' ) );
96
- add_action( $this->execute_cron, array( $this, 'execute_reset' ), 10, 0 );
97
- }
98
-
99
- /**
100
- * Register event schedule for this engine
101
- *
102
- * @since 0.1.0
103
- */
104
- public function schedule_check_interval( $schedules ) {
105
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
106
-
107
- $schedules[$this->event_schedule] = array(
108
- 'interval' => $this->check_interval,
109
- 'display' => $this->event_description
110
- );
111
-
112
- return $schedules;
113
- }
114
-
115
- /**
116
- * Schedule job reset processing
117
- *
118
- * @since 0.2.0
119
- */
120
- public function prime_reset() {
121
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
122
-
123
- $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
124
-
125
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
126
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
127
-
128
- wp_schedule_single_event( $next_exec_time, $this->execute_cron, array() );
129
- }
130
-
131
- /**
132
- * Reset expired jobs
133
- *
134
- * @since 0.2.0
135
- */
136
- public function execute_reset() {
137
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
138
-
139
- foreach ( $this->target_cron as $key => $hook ) {
140
- SCC_Common_Util::log( '[' . __METHOD__ . '] hook: ' . $hook );
141
- SCC_WP_Cron_Util::clear_expired_scheduled_hook( $hook, $this->expiration_time );
142
- }
143
- }
144
-
145
- }
146
-
147
- ?>
1
+ <?php
2
+ /*
3
+ class-scc-common-job-reset-engine.php
4
+
5
+ Description: This class is a job reset engine whitch reset expired jobs
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Common_Job_Reset_Engine extends SCC_Engine {
31
+
32
+ /**
33
+ * Cron name to schedule reset processing
34
+ */
35
+ const DEF_PRIME_CRON = 'scc_common_jobreset_prime';
36
+
37
+ /**
38
+ * Cron name to execute reset processing
39
+ */
40
+ const DEF_EXECUTE_CRON = 'scc_common_jobreset_exec';
41
+
42
+ /**
43
+ * Schedule name for reset processing
44
+ */
45
+ const DEF_EVENT_SCHEDULE = 'common_job_reset_event';
46
+
47
+ /**
48
+ * Schedule description for reset processing
49
+ */
50
+ const DEF_EVENT_DESCRIPTION = '[SCC] Common Job Reset Interval';
51
+
52
+ /**
53
+ * Interval cheking and caching target data
54
+ */
55
+ private $check_interval = 600;
56
+
57
+ /**
58
+ * Time expired
59
+ */
60
+ private $expiration_time = 1800;
61
+
62
+ /**
63
+ * Cache target
64
+ */
65
+ private $target_cron = array();
66
+
67
+ /**
68
+ * instance for delegation
69
+ */
70
+ private $delegate = NULL;
71
+
72
+ /**
73
+ * Initialization
74
+ *
75
+ * @since 0.1.1
76
+ */
77
+ public function initialize( $options = array() ) {
78
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
79
+
80
+ $this->prime_cron = self::DEF_PRIME_CRON;
81
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
82
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
83
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
84
+
85
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
86
+ if ( isset( $options['target_cron'] ) ) $this->target_cron = $options['target_cron'];
87
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
88
+ if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
89
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
90
+ if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
91
+ if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
92
+ if ( isset( $options['expiration_time'] ) ) $this->expiration_time = $options['expiration_time'];
93
+
94
+ add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
95
+ add_action( $this->prime_cron, array( $this, 'prime_reset' ) );
96
+ add_action( $this->execute_cron, array( $this, 'execute_reset' ), 10, 0 );
97
+ }
98
+
99
+ /**
100
+ * Register event schedule for this engine
101
+ *
102
+ * @since 0.1.0
103
+ */
104
+ public function schedule_check_interval( $schedules ) {
105
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
106
+
107
+ $schedules[$this->event_schedule] = array(
108
+ 'interval' => $this->check_interval,
109
+ 'display' => $this->event_description
110
+ );
111
+
112
+ return $schedules;
113
+ }
114
+
115
+ /**
116
+ * Schedule job reset processing
117
+ *
118
+ * @since 0.2.0
119
+ */
120
+ public function prime_reset() {
121
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
122
+
123
+ $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
124
+
125
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
126
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
127
+
128
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array() );
129
+ }
130
+
131
+ /**
132
+ * Reset expired jobs
133
+ *
134
+ * @since 0.2.0
135
+ */
136
+ public function execute_reset() {
137
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
138
+
139
+ foreach ( $this->target_cron as $key => $hook ) {
140
+ SCC_Common_Util::log( '[' . __METHOD__ . '] hook: ' . $hook );
141
+ SCC_WP_Cron_Util::clear_expired_scheduled_hook( $hook, $this->expiration_time );
142
+ }
143
+ }
144
+
145
+ }
146
+
147
+ ?>
includes/class-scc-common-util.php CHANGED
@@ -1,607 +1,663 @@
1
- <?php
2
- /*
3
- class-scc-common-util.php
4
-
5
- Description: This class is a common utility
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Common_Util {
31
-
32
- /**
33
- * Class constarctor
34
- * Hook onto all of the actions and filters needed by the plugin.
35
- *
36
- */
37
- protected function __construct() {
38
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
39
- }
40
-
41
- /**
42
- * Output log message according to WP_DEBUG setting
43
- *
44
- * @since 0.1.0
45
- */
46
- public static function log( $message ) {
47
- if ( WP_DEBUG === true ) {
48
- if ( is_array( $message ) || is_object( $message ) ) {
49
- error_log( print_r( $message, true ) );
50
- } else {
51
- error_log( $message );
52
- }
53
- }
54
- }
55
-
56
- /**
57
- * Get short hash code
58
- *
59
- * @since 0.2.0
60
- */
61
- public static function short_hash( $data, $algo = 'CRC32' ) {
62
- return strtr( rtrim( base64_encode( pack( 'H*', sprintf( '%u', $algo( $data ) ) ) ), '=' ), '+/', '-_' );
63
- }
64
-
65
- /**
66
- * Get file size of given file
67
- *
68
- * @since 0.4.0
69
- */
70
- public static function get_file_size( $file ) {
71
-
72
- if ( file_exists( $file ) && is_file( $file ) ) {
73
- $filesize = filesize( $file );
74
- $s = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB' );
75
- $e = floor( log( $filesize ) / log( 1024 ) );
76
-
77
- if( $e == 0 || $e == 1 ) {
78
- $format = '%d ';
79
- } else {
80
- $format = '%.1f ';
81
- }
82
-
83
- $filesize = sprintf( $format . $s[$e], ( $filesize / pow( 1024, floor( $e ) ) ) );
84
-
85
- return $filesize;
86
- } else {
87
- return null;
88
- }
89
- }
90
-
91
- /**
92
- * Get custom post types
93
- *
94
- * @since 0.4.0
95
- */
96
- public static function get_custom_post_types() {
97
-
98
- global $wpdb;
99
-
100
- $custom_post_types = array();
101
-
102
- $builtin_post_types = get_post_types( array( '_builtin' => true ) );
103
-
104
- $exclude_post_types = "'";
105
- $exclude_post_types .= implode( "','", $builtin_post_types );
106
- $exclude_post_types .= "'";
107
-
108
- $sql = 'SELECT DISTINCT post_type FROM ' . $wpdb->posts . ' WHERE post_type NOT IN ( ' . $exclude_post_types . ' )';
109
-
110
- $results = $wpdb->get_results( $sql );
111
-
112
- foreach ( $results as $value ) {
113
- $custom_post_types[] = $value->post_type;
114
- }
115
-
116
- return $custom_post_types;
117
- }
118
-
119
- /**
120
- * check if php-xml module is loaded or not
121
- *
122
- * @since 0.4.0
123
- */
124
- public static function extension_loaded_php_xml() {
125
- if ( extension_loaded( 'xml' ) && extension_loaded( 'xmlreader' ) && extension_loaded( 'xmlwriter' ) ) {
126
- return true;
127
- } else {
128
- return false;
129
- }
130
- }
131
-
132
- /**
133
- * convert url based on http into url based on https
134
- *
135
- * @since 0.4.0
136
- */
137
- public static function get_secure_url( $url ){
138
- $url = str_replace( 'http://', 'https://', $url );
139
- return $url;
140
- }
141
-
142
- /**
143
- * convert url based on https into url based on http
144
- *
145
- * @since 0.4.0
146
- */
147
- public static function get_normal_url( $url ){
148
- $url = str_replace( 'https://', 'http://', $url );
149
- return $url;
150
- }
151
-
152
- /**
153
- * check if a given url is based on https or not.
154
- *
155
- * @since 0.4.0
156
- */
157
- public static function is_secure_url( $url ){
158
- if ( preg_match( '/^(https)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $url ) ) {
159
- return true;
160
- } else {
161
- return false;
162
- }
163
- }
164
-
165
- /**
166
- * check if a given url is based on http or not.
167
- *
168
- * @since 0.4.0
169
- */
170
- public static function is_normal_url( $url ){
171
- if ( preg_match( '/^(http)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $url ) ) {
172
- return true;
173
- } else {
174
- return false;
175
- }
176
- }
177
-
178
- /**
179
- * get cout data from SNS
180
- *
181
- * @since 0.5.1
182
- */
183
- public static function multi_remote_get( $urls, $headers, $timeout = 0, $sslverify = true, $curl = false ) {
184
- global $wp_version;
185
-
186
- $responses = array();
187
-
188
- if ( empty( $urls ) ) {
189
- return $responses;
190
- }
191
-
192
- if ( $curl ) {
193
- SCC_Common_Util::log( '[' . __METHOD__ . '] cURL: On' );
194
-
195
- $mh = curl_multi_init();
196
- $ch = array();
197
-
198
- foreach ( $urls as $sns => $url ) {
199
- $ch[$sns] = curl_init();
200
-
201
- curl_setopt( $ch[$sns], CURLOPT_URL, $url );
202
- curl_setopt( $ch[$sns], CURLOPT_USERAGENT, 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
203
- curl_setopt( $ch[$sns], CURLOPT_FOLLOWLOCATION, true );
204
- curl_setopt( $ch[$sns], CURLOPT_RETURNTRANSFER, true );
205
- curl_setopt( $ch[$sns], CURLOPT_ENCODING, 'gzip' );
206
-
207
- if ( ! empty( $headers[$sns] ) ) {
208
- //curl_setopt( $ch[$sns], CURLOPT_HEADER, true );
209
-
210
- $http_headers = array();
211
-
212
- foreach ( $headers[$sns] as $key => $value ) {
213
- $http_headers[] = $key . ': ' . $value;
214
- }
215
-
216
- curl_setopt( $ch[$sns], CURLOPT_HTTPHEADER, $http_headers );
217
- }
218
-
219
- if ( $sslverify ) {
220
- curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYPEER, true );
221
- curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYHOST, 2 );
222
- } else {
223
- curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYPEER, false );
224
- curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYHOST, 0 );
225
- }
226
-
227
- if ( $timeout > 0 ) {
228
- curl_setopt( $ch[$sns], CURLOPT_CONNECTTIMEOUT, $timeout );
229
- curl_setopt( $ch[$sns], CURLOPT_TIMEOUT, $timeout );
230
- }
231
-
232
- curl_multi_add_handle( $mh, $ch[$sns] );
233
- }
234
-
235
- $active = null;
236
-
237
- do {
238
- curl_multi_exec( $mh, $active );
239
- curl_multi_select( $mh );
240
- } while ( $active > 0 );
241
-
242
- foreach ( $urls as $sns => $url ) {
243
- $responses[$sns]['error'] = curl_error( $ch[$sns] );
244
-
245
- if ( ! empty( $responses[$sns]['error'] ) ) {
246
- $responses[$sns]['data'] = '';
247
- } else {
248
- $responses[$sns]['data'] = curl_multi_getcontent( $ch[$sns] );
249
- }
250
-
251
- curl_multi_remove_handle( $mh, $ch[$sns] );
252
- curl_close( $ch[$sns] );
253
- }
254
-
255
- curl_multi_close( $mh );
256
-
257
- return $responses;
258
- } else {
259
-
260
- SCC_Common_Util::log( '[' . __METHOD__ . '] cURL: Off' );
261
-
262
- foreach ( $urls as $sns => $url ) {
263
-
264
- $options = array(
265
- 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
266
- );
267
-
268
- if ( $sslverify ) {
269
- $options['sslverify'] = true;
270
- } else {
271
- $options['sslverify'] = false;
272
- }
273
-
274
- if ( $timeout > 0 ) {
275
- $options['timeout'] = $timeout;
276
- }
277
-
278
- if ( ! empty( $headers[$sns] ) ) {
279
- $options['headers'] = $headers[$sns];
280
- }
281
-
282
- $response = wp_remote_get( $url, $options );
283
-
284
- if ( ! is_wp_error( $response ) ) {
285
- if ( $response['response']['code'] === 200 ) {
286
- $responses[$sns]['data'] = $response['body'];
287
- } else {
288
- $responses[$sns]['data'] = '';
289
- $responses[$sns]['error'] = $response['response']['code'] . ': ' . $response['response']['message'];
290
- }
291
- } else {
292
- $responses[$sns]['data'] = '';
293
- $responses[$sns]['error'] = $response->get_error_message();
294
- }
295
- }
296
-
297
- return $responses;
298
- }
299
- }
300
-
301
- public static function serialize_base64_encode( $array ) {
302
- $data = serialize( $array );
303
- $data = base64_encode( $data );
304
-
305
- return $data;
306
- }
307
-
308
- public static function unserialize_base64_decode( $data ) {
309
- $data = base64_decode( $data );
310
- $array = unserialize( $data );
311
-
312
- return $array;
313
- }
314
-
315
- /**
316
- * encrypt given data
317
- *
318
- * @since 0.9.0
319
- */
320
- public static function encrypt_data( $input, $key = 'KEY_DEFAULT' ) {
321
-
322
- if ( extension_loaded( 'mcrypt' ) ) {
323
- self::log( 'mcrypt loaded' );
324
-
325
- $key = md5( $key );
326
-
327
- $td = mcrypt_module_open( 'blowfish', '', 'ecb', '');
328
- $key = substr( $key, 0, mcrypt_enc_get_key_size( $td ) );
329
- $iv = mcrypt_create_iv( mcrypt_enc_get_iv_size( $td ), MCRYPT_RAND );
330
-
331
- if ( mcrypt_generic_init( $td, $key, $iv ) < 0 ) {
332
- exit( 'error.' );
333
- }
334
-
335
- $encrypted_data = base64_encode( mcrypt_generic( $td, $input ) );
336
-
337
- mcrypt_generic_deinit( $td );
338
- mcrypt_module_close( $td );
339
-
340
- return $encrypted_data;
341
- } else {
342
- self::log( 'mcrypt not loaded' );
343
- $crypt = new Crypt_Blowfish( $key );
344
- return $crypt->encrypt( $input );
345
- }
346
- }
347
-
348
- /**
349
- * decrypt given data
350
- *
351
- * @since 0.9.0
352
- */
353
- public static function decrypt_data( $input, $key = 'KEY_DEFAULT' ) {
354
-
355
- if ( extension_loaded( 'mcrypt' ) ) {
356
- self::log( 'mcrypt loaded' );
357
-
358
- $key = md5( $key );
359
-
360
- $td = mcrypt_module_open( 'blowfish', '', 'ecb', '' );
361
- $key = substr( $key, 0, mcrypt_enc_get_key_size( $td ) );
362
- $iv = mcrypt_create_iv( mcrypt_enc_get_iv_size( $td ), MCRYPT_RAND );
363
-
364
- if ( mcrypt_generic_init( $td, $key, $iv ) < 0 ) {
365
- exit( 'error.' );
366
- }
367
-
368
- $data = mdecrypt_generic( $td, base64_decode( $input ) );
369
-
370
- mcrypt_generic_deinit( $td );
371
- mcrypt_module_close( $td );
372
-
373
- return $data;
374
- } else {
375
- self::log( 'mcrypt not loaded' );
376
- $crypt = new Crypt_Blowfish( $key );
377
- return $crypt->decrypt( $input );
378
- }
379
- }
380
-
381
- /**
382
- * Get bearer token for Twitter
383
- *
384
- * @since 0.9.0
385
- */
386
- public static function get_twitter_bearer_token( $cosumer_key, $consumer_secret, $sslverify = true, $timeout = 10 ) {
387
- global $wp_version;
388
-
389
- $bearer_token = '';
390
- $url = 'https://api.twitter.com/oauth2/token';
391
-
392
- $credential = base64_encode( $cosumer_key . ':' . $consumer_secret );
393
-
394
- $options = array(
395
- 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
396
- );
397
-
398
- if ( $sslverify ) {
399
- $options['sslverify'] = true;
400
- } else {
401
- $options['sslverify'] = false;
402
- }
403
-
404
- if ( $timeout > 0 ) {
405
- $options['timeout'] = $timeout;
406
- }
407
-
408
- $headers = array(
409
- 'Authorization' => 'Basic ' . $credential,
410
- 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8'
411
- );
412
-
413
- if ( ! empty( $headers ) ) {
414
- $options['headers'] = $headers;
415
- }
416
-
417
- $body = array(
418
- 'grant_type' => 'client_credentials'
419
- );
420
-
421
- if ( ! empty( $body ) ) {
422
- $options['body'] = $body;
423
- }
424
-
425
- $response = wp_remote_post( $url, $options );
426
-
427
- //self::log( $response );
428
-
429
- if ( ! is_wp_error( $response ) ) {
430
- if ( $response['response']['code'] === 200 ) {
431
- $json = $response['body'];
432
- $content = json_decode( $json, true ) ;
433
- if ( isset( $content['token_type'] ) && $content['token_type'] && $content['token_type'] === 'bearer' ) {
434
- if ( isset( $content['access_token'] ) && $content['access_token'] ) {
435
- $bearer_token = $content['access_token'];
436
- }
437
- }
438
- }
439
- }
440
-
441
- return $bearer_token;
442
- }
443
-
444
- /**
445
- * Get acess token for Instagram
446
- *
447
- * @since 0.9.0
448
- */
449
- public static function get_instagram_access_token( $client_id, $client_secret, $redirect_uri, $code, $sslverify = true, $timeout = 10 ) {
450
- global $wp_version;
451
-
452
- $access_token = '';
453
- $url = 'https://api.instagram.com/oauth/access_token';
454
-
455
- $options = array(
456
- 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
457
- );
458
-
459
- if ( $sslverify ) {
460
- $options['sslverify'] = true;
461
- } else {
462
- $options['sslverify'] = false;
463
- }
464
-
465
- if ( $timeout > 0 ) {
466
- $options['timeout'] = $timeout;
467
- }
468
-
469
- $body = array(
470
- 'client_id' => $client_id,
471
- 'client_secret' => $client_secret,
472
- 'grant_type' => 'authorization_code',
473
- 'redirect_uri' => $redirect_uri,
474
- 'code' => $code
475
- );
476
-
477
- if ( ! empty( $body ) ) {
478
- $options['body'] = $body;
479
- }
480
-
481
- $response = wp_remote_post( $url, $options );
482
-
483
- //self::log( $response );
484
-
485
- if ( ! is_wp_error( $response ) ) {
486
- if ( $response['response']['code'] === 200 ) {
487
- $json = $response['body'];
488
- $content = json_decode( $json, true ) ;
489
- if ( isset( $content['access_token'] ) && $content['access_token'] ) {
490
- $access_token = $content['access_token'];
491
- }
492
- }
493
- }
494
-
495
- return $access_token;
496
- }
497
-
498
- /**
499
- * Get acess token for Facebook
500
- *
501
- * @since 0.9.0
502
- */
503
- public static function get_facebook_access_token( $app_id, $app_secret, $redirect_uri, $code, $sslverify = true, $timeout = 10 ) {
504
- global $wp_version;
505
-
506
- $original_access_token = '';
507
- $extended_access_token = '';
508
- $access_token = '';
509
-
510
- $url = 'https://graph.facebook.com/oauth/access_token';
511
-
512
- $options = array(
513
- 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
514
- );
515
-
516
- if ( $sslverify ) {
517
- $options['sslverify'] = true;
518
- } else {
519
- $options['sslverify'] = false;
520
- }
521
-
522
- if ( $timeout > 0 ) {
523
- $options['timeout'] = $timeout;
524
- }
525
-
526
- $query_parameters = array(
527
- 'client_id' => $app_id,
528
- 'client_secret' => $app_secret,
529
- 'redirect_uri' => $redirect_uri,
530
- 'code' => $code
531
- );
532
-
533
- $request_url = $url . '?' . http_build_query( $query_parameters , '' , '&' );
534
-
535
- $response = wp_remote_get( $request_url, $options );
536
-
537
- //self::log( $response );
538
-
539
- if ( ! is_wp_error( $response ) ) {
540
- if ( $response['response']['code'] === 200 ) {
541
- $json = $response['body'];
542
- $content = json_decode( $json, true ) ;
543
- if ( isset( $content['access_token'] ) && $content['access_token'] ) {
544
- $original_access_token = $content['access_token'];
545
- }
546
- }
547
- }
548
-
549
- if ( isset( $original_access_token ) && $original_access_token ) {
550
- $url = 'https://graph.facebook.com/oauth/access_token';
551
-
552
- $query_parameters = array(
553
- 'client_id' => $app_id,
554
- 'client_secret' => $app_secret,
555
- 'grant_type' => 'fb_exchange_token',
556
- 'fb_exchange_token' => $original_access_token
557
- );
558
-
559
- $request_url = $url . '?' . http_build_query( $query_parameters , '' , '&' );
560
-
561
- $response = wp_remote_get( $request_url, $options );
562
-
563
- //self::log( $response );
564
-
565
- $data = array();
566
-
567
- if ( ! is_wp_error( $response ) ) {
568
- if ( $response['response']['code'] === 200 ) {
569
- parse_str( $response['body'], $data );
570
- if ( isset( $data['access_token'] ) && $data['access_token'] ) {
571
- $extended_access_token = $data['access_token'];
572
- }
573
- }
574
- }
575
- }
576
-
577
- if ( isset( $extended_access_token ) && $extended_access_token ) {
578
- $url = 'https://graph.facebook.com/me/accounts';
579
-
580
- $query_parameters = array(
581
- 'access_token' => $extended_access_token
582
- );
583
-
584
- $request_url = $url . '?' . http_build_query( $query_parameters , '' , '&' );
585
-
586
- $response = wp_remote_get( $request_url, $options );
587
-
588
- //self::log( $response );
589
-
590
- if ( ! is_wp_error( $response ) ) {
591
- if ( $response['response']['code'] === 200 ) {
592
- $json = $response['body'];
593
- $content = json_decode( $json, true ) ;
594
-
595
- if ( isset( $content['data'][0]['access_token'] ) && $content['data'][0]['access_token'] ) {
596
- $access_token = $content['data'][0]['access_token'];
597
- }
598
- }
599
- }
600
- }
601
-
602
- return $access_token;
603
- }
604
-
605
- }
606
-
607
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-common-util.php
4
+
5
+ Description: This class is a common utility
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Common_Util {
31
+
32
+ /**
33
+ * Class constarctor
34
+ * Hook onto all of the actions and filters needed by the plugin.
35
+ *
36
+ */
37
+ protected function __construct() {
38
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
39
+ }
40
+
41
+ /**
42
+ * Output log message according to WP_DEBUG setting
43
+ *
44
+ * @since 0.1.0
45
+ */
46
+ public static function log( $message ) {
47
+ if ( WP_DEBUG === true ) {
48
+ if ( is_array( $message ) || is_object( $message ) ) {
49
+ error_log( print_r( $message, true ) );
50
+ } else {
51
+ error_log( $message );
52
+ }
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Get short hash code
58
+ *
59
+ * @since 0.2.0
60
+ */
61
+ public static function short_hash( $data, $algo = 'CRC32' ) {
62
+ return strtr( rtrim( base64_encode( pack( 'H*', sprintf( '%u', $algo( $data ) ) ) ), '=' ), '+/', '-_' );
63
+ }
64
+
65
+ /**
66
+ * Get file size of given file
67
+ *
68
+ * @since 0.4.0
69
+ */
70
+ public static function get_file_size( $file ) {
71
+
72
+ if ( file_exists( $file ) && is_file( $file ) ) {
73
+ $filesize = filesize( $file );
74
+ $s = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB' );
75
+ $e = floor( log( $filesize ) / log( 1024 ) );
76
+
77
+ if( $e == 0 || $e == 1 ) {
78
+ $format = '%d ';
79
+ } else {
80
+ $format = '%.1f ';
81
+ }
82
+
83
+ $filesize = sprintf( $format . $s[$e], ( $filesize / pow( 1024, floor( $e ) ) ) );
84
+
85
+ return $filesize;
86
+ } else {
87
+ return null;
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Get custom post types
93
+ *
94
+ * @since 0.4.0
95
+ */
96
+ public static function get_custom_post_types() {
97
+
98
+ global $wpdb;
99
+
100
+ $custom_post_types = array();
101
+
102
+ $builtin_post_types = get_post_types( array( '_builtin' => true ) );
103
+
104
+ $exclude_post_types = "'";
105
+ $exclude_post_types .= implode( "','", $builtin_post_types );
106
+ $exclude_post_types .= "'";
107
+
108
+ $sql = 'SELECT DISTINCT post_type FROM ' . $wpdb->posts . ' WHERE post_type NOT IN ( ' . $exclude_post_types . ' )';
109
+
110
+ $results = $wpdb->get_results( $sql );
111
+
112
+ foreach ( $results as $value ) {
113
+ $custom_post_types[] = $value->post_type;
114
+ }
115
+
116
+ return $custom_post_types;
117
+ }
118
+
119
+ /**
120
+ * check if php-xml module is loaded or not
121
+ *
122
+ * @since 0.4.0
123
+ */
124
+ public static function extension_loaded_php_xml() {
125
+ if ( extension_loaded( 'xml' ) && extension_loaded( 'xmlreader' ) && extension_loaded( 'xmlwriter' ) ) {
126
+ return true;
127
+ } else {
128
+ return false;
129
+ }
130
+ }
131
+
132
+ /**
133
+ * convert url based on http into url based on https
134
+ *
135
+ * @since 0.4.0
136
+ */
137
+ public static function get_secure_url( $url ){
138
+ $url = str_replace( 'http://', 'https://', $url );
139
+ return $url;
140
+ }
141
+
142
+ /**
143
+ * convert url based on https into url based on http
144
+ *
145
+ * @since 0.4.0
146
+ */
147
+ public static function get_normal_url( $url ){
148
+ $url = str_replace( 'https://', 'http://', $url );
149
+ return $url;
150
+ }
151
+
152
+ /**
153
+ * check if a given url is based on https or not.
154
+ *
155
+ * @since 0.4.0
156
+ */
157
+ public static function is_secure_url( $url ){
158
+ if ( preg_match( '/^(https)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $url ) ) {
159
+ return true;
160
+ } else {
161
+ return false;
162
+ }
163
+ }
164
+
165
+ /**
166
+ * check if a given url is based on http or not.
167
+ *
168
+ * @since 0.4.0
169
+ */
170
+ public static function is_normal_url( $url ){
171
+ if ( preg_match( '/^(http)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $url ) ) {
172
+ return true;
173
+ } else {
174
+ return false;
175
+ }
176
+ }
177
+
178
+ /**
179
+ * get cout data from SNS
180
+ *
181
+ * @since 0.5.1
182
+ */
183
+ public static function multi_remote_get( $urls, $headers, $timeout = 0, $sslverify = true, $curl = false ) {
184
+ global $wp_version;
185
+
186
+ $responses = array();
187
+
188
+ if ( empty( $urls ) ) {
189
+ return $responses;
190
+ }
191
+
192
+ if ( $curl ) {
193
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cURL: On' );
194
+
195
+ $mh = curl_multi_init();
196
+ $ch = array();
197
+
198
+ foreach ( $urls as $sns => $url ) {
199
+ $ch[$sns] = curl_init();
200
+
201
+ curl_setopt( $ch[$sns], CURLOPT_URL, $url );
202
+ curl_setopt( $ch[$sns], CURLOPT_USERAGENT, 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
203
+ curl_setopt( $ch[$sns], CURLOPT_FOLLOWLOCATION, true );
204
+ curl_setopt( $ch[$sns], CURLOPT_RETURNTRANSFER, true );
205
+ curl_setopt( $ch[$sns], CURLOPT_ENCODING, 'gzip' );
206
+
207
+ if ( ! empty( $headers[$sns] ) ) {
208
+ //curl_setopt( $ch[$sns], CURLOPT_HEADER, true );
209
+
210
+ $http_headers = array();
211
+
212
+ foreach ( $headers[$sns] as $key => $value ) {
213
+ $http_headers[] = $key . ': ' . $value;
214
+ }
215
+
216
+ curl_setopt( $ch[$sns], CURLOPT_HTTPHEADER, $http_headers );
217
+ }
218
+
219
+ if ( $sslverify ) {
220
+ curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYPEER, true );
221
+ curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYHOST, 2 );
222
+ } else {
223
+ curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYPEER, false );
224
+ curl_setopt( $ch[$sns], CURLOPT_SSL_VERIFYHOST, 0 );
225
+ }
226
+
227
+ if ( $timeout > 0 ) {
228
+ curl_setopt( $ch[$sns], CURLOPT_CONNECTTIMEOUT, $timeout );
229
+ curl_setopt( $ch[$sns], CURLOPT_TIMEOUT, $timeout );
230
+ }
231
+
232
+ curl_multi_add_handle( $mh, $ch[$sns] );
233
+ }
234
+
235
+ $active = null;
236
+
237
+ do {
238
+ curl_multi_exec( $mh, $active );
239
+ curl_multi_select( $mh );
240
+ } while ( $active > 0 );
241
+
242
+ foreach ( $urls as $sns => $url ) {
243
+ $responses[$sns]['error'] = curl_error( $ch[$sns] );
244
+
245
+ if ( ! empty( $responses[$sns]['error'] ) ) {
246
+ $responses[$sns]['data'] = '';
247
+ } else {
248
+ $responses[$sns]['data'] = curl_multi_getcontent( $ch[$sns] );
249
+ }
250
+
251
+ curl_multi_remove_handle( $mh, $ch[$sns] );
252
+ curl_close( $ch[$sns] );
253
+ }
254
+
255
+ curl_multi_close( $mh );
256
+
257
+ return $responses;
258
+ } else {
259
+
260
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cURL: Off' );
261
+
262
+ foreach ( $urls as $sns => $url ) {
263
+
264
+ $options = array(
265
+ 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
266
+ );
267
+
268
+ if ( $sslverify ) {
269
+ $options['sslverify'] = true;
270
+ } else {
271
+ $options['sslverify'] = false;
272
+ }
273
+
274
+ if ( $timeout > 0 ) {
275
+ $options['timeout'] = $timeout;
276
+ }
277
+
278
+ if ( ! empty( $headers[$sns] ) ) {
279
+ $options['headers'] = $headers[$sns];
280
+ }
281
+
282
+ $response = wp_remote_get( $url, $options );
283
+
284
+ if ( ! is_wp_error( $response ) ) {
285
+ if ( $response['response']['code'] === 200 ) {
286
+ $responses[$sns]['data'] = $response['body'];
287
+ } else {
288
+ $responses[$sns]['data'] = '';
289
+ $responses[$sns]['error'] = $response['response']['code'] . ': ' . $response['response']['message'];
290
+ }
291
+ } else {
292
+ $responses[$sns]['data'] = '';
293
+ $responses[$sns]['error'] = $response->get_error_message();
294
+ }
295
+ }
296
+
297
+ return $responses;
298
+ }
299
+ }
300
+
301
+ public static function serialize_base64_encode( $array ) {
302
+ $data = serialize( $array );
303
+ $data = base64_encode( $data );
304
+
305
+ return $data;
306
+ }
307
+
308
+ public static function unserialize_base64_decode( $data ) {
309
+ $data = base64_decode( $data );
310
+ $array = unserialize( $data );
311
+
312
+ return $array;
313
+ }
314
+
315
+ /**
316
+ * encrypt given data
317
+ *
318
+ * @since 0.9.0
319
+ */
320
+ public static function encrypt_data( $input, $key = 'KEY_DEFAULT' ) {
321
+
322
+ if ( extension_loaded( 'mcrypt' ) ) {
323
+ self::log( 'mcrypt loaded' );
324
+
325
+ $key = md5( $key );
326
+
327
+ $td = mcrypt_module_open( 'blowfish', '', 'ecb', '');
328
+ $key = substr( $key, 0, mcrypt_enc_get_key_size( $td ) );
329
+ $iv = mcrypt_create_iv( mcrypt_enc_get_iv_size( $td ), MCRYPT_RAND );
330
+
331
+ if ( mcrypt_generic_init( $td, $key, $iv ) < 0 ) {
332
+ exit( 'error.' );
333
+ }
334
+
335
+ $encrypted_data = base64_encode( mcrypt_generic( $td, $input ) );
336
+
337
+ mcrypt_generic_deinit( $td );
338
+ mcrypt_module_close( $td );
339
+
340
+ return $encrypted_data;
341
+ } else {
342
+ self::log( 'mcrypt not loaded' );
343
+ $crypt = new Crypt_Blowfish( $key );
344
+ return $crypt->encrypt( $input );
345
+ }
346
+ }
347
+
348
+ /**
349
+ * decrypt given data
350
+ *
351
+ * @since 0.9.0
352
+ */
353
+ public static function decrypt_data( $input, $key = 'KEY_DEFAULT' ) {
354
+
355
+ if ( extension_loaded( 'mcrypt' ) ) {
356
+ self::log( 'mcrypt loaded' );
357
+
358
+ $key = md5( $key );
359
+
360
+ $td = mcrypt_module_open( 'blowfish', '', 'ecb', '' );
361
+ $key = substr( $key, 0, mcrypt_enc_get_key_size( $td ) );
362
+ $iv = mcrypt_create_iv( mcrypt_enc_get_iv_size( $td ), MCRYPT_RAND );
363
+
364
+ if ( mcrypt_generic_init( $td, $key, $iv ) < 0 ) {
365
+ exit( 'error.' );
366
+ }
367
+
368
+ $data = mdecrypt_generic( $td, base64_decode( $input ) );
369
+
370
+ mcrypt_generic_deinit( $td );
371
+ mcrypt_module_close( $td );
372
+
373
+ return $data;
374
+ } else {
375
+ self::log( 'mcrypt not loaded' );
376
+ $crypt = new Crypt_Blowfish( $key );
377
+ return $crypt->decrypt( $input );
378
+ }
379
+ }
380
+
381
+ /**
382
+ * Get bearer token for Twitter
383
+ *
384
+ * @since 0.9.0
385
+ */
386
+ public static function get_twitter_bearer_token( $cosumer_key, $consumer_secret, $sslverify = true, $timeout = 10 ) {
387
+ global $wp_version;
388
+
389
+ $bearer_token = '';
390
+ $url = 'https://api.twitter.com/oauth2/token';
391
+
392
+ $credential = base64_encode( $cosumer_key . ':' . $consumer_secret );
393
+
394
+ $options = array(
395
+ 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
396
+ );
397
+
398
+ if ( $sslverify ) {
399
+ $options['sslverify'] = true;
400
+ } else {
401
+ $options['sslverify'] = false;
402
+ }
403
+
404
+ if ( $timeout > 0 ) {
405
+ $options['timeout'] = $timeout;
406
+ }
407
+
408
+ $headers = array(
409
+ 'Authorization' => 'Basic ' . $credential,
410
+ 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8'
411
+ );
412
+
413
+ if ( ! empty( $headers ) ) {
414
+ $options['headers'] = $headers;
415
+ }
416
+
417
+ $body = array(
418
+ 'grant_type' => 'client_credentials'
419
+ );
420
+
421
+ if ( ! empty( $body ) ) {
422
+ $options['body'] = $body;
423
+ }
424
+
425
+ $response = wp_remote_post( $url, $options );
426
+
427
+ //self::log( $response );
428
+
429
+ if ( ! is_wp_error( $response ) ) {
430
+ if ( $response['response']['code'] === 200 ) {
431
+ $json = $response['body'];
432
+ $content = json_decode( $json, true ) ;
433
+ if ( isset( $content['token_type'] ) && $content['token_type'] && $content['token_type'] === 'bearer' ) {
434
+ if ( isset( $content['access_token'] ) && $content['access_token'] ) {
435
+ $bearer_token = $content['access_token'];
436
+ }
437
+ }
438
+ } else {
439
+ return new WP_Error( 'invalid_response_code', '[ERROR] Invalid response code: ' . $response['response']['code'] . ' ' . $response['response']['message'] );
440
+ }
441
+ } else {
442
+ return $response;
443
+ }
444
+
445
+ return $bearer_token;
446
+ }
447
+
448
+ /**
449
+ * Get acess token for Instagram
450
+ *
451
+ * @since 0.9.0
452
+ */
453
+ public static function get_instagram_access_token( $client_id, $client_secret, $redirect_uri, $code, $sslverify = true, $timeout = 10 ) {
454
+ global $wp_version;
455
+
456
+ $access_token = '';
457
+ $url = 'https://api.instagram.com/oauth/access_token';
458
+
459
+ $options = array(
460
+ 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
461
+ );
462
+
463
+ if ( $sslverify ) {
464
+ $options['sslverify'] = true;
465
+ } else {
466
+ $options['sslverify'] = false;
467
+ }
468
+
469
+ if ( $timeout > 0 ) {
470
+ $options['timeout'] = $timeout;
471
+ }
472
+
473
+ $body = array(
474
+ 'client_id' => $client_id,
475
+ 'client_secret' => $client_secret,
476
+ 'grant_type' => 'authorization_code',
477
+ 'redirect_uri' => $redirect_uri,
478
+ 'code' => $code
479
+ );
480
+
481
+ if ( ! empty( $body ) ) {
482
+ $options['body'] = $body;
483
+ }
484
+
485
+ $response = wp_remote_post( $url, $options );
486
+
487
+ //self::log( $response );
488
+
489
+ if ( ! is_wp_error( $response ) ) {
490
+ if ( $response['response']['code'] === 200 ) {
491
+ $json = $response['body'];
492
+ $content = json_decode( $json, true ) ;
493
+ if ( isset( $content['access_token'] ) && $content['access_token'] ) {
494
+ $access_token = $content['access_token'];
495
+ }
496
+ } else {
497
+ return new WP_Error( 'invalid_response_code', '[ERROR] Invalid response code: ' . $response['response']['code'] . ' ' . $response['response']['message'] );
498
+ }
499
+ } else {
500
+ return $response;
501
+ }
502
+
503
+ return $access_token;
504
+ }
505
+
506
+ /**
507
+ * Get acess token for Facebook
508
+ *
509
+ * @since 0.9.0
510
+ */
511
+ public static function get_facebook_access_token( $app_id, $app_secret, $redirect_uri, $code, $page_id, $sslverify = true, $timeout = 10 ) {
512
+ global $wp_version;
513
+
514
+ $original_access_token = '';
515
+ $extended_access_token = '';
516
+ $access_token = '';
517
+
518
+ $url = 'https://graph.facebook.com/oauth/access_token';
519
+
520
+ $options = array(
521
+ 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
522
+ );
523
+
524
+ if ( $sslverify ) {
525
+ $options['sslverify'] = true;
526
+ } else {
527
+ $options['sslverify'] = false;
528
+ }
529
+
530
+ if ( $timeout > 0 ) {
531
+ $options['timeout'] = $timeout;
532
+ }
533
+
534
+ $query_parameters = array(
535
+ 'client_id' => $app_id,
536
+ 'client_secret' => $app_secret,
537
+ 'redirect_uri' => $redirect_uri,
538
+ 'code' => $code
539
+ );
540
+
541
+ $request_url = $url . '?' . http_build_query( $query_parameters , '' , '&' );
542
+
543
+ $response = wp_remote_get( $request_url, $options );
544
+
545
+ //self::log( $response );
546
+
547
+ if ( ! is_wp_error( $response ) ) {
548
+ if ( $response['response']['code'] === 200 ) {
549
+ $json = $response['body'];
550
+
551
+ parse_str( $response['body'], $data );
552
+ if ( isset( $data['access_token'] ) && $data['access_token'] ) {
553
+ $original_access_token = $data['access_token'];
554
+ }
555
+ } else {
556
+ return new WP_Error( 'invalid_response_code', '[ERROR] Invalid response code: ' . $response['response']['code'] . ' ' . $response['response']['message'] );
557
+ }
558
+ } else {
559
+ return $response;
560
+ }
561
+
562
+ if ( isset( $original_access_token ) && $original_access_token ) {
563
+ $url = 'https://graph.facebook.com/oauth/access_token';
564
+
565
+ $query_parameters = array(
566
+ 'client_id' => $app_id,
567
+ 'client_secret' => $app_secret,
568
+ 'grant_type' => 'fb_exchange_token',
569
+ 'fb_exchange_token' => $original_access_token
570
+ );
571
+
572
+ $request_url = $url . '?' . http_build_query( $query_parameters , '' , '&' );
573
+
574
+ $response = wp_remote_get( $request_url, $options );
575
+
576
+ //self::log( $response );
577
+
578
+ $data = array();
579
+
580
+ if ( ! is_wp_error( $response ) ) {
581
+ if ( $response['response']['code'] === 200 ) {
582
+ parse_str( $response['body'], $data );
583
+ if ( isset( $data['access_token'] ) && $data['access_token'] ) {
584
+ $extended_access_token = $data['access_token'];
585
+ }
586
+ } else {
587
+ return new WP_Error( 'invalid_response_code', '[ERROR] Invalid response code: ' . $response['response']['code'] . ' ' . $response['response']['message'] );
588
+ }
589
+ } else {
590
+ return $response;
591
+ }
592
+ }
593
+
594
+ if ( isset( $extended_access_token ) && $extended_access_token ) {
595
+ $url = 'https://graph.facebook.com/me/accounts';
596
+
597
+ $query_parameters = array(
598
+ 'access_token' => $extended_access_token
599
+ );
600
+
601
+ $request_url = $url . '?' . http_build_query( $query_parameters , '' , '&' );
602
+
603
+ $response = wp_remote_get( $request_url, $options );
604
+
605
+ //self::log( $response );
606
+
607
+ if ( ! is_wp_error( $response ) ) {
608
+ if ( $response['response']['code'] === 200 ) {
609
+ $json = $response['body'];
610
+ $content = json_decode( $json, true ) ;
611
+
612
+ $i = 0;
613
+
614
+ while( true ) {
615
+ if ( ! isset( $content['data'][$i] ) ) {
616
+ break;
617
+ }
618
+
619
+ if ( isset( $content['data'][$i]['id'] ) && $content['data'][$i]['id'] === $page_id ) {
620
+ if ( isset( $content['data'][$i]['access_token'] ) && $content['data'][$i]['access_token'] ) {
621
+ $access_token = $content['data'][$i]['access_token'];
622
+ }
623
+ break;
624
+ }
625
+
626
+ ++$i;
627
+ }
628
+ } else {
629
+ return new WP_Error( 'invalid_response_code', '[ERROR] Invalid response code: ' . $response['response']['code'] . ' ' . $response['response']['message'] );
630
+ }
631
+ } else {
632
+ return $response;
633
+ }
634
+ }
635
+
636
+ return $access_token;
637
+ }
638
+
639
+ public static function sanitize( $str ) {
640
+ $filtered = wp_check_invalid_utf8( $str );
641
+
642
+ if ( strpos( $filtered, '<' ) !== false ) {
643
+ $filtered = wp_pre_kses_less_than( $filtered );
644
+ // This will strip extra whitespace for us.
645
+ $filtered = wp_strip_all_tags( $filtered, true );
646
+ } else {
647
+ $filtered = trim( preg_replace( '/[\r\n\t ]+/', ' ', $filtered ) );
648
+ }
649
+
650
+ $filtered = trim( preg_replace('/ +/', ' ', $filtered) );
651
+
652
+ return $filtered;
653
+ }
654
+
655
+ public static function sanitize_cache_key( $cache_key ) {
656
+ $cache_key = strtolower( $cache_key );
657
+ $cache_key = preg_replace( '/[^a-z0-9_\-\+]/', '', $cache_key );
658
+ return $cache_key;
659
+ }
660
+
661
+ }
662
+
663
+ ?>
includes/class-scc-crawl-strategy.php CHANGED
@@ -1,229 +1,229 @@
1
- <?php
2
- /*
3
- class-scc-crawl-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- abstract class SCC_Crawl_Strategy {
31
-
32
- /**
33
- * TODO Auto-generated comment.
34
- */
35
- protected $url;
36
-
37
- /**
38
- * TODO Auto-generated comment.
39
- */
40
- protected $method;
41
-
42
- /**
43
- * TODO Auto-generated comment.
44
- */
45
- protected $query_parameters = array();
46
-
47
- /**
48
- * TODO Auto-generated comment.
49
- */
50
- protected $parameters = array();
51
-
52
- /**
53
- * Instance
54
- */
55
- private static $instance = array();
56
-
57
- /**
58
- * Class constarctor
59
- * Hook onto all of the actions and filters needed by the plugin.
60
- *
61
- */
62
- protected function __construct() {
63
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
64
- //$this->get_object_id();
65
- }
66
-
67
- /**
68
- * Get instance
69
- *
70
- * @since 0.1.1
71
- */
72
- public static function get_instance() {
73
- $class_name = get_called_class();
74
-
75
- if ( ! isset( self::$instance[$class_name] ) ) {
76
- self::$instance[$class_name] = new $class_name();
77
- }
78
-
79
- return self::$instance[$class_name];
80
- }
81
-
82
- /**
83
- * Return object ID
84
- *
85
- * @since 0.6.0
86
- */
87
- public function get_object_id() {
88
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
89
-
90
- $object_id = spl_object_hash( $this );
91
-
92
- SCC_Common_Util::log( '[' . __METHOD__ . '] object ID: ' . $object_id );
93
-
94
- return $object_id;
95
- }
96
-
97
- /**
98
- * Inhibit clone
99
- *
100
- * @since 0.6.0
101
- */
102
- final public function __clone() {
103
- throw new Exception('Clone is not allowed against' . get_class( $this ) );
104
- }
105
-
106
- /**
107
- * Initialization
108
- *
109
- * @since 0.6.0
110
- */
111
- abstract public function initialize( $options = array() );
112
-
113
- /**
114
- * TODO Auto-generated comment.
115
- */
116
- public function get_url() {
117
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
118
- return $url;
119
- }
120
-
121
- /**
122
- * TODO Auto-generated comment.
123
- */
124
- public function set_url( $url) {
125
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
126
- $this->url = $url;
127
- }
128
-
129
- /**
130
- * TODO Auto-generated comment.
131
- */
132
- public function get_parameters() {
133
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
134
- return $this->parameters;
135
- }
136
-
137
- public function get_parameter( $key ) {
138
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
139
- return $this->parameters[$key];
140
- }
141
-
142
- /**
143
- * TODO Auto-generated comment.
144
- */
145
- public function set_parameters( $parameters = array() ) {
146
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
147
- //$this->parameters = array_merge( $this->parameters, $parameters );
148
- foreach ( $parameters as $key => $value ) {
149
- $this->set_parameter( $key, $value );
150
- }
151
- }
152
-
153
- /**
154
- * TODO Auto-generated comment.
155
- */
156
- public function set_parameter( $key, $value ) {
157
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
158
- $this->parameters[$key] = $value;
159
- }
160
-
161
- /**
162
- * TODO Auto-generated comment.
163
- */
164
- public function get_query_parameters() {
165
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
166
- return $this->query_parameters;
167
- }
168
-
169
- public function get_query_parameter( $key ) {
170
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
171
- return $this->query_parameters[$key];
172
- }
173
-
174
- /**
175
- * TODO Auto-generated comment.
176
- */
177
- public function set_query_parameters( $query_parameters = array() ) {
178
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
179
- //$this->query_parameters = array_merge( $this->query_parameters, $query_parameters );
180
- foreach( $query_parameters as $key => $value ) {
181
- $this->set_query_parameter( $key, $value );
182
- }
183
- }
184
-
185
- /**
186
- * TODO Auto-generated comment.
187
- */
188
- public function set_query_parameter( $key, $value ) {
189
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
190
- $this->query_parameters[$key] = $value;
191
- }
192
-
193
- /**
194
- * TODO Auto-generated comment.
195
- */
196
- public function get_method() {
197
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
198
- return $method;
199
- }
200
-
201
- /**
202
- * TODO Auto-generated comment.
203
- */
204
- public function set_method( $method) {
205
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
206
- $this->method = $method;
207
- }
208
-
209
- /**
210
- * TODO Auto-generated comment.
211
- */
212
- abstract public function build_query_url();
213
-
214
- /**
215
- * TODO Auto-generated comment.
216
- */
217
- abstract public function extract_count( $content );
218
-
219
- /**
220
- * TODO Auto-generated comment.
221
- */
222
- abstract public function build_header();
223
-
224
- /**
225
- * TODO Auto-generated comment.
226
- */
227
- abstract public function check_configuration();
228
-
229
- }
1
+ <?php
2
+ /*
3
+ class-scc-crawl-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ abstract class SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * TODO Auto-generated comment.
34
+ */
35
+ protected $url;
36
+
37
+ /**
38
+ * TODO Auto-generated comment.
39
+ */
40
+ protected $method;
41
+
42
+ /**
43
+ * TODO Auto-generated comment.
44
+ */
45
+ protected $query_parameters = array();
46
+
47
+ /**
48
+ * TODO Auto-generated comment.
49
+ */
50
+ protected $parameters = array();
51
+
52
+ /**
53
+ * Instance
54
+ */
55
+ private static $instance = array();
56
+
57
+ /**
58
+ * Class constarctor
59
+ * Hook onto all of the actions and filters needed by the plugin.
60
+ *
61
+ */
62
+ protected function __construct() {
63
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
64
+ //$this->get_object_id();
65
+ }
66
+
67
+ /**
68
+ * Get instance
69
+ *
70
+ * @since 0.1.1
71
+ */
72
+ public static function get_instance() {
73
+ $class_name = get_called_class();
74
+
75
+ if ( ! isset( self::$instance[$class_name] ) ) {
76
+ self::$instance[$class_name] = new $class_name();
77
+ }
78
+
79
+ return self::$instance[$class_name];
80
+ }
81
+
82
+ /**
83
+ * Return object ID
84
+ *
85
+ * @since 0.6.0
86
+ */
87
+ public function get_object_id() {
88
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
89
+
90
+ $object_id = spl_object_hash( $this );
91
+
92
+ SCC_Common_Util::log( '[' . __METHOD__ . '] object ID: ' . $object_id );
93
+
94
+ return $object_id;
95
+ }
96
+
97
+ /**
98
+ * Inhibit clone
99
+ *
100
+ * @since 0.6.0
101
+ */
102
+ final public function __clone() {
103
+ throw new Exception('Clone is not allowed against' . get_class( $this ) );
104
+ }
105
+
106
+ /**
107
+ * Initialization
108
+ *
109
+ * @since 0.6.0
110
+ */
111
+ abstract public function initialize( $options = array() );
112
+
113
+ /**
114
+ * TODO Auto-generated comment.
115
+ */
116
+ public function get_url() {
117
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
118
+ return $url;
119
+ }
120
+
121
+ /**
122
+ * TODO Auto-generated comment.
123
+ */
124
+ public function set_url( $url) {
125
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
126
+ $this->url = $url;
127
+ }
128
+
129
+ /**
130
+ * TODO Auto-generated comment.
131
+ */
132
+ public function get_parameters() {
133
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
134
+ return $this->parameters;
135
+ }
136
+
137
+ public function get_parameter( $key ) {
138
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
139
+ return $this->parameters[$key];
140
+ }
141
+
142
+ /**
143
+ * TODO Auto-generated comment.
144
+ */
145
+ public function set_parameters( $parameters = array() ) {
146
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
147
+ //$this->parameters = array_merge( $this->parameters, $parameters );
148
+ foreach ( $parameters as $key => $value ) {
149
+ $this->set_parameter( $key, $value );
150
+ }
151
+ }
152
+
153
+ /**
154
+ * TODO Auto-generated comment.
155
+ */
156
+ public function set_parameter( $key, $value ) {
157
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
158
+ $this->parameters[$key] = $value;
159
+ }
160
+
161
+ /**
162
+ * TODO Auto-generated comment.
163
+ */
164
+ public function get_query_parameters() {
165
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
166
+ return $this->query_parameters;
167
+ }
168
+
169
+ public function get_query_parameter( $key ) {
170
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
171
+ return $this->query_parameters[$key];
172
+ }
173
+
174
+ /**
175
+ * TODO Auto-generated comment.
176
+ */
177
+ public function set_query_parameters( $query_parameters = array() ) {
178
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
179
+ //$this->query_parameters = array_merge( $this->query_parameters, $query_parameters );
180
+ foreach( $query_parameters as $key => $value ) {
181
+ $this->set_query_parameter( $key, $value );
182
+ }
183
+ }
184
+
185
+ /**
186
+ * TODO Auto-generated comment.
187
+ */
188
+ public function set_query_parameter( $key, $value ) {
189
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
190
+ $this->query_parameters[$key] = $value;
191
+ }
192
+
193
+ /**
194
+ * TODO Auto-generated comment.
195
+ */
196
+ public function get_method() {
197
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
198
+ return $method;
199
+ }
200
+
201
+ /**
202
+ * TODO Auto-generated comment.
203
+ */
204
+ public function set_method( $method) {
205
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
206
+ $this->method = $method;
207
+ }
208
+
209
+ /**
210
+ * TODO Auto-generated comment.
211
+ */
212
+ abstract public function build_query_url();
213
+
214
+ /**
215
+ * TODO Auto-generated comment.
216
+ */
217
+ abstract public function extract_count( $content );
218
+
219
+ /**
220
+ * TODO Auto-generated comment.
221
+ */
222
+ abstract public function build_header();
223
+
224
+ /**
225
+ * TODO Auto-generated comment.
226
+ */
227
+ abstract public function check_configuration();
228
+
229
+ }
includes/class-scc-crawler.php CHANGED
@@ -1,199 +1,199 @@
1
- <?php
2
- /*
3
- class-scc-crawler.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- abstract class SCC_Crawler {
31
-
32
- /**
33
- * URL for data crawling
34
- */
35
- protected $url = '';
36
-
37
- /**
38
- * method to crawl
39
- */
40
- protected $crawl_method = 1;
41
-
42
- /**
43
- * Timeout
44
- */
45
- protected $timeout = 10;
46
-
47
- /**
48
- * ssl verification
49
- */
50
- protected $ssl_verification = true;
51
-
52
- /**
53
- * retry flag
54
- */
55
- protected $crawl_retry = false;
56
-
57
- /**
58
- * limit of crawl retry
59
- */
60
- protected $retry_limit = 0;
61
-
62
- /**
63
- * fault tolerance mode
64
- */
65
- protected $fault_tolerance = 1;
66
-
67
- /**
68
- * Instance
69
- */
70
- private static $instance = array();
71
-
72
- /**
73
- * Crawl strategies
74
- */
75
- protected $crawl_strategies = array();
76
-
77
- /**
78
- * Cache target
79
- */
80
- protected $target_sns = array();
81
-
82
- /**
83
- * Class constarctor
84
- * Hook onto all of the actions and filters needed by the plugin.
85
- *
86
- */
87
- protected function __construct() {
88
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
89
- //$this->get_object_id();
90
- }
91
-
92
- /**
93
- * Get instance
94
- *
95
- * @since 0.1.1
96
- */
97
- public static function get_instance() {
98
-
99
- $class_name = get_called_class();
100
-
101
- if ( ! isset( self::$instance[$class_name] ) ) {
102
- self::$instance[$class_name] = new $class_name();
103
- }
104
-
105
- return self::$instance[$class_name];
106
- }
107
-
108
- /**
109
- * Return object ID
110
- *
111
- * @since 0.6.0
112
- */
113
- public function get_object_id() {
114
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
115
-
116
- $object_id = spl_object_hash( $this );
117
-
118
- SCC_Common_Util::log( '[' . __METHOD__ . '] object ID: ' . $object_id );
119
-
120
- return $object_id;
121
- }
122
-
123
- /**
124
- * Inhibit clone
125
- *
126
- * @since 0.6.0
127
- */
128
- final public function __clone() {
129
- throw new Exception( 'Clone is not allowed against' . get_class( $this ) );
130
- }
131
-
132
- /**
133
- * Initialization
134
- *
135
- * @since 0.6.0
136
- */
137
- abstract public function initialize( $options = array() );
138
-
139
- /**
140
- * Abstract method for data crawling
141
- *
142
- * @since 0.1.1
143
- */
144
- abstract public function get_data( $target_sns, $options );
145
-
146
- /**
147
- * Set strategy option
148
- *
149
- * @since 0.9.0
150
- */
151
- public function initialize_crawl_strategy( $sns, $options ) {
152
- if ( isset( $this->crawl_strategies[$sns] ) ) {
153
- $this->crawl_strategies[$sns]->initialize( $options );
154
- }
155
- }
156
-
157
- /**
158
- * Set strategy option
159
- *
160
- * @since 0.9.0
161
- */
162
- public function set_crawl_strategy_parameters( $sns, $options ) {
163
- if ( isset( $this->crawl_strategies[$sns] ) ) {
164
- $this->crawl_strategies[$sns]->set_parameters( $options );
165
- }
166
- }
167
-
168
- /**
169
- * Set strategy option
170
- *
171
- * @since 0.9.0
172
- */
173
- public function set_crawl_strategy_query_parameters( $sns, $options ) {
174
- if ( isset( $this->crawl_strategies[$sns] ) ) {
175
- $this->crawl_strategies[$sns]->set_query_parameters( $options );
176
- }
177
- }
178
-
179
- /**
180
- * Get strategy option
181
- *
182
- * @since 0.9.0
183
- */
184
- public function get_crawl_strategy_query_parameters( $sns ) {
185
- return $this->crawl_strategies[$sns]->get_query_parameters();
186
- }
187
-
188
- /**
189
- * Set strategy option
190
- *
191
- * @since 0.9.0
192
- */
193
- public function check_crawl_strategy_configurations( $sns ) {
194
- return $this->crawl_strategies[$sns]->check_configuration();
195
- }
196
-
197
- }
198
-
199
- ?>
1
+ <?php
2
+ /*
3
+ class-scc-crawler.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ abstract class SCC_Crawler {
31
+
32
+ /**
33
+ * URL for data crawling
34
+ */
35
+ protected $url = '';
36
+
37
+ /**
38
+ * method to crawl
39
+ */
40
+ protected $crawl_method = 1;
41
+
42
+ /**
43
+ * Timeout
44
+ */
45
+ protected $timeout = 10;
46
+
47
+ /**
48
+ * ssl verification
49
+ */
50
+ protected $ssl_verification = true;
51
+
52
+ /**
53
+ * retry flag
54
+ */
55
+ protected $crawl_retry = false;
56
+
57
+ /**
58
+ * limit of crawl retry
59
+ */
60
+ protected $retry_limit = 0;
61
+
62
+ /**
63
+ * fault tolerance mode
64
+ */
65
+ protected $fault_tolerance = 1;
66
+
67
+ /**
68
+ * Instance
69
+ */
70
+ private static $instance = array();
71
+
72
+ /**
73
+ * Crawl strategies
74
+ */
75
+ protected $crawl_strategies = array();
76
+
77
+ /**
78
+ * Cache target
79
+ */
80
+ protected $target_sns = array();
81
+
82
+ /**
83
+ * Class constarctor
84
+ * Hook onto all of the actions and filters needed by the plugin.
85
+ *
86
+ */
87
+ protected function __construct() {
88
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
89
+ //$this->get_object_id();
90
+ }
91
+
92
+ /**
93
+ * Get instance
94
+ *
95
+ * @since 0.1.1
96
+ */
97
+ public static function get_instance() {
98
+
99
+ $class_name = get_called_class();
100
+
101
+ if ( ! isset( self::$instance[$class_name] ) ) {
102
+ self::$instance[$class_name] = new $class_name();
103
+ }
104
+
105
+ return self::$instance[$class_name];
106
+ }
107
+
108
+ /**
109
+ * Return object ID
110
+ *
111
+ * @since 0.6.0
112
+ */
113
+ public function get_object_id() {
114
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
115
+
116
+ $object_id = spl_object_hash( $this );
117
+
118
+ SCC_Common_Util::log( '[' . __METHOD__ . '] object ID: ' . $object_id );
119
+
120
+ return $object_id;
121
+ }
122
+
123
+ /**
124
+ * Inhibit clone
125
+ *
126
+ * @since 0.6.0
127
+ */
128
+ final public function __clone() {
129
+ throw new Exception( 'Clone is not allowed against' . get_class( $this ) );
130
+ }
131
+
132
+ /**
133
+ * Initialization
134
+ *
135
+ * @since 0.6.0
136
+ */
137
+ abstract public function initialize( $options = array() );
138
+
139
+ /**
140
+ * Abstract method for data crawling
141
+ *
142
+ * @since 0.1.1
143
+ */
144
+ abstract public function get_data( $target_sns, $options );
145
+
146
+ /**
147
+ * Set strategy option
148
+ *
149
+ * @since 0.9.0
150
+ */
151
+ public function initialize_crawl_strategy( $sns, $options ) {
152
+ if ( isset( $this->crawl_strategies[$sns] ) ) {
153
+ $this->crawl_strategies[$sns]->initialize( $options );
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Set strategy option
159
+ *
160
+ * @since 0.9.0
161
+ */
162
+ public function set_crawl_strategy_parameters( $sns, $options ) {
163
+ if ( isset( $this->crawl_strategies[$sns] ) ) {
164
+ $this->crawl_strategies[$sns]->set_parameters( $options );
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Set strategy option
170
+ *
171
+ * @since 0.9.0
172
+ */
173
+ public function set_crawl_strategy_query_parameters( $sns, $options ) {
174
+ if ( isset( $this->crawl_strategies[$sns] ) ) {
175
+ $this->crawl_strategies[$sns]->set_query_parameters( $options );
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Get strategy option
181
+ *
182
+ * @since 0.9.0
183
+ */
184
+ public function get_crawl_strategy_query_parameters( $sns ) {
185
+ return $this->crawl_strategies[$sns]->get_query_parameters();
186
+ }
187
+
188
+ /**
189
+ * Set strategy option
190
+ *
191
+ * @since 0.9.0
192
+ */
193
+ public function check_crawl_strategy_configurations( $sns ) {
194
+ return $this->crawl_strategies[$sns]->check_configuration();
195
+ }
196
+
197
+ }
198
+
199
+ ?>
includes/class-scc-engine.php CHANGED
@@ -1,158 +1,158 @@
1
- <?php
2
- /*
3
- class-scc-engine.php
4
-
5
- Description: This class is a engine
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- abstract class SCC_Engine {
31
-
32
- /**
33
- * Cron name to schedule cache processing
34
- */
35
- protected $prime_cron = NULL;
36
-
37
- /**
38
- * Cron name to execute cache processing
39
- */
40
- protected $execute_cron = NULL;
41
-
42
- /**
43
- * Schedule name for cache processing
44
- */
45
- protected $event_schedule = NULL;
46
-
47
- /**
48
- * Schedule description for cache processing
49
- */
50
- protected $event_description = NULL;
51
-
52
- /**
53
- * Instance
54
- */
55
- private static $instance = array();
56
-
57
- /**
58
- * Class constarctor
59
- * Hook onto all of the actions and filters needed by the plugin.
60
- *
61
- */
62
- protected function __construct() {
63
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
64
- //$this->get_object_id();
65
- }
66
-
67
- /**
68
- * Get instance
69
- *
70
- * @since 0.1.1
71
- */
72
- public static function get_instance() {
73
- $class_name = get_called_class();
74
-
75
- if ( ! isset( self::$instance[$class_name] ) ) {
76
- self::$instance[$class_name] = new $class_name();
77
- }
78
-
79
- return self::$instance[$class_name];
80
- }
81
-
82
- /**
83
- * Return object ID
84
- *
85
- * @since 0.6.0
86
- */
87
- public function get_object_id() {
88
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
89
-
90
- $object_id = spl_object_hash( $this );
91
-
92
- SCC_Common_Util::log( '[' . __METHOD__ . '] object ID: ' . $object_id );
93
-
94
- return $object_id;
95
- }
96
-
97
- /**
98
- * Inhibit clone
99
- *
100
- * @since 0.6.0
101
- */
102
- final public function __clone() {
103
- throw new Exception('Clone is not allowed against' . get_class( $this ) );
104
- }
105
-
106
- /**
107
- * Register base schedule for this engine
108
- *
109
- * @since 0.1.0
110
- */
111
- public function register_schedule() {
112
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
113
-
114
- if ( ! wp_next_scheduled( $this->prime_cron ) ) {
115
- wp_schedule_event( time(), $this->event_schedule, $this->prime_cron );
116
- }
117
- }
118
-
119
- /**
120
- * Unregister base schedule for this engine
121
- *
122
- * @since 0.1.0
123
- */
124
- public function unregister_schedule() {
125
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
126
-
127
- wp_clear_scheduled_hook( $this->prime_cron );
128
- SCC_WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
129
- }
130
-
131
- /**
132
- * Get name of prime cron
133
- *
134
- * @since 0.1.1
135
- */
136
- public function get_prime_cron() {
137
- return $this->prime_cron;
138
- }
139
-
140
- /**
141
- * Get name of execute cron
142
- *
143
- * @since 0.1.1
144
- */
145
- public function get_excute_cron() {
146
- return $this->execute_cron;
147
- }
148
-
149
- /**
150
- * Initialization
151
- *
152
- * @since 0.1.1
153
- */
154
- abstract public function initialize( $options = array() );
155
-
156
- }
157
-
158
- ?>
1
+ <?php
2
+ /*
3
+ class-scc-engine.php
4
+
5
+ Description: This class is a engine
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ abstract class SCC_Engine {
31
+
32
+ /**
33
+ * Cron name to schedule cache processing
34
+ */
35
+ protected $prime_cron = NULL;
36
+
37
+ /**
38
+ * Cron name to execute cache processing
39
+ */
40
+ protected $execute_cron = NULL;
41
+
42
+ /**
43
+ * Schedule name for cache processing
44
+ */
45
+ protected $event_schedule = NULL;
46
+
47
+ /**
48
+ * Schedule description for cache processing
49
+ */
50
+ protected $event_description = NULL;
51
+
52
+ /**
53
+ * Instance
54
+ */
55
+ private static $instance = array();
56
+
57
+ /**
58
+ * Class constarctor
59
+ * Hook onto all of the actions and filters needed by the plugin.
60
+ *
61
+ */
62
+ protected function __construct() {
63
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
64
+ //$this->get_object_id();
65
+ }
66
+
67
+ /**
68
+ * Get instance
69
+ *
70
+ * @since 0.1.1
71
+ */
72
+ public static function get_instance() {
73
+ $class_name = get_called_class();
74
+
75
+ if ( ! isset( self::$instance[$class_name] ) ) {
76
+ self::$instance[$class_name] = new $class_name();
77
+ }
78
+
79
+ return self::$instance[$class_name];
80
+ }
81
+
82
+ /**
83
+ * Return object ID
84
+ *
85
+ * @since 0.6.0
86
+ */
87
+ public function get_object_id() {
88
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
89
+
90
+ $object_id = spl_object_hash( $this );
91
+
92
+ SCC_Common_Util::log( '[' . __METHOD__ . '] object ID: ' . $object_id );
93
+
94
+ return $object_id;
95
+ }
96
+
97
+ /**
98
+ * Inhibit clone
99
+ *
100
+ * @since 0.6.0
101
+ */
102
+ final public function __clone() {
103
+ throw new Exception('Clone is not allowed against' . get_class( $this ) );
104
+ }
105
+
106
+ /**
107
+ * Register base schedule for this engine
108
+ *
109
+ * @since 0.1.0
110
+ */
111
+ public function register_schedule() {
112
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
113
+
114
+ if ( ! wp_next_scheduled( $this->prime_cron ) ) {
115
+ wp_schedule_event( time(), $this->event_schedule, $this->prime_cron );
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Unregister base schedule for this engine
121
+ *
122
+ * @since 0.1.0
123
+ */
124
+ public function unregister_schedule() {
125
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
126
+
127
+ wp_clear_scheduled_hook( $this->prime_cron );
128
+ SCC_WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
129
+ }
130
+
131
+ /**
132
+ * Get name of prime cron
133
+ *
134
+ * @since 0.1.1
135
+ */
136
+ public function get_prime_cron() {
137
+ return $this->prime_cron;
138
+ }
139
+
140
+ /**
141
+ * Get name of execute cron
142
+ *
143
+ * @since 0.1.1
144
+ */
145
+ public function get_excute_cron() {
146
+ return $this->execute_cron;
147
+ }
148
+
149
+ /**
150
+ * Initialization
151
+ *
152
+ * @since 0.1.1
153
+ */
154
+ abstract public function initialize( $options = array() );
155
+
156
+ }
157
+
158
+ ?>
includes/class-scc-export-engine.php CHANGED
@@ -1,44 +1,44 @@
1
- <?php
2
- /*
3
- class-scc-export-engine.php
4
-
5
- Description: This class is a data export engine whitch exports cached data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- abstract class SCC_Export_Engine extends SCC_Engine {
31
-
32
- /**
33
- * Meta key for share second cache
34
- */
35
- protected $share_meta_key_prefix = NULL;
36
-
37
- /**
38
- * Meta key for follow second cache
39
- */
40
- protected $follow_meta_key_prefix = NULL;
41
-
42
- }
43
-
44
- ?>
1
+ <?php
2
+ /*
3
+ class-scc-export-engine.php
4
+
5
+ Description: This class is a data export engine whitch exports cached data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ abstract class SCC_Export_Engine extends SCC_Engine {
31
+
32
+ /**
33
+ * Meta key for share second cache
34
+ */
35
+ protected $share_meta_key_prefix = NULL;
36
+
37
+ /**
38
+ * Meta key for follow second cache
39
+ */
40
+ protected $follow_meta_key_prefix = NULL;
41
+
42
+ }
43
+
44
+ ?>
includes/class-scc-follow-analytical-engine.php ADDED
@@ -0,0 +1,371 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-follow-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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Analytical_Engine extends SCC_Analytical_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ const DEF_TRANSIENT_PREFIX = 'scc_follow_count_';
36
+
37
+ /**
38
+ * Prefix of cache ID
39
+ */
40
+ const DEF_BASE_PREFIX = 'scc_follow_base_';
41
+
42
+ /**
43
+ * Prefix of cache ID
44
+ */
45
+ const DEF_DELTA_PREFIX = 'scc_follow_delta_';
46
+
47
+ /**
48
+ * Cron name to schedule cache processing
49
+ */
50
+ const DEF_PRIME_CRON = 'scc_follow_updatebase_prime';
51
+
52
+ /**
53
+ * Cron name to execute cache processing
54
+ */
55
+ const DEF_EXECUTE_CRON = 'scc_follow_updatebase_exec';
56
+
57
+ /**
58
+ * Schedule name for cache processing
59
+ */
60
+ const DEF_EVENT_SCHEDULE = 'follow_update_base_event';
61
+
62
+ /**
63
+ * Schedule description for cache processing
64
+ */
65
+ const DEF_EVENT_DESCRIPTION = '[SCC] Follow Update Base Interval';
66
+
67
+ /**
68
+ * Interval cheking and caching target data
69
+ */
70
+ private $check_interval = 600;
71
+
72
+ /**
73
+ * Offset suffix
74
+ */
75
+ private $base_schedule = '* * * 0 0';
76
+
77
+ /**
78
+ * Base directory
79
+ */
80
+ private $base_dir = NULL;
81
+
82
+ /**
83
+ * Crawl date key
84
+ */
85
+ private $crawl_date_key = NULL;
86
+
87
+ /**
88
+ * Initialization
89
+ *
90
+ * @since 0.1.1
91
+ */
92
+ public function initialize( $options = array() ) {
93
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
94
+
95
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
96
+ $this->base_prefix = self::DEF_BASE_PREFIX;
97
+ $this->delta_prefix = self::DEF_DELTA_PREFIX;
98
+ $this->prime_cron = self::DEF_PRIME_CRON;
99
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
100
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
101
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
102
+ $this->base_dir = WP_PLUGIN_DIR . '/sns-count-cache/data/';
103
+
104
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
105
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
106
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
107
+ if ( isset( $options['base_schedule'] ) ) $this->base_schedule = $options['base_schedule'];
108
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
109
+ if ( isset( $options['base_prefix'] ) ) $this->base_prefix = $options['base_prefix'];
110
+ if ( isset( $options['delta_prefix'] ) ) $this->delta_prefix = $options['delta_prefix'];
111
+ if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
112
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
113
+ if ( isset( $options['crawl_date_key'] ) ) $this->crawl_date_key = $options['crawl_date_key'];
114
+
115
+ add_action( $this->prime_cron, array( $this, 'prime_base' ) );
116
+ add_action( $this->execute_cron, array( $this, 'execute_base' ), 10, 1 );
117
+ add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
118
+ }
119
+
120
+ /**
121
+ * Register event schedule for this engine
122
+ *
123
+ * @since 0.1.0
124
+ */
125
+ public function schedule_check_interval( $schedules ) {
126
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
127
+
128
+ $schedules[$this->event_schedule] = array(
129
+ 'interval' => $this->check_interval,
130
+ 'display' => $this->event_description
131
+ );
132
+
133
+ return $schedules;
134
+ }
135
+
136
+ /**
137
+ * Schedule data retrieval and cache processing
138
+ *
139
+ * @since 0.1.0
140
+ */
141
+ public function prime_base() {
142
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
143
+
144
+ $next_exec_time = SCC_WP_Cron_Util::next_exec_time( $this->base_schedule );
145
+
146
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time (timesatamp): ' . $next_exec_time );
147
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time (date): ' . date_i18n( 'Y/m/d H:i:s', $next_exec_time ) );
148
+
149
+ if ( ! SCC_WP_Cron_Util::is_scheduled_hook( $this->execute_cron ) ) {
150
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( SCC_Common_Util::short_hash( $next_exec_time ) ) );
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Get and cache data of each published post and page
156
+ *
157
+ * @since 0.1.0
158
+ */
159
+ public function execute_base( $hash ) {
160
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
161
+
162
+ $current_date = date_i18n( 'Y/m/d H:i:s' );
163
+
164
+ if ( file_exists( $this->base_dir ) ) {
165
+ $base_file = $this->base_dir . sanitize_file_name( $this->get_base_key( 'follow' ) );
166
+
167
+ if ( ! file_exists( $base_file ) ) {
168
+ if ( touch( $base_file ) ) {
169
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file creation succeeded: ' . $base_file );
170
+ } else {
171
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file creation failed: ' . $base_file );
172
+ }
173
+ }
174
+
175
+ if ( file_exists( $base_file ) ) {
176
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file exists: ' . $base_file );
177
+
178
+ $option_key = $this->get_cache_key( 'follow' );
179
+
180
+ if ( false !== ( $sns_followers = get_option( $option_key ) ) ) {
181
+ foreach ( $this->target_sns as $sns => $active ) {
182
+ if ( $active ) {
183
+ if ( $sns !== $this->crawl_date_key ) {
184
+ if ( ! isset( $sns_followers[$sns] ) || $sns_followers[$sns] < 0 ) {
185
+ $sns_followers[$sns] = (int) -1;
186
+ }
187
+ } else {
188
+ if ( ! isset( $sns_followers[$sns] ) ) {
189
+ $sns_followers[$sns] = '';
190
+ }
191
+ }
192
+ }
193
+ }
194
+
195
+ $data = serialize( $sns_followers );
196
+
197
+ $fp = fopen( $base_file, 'w' );
198
+
199
+ if ( fwrite( $fp, $data ) ) {
200
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ');
201
+ } else {
202
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ');
203
+ }
204
+
205
+ if ( fclose( $fp ) ) {
206
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
207
+ } else {
208
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
209
+ }
210
+ }
211
+ }
212
+ }
213
+
214
+ }
215
+
216
+ /**
217
+ * Initialize meta key for ranking
218
+ *
219
+ * @since 0.6.1
220
+ */
221
+ public function analyze( $options = array() ) {
222
+
223
+ $transient_id = $options['cache_key'];
224
+ $target_sns = $options['target_sns'];
225
+
226
+ $base_file = $this->base_dir . sanitize_file_name( $this->get_base_key( 'follow' ) );
227
+
228
+ $sns_followers = array();
229
+ $sns_base_followers = array();
230
+
231
+ if ( file_exists( $base_file ) ) {
232
+ $fp = fopen( $base_file, 'r' );
233
+
234
+ $data = fread( $fp, filesize( $base_file ) );
235
+
236
+ if ( fclose( $fp ) ) {
237
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
238
+ } else {
239
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
240
+ }
241
+
242
+ $sns_base_followers = unserialize( $data );
243
+ } else {
244
+ // if there is no base file.
245
+
246
+ if ( touch( $base_file ) ) {
247
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file creation succeeded: ' . $base_file );
248
+ } else {
249
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file creation failed: ' . $base_file );
250
+ }
251
+
252
+ if ( file_exists( $base_file ) ) {
253
+
254
+ $sns_followers = array();
255
+
256
+ $option_key = $this->get_cache_key( 'follow' );
257
+
258
+ if ( false !== ( $sns_followers = get_option( $option_key ) ) ) {
259
+ foreach ( $this->target_sns as $sns => $active ) {
260
+ if ( $active ) {
261
+ if ( $sns !== $this->crawl_date_key ) {
262
+ if ( ! isset( $sns_followers[$sns] ) || $sns_followers[$sns] < 0 ) {
263
+ $sns_followers[$sns] = (int) -1;
264
+ }
265
+ } else {
266
+ if ( ! isset( $sns_followers[$sns] ) ) {
267
+ $sns_followers[$sns] = '';
268
+ }
269
+ }
270
+ }
271
+ }
272
+ }
273
+
274
+ $data = serialize( $sns_followers );
275
+
276
+ $fp = fopen( $base_file, 'w' );
277
+
278
+ if ( fwrite( $fp, $data ) ) {
279
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' );
280
+ } else {
281
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' );
282
+ }
283
+
284
+ if ( fclose( $fp ) ) {
285
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
286
+ } else {
287
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
288
+ }
289
+ }
290
+ }
291
+
292
+ $sns_followers = array();
293
+ $diffs = array();
294
+
295
+ $option_key = $this->get_cache_key( 'follow' );
296
+
297
+ $diffs = array();
298
+
299
+ if ( false !== ( $sns_followers = get_option( $option_key ) ) ) {
300
+
301
+ foreach ( $this->target_sns as $sns => $active ) {
302
+ if ( $active ){
303
+ if ( $sns !== $this->crawl_date_key ) {
304
+ if ( isset( $sns_followers[$sns] ) && $sns_followers[$sns] !== '' && $sns_followers[$sns] >= 0 && ! isset( $sns_base_followers[$sns] ) ) {
305
+ $diffs[$sns] = (int) $sns_followers[$sns];
306
+ } elseif ( isset( $sns_followers[$sns] ) && $sns_followers[$sns] >= 0 && isset( $sns_base_followers[$sns] ) && $sns_base_followers[$sns] !== '' && $sns_base_followers[$sns] >= 0 ) {
307
+ $diffs[$sns] = (int)( $sns_followers[$sns] - $sns_base_followers[$sns] );
308
+ } else {
309
+ $diffs[$sns] = (int) 0;
310
+ }
311
+ } else {
312
+ if ( isset( $sns_followers[$sns] ) && isset( $sns_base_followers[$sns] ) && $sns_base_followers[$sns] !== '' ) {
313
+ $diffs[$sns] = $sns_base_followers[$sns] . ',' . $sns_followers[$sns];
314
+ } else {
315
+ $diffs[$sns] = '';
316
+ }
317
+ }
318
+ }
319
+ }
320
+
321
+ $option_key = $this->get_delta_key( 'follow' );
322
+ update_option( $option_key, $diffs );
323
+
324
+ } else {
325
+
326
+ foreach ( $this->target_sns as $sns => $active ) {
327
+ if ( $active ){
328
+ if ( $sns !== $this->crawl_date_key ) {
329
+ $diffs[$sns] = (int) 0;
330
+ } else {
331
+ $diffs[$sns] = '';
332
+ }
333
+ }
334
+ }
335
+
336
+ $option_key = $this->get_delta_key( 'follow' );
337
+ update_option( $option_key, $diffs );
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Initialize meta key for ranking
343
+ *
344
+ * @since 0.3.0
345
+ */
346
+ public function initialize_base() {
347
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
348
+
349
+ /*
350
+ $option_key = $this->get_cache_key( $this->offset_suffix );
351
+
352
+ update_option( $option_key, 0 );
353
+ */
354
+ }
355
+
356
+ /**
357
+ * Clear meta key for ranking
358
+ *
359
+ * @since 0.3.0
360
+ */
361
+ public function clear_base() {
362
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
363
+
364
+ $option_key = $this->get_delta_key( 'follow' );
365
+
366
+ delete_option( $option_key );
367
+ }
368
+
369
+ }
370
+
371
+ ?>
includes/class-scc-follow-base-cache-engine.php CHANGED
@@ -1,229 +1,247 @@
1
- <?php
2
- /*
3
- class-scc-follow-base-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Follow_Base_Cache_Engine extends SCC_Follow_Cache_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- const DEF_TRANSIENT_PREFIX = 'scc_follow_count_';
36
-
37
- /**
38
- * Cron name to schedule cache processing
39
- */
40
- const DEF_PRIME_CRON = 'scc_follow_basecache_prime';
41
-
42
- /**
43
- * Cron name to execute cache processing
44
- */
45
- const DEF_EXECUTE_CRON = 'scc_follow_basecache_exec';
46
-
47
- /**
48
- * Schedule name for cache processing
49
- */
50
- const DEF_EVENT_SCHEDULE = 'follow_base_cache_event';
51
-
52
- /**
53
- * Schedule description for cache processing
54
- */
55
- const DEF_EVENT_DESCRIPTION = '[SCC] Follow Base Cache Interval';
56
-
57
- /**
58
- * Interval cheking and caching target data
59
- */
60
- private $check_interval = 600;
61
-
62
- /**
63
- * Offset suffix
64
- */
65
- private $offset_suffix = 'follow_base_cache_offset';
66
-
67
- /**
68
- * Initialization
69
- *
70
- * @since 0.1.1
71
- */
72
- public function initialize( $options = array() ) {
73
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
74
-
75
- $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
76
- $this->prime_cron = self::DEF_PRIME_CRON;
77
- $this->execute_cron = self::DEF_EXECUTE_CRON;
78
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
79
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
80
-
81
- $this->load_ratio = 0.5;
82
-
83
- if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
84
- if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
85
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
86
- if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
87
- if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
88
- if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
89
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
90
- if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
91
- if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
92
- if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
93
- if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
94
- if ( isset( $options['cache_retry'] ) ) $this->cache_retry = $options['cache_retry'];
95
- if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
96
-
97
- add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
98
- add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
99
- add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
100
- }
101
-
102
- /**
103
- * Register event schedule for this engine
104
- *
105
- * @since 0.1.0
106
- */
107
- public function schedule_check_interval( $schedules ) {
108
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
109
-
110
- $schedules[$this->event_schedule] = array(
111
- 'interval' => $this->check_interval,
112
- 'display' => $this->event_description
113
- );
114
-
115
- return $schedules;
116
- }
117
-
118
- /**
119
- * Schedule data retrieval and cache processing
120
- *
121
- * @since 0.4.0
122
- */
123
- public function prime_cache() {
124
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
125
-
126
- $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
127
-
128
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
129
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
130
-
131
- wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( SCC_Common_Util::short_hash( $next_exec_time ) ) );
132
- }
133
-
134
- /**
135
- * Get and cache data of each published post and page
136
- *
137
- * @since 0.1.0
138
- */
139
- public function execute_cache( $hash ) {
140
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
141
-
142
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
143
-
144
- $cache_expiration = $this->get_cache_expiration();
145
-
146
- SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
147
-
148
- $transient_id = $this->get_cache_key( 'follow' );
149
-
150
- $options = array(
151
- 'cache_key' => $transient_id,
152
- 'target_sns' => $this->target_sns,
153
- 'cache_expiration' => $cache_expiration
154
- );
155
-
156
- // Primary cache
157
- $this->cache( $options );
158
-
159
- // Secondary cache
160
- $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
161
- }
162
-
163
- /**
164
- * Get and cache data for a given post
165
- *
166
- * @since 0.4.0
167
- */
168
- public function direct_cache( $second_sync = false ) {
169
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
170
-
171
- $cache_expiration = $this->get_cache_expiration();
172
-
173
- SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
174
-
175
- $transient_id = $this->get_cache_key( 'follow' );
176
-
177
- $options = array(
178
- 'cache_key' => $transient_id,
179
- 'target_sns' => $this->target_sns,
180
- 'cache_expiration' => $cache_expiration
181
- );
182
-
183
- // Primary cache
184
- $result = $this->cache( $options );
185
-
186
- if ( $second_sync ) {
187
- // Secondary cache
188
- $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
189
- }
190
-
191
- return $result;
192
- }
193
-
194
- /**
195
- * Get cache expiration based on current number of total post and page
196
- *
197
- * @since 0.4.0
198
- */
199
- protected function get_cache_expiration() {
200
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
201
-
202
- return 3 * $this->check_interval;
203
- }
204
-
205
- /**
206
- * Initialize meta key for ranking
207
- *
208
- * @since 0.3.0
209
- */
210
- public function initialize_cache() {
211
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
212
- }
213
-
214
- /**
215
- * Clear meta key for ranking
216
- *
217
- * @since 0.3.0
218
- */
219
- public function clear_cache() {
220
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
221
-
222
- $transient_id = $this->get_cache_key( 'follow' );
223
-
224
- delete_transient( $transient_id );
225
- }
226
-
227
- }
228
-
229
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-follow-base-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Base_Cache_Engine extends SCC_Follow_Cache_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ const DEF_TRANSIENT_PREFIX = 'scc_follow_count_';
36
+
37
+ /**
38
+ * Cron name to schedule cache processing
39
+ */
40
+ const DEF_PRIME_CRON = 'scc_follow_basecache_prime';
41
+
42
+ /**
43
+ * Cron name to execute cache processing
44
+ */
45
+ const DEF_EXECUTE_CRON = 'scc_follow_basecache_exec';
46
+
47
+ /**
48
+ * Schedule name for cache processing
49
+ */
50
+ const DEF_EVENT_SCHEDULE = 'follow_base_cache_event';
51
+
52
+ /**
53
+ * Schedule description for cache processing
54
+ */
55
+ const DEF_EVENT_DESCRIPTION = '[SCC] Follow Base Cache Interval';
56
+
57
+ /**
58
+ * Interval cheking and caching target data
59
+ */
60
+ private $check_interval = 600;
61
+
62
+ /**
63
+ * Offset suffix
64
+ */
65
+ private $offset_suffix = 'follow_base_cache_offset';
66
+
67
+ /**
68
+ * Initialization
69
+ *
70
+ * @since 0.1.1
71
+ */
72
+ public function initialize( $options = array() ) {
73
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
74
+
75
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
76
+ $this->prime_cron = self::DEF_PRIME_CRON;
77
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
78
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
79
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
80
+
81
+ $this->load_ratio = 0.5;
82
+
83
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
84
+ if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
85
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
86
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
87
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
88
+ if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
89
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
90
+ if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
91
+ if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
92
+ if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
93
+ if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
94
+ if ( isset( $options['cache_retry'] ) ) $this->cache_retry = $options['cache_retry'];
95
+ if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
96
+
97
+ add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
98
+ add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
99
+ add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
100
+ }
101
+
102
+ /**
103
+ * Register event schedule for this engine
104
+ *
105
+ * @since 0.1.0
106
+ */
107
+ public function schedule_check_interval( $schedules ) {
108
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
109
+
110
+ $schedules[$this->event_schedule] = array(
111
+ 'interval' => $this->check_interval,
112
+ 'display' => $this->event_description
113
+ );
114
+
115
+ return $schedules;
116
+ }
117
+
118
+ /**
119
+ * Schedule data retrieval and cache processing
120
+ *
121
+ * @since 0.4.0
122
+ */
123
+ public function prime_cache() {
124
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
125
+
126
+ $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
127
+
128
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
129
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
130
+
131
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( SCC_Common_Util::short_hash( $next_exec_time ) ) );
132
+ }
133
+
134
+ /**
135
+ * Get and cache data of each published post and page
136
+ *
137
+ * @since 0.1.0
138
+ */
139
+ public function execute_cache( $hash ) {
140
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
141
+
142
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
143
+
144
+ $cache_expiration = $this->get_cache_expiration();
145
+
146
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
147
+
148
+ $transient_id = $this->get_cache_key( 'follow' );
149
+
150
+ $options = array(
151
+ 'cache_key' => $transient_id,
152
+ 'target_sns' => $this->target_sns,
153
+ 'cache_expiration' => $cache_expiration
154
+ );
155
+
156
+ // Primary cache
157
+ $this->cache( $options );
158
+
159
+ // Secondary cache
160
+ $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
161
+ }
162
+
163
+ /**
164
+ * Get and cache data for a given post
165
+ *
166
+ * @since 0.4.0
167
+ */
168
+ public function direct_cache( $second_sync = false ) {
169
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
170
+
171
+ $cache_expiration = $this->get_cache_expiration();
172
+
173
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
174
+
175
+ $transient_id = $this->get_cache_key( 'follow' );
176
+
177
+ $options = array(
178
+ 'cache_key' => $transient_id,
179
+ 'target_sns' => $this->target_sns,
180
+ 'cache_expiration' => $cache_expiration
181
+ );
182
+
183
+ // Primary cache
184
+ $result = $this->cache( $options );
185
+
186
+ if ( $second_sync ) {
187
+ // Secondary cache
188
+ $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
189
+ }
190
+
191
+ return $result;
192
+ }
193
+
194
+ /**
195
+ * Get cache expiration based on current number of total post and page
196
+ *
197
+ * @since 0.4.0
198
+ */
199
+ protected function get_cache_expiration() {
200
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
201
+
202
+ return 3 * $this->check_interval;
203
+ }
204
+
205
+ /**
206
+ * Initialize meta key for ranking
207
+ *
208
+ * @since 0.3.0
209
+ */
210
+ public function initialize_cache() {
211
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
212
+ }
213
+
214
+ /**
215
+ * Clear meta key for ranking
216
+ *
217
+ * @since 0.3.0
218
+ */
219
+ public function clear_cache() {
220
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
221
+
222
+ $transient_id = $this->get_cache_key( 'follow' );
223
+
224
+ delete_transient( $transient_id );
225
+ }
226
+
227
+ /**
228
+ * Get cache
229
+ *
230
+ * @since 0.10.1
231
+ */
232
+ public function get_cache( $options = array() ) {
233
+
234
+ $transient_id = $this->get_cache_key( 'follow' );
235
+
236
+ $sns_followers = array();
237
+
238
+ if ( false !== ( $sns_followers = get_transient( $transient_id ) ) ) {
239
+ return $sns_followers;
240
+ } else {
241
+ return $this->delegate_order( SCC_Order::ORDER_GET_SECOND_CACHE, $options );
242
+ }
243
+ }
244
+
245
+ }
246
+
247
+ ?>
includes/class-scc-follow-cache-engine.php CHANGED
@@ -1,201 +1,201 @@
1
- <?php
2
- /*
3
- class-scc-follow-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- abstract class SCC_Follow_Cache_Engine extends SCC_Cache_Engine {
31
-
32
- /**
33
- * Crawler instance
34
- */
35
- protected $crawler = NULL;
36
-
37
- /**
38
- * Cache target
39
- */
40
- protected $target_sns = array();
41
-
42
- /**
43
- * migration between http and https
44
- */
45
- protected $scheme_migration_mode = false;
46
-
47
- /**
48
- * excluded keys in scheme migration
49
- */
50
- protected $scheme_migration_exclude_keys = array();
51
-
52
- /**
53
- * load ratio for throttle
54
- */
55
- protected $load_ratio = 0.5;
56
-
57
- /**
58
- * Get and cache data for a given post
59
- *
60
- * @since 0.4.0
61
- */
62
- public function cache( $options = array() ) {
63
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
64
-
65
- $cache_key = $options['cache_key'];
66
- $target_sns = $options['target_sns'];
67
- $cache_expiration = $options['cache_expiration'];
68
-
69
- $data = $this->crawler->get_data( $target_sns, NULL );
70
-
71
- SCC_Common_Util::log( $data );
72
-
73
- $target_sns_base = $target_sns;
74
-
75
- unset( $target_sns_base[SNS_Count_Cache::REF_CRAWL_DATE] );
76
- unset( $target_sns_base[SNS_Count_Cache::REF_SHARE_TOTAL] );
77
-
78
- $target_sns_url = array();
79
-
80
- $query_parameters = array();
81
-
82
- $query_parameters_origin = array();
83
-
84
- $secure_url_flag = false;
85
-
86
- foreach ( $target_sns_base as $sns => $active ) {
87
- if ( $active ) {
88
- $query_parameters[$sns] = $this->crawler->get_crawl_strategy_query_parameters( $sns );
89
- SCC_Common_Util::log( $query_parameters[$sns] );
90
- if ( isset( $query_parameters[$sns]['url'] ) ) {
91
- $target_sns_url[$sns] = true;
92
- SCC_Common_Util::log( $query_parameters[$sns] );
93
- if ( SCC_Common_Util::is_secure_url( $query_parameters[$sns]['url'] ) ) {
94
- $secure_url_flag = true;
95
- }
96
- } elseif ( isset( $query_parameters[$sns]['urls'] ) ) {
97
- $target_sns_url[$sns] = true;
98
- SCC_Common_Util::log( $query_parameters[$sns] );
99
- if ( SCC_Common_Util::is_secure_url( $query_parameters[$sns]['urls'] ) ) {
100
- $secure_url_flag = true;
101
- }
102
- }
103
- }
104
- }
105
-
106
- foreach ( $target_sns_url as $sns => $active ) {
107
- if ( $active ) {
108
- $query_parameters_origin[$sns] = $this->crawler->get_crawl_strategy_query_parameters( $sns );
109
- }
110
- }
111
-
112
- if ( $this->scheme_migration_mode && $secure_url_flag ) {
113
-
114
- foreach ( $target_sns_url as $sns => $active ) {
115
- if ( $active ) {
116
- if ( isset( $query_parameters[$sns]['url'] ) ) {
117
- $query_parameters[$sns]['url'] = SCC_Common_Util::get_normal_url( $query_parameters[$sns]['url'] );
118
- } elseif ( isset( $query_parameters[$sns]['urls'] ) ) {
119
- $query_parameters[$sns]['urls'] = SCC_Common_Util::get_normal_url( $query_parameters[$sns]['urls'] );
120
- }
121
- }
122
- }
123
-
124
- $target_sns_migrated = $target_sns_url;
125
-
126
- foreach ( $this->scheme_migration_exclude_keys as $sns ) {
127
- unset( $target_sns_migrated[$sns] );
128
- }
129
-
130
- foreach( $target_sns_url as $sns => $active ) {
131
- if ( $active ) {
132
- $this->crawler->set_crawl_strategy_query_parameters( $sns, $query_parameters[$sns] );
133
- }
134
- }
135
-
136
- $migrated_data = $this->crawler->get_data( $target_sns_migrated, NULL );
137
-
138
- SCC_Common_Util::log( $migrated_data );
139
-
140
- foreach ( $target_sns_migrated as $sns => $active ) {
141
- if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
142
- $data[$sns] = $data[$sns] + $migrated_data[$sns];
143
- }
144
- }
145
-
146
- foreach ( $target_sns_url as $sns => $active ) {
147
- if ( $active ) {
148
- $this->crawler->set_crawl_strategy_query_parameters( $sns, $query_parameters_origin[$sns] );
149
- }
150
- }
151
- }
152
-
153
- SCC_Common_Util::log( $data );
154
-
155
- if ( $data ) {
156
- $throttle = new SCC_Sleep_Throttle( $this->load_ratio );
157
-
158
- $throttle->reset();
159
- $throttle->start();
160
-
161
- $result = set_transient( $cache_key, $data, $cache_expiration );
162
-
163
- $throttle->stop();
164
-
165
- $retry_count = 0;
166
-
167
- while ( true ) {
168
- SCC_Common_Util::log( '[' . __METHOD__ . '] set_transient result (' . $cache_key . '): ' . $result );
169
-
170
- if ( $result ) {
171
- break;
172
- } else {
173
- if ( $retry_count < $this->retry_limit ) {
174
- SCC_Common_Util::log( '[' . __METHOD__ . '] sleep before set_transient retry (' . $cache_key . '): ' . $throttle->get_sleep_time() . ' sec.' );
175
-
176
- $throttle->sleep();
177
-
178
- ++$retry_count;
179
-
180
- SCC_Common_Util::log( '[' . __METHOD__ . '] count of set_transient retry (' . $cache_key . '): ' . $retry_count );
181
-
182
- $throttle->reset();
183
- $throttle->start();
184
-
185
- $result = set_transient( $cache_key, $data, $cache_expiration );
186
-
187
- $throttle->stop();
188
- } else {
189
- SCC_Common_Util::log( '[' . __METHOD__ . '] set_transient result (' . $cache_key . '): retry failed' );
190
- break;
191
- }
192
- }
193
- }
194
- }
195
-
196
- return $data;
197
- }
198
-
199
- }
200
-
201
- ?>
1
+ <?php
2
+ /*
3
+ class-scc-follow-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ abstract class SCC_Follow_Cache_Engine extends SCC_Cache_Engine {
31
+
32
+ /**
33
+ * Crawler instance
34
+ */
35
+ protected $crawler = NULL;
36
+
37
+ /**
38
+ * Cache target
39
+ */
40
+ protected $target_sns = array();
41
+
42
+ /**
43
+ * migration between http and https
44
+ */
45
+ protected $scheme_migration_mode = false;
46
+
47
+ /**
48
+ * excluded keys in scheme migration
49
+ */
50
+ protected $scheme_migration_exclude_keys = array();
51
+
52
+ /**
53
+ * load ratio for throttle
54
+ */
55
+ protected $load_ratio = 0.5;
56
+
57
+ /**
58
+ * Get and cache data for a given post
59
+ *
60
+ * @since 0.4.0
61
+ */
62
+ public function cache( $options = array() ) {
63
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
64
+
65
+ $cache_key = $options['cache_key'];
66
+ $target_sns = $options['target_sns'];
67
+ $cache_expiration = $options['cache_expiration'];
68
+
69
+ $data = $this->crawler->get_data( $target_sns, NULL );
70
+
71
+ SCC_Common_Util::log( $data );
72
+
73
+ $target_sns_base = $target_sns;
74
+
75
+ unset( $target_sns_base[SNS_Count_Cache::REF_CRAWL_DATE] );
76
+ unset( $target_sns_base[SNS_Count_Cache::REF_SHARE_TOTAL] );
77
+
78
+ $target_sns_url = array();
79
+
80
+ $query_parameters = array();
81
+
82
+ $query_parameters_origin = array();
83
+
84
+ $secure_url_flag = false;
85
+
86
+ foreach ( $target_sns_base as $sns => $active ) {
87
+ if ( $active ) {
88
+ $query_parameters[$sns] = $this->crawler->get_crawl_strategy_query_parameters( $sns );
89
+ SCC_Common_Util::log( $query_parameters[$sns] );
90
+ if ( isset( $query_parameters[$sns]['url'] ) ) {
91
+ $target_sns_url[$sns] = true;
92
+ SCC_Common_Util::log( $query_parameters[$sns] );
93
+ if ( SCC_Common_Util::is_secure_url( $query_parameters[$sns]['url'] ) ) {
94
+ $secure_url_flag = true;
95
+ }
96
+ } elseif ( isset( $query_parameters[$sns]['urls'] ) ) {
97
+ $target_sns_url[$sns] = true;
98
+ SCC_Common_Util::log( $query_parameters[$sns] );
99
+ if ( SCC_Common_Util::is_secure_url( $query_parameters[$sns]['urls'] ) ) {
100
+ $secure_url_flag = true;
101
+ }
102
+ }
103
+ }
104
+ }
105
+
106
+ foreach ( $target_sns_url as $sns => $active ) {
107
+ if ( $active ) {
108
+ $query_parameters_origin[$sns] = $this->crawler->get_crawl_strategy_query_parameters( $sns );
109
+ }
110
+ }
111
+
112
+ if ( $this->scheme_migration_mode && $secure_url_flag ) {
113
+
114
+ foreach ( $target_sns_url as $sns => $active ) {
115
+ if ( $active ) {
116
+ if ( isset( $query_parameters[$sns]['url'] ) ) {
117
+ $query_parameters[$sns]['url'] = SCC_Common_Util::get_normal_url( $query_parameters[$sns]['url'] );
118
+ } elseif ( isset( $query_parameters[$sns]['urls'] ) ) {
119
+ $query_parameters[$sns]['urls'] = SCC_Common_Util::get_normal_url( $query_parameters[$sns]['urls'] );
120
+ }
121
+ }
122
+ }
123
+
124
+ $target_sns_migrated = $target_sns_url;
125
+
126
+ foreach ( $this->scheme_migration_exclude_keys as $sns ) {
127
+ unset( $target_sns_migrated[$sns] );
128
+ }
129
+
130
+ foreach( $target_sns_url as $sns => $active ) {
131
+ if ( $active ) {
132
+ $this->crawler->set_crawl_strategy_query_parameters( $sns, $query_parameters[$sns] );
133
+ }
134
+ }
135
+
136
+ $migrated_data = $this->crawler->get_data( $target_sns_migrated, NULL );
137
+
138
+ SCC_Common_Util::log( $migrated_data );
139
+
140
+ foreach ( $target_sns_migrated as $sns => $active ) {
141
+ if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
142
+ $data[$sns] = $data[$sns] + $migrated_data[$sns];
143
+ }
144
+ }
145
+
146
+ foreach ( $target_sns_url as $sns => $active ) {
147
+ if ( $active ) {
148
+ $this->crawler->set_crawl_strategy_query_parameters( $sns, $query_parameters_origin[$sns] );
149
+ }
150
+ }
151
+ }
152
+
153
+ SCC_Common_Util::log( $data );
154
+
155
+ if ( $data ) {
156
+ $throttle = new SCC_Sleep_Throttle( $this->load_ratio );
157
+
158
+ $throttle->reset();
159
+ $throttle->start();
160
+
161
+ $result = set_transient( $cache_key, $data, $cache_expiration );
162
+
163
+ $throttle->stop();
164
+
165
+ $retry_count = 0;
166
+
167
+ while ( true ) {
168
+ SCC_Common_Util::log( '[' . __METHOD__ . '] set_transient result (' . $cache_key . '): ' . $result );
169
+
170
+ if ( $result ) {
171
+ break;
172
+ } else {
173
+ if ( $retry_count < $this->retry_limit ) {
174
+ SCC_Common_Util::log( '[' . __METHOD__ . '] sleep before set_transient retry (' . $cache_key . '): ' . $throttle->get_sleep_time() . ' sec.' );
175
+
176
+ $throttle->sleep();
177
+
178
+ ++$retry_count;
179
+
180
+ SCC_Common_Util::log( '[' . __METHOD__ . '] count of set_transient retry (' . $cache_key . '): ' . $retry_count );
181
+
182
+ $throttle->reset();
183
+ $throttle->start();
184
+
185
+ $result = set_transient( $cache_key, $data, $cache_expiration );
186
+
187
+ $throttle->stop();
188
+ } else {
189
+ SCC_Common_Util::log( '[' . __METHOD__ . '] set_transient result (' . $cache_key . '): retry failed' );
190
+ break;
191
+ }
192
+ }
193
+ }
194
+ }
195
+
196
+ return $data;
197
+ }
198
+
199
+ }
200
+
201
+ ?>
includes/class-scc-follow-crawl-strategy-factory.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-follow-crawl-strategy-factory.php
4
+
5
+ Description: This class is a data crawler whitch get share count using given API and cURL
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Crawl_Strategy_Factory {
31
+
32
+ /**
33
+ * Carete crawl strategy
34
+ *
35
+ * @since 0.9.0
36
+ */
37
+ public static function create_crawl_strategy( $sns ) {
38
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
39
+
40
+ switch ( $sns ) {
41
+ case SNS_Count_Cache::REF_FOLLOW_TWITTER:
42
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
43
+ return SCC_Follow_Twitter_Strategy::get_instance();
44
+ break;
45
+ case SNS_Count_Cache::REF_FOLLOW_FACEBOOK:
46
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
47
+ return SCC_Follow_Facebook_Strategy::get_instance();
48
+ break;
49
+ case SNS_Count_Cache::REF_FOLLOW_FEEDLY:
50
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
51
+ return SCC_Follow_Feedly_Strategy::get_instance();
52
+ break;
53
+ case SNS_Count_Cache::REF_FOLLOW_INSTAGRAM:
54
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
55
+ return SCC_Follow_Instagram_Strategy::get_instance();
56
+ break;
57
+ case SNS_Count_Cache::REF_FOLLOW_PUSH7:
58
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
59
+ return SCC_Follow_Push7_Strategy::get_instance();
60
+ break;
61
+ }
62
+ }
63
+
64
+ }
65
+
66
+ ?>
includes/class-scc-follow-crawler.php CHANGED
@@ -1,297 +1,265 @@
1
- <?php
2
- /*
3
- class-scc-follow-crawler.php
4
-
5
- Description: This class is a data crawler whitch get share count using given API and cURL
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Follow_Crawler extends SCC_Crawler {
31
-
32
- /**
33
- * Initialization
34
- *
35
- * @since 0.5.1
36
- */
37
- public function initialize( $options = array() ) {
38
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
39
-
40
- //$this->throttle = new Sleep_Throttle( 0.9 );
41
-
42
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
43
- if ( isset( $options['crawl_method'] ) ) $this->crawl_method = $options['crawl_method'];
44
- if ( isset( $options['timeout'] ) ) $this->timeout = $options['timeout'];
45
- if ( isset( $options['ssl_verification'] ) ) $this->ssl_verification = $options['ssl_verification'];
46
- if ( isset( $options['crawl_retry'] ) ) $this->crawl_retry = $options['crawl_retry'];
47
- if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
48
-
49
- $target_sns = $this->target_sns;
50
-
51
- unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
52
-
53
- foreach ( $target_sns as $sns => $active ) {
54
- if ( $active ) {
55
- $this->crawl_strategies[$sns] = $this->create_crawl_strategy( $sns );
56
- }
57
- }
58
-
59
- }
60
-
61
- /**
62
- * Carete crawl strategy
63
- *
64
- * @since 0.9.0
65
- */
66
- private function create_crawl_strategy( $sns ) {
67
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
-
69
- switch ( $sns ) {
70
- case SNS_Count_Cache::REF_FOLLOW_TWITTER:
71
- SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
72
- return SCC_Follow_Twitter_Strategy::get_instance();
73
- break;
74
- case SNS_Count_Cache::REF_FOLLOW_FACEBOOK:
75
- SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
76
- return SCC_Follow_Facebook_Strategy::get_instance();
77
- break;
78
- case SNS_Count_Cache::REF_FOLLOW_FEEDLY:
79
- SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
80
- return SCC_Follow_Feedly_Strategy::get_instance();
81
- break;
82
- case SNS_Count_Cache::REF_FOLLOW_INSTAGRAM:
83
- SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
84
- return SCC_Follow_Instagram_Strategy::get_instance();
85
- break;
86
- case SNS_Count_Cache::REF_FOLLOW_PUSH7:
87
- SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
88
- return SCC_Follow_Push7_Strategy::get_instance();
89
- break;
90
- }
91
- }
92
-
93
- /**
94
- * Check configuration
95
- *
96
- * @since 0.9.0
97
- */
98
- private function check_configurations( $target_sns ) {
99
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
100
-
101
- //$checked_target_sns = array();
102
-
103
- unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
104
-
105
- SCC_Common_Util::log( $target_sns );
106
-
107
- foreach ( $target_sns as $sns => $active ) {
108
- if ( $active ) {
109
- $target_sns[$sns] = $this->crawl_strategies[$sns]->check_configuration();
110
- }
111
- }
112
-
113
- $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] = true;
114
-
115
- return $target_sns;
116
-
117
- }
118
-
119
- /**
120
- * Implementation of abstract method. this method gets each share count
121
- *
122
- * @since 0.1.1
123
- */
124
- public function get_data( $target_sns, $options ) {
125
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
126
-
127
- SCC_Common_Util::log( $target_sns );
128
-
129
- $valid_target_sns = $this->check_configurations( $target_sns );
130
-
131
- SCC_Common_Util::log( $valid_target_sns );
132
-
133
- $query_urls = $this->build_query_urls( $valid_target_sns );
134
-
135
- SCC_Common_Util::log( $query_urls );
136
-
137
- $query_headers = $this->build_query_headers( $valid_target_sns );
138
-
139
- SCC_Common_Util::log( $query_headers );
140
-
141
- $data = array();
142
-
143
- $throttle = new SCC_Sleep_Throttle( 0.9 );
144
-
145
- $throttle->reset();
146
- $throttle->start();
147
-
148
- if ( $this->crawl_method === SNS_Count_Cache::OPT_COMMON_CRAWLER_METHOD_CURL ) {
149
- $data = SCC_Common_Util::multi_remote_get( $query_urls, $query_headers, $this->timeout, $this->ssl_verification, true );
150
- } else {
151
- $data = SCC_Common_Util::multi_remote_get( $query_urls, $query_headers, $this->timeout, $this->ssl_verification, false );
152
- }
153
-
154
- $throttle->stop();
155
-
156
- $retry_count = 0;
157
-
158
- while( true ) {
159
- $target_sns_retry = array();
160
-
161
- $tmp_count = $this->extract_count( $valid_target_sns, $data );
162
-
163
- foreach ( $valid_target_sns as $sns => $active ){
164
- if ( $active ) {
165
- if ( $tmp_count[$sns] === -1 ) {
166
- $target_sns_retry[$sns] = true;
167
- }
168
- }
169
- }
170
-
171
- if ( empty( $target_sns_retry ) ) {
172
- break;
173
- } else {
174
- SCC_Common_Util::log( '[' . __METHOD__ . '] crawl failure' );
175
- SCC_Common_Util::log( $target_sns_retry );
176
-
177
- if ( $retry_count < $this->retry_limit ) {
178
-
179
- SCC_Common_Util::log( '[' . __METHOD__ . '] sleep before crawl retry: ' . $throttle->get_sleep_time() . ' sec.' );
180
-
181
- $throttle->sleep();
182
-
183
- ++$retry_count;
184
-
185
- SCC_Common_Util::log( '[' . __METHOD__ . '] count of crawl retry: ' . $retry_count );
186
-
187
- $query_urls_retry = $this->build_query_urls( $target_sns_retry );
188
-
189
- $query_headers_retry = $this->build_query_headers( $target_sns_retry );
190
-
191
- $data_retry = array();
192
-
193
- $throttle->reset();
194
- $throttle->start();
195
-
196
- if ( $this->crawl_method === SNS_Count_Cache::OPT_COMMON_CRAWLER_METHOD_CURL ) {
197
- $data_retry = SCC_Common_Util::multi_remote_get( $query_urls_retry, $query_headers_retry, $this->timeout, $this->ssl_verification, true );
198
- } else {
199
- $data_retry = SCC_Common_Util::multi_remote_get( $query_urls_retry, $query_headers_retry, $this->timeout, $this->ssl_verification, false );
200
- }
201
-
202
- $throttle->stop();
203
-
204
- $data = array_merge( $data, $data_retry );
205
- } else {
206
- SCC_Common_Util::log( '[' . __METHOD__ . '] crawling: retry failed' );
207
- break;
208
- }
209
- }
210
- }
211
-
212
- return $this->extract_count( $target_sns, $data );
213
- }
214
-
215
- /**
216
- * build query
217
- *
218
- * @since 0.5.1
219
- */
220
- private function build_query_urls( $target_sns ) {
221
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
222
-
223
- $query_urls = array();
224
-
225
- unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
226
-
227
- SCC_Common_Util::log( $target_sns );
228
-
229
-
230
- foreach ( $target_sns as $sns => $active ) {
231
- if ( $active ) {
232
- $query_urls[$sns] = $this->crawl_strategies[$sns]->build_query_url();
233
- }
234
- }
235
-
236
- return $query_urls;
237
- }
238
-
239
- /**
240
- * build query
241
- *
242
- * @since 0.5.1
243
- */
244
- private function build_query_headers( $target_sns ) {
245
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
246
-
247
- $query_headers = array();
248
-
249
- unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
250
-
251
- SCC_Common_Util::log( $target_sns );
252
-
253
- foreach ( $target_sns as $sns => $active ) {
254
- if ( $active ) {
255
- $query_headers[$sns] = $this->crawl_strategies[$sns]->build_header();
256
- }
257
- }
258
-
259
- return $query_headers;
260
- }
261
-
262
- /**
263
- * extract count data from retrieved content
264
- *
265
- * @since 0.5.1
266
- */
267
- private function extract_count( $target_sns, $contents ) {
268
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
269
-
270
- $sns_counts = array();
271
-
272
- $extract_date = date_i18n( 'Y/m/d H:i:s' );
273
-
274
- SCC_Common_Util::log( $contents );
275
-
276
- foreach ( $target_sns as $sns => $active ) {
277
- if ( $active ) {
278
- if ( isset( $contents[$sns] ) ) {
279
- $sns_counts[$sns] = $this->crawl_strategies[$sns]->extract_count( $contents[$sns] );
280
- } else {
281
- $sns_counts[$sns] = (int) -1;
282
- }
283
- }
284
- }
285
-
286
- if ( isset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) && $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) {
287
- $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = $extract_date;
288
- } else {
289
- $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = '';
290
- }
291
-
292
- return $sns_counts;
293
- }
294
-
295
- }
296
-
297
- ?>
1
+ <?php
2
+ /*
3
+ class-scc-follow-crawler.php
4
+
5
+ Description: This class is a data crawler whitch get share count using given API and cURL
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Crawler extends SCC_Crawler {
31
+
32
+ /**
33
+ * Initialization
34
+ *
35
+ * @since 0.5.1
36
+ */
37
+ public function initialize( $options = array() ) {
38
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
39
+
40
+ //$this->throttle = new Sleep_Throttle( 0.9 );
41
+
42
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
43
+ if ( isset( $options['crawl_method'] ) ) $this->crawl_method = $options['crawl_method'];
44
+ if ( isset( $options['timeout'] ) ) $this->timeout = $options['timeout'];
45
+ if ( isset( $options['ssl_verification'] ) ) $this->ssl_verification = $options['ssl_verification'];
46
+ if ( isset( $options['crawl_retry'] ) ) $this->crawl_retry = $options['crawl_retry'];
47
+ if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
48
+
49
+ $target_sns = $this->target_sns;
50
+
51
+ unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
52
+
53
+ foreach ( $target_sns as $sns => $active ) {
54
+ if ( $active ) {
55
+ $this->crawl_strategies[$sns] = SCC_Follow_Crawl_Strategy_Factory::create_crawl_strategy( $sns );
56
+ }
57
+ }
58
+
59
+ }
60
+
61
+ /**
62
+ * Check configuration
63
+ *
64
+ * @since 0.9.0
65
+ */
66
+ private function check_configurations( $target_sns ) {
67
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
+
69
+ //$checked_target_sns = array();
70
+
71
+ unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
72
+
73
+ SCC_Common_Util::log( $target_sns );
74
+
75
+ foreach ( $target_sns as $sns => $active ) {
76
+ if ( $active ) {
77
+ $target_sns[$sns] = $this->crawl_strategies[$sns]->check_configuration();
78
+ }
79
+ }
80
+
81
+ $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] = true;
82
+
83
+ return $target_sns;
84
+
85
+ }
86
+
87
+ /**
88
+ * Implementation of abstract method. this method gets each share count
89
+ *
90
+ * @since 0.1.1
91
+ */
92
+ public function get_data( $target_sns, $options ) {
93
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
94
+
95
+ SCC_Common_Util::log( $target_sns );
96
+
97
+ $valid_target_sns = $this->check_configurations( $target_sns );
98
+
99
+ SCC_Common_Util::log( $valid_target_sns );
100
+
101
+ $query_urls = $this->build_query_urls( $valid_target_sns );
102
+
103
+ SCC_Common_Util::log( $query_urls );
104
+
105
+ $query_headers = $this->build_query_headers( $valid_target_sns );
106
+
107
+ SCC_Common_Util::log( $query_headers );
108
+
109
+ $data = array();
110
+
111
+ $throttle = new SCC_Sleep_Throttle( 0.9 );
112
+
113
+ $throttle->reset();
114
+ $throttle->start();
115
+
116
+ if ( $this->crawl_method === SNS_Count_Cache::OPT_COMMON_CRAWLER_METHOD_CURL ) {
117
+ $data = SCC_Common_Util::multi_remote_get( $query_urls, $query_headers, $this->timeout, $this->ssl_verification, true );
118
+ } else {
119
+ $data = SCC_Common_Util::multi_remote_get( $query_urls, $query_headers, $this->timeout, $this->ssl_verification, false );
120
+ }
121
+
122
+ $throttle->stop();
123
+
124
+ $retry_count = 0;
125
+
126
+ while( true ) {
127
+ $target_sns_retry = array();
128
+
129
+ $tmp_count = $this->extract_count( $valid_target_sns, $data );
130
+
131
+ foreach ( $valid_target_sns as $sns => $active ){
132
+ if ( $active ) {
133
+ if ( $tmp_count[$sns] === -1 ) {
134
+ $target_sns_retry[$sns] = true;
135
+ }
136
+ }
137
+ }
138
+
139
+ if ( empty( $target_sns_retry ) ) {
140
+ break;
141
+ } else {
142
+ SCC_Common_Util::log( '[' . __METHOD__ . '] crawl failure' );
143
+ SCC_Common_Util::log( $target_sns_retry );
144
+
145
+ if ( $retry_count < $this->retry_limit ) {
146
+
147
+ SCC_Common_Util::log( '[' . __METHOD__ . '] sleep before crawl retry: ' . $throttle->get_sleep_time() . ' sec.' );
148
+
149
+ $throttle->sleep();
150
+
151
+ ++$retry_count;
152
+
153
+ SCC_Common_Util::log( '[' . __METHOD__ . '] count of crawl retry: ' . $retry_count );
154
+
155
+ $query_urls_retry = $this->build_query_urls( $target_sns_retry );
156
+
157
+ $query_headers_retry = $this->build_query_headers( $target_sns_retry );
158
+
159
+ $data_retry = array();
160
+
161
+ $throttle->reset();
162
+ $throttle->start();
163
+
164
+ if ( $this->crawl_method === SNS_Count_Cache::OPT_COMMON_CRAWLER_METHOD_CURL ) {
165
+ $data_retry = SCC_Common_Util::multi_remote_get( $query_urls_retry, $query_headers_retry, $this->timeout, $this->ssl_verification, true );
166
+ } else {
167
+ $data_retry = SCC_Common_Util::multi_remote_get( $query_urls_retry, $query_headers_retry, $this->timeout, $this->ssl_verification, false );
168
+ }
169
+
170
+ $throttle->stop();
171
+
172
+ $data = array_merge( $data, $data_retry );
173
+ } else {
174
+ SCC_Common_Util::log( '[' . __METHOD__ . '] crawling: retry failed' );
175
+ break;
176
+ }
177
+ }
178
+ }
179
+
180
+ return $this->extract_count( $target_sns, $data );
181
+ }
182
+
183
+ /**
184
+ * build query
185
+ *
186
+ * @since 0.5.1
187
+ */
188
+ private function build_query_urls( $target_sns ) {
189
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
190
+
191
+ $query_urls = array();
192
+
193
+ unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
194
+
195
+ SCC_Common_Util::log( $target_sns );
196
+
197
+
198
+ foreach ( $target_sns as $sns => $active ) {
199
+ if ( $active ) {
200
+ $query_urls[$sns] = $this->crawl_strategies[$sns]->build_query_url();
201
+ }
202
+ }
203
+
204
+ return $query_urls;
205
+ }
206
+
207
+ /**
208
+ * build query
209
+ *
210
+ * @since 0.5.1
211
+ */
212
+ private function build_query_headers( $target_sns ) {
213
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
214
+
215
+ $query_headers = array();
216
+
217
+ unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
218
+
219
+ SCC_Common_Util::log( $target_sns );
220
+
221
+ foreach ( $target_sns as $sns => $active ) {
222
+ if ( $active ) {
223
+ $query_headers[$sns] = $this->crawl_strategies[$sns]->build_header();
224
+ }
225
+ }
226
+
227
+ return $query_headers;
228
+ }
229
+
230
+ /**
231
+ * extract count data from retrieved content
232
+ *
233
+ * @since 0.5.1
234
+ */
235
+ private function extract_count( $target_sns, $contents ) {
236
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
237
+
238
+ $sns_counts = array();
239
+
240
+ $extract_date = date_i18n( 'Y/m/d H:i:s' );
241
+
242
+ SCC_Common_Util::log( $contents );
243
+
244
+ foreach ( $target_sns as $sns => $active ) {
245
+ if ( $active ) {
246
+ if ( isset( $contents[$sns] ) ) {
247
+ $sns_counts[$sns] = $this->crawl_strategies[$sns]->extract_count( $contents[$sns] );
248
+ } else {
249
+ $sns_counts[$sns] = (int) -1;
250
+ }
251
+ }
252
+ }
253
+
254
+ if ( isset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) && $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) {
255
+ $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = $extract_date;
256
+ } else {
257
+ $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = '';
258
+ }
259
+
260
+ return $sns_counts;
261
+ }
262
+
263
+ }
264
+
265
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-scc-follow-facebook-strategy.php CHANGED
@@ -1,132 +1,138 @@
1
- <?php
2
- /*
3
- class-scc-follow-facebook-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Follow_Facebook_Strategy extends SCC_Crawl_Strategy {
31
-
32
- /**
33
- * SNS base url
34
- */
35
- const DEF_BASE_URL = 'https://graph.facebook.com/';
36
-
37
- /**
38
- * Class constarctor
39
- * Hook onto all of the actions and filters needed by the plugin.
40
- *
41
- */
42
- protected function __construct() {
43
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
-
45
- $this->method = 'GET';
46
- }
47
-
48
- /**
49
- * Initialization
50
- *
51
- * @since 0.9.0
52
- */
53
- public function initialize( $options = array() ) {
54
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
-
56
- if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
- if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
- if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
- }
60
-
61
- /**
62
- * Build header
63
- *
64
- * @since 0.9.0
65
- */
66
- public function build_header() {
67
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
- return null;
69
- }
70
-
71
- /**
72
- * Build query url
73
- *
74
- * @since 0.9.0
75
- */
76
- public function build_query_url() {
77
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
-
79
- $url = self::DEF_BASE_URL . $this->parameters['page_id'] . '/insights/page_fans/lifetime' . '?' . http_build_query( $this->query_parameters , '' , '&' );
80
-
81
- return $url;
82
- }
83
-
84
- /**
85
- * Extract count
86
- *
87
- * @since 0.9.0
88
- */
89
- public function extract_count( $content ) {
90
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
-
92
- $count = (int) -1;
93
-
94
- if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
-
96
- $json = json_decode( $content['data'], true );
97
-
98
- SCC_Common_Util::log( $json );
99
-
100
- if ( isset( $json['data'][0]['values'][2]['value'] ) && is_numeric( $json['data'][0]['values'][2]['value'] ) ) {
101
- $count = (int) $json['data'][0]['values'][2]['value'];
102
- } elseif ( isset( $json['data'][0]['values'][0]['value'] ) && is_numeric( $json['data'][0]['values'][0]['value'] ) ) {
103
- $count = (int) $json['data'][0]['values'][0]['value'];
104
- } else {
105
- $count = (int) -1;
106
- }
107
- } else {
108
- $count = (int) -1;
109
- }
110
-
111
- return $count;
112
- }
113
-
114
- /**
115
- * Check if required paramters are included or not.
116
- *
117
- * @since 0.9.0
118
- */
119
- public function check_configuration() {
120
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
121
-
122
- if ( isset( $this->parameters['client_id'] ) && $this->parameters['client_id'] &&
123
- isset( $this->parameters['client_secret'] ) && $this->parameters['client_secret'] &&
124
- isset( $this->query_parameters['access_token'] ) && $this->query_parameters['access_token'] &&
125
- isset( $this->parameters['page_id'] ) && $this->parameters['page_id'] ) {
126
- return true;
127
- } else {
128
- return false;
129
- }
130
- }
131
-
132
- }
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-follow-facebook-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Facebook_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url
34
+ */
35
+ const DEF_BASE_URL = 'https://graph.facebook.com/';
36
+
37
+ /**
38
+ * Class constarctor
39
+ * Hook onto all of the actions and filters needed by the plugin.
40
+ *
41
+ */
42
+ protected function __construct() {
43
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
+
45
+ $this->method = 'GET';
46
+ }
47
+
48
+ /**
49
+ * Initialization
50
+ *
51
+ * @since 0.9.0
52
+ */
53
+ public function initialize( $options = array() ) {
54
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
+
56
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
+ }
60
+
61
+ /**
62
+ * Build header
63
+ *
64
+ * @since 0.9.0
65
+ */
66
+ public function build_header() {
67
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
+ return null;
69
+ }
70
+
71
+ /**
72
+ * Build query url
73
+ *
74
+ * @since 0.9.0
75
+ */
76
+ public function build_query_url() {
77
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
+
79
+ $url = self::DEF_BASE_URL . $this->parameters['page_id'] . '/insights/page_fans/lifetime' . '?' . http_build_query( $this->query_parameters , '' , '&' );
80
+
81
+ return $url;
82
+ }
83
+
84
+ /**
85
+ * Extract count
86
+ *
87
+ * @since 0.9.0
88
+ */
89
+ public function extract_count( $content ) {
90
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
+
92
+ $count = (int) -1;
93
+
94
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
+
96
+ $json = json_decode( $content['data'], true );
97
+
98
+ SCC_Common_Util::log( $json );
99
+
100
+ if ( isset( $json['data'][0]['values'][2]['value'] ) && is_numeric( $json['data'][0]['values'][2]['value'] ) ) {
101
+ $count = (int) $json['data'][0]['values'][2]['value'];
102
+ } elseif ( isset( $json['data'][0]['values'][0]['value'] ) && is_numeric( $json['data'][0]['values'][0]['value'] ) ) {
103
+ $count = (int) $json['data'][0]['values'][0]['value'];
104
+ } else {
105
+ $count = (int) -1;
106
+ }
107
+ } else {
108
+ $count = (int) -1;
109
+ }
110
+
111
+ return $count;
112
+ }
113
+
114
+ public function set_query_parameter( $key, $value ) {
115
+ if ( $key === 'access_token' ) {
116
+ $this->query_parameters[$key] = $value;
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Check if required paramters are included or not.
122
+ *
123
+ * @since 0.9.0
124
+ */
125
+ public function check_configuration() {
126
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
127
+
128
+ if ( isset( $this->parameters['client_id'] ) && $this->parameters['client_id'] &&
129
+ isset( $this->parameters['client_secret'] ) && $this->parameters['client_secret'] &&
130
+ isset( $this->query_parameters['access_token'] ) && $this->query_parameters['access_token'] &&
131
+ isset( $this->parameters['page_id'] ) && $this->parameters['page_id'] ) {
132
+ return true;
133
+ } else {
134
+ return false;
135
+ }
136
+ }
137
+
138
+ }
includes/class-scc-follow-feedly-strategy.php CHANGED
@@ -1,124 +1,130 @@
1
- <?php
2
- /*
3
- class-scc-follow-feedly-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Follow_Feedly_Strategy extends SCC_Crawl_Strategy {
31
-
32
- /**
33
- * SNS base url
34
- */
35
- const DEF_BASE_URL = 'http://cloud.feedly.com/v3/feeds/feed%2F';
36
-
37
- /**
38
- * Class constarctor
39
- * Hook onto all of the actions and filters needed by the plugin.
40
- *
41
- */
42
- protected function __construct() {
43
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
-
45
- $this->method = 'GET';
46
- }
47
-
48
- /**
49
- * Initialization
50
- *
51
- * @since 0.9.0
52
- */
53
- public function initialize( $options = array() ) {
54
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
-
56
- if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
- if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
- if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
- }
60
-
61
- /**
62
- * Build header
63
- *
64
- * @since 0.9.0
65
- */
66
- public function build_header() {
67
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
- return null;
69
- }
70
-
71
- /**
72
- * Build query url
73
- *
74
- * @since 0.9.0
75
- */
76
- public function build_query_url() {
77
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
-
79
- $url = self::DEF_BASE_URL . rawurlencode( $this->query_parameters['url'] );
80
-
81
- return $url;
82
- }
83
-
84
- /**
85
- * Extract count
86
- *
87
- * @since 0.9.0
88
- */
89
- public function extract_count( $content ) {
90
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
-
92
- $count = (int) -1;
93
-
94
- if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
- $json = json_decode( $content['data'], true );
96
-
97
- if ( isset( $json['subscribers'] ) && is_numeric( $json['subscribers'] ) ) {
98
- $count = (int) $json['subscribers'];
99
- } else {
100
- $count = (int) -1;
101
- }
102
- } else {
103
- $count = (int) -1;
104
- }
105
-
106
- return $count;
107
- }
108
-
109
- /**
110
- * Check if required paramters are included or not.
111
- *
112
- * @since 0.9.0
113
- */
114
- public function check_configuration() {
115
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
116
-
117
- if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
118
- return true;
119
- } else {
120
- return false;
121
- }
122
- }
123
-
124
- }
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-follow-feedly-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Feedly_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url
34
+ */
35
+ const DEF_BASE_URL = 'http://cloud.feedly.com/v3/feeds/feed%2F';
36
+
37
+ /**
38
+ * Class constarctor
39
+ * Hook onto all of the actions and filters needed by the plugin.
40
+ *
41
+ */
42
+ protected function __construct() {
43
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
+
45
+ $this->method = 'GET';
46
+ }
47
+
48
+ /**
49
+ * Initialization
50
+ *
51
+ * @since 0.9.0
52
+ */
53
+ public function initialize( $options = array() ) {
54
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
+
56
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
+ }
60
+
61
+ /**
62
+ * Build header
63
+ *
64
+ * @since 0.9.0
65
+ */
66
+ public function build_header() {
67
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
+ return null;
69
+ }
70
+
71
+ /**
72
+ * Build query url
73
+ *
74
+ * @since 0.9.0
75
+ */
76
+ public function build_query_url() {
77
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
+
79
+ $url = self::DEF_BASE_URL . rawurlencode( $this->query_parameters['url'] );
80
+
81
+ return $url;
82
+ }
83
+
84
+ /**
85
+ * Extract count
86
+ *
87
+ * @since 0.9.0
88
+ */
89
+ public function extract_count( $content ) {
90
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
+
92
+ $count = (int) -1;
93
+
94
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
+ $json = json_decode( $content['data'], true );
96
+
97
+ if ( isset( $json['subscribers'] ) && is_numeric( $json['subscribers'] ) ) {
98
+ $count = (int) $json['subscribers'];
99
+ } else {
100
+ $count = (int) -1;
101
+ }
102
+ } else {
103
+ $count = (int) -1;
104
+ }
105
+
106
+ return $count;
107
+ }
108
+
109
+ public function set_query_parameter( $key, $value ) {
110
+ if ( $key === 'url' ) {
111
+ $this->query_parameters[$key] = $value;
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Check if required paramters are included or not.
117
+ *
118
+ * @since 0.9.0
119
+ */
120
+ public function check_configuration() {
121
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
122
+
123
+ if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
124
+ return true;
125
+ } else {
126
+ return false;
127
+ }
128
+ }
129
+
130
+ }
includes/class-scc-follow-instagram-strategy.php CHANGED
@@ -1,126 +1,132 @@
1
- <?php
2
- /*
3
- class-scc-follow-instagram-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Follow_Instagram_Strategy extends SCC_Crawl_Strategy {
31
-
32
- /**
33
- * SNS base url
34
- */
35
- const DEF_BASE_URL = 'https://api.instagram.com/v1/users/self/';
36
-
37
- /**
38
- * Class constarctor
39
- * Hook onto all of the actions and filters needed by the plugin.
40
- *
41
- */
42
- protected function __construct() {
43
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
-
45
- $this->method = 'GET';
46
- }
47
-
48
- /**
49
- * Initialization
50
- *
51
- * @since 0.9.0
52
- */
53
- public function initialize( $options = array() ) {
54
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
-
56
- if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
- if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
- if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
- }
60
-
61
- /**
62
- * Build header
63
- *
64
- * @since 0.9.0
65
- */
66
- public function build_header() {
67
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
- return null;
69
- }
70
-
71
- /**
72
- * Build query url
73
- *
74
- * @since 0.9.0
75
- */
76
- public function build_query_url() {
77
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
-
79
- $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
80
-
81
- return $url;
82
- }
83
-
84
- /**
85
- * Extract count
86
- *
87
- * @since 0.9.0
88
- */
89
- public function extract_count( $content ) {
90
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
-
92
- $count = (int) -1;
93
-
94
- if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
- $json = json_decode( $content['data'], true );
96
-
97
- if ( isset( $json['data']['counts']['followed_by'] ) && is_numeric( $json['data']['counts']['followed_by'] ) ) {
98
- $count = (int) $json['data']['counts']['followed_by'];
99
- } else {
100
- $count = (int) -1;
101
- }
102
- } else {
103
- $count = (int) -1;
104
- }
105
-
106
- return $count;
107
- }
108
-
109
- /**
110
- * Check if required paramters are included or not.
111
- *
112
- * @since 0.9.0
113
- */
114
- public function check_configuration() {
115
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
116
-
117
- if ( isset( $this->parameters['client_id'] ) && $this->parameters['client_id'] &&
118
- isset( $this->parameters['client_secret'] ) && $this->parameters['client_secret'] &&
119
- isset( $this->query_parameters['access_token'] ) && $this->query_parameters['access_token'] ) {
120
- return true;
121
- } else {
122
- return false;
123
- }
124
- }
125
-
126
- }
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-follow-instagram-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Instagram_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url
34
+ */
35
+ const DEF_BASE_URL = 'https://api.instagram.com/v1/users/self/';
36
+
37
+ /**
38
+ * Class constarctor
39
+ * Hook onto all of the actions and filters needed by the plugin.
40
+ *
41
+ */
42
+ protected function __construct() {
43
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
+
45
+ $this->method = 'GET';
46
+ }
47
+
48
+ /**
49
+ * Initialization
50
+ *
51
+ * @since 0.9.0
52
+ */
53
+ public function initialize( $options = array() ) {
54
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
+
56
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
+ }
60
+
61
+ /**
62
+ * Build header
63
+ *
64
+ * @since 0.9.0
65
+ */
66
+ public function build_header() {
67
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
+ return null;
69
+ }
70
+
71
+ /**
72
+ * Build query url
73
+ *
74
+ * @since 0.9.0
75
+ */
76
+ public function build_query_url() {
77
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
+
79
+ $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
80
+
81
+ return $url;
82
+ }
83
+
84
+ /**
85
+ * Extract count
86
+ *
87
+ * @since 0.9.0
88
+ */
89
+ public function extract_count( $content ) {
90
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
+
92
+ $count = (int) -1;
93
+
94
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
+ $json = json_decode( $content['data'], true );
96
+
97
+ if ( isset( $json['data']['counts']['followed_by'] ) && is_numeric( $json['data']['counts']['followed_by'] ) ) {
98
+ $count = (int) $json['data']['counts']['followed_by'];
99
+ } else {
100
+ $count = (int) -1;
101
+ }
102
+ } else {
103
+ $count = (int) -1;
104
+ }
105
+
106
+ return $count;
107
+ }
108
+
109
+ public function set_query_parameter( $key, $value ) {
110
+ if ( $key === 'access_token' ) {
111
+ $this->query_parameters[$key] = $value;
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Check if required paramters are included or not.
117
+ *
118
+ * @since 0.9.0
119
+ */
120
+ public function check_configuration() {
121
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
122
+
123
+ if ( isset( $this->parameters['client_id'] ) && $this->parameters['client_id'] &&
124
+ isset( $this->parameters['client_secret'] ) && $this->parameters['client_secret'] &&
125
+ isset( $this->query_parameters['access_token'] ) && $this->query_parameters['access_token'] ) {
126
+ return true;
127
+ } else {
128
+ return false;
129
+ }
130
+ }
131
+
132
+ }
includes/class-scc-follow-lazy-cache-engine.php CHANGED
@@ -1,192 +1,210 @@
1
- <?php
2
- /*
3
- class-scc-follow-lazy-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Follow_Lazy_Cache_Engine extends SCC_Follow_Cache_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- const DEF_TRANSIENT_PREFIX = 'scc_follow_count_';
36
-
37
- /**
38
- * Cron name to schedule cache processing
39
- */
40
- const DEF_PRIME_CRON = 'scc_follow_lazycache_prime';
41
-
42
- /**
43
- * Cron name to execute cache processing
44
- */
45
- const DEF_EXECUTE_CRON = 'scc_follow_lazycache_exec';
46
-
47
- /**
48
- * Schedule name for cache processing
49
- */
50
- const DEF_EVENT_SCHEDULE = 'follow_lazy_cache_event';
51
-
52
- /**
53
- * Schedule description for cache processing
54
- */
55
- const DEF_EVENT_DESCRIPTION = '[SCC] Follow Lazy Cache Interval';
56
-
57
- /**
58
- * Interval cheking and caching target data
59
- */
60
- private $check_interval = 600;
61
-
62
- /**
63
- * Latency suffix
64
- */
65
- private $check_latency = 10;
66
-
67
- /**
68
- * Initialization
69
- *
70
- * @since 0.1.1
71
- */
72
- public function initialize( $options = array() ) {
73
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
74
-
75
- $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
76
- $this->prime_cron = self::DEF_PRIME_CRON;
77
- $this->execute_cron = self::DEF_EXECUTE_CRON;
78
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
79
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
80
-
81
- $this->load_ratio = 0.5;
82
-
83
- if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
84
- if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
85
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
86
- if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
87
- if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
88
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
89
- if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
90
- if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
91
- if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
92
- if ( isset( $options['cache_retry'] ) ) $this->cache_retry = $options['cache_retry'];
93
- if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
94
-
95
- add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 0 );
96
- }
97
-
98
- /**
99
- * Register base schedule for this engine
100
- *
101
- * @since 0.1.0
102
- */
103
- public function register_schedule() {
104
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
105
- }
106
-
107
- /**
108
- * Unregister base schedule for this engine
109
- *
110
- * @since 0.1.0
111
- */
112
- public function unregister_schedule() {
113
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
114
-
115
- SCC_WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
116
- }
117
-
118
- /**
119
- * Schedule data retrieval and cache processing
120
- *
121
- * @since 0.4.0
122
- */
123
- public function prime_cache() {
124
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
125
-
126
- $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_latency;
127
-
128
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_latency: ' . $this->check_latency );
129
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
130
-
131
- wp_schedule_single_event( $next_exec_time, $this->execute_cron, array() );
132
- }
133
-
134
- /**
135
- * Get and cache data of each published post
136
- *
137
- * @since 0.4.0
138
- */
139
- public function execute_cache() {
140
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
141
-
142
- $cache_expiration = $this->get_cache_expiration();
143
-
144
- SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
145
-
146
- $transient_id = $this->get_cache_key( 'follow' );
147
-
148
- $options = array(
149
- 'cache_key' => $transient_id,
150
- 'target_sns' => $this->target_sns,
151
- 'cache_expiration' => $cache_expiration
152
- );
153
-
154
- // Primary cache
155
- $this->cache( $options );
156
-
157
- // Secondary cache
158
- $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
159
- }
160
-
161
- /**
162
- * Get cache expiration based on current number of total post and page
163
- *
164
- * @since 0.4.0
165
- */
166
- protected function get_cache_expiration() {
167
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
168
-
169
- return 3 * $this->check_interval;
170
- }
171
-
172
- /**
173
- * Initialize meta key for ranking
174
- *
175
- * @since 0.3.0
176
- */
177
- public function initialize_cache() {
178
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
179
- }
180
-
181
- /**
182
- * Clear meta key for ranking
183
- *
184
- * @since 0.3.0
185
- */
186
- public function clear_cache() {
187
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
188
- }
189
-
190
- }
191
-
192
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-follow-lazy-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Lazy_Cache_Engine extends SCC_Follow_Cache_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ const DEF_TRANSIENT_PREFIX = 'scc_follow_count_';
36
+
37
+ /**
38
+ * Cron name to schedule cache processing
39
+ */
40
+ const DEF_PRIME_CRON = 'scc_follow_lazycache_prime';
41
+
42
+ /**
43
+ * Cron name to execute cache processing
44
+ */
45
+ const DEF_EXECUTE_CRON = 'scc_follow_lazycache_exec';
46
+
47
+ /**
48
+ * Schedule name for cache processing
49
+ */
50
+ const DEF_EVENT_SCHEDULE = 'follow_lazy_cache_event';
51
+
52
+ /**
53
+ * Schedule description for cache processing
54
+ */
55
+ const DEF_EVENT_DESCRIPTION = '[SCC] Follow Lazy Cache Interval';
56
+
57
+ /**
58
+ * Interval cheking and caching target data
59
+ */
60
+ private $check_interval = 600;
61
+
62
+ /**
63
+ * Latency suffix
64
+ */
65
+ private $check_latency = 10;
66
+
67
+ /**
68
+ * Initialization
69
+ *
70
+ * @since 0.1.1
71
+ */
72
+ public function initialize( $options = array() ) {
73
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
74
+
75
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
76
+ $this->prime_cron = self::DEF_PRIME_CRON;
77
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
78
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
79
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
80
+
81
+ $this->load_ratio = 0.5;
82
+
83
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
84
+ if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
85
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
86
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
87
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
88
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
89
+ if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
90
+ if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
91
+ if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
92
+ if ( isset( $options['cache_retry'] ) ) $this->cache_retry = $options['cache_retry'];
93
+ if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
94
+
95
+ add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 0 );
96
+ }
97
+
98
+ /**
99
+ * Register base schedule for this engine
100
+ *
101
+ * @since 0.1.0
102
+ */
103
+ public function register_schedule() {
104
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
105
+ }
106
+
107
+ /**
108
+ * Unregister base schedule for this engine
109
+ *
110
+ * @since 0.1.0
111
+ */
112
+ public function unregister_schedule() {
113
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
114
+
115
+ SCC_WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
116
+ }
117
+
118
+ /**
119
+ * Schedule data retrieval and cache processing
120
+ *
121
+ * @since 0.4.0
122
+ */
123
+ public function prime_cache() {
124
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
125
+
126
+ $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_latency;
127
+
128
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_latency: ' . $this->check_latency );
129
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
130
+
131
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array() );
132
+ }
133
+
134
+ /**
135
+ * Get and cache data of each published post
136
+ *
137
+ * @since 0.4.0
138
+ */
139
+ public function execute_cache() {
140
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
141
+
142
+ $cache_expiration = $this->get_cache_expiration();
143
+
144
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
145
+
146
+ $transient_id = $this->get_cache_key( 'follow' );
147
+
148
+ $options = array(
149
+ 'cache_key' => $transient_id,
150
+ 'target_sns' => $this->target_sns,
151
+ 'cache_expiration' => $cache_expiration
152
+ );
153
+
154
+ // Primary cache
155
+ $this->cache( $options );
156
+
157
+ // Secondary cache
158
+ $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
159
+ }
160
+
161
+ /**
162
+ * Get cache expiration based on current number of total post and page
163
+ *
164
+ * @since 0.4.0
165
+ */
166
+ protected function get_cache_expiration() {
167
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
168
+
169
+ return 3 * $this->check_interval;
170
+ }
171
+
172
+ /**
173
+ * Initialize meta key for ranking
174
+ *
175
+ * @since 0.3.0
176
+ */
177
+ public function initialize_cache() {
178
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
179
+ }
180
+
181
+ /**
182
+ * Clear meta key for ranking
183
+ *
184
+ * @since 0.3.0
185
+ */
186
+ public function clear_cache() {
187
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
188
+ }
189
+
190
+ /**
191
+ * Get cache
192
+ *
193
+ * @since 0.10.1
194
+ */
195
+ public function get_cache( $options = array() ) {
196
+
197
+ $transient_id = $this->get_cache_key( 'follow' );
198
+
199
+ $sns_followers = array();
200
+
201
+ if ( false !== ( $sns_followers = get_transient( $transient_id ) ) ) {
202
+ return $sns_followers;
203
+ } else {
204
+ return $this->delegate_order( SCC_Order::ORDER_GET_SECOND_CACHE, $options );
205
+ }
206
+ }
207
+
208
+ }
209
+
210
+ ?>
includes/class-scc-follow-push7-strategy.php CHANGED
@@ -1,124 +1,128 @@
1
- <?php
2
- /*
3
- class-scc-follow-push7-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Follow_Push7_Strategy extends SCC_Crawl_Strategy {
31
-
32
- /**
33
- * SNS base url
34
- */
35
- const DEF_BASE_URL = 'https://api.push7.jp/api/v1/';
36
-
37
- /**
38
- * Class constarctor
39
- * Hook onto all of the actions and filters needed by the plugin.
40
- *
41
- */
42
- protected function __construct() {
43
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
-
45
- $this->method = 'GET';
46
- }
47
-
48
- /**
49
- * Initialization
50
- *
51
- * @since 0.9.0
52
- */
53
- public function initialize( $options = array() ) {
54
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
-
56
- if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
- if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
- if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
- }
60
-
61
- /**
62
- * Build header
63
- *
64
- * @since 0.9.0
65
- */
66
- public function build_header() {
67
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
- return null;
69
- }
70
-
71
- /**
72
- * Build query url
73
- *
74
- * @since 0.9.0
75
- */
76
- public function build_query_url() {
77
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
-
79
- $url = self::DEF_BASE_URL . $this->parameters['appno'] . '/head';
80
-
81
- return $url;
82
- }
83
-
84
- /**
85
- * Extract count
86
- *
87
- * @since 0.9.0
88
- */
89
- public function extract_count( $content ) {
90
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
-
92
- $count = (int) -1;
93
-
94
- if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
- $json = json_decode( $content['data'], true );
96
-
97
- if ( isset( $json['subscribers'] ) && is_numeric( $json['subscribers'] ) ) {
98
- $count = (int) $json['subscribers'];
99
- } else {
100
- $count = (int) -1;
101
- }
102
- } else {
103
- $count = (int) -1;
104
- }
105
-
106
- return $count;
107
- }
108
-
109
- /**
110
- * Check if required paramters are included or not.
111
- *
112
- * @since 0.9.0
113
- */
114
- public function check_configuration() {
115
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
116
-
117
- if ( isset( $this->parameters['appno'] ) && $this->parameters['appno'] ) {
118
- return true;
119
- } else {
120
- return false;
121
- }
122
- }
123
-
124
- }
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-follow-push7-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Push7_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url
34
+ */
35
+ const DEF_BASE_URL = 'https://api.push7.jp/api/v1/';
36
+
37
+ /**
38
+ * Class constarctor
39
+ * Hook onto all of the actions and filters needed by the plugin.
40
+ *
41
+ */
42
+ protected function __construct() {
43
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
+
45
+ $this->method = 'GET';
46
+ }
47
+
48
+ /**
49
+ * Initialization
50
+ *
51
+ * @since 0.9.0
52
+ */
53
+ public function initialize( $options = array() ) {
54
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
+
56
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
+ }
60
+
61
+ /**
62
+ * Build header
63
+ *
64
+ * @since 0.9.0
65
+ */
66
+ public function build_header() {
67
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
+ return null;
69
+ }
70
+
71
+ /**
72
+ * Build query url
73
+ *
74
+ * @since 0.9.0
75
+ */
76
+ public function build_query_url() {
77
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
+
79
+ $url = self::DEF_BASE_URL . $this->parameters['appno'] . '/head';
80
+
81
+ return $url;
82
+ }
83
+
84
+ /**
85
+ * Extract count
86
+ *
87
+ * @since 0.9.0
88
+ */
89
+ public function extract_count( $content ) {
90
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
+
92
+ $count = (int) -1;
93
+
94
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
+ $json = json_decode( $content['data'], true );
96
+
97
+ if ( isset( $json['subscribers'] ) && is_numeric( $json['subscribers'] ) ) {
98
+ $count = (int) $json['subscribers'];
99
+ } else {
100
+ $count = (int) -1;
101
+ }
102
+ } else {
103
+ $count = (int) -1;
104
+ }
105
+
106
+ return $count;
107
+ }
108
+
109
+ public function set_query_parameter( $key, $value ) {
110
+
111
+ }
112
+
113
+ /**
114
+ * Check if required paramters are included or not.
115
+ *
116
+ * @since 0.9.0
117
+ */
118
+ public function check_configuration() {
119
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
120
+
121
+ if ( isset( $this->parameters['appno'] ) && $this->parameters['appno'] ) {
122
+ return true;
123
+ } else {
124
+ return false;
125
+ }
126
+ }
127
+
128
+ }
includes/class-scc-follow-restore-cache-engine.php CHANGED
@@ -1,208 +1,233 @@
1
- <?php
2
- /*
3
- class-scc-follow-restore-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch restore cache data from second cache.
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
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Follow_Restore_Cache_Engine extends SCC_Cache_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- const DEF_TRANSIENT_PREFIX = 'scc_follow_count_';
36
-
37
- /**
38
- * Cron name to schedule cache processing
39
- */
40
- const DEF_PRIME_CRON = 'scc_follow_restorecache_prime';
41
-
42
- /**
43
- * Cron name to execute cache processing
44
- */
45
- const DEF_EXECUTE_CRON = 'scc_follow_restorecache_exec';
46
-
47
- /**
48
- * Schedule name for cache processing
49
- */
50
- const DEF_EVENT_SCHEDULE = 'follow_restore_cache_event';
51
-
52
- /**
53
- * Schedule description for cache processing
54
- */
55
- const DEF_EVENT_DESCRIPTION = '[SCC] Follow Restore Cache Interval';
56
-
57
- /**
58
- * Interval cheking and caching target data
59
- */
60
- private $check_interval = 600;
61
-
62
- /**
63
- * Latency suffix
64
- */
65
- private $check_latency = 10;
66
-
67
- /**
68
- * Initialization
69
- *
70
- * @since 0.1.1
71
- */
72
- public function initialize( $options = array() ) {
73
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
74
-
75
- $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
76
- $this->prime_cron = self::DEF_PRIME_CRON;
77
- $this->execute_cron = self::DEF_EXECUTE_CRON;
78
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
79
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
80
-
81
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
82
- if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
83
- if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
84
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
85
- if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
86
-
87
- add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 0 );
88
- }
89
-
90
- /**
91
- * Register base schedule for this engine
92
- *
93
- * @since 0.1.0
94
- */
95
- public function register_schedule() {
96
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
97
- }
98
-
99
- /**
100
- * Unregister base schedule for this engine
101
- *
102
- * @since 0.1.0
103
- */
104
- public function unregister_schedule() {
105
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
106
-
107
- SCC_WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
108
- }
109
-
110
- /**
111
- * Schedule data retrieval and cache processing
112
- *
113
- * @since 0.4.0
114
- */
115
- public function prime_cache() {
116
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
117
-
118
- $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_latency;
119
-
120
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_latency: ' . $this->check_latency );
121
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
122
-
123
- wp_schedule_single_event( $next_exec_time, $this->execute_cron, array() );
124
- }
125
-
126
- /**
127
- * Get and cache data of each published post
128
- *
129
- * @since 0.4.0
130
- */
131
- public function execute_cache() {
132
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
133
-
134
- $cache_expiration = $this->get_cache_expiration();
135
-
136
- SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
137
-
138
- $transient_id = $this->get_cache_key( 'follow' );
139
-
140
- $options = array(
141
- 'cache_key' => $transient_id,
142
- 'target_sns' => $this->target_sns,
143
- 'cache_expiration' => $cache_expiration
144
- );
145
-
146
- $this->cache( $options );
147
- }
148
-
149
- /**
150
- * Get and cache data for a given post
151
- *
152
- * @since 0.1.1
153
- */
154
- public function cache( $options = array() ) {
155
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
156
-
157
- $transient_id = $options['cache_key'];
158
- $target_sns = $options['target_sns'];
159
- $cache_expiration = $options['cache_expiration'];
160
-
161
- $sns_followers = array();
162
-
163
- $option_key = $this->get_cache_key( 'follow' );
164
-
165
- if ( false !== ( $sns_followers = get_option( $option_key ) ) ) {
166
- } else {
167
- foreach ( $this->share_base_cache_target as $sns => $active ) {
168
- if ( $active ) {
169
- $sns_followers[$sns] = (int) -1;
170
- }
171
- }
172
- }
173
-
174
- $result = set_transient( $transient_id, $sns_followers, $cache_expiration );
175
- }
176
-
177
- /**
178
- * Get cache expiration based on current number of total post and page
179
- *
180
- * @since 0.4.0
181
- */
182
- protected function get_cache_expiration() {
183
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
184
-
185
- return 3 * $this->check_interval;
186
- }
187
-
188
- /**
189
- * Initialize meta key for ranking
190
- *
191
- * @since 0.3.0
192
- */
193
- public function initialize_cache() {
194
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
195
- }
196
-
197
- /**
198
- * Clear meta key for ranking
199
- *
200
- * @since 0.3.0
201
- */
202
- public function clear_cache() {
203
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
204
- }
205
-
206
- }
207
-
208
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-follow-restore-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch restore cache data from second cache.
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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Restore_Cache_Engine extends SCC_Cache_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ const DEF_TRANSIENT_PREFIX = 'scc_follow_count_';
36
+
37
+ /**
38
+ * Cron name to schedule cache processing
39
+ */
40
+ const DEF_PRIME_CRON = 'scc_follow_restorecache_prime';
41
+
42
+ /**
43
+ * Cron name to execute cache processing
44
+ */
45
+ const DEF_EXECUTE_CRON = 'scc_follow_restorecache_exec';
46
+
47
+ /**
48
+ * Schedule name for cache processing
49
+ */
50
+ const DEF_EVENT_SCHEDULE = 'follow_restore_cache_event';
51
+
52
+ /**
53
+ * Schedule description for cache processing
54
+ */
55
+ const DEF_EVENT_DESCRIPTION = '[SCC] Follow Restore Cache Interval';
56
+
57
+ /**
58
+ * Interval cheking and caching target data
59
+ */
60
+ private $check_interval = 600;
61
+
62
+ /**
63
+ * Latency suffix
64
+ */
65
+ private $check_latency = 10;
66
+
67
+ /**
68
+ * Initialization
69
+ *
70
+ * @since 0.1.1
71
+ */
72
+ public function initialize( $options = array() ) {
73
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
74
+
75
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
76
+ $this->prime_cron = self::DEF_PRIME_CRON;
77
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
78
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
79
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
80
+
81
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
82
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
83
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
84
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
85
+ if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
86
+
87
+ add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 0 );
88
+ }
89
+
90
+ /**
91
+ * Register base schedule for this engine
92
+ *
93
+ * @since 0.1.0
94
+ */
95
+ public function register_schedule() {
96
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
97
+ }
98
+
99
+ /**
100
+ * Unregister base schedule for this engine
101
+ *
102
+ * @since 0.1.0
103
+ */
104
+ public function unregister_schedule() {
105
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
106
+
107
+ SCC_WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
108
+ }
109
+
110
+ /**
111
+ * Schedule data retrieval and cache processing
112
+ *
113
+ * @since 0.4.0
114
+ */
115
+ public function prime_cache() {
116
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
117
+
118
+ $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_latency;
119
+
120
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_latency: ' . $this->check_latency );
121
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
122
+
123
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array() );
124
+ }
125
+
126
+ /**
127
+ * Get and cache data of each published post
128
+ *
129
+ * @since 0.4.0
130
+ */
131
+ public function execute_cache() {
132
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
133
+
134
+ $cache_expiration = $this->get_cache_expiration();
135
+
136
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
137
+
138
+ $transient_id = $this->get_cache_key( 'follow' );
139
+
140
+ $options = array(
141
+ 'cache_key' => $transient_id,
142
+ 'target_sns' => $this->target_sns,
143
+ 'cache_expiration' => $cache_expiration
144
+ );
145
+
146
+ $this->cache( $options );
147
+ }
148
+
149
+ /**
150
+ * Get and cache data for a given post
151
+ *
152
+ * @since 0.1.1
153
+ */
154
+ public function cache( $options = array() ) {
155
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
156
+
157
+ $transient_id = $options['cache_key'];
158
+ $target_sns = $options['target_sns'];
159
+ $cache_expiration = $options['cache_expiration'];
160
+
161
+ $sns_followers = array();
162
+
163
+ $option_key = $this->get_cache_key( 'follow' );
164
+
165
+ if ( false !== ( $sns_followers = get_option( $option_key ) ) ) {
166
+ } else {
167
+ foreach ( $this->share_base_cache_target as $sns => $active ) {
168
+ if ( $active ) {
169
+ $sns_followers[$sns] = (int) -1;
170
+ }
171
+ }
172
+ }
173
+
174
+ $result = set_transient( $transient_id, $sns_followers, $cache_expiration );
175
+ }
176
+
177
+ /**
178
+ * Get cache expiration based on current number of total post and page
179
+ *
180
+ * @since 0.4.0
181
+ */
182
+ protected function get_cache_expiration() {
183
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
184
+
185
+ return 3 * $this->check_interval;
186
+ }
187
+
188
+ /**
189
+ * Initialize meta key for ranking
190
+ *
191
+ * @since 0.3.0
192
+ */
193
+ public function initialize_cache() {
194
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
195
+ }
196
+
197
+ /**
198
+ * Clear meta key for ranking
199
+ *
200
+ * @since 0.3.0
201
+ */
202
+ public function clear_cache() {
203
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
204
+ }
205
+
206
+ /**
207
+ * Get cache
208
+ *
209
+ * @since 0.10.1
210
+ */
211
+ public function get_cache( $options = array() ) {
212
+
213
+ $target_sns = $options['target_sns'];
214
+
215
+ $sns_followers = array();
216
+
217
+ $option_key = $this->get_cache_key( 'follow' );
218
+
219
+ if ( false !== ( $sns_followers = get_option( $option_key ) ) ) {
220
+ } else {
221
+ foreach ( $this->share_base_cache_target as $sns => $active ) {
222
+ if ( $active ) {
223
+ $sns_followers[$sns] = (int) -1;
224
+ }
225
+ }
226
+ }
227
+
228
+ return $sns_followers;
229
+ }
230
+
231
+ }
232
+
233
+ ?>
includes/class-scc-follow-second-cache-engine.php CHANGED
@@ -1,228 +1,253 @@
1
- <?php
2
- /*
3
- class-scc-follow-second-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Follow_Second_Cache_Engine extends SCC_Cache_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- const DEF_TRANSIENT_PREFIX = 'scc_follow_count_';
36
-
37
- /**
38
- * Cron name to schedule cache processing
39
- */
40
- const DEF_PRIME_CRON = 'scc_follow_2ndcache_prime';
41
-
42
- /**
43
- * Cron name to execute cache processing
44
- */
45
- const DEF_EXECUTE_CRON = 'scc_follow_2ndcache_exec';
46
-
47
- /**
48
- * Schedule name for cache processing
49
- */
50
- const DEF_EVENT_SCHEDULE = 'follow_second_cache_event';
51
-
52
- /**
53
- * Schedule description for cache processing
54
- */
55
- const DEF_EVENT_DESCRIPTION = '[SCC] Follow Second Cache Interval';
56
-
57
- /**
58
- * Interval cheking and caching target data
59
- */
60
- private $check_interval = 600;
61
-
62
- /**
63
- * Prefix of cache ID
64
- */
65
- private $meta_key_prefix = 'scc_follow_count_';
66
-
67
- /**
68
- * Cache target
69
- */
70
- private $target_sns = array();
71
-
72
- /**
73
- * Initialization
74
- *
75
- * @since 0.1.1
76
- */
77
- public function initialize( $options = array() ) {
78
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
79
-
80
- $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
81
- $this->prime_cron = self::DEF_PRIME_CRON;
82
- $this->execute_cron = self::DEF_EXECUTE_CRON;
83
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
84
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
85
-
86
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
87
- if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
88
- if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
89
- if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
90
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
91
- if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
92
- if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
93
- if ( isset( $options['meta_key_prefix'] ) ) $this->meta_key_prefix = $options['meta_key_prefix'];
94
-
95
- add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
96
- add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
97
- add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 0 );
98
- }
99
-
100
- /**
101
- * Register event schedule for this engine
102
- *
103
- * @since 0.1.0
104
- */
105
- public function schedule_check_interval( $schedules ) {
106
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
107
-
108
- $schedules[$this->event_schedule] = array(
109
- 'interval' => $this->check_interval,
110
- 'display' => $this->event_description
111
- );
112
-
113
- return $schedules;
114
- }
115
-
116
- /**
117
- * Schedule data retrieval and cache processing
118
- *
119
- * @since 0.3.0
120
- */
121
- public function prime_cache() {
122
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
123
-
124
- $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
125
-
126
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
127
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
128
-
129
- wp_schedule_single_event( $next_exec_time, $this->execute_cron );
130
- }
131
-
132
- /**
133
- * Get and cache data of each published post and page
134
- *
135
- * @since 0.4.0
136
- */
137
- public function execute_cache() {
138
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
139
-
140
- $url = get_feed_link();
141
-
142
- $transient_id = $this->get_cache_key( 'follow' );
143
-
144
- $options = array(
145
- 'cache_key' => $transient_id,
146
- 'target_sns' => $this->target_sns,
147
- );
148
-
149
- $this->cache( $options );
150
- }
151
-
152
- /**
153
- * Get and cache data for a given post
154
- *
155
- * @since 0.1.1
156
- */
157
- public function cache( $options = array() ) {
158
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
159
-
160
- $transient_id = $options['cache_key'];
161
- $target_sns = $options['target_sns'];
162
-
163
- if ( false !== ( $sns_followers = get_transient( $transient_id ) ) ) {
164
-
165
- $option_key = $this->get_cache_key( 'follow' );
166
-
167
- update_option( $option_key, $sns_followers );
168
- }
169
- }
170
-
171
- /**
172
- * Get cache expiration based on current number of total post and page
173
- *
174
- * @since 0.2.0
175
- */
176
- protected function get_cache_expiration() {
177
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
178
-
179
- return 0;
180
- }
181
-
182
- /**
183
- * Initialize meta key for ranking
184
- *
185
- * @since 0.3.0
186
- */
187
- public function initialize_cache() {
188
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
189
-
190
- $option_key = $this->get_cache_key( 'follow' );
191
-
192
- $sns_followers = array();
193
-
194
- foreach ( $this->target_sns as $sns => $active ) {
195
- if ( $active ) {
196
- $sns_followers[$sns] = (int) -1;
197
- }
198
- }
199
-
200
- update_option( $option_key, $sns_followers );
201
- }
202
-
203
- /**
204
- * Clear meta key for ranking
205
- *
206
- * @since 0.3.0
207
- */
208
- public function clear_cache() {
209
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
210
-
211
- $option_key = $this->get_cache_key( 'follow' );
212
-
213
- delete_option( $option_key );
214
-
215
- // Compatibility for old version
216
- foreach ( $this->target_sns as $sns => $active ) {
217
-
218
- $option_key = $this->get_cache_key( $sns );
219
-
220
- if ( $active ) {
221
- delete_option( $option_key );
222
- }
223
- }
224
- }
225
-
226
- }
227
-
228
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-follow-second-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Second_Cache_Engine extends SCC_Cache_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ const DEF_TRANSIENT_PREFIX = 'scc_follow_count_';
36
+
37
+ /**
38
+ * Cron name to schedule cache processing
39
+ */
40
+ const DEF_PRIME_CRON = 'scc_follow_2ndcache_prime';
41
+
42
+ /**
43
+ * Cron name to execute cache processing
44
+ */
45
+ const DEF_EXECUTE_CRON = 'scc_follow_2ndcache_exec';
46
+
47
+ /**
48
+ * Schedule name for cache processing
49
+ */
50
+ const DEF_EVENT_SCHEDULE = 'follow_second_cache_event';
51
+
52
+ /**
53
+ * Schedule description for cache processing
54
+ */
55
+ const DEF_EVENT_DESCRIPTION = '[SCC] Follow Second Cache Interval';
56
+
57
+ /**
58
+ * Interval cheking and caching target data
59
+ */
60
+ private $check_interval = 600;
61
+
62
+ /**
63
+ * Prefix of cache ID
64
+ */
65
+ private $meta_key_prefix = 'scc_follow_count_';
66
+
67
+ /**
68
+ * Cache target
69
+ */
70
+ private $target_sns = array();
71
+
72
+ /**
73
+ * Initialization
74
+ *
75
+ * @since 0.1.1
76
+ */
77
+ public function initialize( $options = array() ) {
78
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
79
+
80
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
81
+ $this->prime_cron = self::DEF_PRIME_CRON;
82
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
83
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
84
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
85
+
86
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
87
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
88
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
89
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
90
+ if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
91
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
92
+ if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
93
+ if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
94
+ if ( isset( $options['meta_key_prefix'] ) ) $this->meta_key_prefix = $options['meta_key_prefix'];
95
+
96
+ add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
97
+ add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
98
+ add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 0 );
99
+ }
100
+
101
+ /**
102
+ * Register event schedule for this engine
103
+ *
104
+ * @since 0.1.0
105
+ */
106
+ public function schedule_check_interval( $schedules ) {
107
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
108
+
109
+ $schedules[$this->event_schedule] = array(
110
+ 'interval' => $this->check_interval,
111
+ 'display' => $this->event_description
112
+ );
113
+
114
+ return $schedules;
115
+ }
116
+
117
+ /**
118
+ * Schedule data retrieval and cache processing
119
+ *
120
+ * @since 0.3.0
121
+ */
122
+ public function prime_cache() {
123
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
124
+
125
+ $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
126
+
127
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
128
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
129
+
130
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron );
131
+ }
132
+
133
+ /**
134
+ * Get and cache data of each published post and page
135
+ *
136
+ * @since 0.4.0
137
+ */
138
+ public function execute_cache() {
139
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
140
+
141
+ $url = get_feed_link();
142
+
143
+ $transient_id = $this->get_cache_key( 'follow' );
144
+
145
+ $options = array(
146
+ 'cache_key' => $transient_id,
147
+ 'target_sns' => $this->target_sns,
148
+ );
149
+
150
+ $this->cache( $options );
151
+ }
152
+
153
+ /**
154
+ * Get and cache data for a given post
155
+ *
156
+ * @since 0.1.1
157
+ */
158
+ public function cache( $options = array() ) {
159
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
160
+
161
+ $transient_id = $options['cache_key'];
162
+ $target_sns = $options['target_sns'];
163
+
164
+ if ( false !== ( $sns_followers = get_transient( $transient_id ) ) ) {
165
+
166
+ $option_key = $this->get_cache_key( 'follow' );
167
+
168
+ update_option( $option_key, $sns_followers );
169
+ }
170
+
171
+ $this->delegate_order( SCC_Order::ORDER_DO_ANALYSIS, $options );
172
+
173
+ }
174
+
175
+ /**
176
+ * Get cache expiration based on current number of total post and page
177
+ *
178
+ * @since 0.2.0
179
+ */
180
+ protected function get_cache_expiration() {
181
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
182
+
183
+ return 0;
184
+ }
185
+
186
+ /**
187
+ * Initialize meta key for ranking
188
+ *
189
+ * @since 0.3.0
190
+ */
191
+ public function initialize_cache() {
192
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
193
+
194
+ $option_key = $this->get_cache_key( 'follow' );
195
+
196
+ $sns_followers = array();
197
+
198
+ foreach ( $this->target_sns as $sns => $active ) {
199
+ if ( $active ) {
200
+ $sns_followers[$sns] = (int) -1;
201
+ }
202
+ }
203
+
204
+ update_option( $option_key, $sns_followers );
205
+ }
206
+
207
+ /**
208
+ * Clear meta key for ranking
209
+ *
210
+ * @since 0.3.0
211
+ */
212
+ public function clear_cache() {
213
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
214
+
215
+ $option_key = $this->get_cache_key( 'follow' );
216
+
217
+ delete_option( $option_key );
218
+
219
+ // Compatibility for old version
220
+ foreach ( $this->target_sns as $sns => $active ) {
221
+
222
+ $option_key = $this->get_cache_key( $sns );
223
+
224
+ if ( $active ) {
225
+ delete_option( $option_key );
226
+ }
227
+ }
228
+ }
229
+
230
+ /**
231
+ * Get cache
232
+ *
233
+ * @since 0.10.1
234
+ */
235
+ public function get_cache( $options = array() ) {
236
+ $option_key = $this->get_cache_key( 'follow' );
237
+ $sns_followers = array();
238
+
239
+ if ( false !== ( $sns_followers = get_option( $option_key ) ) ) {
240
+ } else {
241
+ foreach ( $this->target_sns as $sns => $active ) {
242
+ if ( $active ) {
243
+ $sns_followers[$sns] = (int) -1;
244
+ }
245
+ }
246
+ }
247
+
248
+ return $sns_followers;
249
+ }
250
+
251
+ }
252
+
253
+ ?>
includes/class-scc-follow-twitter-strategy.php CHANGED
@@ -1,180 +1,186 @@
1
- <?php
2
- /*
3
- class-scc-follow-twitter-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Follow_Twitter_Strategy extends SCC_Crawl_Strategy {
31
-
32
- /**
33
- * SNS base url
34
- */
35
- const DEF_BASE_URL = 'https://api.twitter.com/1.1/users/show.json';
36
-
37
- /**
38
- * Class constarctor
39
- * Hook onto all of the actions and filters needed by the plugin.
40
- *
41
- */
42
- protected function __construct() {
43
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
-
45
- $this->method = 'GET';
46
- }
47
-
48
- /**
49
- * Initialization
50
- *
51
- * @since 0.9.0
52
- */
53
- public function initialize( $options = array() ) {
54
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
-
56
- if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
- if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
- if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
- }
60
-
61
- /**
62
- * Build header
63
- *
64
- * @since 0.9.0
65
- */
66
- public function build_header() {
67
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
-
69
- $headers = array();
70
-
71
- /*
72
- // vesion using user auth
73
- $oauth_parameters = array(
74
- 'oauth_consumer_key' => $this->parameters['consumer_key'],
75
- 'oauth_token' => $this->parameters['access_token'],
76
- 'oauth_nonce' => microtime(),
77
- 'oauth_signature_method' => 'HMAC-SHA1',
78
- 'oauth_timestamp' => time(),
79
- 'oauth_version' => '1.0'
80
- );
81
-
82
- $signature_key = rawurlencode( $this->parameters['consumer_secret'] ) . '&' . rawurlencode( $this->parameters['access_token_secret'] );
83
-
84
- $oauth_parameters = array_merge( $oauth_parameters, $this->query_parameters );
85
-
86
- ksort( $oauth_parameters );
87
-
88
- $signature_parameters = str_replace( array( '+' , '%7E' ) , array( '%20' , '~' ) , http_build_query( $oauth_parameters , '' , '&' ) );
89
-
90
- $signature_data = rawurlencode( $this->method ) . '&' . rawurlencode( self::DEF_BASE_URL ) . '&' . rawurlencode( $signature_parameters );
91
-
92
- $signature = base64_encode( hash_hmac( 'sha1' , $signature_data , $signature_key , true ) );
93
-
94
- $oauth_parameters['oauth_signature'] = $signature;
95
-
96
- $header_parameters = http_build_query( $oauth_parameters, '', ',' );
97
-
98
- $headers['Authorization'] = 'OAuth ' . $header_parameters;
99
- */
100
-
101
- //version using application-only auth
102
- $headers['Authorization'] = 'Bearer ' . $this->parameters['bearer_token'];
103
-
104
- return $headers;
105
- }
106
-
107
- /**
108
- * Build query url
109
- *
110
- * @since 0.9.0
111
- */
112
- public function build_query_url() {
113
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
114
-
115
- $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
116
-
117
- return $url;
118
- }
119
-
120
- /**
121
- * Extract count
122
- *
123
- * @since 0.9.0
124
- */
125
- public function extract_count( $content ) {
126
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
127
-
128
- $count = (int) -1;
129
-
130
- if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
131
- $json = json_decode( $content['data'], true );
132
-
133
- if ( isset( $json['followers_count'] ) && is_numeric( $json['followers_count'] ) ) {
134
- $count = (int) $json['followers_count'];
135
- } else {
136
- $count = (int) -1;
137
- }
138
- } else {
139
- $count = (int) -1;
140
- }
141
-
142
- return $count;
143
- }
144
-
145
- /**
146
- * Check if required paramters are included or not.
147
- *
148
- * @since 0.9.0
149
- */
150
- public function check_configuration() {
151
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
152
-
153
- /*
154
- // vesion using user auth
155
- if ( isset( $this->query_parameters['screen_name'] ) && $this->query_parameters['screen_name'] &&
156
- isset( $this->parameters['consumer_key'] ) && $this->parameters['consumer_key'] &&
157
- isset( $this->parameters['consumer_secret'] ) && $this->parameters['consumer_secret'] &&
158
- isset( $this->parameters['access_token'] ) && $this->parameters['access_token'] &&
159
- isset( $this->parameters['access_token_secret'] ) && $this->parameters['access_token_secret']
160
- ) {
161
- return true;
162
- } else {
163
- return false;
164
- }
165
- */
166
-
167
- //version using application-only auth
168
- if ( isset( $this->query_parameters['screen_name'] ) && $this->query_parameters['screen_name'] &&
169
- isset( $this->parameters['consumer_key'] ) && $this->parameters['consumer_key'] &&
170
- isset( $this->parameters['consumer_secret'] ) && $this->parameters['consumer_secret'] &&
171
- isset( $this->parameters['bearer_token'] ) && $this->parameters['bearer_token']
172
- ) {
173
- return true;
174
- } else {
175
- return false;
176
- }
177
-
178
- }
179
-
180
- }
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-follow-twitter-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Follow_Twitter_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url
34
+ */
35
+ const DEF_BASE_URL = 'https://api.twitter.com/1.1/users/show.json';
36
+
37
+ /**
38
+ * Class constarctor
39
+ * Hook onto all of the actions and filters needed by the plugin.
40
+ *
41
+ */
42
+ protected function __construct() {
43
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
+
45
+ $this->method = 'GET';
46
+ }
47
+
48
+ /**
49
+ * Initialization
50
+ *
51
+ * @since 0.9.0
52
+ */
53
+ public function initialize( $options = array() ) {
54
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
+
56
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
+ }
60
+
61
+ /**
62
+ * Build header
63
+ *
64
+ * @since 0.9.0
65
+ */
66
+ public function build_header() {
67
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
+
69
+ $headers = array();
70
+
71
+ /*
72
+ // vesion using user auth
73
+ $oauth_parameters = array(
74
+ 'oauth_consumer_key' => $this->parameters['consumer_key'],
75
+ 'oauth_token' => $this->parameters['access_token'],
76
+ 'oauth_nonce' => microtime(),
77
+ 'oauth_signature_method' => 'HMAC-SHA1',
78
+ 'oauth_timestamp' => time(),
79
+ 'oauth_version' => '1.0'
80
+ );
81
+
82
+ $signature_key = rawurlencode( $this->parameters['consumer_secret'] ) . '&' . rawurlencode( $this->parameters['access_token_secret'] );
83
+
84
+ $oauth_parameters = array_merge( $oauth_parameters, $this->query_parameters );
85
+
86
+ ksort( $oauth_parameters );
87
+
88
+ $signature_parameters = str_replace( array( '+' , '%7E' ) , array( '%20' , '~' ) , http_build_query( $oauth_parameters , '' , '&' ) );
89
+
90
+ $signature_data = rawurlencode( $this->method ) . '&' . rawurlencode( self::DEF_BASE_URL ) . '&' . rawurlencode( $signature_parameters );
91
+
92
+ $signature = base64_encode( hash_hmac( 'sha1' , $signature_data , $signature_key , true ) );
93
+
94
+ $oauth_parameters['oauth_signature'] = $signature;
95
+
96
+ $header_parameters = http_build_query( $oauth_parameters, '', ',' );
97
+
98
+ $headers['Authorization'] = 'OAuth ' . $header_parameters;
99
+ */
100
+
101
+ //version using application-only auth
102
+ $headers['Authorization'] = 'Bearer ' . $this->parameters['bearer_token'];
103
+
104
+ return $headers;
105
+ }
106
+
107
+ /**
108
+ * Build query url
109
+ *
110
+ * @since 0.9.0
111
+ */
112
+ public function build_query_url() {
113
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
114
+
115
+ $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
116
+
117
+ return $url;
118
+ }
119
+
120
+ /**
121
+ * Extract count
122
+ *
123
+ * @since 0.9.0
124
+ */
125
+ public function extract_count( $content ) {
126
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
127
+
128
+ $count = (int) -1;
129
+
130
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
131
+ $json = json_decode( $content['data'], true );
132
+
133
+ if ( isset( $json['followers_count'] ) && is_numeric( $json['followers_count'] ) ) {
134
+ $count = (int) $json['followers_count'];
135
+ } else {
136
+ $count = (int) -1;
137
+ }
138
+ } else {
139
+ $count = (int) -1;
140
+ }
141
+
142
+ return $count;
143
+ }
144
+
145
+ public function set_query_parameter( $key, $value ) {
146
+ if ( $key === 'screen_name' ) {
147
+ $this->query_parameters[$key] = $value;
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Check if required paramters are included or not.
153
+ *
154
+ * @since 0.9.0
155
+ */
156
+ public function check_configuration() {
157
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
158
+
159
+ /*
160
+ // vesion using user auth
161
+ if ( isset( $this->query_parameters['screen_name'] ) && $this->query_parameters['screen_name'] &&
162
+ isset( $this->parameters['consumer_key'] ) && $this->parameters['consumer_key'] &&
163
+ isset( $this->parameters['consumer_secret'] ) && $this->parameters['consumer_secret'] &&
164
+ isset( $this->parameters['access_token'] ) && $this->parameters['access_token'] &&
165
+ isset( $this->parameters['access_token_secret'] ) && $this->parameters['access_token_secret']
166
+ ) {
167
+ return true;
168
+ } else {
169
+ return false;
170
+ }
171
+ */
172
+
173
+ //version using application-only auth
174
+ if ( isset( $this->query_parameters['screen_name'] ) && $this->query_parameters['screen_name'] &&
175
+ isset( $this->parameters['consumer_key'] ) && $this->parameters['consumer_key'] &&
176
+ isset( $this->parameters['consumer_secret'] ) && $this->parameters['consumer_secret'] &&
177
+ isset( $this->parameters['bearer_token'] ) && $this->parameters['bearer_token']
178
+ ) {
179
+ return true;
180
+ } else {
181
+ return false;
182
+ }
183
+
184
+ }
185
+
186
+ }
includes/class-scc-share-analytical-engine.php CHANGED
@@ -1,580 +1,550 @@
1
- <?php
2
- /*
3
- class-scc-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
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Analytical_Engine extends SCC_Analytical_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
-
37
- /**
38
- * Prefix of cache ID
39
- */
40
- const DEF_BASE_PREFIX = 'scc_share_base_';
41
-
42
- /**
43
- * Prefix of cache ID
44
- */
45
- const DEF_DELTA_PREFIX = 'scc_share_delta_';
46
-
47
- /**
48
- * Cron name to schedule cache processing
49
- */
50
- const DEF_PRIME_CRON = 'scc_share_updatebase_prime';
51
-
52
- /**
53
- * Cron name to execute cache processing
54
- */
55
- const DEF_EXECUTE_CRON = 'scc_share_updatebase_exec';
56
-
57
- /**
58
- * Schedule name for cache processing
59
- */
60
- const DEF_EVENT_SCHEDULE = 'share_update_base_event';
61
-
62
- /**
63
- * Schedule description for cache processing
64
- */
65
- const DEF_EVENT_DESCRIPTION = '[SCC] Share Update Base Interval';
66
-
67
- /**
68
- * Interval cheking and caching target data
69
- */
70
- private $check_interval = 600;
71
-
72
- /**
73
- * Offset suffix
74
- */
75
- private $base_schedule = '* * * 0 0';
76
-
77
- /**
78
- * Base directory
79
- */
80
- private $base_dir = NULL;
81
-
82
- /**
83
- * Crawl date key
84
- */
85
- private $crawl_date_key = NULL;
86
-
87
- /**
88
- * Initialization
89
- *
90
- * @since 0.1.1
91
- */
92
- public function initialize( $options = array() ) {
93
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
94
-
95
- $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
96
- $this->base_prefix = self::DEF_BASE_PREFIX;
97
- $this->delta_prefix = self::DEF_DELTA_PREFIX;
98
- $this->prime_cron = self::DEF_PRIME_CRON;
99
- $this->execute_cron = self::DEF_EXECUTE_CRON;
100
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
101
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
102
- $this->base_dir = WP_PLUGIN_DIR . '/sns-count-cache/data/';
103
-
104
- if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
105
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
106
- if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
107
- if ( isset( $options['base_schedule'] ) ) $this->base_schedule = $options['base_schedule'];
108
- if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
109
- if ( isset( $options['base_prefix'] ) ) $this->base_prefix = $options['base_prefix'];
110
- if ( isset( $options['delta_prefix'] ) ) $this->delta_prefix = $options['delta_prefix'];
111
- if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
112
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
113
- if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
114
- if ( isset( $options['crawl_date_key'] ) ) $this->crawl_date_key = $options['crawl_date_key'];
115
-
116
- add_action( $this->prime_cron, array( $this, 'prime_base' ) );
117
- add_action( $this->execute_cron, array( $this, 'execute_base' ), 10, 1 );
118
- add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
119
- }
120
-
121
- /**
122
- * Register event schedule for this engine
123
- *
124
- * @since 0.1.0
125
- */
126
- public function schedule_check_interval( $schedules ) {
127
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
128
-
129
- $schedules[$this->event_schedule] = array(
130
- 'interval' => $this->check_interval,
131
- 'display' => $this->event_description
132
- );
133
-
134
- return $schedules;
135
- }
136
-
137
- /**
138
- * Schedule data retrieval and cache processing
139
- *
140
- * @since 0.1.0
141
- */
142
- public function prime_base() {
143
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
144
-
145
- $next_exec_time = SCC_WP_Cron_Util::next_exec_time( $this->base_schedule );
146
-
147
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time (timesatamp): ' . $next_exec_time );
148
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time (date): ' . date_i18n( 'Y/m/d H:i:s', $next_exec_time ) );
149
-
150
- if ( ! SCC_WP_Cron_Util::is_scheduled_hook( $this->execute_cron ) ) {
151
- wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( SCC_Common_Util::short_hash( $next_exec_time ) ) );
152
- }
153
- }
154
-
155
- /**
156
- * Get and cache data of each published post and page
157
- *
158
- * @since 0.1.0
159
- */
160
- public function execute_base( $hash ) {
161
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
162
-
163
- $current_date = date_i18n( 'Y/m/d H:i:s' );
164
-
165
- if ( file_exists( $this->base_dir ) ) {
166
- $base_file = $this->base_dir . $this->get_base_key( 'home' );
167
-
168
- if ( ! file_exists( $base_file ) ) {
169
- if ( touch( $base_file ) ) {
170
- SCC_Common_Util::log( '[' . __METHOD__ . '] file creation succeeded: ' . $base_file );
171
- } else {
172
- SCC_Common_Util::log( '[' . __METHOD__ . '] file creation failed: ' . $base_file );
173
- }
174
- }
175
-
176
- if ( file_exists( $base_file ) ) {
177
- SCC_Common_Util::log( '[' . __METHOD__ . '] file exists: ' . $base_file );
178
-
179
- $option_key = $this->get_cache_key( 'home' );
180
-
181
- if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
182
- foreach ( $this->target_sns as $sns => $active ) {
183
- if ( $active ) {
184
- if ( $sns !== $this->crawl_date_key ) {
185
- if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
186
- $sns_counts[$sns] = (int) -1;
187
- }
188
- } else {
189
- if ( ! isset( $sns_counts[$sns] ) ) {
190
- $sns_counts[$sns] = '';
191
- }
192
- }
193
- }
194
- }
195
-
196
- if ( ! in_array( -1, $sns_counts, true ) ) {
197
- $data = serialize( $sns_counts );
198
-
199
- $fp = fopen( $base_file, 'w' );
200
-
201
- if ( fwrite( $fp, $data ) ) {
202
- SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ');
203
- } else {
204
- SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ');
205
- }
206
-
207
- if ( fclose( $fp ) ) {
208
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
209
- } else {
210
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
211
- }
212
- }
213
- }
214
- }
215
-
216
- $query_args = array(
217
- 'post_type' => $this->post_types,
218
- 'post_status' => 'publish',
219
- 'nopaging' => true,
220
- 'update_post_term_cache' => false,
221
- 'update_post_meta_cache' => false
222
- );
223
-
224
- $posts_query = new WP_Query( $query_args );
225
-
226
- if ( $posts_query->have_posts() ) {
227
- while ( $posts_query->have_posts() ) {
228
- $posts_query->the_post();
229
-
230
- $post_id = get_the_ID();
231
-
232
- $base_file = $this->base_dir . $this->get_base_key( $post_id );
233
-
234
- if ( ! file_exists( $base_file ) ) {
235
- if ( touch( $base_file ) ) {
236
- SCC_Common_Util::log( '[' . __METHOD__ . '] export file creation succeeded: ' . $base_file );
237
- } else {
238
- SCC_Common_Util::log( '[' . __METHOD__ . '] export file creation failed: ' . $base_file );
239
- }
240
- }
241
-
242
- if ( file_exists( $base_file ) ) {
243
- $sns_counts = array();
244
-
245
- foreach ( $this->target_sns as $sns => $active ) {
246
- if ( $active ) {
247
- if ( $sns !== $this->crawl_date_key ) {
248
- $meta_key = $this->get_cache_key( $sns );
249
-
250
- $sns_count = get_post_meta( $post_id, $meta_key, true );
251
-
252
- if ( isset( $sns_count ) && $sns_count !== '' && $sns_count >= 0 ) {
253
- $sns_counts[$sns] = (int) $sns_count;
254
- } else {
255
- $sns_counts[$sns] = (int) -1;
256
- }
257
- } else {
258
- $meta_key = $this->get_cache_key( $sns );
259
-
260
- $sns_count = get_post_meta( $post_id, $meta_key, true );
261
-
262
- if ( isset( $sns_count ) && $sns_count !== '' ) {
263
- $sns_counts[$sns] = $sns_count;
264
- } else {
265
- $sns_counts[$sns] = '';
266
- }
267
- }
268
- }
269
- }
270
-
271
- if ( ! in_array( -1, $sns_counts, true ) ) {
272
-
273
- $data = serialize( $sns_counts );
274
-
275
- $fp = fopen( $base_file, 'w' );
276
-
277
- if ( fwrite( $fp, $data ) ) {
278
- SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' );
279
- } else {
280
- SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' );
281
- }
282
-
283
- if ( fclose( $fp ) ) {
284
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
285
- } else {
286
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
287
- }
288
- }
289
- }
290
- }
291
- }
292
- wp_reset_postdata();
293
- }
294
-
295
- }
296
-
297
- /**
298
- * Initialize meta key for ranking
299
- *
300
- * @since 0.6.1
301
- */
302
- public function analyze( $options = array() ) {
303
-
304
- $transient_id = $options['cache_key'];
305
- $target_sns = $options['target_sns'];
306
- $post_id = $options['post_id'];
307
-
308
- $base_file = $this->base_dir . $this->get_base_key( $post_id );
309
-
310
- $sns_counts = array();
311
- $sns_base_counts = array();
312
-
313
- if ( file_exists( $base_file ) ) {
314
- $fp = fopen( $base_file, 'r' );
315
-
316
- $data = fread( $fp, filesize( $base_file ) );
317
-
318
- if ( fclose( $fp ) ) {
319
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
320
- } else {
321
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
322
- }
323
-
324
- $sns_base_counts = unserialize( $data );
325
- } else {
326
- // if there is no base file.
327
-
328
- if ( touch( $base_file ) ) {
329
- SCC_Common_Util::log( '[' . __METHOD__ . '] file creation succeeded: ' . $base_file );
330
- } else {
331
- SCC_Common_Util::log( '[' . __METHOD__ . '] file creation failed: ' . $base_file );
332
- }
333
-
334
- if ( file_exists( $base_file ) ) {
335
-
336
- $sns_counts = array();
337
-
338
- if ( $post_id !== 'home' ) {
339
- foreach ( $this->target_sns as $sns => $active ) {
340
- if ( $active ) {
341
- if ( $sns !== $this->crawl_date_key ) {
342
- $meta_key = $this->get_cache_key( $sns );
343
-
344
- $sns_count = get_post_meta( $post_id, $meta_key, true );
345
-
346
- if ( isset( $sns_count ) && $sns_count !== '' && $sns_count >= 0 ) {
347
- $sns_counts[$sns] = (int) $sns_count;
348
- } else {
349
- $sns_counts[$sns] = (int) -1;
350
- }
351
- } else {
352
- $meta_key = $this->get_cache_key( $sns );
353
-
354
- $sns_count = get_post_meta( $post_id, $meta_key, true );
355
-
356
- if ( isset( $sns_count ) && $sns_count !== '' ) {
357
- $sns_counts[$sns] = $sns_count;
358
- } else {
359
- $sns_counts[$sns] = '';
360
- }
361
- }
362
- }
363
- }
364
- } else {
365
- $option_key = $this->get_cache_key( 'home' );
366
-
367
- if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
368
- foreach ( $this->target_sns as $sns => $active ) {
369
- if ( $active ) {
370
- if ( $sns !== $this->crawl_date_key ) {
371
- if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
372
- $sns_counts[$sns] = (int) -1;
373
- }
374
- } else {
375
- if ( ! isset( $sns_counts[$sns] ) ) {
376
- $sns_counts[$sns] = '';
377
- }
378
- }
379
- }
380
- }
381
- }
382
- }
383
-
384
- if ( ! in_array( -1, $sns_counts, true ) ) {
385
- $data = serialize( $sns_counts );
386
-
387
- $fp = fopen( $base_file, 'w' );
388
-
389
- if ( fwrite( $fp, $data ) ) {
390
- SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' );
391
- } else {
392
- SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' );
393
- }
394
-
395
- if ( fclose( $fp ) ) {
396
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
397
- } else {
398
- SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
399
- }
400
- }
401
- }
402
- }
403
-
404
- $sns_counts = array();
405
- $diffs = array();
406
-
407
- if ( $post_id !== 'home' ) {
408
- foreach ( $this->target_sns as $sns => $active ) {
409
- if( $active ){
410
- $meta_key = $this->get_cache_key( $sns );
411
- $sns_counts[$sns] = get_post_meta( $post_id, $meta_key, true );
412
- }
413
- }
414
-
415
- if ( ! in_array( -1, $sns_counts, true ) ) {
416
-
417
- foreach ( $this->target_sns as $sns => $active ) {
418
- if ( $active ){
419
- if ( $sns !== $this->crawl_date_key ) {
420
- $diff = 0;
421
-
422
- 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 ) {
423
- $diff = $sns_counts[$sns] - $sns_base_counts[$sns];
424
- } else {
425
- $diff = 0;
426
- }
427
-
428
- $meta_key = $this->get_delta_key( $sns );
429
-
430
- update_post_meta( $post_id, $meta_key, (int) $diff );
431
- } else {
432
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && isset( $sns_base_counts[$sns] ) && $sns_base_counts[$sns] !== '' ) {
433
- $crawl_date = $sns_base_counts[$sns] . ',' . $sns_counts[$sns];
434
- } else {
435
- $crawl_date = '';
436
- }
437
-
438
- $meta_key = $this->get_delta_key( $sns );
439
-
440
- update_post_meta( $post_id, $meta_key, $crawl_date );
441
- }
442
- }
443
- }
444
- } else {
445
- foreach ( $this->target_sns as $sns => $active ) {
446
- if( $active ){
447
- $meta_key = $this->get_delta_key( $sns );
448
- if ( $sns !== $this->crawl_date_key ) {
449
- $diff = 0;
450
-
451
- update_post_meta( $post_id, $meta_key, (int) $diff );
452
- } else {
453
- $crawl_date = '';
454
-
455
- update_post_meta( $post_id, $meta_key, $crawl_date );
456
- }
457
- }
458
- }
459
- }
460
- } else {
461
- $option_key = $this->get_cache_key( 'home' );
462
-
463
- $diffs = array();
464
-
465
- if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
466
-
467
- if ( ! in_array( -1, $sns_counts, true ) ) {
468
- foreach ( $this->target_sns as $sns => $active ) {
469
- if( $active ){
470
- if ( $sns !== $this->crawl_date_key ) {
471
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 && isset( $sns_base_counts[$sns] ) && $sns_base_counts[$sns] !== '' && $sns_base_counts[$sns] >= 0 ) {
472
- $diffs[$sns] = (int)( $sns_counts[$sns] - $sns_base_counts[$sns] );
473
- } else {
474
- $diffs[$sns] = 0;
475
- }
476
- } else {
477
- if ( isset( $sns_counts[$sns] ) && isset( $sns_base_counts[$sns] ) && $sns_base_counts[$sns] !== '' ) {
478
- $diffs[$sns] = $sns_base_counts[$sns] . ',' . $sns_counts[$sns];
479
- } else {
480
- $diffs[$sns] = '';
481
- }
482
- }
483
- }
484
- }
485
-
486
- $option_key = $this->get_delta_key( 'home' );
487
-
488
- update_option( $option_key, $diffs );
489
- } else {
490
- foreach ( $this->target_sns as $sns => $active ) {
491
- if ( $active ) {
492
- if ( $sns !== $this->crawl_date_key ) {
493
- $diffs[$sns] = (int) 0;
494
- } else {
495
- $diffs[$sns] = '';
496
- }
497
- }
498
- }
499
-
500
- $option_key = $this->get_delta_key( 'home' );
501
-
502
- update_option( $option_key, $diffs );
503
- }
504
- } else {
505
-
506
- foreach ( $this->target_sns as $sns => $active ) {
507
- if ( $active ){
508
- if ( $sns !== $this->crawl_date_key ) {
509
- $diffs[$sns] = (int) 0;
510
- } else {
511
- $diffs[$sns] = '';
512
- }
513
- }
514
- }
515
-
516
- $option_key = $this->get_delta_key( 'home' );
517
-
518
- update_option( $option_key, $diffs );
519
- }
520
- }
521
-
522
- }
523
-
524
- /**
525
- * Initialize meta key for ranking
526
- *
527
- * @since 0.3.0
528
- */
529
- public function initialize_base() {
530
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
531
-
532
- /*
533
- $option_key = $this->get_cache_key( $this->offset_suffix );
534
-
535
- update_option( $option_key, 0 );
536
- */
537
- }
538
-
539
- /**
540
- * Clear meta key for ranking
541
- *
542
- * @since 0.3.0
543
- */
544
- public function clear_base() {
545
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
546
-
547
- $option_key = $this->get_delta_key( 'home' );
548
-
549
- delete_option( $option_key );
550
-
551
- foreach ( $this->target_sns as $sns => $active ) {
552
- if ( $active ) {
553
- $meta_key = $this->get_delta_key( $sns );
554
-
555
- delete_post_meta_by_key( $meta_key );
556
- }
557
- }
558
-
559
- }
560
-
561
- /**
562
- * Clear meta key for ranking
563
- *
564
- * @since 0.7.0
565
- */
566
- public function clear_base_by_post_id( $post_id ) {
567
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
568
-
569
- foreach ( $this->target_sns as $sns => $active ) {
570
- if ( $active ) {
571
- $meta_key = $this->get_delta_key( $sns );
572
- delete_post_meta( $post_id, $meta_key );
573
- }
574
- }
575
-
576
- }
577
-
578
- }
579
-
580
- ?>
1
+ <?php
2
+ /*
3
+ class-scc-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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Analytical_Engine extends SCC_Analytical_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
+
37
+ /**
38
+ * Prefix of cache ID
39
+ */
40
+ const DEF_BASE_PREFIX = 'scc_share_base_';
41
+
42
+ /**
43
+ * Prefix of cache ID
44
+ */
45
+ const DEF_DELTA_PREFIX = 'scc_share_delta_';
46
+
47
+ /**
48
+ * Cron name to schedule cache processing
49
+ */
50
+ const DEF_PRIME_CRON = 'scc_share_updatebase_prime';
51
+
52
+ /**
53
+ * Cron name to execute cache processing
54
+ */
55
+ const DEF_EXECUTE_CRON = 'scc_share_updatebase_exec';
56
+
57
+ /**
58
+ * Schedule name for cache processing
59
+ */
60
+ const DEF_EVENT_SCHEDULE = 'share_update_base_event';
61
+
62
+ /**
63
+ * Schedule description for cache processing
64
+ */
65
+ const DEF_EVENT_DESCRIPTION = '[SCC] Share Update Base Interval';
66
+
67
+ /**
68
+ * Cache post types
69
+ */
70
+ private $post_types = array( 'post', 'page' );
71
+
72
+ /**
73
+ * Interval cheking and caching target data
74
+ */
75
+ private $check_interval = 600;
76
+
77
+ /**
78
+ * Offset suffix
79
+ */
80
+ private $base_schedule = '* * * 0 0';
81
+
82
+ /**
83
+ * Base directory
84
+ */
85
+ private $base_dir = NULL;
86
+
87
+ /**
88
+ * Crawl date key
89
+ */
90
+ private $crawl_date_key = NULL;
91
+
92
+ /**
93
+ * Initialization
94
+ *
95
+ * @since 0.1.1
96
+ */
97
+ public function initialize( $options = array() ) {
98
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
99
+
100
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
101
+ $this->base_prefix = self::DEF_BASE_PREFIX;
102
+ $this->delta_prefix = self::DEF_DELTA_PREFIX;
103
+ $this->prime_cron = self::DEF_PRIME_CRON;
104
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
105
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
106
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
107
+ $this->base_dir = WP_PLUGIN_DIR . '/sns-count-cache/data/';
108
+
109
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
110
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
111
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
112
+ if ( isset( $options['base_schedule'] ) ) $this->base_schedule = $options['base_schedule'];
113
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
114
+ if ( isset( $options['base_prefix'] ) ) $this->base_prefix = $options['base_prefix'];
115
+ if ( isset( $options['delta_prefix'] ) ) $this->delta_prefix = $options['delta_prefix'];
116
+ if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
117
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
118
+ if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
119
+ if ( isset( $options['crawl_date_key'] ) ) $this->crawl_date_key = $options['crawl_date_key'];
120
+
121
+ add_action( $this->prime_cron, array( $this, 'prime_base' ) );
122
+ add_action( $this->execute_cron, array( $this, 'execute_base' ), 10, 1 );
123
+ add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
124
+ }
125
+
126
+ /**
127
+ * Register event schedule for this engine
128
+ *
129
+ * @since 0.1.0
130
+ */
131
+ public function schedule_check_interval( $schedules ) {
132
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
133
+
134
+ $schedules[$this->event_schedule] = array(
135
+ 'interval' => $this->check_interval,
136
+ 'display' => $this->event_description
137
+ );
138
+
139
+ return $schedules;
140
+ }
141
+
142
+ /**
143
+ * Schedule data retrieval and cache processing
144
+ *
145
+ * @since 0.1.0
146
+ */
147
+ public function prime_base() {
148
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
149
+
150
+ $next_exec_time = SCC_WP_Cron_Util::next_exec_time( $this->base_schedule );
151
+
152
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time (timesatamp): ' . $next_exec_time );
153
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time (date): ' . date_i18n( 'Y/m/d H:i:s', $next_exec_time ) );
154
+
155
+ if ( ! SCC_WP_Cron_Util::is_scheduled_hook( $this->execute_cron ) ) {
156
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( SCC_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
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
167
+
168
+ $current_date = date_i18n( 'Y/m/d H:i:s' );
169
+
170
+ if ( file_exists( $this->base_dir ) ) {
171
+ $base_file = $this->base_dir . sanitize_file_name( $this->get_base_key( 'home' ) );
172
+
173
+ if ( ! file_exists( $base_file ) ) {
174
+ if ( touch( $base_file ) ) {
175
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file creation succeeded: ' . $base_file );
176
+ } else {
177
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file creation failed: ' . $base_file );
178
+ }
179
+ }
180
+
181
+ if ( file_exists( $base_file ) ) {
182
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file exists: ' . $base_file );
183
+
184
+ $option_key = $this->get_cache_key( 'home' );
185
+
186
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
187
+ foreach ( $this->target_sns as $sns => $active ) {
188
+ if ( $active ) {
189
+ if ( $sns !== $this->crawl_date_key ) {
190
+ if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
191
+ $sns_counts[$sns] = (int) -1;
192
+ }
193
+ } else {
194
+ if ( ! isset( $sns_counts[$sns] ) ) {
195
+ $sns_counts[$sns] = '';
196
+ }
197
+ }
198
+ }
199
+ }
200
+
201
+ $data = serialize( $sns_counts );
202
+
203
+ $fp = fopen( $base_file, 'w' );
204
+
205
+ if ( fwrite( $fp, $data ) ) {
206
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ');
207
+ } else {
208
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ');
209
+ }
210
+
211
+ if ( fclose( $fp ) ) {
212
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
213
+ } else {
214
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
215
+ }
216
+ }
217
+ }
218
+
219
+ $query_args = array(
220
+ 'post_type' => $this->post_types,
221
+ 'post_status' => 'publish',
222
+ 'nopaging' => true,
223
+ 'update_post_term_cache' => false,
224
+ 'update_post_meta_cache' => false
225
+ );
226
+
227
+ $posts_query = new WP_Query( $query_args );
228
+
229
+ if ( $posts_query->have_posts() ) {
230
+ while ( $posts_query->have_posts() ) {
231
+ $posts_query->the_post();
232
+
233
+ $post_id = get_the_ID();
234
+
235
+ $base_file = $this->base_dir . sanitize_file_name( $this->get_base_key( $post_id ) );
236
+
237
+ if ( ! file_exists( $base_file ) ) {
238
+ if ( touch( $base_file ) ) {
239
+ SCC_Common_Util::log( '[' . __METHOD__ . '] export file creation succeeded: ' . $base_file );
240
+ } else {
241
+ SCC_Common_Util::log( '[' . __METHOD__ . '] export file creation failed: ' . $base_file );
242
+ }
243
+ }
244
+
245
+ if ( file_exists( $base_file ) ) {
246
+ $sns_counts = array();
247
+
248
+ foreach ( $this->target_sns as $sns => $active ) {
249
+ if ( $active ) {
250
+ if ( $sns !== $this->crawl_date_key ) {
251
+ $meta_key = $this->get_cache_key( $sns );
252
+
253
+ $sns_count = get_post_meta( $post_id, $meta_key, true );
254
+
255
+ if ( isset( $sns_count ) && $sns_count !== '' && $sns_count >= 0 ) {
256
+ $sns_counts[$sns] = (int) $sns_count;
257
+ } else {
258
+ $sns_counts[$sns] = (int) -1;
259
+ }
260
+ } else {
261
+ $meta_key = $this->get_cache_key( $sns );
262
+
263
+ $sns_count = get_post_meta( $post_id, $meta_key, true );
264
+
265
+ if ( isset( $sns_count ) && $sns_count !== '' ) {
266
+ $sns_counts[$sns] = $sns_count;
267
+ } else {
268
+ $sns_counts[$sns] = '';
269
+ }
270
+ }
271
+ }
272
+ }
273
+
274
+ $data = serialize( $sns_counts );
275
+
276
+ $fp = fopen( $base_file, 'w' );
277
+
278
+ if ( fwrite( $fp, $data ) ) {
279
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' );
280
+ } else {
281
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' );
282
+ }
283
+
284
+ if ( fclose( $fp ) ) {
285
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
286
+ } else {
287
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
288
+ }
289
+
290
+ }
291
+ }
292
+ }
293
+ wp_reset_postdata();
294
+ }
295
+
296
+ }
297
+
298
+ /**
299
+ * Initialize meta key for ranking
300
+ *
301
+ * @since 0.6.1
302
+ */
303
+ public function analyze( $options = array() ) {
304
+
305
+ $transient_id = $options['cache_key'];
306
+ $target_sns = $options['target_sns'];
307
+ $post_id = $options['post_id'];
308
+
309
+ $base_file = $this->base_dir . sanitize_file_name( $this->get_base_key( $post_id ) );
310
+
311
+ $sns_counts = array();
312
+ $sns_base_counts = array();
313
+
314
+ if ( file_exists( $base_file ) ) {
315
+ $fp = fopen( $base_file, 'r' );
316
+
317
+ $data = fread( $fp, filesize( $base_file ) );
318
+
319
+ if ( fclose( $fp ) ) {
320
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
321
+ } else {
322
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
323
+ }
324
+
325
+ $sns_base_counts = unserialize( $data );
326
+ } else {
327
+ // if there is no base file.
328
+
329
+ if ( touch( $base_file ) ) {
330
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file creation succeeded: ' . $base_file );
331
+ } else {
332
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file creation failed: ' . $base_file );
333
+ }
334
+
335
+ if ( file_exists( $base_file ) ) {
336
+
337
+ $sns_counts = array();
338
+
339
+ if ( $post_id !== 'home' ) {
340
+ foreach ( $this->target_sns as $sns => $active ) {
341
+ if ( $active ) {
342
+ if ( $sns !== $this->crawl_date_key ) {
343
+ $meta_key = $this->get_cache_key( $sns );
344
+
345
+ $sns_count = get_post_meta( $post_id, $meta_key, true );
346
+
347
+ if ( isset( $sns_count ) && $sns_count !== '' && $sns_count >= 0 ) {
348
+ $sns_counts[$sns] = (int) $sns_count;
349
+ } else {
350
+ $sns_counts[$sns] = (int) -1;
351
+ }
352
+ } else {
353
+ $meta_key = $this->get_cache_key( $sns );
354
+
355
+ $sns_count = get_post_meta( $post_id, $meta_key, true );
356
+
357
+ if ( isset( $sns_count ) && $sns_count !== '' ) {
358
+ $sns_counts[$sns] = $sns_count;
359
+ } else {
360
+ $sns_counts[$sns] = '';
361
+ }
362
+ }
363
+ }
364
+ }
365
+ } else {
366
+ $option_key = $this->get_cache_key( 'home' );
367
+
368
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
369
+ foreach ( $this->target_sns as $sns => $active ) {
370
+ if ( $active ) {
371
+ if ( $sns !== $this->crawl_date_key ) {
372
+ if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
373
+ $sns_counts[$sns] = (int) -1;
374
+ }
375
+ } else {
376
+ if ( ! isset( $sns_counts[$sns] ) ) {
377
+ $sns_counts[$sns] = '';
378
+ }
379
+ }
380
+ }
381
+ }
382
+ }
383
+ }
384
+
385
+ $data = serialize( $sns_counts );
386
+
387
+ $fp = fopen( $base_file, 'w' );
388
+
389
+ if ( fwrite( $fp, $data ) ) {
390
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file write succeeded: ' );
391
+ } else {
392
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file wrote failed: ' );
393
+ }
394
+
395
+ if ( fclose( $fp ) ) {
396
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close succeeded: ' . $base_file );
397
+ } else {
398
+ SCC_Common_Util::log( '[' . __METHOD__ . '] file close failed: ' . $base_file );
399
+ }
400
+ }
401
+ }
402
+
403
+ $sns_counts = array();
404
+ $diffs = array();
405
+
406
+ if ( $post_id !== 'home' ) {
407
+ foreach ( $this->target_sns as $sns => $active ) {
408
+ if( $active ){
409
+ $meta_key = $this->get_cache_key( $sns );
410
+ $sns_counts[$sns] = get_post_meta( $post_id, $meta_key, true );
411
+ }
412
+ }
413
+
414
+ foreach ( $this->target_sns as $sns => $active ) {
415
+ if ( $active ){
416
+ if ( $sns !== $this->crawl_date_key ) {
417
+ $diff = (int) 0;
418
+
419
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 && ! isset( $sns_base_counts[$sns] ) ) {
420
+ $diff = (int) $sns_counts[$sns];
421
+ } elseif ( 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 ) {
422
+ $diff = (int) ( $sns_counts[$sns] - $sns_base_counts[$sns] );
423
+ } else {
424
+ $diff = (int) 0;
425
+ }
426
+
427
+ $meta_key = $this->get_delta_key( $sns );
428
+
429
+ update_post_meta( $post_id, $meta_key, (int) $diff );
430
+ } else {
431
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && isset( $sns_base_counts[$sns] ) && $sns_base_counts[$sns] !== '' ) {
432
+ $crawl_date = $sns_base_counts[$sns] . ',' . $sns_counts[$sns];
433
+ } else {
434
+ $crawl_date = '';
435
+ }
436
+
437
+ $meta_key = $this->get_delta_key( $sns );
438
+
439
+ update_post_meta( $post_id, $meta_key, $crawl_date );
440
+ }
441
+ }
442
+ }
443
+ } else {
444
+ $option_key = $this->get_cache_key( 'home' );
445
+
446
+ $diffs = array();
447
+
448
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
449
+
450
+ foreach ( $this->target_sns as $sns => $active ) {
451
+ if ( $active ){
452
+ if ( $sns !== $this->crawl_date_key ) {
453
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' && $sns_counts[$sns] >= 0 && ! isset( $sns_base_counts[$sns] ) ) {
454
+ $diffs[$sns] = (int) $sns_counts[$sns];
455
+ } elseif ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 && isset( $sns_base_counts[$sns] ) && $sns_base_counts[$sns] !== '' && $sns_base_counts[$sns] >= 0 ) {
456
+ $diffs[$sns] = (int)( $sns_counts[$sns] - $sns_base_counts[$sns] );
457
+ } else {
458
+ $diffs[$sns] = (int) 0;
459
+ }
460
+ } else {
461
+ if ( isset( $sns_counts[$sns] ) && isset( $sns_base_counts[$sns] ) && $sns_base_counts[$sns] !== '' ) {
462
+ $diffs[$sns] = $sns_base_counts[$sns] . ',' . $sns_counts[$sns];
463
+ } else {
464
+ $diffs[$sns] = '';
465
+ }
466
+ }
467
+ }
468
+ }
469
+
470
+ $option_key = $this->get_delta_key( 'home' );
471
+
472
+ update_option( $option_key, $diffs );
473
+
474
+ } else {
475
+
476
+ foreach ( $this->target_sns as $sns => $active ) {
477
+ if ( $active ){
478
+ if ( $sns !== $this->crawl_date_key ) {
479
+ $diffs[$sns] = (int) 0;
480
+ } else {
481
+ $diffs[$sns] = '';
482
+ }
483
+ }
484
+ }
485
+
486
+ $option_key = $this->get_delta_key( 'home' );
487
+
488
+ update_option( $option_key, $diffs );
489
+ }
490
+ }
491
+
492
+ }
493
+
494
+ /**
495
+ * Initialize meta key for ranking
496
+ *
497
+ * @since 0.3.0
498
+ */
499
+ public function initialize_base() {
500
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
501
+
502
+ /*
503
+ $option_key = $this->get_cache_key( $this->offset_suffix );
504
+
505
+ update_option( $option_key, 0 );
506
+ */
507
+ }
508
+
509
+ /**
510
+ * Clear meta key for ranking
511
+ *
512
+ * @since 0.3.0
513
+ */
514
+ public function clear_base() {
515
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
516
+
517
+ $option_key = $this->get_delta_key( 'home' );
518
+
519
+ delete_option( $option_key );
520
+
521
+ foreach ( $this->target_sns as $sns => $active ) {
522
+ if ( $active ) {
523
+ $meta_key = $this->get_delta_key( $sns );
524
+
525
+ delete_post_meta_by_key( $meta_key );
526
+ }
527
+ }
528
+
529
+ }
530
+
531
+ /**
532
+ * Clear meta key for ranking
533
+ *
534
+ * @since 0.7.0
535
+ */
536
+ public function clear_base_by_post_id( $post_id ) {
537
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
538
+
539
+ foreach ( $this->target_sns as $sns => $active ) {
540
+ if ( $active ) {
541
+ $meta_key = $this->get_delta_key( $sns );
542
+ delete_post_meta( $post_id, $meta_key );
543
+ }
544
+ }
545
+
546
+ }
547
+
548
+ }
549
+
550
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-scc-share-base-cache-engine.php CHANGED
@@ -1,410 +1,422 @@
1
- <?php
2
- /*
3
- class-scc-share-base-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Base_Cache_Engine extends SCC_Share_Cache_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
-
37
- /**
38
- * Cron name to schedule cache processing
39
- */
40
- const DEF_PRIME_CRON = 'scc_share_basecache_prime';
41
-
42
- /**
43
- * Cron name to execute cache processing
44
- */
45
- const DEF_EXECUTE_CRON = 'scc_share_basecache_exec';
46
-
47
- /**
48
- * Schedule name for cache processing
49
- */
50
- const DEF_EVENT_SCHEDULE = 'share_base_cache_event';
51
-
52
- /**
53
- * Schedule description for cache processing
54
- */
55
- const DEF_EVENT_DESCRIPTION = '[SCC] Share Base Cache Interval';
56
-
57
- /**
58
- * Interval cheking and caching target data
59
- */
60
- private $check_interval = 600;
61
-
62
- /**
63
- * Number of posts to check at a time
64
- */
65
- private $posts_per_check = 20;
66
-
67
- /**
68
- * Offset suffix
69
- */
70
- private $offset_suffix = 'base_offset';
71
-
72
- /**
73
- * Initialization
74
- *
75
- * @since 0.1.1
76
- */
77
- public function initialize( $options = array() ) {
78
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
79
-
80
- $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
81
- $this->prime_cron = self::DEF_PRIME_CRON;
82
- $this->execute_cron = self::DEF_EXECUTE_CRON;
83
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
84
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
85
-
86
- $this->load_ratio = 0.5;
87
-
88
- if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
89
- if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
90
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
91
- if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
92
- if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
93
- if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
94
- if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
95
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
96
- if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
97
- if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
98
- if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
99
- if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
100
- if ( isset( $options['scheme_migration_date'] ) ) $this->scheme_migration_date = $options['scheme_migration_date'];
101
- if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
102
- if ( isset( $options['cache_retry'] ) ) $this->cache_retry = $options['cache_retry'];
103
- if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
104
- if ( isset( $options['fault_tolerance'] ) ) $this->fault_tolerance = $options['fault_tolerance'];
105
-
106
- add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
107
- add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
108
- add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
109
- }
110
-
111
- /**
112
- * Register event schedule for this engine
113
- *
114
- * @since 0.1.0
115
- */
116
- public function schedule_check_interval( $schedules ) {
117
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
118
-
119
- $schedules[$this->event_schedule] = array(
120
- 'interval' => $this->check_interval,
121
- 'display' => $this->event_description
122
- );
123
-
124
- return $schedules;
125
- }
126
-
127
- /**
128
- * Schedule data retrieval and cache processing
129
- *
130
- * @since 0.1.0
131
- */
132
- public function prime_cache() {
133
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
134
-
135
- $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
136
- $posts_total = $this->get_posts_total();
137
-
138
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
139
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_per_check: ' . $this->posts_per_check );
140
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
141
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
142
-
143
- $option_key = $this->get_cache_key( $this->offset_suffix );
144
-
145
- if ( false === ( $posts_offset = get_option( $option_key ) ) ) {
146
- $posts_offset = 0;
147
- }
148
-
149
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_offset: ' . $posts_offset );
150
-
151
- wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( (int) $posts_offset ) );
152
-
153
- $posts_offset = $posts_offset + $this->posts_per_check;
154
-
155
- if ( $posts_offset > $posts_total ) {
156
- $posts_offset = 0;
157
- }
158
-
159
- update_option( $option_key, $posts_offset );
160
- }
161
-
162
- /**
163
- * Get and cache data of each published post and page
164
- *
165
- * @since 0.1.0
166
- */
167
- public function execute_cache( $posts_offset ) {
168
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
169
-
170
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_offset: ' . $posts_offset );
171
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
172
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_per_check: ' . $this->posts_per_check );
173
-
174
- $cache_expiration = $this->get_cache_expiration();
175
-
176
- SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
177
-
178
- // Cache home url
179
- if ( $posts_offset == 0 ) {
180
- $post_ID = 'home';
181
-
182
- $transient_id = $this->get_cache_key( $post_ID );
183
- $url = home_url( '/' );
184
-
185
- $options = array(
186
- 'cache_key' => $transient_id,
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
-
194
- // Primary cache
195
- $this->cache( $options );
196
-
197
- // Secondary cache
198
- $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
199
- }
200
-
201
- $query_args = array(
202
- 'post_type' => $this->post_types,
203
- 'post_status' => 'publish',
204
- 'offset' => $posts_offset,
205
- 'posts_per_page' => $this->posts_per_check,
206
- 'no_found_rows' => true,
207
- 'update_post_term_cache' => false,
208
- 'update_post_meta_cache' => false
209
- );
210
-
211
- $posts_query = new WP_Query( $query_args );
212
-
213
- if ( $posts_query->have_posts() ) {
214
- while ( $posts_query->have_posts() ) {
215
- $posts_query->the_post();
216
-
217
- $post_ID = get_the_ID();
218
-
219
- SCC_Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
220
-
221
- $transient_id = $this->get_cache_key( $post_ID );
222
-
223
- $url = get_permalink( $post_ID );
224
-
225
- $options = array(
226
- 'cache_key' => $transient_id,
227
- 'post_id' => $post_ID,
228
- 'target_url' => $url,
229
- 'target_sns' => $this->target_sns,
230
- 'publish_date' => get_the_date( 'Y/m/d' ),
231
- 'cache_expiration' => $cache_expiration
232
- );
233
-
234
- // Primary cache
235
- $this->cache( $options );
236
-
237
- // Secondary cache
238
- $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
239
- }
240
- }
241
- wp_reset_postdata();
242
- }
243
-
244
- /**
245
- * Get and cache data for a given post
246
- *
247
- * @since 0.1.1
248
- */
249
- public function direct_cache( $post_ID, $second_sync = false ) {
250
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
251
-
252
- $cache_expiration = $this->get_cache_expiration();
253
-
254
- SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
255
-
256
- $transient_id = $this->get_cache_key( $post_ID );
257
-
258
- if ( $post_ID != 'home' ) {
259
- $url = get_permalink( $post_ID );
260
- $publish_date = get_the_date( 'Y/m/d', $post_ID );
261
- } else {
262
- $url = home_url( '/' );
263
- $publish_date = NULL;
264
- }
265
-
266
- $options = array(
267
- 'cache_key' => $transient_id,
268
- 'post_id' => $post_ID,
269
- 'target_url' => $url,
270
- 'target_sns' => $this->target_sns,
271
- 'publish_date' => $publish_date,
272
- 'cache_expiration' => $cache_expiration
273
- );
274
-
275
- // Primary cache
276
- $result = $this->cache( $options );
277
-
278
- if ( $second_sync ) {
279
- // Secondary cache
280
- $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
281
- }
282
-
283
- return $result;
284
- }
285
-
286
- /**
287
- * Get cache expiration based on current number of total post and page
288
- *
289
- * @since 0.1.1
290
- */
291
- protected function get_cache_expiration() {
292
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
293
-
294
- $posts_total = $this->get_posts_total();
295
-
296
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
297
-
298
- return ceil( $posts_total / $this->posts_per_check ) * $this->check_interval * 3;
299
- }
300
-
301
- /**
302
- * Initialize meta key for ranking
303
- *
304
- * @since 0.3.0
305
- */
306
- public function initialize_cache() {
307
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
308
-
309
- $option_key = $this->get_cache_key( $this->offset_suffix );
310
-
311
- update_option( $option_key, 0 );
312
- }
313
-
314
- /**
315
- * Clear meta key for ranking
316
- *
317
- * @since 0.3.0
318
- */
319
- public function clear_cache() {
320
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
321
-
322
- $transient_id = $this->get_cache_key( 'home' );
323
-
324
- delete_transient( $transient_id );
325
-
326
- $query_args = array(
327
- 'post_type' => $this->post_types,
328
- 'post_status' => 'publish',
329
- 'nopaging' => true,
330
- 'update_post_term_cache' => false,
331
- 'update_post_meta_cache' => false
332
- );
333
-
334
- $posts_query = new WP_Query( $query_args );
335
-
336
- if ( $posts_query->have_posts() ) {
337
- while ( $posts_query->have_posts() ) {
338
- $posts_query->the_post();
339
-
340
- $post_ID = get_the_ID();
341
-
342
- $transient_id = $this->get_cache_key( $post_ID );
343
-
344
- delete_transient( $transient_id );
345
- }
346
- }
347
- wp_reset_postdata();
348
-
349
- $option_key = $this->get_cache_key( $this->offset_suffix );
350
-
351
- delete_option( $option_key );
352
- }
353
-
354
-
355
- /**
356
- * Clear meta key for ranking
357
- *
358
- * @since 0.7.0
359
- */
360
- public function clear_cache_by_post_id( $post_id ) {
361
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
362
-
363
- $transient_id = $this->get_cache_key( $post_id );
364
-
365
- delete_transient( $transient_id );
366
- }
367
-
368
- /**
369
- * Get total count of current published post and page
370
- *
371
- * @since 0.1.0
372
- */
373
- private function get_posts_total() {
374
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
375
-
376
- $query_args = array(
377
- 'post_type' => $this->post_types,
378
- 'post_status' => 'publish',
379
- 'nopaging' => true,
380
- 'update_post_term_cache' => false,
381
- 'update_post_meta_cache' => false
382
- );
383
-
384
- $posts_query = new WP_Query( $query_args );
385
-
386
- return $posts_query->found_posts;
387
- }
388
-
389
- /**
390
- * Get current cache
391
- *
392
- * @since 0.9.3
393
- */
394
- protected function get_current_cache( $options = array() ) {
395
- $post_id = $options['post_id'];
396
-
397
- $transient_id = $this->get_cache_key( $post_id );
398
-
399
- $sns_counts = array();
400
-
401
- if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
402
- return $sns_counts;
403
- } else {
404
- return $this->delegate_order( SCC_Order::ORDER_GET_SECOND_CACHE, $options );
405
- }
406
- }
407
-
408
- }
409
-
410
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-base-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Base_Cache_Engine extends SCC_Share_Cache_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
+
37
+ /**
38
+ * Cron name to schedule cache processing
39
+ */
40
+ const DEF_PRIME_CRON = 'scc_share_basecache_prime';
41
+
42
+ /**
43
+ * Cron name to execute cache processing
44
+ */
45
+ const DEF_EXECUTE_CRON = 'scc_share_basecache_exec';
46
+
47
+ /**
48
+ * Schedule name for cache processing
49
+ */
50
+ const DEF_EVENT_SCHEDULE = 'share_base_cache_event';
51
+
52
+ /**
53
+ * Schedule description for cache processing
54
+ */
55
+ const DEF_EVENT_DESCRIPTION = '[SCC] Share Base Cache Interval';
56
+
57
+ /**
58
+ * Cache post types
59
+ */
60
+ private $post_types = array( 'post', 'page' );
61
+
62
+ /**
63
+ * Interval cheking and caching target data
64
+ */
65
+ private $check_interval = 600;
66
+
67
+ /**
68
+ * Number of posts to check at a time
69
+ */
70
+ private $posts_per_check = 20;
71
+
72
+ /**
73
+ * Offset suffix
74
+ */
75
+ private $offset_suffix = 'base_offset';
76
+
77
+ /**
78
+ * Initialization
79
+ *
80
+ * @since 0.1.1
81
+ */
82
+ public function initialize( $options = array() ) {
83
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
84
+
85
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
86
+ $this->prime_cron = self::DEF_PRIME_CRON;
87
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
88
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
89
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
90
+
91
+ $this->load_ratio = 0.5;
92
+
93
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
94
+ if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
95
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
96
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
97
+ if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
98
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
99
+ if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
100
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
101
+ if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
102
+ if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
103
+ if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
104
+ if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
105
+ if ( isset( $options['scheme_migration_date'] ) ) $this->scheme_migration_date = $options['scheme_migration_date'];
106
+ if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
107
+ if ( isset( $options['cache_retry'] ) ) $this->cache_retry = $options['cache_retry'];
108
+ if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
109
+ if ( isset( $options['fault_tolerance'] ) ) $this->fault_tolerance = $options['fault_tolerance'];
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, 1 );
114
+ }
115
+
116
+ /**
117
+ * Register event schedule for this engine
118
+ *
119
+ * @since 0.1.0
120
+ */
121
+ public function schedule_check_interval( $schedules ) {
122
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
123
+
124
+ $schedules[$this->event_schedule] = array(
125
+ 'interval' => $this->check_interval,
126
+ 'display' => $this->event_description
127
+ );
128
+
129
+ return $schedules;
130
+ }
131
+
132
+ /**
133
+ * Schedule data retrieval and cache processing
134
+ *
135
+ * @since 0.1.0
136
+ */
137
+ public function prime_cache() {
138
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
139
+
140
+ $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
141
+ $posts_total = $this->get_posts_total();
142
+
143
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
144
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_per_check: ' . $this->posts_per_check );
145
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
146
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
147
+
148
+ $option_key = $this->get_cache_key( $this->offset_suffix );
149
+
150
+ if ( false === ( $posts_offset = get_option( $option_key ) ) ) {
151
+ $posts_offset = 0;
152
+ }
153
+
154
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_offset: ' . $posts_offset );
155
+
156
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( (int) $posts_offset ) );
157
+
158
+ $posts_offset = $posts_offset + $this->posts_per_check;
159
+
160
+ if ( $posts_offset > $posts_total ) {
161
+ $posts_offset = 0;
162
+ }
163
+
164
+ update_option( $option_key, $posts_offset );
165
+ }
166
+
167
+ /**
168
+ * Get and cache data of each published post and page
169
+ *
170
+ * @since 0.1.0
171
+ */
172
+ public function execute_cache( $posts_offset ) {
173
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
174
+
175
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_offset: ' . $posts_offset );
176
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
177
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_per_check: ' . $this->posts_per_check );
178
+
179
+ $cache_expiration = $this->get_cache_expiration();
180
+
181
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
182
+
183
+ // Cache home url
184
+ if ( $posts_offset == 0 ) {
185
+ $post_ID = 'home';
186
+
187
+ $transient_id = $this->get_cache_key( $post_ID );
188
+ $url = home_url( '/' );
189
+ $title = get_bloginfo( 'name' );
190
+
191
+ $options = array(
192
+ 'cache_key' => $transient_id,
193
+ 'post_id' => $post_ID,
194
+ 'target_url' => $url,
195
+ 'target_sns' => $this->target_sns,
196
+ 'target_title' => $title,
197
+ 'publish_date' => NULL,
198
+ 'cache_expiration' => $cache_expiration
199
+ );
200
+
201
+ // Primary cache
202
+ $this->cache( $options );
203
+
204
+ // Secondary cache
205
+ $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
206
+ }
207
+
208
+ $query_args = array(
209
+ 'post_type' => $this->post_types,
210
+ 'post_status' => 'publish',
211
+ 'offset' => $posts_offset,
212
+ 'posts_per_page' => $this->posts_per_check,
213
+ 'no_found_rows' => true,
214
+ 'update_post_term_cache' => false,
215
+ 'update_post_meta_cache' => false
216
+ );
217
+
218
+ $posts_query = new WP_Query( $query_args );
219
+
220
+ if ( $posts_query->have_posts() ) {
221
+ while ( $posts_query->have_posts() ) {
222
+ $posts_query->the_post();
223
+
224
+ $post_ID = get_the_ID();
225
+
226
+ SCC_Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
227
+
228
+ $transient_id = $this->get_cache_key( $post_ID );
229
+
230
+ $url = get_permalink( $post_ID );
231
+ $title = get_the_title( $post_ID );
232
+
233
+ $options = array(
234
+ 'cache_key' => $transient_id,
235
+ 'post_id' => $post_ID,
236
+ 'target_url' => $url,
237
+ 'target_sns' => $this->target_sns,
238
+ 'target_title' => $title,
239
+ 'publish_date' => get_the_date( 'Y/m/d' ),
240
+ 'cache_expiration' => $cache_expiration
241
+ );
242
+
243
+ // Primary cache
244
+ $this->cache( $options );
245
+
246
+ // Secondary cache
247
+ $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
248
+ }
249
+ }
250
+ wp_reset_postdata();
251
+ }
252
+
253
+ /**
254
+ * Get and cache data for a given post
255
+ *
256
+ * @since 0.1.1
257
+ */
258
+ public function direct_cache( $post_ID, $second_sync = false ) {
259
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
260
+
261
+ $cache_expiration = $this->get_cache_expiration();
262
+
263
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
264
+
265
+ $transient_id = $this->get_cache_key( $post_ID );
266
+
267
+ if ( $post_ID != 'home' ) {
268
+ $url = get_permalink( $post_ID );
269
+ $title = get_the_title( $post_ID );
270
+ $publish_date = get_the_date( 'Y/m/d', $post_ID );
271
+ } else {
272
+ $url = home_url( '/' );
273
+ $title = get_bloginfo( 'name' );
274
+ $publish_date = NULL;
275
+ }
276
+
277
+ $options = array(
278
+ 'cache_key' => $transient_id,
279
+ 'post_id' => $post_ID,
280
+ 'target_url' => $url,
281
+ 'target_sns' => $this->target_sns,
282
+ 'target_title' => $title,
283
+ 'publish_date' => $publish_date,
284
+ 'cache_expiration' => $cache_expiration
285
+ );
286
+
287
+ // Primary cache
288
+ $result = $this->cache( $options );
289
+
290
+ if ( $second_sync ) {
291
+ // Secondary cache
292
+ $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
293
+ }
294
+
295
+ return $result;
296
+ }
297
+
298
+ /**
299
+ * Get cache expiration based on current number of total post and page
300
+ *
301
+ * @since 0.1.1
302
+ */
303
+ protected function get_cache_expiration() {
304
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
305
+
306
+ $posts_total = $this->get_posts_total();
307
+
308
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
309
+
310
+ return ceil( $posts_total / $this->posts_per_check ) * $this->check_interval * 3;
311
+ }
312
+
313
+ /**
314
+ * Initialize meta key for ranking
315
+ *
316
+ * @since 0.3.0
317
+ */
318
+ public function initialize_cache() {
319
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
320
+
321
+ $option_key = $this->get_cache_key( $this->offset_suffix );
322
+
323
+ update_option( $option_key, 0 );
324
+ }
325
+
326
+ /**
327
+ * Clear meta key for ranking
328
+ *
329
+ * @since 0.3.0
330
+ */
331
+ public function clear_cache() {
332
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
333
+
334
+ $transient_id = $this->get_cache_key( 'home' );
335
+
336
+ delete_transient( $transient_id );
337
+
338
+ $query_args = array(
339
+ 'post_type' => $this->post_types,
340
+ 'post_status' => 'publish',
341
+ 'nopaging' => true,
342
+ 'update_post_term_cache' => false,
343
+ 'update_post_meta_cache' => false
344
+ );
345
+
346
+ $posts_query = new WP_Query( $query_args );
347
+
348
+ if ( $posts_query->have_posts() ) {
349
+ while ( $posts_query->have_posts() ) {
350
+ $posts_query->the_post();
351
+
352
+ $post_ID = get_the_ID();
353
+
354
+ $transient_id = $this->get_cache_key( $post_ID );
355
+
356
+ delete_transient( $transient_id );
357
+ }
358
+ }
359
+ wp_reset_postdata();
360
+
361
+ $option_key = $this->get_cache_key( $this->offset_suffix );
362
+
363
+ delete_option( $option_key );
364
+ }
365
+
366
+
367
+ /**
368
+ * Clear meta key for ranking
369
+ *
370
+ * @since 0.7.0
371
+ */
372
+ public function clear_cache_by_post_id( $post_id ) {
373
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
374
+
375
+ $transient_id = $this->get_cache_key( $post_id );
376
+
377
+ delete_transient( $transient_id );
378
+ }
379
+
380
+ /**
381
+ * Get total count of current published post and page
382
+ *
383
+ * @since 0.1.0
384
+ */
385
+ private function get_posts_total() {
386
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
387
+
388
+ $query_args = array(
389
+ 'post_type' => $this->post_types,
390
+ 'post_status' => 'publish',
391
+ 'nopaging' => true,
392
+ 'update_post_term_cache' => false,
393
+ 'update_post_meta_cache' => false
394
+ );
395
+
396
+ $posts_query = new WP_Query( $query_args );
397
+
398
+ return $posts_query->found_posts;
399
+ }
400
+
401
+ /**
402
+ * Get cache
403
+ *
404
+ * @since 0.9.3
405
+ */
406
+ public function get_cache( $options = array() ) {
407
+ $post_id = $options['post_id'];
408
+
409
+ $transient_id = $this->get_cache_key( $post_id );
410
+
411
+ $sns_counts = array();
412
+
413
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
414
+ return $sns_counts;
415
+ } else {
416
+ return $this->delegate_order( SCC_Order::ORDER_GET_SECOND_CACHE, $options );
417
+ }
418
+ }
419
+
420
+ }
421
+
422
+ ?>
includes/class-scc-share-cache-engine.php CHANGED
@@ -1,296 +1,308 @@
1
- <?php
2
- /*
3
- class-scc-share-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- abstract class SCC_Share_Cache_Engine extends SCC_Cache_Engine {
31
-
32
- /**
33
- * Crawler instance
34
- */
35
- protected $crawler = NULL;
36
-
37
- /**
38
- * Cache target
39
- */
40
- protected $target_sns = array();
41
-
42
- /**
43
- * Cache post types
44
- */
45
- protected $post_types = array( 'post', 'page' );
46
-
47
- /**
48
- * migration mode from http to https
49
- */
50
- protected $scheme_migration_mode = false;
51
-
52
- /**
53
- * migration date from http to https
54
- */
55
- protected $scheme_migration_date = NULL;
56
-
57
- /**
58
- * excluded keys in scheme migration
59
- */
60
- protected $scheme_migration_exclude_keys = array();
61
-
62
- /**
63
- * load ratio for throttle
64
- */
65
- protected $load_ratio = 0.5;
66
-
67
- /**
68
- * Get and cache data for a given post
69
- *
70
- * @since 0.1.1
71
- */
72
- public function cache( $options = array() ) {
73
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
74
-
75
- $cache_key = $options['cache_key'];
76
- $post_id = $options['post_id'];
77
- $target_url = $options['target_url'];
78
- $target_sns = $options['target_sns'];
79
- $cache_expiration = $options['cache_expiration'];
80
- $publish_date = $options['publish_date'];
81
-
82
- SCC_Common_Util::log( '[' . __METHOD__ . '] current memory usage: ' . round( memory_get_usage( true )/1024/1024, 2 ) . ' MB' );
83
- SCC_Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_url );
84
-
85
- $data = $this->get_data( $target_sns, $target_url );
86
-
87
- SCC_Common_Util::log( $data );
88
- SCC_Common_Util::log( '[' . __METHOD__ . '] scheme migration date: ' . $this->scheme_migration_date );
89
- SCC_Common_Util::log( '[' . __METHOD__ . '] publish date: ' . $publish_date );
90
-
91
- if ( $this->scheme_migration_mode && SCC_Common_Util::is_secure_url( $target_url ) ) {
92
- if ( ! isset( $this->scheme_migration_date ) ) {
93
- $target_normal_url = SCC_Common_Util::get_normal_url( $target_url );
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
- SCC_Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_normal_url );
101
-
102
- $migrated_data = $this->get_data( $target_sns_migrated, $target_normal_url );
103
-
104
- SCC_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
- $target_normal_url = SCC_Common_Util::get_normal_url( $target_url );
116
- $target_sns_migrated = $target_sns;
117
-
118
- foreach ( $this->scheme_migration_exclude_keys as $sns ) {
119
- unset( $target_sns_migrated[$sns] );
120
- }
121
-
122
- SCC_Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_normal_url );
123
-
124
- $migrated_data = $this->get_data( $target_sns_migrated, $target_normal_url );
125
-
126
- SCC_Common_Util::log( $migrated_data );
127
-
128
- foreach ( $target_sns_migrated as $sns => $active ) {
129
- if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
130
- $data[$sns] = $data[$sns] + $migrated_data[$sns];
131
- }
132
- }
133
- }
134
- } else {
135
- $target_normal_url = SCC_Common_Util::get_normal_url( $target_url );
136
- $target_sns_migrated = $target_sns;
137
-
138
- foreach ( $this->scheme_migration_exclude_keys as $sns ) {
139
- unset( $target_sns_migrated[$sns] );
140
- }
141
-
142
- SCC_Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_url );
143
-
144
- $migrated_data = $this->get_data( $target_sns_migrated, $target_url );
145
-
146
- SCC_Common_Util::log( $migrated_data );
147
-
148
- foreach ( $target_sns_migrated as $sns => $active ) {
149
- if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
150
- $data[$sns] = $data[$sns] + $migrated_data[$sns];
151
- }
152
- }
153
- }
154
- }
155
-
156
- $target_sns_param = $target_sns;
157
-
158
- unset( $target_sns_param[SNS_Count_Cache::REF_CRAWL_DATE] );
159
- unset( $target_sns_param[SNS_Count_Cache::REF_SHARE_TOTAL] );
160
-
161
- $query_parameters = array(
162
- 'url' => $target_url
163
- );
164
-
165
- foreach ( $target_sns_param as $sns => $active ) {
166
- if ( $active ) {
167
- $this->crawler->set_crawl_strategy_query_parameters( $sns, $query_parameters );
168
- }
169
- }
170
- }
171
-
172
- if ( $this->fault_tolerance === SNS_Count_Cache::OPT_COMMON_FAULT_TOLERANCE_ON ) {
173
-
174
- $target_sns_tmp = $target_sns;
175
- unset( $target_sns_tmp[SNS_Count_Cache::REF_CRAWL_DATE] );
176
- unset( $target_sns_tmp[SNS_Count_Cache::REF_SHARE_TOTAL] );
177
-
178
- $target_sns_tolerance = array();
179
-
180
- foreach ( $target_sns_tmp as $sns => $active ){
181
- if ( $active ) {
182
- if ( ! isset( $data[$sns] ) || $data[$sns] === -1 ) {
183
- $target_sns_tolerance[$sns] = true;
184
- }
185
- }
186
- }
187
-
188
- if ( ! empty( $target_sns_tolerance) ) {
189
- $current_data = $this->get_current_cache( $options );
190
-
191
- foreach ( $target_sns_tolerance as $sns => $active ){
192
- if ( $active ) {
193
- if ( isset( $current_data[$sns] ) && $current_data[$sns] >= 0 ) {
194
- $data[$sns] = $current_data[$sns];
195
- }
196
- }
197
- }
198
-
199
- $total = 0;
200
-
201
- foreach ( $target_sns_tmp as $sns => $active ){
202
- if ( $active ) {
203
- if ( isset( $data[$sns] ) && $data[$sns] >= 0 ) {
204
- $total = $total + $data[$sns];
205
- }
206
- }
207
- }
208
-
209
- $data[SNS_Count_Cache::REF_SHARE_TOTAL] = $total;
210
- }
211
- }
212
-
213
- SCC_Common_Util::log( $data );
214
-
215
- if ( $data ) {
216
- $throttle = new SCC_Sleep_Throttle( $this->load_ratio );
217
-
218
- $throttle->reset();
219
- $throttle->start();
220
-
221
- $result = set_transient( $cache_key, $data, $cache_expiration );
222
- $throttle->stop();
223
-
224
- $retry_count = 0;
225
-
226
- while ( true ) {
227
-
228
- SCC_Common_Util::log( '[' . __METHOD__ . '] set_transient result (' . $cache_key . '): ' . $result );
229
-
230
- if ( $result ) {
231
- break;
232
- } else {
233
- if ( $retry_count < $this->retry_limit ) {
234
- SCC_Common_Util::log( '[' . __METHOD__ . '] sleep before set_transient retry (' . $cache_key . '): ' . $throttle->get_sleep_time() . ' sec.' );
235
-
236
- $throttle->sleep();
237
- ++$retry_count;
238
-
239
- SCC_Common_Util::log( '[' . __METHOD__ . '] count of set_transient retry (' . $cache_key . '): ' . $retry_count );
240
-
241
- $throttle->reset();
242
- $throttle->start();
243
-
244
- $result = set_transient( $cache_key, $data, $cache_expiration );
245
-
246
- $throttle->stop();
247
- } else {
248
- SCC_Common_Util::log( '[' . __METHOD__ . '] set_transient result (' . $cache_key . '): retry failed' );
249
- break;
250
- }
251
- }
252
- }
253
- }
254
-
255
- SCC_Common_Util::log( '[' . __METHOD__ . '] current memory usage: ' . round( memory_get_usage( true )/1024/1024, 2 ) . ' MB' );
256
- SCC_Common_Util::log( '[' . __METHOD__ . '] max memory usage: ' . round( memory_get_peak_usage( true )/1024/1024, 2 ) . ' MB' );
257
-
258
- return $data;
259
- }
260
-
261
- /**
262
- * Get data
263
- *
264
- * @since 0.9.0
265
- */
266
- private function get_data( $target_sns, $target_url ) {
267
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
268
-
269
- $target_sns_base = $target_sns;
270
-
271
- unset( $target_sns_base[SNS_Count_Cache::REF_CRAWL_DATE] );
272
- unset( $target_sns_base[SNS_Count_Cache::REF_SHARE_TOTAL] );
273
-
274
- $query_parameters = array(
275
- 'url' => $target_url
276
- );
277
-
278
- foreach ( $target_sns_base as $sns => $active ) {
279
- if ( $active ) {
280
- $this->crawler->set_crawl_strategy_query_parameters( $sns, $query_parameters );
281
- }
282
- }
283
-
284
- return $this->crawler->get_data( $target_sns, NULL );
285
- }
286
-
287
- /**
288
- * Get current cache
289
- *
290
- * @since 0.9.3
291
- */
292
- abstract protected function get_current_cache( $options = array() );
293
-
294
- }
295
-
296
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ abstract class SCC_Share_Cache_Engine extends SCC_Cache_Engine {
31
+
32
+ /**
33
+ * Crawler instance
34
+ */
35
+ protected $crawler = NULL;
36
+
37
+ /**
38
+ * Cache target
39
+ */
40
+ protected $target_sns = array();
41
+
42
+ /**
43
+ * migration mode from http to https
44
+ */
45
+ protected $scheme_migration_mode = false;
46
+
47
+ /**
48
+ * migration date from http to https
49
+ */
50
+ protected $scheme_migration_date = NULL;
51
+
52
+ /**
53
+ * excluded keys in scheme migration
54
+ */
55
+ protected $scheme_migration_exclude_keys = array();
56
+
57
+ /**
58
+ * load ratio for throttle
59
+ */
60
+ protected $load_ratio = 0.5;
61
+
62
+ /**
63
+ * Get and cache data for a given post
64
+ *
65
+ * @since 0.1.1
66
+ */
67
+ public function cache( $options = array() ) {
68
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
69
+
70
+ $cache_key = $options['cache_key'];
71
+ $target_url = $options['target_url'];
72
+ $target_sns = $options['target_sns'];
73
+ $cache_expiration = $options['cache_expiration'];
74
+ $publish_date = $options['publish_date'];
75
+ $target_title = $options['target_title'];
76
+
77
+ SCC_Common_Util::log( '[' . __METHOD__ . '] current memory usage: ' . round( memory_get_usage( true )/1024/1024, 2 ) . ' MB' );
78
+ SCC_Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_url );
79
+
80
+ $target_option = array(
81
+ 'target_url' => $target_url,
82
+ 'target_title' => $target_title
83
+ );
84
+
85
+ $data = $this->get_data( $target_sns, $target_option );
86
+
87
+ SCC_Common_Util::log( $data );
88
+ SCC_Common_Util::log( '[' . __METHOD__ . '] scheme migration date: ' . $this->scheme_migration_date );
89
+ SCC_Common_Util::log( '[' . __METHOD__ . '] publish date: ' . $publish_date );
90
+
91
+ if ( $this->scheme_migration_mode && SCC_Common_Util::is_secure_url( $target_url ) ) {
92
+ if ( ! isset( $this->scheme_migration_date ) ) {
93
+ $target_normal_url = SCC_Common_Util::get_normal_url( $target_url );
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
+ SCC_Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_normal_url );
101
+
102
+ $target_option = array(
103
+ 'target_url' => $target_normal_url,
104
+ 'target_title' => $target_title
105
+ );
106
+
107
+ $migrated_data = $this->get_data( $target_sns_migrated, $target_option );
108
+
109
+ SCC_Common_Util::log( $migrated_data );
110
+
111
+ foreach ( $target_sns_migrated as $sns => $active ) {
112
+ if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
113
+ $data[$sns] = $data[$sns] + $migrated_data[$sns];
114
+ }
115
+ }
116
+
117
+ } else {
118
+ if ( isset( $publish_date ) ) {
119
+ if ( strtotime( $publish_date ) <= strtotime( $this->scheme_migration_date ) ) {
120
+ $target_normal_url = SCC_Common_Util::get_normal_url( $target_url );
121
+ $target_sns_migrated = $target_sns;
122
+
123
+ foreach ( $this->scheme_migration_exclude_keys as $sns ) {
124
+ unset( $target_sns_migrated[$sns] );
125
+ }
126
+
127
+ SCC_Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_normal_url );
128
+
129
+ $target_option = array(
130
+ 'target_url' => $target_normal_url,
131
+ 'target_title' => $target_title
132
+ );
133
+
134
+ $migrated_data = $this->get_data( $target_sns_migrated, $target_option );
135
+
136
+ SCC_Common_Util::log( $migrated_data );
137
+
138
+ foreach ( $target_sns_migrated as $sns => $active ) {
139
+ if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
140
+ $data[$sns] = $data[$sns] + $migrated_data[$sns];
141
+ }
142
+ }
143
+ }
144
+ } else {
145
+ $target_normal_url = SCC_Common_Util::get_normal_url( $target_url );
146
+ $target_sns_migrated = $target_sns;
147
+
148
+ foreach ( $this->scheme_migration_exclude_keys as $sns ) {
149
+ unset( $target_sns_migrated[$sns] );
150
+ }
151
+
152
+ SCC_Common_Util::log( '[' . __METHOD__ . '] target url: ' . $target_url );
153
+
154
+ $target_option = array(
155
+ 'target_url' => $target_url,
156
+ 'target_title' => $target_title
157
+ );
158
+
159
+ $migrated_data = $this->get_data( $target_sns_migrated, $target_option );
160
+
161
+ SCC_Common_Util::log( $migrated_data );
162
+
163
+ foreach ( $target_sns_migrated as $sns => $active ) {
164
+ if ( $active && isset( $migrated_data[$sns] ) && is_numeric( $migrated_data[$sns] ) && $migrated_data[$sns] > 0 ){
165
+ $data[$sns] = $data[$sns] + $migrated_data[$sns];
166
+ }
167
+ }
168
+ }
169
+ }
170
+
171
+ $target_sns_param = $target_sns;
172
+
173
+ unset( $target_sns_param[SNS_Count_Cache::REF_CRAWL_DATE] );
174
+ unset( $target_sns_param[SNS_Count_Cache::REF_SHARE_TOTAL] );
175
+
176
+ $query_parameters = array(
177
+ 'url' => $target_url
178
+ );
179
+
180
+ foreach ( $target_sns_param as $sns => $active ) {
181
+ if ( $active ) {
182
+ $this->crawler->set_crawl_strategy_query_parameters( $sns, $query_parameters );
183
+ }
184
+ }
185
+ }
186
+
187
+ if ( $this->fault_tolerance === SNS_Count_Cache::OPT_COMMON_FAULT_TOLERANCE_ON ) {
188
+
189
+ $target_sns_tmp = $target_sns;
190
+ unset( $target_sns_tmp[SNS_Count_Cache::REF_CRAWL_DATE] );
191
+ unset( $target_sns_tmp[SNS_Count_Cache::REF_SHARE_TOTAL] );
192
+
193
+ $target_sns_tolerance = array();
194
+
195
+ foreach ( $target_sns_tmp as $sns => $active ){
196
+ if ( $active ) {
197
+ if ( ! isset( $data[$sns] ) || $data[$sns] === -1 ) {
198
+ $target_sns_tolerance[$sns] = true;
199
+ }
200
+ }
201
+ }
202
+
203
+ if ( ! empty( $target_sns_tolerance) ) {
204
+ $current_data = $this->get_cache( $options );
205
+
206
+ foreach ( $target_sns_tolerance as $sns => $active ){
207
+ if ( $active ) {
208
+ if ( isset( $current_data[$sns] ) && $current_data[$sns] >= 0 ) {
209
+ $data[$sns] = $current_data[$sns];
210
+ }
211
+ }
212
+ }
213
+
214
+ $total = 0;
215
+
216
+ foreach ( $target_sns_tmp as $sns => $active ){
217
+ if ( $active ) {
218
+ if ( isset( $data[$sns] ) && $data[$sns] >= 0 ) {
219
+ $total = $total + $data[$sns];
220
+ }
221
+ }
222
+ }
223
+
224
+ $data[SNS_Count_Cache::REF_SHARE_TOTAL] = $total;
225
+ }
226
+ }
227
+
228
+ SCC_Common_Util::log( $data );
229
+
230
+ if ( $data ) {
231
+ $throttle = new SCC_Sleep_Throttle( $this->load_ratio );
232
+
233
+ $throttle->reset();
234
+ $throttle->start();
235
+
236
+ $result = set_transient( $cache_key, $data, $cache_expiration );
237
+ $throttle->stop();
238
+
239
+ $retry_count = 0;
240
+
241
+ while ( true ) {
242
+
243
+ SCC_Common_Util::log( '[' . __METHOD__ . '] set_transient result (' . $cache_key . '): ' . $result );
244
+
245
+ if ( $result ) {
246
+ break;
247
+ } else {
248
+ if ( $retry_count < $this->retry_limit ) {
249
+ SCC_Common_Util::log( '[' . __METHOD__ . '] sleep before set_transient retry (' . $cache_key . '): ' . $throttle->get_sleep_time() . ' sec.' );
250
+
251
+ $throttle->sleep();
252
+ ++$retry_count;
253
+
254
+ SCC_Common_Util::log( '[' . __METHOD__ . '] count of set_transient retry (' . $cache_key . '): ' . $retry_count );
255
+
256
+ $throttle->reset();
257
+ $throttle->start();
258
+
259
+ $result = set_transient( $cache_key, $data, $cache_expiration );
260
+
261
+ $throttle->stop();
262
+ } else {
263
+ SCC_Common_Util::log( '[' . __METHOD__ . '] set_transient result (' . $cache_key . '): retry failed' );
264
+ break;
265
+ }
266
+ }
267
+ }
268
+ }
269
+
270
+ SCC_Common_Util::log( '[' . __METHOD__ . '] current memory usage: ' . round( memory_get_usage( true )/1024/1024, 2 ) . ' MB' );
271
+ SCC_Common_Util::log( '[' . __METHOD__ . '] max memory usage: ' . round( memory_get_peak_usage( true )/1024/1024, 2 ) . ' MB' );
272
+
273
+ return $data;
274
+ }
275
+
276
+ /**
277
+ * Get data
278
+ *
279
+ * @since 0.9.0
280
+ */
281
+ private function get_data( $target_sns, $target_option ) {
282
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
283
+
284
+ $target_sns_base = $target_sns;
285
+
286
+ $target_url = $target_option['target_url'];
287
+ $target_title = $target_option['target_title'];
288
+
289
+ unset( $target_sns_base[SNS_Count_Cache::REF_CRAWL_DATE] );
290
+ unset( $target_sns_base[SNS_Count_Cache::REF_SHARE_TOTAL] );
291
+
292
+ $query_parameters = array(
293
+ 'url' => $target_url,
294
+ 'title' => $target_title
295
+ );
296
+
297
+ foreach ( $target_sns_base as $sns => $active ) {
298
+ if ( $active ) {
299
+ $this->crawler->set_crawl_strategy_query_parameters( $sns, $query_parameters );
300
+ }
301
+ }
302
+
303
+ return $this->crawler->get_data( $target_sns, NULL );
304
+ }
305
+
306
+ }
307
+
308
+ ?>
includes/class-scc-share-crawl-strategy-factory.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-crawl-strategy-factory.php
4
+
5
+ Description: This class is a data crawler whitch get share count using given API and cURL
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Crawl_Strategy_Factory {
31
+
32
+ /**
33
+ * Carete crawl strategy
34
+ *
35
+ * @since 0.9.0
36
+ */
37
+ public static function create_crawl_strategy( $sns ) {
38
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
39
+
40
+ switch ( $sns ) {
41
+ case SNS_Count_Cache::REF_SHARE_TWITTER:
42
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
43
+ return SCC_Share_Twitter_Strategy::get_instance();
44
+ break;
45
+ case SNS_Count_Cache::REF_SHARE_FACEBOOK:
46
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
47
+ return SCC_Share_Facebook_Strategy::get_instance();
48
+ break;
49
+ case SNS_Count_Cache::REF_SHARE_GPLUS:
50
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
51
+ return SCC_Share_Google_Strategy::get_instance();
52
+ break;
53
+ case SNS_Count_Cache::REF_SHARE_POCKET:
54
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
55
+ return SCC_Share_Pocket_Strategy::get_instance();
56
+ break;
57
+ case SNS_Count_Cache::REF_SHARE_HATEBU:
58
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
59
+ return SCC_Share_Hatebu_Strategy::get_instance();
60
+ break;
61
+ case SNS_Count_Cache::REF_SHARE_PINTEREST:
62
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
63
+ return SCC_Share_Pinterest_Strategy::get_instance();
64
+ break;
65
+ case SNS_Count_Cache::REF_SHARE_LINKEDIN:
66
+ SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
67
+ return SCC_Share_Linkedin_Strategy::get_instance();
68
+ break;
69
+ }
70
+ }
71
+
72
+ }
73
+
74
+ ?>
includes/class-scc-share-crawler.php CHANGED
@@ -1,307 +1,271 @@
1
- <?php
2
- /*
3
- class-scc-share-crawler.php
4
-
5
- Description: This class is a data crawler whitch get share count using given API and cURL
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Crawler extends SCC_Crawler {
31
-
32
- /**
33
- * Initialization
34
- *
35
- * @since 0.5.1
36
- */
37
- public function initialize( $options = array() ) {
38
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
39
-
40
- //$this->throttle = new Sleep_Throttle( 0.9 );
41
-
42
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
43
- if ( isset( $options['crawl_method'] ) ) $this->crawl_method = $options['crawl_method'];
44
- if ( isset( $options['timeout'] ) ) $this->timeout = $options['timeout'];
45
- if ( isset( $options['ssl_verification'] ) ) $this->ssl_verification = $options['ssl_verification'];
46
- if ( isset( $options['crawl_retry'] ) ) $this->crawl_retry = $options['crawl_retry'];
47
- if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
48
-
49
- $target_sns = $this->target_sns;
50
-
51
- unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
52
- unset( $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] );
53
-
54
- foreach ( $target_sns as $sns => $active ) {
55
- if ( $active ) {
56
- $this->crawl_strategies[$sns] = $this->create_crawl_strategy( $sns );
57
- }
58
- }
59
-
60
- }
61
-
62
- /**
63
- * Carete crawl strategy
64
- *
65
- * @since 0.9.0
66
- */
67
- private function create_crawl_strategy( $sns ) {
68
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
69
-
70
- switch ( $sns ) {
71
- case SNS_Count_Cache::REF_SHARE_TWITTER:
72
- SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
73
- return SCC_Share_Twitter_Strategy::get_instance();
74
- break;
75
- case SNS_Count_Cache::REF_SHARE_FACEBOOK:
76
- SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
77
- return SCC_Share_Facebook_Strategy::get_instance();
78
- break;
79
- case SNS_Count_Cache::REF_SHARE_GPLUS:
80
- SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
81
- return SCC_Share_Google_Strategy::get_instance();
82
- break;
83
- case SNS_Count_Cache::REF_SHARE_POCKET:
84
- SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
85
- return SCC_Share_Pocket_Strategy::get_instance();
86
- break;
87
- case SNS_Count_Cache::REF_SHARE_HATEBU:
88
- SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
89
- return SCC_Share_Hatebu_Strategy::get_instance();
90
- break;
91
- case SNS_Count_Cache::REF_SHARE_PINTEREST:
92
- SCC_Common_Util::log( '[' . __METHOD__ . '] create crawl strategy: ' . $sns );
93
- return SCC_Share_Pinterest_Strategy::get_instance();
94
- break;
95
- }
96
- }
97
-
98
- /**
99
- * Check configuration
100
- *
101
- * @since 0.9.0
102
- */
103
- private function check_configurations( $target_sns ) {
104
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
105
-
106
- //$checked_target_sns = array();
107
-
108
- unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
109
- unset( $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] );
110
-
111
- SCC_Common_Util::log( $target_sns );
112
-
113
- foreach ( $target_sns as $sns => $active ) {
114
- if ( $active ) {
115
- $target_sns[$sns] = $this->crawl_strategies[$sns]->check_configuration();
116
- }
117
- }
118
-
119
- $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] = true;
120
- $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] = true;
121
-
122
- return $target_sns;
123
-
124
- }
125
-
126
- /**
127
- * Implementation of abstract method. this method gets each share count
128
- *
129
- * @since 0.1.1
130
- */
131
- public function get_data( $target_sns, $options ) {
132
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
133
-
134
- SCC_Common_Util::log( $target_sns );
135
-
136
- $valid_target_sns = $this->check_configurations( $target_sns );
137
- SCC_Common_Util::log( $valid_target_sns );
138
-
139
- $query_urls = $this->build_query_urls( $valid_target_sns );
140
- SCC_Common_Util::log( $query_urls );
141
-
142
- $query_headers = $this->build_query_headers( $valid_target_sns );
143
- SCC_Common_Util::log( $query_headers );
144
-
145
- $data = array();
146
-
147
- $throttle = new SCC_Sleep_Throttle( 0.9 );
148
- $throttle->reset();
149
- $throttle->start();
150
-
151
- if ( $this->crawl_method === SNS_Count_Cache::OPT_COMMON_CRAWLER_METHOD_CURL ) {
152
- $data = SCC_Common_Util::multi_remote_get( $query_urls, $query_headers, $this->timeout, $this->ssl_verification, true );
153
- } else {
154
- $data = SCC_Common_Util::multi_remote_get( $query_urls, $query_headers, $this->timeout, $this->ssl_verification, false );
155
- }
156
-
157
- $throttle->stop();
158
- $retry_count = 0;
159
-
160
- while( true ) {
161
- $target_sns_retry = array();
162
- $tmp_count = $this->extract_count( $valid_target_sns, $data );
163
-
164
- foreach ( $valid_target_sns as $sns => $active ){
165
- if ( $active ) {
166
- if( $tmp_count[$sns] === -1 ) {
167
- $target_sns_retry[$sns] = true;
168
- }
169
- }
170
- }
171
-
172
- if ( empty( $target_sns_retry ) ) {
173
- break;
174
- } else {
175
- SCC_Common_Util::log( '[' . __METHOD__ . '] crawl failure' );
176
- SCC_Common_Util::log( $target_sns_retry );
177
-
178
- if ( $retry_count < $this->retry_limit ) {
179
- SCC_Common_Util::log( '[' . __METHOD__ . '] sleep before crawl retry: ' . $throttle->get_sleep_time() . ' sec.' );
180
-
181
- $throttle->sleep();
182
-
183
- ++$retry_count;
184
- SCC_Common_Util::log( '[' . __METHOD__ . '] count of crawl retry: ' . $retry_count );
185
-
186
- $query_urls_retry = $this->build_query_urls( $target_sns_retry );
187
- $query_headers_retry = $this->build_query_headers( $target_sns_retry );
188
-
189
- $data_retry = array();
190
-
191
- $throttle->reset();
192
- $throttle->start();
193
-
194
- if ( $this->crawl_method === SNS_Count_Cache::OPT_COMMON_CRAWLER_METHOD_CURL ) {
195
- $data_retry = SCC_Common_Util::multi_remote_get( $query_urls_retry, $query_headers_retry, $this->timeout, $this->ssl_verification, true );
196
- } else {
197
- $data_retry = SCC_Common_Util::multi_remote_get( $query_urls_retry, $query_headers_retry, $this->timeout, $this->ssl_verification, false );
198
- }
199
-
200
- $throttle->stop();
201
- $data = array_merge( $data, $data_retry );
202
- } else {
203
- SCC_Common_Util::log( '[' . __METHOD__ . '] crawl retry ended' );
204
- break;
205
- }
206
- }
207
- }
208
-
209
- return $this->extract_count( $target_sns, $data );
210
- }
211
-
212
- /**
213
- * build query
214
- *
215
- * @since 0.5.1
216
- */
217
- private function build_query_urls( $target_sns ) {
218
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
219
-
220
- $query_urls = array();
221
-
222
- unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
223
- unset( $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] );
224
-
225
- SCC_Common_Util::log( $target_sns );
226
-
227
- foreach ( $target_sns as $sns => $active ) {
228
- if ( $active ) {
229
- $query_urls[$sns] = $this->crawl_strategies[$sns]->build_query_url();
230
- }
231
- }
232
-
233
- return $query_urls;
234
- }
235
-
236
- /**
237
- * build query
238
- *
239
- * @since 0.5.1
240
- */
241
- private function build_query_headers( $target_sns ) {
242
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
243
-
244
- $query_headers = array();
245
-
246
- unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
247
- unset( $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] );
248
-
249
- SCC_Common_Util::log( $target_sns );
250
-
251
- foreach ( $target_sns as $sns => $active ) {
252
- if ( $active ) {
253
- $query_headers[$sns] = $this->crawl_strategies[$sns]->build_header();
254
- }
255
- }
256
-
257
- return $query_headers;
258
- }
259
-
260
- /**
261
- * extract count data from retrieved content
262
- *
263
- * @since 0.5.1
264
- */
265
- private function extract_count( $target_sns, $contents ) {
266
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
267
-
268
- $sns_counts = array();
269
-
270
- $extract_date = date_i18n( 'Y/m/d H:i:s' );
271
-
272
- SCC_Common_Util::log( $contents );
273
-
274
- foreach ( $target_sns as $sns => $active ) {
275
- if ( $active ) {
276
- if ( isset( $contents[$sns] ) ) {
277
- $sns_counts[$sns] = $this->crawl_strategies[$sns]->extract_count( $contents[$sns] );
278
- } else {
279
- $sns_counts[$sns] = (int) -1;
280
- }
281
- }
282
- }
283
-
284
- if ( isset( $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] ) && $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] ) {
285
- $total = 0;
286
-
287
- foreach ( $sns_counts as $sns => $count ) {
288
- if ( isset( $count ) && $count >= 0 ) {
289
- $total = $total + $count;
290
- }
291
- }
292
-
293
- $sns_counts[SNS_Count_Cache::REF_SHARE_TOTAL] = (int) $total;
294
- }
295
-
296
- if ( isset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) && $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) {
297
- $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = $extract_date;
298
- } else {
299
- $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = '';
300
- }
301
-
302
- return $sns_counts;
303
- }
304
-
305
- }
306
-
307
- ?>
1
+ <?php
2
+ /*
3
+ class-scc-share-crawler.php
4
+
5
+ Description: This class is a data crawler whitch get share count using given API and cURL
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Crawler extends SCC_Crawler {
31
+
32
+ /**
33
+ * Initialization
34
+ *
35
+ * @since 0.5.1
36
+ */
37
+ public function initialize( $options = array() ) {
38
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
39
+
40
+ //$this->throttle = new Sleep_Throttle( 0.9 );
41
+
42
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
43
+ if ( isset( $options['crawl_method'] ) ) $this->crawl_method = $options['crawl_method'];
44
+ if ( isset( $options['timeout'] ) ) $this->timeout = $options['timeout'];
45
+ if ( isset( $options['ssl_verification'] ) ) $this->ssl_verification = $options['ssl_verification'];
46
+ if ( isset( $options['crawl_retry'] ) ) $this->crawl_retry = $options['crawl_retry'];
47
+ if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
48
+
49
+ $target_sns = $this->target_sns;
50
+
51
+ unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
52
+ unset( $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] );
53
+
54
+ foreach ( $target_sns as $sns => $active ) {
55
+ if ( $active ) {
56
+ $this->crawl_strategies[$sns] = SCC_Share_Crawl_Strategy_Factory::create_crawl_strategy( $sns );
57
+ }
58
+ }
59
+
60
+ }
61
+
62
+ /**
63
+ * Check configuration
64
+ *
65
+ * @since 0.9.0
66
+ */
67
+ private function check_configurations( $target_sns ) {
68
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
69
+
70
+ //$checked_target_sns = array();
71
+
72
+ unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
73
+ unset( $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] );
74
+
75
+ SCC_Common_Util::log( $target_sns );
76
+
77
+ foreach ( $target_sns as $sns => $active ) {
78
+ if ( $active ) {
79
+ $target_sns[$sns] = $this->crawl_strategies[$sns]->check_configuration();
80
+ }
81
+ }
82
+
83
+ $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] = true;
84
+ $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] = true;
85
+
86
+ return $target_sns;
87
+
88
+ }
89
+
90
+ /**
91
+ * Implementation of abstract method. this method gets each share count
92
+ *
93
+ * @since 0.1.1
94
+ */
95
+ public function get_data( $target_sns, $options ) {
96
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
97
+
98
+ SCC_Common_Util::log( $target_sns );
99
+
100
+ $valid_target_sns = $this->check_configurations( $target_sns );
101
+ SCC_Common_Util::log( $valid_target_sns );
102
+
103
+ $query_urls = $this->build_query_urls( $valid_target_sns );
104
+ SCC_Common_Util::log( $query_urls );
105
+
106
+ $query_headers = $this->build_query_headers( $valid_target_sns );
107
+ SCC_Common_Util::log( $query_headers );
108
+
109
+ $data = array();
110
+
111
+ $throttle = new SCC_Sleep_Throttle( 0.9 );
112
+ $throttle->reset();
113
+ $throttle->start();
114
+
115
+ if ( $this->crawl_method === SNS_Count_Cache::OPT_COMMON_CRAWLER_METHOD_CURL ) {
116
+ $data = SCC_Common_Util::multi_remote_get( $query_urls, $query_headers, $this->timeout, $this->ssl_verification, true );
117
+ } else {
118
+ $data = SCC_Common_Util::multi_remote_get( $query_urls, $query_headers, $this->timeout, $this->ssl_verification, false );
119
+ }
120
+
121
+ $throttle->stop();
122
+ $retry_count = 0;
123
+
124
+ while( true ) {
125
+ $target_sns_retry = array();
126
+ $tmp_count = $this->extract_count( $valid_target_sns, $data );
127
+
128
+ foreach ( $valid_target_sns as $sns => $active ){
129
+ if ( $active ) {
130
+ if( $tmp_count[$sns] === -1 ) {
131
+ $target_sns_retry[$sns] = true;
132
+ }
133
+ }
134
+ }
135
+
136
+ if ( empty( $target_sns_retry ) ) {
137
+ break;
138
+ } else {
139
+ SCC_Common_Util::log( '[' . __METHOD__ . '] crawl failure' );
140
+ SCC_Common_Util::log( $target_sns_retry );
141
+
142
+ if ( $retry_count < $this->retry_limit ) {
143
+ SCC_Common_Util::log( '[' . __METHOD__ . '] sleep before crawl retry: ' . $throttle->get_sleep_time() . ' sec.' );
144
+
145
+ $throttle->sleep();
146
+
147
+ ++$retry_count;
148
+ SCC_Common_Util::log( '[' . __METHOD__ . '] count of crawl retry: ' . $retry_count );
149
+
150
+ $query_urls_retry = $this->build_query_urls( $target_sns_retry );
151
+ $query_headers_retry = $this->build_query_headers( $target_sns_retry );
152
+
153
+ $data_retry = array();
154
+
155
+ $throttle->reset();
156
+ $throttle->start();
157
+
158
+ if ( $this->crawl_method === SNS_Count_Cache::OPT_COMMON_CRAWLER_METHOD_CURL ) {
159
+ $data_retry = SCC_Common_Util::multi_remote_get( $query_urls_retry, $query_headers_retry, $this->timeout, $this->ssl_verification, true );
160
+ } else {
161
+ $data_retry = SCC_Common_Util::multi_remote_get( $query_urls_retry, $query_headers_retry, $this->timeout, $this->ssl_verification, false );
162
+ }
163
+
164
+ $throttle->stop();
165
+ $data = array_merge( $data, $data_retry );
166
+ } else {
167
+ SCC_Common_Util::log( '[' . __METHOD__ . '] crawl retry ended' );
168
+ break;
169
+ }
170
+ }
171
+ }
172
+
173
+ return $this->extract_count( $target_sns, $data );
174
+ }
175
+
176
+ /**
177
+ * build query
178
+ *
179
+ * @since 0.5.1
180
+ */
181
+ private function build_query_urls( $target_sns ) {
182
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
183
+
184
+ $query_urls = array();
185
+
186
+ unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
187
+ unset( $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] );
188
+
189
+ SCC_Common_Util::log( $target_sns );
190
+
191
+ foreach ( $target_sns as $sns => $active ) {
192
+ if ( $active ) {
193
+ $query_urls[$sns] = $this->crawl_strategies[$sns]->build_query_url();
194
+ }
195
+ }
196
+
197
+ return $query_urls;
198
+ }
199
+
200
+ /**
201
+ * build query
202
+ *
203
+ * @since 0.5.1
204
+ */
205
+ private function build_query_headers( $target_sns ) {
206
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
207
+
208
+ $query_headers = array();
209
+
210
+ unset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] );
211
+ unset( $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] );
212
+
213
+ SCC_Common_Util::log( $target_sns );
214
+
215
+ foreach ( $target_sns as $sns => $active ) {
216
+ if ( $active ) {
217
+ $query_headers[$sns] = $this->crawl_strategies[$sns]->build_header();
218
+ }
219
+ }
220
+
221
+ return $query_headers;
222
+ }
223
+
224
+ /**
225
+ * extract count data from retrieved content
226
+ *
227
+ * @since 0.5.1
228
+ */
229
+ private function extract_count( $target_sns, $contents ) {
230
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
231
+
232
+ $sns_counts = array();
233
+
234
+ $extract_date = date_i18n( 'Y/m/d H:i:s' );
235
+
236
+ SCC_Common_Util::log( $contents );
237
+
238
+ foreach ( $target_sns as $sns => $active ) {
239
+ if ( $active ) {
240
+ if ( isset( $contents[$sns] ) ) {
241
+ $sns_counts[$sns] = $this->crawl_strategies[$sns]->extract_count( $contents[$sns] );
242
+ } else {
243
+ $sns_counts[$sns] = (int) -1;
244
+ }
245
+ }
246
+ }
247
+
248
+ if ( isset( $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] ) && $target_sns[SNS_Count_Cache::REF_SHARE_TOTAL] ) {
249
+ $total = 0;
250
+
251
+ foreach ( $sns_counts as $sns => $count ) {
252
+ if ( isset( $count ) && $count >= 0 ) {
253
+ $total = $total + $count;
254
+ }
255
+ }
256
+
257
+ $sns_counts[SNS_Count_Cache::REF_SHARE_TOTAL] = (int) $total;
258
+ }
259
+
260
+ if ( isset( $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) && $target_sns[SNS_Count_Cache::REF_CRAWL_DATE] ) {
261
+ $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = $extract_date;
262
+ } else {
263
+ $sns_counts[SNS_Count_Cache::REF_CRAWL_DATE] = '';
264
+ }
265
+
266
+ return $sns_counts;
267
+ }
268
+
269
+ }
270
+
271
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/class-scc-share-facebook-strategy.php CHANGED
@@ -1,135 +1,134 @@
1
- <?php
2
- /*
3
- class-scc-share-facebook-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Facebook_Strategy extends SCC_Crawl_Strategy {
31
-
32
- /**
33
- * SNS base url
34
- */
35
- const DEF_BASE_URL = 'https://graph.facebook.com/';
36
-
37
- /**
38
- * Class constarctor
39
- * Hook onto all of the actions and filters needed by the plugin.
40
- *
41
- */
42
- protected function __construct() {
43
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
-
45
- $this->method = 'GET';
46
- }
47
-
48
- /**
49
- * Initialization
50
- *
51
- * @since 0.9.0
52
- */
53
- public function initialize( $options = array() ) {
54
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
-
56
- if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
- if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
- if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
- }
60
-
61
- /**
62
- * Build header
63
- *
64
- * @since 0.9.0
65
- */
66
- public function build_header() {
67
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
- return null;
69
- }
70
-
71
- /**
72
- * Build query url
73
- *
74
- * @since 0.9.0
75
- */
76
- public function build_query_url() {
77
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
-
79
- $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
80
-
81
- return $url;
82
- }
83
-
84
- /**
85
- * Extract count
86
- *
87
- * @since 0.9.0
88
- */
89
- public function extract_count( $content ) {
90
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
-
92
- $count = (int) -1;
93
-
94
- if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
- $json = json_decode( $content['data'], true );
96
-
97
- if ( isset( $json['share']['share_count'] ) && is_numeric( $json['share']['share_count'] ) ) {
98
- $count = (int) $json['share']['share_count'];
99
- } else {
100
- $count = (int) -1;
101
- }
102
- } else {
103
- $count = (int) -1;
104
- }
105
-
106
- return $count;
107
- }
108
-
109
-
110
- public function set_query_parameter( $key, $value ) {
111
- if ( $key === 'url' ) {
112
- $this->query_parameters['id'] = $value;
113
- } else {
114
- $this->query_parameters[$key] = $value;
115
- }
116
- }
117
-
118
- /**
119
- * Check if required paramters are included or not.
120
- *
121
- * @since 0.9.0
122
- */
123
- public function check_configuration() {
124
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
125
-
126
- if ( isset( $this->parameters['app_id'] ) && $this->parameters['app_id'] &&
127
- isset( $this->parameters['app_secret'] ) && $this->parameters['app_secret'] &&
128
- isset( $this->query_parameters['access_token'] ) && $this->query_parameters['access_token'] ) {
129
- return true;
130
- } else {
131
- return false;
132
- }
133
- }
134
-
135
- }
1
+ <?php
2
+ /*
3
+ class-scc-share-facebook-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Facebook_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url
34
+ */
35
+ const DEF_BASE_URL = 'https://graph.facebook.com/';
36
+
37
+ /**
38
+ * Class constarctor
39
+ * Hook onto all of the actions and filters needed by the plugin.
40
+ *
41
+ */
42
+ protected function __construct() {
43
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
+
45
+ $this->method = 'GET';
46
+ }
47
+
48
+ /**
49
+ * Initialization
50
+ *
51
+ * @since 0.9.0
52
+ */
53
+ public function initialize( $options = array() ) {
54
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
+
56
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
+ }
60
+
61
+ /**
62
+ * Build header
63
+ *
64
+ * @since 0.9.0
65
+ */
66
+ public function build_header() {
67
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
+ return null;
69
+ }
70
+
71
+ /**
72
+ * Build query url
73
+ *
74
+ * @since 0.9.0
75
+ */
76
+ public function build_query_url() {
77
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
+
79
+ $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
80
+
81
+ return $url;
82
+ }
83
+
84
+ /**
85
+ * Extract count
86
+ *
87
+ * @since 0.9.0
88
+ */
89
+ public function extract_count( $content ) {
90
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
+
92
+ $count = (int) -1;
93
+
94
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
+ $json = json_decode( $content['data'], true );
96
+
97
+ if ( isset( $json['share']['share_count'] ) && is_numeric( $json['share']['share_count'] ) ) {
98
+ $count = (int) $json['share']['share_count'];
99
+ } else {
100
+ $count = (int) -1;
101
+ }
102
+ } else {
103
+ $count = (int) -1;
104
+ }
105
+
106
+ return $count;
107
+ }
108
+
109
+ public function set_query_parameter( $key, $value ) {
110
+ if ( $key === 'url' ) {
111
+ $this->query_parameters['id'] = $value;
112
+ } elseif ( $key === 'access_token' ) {
113
+ $this->query_parameters[$key] = $value;
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Check if required paramters are included or not.
119
+ *
120
+ * @since 0.9.0
121
+ */
122
+ public function check_configuration() {
123
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
124
+
125
+ if ( isset( $this->parameters['app_id'] ) && $this->parameters['app_id'] &&
126
+ isset( $this->parameters['app_secret'] ) && $this->parameters['app_secret'] &&
127
+ isset( $this->query_parameters['access_token'] ) && $this->query_parameters['access_token'] ) {
128
+ return true;
129
+ } else {
130
+ return false;
131
+ }
132
+ }
133
+
134
+ }
 
includes/class-scc-share-google-strategy.php CHANGED
@@ -1,124 +1,130 @@
1
- <?php
2
- /*
3
- class-scc-share-google-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Google_Strategy extends SCC_Crawl_Strategy {
31
-
32
- /**
33
- * SNS base url
34
- */
35
- const DEF_BASE_URL = 'https://apis.google.com/_/+1/fastbutton';
36
-
37
- /**
38
- * Class constarctor
39
- * Hook onto all of the actions and filters needed by the plugin.
40
- *
41
- */
42
- protected function __construct() {
43
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
44
-
45
- $this->method = 'GET';
46
- }
47
-
48
- /**
49
- * Initialization
50
- *
51
- * @since 0.9.0
52
- */
53
- public function initialize( $options = array() ) {
54
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
-
56
- if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
- if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
- if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
- }
60
-
61
- /**
62
- * Build header
63
- *
64
- * @since 0.9.0
65
- */
66
- public function build_header() {
67
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
- return null;
69
- }
70
-
71
- /**
72
- * Build query url
73
- *
74
- * @since 0.9.0
75
- */
76
- public function build_query_url() {
77
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
-
79
- $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters, '' , '&' );
80
-
81
- return $url;
82
- }
83
-
84
- /**
85
- * Extract count
86
- *
87
- * @since 0.9.0
88
- */
89
- public function extract_count( $content ) {
90
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
-
92
- $count = (int) -1;
93
-
94
- if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
- $return_code = preg_match( '/\[2,([0-9.]+),\[/', $content['data'], $matches );
96
-
97
- if ( $return_code && isset( $matches[1] ) && is_numeric( $matches[1] ) ) {
98
- $count = (int) $matches[1];
99
- } else {
100
- $count = (int) -1;
101
- }
102
- } else {
103
- $count = (int) -1;
104
- }
105
-
106
- return $count;
107
- }
108
-
109
- /**
110
- * Check if required paramters are included or not.
111
- *
112
- * @since 0.9.0
113
- */
114
- public function check_configuration() {
115
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
116
-
117
- if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
118
- return true;
119
- } else {
120
- return false;
121
- }
122
- }
123
-
124
- }
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-google-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Google_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url
34
+ */
35
+ const DEF_BASE_URL = 'https://apis.google.com/_/+1/fastbutton';
36
+
37
+ /**
38
+ * Class constarctor
39
+ * Hook onto all of the actions and filters needed by the plugin.
40
+ *
41
+ */
42
+ protected function __construct() {
43
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
44
+
45
+ $this->method = 'GET';
46
+ }
47
+
48
+ /**
49
+ * Initialization
50
+ *
51
+ * @since 0.9.0
52
+ */
53
+ public function initialize( $options = array() ) {
54
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
+
56
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
+ }
60
+
61
+ /**
62
+ * Build header
63
+ *
64
+ * @since 0.9.0
65
+ */
66
+ public function build_header() {
67
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
+ return null;
69
+ }
70
+
71
+ /**
72
+ * Build query url
73
+ *
74
+ * @since 0.9.0
75
+ */
76
+ public function build_query_url() {
77
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
+
79
+ $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters, '' , '&' );
80
+
81
+ return $url;
82
+ }
83
+
84
+ /**
85
+ * Extract count
86
+ *
87
+ * @since 0.9.0
88
+ */
89
+ public function extract_count( $content ) {
90
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
+
92
+ $count = (int) -1;
93
+
94
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
+ $return_code = preg_match( '/\[2,([0-9.]+),\[/', $content['data'], $matches );
96
+
97
+ if ( $return_code && isset( $matches[1] ) && is_numeric( $matches[1] ) ) {
98
+ $count = (int) $matches[1];
99
+ } else {
100
+ $count = (int) -1;
101
+ }
102
+ } else {
103
+ $count = (int) -1;
104
+ }
105
+
106
+ return $count;
107
+ }
108
+
109
+ public function set_query_parameter( $key, $value ) {
110
+ if ( $key === 'url' ) {
111
+ $this->query_parameters[$key] = $value;
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Check if required paramters are included or not.
117
+ *
118
+ * @since 0.9.0
119
+ */
120
+ public function check_configuration() {
121
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
122
+
123
+ if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
124
+ return true;
125
+ } else {
126
+ return false;
127
+ }
128
+ }
129
+
130
+ }
includes/class-scc-share-hatebu-strategy.php CHANGED
@@ -1,120 +1,126 @@
1
- <?php
2
- /*
3
- class-scc-share-hatebu-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Hatebu_Strategy extends SCC_Crawl_Strategy {
31
-
32
- /**
33
- * SNS base url
34
- */
35
- const DEF_BASE_URL = 'http://api.b.st-hatena.com/entry.count';
36
-
37
- /**
38
- * Class constarctor
39
- * Hook onto all of the actions and filters needed by the plugin.
40
- *
41
- */
42
- protected function __construct() {
43
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
-
45
- $this->method = 'GET';
46
- }
47
-
48
- /**
49
- * Initialization
50
- *
51
- * @since 0.9.0
52
- */
53
- public function initialize( $options = array() ) {
54
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
-
56
- if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
- if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
- if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
- }
60
-
61
- /**
62
- * Build header
63
- *
64
- * @since 0.9.0
65
- */
66
- public function build_header() {
67
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
- return null;
69
- }
70
-
71
- /**
72
- * Build query url
73
- *
74
- * @since 0.9.0
75
- */
76
- public function build_query_url() {
77
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
-
79
- $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
80
-
81
- return $url;
82
- }
83
-
84
- /**
85
- * Extract count
86
- *
87
- * @since 0.9.0
88
- */
89
- public function extract_count( $content ) {
90
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
-
92
- $count = (int) -1;
93
-
94
- if ( isset( $content['data'] ) && empty( $content['error'] ) && is_numeric( $content['data'] ) ) {
95
- $count = (int) $content['data'];
96
- } elseif ( empty( $content['data'] ) && empty( $content['error'] ) ) {
97
- $count = (int) 0;
98
- } else {
99
- $count = (int) -1;
100
- }
101
-
102
- return $count;
103
- }
104
-
105
- /**
106
- * Check if required paramters are included or not.
107
- *
108
- * @since 0.9.0
109
- */
110
- public function check_configuration() {
111
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
112
-
113
- if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
114
- return true;
115
- } else {
116
- return false;
117
- }
118
- }
119
-
120
- }
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-hatebu-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Hatebu_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url
34
+ */
35
+ const DEF_BASE_URL = 'http://api.b.st-hatena.com/entry.count';
36
+
37
+ /**
38
+ * Class constarctor
39
+ * Hook onto all of the actions and filters needed by the plugin.
40
+ *
41
+ */
42
+ protected function __construct() {
43
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
+
45
+ $this->method = 'GET';
46
+ }
47
+
48
+ /**
49
+ * Initialization
50
+ *
51
+ * @since 0.9.0
52
+ */
53
+ public function initialize( $options = array() ) {
54
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
+
56
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
+ }
60
+
61
+ /**
62
+ * Build header
63
+ *
64
+ * @since 0.9.0
65
+ */
66
+ public function build_header() {
67
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
+ return null;
69
+ }
70
+
71
+ /**
72
+ * Build query url
73
+ *
74
+ * @since 0.9.0
75
+ */
76
+ public function build_query_url() {
77
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
+
79
+ $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
80
+
81
+ return $url;
82
+ }
83
+
84
+ /**
85
+ * Extract count
86
+ *
87
+ * @since 0.9.0
88
+ */
89
+ public function extract_count( $content ) {
90
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
+
92
+ $count = (int) -1;
93
+
94
+ if ( isset( $content['data'] ) && empty( $content['error'] ) && is_numeric( $content['data'] ) ) {
95
+ $count = (int) $content['data'];
96
+ } elseif ( empty( $content['data'] ) && empty( $content['error'] ) ) {
97
+ $count = (int) 0;
98
+ } else {
99
+ $count = (int) -1;
100
+ }
101
+
102
+ return $count;
103
+ }
104
+
105
+ public function set_query_parameter( $key, $value ) {
106
+ if ( $key === 'url' ) {
107
+ $this->query_parameters[$key] = $value;
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Check if required paramters are included or not.
113
+ *
114
+ * @since 0.9.0
115
+ */
116
+ public function check_configuration() {
117
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
118
+
119
+ if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
120
+ return true;
121
+ } else {
122
+ return false;
123
+ }
124
+ }
125
+
126
+ }
includes/class-scc-share-lazy-cache-engine.php CHANGED
@@ -1,257 +1,264 @@
1
- <?php
2
- /*
3
- class-scc-share-lazy-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Lazy_Cache_Engine extends SCC_Share_Cache_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
-
37
- /**
38
- * Cron name to schedule cache processing
39
- */
40
- const DEF_PRIME_CRON = 'scc_share_lazycache_prime';
41
-
42
- /**
43
- * Cron name to execute cache processing
44
- */
45
- const DEF_EXECUTE_CRON = 'scc_share_lazycache_exec';
46
-
47
- /**
48
- * Schedule name for cache processing
49
- */
50
- const DEF_EVENT_SCHEDULE = 'share_lazy_cache_event';
51
-
52
- /**
53
- * Schedule description for cache processing
54
- */
55
- const DEF_EVENT_DESCRIPTION = '[SCC] Share Lazy Cache Interval';
56
-
57
- /**
58
- * Interval cheking and caching target data
59
- */
60
- private $check_interval = 600;
61
-
62
- /**
63
- * Number of posts to check at a time
64
- */
65
- private $posts_per_check = 20;
66
-
67
- /**
68
- * Latency suffix
69
- */
70
- private $check_latency = 10;
71
-
72
- /**
73
- * Initialization
74
- *
75
- * @since 0.1.1
76
- */
77
- public function initialize( $options = array() ) {
78
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
79
-
80
- $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
81
- $this->prime_cron = self::DEF_PRIME_CRON;
82
- $this->execute_cron = self::DEF_EXECUTE_CRON;
83
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
84
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
85
-
86
- $this->load_ratio = 0.5;
87
-
88
- if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
89
- if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
90
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
91
- if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
92
- if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
93
- if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
94
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
95
- if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
96
- if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
97
- if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
98
- if ( isset( $options['scheme_migration_date'] ) ) $this->scheme_migration_date = $options['scheme_migration_date'];
99
- if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
100
- if ( isset( $options['cache_retry'] ) ) $this->cache_retry = $options['cache_retry'];
101
- if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
102
- if ( isset( $options['fault_tolerance'] ) ) $this->fault_tolerance = $options['fault_tolerance'];
103
-
104
- add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
105
- }
106
-
107
- /**
108
- * Register base schedule for this engine
109
- *
110
- * @since 0.1.0
111
- */
112
- public function register_schedule() {
113
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
114
- }
115
-
116
- /**
117
- * Unregister base schedule for this engine
118
- *
119
- * @since 0.1.0
120
- */
121
- public function unregister_schedule() {
122
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
123
-
124
- SCC_WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
125
- }
126
-
127
- /**
128
- * Schedule data retrieval and cache processing
129
- *
130
- * @since 0.2.0
131
- */
132
- public function prime_cache( $post_ID ) {
133
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
134
-
135
- $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_latency;
136
-
137
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_latency: ' . $this->check_latency );
138
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
139
-
140
- wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( $post_ID ) );
141
- }
142
-
143
- /**
144
- * Get and cache data of each published post
145
- *
146
- * @since 0.2.0
147
- */
148
- public function execute_cache( $post_ID ) {
149
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
150
-
151
- $cache_expiration = $this->get_cache_expiration();
152
-
153
- SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
154
-
155
- $transient_id = $this->get_cache_key( $post_ID );
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(
166
- 'cache_key' => $transient_id,
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
-
174
- // Primary cache
175
- $this->cache( $options );
176
-
177
- // Secondary cache
178
- $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
179
- }
180
-
181
- /**
182
- * Get cache expiration based on current number of total post and page
183
- *
184
- * @since 0.1.1
185
- */
186
- protected function get_cache_expiration() {
187
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
188
-
189
- $posts_total = $this->get_posts_total();
190
-
191
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
192
-
193
- return ceil( $posts_total / $this->posts_per_check ) * $this->check_interval * 3;
194
- }
195
-
196
- /**
197
- * Get total count of current published post and page
198
- *
199
- * @since 0.1.0
200
- */
201
- private function get_posts_total() {
202
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
203
-
204
- $query_args = array(
205
- 'post_type' => $this->post_types,
206
- 'post_status' => 'publish',
207
- 'nopaging' => true,
208
- 'update_post_term_cache' => false,
209
- 'update_post_meta_cache' => false
210
- );
211
-
212
- $posts_query = new WP_Query( $query_args );
213
-
214
- return $posts_query->found_posts;
215
- }
216
-
217
- /**
218
- * Initialize meta key for ranking
219
- *
220
- * @since 0.3.0
221
- */
222
- public function initialize_cache() {
223
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
224
- }
225
-
226
- /**
227
- * Clear meta key for ranking
228
- *
229
- * @since 0.3.0
230
- */
231
- public function clear_cache() {
232
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
233
- }
234
-
235
- /**
236
- * Get current cache
237
- *
238
- * @since 0.9.3
239
- */
240
- protected function get_current_cache( $options = array() ) {
241
- $post_id = $options['post_id'];
242
-
243
- $transient_id = $this->get_cache_key( $post_id );
244
-
245
- $sns_counts = array();
246
-
247
- if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
248
- return $sns_counts;
249
- } else {
250
- return $this->delegate_order( SCC_Order::ORDER_GET_SECOND_CACHE, $options );
251
- }
252
- }
253
-
254
-
255
- }
256
-
257
- ?>
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-lazy-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Lazy_Cache_Engine extends SCC_Share_Cache_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
+
37
+ /**
38
+ * Cron name to schedule cache processing
39
+ */
40
+ const DEF_PRIME_CRON = 'scc_share_lazycache_prime';
41
+
42
+ /**
43
+ * Cron name to execute cache processing
44
+ */
45
+ const DEF_EXECUTE_CRON = 'scc_share_lazycache_exec';
46
+
47
+ /**
48
+ * Schedule name for cache processing
49
+ */
50
+ const DEF_EVENT_SCHEDULE = 'share_lazy_cache_event';
51
+
52
+ /**
53
+ * Schedule description for cache processing
54
+ */
55
+ const DEF_EVENT_DESCRIPTION = '[SCC] Share Lazy Cache Interval';
56
+
57
+ /**
58
+ * Cache post types
59
+ */
60
+ private $post_types = array( 'post', 'page' );
61
+
62
+ /**
63
+ * Interval cheking and caching target data
64
+ */
65
+ private $check_interval = 600;
66
+
67
+ /**
68
+ * Number of posts to check at a time
69
+ */
70
+ private $posts_per_check = 20;
71
+
72
+ /**
73
+ * Latency suffix
74
+ */
75
+ private $check_latency = 10;
76
+
77
+ /**
78
+ * Initialization
79
+ *
80
+ * @since 0.1.1
81
+ */
82
+ public function initialize( $options = array() ) {
83
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
84
+
85
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
86
+ $this->prime_cron = self::DEF_PRIME_CRON;
87
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
88
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
89
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
90
+
91
+ $this->load_ratio = 0.5;
92
+
93
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
94
+ if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
95
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
96
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
97
+ if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
98
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
99
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
100
+ if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
101
+ if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
102
+ if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
103
+ if ( isset( $options['scheme_migration_date'] ) ) $this->scheme_migration_date = $options['scheme_migration_date'];
104
+ if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
105
+ if ( isset( $options['cache_retry'] ) ) $this->cache_retry = $options['cache_retry'];
106
+ if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
107
+ if ( isset( $options['fault_tolerance'] ) ) $this->fault_tolerance = $options['fault_tolerance'];
108
+
109
+ add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
110
+ }
111
+
112
+ /**
113
+ * Register base schedule for this engine
114
+ *
115
+ * @since 0.1.0
116
+ */
117
+ public function register_schedule() {
118
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
119
+ }
120
+
121
+ /**
122
+ * Unregister base schedule for this engine
123
+ *
124
+ * @since 0.1.0
125
+ */
126
+ public function unregister_schedule() {
127
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
128
+
129
+ SCC_WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
130
+ }
131
+
132
+ /**
133
+ * Schedule data retrieval and cache processing
134
+ *
135
+ * @since 0.2.0
136
+ */
137
+ public function prime_cache( $post_ID ) {
138
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
139
+
140
+ $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_latency;
141
+
142
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_latency: ' . $this->check_latency );
143
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
144
+
145
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( $post_ID ) );
146
+ }
147
+
148
+ /**
149
+ * Get and cache data of each published post
150
+ *
151
+ * @since 0.2.0
152
+ */
153
+ public function execute_cache( $post_ID ) {
154
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
155
+
156
+ $cache_expiration = $this->get_cache_expiration();
157
+
158
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
159
+
160
+ $transient_id = $this->get_cache_key( $post_ID );
161
+
162
+ if ( $post_ID != 'home' ) {
163
+ $url = get_permalink( $post_ID );
164
+ $title = get_the_title( $post_ID );
165
+ $publish_date = get_the_date( 'Y/m/d', $post_ID );
166
+ } else {
167
+ $url = home_url( '/' );
168
+ $title = get_bloginfo( 'name' );
169
+ $publish_date = NULL;
170
+ }
171
+
172
+ $options = array(
173
+ 'cache_key' => $transient_id,
174
+ 'post_id' => $post_ID,
175
+ 'target_url' => $url,
176
+ 'target_sns' => $this->target_sns,
177
+ 'target_title' => $title,
178
+ 'publish_date' => $publish_date,
179
+ 'cache_expiration' => $cache_expiration
180
+ );
181
+
182
+ // Primary cache
183
+ $this->cache( $options );
184
+
185
+ // Secondary cache
186
+ $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
187
+ }
188
+
189
+ /**
190
+ * Get cache expiration based on current number of total post and page
191
+ *
192
+ * @since 0.1.1
193
+ */
194
+ protected function get_cache_expiration() {
195
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
196
+
197
+ $posts_total = $this->get_posts_total();
198
+
199
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
200
+
201
+ return ceil( $posts_total / $this->posts_per_check ) * $this->check_interval * 3;
202
+ }
203
+
204
+ /**
205
+ * Get total count of current published post and page
206
+ *
207
+ * @since 0.1.0
208
+ */
209
+ private function get_posts_total() {
210
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
211
+
212
+ $query_args = array(
213
+ 'post_type' => $this->post_types,
214
+ 'post_status' => 'publish',
215
+ 'nopaging' => true,
216
+ 'update_post_term_cache' => false,
217
+ 'update_post_meta_cache' => false
218
+ );
219
+
220
+ $posts_query = new WP_Query( $query_args );
221
+
222
+ return $posts_query->found_posts;
223
+ }
224
+
225
+ /**
226
+ * Initialize meta key for ranking
227
+ *
228
+ * @since 0.3.0
229
+ */
230
+ public function initialize_cache() {
231
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
232
+ }
233
+
234
+ /**
235
+ * Clear meta key for ranking
236
+ *
237
+ * @since 0.3.0
238
+ */
239
+ public function clear_cache() {
240
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
241
+ }
242
+
243
+ /**
244
+ * Get current cache
245
+ *
246
+ * @since 0.9.3
247
+ */
248
+ public function get_cache( $options = array() ) {
249
+ $post_id = $options['post_id'];
250
+
251
+ $transient_id = $this->get_cache_key( $post_id );
252
+
253
+ $sns_counts = array();
254
+
255
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
256
+ return $sns_counts;
257
+ } else {
258
+ return $this->delegate_order( SCC_Order::ORDER_GET_SECOND_CACHE, $options );
259
+ }
260
+ }
261
+
262
+ }
263
+
264
+ ?>
includes/class-scc-share-linkedin-strategy.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-linkedin-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Linkedin_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url
34
+ * @var string
35
+ */
36
+ const DEF_BASE_URL = 'https://www.linkedin.com/countserv/count/share';
37
+
38
+ /**
39
+ * Class constarctor
40
+ * Hook onto all of the actions and filters needed by the plugin.
41
+ *
42
+ */
43
+ protected function __construct() {
44
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
45
+
46
+ $this->method = 'GET';
47
+ $this->query_parameters['format'] = 'json';
48
+ }
49
+
50
+ /**
51
+ * Initialization
52
+ * @since 0.11.0
53
+ * @param array $options Option for this strategy
54
+ * @return null There is no return.
55
+ */
56
+ public function initialize( $options = array() ) {
57
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
58
+
59
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
60
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
61
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
62
+ }
63
+
64
+ /**
65
+ * Build header
66
+ * @since 0.11.0
67
+ * @return null no need to build header for Twitter share count retrieval.
68
+ */
69
+ public function build_header() {
70
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
71
+ return null;
72
+ }
73
+
74
+ /**
75
+ * Build query URL
76
+ * @since 0.11.0
77
+ * @return string Query URL
78
+ */
79
+ public function build_query_url() {
80
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
81
+
82
+ $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
83
+
84
+ return $url;
85
+ }
86
+
87
+ /**
88
+ * Extract count
89
+ * @since 0.11.0
90
+ * @param string $content Target content
91
+ * @return int SNS count
92
+ */
93
+ public function extract_count( $content ) {
94
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
95
+
96
+ $count = (int) -1;
97
+
98
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
99
+
100
+ $json = json_decode( $content['data'], true );
101
+
102
+ if ( isset( $json['count'] ) && is_numeric( $json['count'] ) ) {
103
+ $count = (int) $json['count'];
104
+ } else {
105
+ $count = (int) -1;
106
+ }
107
+ } else {
108
+ $count = (int) -1;
109
+ }
110
+
111
+ return $count;
112
+ }
113
+
114
+ /**
115
+ * Setter of query parameters
116
+ * @param string $key key
117
+ * @param string $value value
118
+ */
119
+ public function set_query_parameter( $key, $value ) {
120
+ if ( $key === 'url' ) {
121
+ $this->query_parameters[$key] = $value;
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Check if required paramters are included or not.
127
+ * @since 0.11.0
128
+ * @return boolean Check result
129
+ */
130
+ public function check_configuration() {
131
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
132
+
133
+ if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
134
+ return true;
135
+ } else {
136
+ return false;
137
+ }
138
+ }
139
+
140
+ }
includes/class-scc-share-pinterest-strategy.php CHANGED
@@ -1,128 +1,134 @@
1
- <?php
2
- /*
3
- class-scc-share-pinterest-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Pinterest_Strategy extends SCC_Crawl_Strategy {
31
-
32
- /**
33
- * SNS base url
34
- */
35
- const DEF_BASE_URL = 'https://api.pinterest.com/v1/urls/count.json';
36
-
37
- /**
38
- * Class constarctor
39
- * Hook onto all of the actions and filters needed by the plugin.
40
- *
41
- */
42
- protected function __construct() {
43
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
-
45
- $this->method = 'GET';
46
- }
47
-
48
- /**
49
- * Initialization
50
- *
51
- * @since 0.9.0
52
- */
53
- public function initialize( $options = array() ) {
54
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
-
56
- if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
- if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
- if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
- }
60
-
61
- /**
62
- * Build header
63
- *
64
- * @since 0.9.0
65
- */
66
- public function build_header() {
67
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
- return null;
69
- }
70
-
71
- /**
72
- * Build query url
73
- *
74
- * @since 0.9.0
75
- */
76
- public function build_query_url() {
77
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
-
79
- $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
80
-
81
- return $url;
82
- }
83
-
84
- /**
85
- * Extract count
86
- *
87
- * @since 0.9.0
88
- */
89
- public function extract_count( $content ) {
90
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
-
92
- $count = (int) -1;
93
-
94
- if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
-
96
- $data = rtrim( $content['data'], ');' );
97
- $data = ltrim( $data, 'receiveCount(' );
98
-
99
- $json = json_decode( $data, true );
100
-
101
- if ( isset( $json['count'] ) && is_numeric( $json['count'] ) ) {
102
- $count = (int) $json['count'];
103
- } else {
104
- $count = (int) -1;
105
- }
106
- } else {
107
- $count = (int) -1;
108
- }
109
-
110
- return $count;
111
- }
112
-
113
- /**
114
- * Check if required paramters are included or not.
115
- *
116
- * @since 0.9.0
117
- */
118
- public function check_configuration() {
119
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
120
-
121
- if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
122
- return true;
123
- } else {
124
- return false;
125
- }
126
- }
127
-
128
- }
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-pinterest-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Pinterest_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url
34
+ */
35
+ const DEF_BASE_URL = 'https://api.pinterest.com/v1/urls/count.json';
36
+
37
+ /**
38
+ * Class constarctor
39
+ * Hook onto all of the actions and filters needed by the plugin.
40
+ *
41
+ */
42
+ protected function __construct() {
43
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
+
45
+ $this->method = 'GET';
46
+ }
47
+
48
+ /**
49
+ * Initialization
50
+ *
51
+ * @since 0.9.0
52
+ */
53
+ public function initialize( $options = array() ) {
54
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
55
+
56
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
57
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
58
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
59
+ }
60
+
61
+ /**
62
+ * Build header
63
+ *
64
+ * @since 0.9.0
65
+ */
66
+ public function build_header() {
67
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
68
+ return null;
69
+ }
70
+
71
+ /**
72
+ * Build query url
73
+ *
74
+ * @since 0.9.0
75
+ */
76
+ public function build_query_url() {
77
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
78
+
79
+ $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
80
+
81
+ return $url;
82
+ }
83
+
84
+ /**
85
+ * Extract count
86
+ *
87
+ * @since 0.9.0
88
+ */
89
+ public function extract_count( $content ) {
90
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
91
+
92
+ $count = (int) -1;
93
+
94
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
95
+
96
+ $data = rtrim( $content['data'], ');' );
97
+ $data = ltrim( $data, 'receiveCount(' );
98
+
99
+ $json = json_decode( $data, true );
100
+
101
+ if ( isset( $json['count'] ) && is_numeric( $json['count'] ) ) {
102
+ $count = (int) $json['count'];
103
+ } else {
104
+ $count = (int) -1;
105
+ }
106
+ } else {
107
+ $count = (int) -1;
108
+ }
109
+
110
+ return $count;
111
+ }
112
+
113
+ public function set_query_parameter( $key, $value ) {
114
+ if ( $key === 'url' ) {
115
+ $this->query_parameters[$key] = $value;
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Check if required paramters are included or not.
121
+ *
122
+ * @since 0.9.0
123
+ */
124
+ public function check_configuration() {
125
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
126
+
127
+ if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
128
+ return true;
129
+ } else {
130
+ return false;
131
+ }
132
+ }
133
+
134
+ }
includes/class-scc-share-pocket-strategy.php CHANGED
@@ -1,127 +1,138 @@
1
- <?php
2
- /*
3
- class-scc-share-pocket-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Pocket_Strategy extends SCC_Crawl_Strategy {
31
-
32
- /**
33
- * SNS base url
34
- */
35
- const DEF_BASE_URL = 'http://widgets.getpocket.com/v1/button';
36
-
37
- /**
38
- * Class constarctor
39
- * Hook onto all of the actions and filters needed by the plugin.
40
- *
41
- */
42
- protected function __construct() {
43
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
-
45
- $this->method = 'GET';
46
- $this->query_parameters['v'] = '1';
47
- $this->query_parameters['count'] = 'horizontal';
48
- }
49
-
50
- /**
51
- * Initialization
52
- *
53
- * @since 0.9.0
54
- */
55
- public function initialize( $options = array() ) {
56
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
57
-
58
- if ( isset( $options['url'] ) ) $this->url = $options['url'];
59
- if ( isset( $options['method'] ) ) $this->method = $options['method'];
60
- if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
61
- }
62
-
63
- /**
64
- * Build header
65
- *
66
- * @since 0.9.0
67
- */
68
- public function build_header() {
69
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
70
- return null;
71
- }
72
-
73
- /**
74
- * Build query url
75
- *
76
- * @since 0.9.0
77
- */
78
- public function build_query_url() {
79
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
80
-
81
- $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
82
-
83
- return $url;
84
- }
85
-
86
- /**
87
- * Extract count
88
- *
89
- * @since 0.9.0
90
- */
91
- public function extract_count( $content ) {
92
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
93
-
94
- $count = (int) -1;
95
-
96
- if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
97
-
98
- $return_code = preg_match( '/<em\sid=\"cnt\">([0-9]+)<\/em>/i', $content['data'], $matches );
99
-
100
- if ( $return_code && isset( $matches[1] ) && is_numeric( $matches[1] ) ) {
101
- $count = (int) $matches[1];
102
- } else {
103
- $count = (int) -1;
104
- }
105
- } else {
106
- $count = (int) -1;
107
- }
108
-
109
- return $count;
110
- }
111
-
112
- /**
113
- * Check if required paramters are included or not.
114
- *
115
- * @since 0.9.0
116
- */
117
- public function check_configuration() {
118
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
119
-
120
- if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
121
- return true;
122
- } else {
123
- return false;
124
- }
125
- }
126
-
127
- }
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-pocket-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Pocket_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url
34
+ */
35
+ const DEF_BASE_URL = 'http://widgets.getpocket.com/v1/button';
36
+
37
+ /**
38
+ * Class constarctor
39
+ * Hook onto all of the actions and filters needed by the plugin.
40
+ *
41
+ */
42
+ protected function __construct() {
43
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
44
+
45
+ $this->method = 'GET';
46
+ $this->query_parameters['v'] = '1';
47
+ $this->query_parameters['count'] = 'horizontal';
48
+ //$this->query_parameters['title'] = 'hoge';
49
+ //$this->query_parameters['src'] = 'hoge';
50
+ }
51
+
52
+ /**
53
+ * Initialization
54
+ *
55
+ * @since 0.9.0
56
+ */
57
+ public function initialize( $options = array() ) {
58
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
59
+
60
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
61
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
62
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
63
+ }
64
+
65
+ /**
66
+ * Build header
67
+ *
68
+ * @since 0.9.0
69
+ */
70
+ public function build_header() {
71
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
72
+ return null;
73
+ }
74
+
75
+ /**
76
+ * Build query url
77
+ *
78
+ * @since 0.9.0
79
+ */
80
+ public function build_query_url() {
81
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
82
+
83
+ $url = self::DEF_BASE_URL . '?' . http_build_query( $this->query_parameters , '' , '&' );
84
+
85
+ return $url;
86
+ }
87
+
88
+ /**
89
+ * Extract count
90
+ *
91
+ * @since 0.9.0
92
+ */
93
+ public function extract_count( $content ) {
94
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
95
+
96
+ $count = (int) -1;
97
+
98
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
99
+
100
+ $return_code = preg_match( '/<em\sid=\"cnt\">([0-9]+)<\/em>/i', $content['data'], $matches );
101
+
102
+ if ( $return_code && isset( $matches[1] ) && is_numeric( $matches[1] ) ) {
103
+ $count = (int) $matches[1];
104
+ } else {
105
+ $count = (int) -1;
106
+ }
107
+ } else {
108
+ $count = (int) -1;
109
+ }
110
+
111
+ return $count;
112
+ }
113
+
114
+ public function set_query_parameter( $key, $value ) {
115
+ if ( $key === 'url' ) {
116
+ $this->query_parameters['url'] = $value;
117
+ $this->query_parameters['src'] = $value;
118
+ } elseif ( $key === 'title' ) {
119
+ $this->query_parameters[$key] = $value;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Check if required paramters are included or not.
125
+ *
126
+ * @since 0.9.0
127
+ */
128
+ public function check_configuration() {
129
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
130
+
131
+ if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
132
+ return true;
133
+ } else {
134
+ return false;
135
+ }
136
+ }
137
+
138
+ }
includes/class-scc-share-restore-cache-engine.php CHANGED
@@ -1,267 +1,312 @@
1
- <?php
2
- /*
3
- class-scc-share-restore-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch restore cache data from second cache.
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
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Restore_Cache_Engine extends SCC_Cache_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
-
37
- /**
38
- * Cron name to schedule cache processing
39
- */
40
- const DEF_PRIME_CRON = 'scc_share_restorecache_prime';
41
-
42
- /**
43
- * Cron name to execute cache processing
44
- */
45
- const DEF_EXECUTE_CRON = 'scc_share_restorecache_exec';
46
-
47
- /**
48
- * Schedule name for cache processing
49
- */
50
- const DEF_EVENT_SCHEDULE = 'share_restore_cache_event';
51
-
52
- /**
53
- * Schedule description for cache processing
54
- */
55
- const DEF_EVENT_DESCRIPTION = '[SCC] Share Restore Cache Interval';
56
-
57
- /**
58
- * Interval cheking and caching target data
59
- */
60
- private $check_interval = 600;
61
-
62
- /**
63
- * Number of posts to check at a time
64
- */
65
- private $posts_per_check = 20;
66
-
67
- /**
68
- * Latency suffix
69
- */
70
- private $check_latency = 10;
71
-
72
- /**
73
- * Cache post types
74
- */
75
- private $post_types = array( 'post', 'page' );
76
-
77
- /**
78
- * Initialization
79
- *
80
- * @since 0.1.1
81
- */
82
- public function initialize( $options = array() ) {
83
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
84
-
85
- $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
86
- $this->prime_cron = self::DEF_PRIME_CRON;
87
- $this->execute_cron = self::DEF_EXECUTE_CRON;
88
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
89
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
90
-
91
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
92
- if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
93
- if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
94
- if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
95
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
96
- if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
97
- if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
98
-
99
- add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
100
- }
101
-
102
- /**
103
- * Register base schedule for this engine
104
- *
105
- * @since 0.1.0
106
- */
107
- public function register_schedule() {
108
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
109
- }
110
-
111
- /**
112
- * Unregister base schedule for this engine
113
- *
114
- * @since 0.1.0
115
- */
116
- public function unregister_schedule() {
117
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
118
-
119
- SCC_WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
120
- }
121
-
122
- /**
123
- * Schedule data retrieval and cache processing
124
- *
125
- * @since 0.2.0
126
- */
127
- public function prime_cache( $post_ID ) {
128
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
129
-
130
- $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_latency;
131
-
132
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_latency: ' . $this->check_latency );
133
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
134
-
135
- wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( $post_ID ) );
136
- }
137
-
138
- /**
139
- * Get and cache data of each published post
140
- *
141
- * @since 0.2.0
142
- */
143
- public function execute_cache( $post_ID ) {
144
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
145
-
146
- $cache_expiration = $this->get_cache_expiration();
147
-
148
- SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
149
-
150
- $transient_id = $this->get_cache_key( $post_ID );
151
-
152
- $options = array(
153
- 'cache_key' => $transient_id,
154
- 'post_id' => $post_ID,
155
- 'target_sns' => $this->target_sns,
156
- 'cache_expiration' => $cache_expiration
157
- );
158
-
159
- $this->cache( $options );
160
- }
161
-
162
- /**
163
- * Get and cache data for a given post
164
- *
165
- * @since 0.1.1
166
- */
167
- public function cache( $options = array() ) {
168
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
169
-
170
- $transient_id = $options['cache_key'];
171
- $target_sns = $options['target_sns'];
172
- $post_id = $options['post_id'];
173
- $cache_expiration = $options['cache_expiration'];
174
-
175
- $sns_counts = array();
176
-
177
- if ( $post_id !== 'home' ) {
178
- foreach ( $target_sns as $sns => $active ) {
179
- if ( $active ) {
180
- $meta_key = $this->get_cache_key( $sns );
181
-
182
- $sns_count = get_post_meta( $post_id, $meta_key, true );
183
-
184
- if ( isset( $sns_count ) && $sns_count !== '' ) {
185
- if ( is_numeric( $sns_count ) ) {
186
- $sns_counts[$sns] = (int) $sns_count;
187
- } else {
188
- $sns_counts[$sns] = $sns_count;
189
- }
190
- } else {
191
-
192
- }
193
- }
194
- }
195
- } else {
196
- $option_key = $this->get_cache_key( 'home' );
197
-
198
- if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
199
- } else {
200
- foreach ( $this->share_base_cache_target as $sns => $active ) {
201
- if ( $active ) {
202
- $sns_counts[$sns] = (int) -1;
203
- }
204
- }
205
- }
206
- }
207
-
208
- $result = set_transient( $transient_id, $sns_counts, $cache_expiration );
209
- }
210
-
211
- /**
212
- * Get cache expiration based on current number of total post and page
213
- *
214
- * @since 0.1.1
215
- */
216
- protected function get_cache_expiration() {
217
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
218
-
219
- $posts_total = $this->get_posts_total();
220
-
221
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
222
-
223
- return ceil( $posts_total / $this->posts_per_check ) * $this->check_interval * 3;
224
- }
225
-
226
- /**
227
- * Get total count of current published post and page
228
- *
229
- * @since 0.1.0
230
- */
231
- private function get_posts_total() {
232
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
233
-
234
- $query_args = array(
235
- 'post_type' => $this->post_types,
236
- 'post_status' => 'publish',
237
- 'nopaging' => true,
238
- 'update_post_term_cache' => false,
239
- 'update_post_meta_cache' => false
240
- );
241
-
242
- $posts_query = new WP_Query( $query_args );
243
-
244
- return $posts_query->found_posts;
245
- }
246
-
247
- /**
248
- * Initialize meta key for ranking
249
- *
250
- * @since 0.3.0
251
- */
252
- public function initialize_cache() {
253
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
254
- }
255
-
256
- /**
257
- * Clear meta key for ranking
258
- *
259
- * @since 0.3.0
260
- */
261
- public function clear_cache() {
262
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
263
- }
264
-
265
- }
266
-
267
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-restore-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch restore cache data from second cache.
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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Restore_Cache_Engine extends SCC_Cache_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
+
37
+ /**
38
+ * Cron name to schedule cache processing
39
+ */
40
+ const DEF_PRIME_CRON = 'scc_share_restorecache_prime';
41
+
42
+ /**
43
+ * Cron name to execute cache processing
44
+ */
45
+ const DEF_EXECUTE_CRON = 'scc_share_restorecache_exec';
46
+
47
+ /**
48
+ * Schedule name for cache processing
49
+ */
50
+ const DEF_EVENT_SCHEDULE = 'share_restore_cache_event';
51
+
52
+ /**
53
+ * Schedule description for cache processing
54
+ */
55
+ const DEF_EVENT_DESCRIPTION = '[SCC] Share Restore Cache Interval';
56
+
57
+ /**
58
+ * Interval cheking and caching target data
59
+ */
60
+ private $check_interval = 600;
61
+
62
+ /**
63
+ * Number of posts to check at a time
64
+ */
65
+ private $posts_per_check = 20;
66
+
67
+ /**
68
+ * Latency suffix
69
+ */
70
+ private $check_latency = 10;
71
+
72
+ /**
73
+ * Cache post types
74
+ */
75
+ private $post_types = array( 'post', 'page' );
76
+
77
+ /**
78
+ * Initialization
79
+ *
80
+ * @since 0.1.1
81
+ */
82
+ public function initialize( $options = array() ) {
83
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
84
+
85
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
86
+ $this->prime_cron = self::DEF_PRIME_CRON;
87
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
88
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
89
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
90
+
91
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
92
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
93
+ if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
94
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
95
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
96
+ if ( isset( $options['check_latency'] ) ) $this->check_latency = $options['check_latency'];
97
+ if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
98
+
99
+ add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 1 );
100
+ }
101
+
102
+ /**
103
+ * Register base schedule for this engine
104
+ *
105
+ * @since 0.1.0
106
+ */
107
+ public function register_schedule() {
108
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
109
+ }
110
+
111
+ /**
112
+ * Unregister base schedule for this engine
113
+ *
114
+ * @since 0.1.0
115
+ */
116
+ public function unregister_schedule() {
117
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
118
+
119
+ SCC_WP_Cron_Util::clear_scheduled_hook( $this->execute_cron );
120
+ }
121
+
122
+ /**
123
+ * Schedule data retrieval and cache processing
124
+ *
125
+ * @since 0.2.0
126
+ */
127
+ public function prime_cache( $post_ID ) {
128
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
129
+
130
+ $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_latency;
131
+
132
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_latency: ' . $this->check_latency );
133
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
134
+
135
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( $post_ID ) );
136
+ }
137
+
138
+ /**
139
+ * Get and cache data of each published post
140
+ *
141
+ * @since 0.2.0
142
+ */
143
+ public function execute_cache( $post_ID ) {
144
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
145
+
146
+ $cache_expiration = $this->get_cache_expiration();
147
+
148
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
149
+
150
+ $transient_id = $this->get_cache_key( $post_ID );
151
+
152
+ $options = array(
153
+ 'cache_key' => $transient_id,
154
+ 'post_id' => $post_ID,
155
+ 'target_sns' => $this->target_sns,
156
+ 'cache_expiration' => $cache_expiration
157
+ );
158
+
159
+ $this->cache( $options );
160
+ }
161
+
162
+ /**
163
+ * Get and cache data for a given post
164
+ *
165
+ * @since 0.1.1
166
+ */
167
+ public function cache( $options = array() ) {
168
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
169
+
170
+ $transient_id = $options['cache_key'];
171
+ $target_sns = $options['target_sns'];
172
+ $post_id = $options['post_id'];
173
+ $cache_expiration = $options['cache_expiration'];
174
+
175
+ $sns_counts = array();
176
+
177
+ if ( $post_id !== 'home' ) {
178
+ foreach ( $target_sns as $sns => $active ) {
179
+ if ( $active ) {
180
+ $meta_key = $this->get_cache_key( $sns );
181
+
182
+ $sns_count = get_post_meta( $post_id, $meta_key, true );
183
+
184
+ if ( isset( $sns_count ) && $sns_count !== '' ) {
185
+ if ( is_numeric( $sns_count ) ) {
186
+ $sns_counts[$sns] = (int) $sns_count;
187
+ } else {
188
+ $sns_counts[$sns] = $sns_count;
189
+ }
190
+ } else {
191
+
192
+ }
193
+ }
194
+ }
195
+ } else {
196
+ $option_key = $this->get_cache_key( 'home' );
197
+
198
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
199
+ } else {
200
+ foreach ( $this->share_base_cache_target as $sns => $active ) {
201
+ if ( $active ) {
202
+ $sns_counts[$sns] = (int) -1;
203
+ }
204
+ }
205
+ }
206
+ }
207
+
208
+ $result = set_transient( $transient_id, $sns_counts, $cache_expiration );
209
+ }
210
+
211
+ /**
212
+ * Get cache expiration based on current number of total post and page
213
+ *
214
+ * @since 0.1.1
215
+ */
216
+ protected function get_cache_expiration() {
217
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
218
+
219
+ $posts_total = $this->get_posts_total();
220
+
221
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
222
+
223
+ return ceil( $posts_total / $this->posts_per_check ) * $this->check_interval * 3;
224
+ }
225
+
226
+ /**
227
+ * Get total count of current published post and page
228
+ *
229
+ * @since 0.1.0
230
+ */
231
+ private function get_posts_total() {
232
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
233
+
234
+ $query_args = array(
235
+ 'post_type' => $this->post_types,
236
+ 'post_status' => 'publish',
237
+ 'nopaging' => true,
238
+ 'update_post_term_cache' => false,
239
+ 'update_post_meta_cache' => false
240
+ );
241
+
242
+ $posts_query = new WP_Query( $query_args );
243
+
244
+ return $posts_query->found_posts;
245
+ }
246
+
247
+ /**
248
+ * Initialize meta key for ranking
249
+ *
250
+ * @since 0.3.0
251
+ */
252
+ public function initialize_cache() {
253
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
254
+ }
255
+
256
+ /**
257
+ * Clear meta key for ranking
258
+ *
259
+ * @since 0.3.0
260
+ */
261
+ public function clear_cache() {
262
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
263
+ }
264
+
265
+ /**
266
+ * Get cache
267
+ *
268
+ * @since 0.10.1
269
+ */
270
+ public function get_cache( $options = array() ) {
271
+ $target_sns = $options['target_sns'];
272
+ $post_id = $options['post_id'];
273
+
274
+ $sns_counts = array();
275
+
276
+ if ( $post_id !== 'home' ) {
277
+ foreach ( $target_sns as $sns => $active ) {
278
+ if ( $active ) {
279
+ $meta_key = $this->get_cache_key( $sns );
280
+
281
+ $sns_count = get_post_meta( $post_id, $meta_key, true );
282
+
283
+ if ( isset( $sns_count ) && $sns_count !== '' ) {
284
+ if ( is_numeric( $sns_count ) ) {
285
+ $sns_counts[$sns] = (int) $sns_count;
286
+ } else {
287
+ $sns_counts[$sns] = $sns_count;
288
+ }
289
+ } else {
290
+
291
+ }
292
+ }
293
+ }
294
+ } else {
295
+ $option_key = $this->get_cache_key( 'home' );
296
+
297
+ if ( false !== ( $sns_counts = get_option( $option_key ) ) ) {
298
+ } else {
299
+ foreach ( $this->share_base_cache_target as $sns => $active ) {
300
+ if ( $active ) {
301
+ $sns_counts[$sns] = (int) -1;
302
+ }
303
+ }
304
+ }
305
+ }
306
+
307
+ return $sns_counts;
308
+ }
309
+
310
+ }
311
+
312
+ ?>
includes/class-scc-share-rush-cache-engine.php CHANGED
@@ -1,345 +1,352 @@
1
- <?php
2
- /*
3
- class-scc-share-rush-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Rush_Cache_Engine extends SCC_Share_Cache_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
-
37
- /**
38
- * Cron name to schedule cache processing
39
- */
40
- const DEF_PRIME_CRON = 'scc_share_rushcache_prime';
41
-
42
- /**
43
- * Cron name to execute cache processing
44
- */
45
- const DEF_EXECUTE_CRON = 'scc_share_rushcache_exec';
46
-
47
- /**
48
- * Schedule name for cache processing
49
- */
50
- const DEF_EVENT_SCHEDULE = 'share_rush_cache_event';
51
-
52
- /**
53
- * Schedule description for cache processing
54
- */
55
- const DEF_EVENT_DESCRIPTION = '[SCC] Share Rush Cache Interval';
56
-
57
- /**
58
- * Interval cheking and caching target data
59
- */
60
- private $check_interval = 600;
61
-
62
- /**
63
- * Number of posts to check at a time
64
- */
65
- private $posts_per_check = 20;
66
-
67
- /**
68
- * Offset suffix
69
- */
70
- private $offset_suffix = 'rush_offset';
71
-
72
- /**
73
- * Term considered as new content
74
- */
75
- private $new_content_term = 3;
76
-
77
- /**
78
- * Initialization
79
- *
80
- * @since 0.1.1
81
- */
82
- public function initialize( $options = array() ) {
83
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
84
-
85
- $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
86
- $this->prime_cron = self::DEF_PRIME_CRON;
87
- $this->execute_cron = self::DEF_EXECUTE_CRON;
88
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
89
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
90
-
91
- $this->load_ratio = 0.5;
92
-
93
- if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
94
- if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
95
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
96
- if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
97
- if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
98
- if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
99
- if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
100
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
101
- if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
102
- if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
103
- if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
104
- if ( isset( $options['new_content_term'] ) ) $this->new_content_term = $options['new_content_term'];
105
- if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
106
- if ( isset( $options['scheme_migration_date'] ) ) $this->scheme_migration_date = $options['scheme_migration_date'];
107
- if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
108
- if ( isset( $options['cache_retry'] ) ) $this->cache_retry = $options['cache_retry'];
109
- if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
110
- if ( isset( $options['fault_tolerance'] ) ) $this->fault_tolerance = $options['fault_tolerance'];
111
-
112
- add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
113
- add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
114
- add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 2 );
115
- }
116
-
117
- /**
118
- * Register event schedule for this engine
119
- *
120
- * @since 0.1.0
121
- */
122
- public function schedule_check_interval( $schedules ) {
123
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
124
-
125
- $schedules[$this->event_schedule] = array(
126
- 'interval' => $this->check_interval,
127
- 'display' => $this->event_description
128
- );
129
-
130
- return $schedules;
131
- }
132
-
133
- /**
134
- * Schedule data retrieval and cache processing
135
- *
136
- * @since 0.2.0
137
- */
138
- public function prime_cache() {
139
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
140
-
141
- $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
142
- $posts_total = $this->get_posts_total();
143
-
144
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
145
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_per_check: ' . $this->posts_per_check );
146
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
147
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
148
-
149
- $option_key = $this->get_cache_key($this->offset_suffix);
150
-
151
- if ( false === ( $posts_offset = get_option( $option_key ) ) ) {
152
- $posts_offset = 0;
153
- }
154
-
155
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_offset: ' . $posts_offset );
156
-
157
- wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( (int) $posts_offset, SCC_Common_Util::short_hash( $next_exec_time ) ) );
158
-
159
- $posts_offset = $posts_offset + $this->posts_per_check;
160
-
161
- if ( $posts_offset > $posts_total ) {
162
- $posts_offset = 0;
163
- }
164
-
165
- update_option( $option_key, $posts_offset );
166
- }
167
-
168
- /**
169
- * Get and cache data of each published post and page
170
- *
171
- * @since 0.2.0
172
- */
173
- public function execute_cache( $posts_offset, $hash ) {
174
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
175
-
176
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_offset: ' . $posts_offset );
177
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
178
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_per_check: ' . $this->posts_per_check );
179
-
180
- $cache_expiration = $this->get_cache_expiration();
181
-
182
- $term_threshold = $this->get_new_contet_term();
183
-
184
- SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
185
-
186
- SCC_Common_Util::log( '[' . __METHOD__ . '] term_threshold: ' . $term_threshold );
187
-
188
- $query_args = array(
189
- 'post_type' => $this->post_types,
190
- 'post_status' => 'publish',
191
- 'offset' => $posts_offset,
192
- 'posts_per_page' => $this->posts_per_check,
193
- 'date_query' => array(
194
- 'column' => 'post_date_gmt',
195
- 'after' => $term_threshold
196
- ),
197
- 'no_found_rows' => true,
198
- 'update_post_term_cache' => false,
199
- 'update_post_meta_cache' => false
200
- );
201
-
202
- $posts_query = new WP_Query( $query_args );
203
-
204
- if ( $posts_query->have_posts() ) {
205
- while ( $posts_query->have_posts() ) {
206
- $posts_query->the_post();
207
-
208
- $post_ID = get_the_ID();
209
-
210
- SCC_Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
211
-
212
- $transient_id = $this->get_cache_key( $post_ID );
213
-
214
- $url = get_permalink( $post_ID );
215
-
216
- $options = array(
217
- 'cache_key' => $transient_id,
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
-
225
- // Primary cache
226
- $this->cache( $options );
227
-
228
- // Secondary cache
229
- $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
230
- }
231
- }
232
- wp_reset_postdata();
233
- }
234
-
235
- /**
236
- * Get term considered as new content
237
- *
238
- * @since 0.4.0
239
- */
240
- private function get_new_contet_term() {
241
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
242
-
243
- $term_threshold = '3 days ago';
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
-
251
- return $term_threshold;
252
- }
253
-
254
- /**
255
- * Get cache expiration based on current number of total post and page
256
- *
257
- * @since 0.2.0
258
- */
259
- protected function get_cache_expiration() {
260
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
261
-
262
- $posts_total = $this->get_posts_total();
263
-
264
- SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
265
-
266
- return ceil( $posts_total / $this->posts_per_check ) * $this->check_interval * 3;
267
- }
268
-
269
- /**
270
- * Get total count of current published post and page
271
- *
272
- * @since 0.2.0
273
- */
274
- private function get_posts_total() {
275
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
276
-
277
- $term_threshold = $this->get_new_contet_term();
278
-
279
- $query_args = array(
280
- 'post_type' => $this->post_types,
281
- 'post_status' => 'publish',
282
- 'date_query' => array(
283
- 'column' => 'post_date_gmt',
284
- 'after' => $term_threshold
285
- ),
286
- 'nopaging' => true,
287
- 'no_found_rows' => true,
288
- 'update_post_term_cache' => false,
289
- 'update_post_meta_cache' => false
290
- );
291
-
292
- $posts_query = new WP_Query( $query_args );
293
-
294
- return $posts_query->found_posts;
295
- }
296
-
297
- /**
298
- * Initialize meta key for ranking
299
- *
300
- * @since 0.3.0
301
- */
302
- public function initialize_cache() {
303
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
304
-
305
- $option_key = $this->get_cache_key( $this->offset_suffix );
306
-
307
- update_option( $option_key, 0 );
308
- }
309
-
310
- /**
311
- * Clear meta key for ranking
312
- *
313
- * @since 0.3.0
314
- */
315
- public function clear_cache() {
316
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
317
-
318
- $option_key = $this->get_cache_key( $this->offset_suffix );
319
-
320
- delete_option( $option_key );
321
-
322
- }
323
-
324
- /**
325
- * Get current cache
326
- *
327
- * @since 0.9.3
328
- */
329
- protected function get_current_cache( $options = array() ) {
330
- $post_id = $options['post_id'];
331
-
332
- $transient_id = $this->get_cache_key( $post_id );
333
-
334
- $sns_counts = array();
335
-
336
- if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
337
- return $sns_counts;
338
- } else {
339
- return $this->delegate_order( SCC_Order::ORDER_GET_SECOND_CACHE, $options );
340
- }
341
- }
342
-
343
- }
344
-
345
- ?>
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-rush-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Rush_Cache_Engine extends SCC_Share_Cache_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
+
37
+ /**
38
+ * Cron name to schedule cache processing
39
+ */
40
+ const DEF_PRIME_CRON = 'scc_share_rushcache_prime';
41
+
42
+ /**
43
+ * Cron name to execute cache processing
44
+ */
45
+ const DEF_EXECUTE_CRON = 'scc_share_rushcache_exec';
46
+
47
+ /**
48
+ * Schedule name for cache processing
49
+ */
50
+ const DEF_EVENT_SCHEDULE = 'share_rush_cache_event';
51
+
52
+ /**
53
+ * Schedule description for cache processing
54
+ */
55
+ const DEF_EVENT_DESCRIPTION = '[SCC] Share Rush Cache Interval';
56
+
57
+ /**
58
+ * Cache post types
59
+ */
60
+ private $post_types = array( 'post', 'page' );
61
+
62
+ /**
63
+ * Interval cheking and caching target data
64
+ */
65
+ private $check_interval = 600;
66
+
67
+ /**
68
+ * Number of posts to check at a time
69
+ */
70
+ private $posts_per_check = 20;
71
+
72
+ /**
73
+ * Offset suffix
74
+ */
75
+ private $offset_suffix = 'rush_offset';
76
+
77
+ /**
78
+ * Term considered as new content
79
+ */
80
+ private $new_content_term = 3;
81
+
82
+ /**
83
+ * Initialization
84
+ *
85
+ * @since 0.1.1
86
+ */
87
+ public function initialize( $options = array() ) {
88
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
89
+
90
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
91
+ $this->prime_cron = self::DEF_PRIME_CRON;
92
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
93
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
94
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
95
+
96
+ $this->load_ratio = 0.5;
97
+
98
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
99
+ if ( isset( $options['crawler'] ) ) $this->crawler = $options['crawler'];
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'];
103
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
104
+ if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
105
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
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['new_content_term'] ) ) $this->new_content_term = $options['new_content_term'];
110
+ if ( isset( $options['scheme_migration_mode'] ) ) $this->scheme_migration_mode = $options['scheme_migration_mode'];
111
+ if ( isset( $options['scheme_migration_date'] ) ) $this->scheme_migration_date = $options['scheme_migration_date'];
112
+ if ( isset( $options['scheme_migration_exclude_keys'] ) ) $this->scheme_migration_exclude_keys = $options['scheme_migration_exclude_keys'];
113
+ if ( isset( $options['cache_retry'] ) ) $this->cache_retry = $options['cache_retry'];
114
+ if ( isset( $options['retry_limit'] ) ) $this->retry_limit = $options['retry_limit'];
115
+ if ( isset( $options['fault_tolerance'] ) ) $this->fault_tolerance = $options['fault_tolerance'];
116
+
117
+ add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
118
+ add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
119
+ add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 2 );
120
+ }
121
+
122
+ /**
123
+ * Register event schedule for this engine
124
+ *
125
+ * @since 0.1.0
126
+ */
127
+ public function schedule_check_interval( $schedules ) {
128
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
129
+
130
+ $schedules[$this->event_schedule] = array(
131
+ 'interval' => $this->check_interval,
132
+ 'display' => $this->event_description
133
+ );
134
+
135
+ return $schedules;
136
+ }
137
+
138
+ /**
139
+ * Schedule data retrieval and cache processing
140
+ *
141
+ * @since 0.2.0
142
+ */
143
+ public function prime_cache() {
144
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
145
+
146
+ $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
147
+ $posts_total = $this->get_posts_total();
148
+
149
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
150
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_per_check: ' . $this->posts_per_check );
151
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
152
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
153
+
154
+ $option_key = $this->get_cache_key($this->offset_suffix);
155
+
156
+ if ( false === ( $posts_offset = get_option( $option_key ) ) ) {
157
+ $posts_offset = 0;
158
+ }
159
+
160
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_offset: ' . $posts_offset );
161
+
162
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron, array( (int) $posts_offset, SCC_Common_Util::short_hash( $next_exec_time ) ) );
163
+
164
+ $posts_offset = $posts_offset + $this->posts_per_check;
165
+
166
+ if ( $posts_offset > $posts_total ) {
167
+ $posts_offset = 0;
168
+ }
169
+
170
+ update_option( $option_key, $posts_offset );
171
+ }
172
+
173
+ /**
174
+ * Get and cache data of each published post and page
175
+ *
176
+ * @since 0.2.0
177
+ */
178
+ public function execute_cache( $posts_offset, $hash ) {
179
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
180
+
181
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_offset: ' . $posts_offset );
182
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
183
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_per_check: ' . $this->posts_per_check );
184
+
185
+ $cache_expiration = $this->get_cache_expiration();
186
+
187
+ $term_threshold = $this->get_new_contet_term();
188
+
189
+ SCC_Common_Util::log( '[' . __METHOD__ . '] cache_expiration: ' . $cache_expiration );
190
+
191
+ SCC_Common_Util::log( '[' . __METHOD__ . '] term_threshold: ' . $term_threshold );
192
+
193
+ $query_args = array(
194
+ 'post_type' => $this->post_types,
195
+ 'post_status' => 'publish',
196
+ 'offset' => $posts_offset,
197
+ 'posts_per_page' => $this->posts_per_check,
198
+ 'date_query' => array(
199
+ 'column' => 'post_date_gmt',
200
+ 'after' => $term_threshold
201
+ ),
202
+ 'no_found_rows' => true,
203
+ 'update_post_term_cache' => false,
204
+ 'update_post_meta_cache' => false
205
+ );
206
+
207
+ $posts_query = new WP_Query( $query_args );
208
+
209
+ if ( $posts_query->have_posts() ) {
210
+ while ( $posts_query->have_posts() ) {
211
+ $posts_query->the_post();
212
+
213
+ $post_ID = get_the_ID();
214
+
215
+ SCC_Common_Util::log( '[' . __METHOD__ . '] post_id: ' . $post_ID );
216
+
217
+ $transient_id = $this->get_cache_key( $post_ID );
218
+
219
+ $url = get_permalink( $post_ID );
220
+ $title = get_the_title( $post_ID );
221
+
222
+ $options = array(
223
+ 'cache_key' => $transient_id,
224
+ 'post_id' => $post_ID,
225
+ 'target_url' => $url,
226
+ 'target_sns' => $this->target_sns,
227
+ 'target_title' => $title,
228
+ 'publish_date' => get_the_date( 'Y/m/d' ),
229
+ 'cache_expiration' => $cache_expiration
230
+ );
231
+
232
+ // Primary cache
233
+ $this->cache( $options );
234
+
235
+ // Secondary cache
236
+ $this->delegate_order( SCC_Order::ORDER_DO_SECOND_CACHE, $options );
237
+ }
238
+ }
239
+ wp_reset_postdata();
240
+ }
241
+
242
+ /**
243
+ * Get term considered as new content
244
+ *
245
+ * @since 0.4.0
246
+ */
247
+ private function get_new_contet_term() {
248
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
249
+
250
+ $term_threshold = '3 days ago';
251
+
252
+ if ( $this->new_content_term > 1 ) {
253
+ $term_threshold = $this->new_content_term . ' days ago';
254
+ } elseif ( $this->new_content_term == 1 ) {
255
+ $term_threshold = $this->new_content_term . ' day ago';
256
+ }
257
+
258
+ return $term_threshold;
259
+ }
260
+
261
+ /**
262
+ * Get cache expiration based on current number of total post and page
263
+ *
264
+ * @since 0.2.0
265
+ */
266
+ protected function get_cache_expiration() {
267
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
268
+
269
+ $posts_total = $this->get_posts_total();
270
+
271
+ SCC_Common_Util::log( '[' . __METHOD__ . '] posts_total: ' . $posts_total );
272
+
273
+ return ceil( $posts_total / $this->posts_per_check ) * $this->check_interval * 3;
274
+ }
275
+
276
+ /**
277
+ * Get total count of current published post and page
278
+ *
279
+ * @since 0.2.0
280
+ */
281
+ private function get_posts_total() {
282
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
283
+
284
+ $term_threshold = $this->get_new_contet_term();
285
+
286
+ $query_args = array(
287
+ 'post_type' => $this->post_types,
288
+ 'post_status' => 'publish',
289
+ 'date_query' => array(
290
+ 'column' => 'post_date_gmt',
291
+ 'after' => $term_threshold
292
+ ),
293
+ 'nopaging' => true,
294
+ 'no_found_rows' => true,
295
+ 'update_post_term_cache' => false,
296
+ 'update_post_meta_cache' => false
297
+ );
298
+
299
+ $posts_query = new WP_Query( $query_args );
300
+
301
+ return $posts_query->found_posts;
302
+ }
303
+
304
+ /**
305
+ * Initialize meta key for ranking
306
+ *
307
+ * @since 0.3.0
308
+ */
309
+ public function initialize_cache() {
310
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
311
+
312
+ $option_key = $this->get_cache_key( $this->offset_suffix );
313
+
314
+ update_option( $option_key, 0 );
315
+ }
316
+
317
+ /**
318
+ * Clear meta key for ranking
319
+ *
320
+ * @since 0.3.0
321
+ */
322
+ public function clear_cache() {
323
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
324
+
325
+ $option_key = $this->get_cache_key( $this->offset_suffix );
326
+
327
+ delete_option( $option_key );
328
+
329
+ }
330
+
331
+ /**
332
+ * Get current cache
333
+ *
334
+ * @since 0.9.3
335
+ */
336
+ public function get_cache( $options = array() ) {
337
+ $post_id = $options['post_id'];
338
+
339
+ $transient_id = $this->get_cache_key( $post_id );
340
+
341
+ $sns_counts = array();
342
+
343
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
344
+ return $sns_counts;
345
+ } else {
346
+ return $this->delegate_order( SCC_Order::ORDER_GET_SECOND_CACHE, $options );
347
+ }
348
+ }
349
+
350
+ }
351
+
352
+ ?>
includes/class-scc-share-second-cache-engine.php CHANGED
@@ -1,347 +1,370 @@
1
- <?php
2
- /*
3
- class-scc-share-second-cache-engine.php
4
-
5
- Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Second_Cache_Engine extends SCC_Cache_Engine {
31
-
32
- /**
33
- * Prefix of cache ID
34
- */
35
- const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
-
37
- /**
38
- * Cron name to schedule cache processing
39
- */
40
- const DEF_PRIME_CRON = 'scc_share_2ndcache_prime';
41
-
42
- /**
43
- * Cron name to execute cache processing
44
- */
45
- const DEF_EXECUTE_CRON = 'scc_share_2ndcache_exec';
46
-
47
- /**
48
- * Schedule name for cache processing
49
- */
50
- const DEF_EVENT_SCHEDULE = 'share_second_cache_event';
51
-
52
- /**
53
- * Schedule description for cache processing
54
- */
55
- const DEF_EVENT_DESCRIPTION = '[SCC] Share Second Cache Interval';
56
-
57
- /**
58
- * Interval cheking and caching target data
59
- */
60
- private $check_interval = 600;
61
-
62
- /**
63
- * Number of posts to check at a time
64
- */
65
- private $posts_per_check = 20;
66
-
67
- /**
68
- * Cache target
69
- */
70
- private $target_sns = array();
71
-
72
- /**
73
- * Cache post types
74
- */
75
- private $post_types = array( 'post', 'page' );
76
-
77
- /**
78
- * Crawl date key
79
- */
80
- private $crawl_date_key = NULL;
81
-
82
- /**
83
- * Initialization
84
- *
85
- * @since 0.1.1
86
- */
87
- public function initialize( $options = array() ) {
88
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
89
-
90
- $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
91
- $this->prime_cron = self::DEF_PRIME_CRON;
92
- $this->execute_cron = self::DEF_EXECUTE_CRON;
93
- $this->event_schedule = self::DEF_EVENT_SCHEDULE;
94
- $this->event_description = self::DEF_EVENT_DESCRIPTION;
95
-
96
- if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
97
- if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
98
- if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
99
- if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
100
- if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
101
- if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
102
- if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
103
- if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
104
- if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
105
- if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
106
- if ( isset( $options['crawl_date_key'] ) ) $this->crawl_date_key = $options['crawl_date_key'];
107
-
108
- add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
109
- add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
110
- add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 0 );
111
- }
112
-
113
- /**
114
- * Register event schedule for this engine
115
- *
116
- * @since 0.1.0
117
- */
118
- public function schedule_check_interval( $schedules ) {
119
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
120
-
121
- $schedules[$this->event_schedule] = array(
122
- 'interval' => $this->check_interval,
123
- 'display' => $this->event_description
124
- );
125
-
126
- return $schedules;
127
- }
128
-
129
- /**
130
- * Schedule data retrieval and cache processing
131
- *
132
- * @since 0.3.0
133
- */
134
- public function prime_cache() {
135
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
136
-
137
- $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
138
-
139
- SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
140
- SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
141
-
142
- wp_schedule_single_event( $next_exec_time, $this->execute_cron );
143
- }
144
-
145
- /**
146
- * Get and cache data of each published post and page
147
- *
148
- * @since 0.3.0
149
- */
150
- public function execute_cache() {
151
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
152
-
153
- $query_args = array(
154
- 'post_type' => $this->post_types,
155
- 'post_status' => 'publish',
156
- 'nopaging' => true,
157
- 'update_post_term_cache' => false,
158
- 'update_post_meta_cache' => false
159
- );
160
-
161
- $posts_query = new WP_Query( $query_args );
162
-
163
- if ( $posts_query->have_posts() ) {
164
- while ( $posts_query->have_posts() ) {
165
- $posts_query->the_post();
166
-
167
- $post_id = get_the_ID();
168
-
169
- $transient_id = $this->get_cache_key( $post_id );
170
-
171
- $url = get_permalink( $post_id );
172
-
173
- $options = array(
174
- 'cache_key' => $transient_id,
175
- 'post_id' => $post_id,
176
- 'target_sns' => $this->target_sns
177
- );
178
-
179
- $this->cache( $options );
180
- }
181
- }
182
- wp_reset_postdata();
183
-
184
- }
185
-
186
- /**
187
- * Get and cache data for a given post
188
- *
189
- * @since 0.1.1
190
- */
191
- public function cache( $options = array() ) {
192
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
193
-
194
- $transient_id = $options['cache_key'];
195
- $target_sns = $options['target_sns'];
196
- $post_id = $options['post_id'];
197
-
198
- $sns_counts = array();
199
-
200
- if ( $post_id !== 'home' ) {
201
- if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
202
- foreach ( $target_sns as $sns => $active ) {
203
- if ( $active ) {
204
- $meta_key = $this->get_cache_key( $sns );
205
-
206
- if ( $sns !== $this->crawl_date_key ) {
207
-
208
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
209
- update_post_meta( $post_id, $meta_key, (int) $sns_counts[$sns] );
210
- } else {
211
- update_post_meta( $post_id, $meta_key, (int) -1 );
212
- }
213
- } else {
214
- if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' ) {
215
- update_post_meta( $post_id, $meta_key, $sns_counts[$sns] );
216
- } else {
217
- update_post_meta( $post_id, $meta_key, '' );
218
- }
219
- }
220
- }
221
- }
222
- }
223
- } else {
224
- if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
225
-
226
- $option_key = $this->get_cache_key( 'home' );
227
-
228
- foreach ( $target_sns as $sns => $active ) {
229
- if ( $active ) {
230
- if ( $sns !== $this->crawl_date_key ) {
231
- if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
232
- $sns_counts[$sns] = (int) -1;
233
- }
234
- } else {
235
- if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] === '' ) {
236
- $sns_counts[$sns] = '';
237
- }
238
- }
239
- }
240
- }
241
-
242
- update_option( $option_key, $sns_counts );
243
- }
244
- }
245
-
246
- $this->delegate_order( SCC_Order::ORDER_DO_ANALYSIS, $options );
247
-
248
- }
249
-
250
- /**
251
- * Get cache expiration based on current number of total post and page
252
- *
253
- * @since 0.2.0
254
- */
255
- protected function get_cache_expiration() {
256
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
257
-
258
- return 0;
259
- }
260
-
261
- /**
262
- * Initialize meta key for ranking
263
- *
264
- * @since 0.3.0
265
- */
266
- public function initialize_cache() {
267
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
268
-
269
- $option_key = $this->get_cache_key( 'home' );
270
-
271
- $sns_counts = array();
272
-
273
- foreach ( $this->target_sns as $sns => $active ) {
274
- if ( $active ) {
275
- $sns_counts[$sns] = (int) -1;
276
- }
277
- }
278
-
279
- update_option( $option_key, $sns_counts );
280
-
281
- $query_args = array(
282
- 'post_type' => $this->post_types,
283
- 'post_status' => 'publish',
284
- 'nopaging' => true,
285
- 'update_post_term_cache' => false,
286
- 'update_post_meta_cache' => false
287
- );
288
-
289
- $posts_query = new WP_Query( $query_args );
290
-
291
- if ( $posts_query->have_posts() ) {
292
- while ( $posts_query->have_posts() ) {
293
- $posts_query->the_post();
294
-
295
- $post_id = get_the_ID();
296
-
297
- foreach ( $this->target_sns as $sns => $active ) {
298
- $meta_key = $this->get_cache_key( $sns );
299
-
300
- if ( $active ) {
301
- update_post_meta( $post_id, $meta_key, (int) -1 );
302
- }
303
- }
304
- }
305
- }
306
- wp_reset_postdata();
307
- }
308
-
309
- /**
310
- * Clear meta key for ranking
311
- *
312
- * @since 0.3.0
313
- */
314
- public function clear_cache() {
315
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
316
-
317
- $option_key = $this->get_cache_key( 'home' );
318
- delete_option( $option_key );
319
-
320
- foreach ( $this->target_sns as $sns => $active ) {
321
- if ( $active ) {
322
- $meta_key = $this->get_cache_key( $sns );
323
- delete_post_meta_by_key( $meta_key );
324
- }
325
- }
326
- }
327
-
328
- /**
329
- * Clear meta key for ranking
330
- *
331
- * @since 0.7.0
332
- */
333
- public function clear_cache_by_post_id( $post_id ) {
334
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
335
-
336
- foreach ( $this->target_sns as $sns => $active ) {
337
- if ( $active ) {
338
- $meta_key = $this->get_cache_key( $sns );
339
- delete_post_meta( $post_id, $meta_key );
340
- }
341
- }
342
-
343
- }
344
-
345
- }
346
-
347
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-second-cache-engine.php
4
+
5
+ Description: This class is a data cache engine whitch get and cache data using wp-cron at regular intervals
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Second_Cache_Engine extends SCC_Cache_Engine {
31
+
32
+ /**
33
+ * Prefix of cache ID
34
+ */
35
+ const DEF_TRANSIENT_PREFIX = 'scc_share_count_';
36
+
37
+ /**
38
+ * Cron name to schedule cache processing
39
+ */
40
+ const DEF_PRIME_CRON = 'scc_share_2ndcache_prime';
41
+
42
+ /**
43
+ * Cron name to execute cache processing
44
+ */
45
+ const DEF_EXECUTE_CRON = 'scc_share_2ndcache_exec';
46
+
47
+ /**
48
+ * Schedule name for cache processing
49
+ */
50
+ const DEF_EVENT_SCHEDULE = 'share_second_cache_event';
51
+
52
+ /**
53
+ * Schedule description for cache processing
54
+ */
55
+ const DEF_EVENT_DESCRIPTION = '[SCC] Share Second Cache Interval';
56
+
57
+ /**
58
+ * Interval cheking and caching target data
59
+ */
60
+ private $check_interval = 600;
61
+
62
+ /**
63
+ * Number of posts to check at a time
64
+ */
65
+ private $posts_per_check = 20;
66
+
67
+ /**
68
+ * Cache target
69
+ */
70
+ private $target_sns = array();
71
+
72
+ /**
73
+ * Cache post types
74
+ */
75
+ private $post_types = array( 'post', 'page' );
76
+
77
+ /**
78
+ * Crawl date key
79
+ */
80
+ private $crawl_date_key = NULL;
81
+
82
+ /**
83
+ * Initialization
84
+ *
85
+ * @since 0.1.1
86
+ */
87
+ public function initialize( $options = array() ) {
88
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
89
+
90
+ $this->cache_prefix = self::DEF_TRANSIENT_PREFIX;
91
+ $this->prime_cron = self::DEF_PRIME_CRON;
92
+ $this->execute_cron = self::DEF_EXECUTE_CRON;
93
+ $this->event_schedule = self::DEF_EVENT_SCHEDULE;
94
+ $this->event_description = self::DEF_EVENT_DESCRIPTION;
95
+
96
+ if ( isset( $options['delegate'] ) ) $this->delegate = $options['delegate'];
97
+ if ( isset( $options['target_sns'] ) ) $this->target_sns = $options['target_sns'];
98
+ if ( isset( $options['check_interval'] ) ) $this->check_interval = $options['check_interval'];
99
+ if ( isset( $options['posts_per_check'] ) ) $this->posts_per_check = $options['posts_per_check'];
100
+ if ( isset( $options['cache_prefix'] ) ) $this->cache_prefix = $options['cache_prefix'];
101
+ if ( isset( $options['prime_cron'] ) ) $this->prime_cron = $options['prime_cron'];
102
+ if ( isset( $options['execute_cron'] ) ) $this->execute_cron = $options['execute_cron'];
103
+ if ( isset( $options['event_schedule'] ) ) $this->event_schedule = $options['event_schedule'];
104
+ if ( isset( $options['event_description'] ) ) $this->event_description = $options['event_description'];
105
+ if ( isset( $options['post_types'] ) ) $this->post_types = $options['post_types'];
106
+ if ( isset( $options['crawl_date_key'] ) ) $this->crawl_date_key = $options['crawl_date_key'];
107
+
108
+ add_filter( 'cron_schedules', array( $this, 'schedule_check_interval' ) );
109
+ add_action( $this->prime_cron, array( $this, 'prime_cache' ) );
110
+ add_action( $this->execute_cron, array( $this, 'execute_cache' ), 10, 0 );
111
+ }
112
+
113
+ /**
114
+ * Register event schedule for this engine
115
+ *
116
+ * @since 0.1.0
117
+ */
118
+ public function schedule_check_interval( $schedules ) {
119
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
120
+
121
+ $schedules[$this->event_schedule] = array(
122
+ 'interval' => $this->check_interval,
123
+ 'display' => $this->event_description
124
+ );
125
+
126
+ return $schedules;
127
+ }
128
+
129
+ /**
130
+ * Schedule data retrieval and cache processing
131
+ *
132
+ * @since 0.3.0
133
+ */
134
+ public function prime_cache() {
135
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
136
+
137
+ $next_exec_time = (int) current_time( 'timestamp', 1 ) + $this->check_interval;
138
+
139
+ SCC_Common_Util::log( '[' . __METHOD__ . '] check_interval: ' . $this->check_interval );
140
+ SCC_Common_Util::log( '[' . __METHOD__ . '] next_exec_time: ' . $next_exec_time );
141
+
142
+ wp_schedule_single_event( $next_exec_time, $this->execute_cron );
143
+ }
144
+
145
+ /**
146
+ * Get and cache data of each published post and page
147
+ *
148
+ * @since 0.3.0
149
+ */
150
+ public function execute_cache() {
151
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
152
+
153
+ $query_args = array(
154
+ 'post_type' => $this->post_types,
155
+ 'post_status' => 'publish',
156
+ 'nopaging' => true,
157
+ 'update_post_term_cache' => false,
158
+ 'update_post_meta_cache' => false
159
+ );
160
+
161
+ $posts_query = new WP_Query( $query_args );
162
+
163
+ if ( $posts_query->have_posts() ) {
164
+ while ( $posts_query->have_posts() ) {
165
+ $posts_query->the_post();
166
+
167
+ $post_id = get_the_ID();
168
+
169
+ $transient_id = $this->get_cache_key( $post_id );
170
+
171
+ $url = get_permalink( $post_id );
172
+
173
+ $options = array(
174
+ 'cache_key' => $transient_id,
175
+ 'post_id' => $post_id,
176
+ 'target_sns' => $this->target_sns
177
+ );
178
+
179
+ $this->cache( $options );
180
+ }
181
+ }
182
+ wp_reset_postdata();
183
+
184
+ }
185
+
186
+ /**
187
+ * Get and cache data for a given post
188
+ *
189
+ * @since 0.1.1
190
+ */
191
+ public function cache( $options = array() ) {
192
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
193
+
194
+ $transient_id = $options['cache_key'];
195
+ $target_sns = $options['target_sns'];
196
+ $post_id = $options['post_id'];
197
+
198
+ $sns_counts = array();
199
+
200
+ if ( $post_id !== 'home' ) {
201
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
202
+ foreach ( $target_sns as $sns => $active ) {
203
+ if ( $active ) {
204
+ $meta_key = $this->get_cache_key( $sns );
205
+
206
+ if ( $sns !== $this->crawl_date_key ) {
207
+
208
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] >= 0 ) {
209
+ update_post_meta( $post_id, $meta_key, (int) $sns_counts[$sns] );
210
+ } else {
211
+ update_post_meta( $post_id, $meta_key, (int) -1 );
212
+ }
213
+ } else {
214
+ if ( isset( $sns_counts[$sns] ) && $sns_counts[$sns] !== '' ) {
215
+ update_post_meta( $post_id, $meta_key, $sns_counts[$sns] );
216
+ } else {
217
+ update_post_meta( $post_id, $meta_key, '' );
218
+ }
219
+ }
220
+ }
221
+ }
222
+ }
223
+ } else {
224
+ if ( false !== ( $sns_counts = get_transient( $transient_id ) ) ) {
225
+
226
+ $option_key = $this->get_cache_key( 'home' );
227
+
228
+ foreach ( $target_sns as $sns => $active ) {
229
+ if ( $active ) {
230
+ if ( $sns !== $this->crawl_date_key ) {
231
+ if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] < 0 ) {
232
+ $sns_counts[$sns] = (int) -1;
233
+ }
234
+ } else {
235
+ if ( ! isset( $sns_counts[$sns] ) || $sns_counts[$sns] === '' ) {
236
+ $sns_counts[$sns] = '';
237
+ }
238
+ }
239
+ }
240
+ }
241
+
242
+ update_option( $option_key, $sns_counts );
243
+ }
244
+ }
245
+
246
+ $this->delegate_order( SCC_Order::ORDER_DO_ANALYSIS, $options );
247
+
248
+ }
249
+
250
+ /**
251
+ * Get cache expiration based on current number of total post and page
252
+ *
253
+ * @since 0.2.0
254
+ */
255
+ protected function get_cache_expiration() {
256
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
257
+
258
+ return 0;
259
+ }
260
+
261
+ /**
262
+ * Initialize meta key for ranking
263
+ *
264
+ * @since 0.3.0
265
+ */
266
+ public function initialize_cache() {
267
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
268
+
269
+ $option_key = $this->get_cache_key( 'home' );
270
+
271
+ $sns_counts = array();
272
+
273
+ foreach ( $this->target_sns as $sns => $active ) {
274
+ if ( $active ) {
275
+ $sns_counts[$sns] = (int) -1;
276
+ }
277
+ }
278
+
279
+ update_option( $option_key, $sns_counts );
280
+
281
+ $query_args = array(
282
+ 'post_type' => $this->post_types,
283
+ 'post_status' => 'publish',
284
+ 'nopaging' => true,
285
+ 'update_post_term_cache' => false,
286
+ 'update_post_meta_cache' => false
287
+ );
288
+
289
+ $posts_query = new WP_Query( $query_args );
290
+
291
+ if ( $posts_query->have_posts() ) {
292
+ while ( $posts_query->have_posts() ) {
293
+ $posts_query->the_post();
294
+
295
+ $post_id = get_the_ID();
296
+
297
+ foreach ( $this->target_sns as $sns => $active ) {
298
+ $meta_key = $this->get_cache_key( $sns );
299
+
300
+ if ( $active ) {
301
+ update_post_meta( $post_id, $meta_key, (int) -1 );
302
+ }
303
+ }
304
+ }
305
+ }
306
+ wp_reset_postdata();
307
+ }
308
+
309
+ /**
310
+ * Get cache
311
+ *
312
+ * @since 0.10.1
313
+ */
314
+ public function get_cache( $options = array() ) {
315
+ $post_id = $options['post_id'];
316
+ $sns_counts = array();
317
+
318
+ if ( $post_id !== 'home' ) {
319
+ foreach ( $this->target_sns as $sns => $active ) {
320
+ if ( $active ) {
321
+ $meta_key = $this->get_cache_key( $sns );
322
+ $sns_counts[$sns] = get_post_meta( $post_id, $meta_key, true );
323
+ }
324
+ }
325
+ } else {
326
+ $option_key = $this-->get_cache_key( 'home' );
327
+ $sns_counts = get_option( $option_key );
328
+ }
329
+ return $sns_counts;
330
+ }
331
+
332
+ /**
333
+ * Clear meta key for ranking
334
+ *
335
+ * @since 0.3.0
336
+ */
337
+ public function clear_cache() {
338
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
339
+
340
+ $option_key = $this->get_cache_key( 'home' );
341
+ delete_option( $option_key );
342
+
343
+ foreach ( $this->target_sns as $sns => $active ) {
344
+ if ( $active ) {
345
+ $meta_key = $this->get_cache_key( $sns );
346
+ delete_post_meta_by_key( $meta_key );
347
+ }
348
+ }
349
+ }
350
+
351
+ /**
352
+ * Clear meta key for ranking
353
+ *
354
+ * @since 0.7.0
355
+ */
356
+ public function clear_cache_by_post_id( $post_id ) {
357
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
358
+
359
+ foreach ( $this->target_sns as $sns => $active ) {
360
+ if ( $active ) {
361
+ $meta_key = $this->get_cache_key( $sns );
362
+ delete_post_meta( $post_id, $meta_key );
363
+ }
364
+ }
365
+
366
+ }
367
+
368
+ }
369
+
370
+ ?>
includes/class-scc-share-twitter-strategy.php CHANGED
@@ -1,162 +1,194 @@
1
- <?php
2
- /*
3
- class-scc-share-twitter-strategy.php
4
-
5
- Description: This class is abstract class of a data crawler
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_Share_Twitter_Strategy extends SCC_Crawl_Strategy {
31
-
32
- /**
33
- * SNS base url
34
- */
35
- const DEF_BASE_URL_JSOON = 'http://jsoon.digitiminimi.com/twitter/count.json';
36
-
37
- const DEF_BASE_URL_OPENSHARECOUNT = 'http://opensharecount.com/count.json';
38
-
39
- const DEF_BASE_URL_TWITCOUNT = 'http://opensharecount.com/count.json';
40
-
41
- /**
42
- * Class constarctor
43
- * Hook onto all of the actions and filters needed by the plugin.
44
- *
45
- */
46
- protected function __construct() {
47
- SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
48
- $this->method = 'GET';
49
- }
50
-
51
- /**
52
- * Initialization
53
- *
54
- * @since 0.9.0
55
- */
56
- public function initialize( $options = array() ) {
57
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
58
-
59
- if ( isset( $options['url'] ) ) $this->url = $options['url'];
60
- if ( isset( $options['method'] ) ) $this->method = $options['method'];
61
- if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
62
- if ( isset( $options['twitter_api'] ) ) $this->twitter_api = $options['twitter_api'];
63
- }
64
-
65
- /**
66
- * Build header
67
- *
68
- * @since 0.9.0
69
- */
70
- public function build_header() {
71
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
72
- return null;
73
- }
74
-
75
- /**
76
- * Build query url
77
- *
78
- * @since 0.9.0
79
- */
80
- public function build_query_url() {
81
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
82
-
83
- $base_url = self::DEF_BASE_URL_JSOON;
84
-
85
- if ( isset( $this->twitter_api ) && $this->twitter_api ) {
86
- if ( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_JSOON ) {
87
- $base_url = self::DEF_BASE_URL_JSOON;
88
- } elseif ( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_OPENSHARECOUNT ) {
89
- $base_url = self::DEF_BASE_URL_OPENSHARECOUNT;
90
- } elseif( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_TWITCOUNT ) {
91
- $base_url = self::DEF_BASE_URL_TWITCOUNT;
92
- }
93
- }
94
-
95
- $url = $base_url . '?' . http_build_query( $this->query_parameters , '' , '&' );
96
-
97
- return $url;
98
- }
99
-
100
- /**
101
- * Extract count
102
- *
103
- * @since 0.9.0
104
- */
105
- public function extract_count( $content ) {
106
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
107
-
108
- $count = (int) -1;
109
-
110
- if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
111
- $json = json_decode( $content['data'], true );
112
-
113
- if ( isset( $json['count'] ) && is_numeric( $json['count'] ) ) {
114
- $count = (int) $json['count'];
115
- } else {
116
- $count = (int) -1;
117
- }
118
- } else {
119
- $count = (int) -1;
120
- }
121
-
122
- return $count;
123
- }
124
-
125
- public function set_query_parameter( $key, $value ) {
126
- if ( isset( $this->twitter_api ) && $this->twitter_api ) {
127
- if ( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_JSOON ) {
128
- if ( $key === 'url' ) {
129
- if ( $value === home_url( '/', 'http' ) || $value === home_url( '/', 'https' ) ) {
130
- $this->query_parameters[$key] = '"' . $value . '"';
131
- } else {
132
- $this->query_parameters[$key] = $value;
133
- }
134
- } else {
135
- $this->query_parameters[$key] = $value;
136
- }
137
- } elseif ( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_OPENSHARECOUNT ) {
138
- $this->query_parameters[$key] = $value;
139
- } elseif( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_TWITCOUNT ) {
140
- $this->query_parameters[$key] = $value;
141
- }
142
- } else {
143
- $this->query_parameters[$key] = $value;
144
- }
145
- }
146
-
147
- /**
148
- * Check if required paramters are included or not.
149
- *
150
- * @since 0.9.0
151
- */
152
- public function check_configuration() {
153
- SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
154
-
155
- if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
156
- return true;
157
- } else {
158
- return false;
159
- }
160
- }
161
-
162
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-share-twitter-strategy.php
4
+
5
+ Description: This class is abstract class of a data crawler
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_Share_Twitter_Strategy extends SCC_Crawl_Strategy {
31
+
32
+ /**
33
+ * SNS base url (widgetoon.js & count.jsoon)
34
+ * @var string
35
+ */
36
+ const DEF_BASE_URL_JSOON = 'http://jsoon.digitiminimi.com/twitter/count.json';
37
+
38
+ /**
39
+ * SNS base url (OpenShareCount)
40
+ * @var string
41
+ */
42
+ const DEF_BASE_URL_OPENSHARECOUNT = 'http://opensharecount.com/count.json';
43
+
44
+ /**
45
+ * SNS base url (TwitCount)
46
+ * @var string
47
+ */
48
+ const DEF_BASE_URL_TWITCOUNT = 'http://counts.twitcount.com/counts.php';
49
+
50
+ /**
51
+ * SNS base url (NewShareCounts)
52
+ * @var string
53
+ */
54
+ const DEF_BASE_URL_NEWSHARECOUNTS = 'http://public.newsharecounts.com/count.json';
55
+
56
+ /**
57
+ * Class constarctor
58
+ * Hook onto all of the actions and filters needed by the plugin.
59
+ *
60
+ */
61
+ protected function __construct() {
62
+ SCC_Common_Util::log('[' . __METHOD__ . '] (line='. __LINE__ . ')');
63
+ $this->method = 'GET';
64
+ }
65
+
66
+ /**
67
+ * Initialization
68
+ * @since 0.9.0
69
+ * @param array $options Option for this strategy
70
+ * @return null There is no return.
71
+ */
72
+ public function initialize( $options = array() ) {
73
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
74
+
75
+ if ( isset( $options['url'] ) ) $this->url = $options['url'];
76
+ if ( isset( $options['method'] ) ) $this->method = $options['method'];
77
+ if ( isset( $options['parameters'] ) ) $this->parameters = $options['parameters'];
78
+ if ( isset( $options['twitter_api'] ) ) $this->twitter_api = $options['twitter_api'];
79
+ }
80
+
81
+ /**
82
+ * Build header
83
+ * @since 0.9.0
84
+ * @return null no need to build header for Twitter share count retrieval.
85
+ */
86
+ public function build_header() {
87
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
88
+ return null;
89
+ }
90
+
91
+ /**
92
+ * Build query URL
93
+ * @since 0.9.0
94
+ * @return string Query URL
95
+ */
96
+ public function build_query_url() {
97
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
98
+
99
+ $base_url = self::DEF_BASE_URL_JSOON;
100
+
101
+ if ( isset( $this->twitter_api ) && $this->twitter_api ) {
102
+ if ( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_JSOON ) {
103
+ $base_url = self::DEF_BASE_URL_JSOON;
104
+ } elseif ( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_OPENSHARECOUNT ) {
105
+ $base_url = self::DEF_BASE_URL_OPENSHARECOUNT;
106
+ } elseif( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_TWITCOUNT ) {
107
+ $base_url = self::DEF_BASE_URL_TWITCOUNT;
108
+ } elseif( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_NEWSHARECOUNTS ) {
109
+ $base_url = self::DEF_BASE_URL_NEWSHARECOUNTS;
110
+ }
111
+ }
112
+
113
+ $url = $base_url . '?' . http_build_query( $this->query_parameters , '' , '&' );
114
+
115
+ return $url;
116
+ }
117
+
118
+ /**
119
+ * Extract count
120
+ * @since 0.9.0
121
+ * @param string $content Target content
122
+ * @return int SNS count
123
+ */
124
+ public function extract_count( $content ) {
125
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
126
+
127
+ $count = (int) -1;
128
+
129
+ if ( isset( $content['data'] ) && empty( $content['error'] ) ) {
130
+ $json = json_decode( $content['data'], true );
131
+
132
+ if ( isset( $json['count'] ) && is_numeric( $json['count'] ) ) {
133
+ $count = (int) $json['count'];
134
+ } else {
135
+ $count = (int) -1;
136
+ }
137
+ } else {
138
+ $count = (int) -1;
139
+ }
140
+
141
+ return $count;
142
+ }
143
+
144
+ /**
145
+ * Setter of query parameters
146
+ * @param string $key key
147
+ * @param string $value value
148
+ */
149
+ public function set_query_parameter( $key, $value ) {
150
+ if ( isset( $this->twitter_api ) && $this->twitter_api ) {
151
+ if ( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_JSOON ) {
152
+ if ( $key === 'url' ) {
153
+ if ( $value === home_url( '/', 'http' ) || $value === home_url( '/', 'https' ) ) {
154
+ $this->query_parameters[$key] = '"' . $value . '"';
155
+ } else {
156
+ $this->query_parameters[$key] = $value;
157
+ }
158
+ }
159
+ } elseif ( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_OPENSHARECOUNT ) {
160
+ if ( $key === 'url' ) {
161
+ $this->query_parameters[$key] = $value;
162
+ }
163
+ } elseif( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_TWITCOUNT ) {
164
+ if ( $key === 'url' ) {
165
+ $this->query_parameters[$key] = $value;
166
+ }
167
+ } elseif ( $this->twitter_api === SNS_Count_Cache::OPT_SHARE_TWITTER_API_NEWSHARECOUNTS ) {
168
+ if ( $key === 'url' ) {
169
+ $this->query_parameters[$key] = $value;
170
+ }
171
+ }
172
+ } else {
173
+ if ( $key === 'url' ) {
174
+ $this->query_parameters[$key] = $value;
175
+ }
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Check if required paramters are included or not.
181
+ * @since 0.9.0
182
+ * @return boolean Check result
183
+ */
184
+ public function check_configuration() {
185
+ SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
186
+
187
+ if ( isset( $this->query_parameters['url'] ) && $this->query_parameters['url'] ) {
188
+ return true;
189
+ } else {
190
+ return false;
191
+ }
192
+ }
193
+
194
+ }
includes/class-scc-sleep-throttle.php CHANGED
@@ -1,124 +1,124 @@
1
- <?php
2
- /*
3
- class-scc-sleep-throttle.php
4
-
5
- Description: sleep utility
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
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- final class SCC_Sleep_Throttle {
31
-
32
- /*
33
- *
34
- */
35
- const SECOND_TO_MICRO_SECONDS = 1000000;
36
-
37
- /*
38
- *
39
- */
40
- private $load_ratio = 0.9;
41
-
42
- /*
43
- *
44
- */
45
- private $start_time = null;
46
-
47
- /*
48
- *
49
- */
50
- private $stop_time = null;
51
-
52
- /*
53
- *
54
- */
55
- private $sleep_time = null;
56
-
57
- /*
58
- *
59
- */
60
- function __construct( $load_ratio ) {
61
- $this->load_ratio = $load_ratio;
62
- }
63
-
64
- /*
65
- *
66
- */
67
- public function reset() {
68
- $this->start_time = null;
69
- $this->stop_time = null;
70
- $this->sleep_time = null;
71
- }
72
-
73
- /*
74
- *
75
- */
76
- public function start() {
77
- $this->start_time = gettimeofday( true );
78
- }
79
-
80
- /*
81
- *
82
- */
83
- public function stop() {
84
- $this->stop_time = gettimeofday( true );
85
-
86
- if ( ! is_null( $this->start_time ) && ! is_null( $this->stop_time ) ) {
87
- $this->sleep_time = $this->calculate_sleep_time( $this->load_ratio, $this->stop_time - $this->start_time );
88
- }
89
- }
90
-
91
- /*
92
- *
93
- */
94
- public function sleep() {
95
- if ( ! is_null( $this->sleep_time) && $this->sleep_time > 0 ) {
96
- usleep( $this->sleep_time * self::SECOND_TO_MICRO_SECONDS );
97
- }
98
- }
99
-
100
- /*
101
- *
102
- */
103
- public function get_sleep_time() {
104
- if ( ! is_null( $this->sleep_time) && $this->sleep_time > 0 ) {
105
- return $this->sleep_time;
106
- } else {
107
- return 0;
108
- }
109
- }
110
-
111
- /*
112
- *
113
- */
114
- private function calculate_sleep_time( $load_ratio, $time ) {
115
- if ( $time > 0.0 ) {
116
- return $time * ( 1 - $load_ratio ) / $load_ratio;
117
- } else {
118
- return 0;
119
- }
120
- }
121
-
122
- }
123
-
124
- ?>
1
+ <?php
2
+ /*
3
+ class-scc-sleep-throttle.php
4
+
5
+ Description: sleep utility
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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ final class SCC_Sleep_Throttle {
31
+
32
+ /*
33
+ *
34
+ */
35
+ const SECOND_TO_MICRO_SECONDS = 1000000;
36
+
37
+ /*
38
+ *
39
+ */
40
+ private $load_ratio = 0.9;
41
+
42
+ /*
43
+ *
44
+ */
45
+ private $start_time = null;
46
+
47
+ /*
48
+ *
49
+ */
50
+ private $stop_time = null;
51
+
52
+ /*
53
+ *
54
+ */
55
+ private $sleep_time = null;
56
+
57
+ /*
58
+ *
59
+ */
60
+ function __construct( $load_ratio ) {
61
+ $this->load_ratio = $load_ratio;
62
+ }
63
+
64
+ /*
65
+ *
66
+ */
67
+ public function reset() {
68
+ $this->start_time = null;
69
+ $this->stop_time = null;
70
+ $this->sleep_time = null;
71
+ }
72
+
73
+ /*
74
+ *
75
+ */
76
+ public function start() {
77
+ $this->start_time = gettimeofday( true );
78
+ }
79
+
80
+ /*
81
+ *
82
+ */
83
+ public function stop() {
84
+ $this->stop_time = gettimeofday( true );
85
+
86
+ if ( ! is_null( $this->start_time ) && ! is_null( $this->stop_time ) ) {
87
+ $this->sleep_time = $this->calculate_sleep_time( $this->load_ratio, $this->stop_time - $this->start_time );
88
+ }
89
+ }
90
+
91
+ /*
92
+ *
93
+ */
94
+ public function sleep() {
95
+ if ( ! is_null( $this->sleep_time) && $this->sleep_time > 0 ) {
96
+ usleep( $this->sleep_time * self::SECOND_TO_MICRO_SECONDS );
97
+ }
98
+ }
99
+
100
+ /*
101
+ *
102
+ */
103
+ public function get_sleep_time() {
104
+ if ( ! is_null( $this->sleep_time) && $this->sleep_time > 0 ) {
105
+ return $this->sleep_time;
106
+ } else {
107
+ return 0;
108
+ }
109
+ }
110
+
111
+ /*
112
+ *
113
+ */
114
+ private function calculate_sleep_time( $load_ratio, $time ) {
115
+ if ( $time > 0.0 ) {
116
+ return $time * ( 1 - $load_ratio ) / $load_ratio;
117
+ } else {
118
+ return 0;
119
+ }
120
+ }
121
+
122
+ }
123
+
124
+ ?>
includes/class-scc-wp-cron-util.php CHANGED
@@ -1,267 +1,317 @@
1
- <?php
2
- /*
3
- class-scc-wp-cron-util.php
4
-
5
- Description: This class is a utility for WP-Cron
6
- Author: Daisuke Maruyama
7
- Author URI: http://marubon.info/
8
- License: GPL2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
- */
11
-
12
- /*
13
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- class SCC_WP_Cron_Util {
31
-
32
- /**
33
- * Class constarctor
34
- * Hook onto all of the actions and filters needed by the plugin.
35
- *
36
- */
37
- protected function __construct() {
38
-
39
- }
40
-
41
-
42
- /**
43
- * Clear expired scheduled hook based related to specified hook name
44
- *
45
- * @since 0.4.1
46
- */
47
- public static function clear_expired_scheduled_hook( $hook, $elapsed_time ) {
48
- $crons = _get_cron_array();
49
-
50
- if ( empty( $crons ) ) {
51
- return;
52
- }
53
-
54
- $current_time = (int) current_time( 'timestamp', 1 );
55
-
56
- foreach( $crons as $timestamp => $cron ) {
57
- if ( isset( $cron[$hook] ) ) {
58
- $duration = $current_time - $timestamp;
59
-
60
- if ( $duration > $elapsed_time ) {
61
- foreach ( $cron[$hook] as $signature => $data ) {
62
- wp_unschedule_event( $timestamp, $hook, $data['args'] );
63
- }
64
- }
65
- }
66
- }
67
- }
68
-
69
-
70
- /**
71
- * Clear scheduled hook based related to specified hook name
72
- *
73
- * @since 0.1.1
74
- */
75
- public static function clear_scheduled_hook( $hook ) {
76
- $crons = _get_cron_array();
77
-
78
- if ( empty( $crons ) ) return;
79
-
80
- foreach( $crons as $timestamp => $cron ) {
81
- if ( isset( $cron[$hook] ) ) {
82
- foreach ( $cron[$hook] as $signature => $data ) {
83
- wp_unschedule_event( $timestamp, $hook, $data['args'] );
84
- }
85
- }
86
- }
87
- }
88
-
89
- /**
90
- * Return if there is the given hook or not
91
- *
92
- * @since 0.1.1
93
- */
94
- public static function is_scheduled_hook( $hook ) {
95
- $crons = _get_cron_array();
96
-
97
- if ( empty( $crons ) ) return false;
98
-
99
- foreach( $crons as $timestamp => $cron ) {
100
- if ( isset( $cron[$hook] ) ) {
101
- return true;
102
- }
103
- }
104
-
105
- return false;
106
- }
107
-
108
- /**
109
- * Get scheduled hook related to specified hook name
110
- *
111
- * @since 0.1.1
112
- */
113
- public static function get_scheduled_hook( $hook ) {
114
- //SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
115
-
116
- $crons = _get_cron_array();
117
-
118
- $info = array();
119
- $index = 0;
120
-
121
- if ( empty( $crons ) ) return;
122
-
123
- foreach( $crons as $timestamp => $cron ) {
124
- if ( isset( $cron[$hook] ) ) {
125
- //SCC_Common_Util::log( $cron[$hook] );
126
- foreach ( $cron[$hook] as $signature => $data ) {
127
-
128
- //SCC_Common_Util::log( '[' . __METHOD__ . '] hook: ' . $hook . ' offset: ' . $data['args'][0]. ' timestamp: ' . $timestamp );
129
-
130
- $info[$index]['hook'] = $hook;
131
- $info[$index]['timestamp'] = $timestamp;
132
- $info[$index]['args'] = $data['args'];
133
- //wp_unschedule_event( $timestamp, $hook, $data['args'] );
134
- }
135
- $index++;
136
- }
137
- }
138
-
139
- return $info;
140
- }
141
-
142
- /**
143
- *
144
- * Get the local time timestamp of the next cron execution
145
- * This code is cited from wordpress plugin BackWPup
146
- *
147
- * @param string $cronstring cron (* * * * *)
148
- * @return int timestamp
149
- */
150
- public static function next_exec_time( $cronstring ) {
151
- $cron = array();
152
- $cronarray = array();
153
- //Cron string
154
- list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ', trim( $cronstring ), 5 );
155
-
156
- //make arrays form string
157
- foreach ( $cronstr as $key => $value ) {
158
- if ( strstr( $value, ',' ) ) {
159
- $cronarray[ $key ] = explode( ',', $value );
160
- } else {
161
- $cronarray[ $key ] = array( 0 => $value );
162
- }
163
- }
164
-
165
- //make arrays complete with ranges and steps
166
- foreach ( $cronarray as $cronarraykey => $cronarrayvalue ) {
167
- $cron[ $cronarraykey ] = array();
168
- foreach ( $cronarrayvalue as $value ) {
169
- //steps
170
- $step = 1;
171
- if ( strstr( $value, '/' ) ) {
172
- list( $value, $step ) = explode( '/', $value, 2 );
173
- }
174
- //replace weekday 7 with 0 for sundays
175
- if ( $cronarraykey === 'wday' ) {
176
- $value = str_replace( '7', '0', $value );
177
- }
178
- //ranges
179
- if ( strstr( $value, '-' ) ) {
180
- list( $first, $last ) = explode( '-', $value, 2 );
181
- if ( ! is_numeric( $first ) || ! is_numeric( $last ) || $last > 60 || $first > 60 ) { //check
182
- return PHP_INT_MAX;
183
- }
184
- if ( $cronarraykey === 'minutes' && $step < 5 ) { //set step minimum to 5 min.
185
- $step = 5;
186
- }
187
- $range = array();
188
- for ( $i = $first; $i <= $last; $i = $i + $step ) {
189
- $range[ ] = $i;
190
- }
191
- $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], $range );
192
- }
193
- elseif ( $value === '*' ) {
194
- $range = array();
195
- if ( $cronarraykey === 'minutes' ) {
196
- if ( $step < 10 ) { //set step minimum to 5 min.
197
- $step = 10;
198
- }
199
- for ( $i = 0; $i <= 59; $i = $i + $step ) {
200
- $range[ ] = $i;
201
- }
202
- }
203
- if ( $cronarraykey === 'hours' ) {
204
- for ( $i = 0; $i <= 23; $i = $i + $step ) {
205
- $range[ ] = $i;
206
- }
207
- }
208
- if ( $cronarraykey === 'mday' ) {
209
- for ( $i = $step; $i <= 31; $i = $i + $step ) {
210
- $range[ ] = $i;
211
- }
212
- }
213
- if ( $cronarraykey === 'mon' ) {
214
- for ( $i = $step; $i <= 12; $i = $i + $step ) {
215
- $range[ ] = $i;
216
- }
217
- }
218
- if ( $cronarraykey === 'wday' ) {
219
- for ( $i = 0; $i <= 6; $i = $i + $step ) {
220
- $range[ ] = $i;
221
- }
222
- }
223
- $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], $range );
224
- }
225
- else {
226
- if ( ! is_numeric( $value ) || (int) $value > 60 ) {
227
- return PHP_INT_MAX;
228
- }
229
- $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], array( 0 => absint( $value ) ) );
230
- }
231
- }
232
- }
233
-
234
- //generate years
235
- $year = (int) gmdate( 'Y' );
236
- for ( $i = $year; $i < $year + 100; $i ++ ) {
237
- $cron[ 'year' ][ ] = $i;
238
- }
239
-
240
- //calc next timestamp
241
- $current_timestamp = (int) current_time( 'timestamp' );
242
- foreach ( $cron[ 'year' ] as $year ) {
243
- foreach ( $cron[ 'mon' ] as $mon ) {
244
- foreach ( $cron[ 'mday' ] as $mday ) {
245
- if ( ! checkdate( $mon, $mday, $year ) ) {
246
- continue;
247
- }
248
- foreach ( $cron[ 'hours' ] as $hours ) {
249
- foreach ( $cron[ 'minutes' ] as $minutes ) {
250
- $timestamp = gmmktime( $hours, $minutes, 0, $mon, $mday, $year );
251
- if ( $timestamp && in_array( (int) gmdate( 'j', $timestamp ), $cron[ 'mday' ], true ) && in_array( (int) gmdate( 'w', $timestamp ), $cron[ 'wday' ], true ) && $timestamp > $current_timestamp ) {
252
- return $timestamp - ( (int) get_option( 'gmt_offset' ) * 3600 );
253
- }
254
- }
255
- }
256
- }
257
- }
258
- }
259
-
260
- return PHP_INT_MAX;
261
- }
262
-
263
- }
264
-
265
-
266
-
267
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ class-scc-wp-cron-util.php
4
+
5
+ Description: This class is a utility for WP-Cron
6
+ Author: Daisuke Maruyama
7
+ Author URI: http://marubon.info/
8
+ License: GPL2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
10
+ */
11
+
12
+ /*
13
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ class SCC_WP_Cron_Util {
31
+
32
+ /**
33
+ * Class constarctor
34
+ * Hook onto all of the actions and filters needed by the plugin.
35
+ *
36
+ */
37
+ protected function __construct() {
38
+
39
+ }
40
+
41
+
42
+ /**
43
+ * Clear expired scheduled hook based related to specified hook name
44
+ *
45
+ * @since 0.4.1
46
+ */
47
+ public static function clear_expired_scheduled_hook( $hook, $elapsed_time ) {
48
+ $crons = _get_cron_array();
49
+
50
+ if ( empty( $crons ) ) {
51
+ return;
52
+ }
53
+
54
+ $current_time = (int) current_time( 'timestamp', 1 );
55
+
56
+ foreach( $crons as $timestamp => $cron ) {
57
+ if ( isset( $cron[$hook] ) ) {
58
+ $duration = $current_time - $timestamp;
59
+
60
+ if ( $duration > $elapsed_time ) {
61
+ foreach ( $cron[$hook] as $signature => $data ) {
62
+ wp_unschedule_event( $timestamp, $hook, $data['args'] );
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+
70
+ /**
71
+ * Clear scheduled hook based related to specified hook name
72
+ *
73
+ * @since 0.1.1
74
+ */
75
+ public static function clear_scheduled_hook( $hook ) {
76
+ $crons = _get_cron_array();
77
+
78
+ if ( empty( $crons ) ) return;
79
+
80
+ foreach( $crons as $timestamp => $cron ) {
81
+ if ( isset( $cron[$hook] ) ) {
82
+ foreach ( $cron[$hook] as $signature => $data ) {
83
+ wp_unschedule_event( $timestamp, $hook, $data['args'] );
84
+ }
85
+ }
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Return if there is the given hook or not
91
+ *
92
+ * @since 0.1.1
93
+ */
94
+ public static function is_scheduled_hook( $hook ) {
95
+ $crons = _get_cron_array();
96
+
97
+ if ( empty( $crons ) ) return false;
98
+
99
+ foreach( $crons as $timestamp => $cron ) {
100
+ if ( isset( $cron[$hook] ) ) {
101
+ return true;
102
+ }
103
+ }
104
+
105
+ return false;
106
+ }
107
+
108
+ /**
109
+ * Get scheduled hook related to specified hook name
110
+ *
111
+ * @since 0.1.1
112
+ */
113
+ public static function get_scheduled_hook( $hook ) {
114
+ //SCC_Common_Util::log( '[' . __METHOD__ . '] (line='. __LINE__ . ')' );
115
+
116
+ $crons = _get_cron_array();
117
+
118
+ $info = array();
119
+ $index = 0;
120
+
121
+ if ( empty( $crons ) ) return;
122
+
123
+ foreach( $crons as $timestamp => $cron ) {
124
+ if ( isset( $cron[$hook] ) ) {
125
+ //SCC_Common_Util::log( $cron[$hook] );
126
+ foreach ( $cron[$hook] as $signature => $data ) {
127
+
128
+ //SCC_Common_Util::log( '[' . __METHOD__ . '] hook: ' . $hook . ' offset: ' . $data['args'][0]. ' timestamp: ' . $timestamp );
129
+
130
+ $info[$index]['hook'] = $hook;
131
+ $info[$index]['timestamp'] = $timestamp;
132
+ $info[$index]['args'] = $data['args'];
133
+ //wp_unschedule_event( $timestamp, $hook, $data['args'] );
134
+ }
135
+ $index++;
136
+ }
137
+ }
138
+
139
+ return $info;
140
+ }
141
+
142
+ /**
143
+ *
144
+ * Get the local time timestamp of the next cron execution
145
+ * This code is cited from wordpress plugin BackWPup
146
+ *
147
+ * @param string $cronstring cron (* * * * *)
148
+ * @return int timestamp
149
+ */
150
+ public static function next_exec_time( $cronstring ) {
151
+ $cron = array();
152
+ $cronarray = array();
153
+ //Cron string
154
+ list( $cronstr[ 'minutes' ], $cronstr[ 'hours' ], $cronstr[ 'mday' ], $cronstr[ 'mon' ], $cronstr[ 'wday' ] ) = explode( ' ', trim( $cronstring ), 5 );
155
+
156
+ //make arrays form string
157
+ foreach ( $cronstr as $key => $value ) {
158
+ if ( strstr( $value, ',' ) ) {
159
+ $cronarray[ $key ] = explode( ',', $value );
160
+ } else {
161
+ $cronarray[ $key ] = array( 0 => $value );
162
+ }
163
+ }
164
+
165
+ //make arrays complete with ranges and steps
166
+ foreach ( $cronarray as $cronarraykey => $cronarrayvalue ) {
167
+ $cron[ $cronarraykey ] = array();
168
+ foreach ( $cronarrayvalue as $value ) {
169
+ //steps
170
+ $step = 1;
171
+ if ( strstr( $value, '/' ) ) {
172
+ list( $value, $step ) = explode( '/', $value, 2 );
173
+ }
174
+ //replace weekday 7 with 0 for sundays
175
+ if ( $cronarraykey === 'wday' ) {
176
+ $value = str_replace( '7', '0', $value );
177
+ }
178
+ //ranges
179
+ if ( strstr( $value, '-' ) ) {
180
+ list( $first, $last ) = explode( '-', $value, 2 );
181
+ if ( ! is_numeric( $first ) || ! is_numeric( $last ) || $last > 60 || $first > 60 ) { //check
182
+ return PHP_INT_MAX;
183
+ }
184
+ if ( $cronarraykey === 'minutes' && $step < 5 ) { //set step minimum to 5 min.
185
+ $step = 5;
186
+ }
187
+ $range = array();
188
+ for ( $i = $first; $i <= $last; $i = $i + $step ) {
189
+ $range[ ] = $i;
190
+ }
191
+ $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], $range );
192
+ }
193
+ elseif ( $value === '*' ) {
194
+ $range = array();
195
+ if ( $cronarraykey === 'minutes' ) {
196
+ if ( $step < 10 ) { //set step minimum to 5 min.
197
+ $step = 10;
198
+ }
199
+ for ( $i = 0; $i <= 59; $i = $i + $step ) {
200
+ $range[ ] = $i;
201
+ }
202
+ }
203
+ if ( $cronarraykey === 'hours' ) {
204
+ for ( $i = 0; $i <= 23; $i = $i + $step ) {
205
+ $range[ ] = $i;
206
+ }
207
+ }
208
+ if ( $cronarraykey === 'mday' ) {
209
+ for ( $i = $step; $i <= 31; $i = $i + $step ) {
210
+ $range[ ] = $i;
211
+ }
212
+ }
213
+ if ( $cronarraykey === 'mon' ) {
214
+ for ( $i = $step; $i <= 12; $i = $i + $step ) {
215
+ $range[ ] = $i;
216
+ }
217
+ }
218
+ if ( $cronarraykey === 'wday' ) {
219
+ for ( $i = 0; $i <= 6; $i = $i + $step ) {
220
+ $range[ ] = $i;
221
+ }
222
+ }
223
+ $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], $range );
224
+ }
225
+ else {
226
+ if ( ! is_numeric( $value ) || (int) $value > 60 ) {
227
+ return PHP_INT_MAX;
228
+ }
229
+ $cron[ $cronarraykey ] = array_merge( $cron[ $cronarraykey ], array( 0 => absint( $value ) ) );
230
+ }
231
+ }
232
+ }
233
+
234
+ //generate years
235
+ $year = (int) gmdate( 'Y' );
236
+ for ( $i = $year; $i < $year + 100; $i ++ ) {
237
+ $cron[ 'year' ][ ] = $i;
238
+ }
239
+
240
+ //calc next timestamp
241
+ $current_timestamp = (int) current_time( 'timestamp' );
242
+ foreach ( $cron[ 'year' ] as $year ) {
243
+ foreach ( $cron[ 'mon' ] as $mon ) {
244
+ foreach ( $cron[ 'mday' ] as $mday ) {
245
+ if ( ! checkdate( $mon, $mday, $year ) ) {
246
+ continue;
247
+ }
248
+ foreach ( $cron[ 'hours' ] as $hours ) {
249
+ foreach ( $cron[ 'minutes' ] as $minutes ) {
250
+ $timestamp = gmmktime( $hours, $minutes, 0, $mon, $mday, $year );
251
+ if ( $timestamp && in_array( (int) gmdate( 'j', $timestamp ), $cron[ 'mday' ], true ) && in_array( (int) gmdate( 'w', $timestamp ), $cron[ 'wday' ], true ) && $timestamp > $current_timestamp ) {
252
+ return $timestamp - ( (int) get_option( 'gmt_offset' ) * 3600 );
253
+ }
254
+ }
255
+ }
256
+ }
257
+ }
258
+ }
259
+
260
+ return PHP_INT_MAX;
261
+ }
262
+
263
+ /**
264
+ * Gets the status of WP-Cron functionality on the site by performing a test spawn. Cached for one hour when all is well.
265
+ * This code is cited from wordpress plugin WP Crontrol
266
+ */
267
+ public static function test_cron_spawn( $cache = true ) {
268
+ global $wp_version;
269
+
270
+ if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
271
+ return new WP_Error( 'scc_wp_cron_info', sprintf( __( 'The %s constant is set to true. WP-Cron spawning is disabled.', 'wp-crontrol' ), 'DISABLE_WP_CRON' ) );
272
+ }
273
+
274
+ if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
275
+ return new WP_Error( 'scc_wp_cron_info', sprintf( __( 'The %s constant is set to true.', 'wp-crontrol' ), 'ALTERNATE_WP_CRON' ) );
276
+ }
277
+
278
+ $cached_status = get_transient( 'scc_wp_cron_test' );
279
+
280
+ if ( $cache && $cached_status ) {
281
+ return true;
282
+ }
283
+
284
+ $sslverify = version_compare( $wp_version, 4.0, '<' );
285
+ $doing_wp_cron = sprintf( '%.22F', microtime( true ) );
286
+
287
+ $cron_request = apply_filters( 'cron_request', array(
288
+ 'url' => site_url( 'wp-cron.php?doing_wp_cron=' . $doing_wp_cron ),
289
+ 'key' => $doing_wp_cron,
290
+ 'args' => array(
291
+ 'timeout' => 3,
292
+ 'blocking' => true,
293
+ 'sslverify' => apply_filters( 'https_local_ssl_verify', $sslverify ),
294
+ ),
295
+ ) );
296
+
297
+ $cron_request['args']['blocking'] = true;
298
+
299
+ $result = wp_remote_post( $cron_request['url'], $cron_request['args'] );
300
+
301
+ if ( is_wp_error( $result ) ) {
302
+ return $result;
303
+ } else if ( wp_remote_retrieve_response_code( $result ) >= 300 ) {
304
+ return new WP_Error( 'unexpected_http_response_code', sprintf(
305
+ __( 'Unexpected HTTP response code: %s', 'wp-crontrol' ),
306
+ intval( wp_remote_retrieve_response_code( $result ) )
307
+ ) );
308
+ } else {
309
+ set_transient( 'scc_wp_cron_test', 1, 3600 );
310
+ return true;
311
+ }
312
+
313
+ }
314
+
315
+ }
316
+
317
+ ?>
includes/download.php CHANGED
@@ -1,75 +1,75 @@
1
- <?php
2
- /*
3
- download.php
4
-
5
- Description: Download 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
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- require_once( '../../../../wp-load.php' );
31
-
32
- if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
33
-
34
- $abs_path = WP_PLUGIN_DIR . '/sns-count-cache/data/sns-count-cache-data.csv';
35
-
36
- if ( current_user_can( 'manage_options' ) ) {
37
- if ( isset( $_POST['_wpnonce'] ) && $_POST['_wpnonce'] && check_admin_referer( 'download', '_wpnonce' ) ) {
38
- if ( isset( $_POST["download_data"] ) && $_POST["download_data"] === __( 'Download', SNS_Count_Cache::DOMAIN ) ) {
39
- if ( file_exists( $abs_path ) ) {
40
- $file_name = "sns-count-cache_data_" . date_i18n( 'YmdHis' ) . ".csv";
41
-
42
- $size = filesize( $abs_path );
43
- header( 'Content-Length: ' . $size );
44
- header( 'Content-Disposition: attachment; filename="' . $file_name . '"' );
45
- header( 'Content-Transfer-Encoding: binary' );
46
- header( 'Content-Type: application/octet-stream' );
47
-
48
- while ( ob_get_level() > 0 ) {
49
- ob_end_clean();
50
- }
51
-
52
- ob_start();
53
- if ( $fp = fopen( $abs_path, 'rb' ) ) {
54
- while( ! feof( $fp ) && ( connection_status() == 0 ) ) {
55
- echo fread( $fp, 8192 );
56
- ob_flush();
57
- }
58
-
59
- ob_flush();
60
- fclose( $fp );
61
- }
62
- ob_end_clean();
63
- } else {
64
- echo 'There is no exported file.';
65
- }
66
- }
67
- } else {
68
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
69
- }
70
- } else {
71
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
72
- }
73
- die();
74
-
75
- ?>
1
+ <?php
2
+ /*
3
+ download.php
4
+
5
+ Description: Download 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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ require_once( '../../../../wp-load.php' );
31
+
32
+ if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
33
+
34
+ $abs_path = WP_PLUGIN_DIR . '/sns-count-cache/data/sns-count-cache-data.csv';
35
+
36
+ if ( current_user_can( 'manage_options' ) ) {
37
+ if ( isset( $_POST['_wpnonce'] ) && $_POST['_wpnonce'] && check_admin_referer( 'download', '_wpnonce' ) ) {
38
+ if ( isset( $_POST["download_data"] ) && $_POST["download_data"] === __( 'Download', SNS_Count_Cache::DOMAIN ) ) {
39
+ if ( file_exists( $abs_path ) ) {
40
+ $file_name = "sns-count-cache_data_" . date_i18n( 'YmdHis' ) . ".csv";
41
+
42
+ $size = filesize( $abs_path );
43
+ header( 'Content-Length: ' . $size );
44
+ header( 'Content-Disposition: attachment; filename="' . $file_name . '"' );
45
+ header( 'Content-Transfer-Encoding: binary' );
46
+ header( 'Content-Type: application/octet-stream' );
47
+
48
+ while ( ob_get_level() > 0 ) {
49
+ ob_end_clean();
50
+ }
51
+
52
+ ob_start();
53
+ if ( $fp = fopen( $abs_path, 'rb' ) ) {
54
+ while( ! feof( $fp ) && ( connection_status() == 0 ) ) {
55
+ echo fread( $fp, 8192 );
56
+ ob_flush();
57
+ }
58
+
59
+ ob_flush();
60
+ fclose( $fp );
61
+ }
62
+ ob_end_clean();
63
+ } else {
64
+ echo 'There is no exported file.';
65
+ }
66
+ }
67
+ } else {
68
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
69
+ }
70
+ } else {
71
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
72
+ }
73
+ die();
74
+
75
+ ?>
includes/interface-scc-order.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- /*
3
- interface-scc-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
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- interface SCC_Order {
31
-
32
- const ORDER_DO_SECOND_CACHE = 'do_second_cache';
33
-
34
- const ORDER_GET_SECOND_CACHE = 'get_second_cache';
35
-
36
- const ORDER_DO_ANALYSIS = 'do_analysis';
37
-
38
- public function order( SCC_Cache_Engine $engine, $order, $options = array() );
39
- }
40
-
41
- ?>
1
+ <?php
2
+ /*
3
+ interface-scc-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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ interface SCC_Order {
31
+
32
+ const ORDER_DO_SECOND_CACHE = 'do_second_cache';
33
+
34
+ const ORDER_GET_SECOND_CACHE = 'get_second_cache';
35
+
36
+ const ORDER_DO_ANALYSIS = 'do_analysis';
37
+
38
+ public function order( SCC_Cache_Engine $engine, $order, $options = array() );
39
+ }
40
+
41
+ ?>
index.php CHANGED
@@ -1,58 +1,62 @@
1
- <?php
2
- /*
3
- index.php
4
-
5
- Description:
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
- Copyright (C) 2014 - 2016 Daisuke Maruyama
14
-
15
- This program is free software; you can redistribute it and/or
16
- modify it under the terms of the GNU General Public License
17
- as published by the Free Software Foundation; either version 2
18
- of the License, or (at your option) any later version.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
- */
29
-
30
- require_once( '../../../wp-load.php' );
31
-
32
- if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
33
-
34
- if ( current_user_can( 'manage_options' ) ) {
35
- if ( isset( $_GET['state'] ) && $_GET['state'] && isset( $_GET['action'] ) && $_GET['action'] && isset( $_GET['code'] ) && $_GET['code'] ) {
36
- if ( $_GET['action'] === 'instagram-auth' ) {
37
- if ( check_admin_referer( 'instagram-auth', 'state' ) ) {
38
- $redirect_url = admin_url( 'admin.php?page=scc-setting' ) . '&action=instagram-auth&code=' . $_GET['code'] .'&_wpnonce=' . $_GET['state'];
39
- wp_safe_redirect( $redirect_url );
40
- exit;
41
- }
42
- } elseif ( $_GET['action'] === 'facebook-auth' ) {
43
- if ( check_admin_referer( 'facebook-auth', 'state' ) ) {
44
- $redirect_url = admin_url( 'admin.php?page=scc-setting' ) . '&action=facebook-auth&code=' . $_GET['code'] .'&_wpnonce=' . $_GET['state'];
45
- wp_safe_redirect( $redirect_url );
46
- exit;
47
- }
48
- } else {
49
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
50
- }
51
- } else {
52
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
53
- }
54
- } else {
55
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
56
- }
57
-
58
- ?>
 
 
 
 
1
+ <?php
2
+ /*
3
+ index.php
4
+
5
+ Description:
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
+ Copyright (C) 2014 - 2017 Daisuke Maruyama
14
+
15
+ This program is free software; you can redistribute it and/or
16
+ modify it under the terms of the GNU General Public License
17
+ as published by the Free Software Foundation; either version 2
18
+ of the License, or (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
+ */
29
+
30
+ require_once( '../../../wp-load.php' );
31
+
32
+ if ( ! defined( 'ABSPATH' ) ) exit(); // Exit if accessed directly
33
+
34
+ if ( current_user_can( 'manage_options' ) ) {
35
+ if ( isset( $_GET['state'] ) && $_GET['state'] && isset( $_GET['action'] ) && $_GET['action'] && isset( $_GET['code'] ) && $_GET['code'] ) {
36
+ if ( $_GET['action'] === 'instagram-auth' ) {
37
+ if ( check_admin_referer( 'instagram-auth', 'state' ) ) {
38
+ $redirect_url = admin_url( 'admin.php?page=scc-setting' ) . '&action=instagram-auth&code=' . $_GET['code'] .'&_wpnonce=' . $_GET['state'];
39
+ wp_safe_redirect( $redirect_url );
40
+ exit;
41
+ } else {
42
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
43
+ }
44
+ } elseif ( $_GET['action'] === 'facebook-auth' ) {
45
+ if ( check_admin_referer( 'facebook-auth', 'state' ) ) {
46
+ $redirect_url = admin_url( 'admin.php?page=scc-setting' ) . '&action=facebook-auth&code=' . $_GET['code'] .'&_wpnonce=' . $_GET['state'];
47
+ wp_safe_redirect( $redirect_url );
48
+ exit;
49
+ } else {
50
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
51
+ }
52
+ } else {
53
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
54
+ }
55
+ } else {
56
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
57
+ }
58
+ } else {
59
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
60
+ }
61
+
62
+ ?>
js/highlight.pack.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! highlight.js v9.3.0 | BSD3 License | git.io/hljslicense */
2
- !function(e){var n="object"==typeof window&&window||"object"==typeof self&&self;"undefined"!=typeof exports?e(exports):n&&(n.hljs=e({}),"function"==typeof define&&define.amd&&define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&/gm,"&amp;").replace(/</gm,"&lt;").replace(/>/gm,"&gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&&e.exec(n);return t&&0==t.index}function a(e){return/^(no-?highlight|plain|text)$/i.test(e)}function i(e){var n,t,r,i=e.className+" ";if(i+=e.parentNode?e.parentNode.className:"",t=/\blang(?:uage)?-([\w-]+)\b/i.exec(i))return w(t[1])?t[1]:"no-highlight";for(i=i.split(/\s+/),n=0,r=i.length;r>n;n++)if(w(i[n])||a(i[n]))return i[n]}function o(e,n){var t,r={};for(t in e)r[t]=e[t];if(n)for(t in n)r[t]=n[t];return r}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3==i.nodeType?a+=i.nodeValue.length:1==i.nodeType&&(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&&r.length?e[0].offset!=r[0].offset?e[0].offset<r[0].offset?e:r:"start"==r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value)+'"'}f+="<"+t(e)+Array.prototype.map.call(e.attributes,r).join("")+">"}function u(e){f+="</"+t(e)+">"}function c(e){("start"==e.event?o:u)(e.node)}for(var s=0,f="",l=[];e.length||r.length;){var g=i();if(f+=n(a.substr(s,g[0].offset-s)),s=g[0].offset,g==e){l.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g==e&&g.length&&g[0].offset==s);l.reverse().forEach(o)}else"start"==g[0].event?l.push(g[0].node):l.pop(),c(g.splice(0,1)[0])}return f+n(a.substr(s))}function s(e){function n(e){return e&&e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var u={},c=function(n,t){e.cI&&(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");u[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?c("keyword",a.k):Object.keys(a.k).forEach(function(e){c(e,a.k[e])}),a.k=u}a.lR=t(a.l||/\w+/,!0),i&&(a.bK&&(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&&(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&&i.tE&&(a.tE+=(a.e?"|":"")+i.tE)),a.i&&(a.iR=t(a.i)),void 0===a.r&&(a.r=1),a.c||(a.c=[]);var s=[];a.c.forEach(function(e){e.v?e.v.forEach(function(n){s.push(o(e,n))}):s.push("self"==e?a:e)}),a.c=s,a.c.forEach(function(e){r(e,a)}),a.starts&&r(a.starts,i);var f=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=f.length?t(f.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){for(var t=0;t<n.c.length;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&&e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&&r(n.iR,e)}function g(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&&e.k[t]}function p(e,n,t,r){var a=r?"":E.classPrefix,i='<span class="'+a,o=t?"":"</span>";return i+=e+'">',i+n+o}function h(){if(!k.k)return n(M);var e="",t=0;k.lR.lastIndex=0;for(var r=k.lR.exec(M);r;){e+=n(M.substr(t,r.index-t));var a=g(k,r);a?(B+=a[1],e+=p(a[0],n(r[0]))):e+=n(r[0]),t=k.lR.lastIndex,r=k.lR.exec(M)}return e+n(M.substr(t))}function d(){var e="string"==typeof k.sL;if(e&&!R[k.sL])return n(M);var t=e?f(k.sL,M,!0,y[k.sL]):l(M,k.sL.length?k.sL:void 0);return k.r>0&&(B+=t.r),e&&(y[k.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=void 0!==k.sL?d():h(),M=""}function v(e,n){L+=e.cN?p(e.cN,"",!0):"",k=Object.create(e,{parent:{value:k}})}function m(e,n){if(M+=e,void 0===n)return b(),0;var t=o(n,k);if(t)return t.skip?M+=n:(t.eB&&(M+=n),b(),t.rB||t.eB||(M=n)),v(t,n),t.rB?0:n.length;var r=u(k,n);if(r){var a=k;a.skip?M+=n:(a.rE||a.eE||(M+=n),b(),a.eE&&(M=n));do k.cN&&(L+="</span>"),k.skip||(B+=k.r),k=k.parent;while(k!=r.parent);return r.starts&&v(r.starts,""),a.rE?0:n.length}if(c(n,k))throw new Error('Illegal lexeme "'+n+'" for mode "'+(k.cN||"<unnamed>")+'"');return M+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var x,k=i||N,y={},L="";for(x=k;x!=N;x=x.parent)x.cN&&(L=p(x.cN,"",!0)+L);var M="",B=0;try{for(var C,j,I=0;;){if(k.t.lastIndex=I,C=k.t.exec(t),!C)break;j=m(t.substr(I,C.index-I),C[0]),I=C.index+j}for(m(t.substr(I)),x=k;x.parent;x=x.parent)x.cN&&(L+="</span>");return{r:B,value:L,language:e,top:k}}catch(O){if(-1!=O.message.indexOf("Illegal"))return{r:0,value:n(t)};throw O}}function l(e,t){t=t||E.languages||Object.keys(R);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r>a.r&&(a=t),t.r>r.r&&(a=r,r=t)}),a.language&&(r.second_best=a),r}function g(e){return E.tabReplace&&(e=e.replace(/^((<[^>]+>|\t)+)/gm,function(e,n){return n.replace(/\t/g,E.tabReplace)})),E.useBR&&(e=e.replace(/\n/g,"<br>")),e}function p(e,n,t){var r=n?x[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&&a.push(r),a.join(" ").trim()}function h(e){var n=i(e);if(!a(n)){var t;E.useBR?(t=document.createElementNS("http://www.w3.org/1999/xhtml","div"),t.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/<br[ \/]*>/g,"\n")):t=e;var r=t.textContent,o=n?f(n,r,!0):l(r),s=u(t);if(s.length){var h=document.createElementNS("http://www.w3.org/1999/xhtml","div");h.innerHTML=o.value,o.value=c(s,u(h),r)}o.value=g(o.value),e.innerHTML=o.value,e.className=p(e.className,n,o.language),e.result={language:o.language,re:o.r},o.second_best&&(e.second_best={language:o.second_best.language,re:o.second_best.r})}}function d(e){E=o(E,e)}function b(){if(!b.called){b.called=!0;var e=document.querySelectorAll("pre code");Array.prototype.forEach.call(e,h)}}function v(){addEventListener("DOMContentLoaded",b,!1),addEventListener("load",b,!1)}function m(n,t){var r=R[n]=t(e);r.aliases&&r.aliases.forEach(function(e){x[e]=n})}function N(){return Object.keys(R)}function w(e){return e=(e||"").toLowerCase(),R[e]||R[x[e]]}var E={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0},R={},x={};return e.highlight=f,e.highlightAuto=l,e.fixMarkup=g,e.highlightBlock=h,e.configure=d,e.initHighlighting=b,e.initHighlightingOnLoad=v,e.registerLanguage=m,e.listLanguages=N,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|like)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("xml",function(s){var e="[A-Za-z0-9\\._:-]+",t={eW:!0,i:/</,r:0,c:[{cN:"attr",b:e,r:0},{b:/=\s*/,r:0,c:[{cN:"string",endsParent:!0,v:[{b:/"/,e:/"/},{b:/'/,e:/'/},{b:/[^\s"'=<>`]+/}]}]}]};return{aliases:["html","xhtml","rss","atom","xsl","plist"],cI:!0,c:[{cN:"meta",b:"<!DOCTYPE",e:">",r:10,c:[{b:"\\[",e:"\\]"}]},s.C("<!--","-->",{r:10}),{b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{b:/<\?(php)?/,e:/\?>/,sL:"php",c:[{b:"/\\*",e:"\\*/",skip:!0}]},{cN:"tag",b:"<style(?=\\s|>|$)",e:">",k:{name:"style"},c:[t],starts:{e:"</style>",rE:!0,sL:["css","xml"]}},{cN:"tag",b:"<script(?=\\s|>|$)",e:">",k:{name:"script"},c:[t],starts:{e:"</script>",rE:!0,sL:["actionscript","javascript","handlebars","xml"]}},{cN:"meta",v:[{b:/<\?xml/,e:/\?>/,r:10},{b:/<\?\w+/,e:/\?>/}]},{cN:"tag",b:"</?",e:"/?>",c:[{cN:"name",b:/[^\/><\s]+/,r:0},t]}]}});hljs.registerLanguage("php",function(e){var c={b:"\\$+[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*"},a={cN:"meta",b:/<\?(php)?|\?>/},i={cN:"string",c:[e.BE,a],v:[{b:'b"',e:'"'},{b:"b'",e:"'"},e.inherit(e.ASM,{i:null}),e.inherit(e.QSM,{i:null})]},t={v:[e.BNM,e.CNM]};return{aliases:["php3","php4","php5","php6"],cI:!0,k:"and include_once list abstract global private echo interface as static endswitch array null if endwhile or const for endforeach self var while isset public protected exit foreach throw elseif include __FILE__ empty require_once do xor return parent clone use __CLASS__ __LINE__ else break print eval new catch __METHOD__ case exception default die require __FUNCTION__ enddeclare final try switch continue endfor endif declare unset true false trait goto instanceof insteadof __DIR__ __NAMESPACE__ yield finally",c:[e.HCM,e.C("//","$",{c:[a]}),e.C("/\\*","\\*/",{c:[{cN:"doctag",b:"@[A-Za-z]+"}]}),e.C("__halt_compiler.+?;",!1,{eW:!0,k:"__halt_compiler",l:e.UIR}),{cN:"string",b:/<<<['"]?\w+['"]?$/,e:/^\w+;?$/,c:[e.BE,{cN:"subst",v:[{b:/\$\w+/},{b:/\{\$/,e:/\}/}]}]},a,c,{b:/(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/},{cN:"function",bK:"function",e:/[;{]/,eE:!0,i:"\\$|\\[|%",c:[e.UTM,{cN:"params",b:"\\(",e:"\\)",c:["self",c,e.CBCM,i,t]}]},{cN:"class",bK:"class interface",e:"{",eE:!0,i:/[:\(\$"]/,c:[{bK:"extends implements"},e.UTM]},{bK:"namespace",e:";",i:/[\.']/,c:[e.UTM]},{bK:"use",e:";",c:[e.UTM]},{b:"=>"},i,t]}});
1
+ /*! highlight.js v9.3.0 | BSD3 License | git.io/hljslicense */
2
+ !function(e){var n="object"==typeof window&&window||"object"==typeof self&&self;"undefined"!=typeof exports?e(exports):n&&(n.hljs=e({}),"function"==typeof define&&define.amd&&define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&/gm,"&amp;").replace(/</gm,"&lt;").replace(/>/gm,"&gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&&e.exec(n);return t&&0==t.index}function a(e){return/^(no-?highlight|plain|text)$/i.test(e)}function i(e){var n,t,r,i=e.className+" ";if(i+=e.parentNode?e.parentNode.className:"",t=/\blang(?:uage)?-([\w-]+)\b/i.exec(i))return w(t[1])?t[1]:"no-highlight";for(i=i.split(/\s+/),n=0,r=i.length;r>n;n++)if(w(i[n])||a(i[n]))return i[n]}function o(e,n){var t,r={};for(t in e)r[t]=e[t];if(n)for(t in n)r[t]=n[t];return r}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3==i.nodeType?a+=i.nodeValue.length:1==i.nodeType&&(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&&r.length?e[0].offset!=r[0].offset?e[0].offset<r[0].offset?e:r:"start"==r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value)+'"'}f+="<"+t(e)+Array.prototype.map.call(e.attributes,r).join("")+">"}function u(e){f+="</"+t(e)+">"}function c(e){("start"==e.event?o:u)(e.node)}for(var s=0,f="",l=[];e.length||r.length;){var g=i();if(f+=n(a.substr(s,g[0].offset-s)),s=g[0].offset,g==e){l.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g==e&&g.length&&g[0].offset==s);l.reverse().forEach(o)}else"start"==g[0].event?l.push(g[0].node):l.pop(),c(g.splice(0,1)[0])}return f+n(a.substr(s))}function s(e){function n(e){return e&&e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var u={},c=function(n,t){e.cI&&(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");u[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?c("keyword",a.k):Object.keys(a.k).forEach(function(e){c(e,a.k[e])}),a.k=u}a.lR=t(a.l||/\w+/,!0),i&&(a.bK&&(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&&(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&&i.tE&&(a.tE+=(a.e?"|":"")+i.tE)),a.i&&(a.iR=t(a.i)),void 0===a.r&&(a.r=1),a.c||(a.c=[]);var s=[];a.c.forEach(function(e){e.v?e.v.forEach(function(n){s.push(o(e,n))}):s.push("self"==e?a:e)}),a.c=s,a.c.forEach(function(e){r(e,a)}),a.starts&&r(a.starts,i);var f=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=f.length?t(f.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){for(var t=0;t<n.c.length;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&&e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&&r(n.iR,e)}function g(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&&e.k[t]}function p(e,n,t,r){var a=r?"":E.classPrefix,i='<span class="'+a,o=t?"":"</span>";return i+=e+'">',i+n+o}function h(){if(!k.k)return n(M);var e="",t=0;k.lR.lastIndex=0;for(var r=k.lR.exec(M);r;){e+=n(M.substr(t,r.index-t));var a=g(k,r);a?(B+=a[1],e+=p(a[0],n(r[0]))):e+=n(r[0]),t=k.lR.lastIndex,r=k.lR.exec(M)}return e+n(M.substr(t))}function d(){var e="string"==typeof k.sL;if(e&&!R[k.sL])return n(M);var t=e?f(k.sL,M,!0,y[k.sL]):l(M,k.sL.length?k.sL:void 0);return k.r>0&&(B+=t.r),e&&(y[k.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=void 0!==k.sL?d():h(),M=""}function v(e,n){L+=e.cN?p(e.cN,"",!0):"",k=Object.create(e,{parent:{value:k}})}function m(e,n){if(M+=e,void 0===n)return b(),0;var t=o(n,k);if(t)return t.skip?M+=n:(t.eB&&(M+=n),b(),t.rB||t.eB||(M=n)),v(t,n),t.rB?0:n.length;var r=u(k,n);if(r){var a=k;a.skip?M+=n:(a.rE||a.eE||(M+=n),b(),a.eE&&(M=n));do k.cN&&(L+="</span>"),k.skip||(B+=k.r),k=k.parent;while(k!=r.parent);return r.starts&&v(r.starts,""),a.rE?0:n.length}if(c(n,k))throw new Error('Illegal lexeme "'+n+'" for mode "'+(k.cN||"<unnamed>")+'"');return M+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var x,k=i||N,y={},L="";for(x=k;x!=N;x=x.parent)x.cN&&(L=p(x.cN,"",!0)+L);var M="",B=0;try{for(var C,j,I=0;;){if(k.t.lastIndex=I,C=k.t.exec(t),!C)break;j=m(t.substr(I,C.index-I),C[0]),I=C.index+j}for(m(t.substr(I)),x=k;x.parent;x=x.parent)x.cN&&(L+="</span>");return{r:B,value:L,language:e,top:k}}catch(O){if(-1!=O.message.indexOf("Illegal"))return{r:0,value:n(t)};throw O}}function l(e,t){t=t||E.languages||Object.keys(R);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r>a.r&&(a=t),t.r>r.r&&(a=r,r=t)}),a.language&&(r.second_best=a),r}function g(e){return E.tabReplace&&(e=e.replace(/^((<[^>]+>|\t)+)/gm,function(e,n){return n.replace(/\t/g,E.tabReplace)})),E.useBR&&(e=e.replace(/\n/g,"<br>")),e}function p(e,n,t){var r=n?x[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&&a.push(r),a.join(" ").trim()}function h(e){var n=i(e);if(!a(n)){var t;E.useBR?(t=document.createElementNS("http://www.w3.org/1999/xhtml","div"),t.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/<br[ \/]*>/g,"\n")):t=e;var r=t.textContent,o=n?f(n,r,!0):l(r),s=u(t);if(s.length){var h=document.createElementNS("http://www.w3.org/1999/xhtml","div");h.innerHTML=o.value,o.value=c(s,u(h),r)}o.value=g(o.value),e.innerHTML=o.value,e.className=p(e.className,n,o.language),e.result={language:o.language,re:o.r},o.second_best&&(e.second_best={language:o.second_best.language,re:o.second_best.r})}}function d(e){E=o(E,e)}function b(){if(!b.called){b.called=!0;var e=document.querySelectorAll("pre code");Array.prototype.forEach.call(e,h)}}function v(){addEventListener("DOMContentLoaded",b,!1),addEventListener("load",b,!1)}function m(n,t){var r=R[n]=t(e);r.aliases&&r.aliases.forEach(function(e){x[e]=n})}function N(){return Object.keys(R)}function w(e){return e=(e||"").toLowerCase(),R[e]||R[x[e]]}var E={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0},R={},x={};return e.highlight=f,e.highlightAuto=l,e.fixMarkup=g,e.highlightBlock=h,e.configure=d,e.initHighlighting=b,e.initHighlightingOnLoad=v,e.registerLanguage=m,e.listLanguages=N,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|like)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("xml",function(s){var e="[A-Za-z0-9\\._:-]+",t={eW:!0,i:/</,r:0,c:[{cN:"attr",b:e,r:0},{b:/=\s*/,r:0,c:[{cN:"string",endsParent:!0,v:[{b:/"/,e:/"/},{b:/'/,e:/'/},{b:/[^\s"'=<>`]+/}]}]}]};return{aliases:["html","xhtml","rss","atom","xsl","plist"],cI:!0,c:[{cN:"meta",b:"<!DOCTYPE",e:">",r:10,c:[{b:"\\[",e:"\\]"}]},s.C("<!--","-->",{r:10}),{b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{b:/<\?(php)?/,e:/\?>/,sL:"php",c:[{b:"/\\*",e:"\\*/",skip:!0}]},{cN:"tag",b:"<style(?=\\s|>|$)",e:">",k:{name:"style"},c:[t],starts:{e:"</style>",rE:!0,sL:["css","xml"]}},{cN:"tag",b:"<script(?=\\s|>|$)",e:">",k:{name:"script"},c:[t],starts:{e:"</script>",rE:!0,sL:["actionscript","javascript","handlebars","xml"]}},{cN:"meta",v:[{b:/<\?xml/,e:/\?>/,r:10},{b:/<\?\w+/,e:/\?>/}]},{cN:"tag",b:"</?",e:"/?>",c:[{cN:"name",b:/[^\/><\s]+/,r:0},t]}]}});hljs.registerLanguage("php",function(e){var c={b:"\\$+[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*"},a={cN:"meta",b:/<\?(php)?|\?>/},i={cN:"string",c:[e.BE,a],v:[{b:'b"',e:'"'},{b:"b'",e:"'"},e.inherit(e.ASM,{i:null}),e.inherit(e.QSM,{i:null})]},t={v:[e.BNM,e.CNM]};return{aliases:["php3","php4","php5","php6"],cI:!0,k:"and include_once list abstract global private echo interface as static endswitch array null if endwhile or const for endforeach self var while isset public protected exit foreach throw elseif include __FILE__ empty require_once do xor return parent clone use __CLASS__ __LINE__ else break print eval new catch __METHOD__ case exception default die require __FUNCTION__ enddeclare final try switch continue endfor endif declare unset true false trait goto instanceof insteadof __DIR__ __NAMESPACE__ yield finally",c:[e.HCM,e.C("//","$",{c:[a]}),e.C("/\\*","\\*/",{c:[{cN:"doctag",b:"@[A-Za-z]+"}]}),e.C("__halt_compiler.+?;",!1,{eW:!0,k:"__halt_compiler",l:e.UIR}),{cN:"string",b:/<<<['"]?\w+['"]?$/,e:/^\w+;?$/,c:[e.BE,{cN:"subst",v:[{b:/\$\w+/},{b:/\{\$/,e:/\}/}]}]},a,c,{b:/(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/},{cN:"function",bK:"function",e:/[;{]/,eE:!0,i:"\\$|\\[|%",c:[e.UTM,{cN:"params",b:"\\(",e:"\\)",c:["self",c,e.CBCM,i,t]}]},{cN:"class",bK:"class interface",e:"{",eE:!0,i:/[:\(\$"]/,c:[{bK:"extends implements"},e.UTM]},{bK:"namespace",e:";",i:/[\.']/,c:[e.UTM]},{bK:"use",e:";",c:[e.UTM]},{b:"=>"},i,t]}});
js/jquery.scc-cache-info.js CHANGED
@@ -1,161 +1,169 @@
1
- /*
2
- jquery.scc-cache-info.js
3
- Author: Daisuke Maruyama
4
- Author URI: http://marubon.info/
5
- License: GPL2 or later
6
- License URI: http://www.gnu.org/licenses/gpl-2.0.txt
7
- */
8
- ;jQuery(document).ready(function ($) {
9
- return $('#scc-dashboard,#scc-dashboard-widget').each(function() {
10
- $("span[data-scc]").css('display', 'none');
11
-
12
- function isset( data ){
13
- return ( typeof( data ) != 'undefined' );
14
- }
15
-
16
- $.ajax({
17
- url: scc.endpoint + '?action=' + scc.action + '&nonce=' + scc.nonce,
18
- dataType: 'jsonp',
19
- cache: false,
20
- success: function(res) {
21
- if (res) {
22
- console.log(res);
23
- $("span[data-scc='spc']").text(res.share.post_count);
24
- $("span[data-scc='spfcc']").text(res.share.primary.full_cache_count);
25
- $("span[data-scc='sppcc']").text(res.share.primary.partial_cache_count);
26
- $("span[data-scc='spncc']").text(res.share.primary.no_cache_count);
27
- $("span[data-scc='spcs']").text(res.share.primary.cache_status);
28
-
29
- $("span[data-scc='ssfcc']").text(res.share.secondary.full_cache_count);
30
- $("span[data-scc='sspcc']").text(res.share.secondary.partial_cache_count);
31
- $("span[data-scc='ssncc']").text(res.share.secondary.no_cache_count);
32
- $("span[data-scc='sscs']").text(res.share.secondary.cache_status);
33
-
34
- if ( res.share_delta.twitter > 0) {
35
- $("span[data-scc='stwitter']").html(res.share_count.twitter + ' (<span class="delta-rise">+' + res.share_delta.twitter + '</span>)');
36
- } else if (res.share_delta.twitter < 0) {
37
- $("span[data-scc='stwitter']").html(res.share_count.twitter + ' (<span class="delta-fall">' + res.share_delta.twitter + '</span>)');
38
- } else {
39
- $("span[data-scc='stwitter']").html(res.share_count.twitter);
40
- }
41
- if (res.share_delta.facebook > 0) {
42
- $("span[data-scc='sfacebook']").html(res.share_count.facebook + ' (<span class="delta-rise">+' + res.share_delta.facebook + '</span>)');
43
- } else if (res.share_delta.facebook < 0) {
44
- $("span[data-scc='sfacebook']").html(res.share_count.facebook + ' (<span class="delta-fall">' + res.share_delta.facebook + '</span>)');
45
- } else {
46
- $("span[data-scc='sfacebook']").html(res.share_count.facebook);
47
- }
48
-
49
- if (res.share_delta.gplus > 0) {
50
- $("span[data-scc='sgplus']").html(res.share_count.gplus + ' (<span class="delta-rise">+' + res.share_delta.gplus + '</span>)');
51
- } else if (res.share_delta.gplus < 0) {
52
- $("span[data-scc='sgplus']").html(res.share_count.gplus + ' (<span class="delta-fall">' + res.share_delta.gplus + '</span>)');
53
- } else {
54
- $("span[data-scc='sgplus']").html(res.share_count.gplus);
55
- }
56
-
57
- if (res.share_delta.pocket > 0) {
58
- $("span[data-scc='spocket']").html(res.share_count.pocket + ' (<span class="delta-rise">+' + res.share_delta.pocket + '</span>)');
59
- } else if (res.share_delta.pocket < 0) {
60
- $("span[data-scc='spocket']").html(res.share_count.pocket + ' (<span class="delta-fall">' + res.share_delta.pocket + '</span>)');
61
- } else {
62
- $("span[data-scc='spocket']").html(res.share_count.pocket);
63
- }
64
-
65
- if (res.share_delta.hatebu > 0) {
66
- $("span[data-scc='shatebu']").html(res.share_count.hatebu + ' (<span class="delta-rise">+' + res.share_delta.hatebu + '</span>)');
67
- } else if (res.share_delta.hatebu < 0) {
68
- $("span[data-scc='shatebu']").html(res.share_count.hatebu + ' (<span class="delta-fall">' + res.share_delta.hatebu + '</span>)');
69
- } else {
70
- $("span[data-scc='shatebu']").html(res.share_count.hatebu);
71
- }
72
-
73
- if (res.share_delta.pinterest > 0) {
74
- $("span[data-scc='spinterest']").html(res.share_count.pinterest + ' (<span class="delta-rise">+' + res.share_delta.pinterest + '</span>)');
75
- } else if (res.share_delta.pinterest < 0) {
76
- $("span[data-scc='spinterest']").html(res.share_count.pinterest + ' (<span class="delta-fall">' + res.share_delta.pinterest + '</span>)');
77
- } else {
78
- $("span[data-scc='spinterest']").html(res.share_count.pinterest);
79
- }
80
-
81
- if (res.share_delta.total > 0) {
82
- $("span[data-scc='stotal']").html(res.share_count.total + ' (<span class="delta-rise">+' + res.share_delta.total + '</span>)');
83
- } else if (res.share_delta.total < 0) {
84
- $("span[data-scc='stotal']").html(res.share_count.total + ' (<span class="delta-fall">' + res.share_delta.total + '</span>)');
85
- } else {
86
- $("span[data-scc='stotal']").html(res.share_count.total);
87
- }
88
-
89
- $("span[data-scc='fpc']").text(res.follow.post_count);
90
- $("span[data-scc='fpfcc']").text(res.follow.primary.full_cache_count);
91
- $("span[data-scc='fppcc']").text(res.follow.primary.partial_cache_count);
92
- $("span[data-scc='fpncc']").text(res.follow.primary.no_cache_count);
93
- $("span[data-scc='fpcs']").text(res.follow.primary.cache_status);
94
-
95
- $("span[data-scc='fsfcc']").text(res.follow.secondary.full_cache_count);
96
- $("span[data-scc='fspcc']").text(res.follow.secondary.partial_cache_count);
97
- $("span[data-scc='fsncc']").text(res.follow.secondary.no_cache_count);
98
- $("span[data-scc='fscs']").text(res.follow.secondary.cache_status);
99
-
100
- if (isset(res.follow_count)) {
101
- if (isset(res.follow_delta) && res.follow_delta.twitter > 0) {
102
- $("span[data-scc='ftwitter']").html(res.follow_count.twitter + ' (<span class="delta-rise">+' + res.follow_delta.twitter + '</span>)');
103
- } else if (isset(res.follow_delta) && res.follow_delta.twitter < 0) {
104
- $("span[data-scc='ftwitter']").html(res.follow_count.twitter + ' (<span class="delta-fall">' + res.follow_delta.twitter + '</span>)');
105
- } else {
106
- $("span[data-scc='ftwitter']").html(res.follow_count.twitter);
107
- }
108
- }
109
-
110
- if (isset(res.follow_count)) {
111
- if (isset(res.follow_delta) && res.follow_delta.facebook > 0) {
112
- $("span[data-scc='ffacebook']").html(res.follow_count.facebook + ' (<span class="delta-rise">+' + res.follow_delta.facebook + '</span>)');
113
- } else if (isset(res.follow_delta) && res.follow_delta.facebook < 0) {
114
- $("span[data-scc='ffacebook']").html(res.follow_count.facebook + ' (<span class="delta-fall">' + res.follow_delta.facebook + '</span>)');
115
- } else {
116
- $("span[data-scc='ffacebook']").html(res.follow_count.facebook);
117
- }
118
- }
119
-
120
- if ( isset( res.follow_count ) ) {
121
- if (isset(res.follow_delta) && res.follow_delta.feedly > 0) {
122
- $("span[data-scc='ffeedly']").html(res.follow_count.feedly + ' (<span class="delta-rise">+' + res.follow_delta.feedly + '</span>)');
123
- } else if (isset(res.follow_delta) && res.follow_delta.feedly < 0) {
124
- $("span[data-scc='ffeedly']").html(res.follow_count.feedly + ' (<span class="delta-fall">' + res.follow_delta.feedly + '</span>)');
125
- } else {
126
- $("span[data-scc='ffeedly']").html(res.follow_count.feedly);
127
- }
128
- }
129
-
130
- if ( isset( res.follow_count ) ) {
131
- if (isset(res.follow_delta) && res.follow_delta.push7 > 0) {
132
- $("span[data-scc='fpush7']").html(res.follow_count.push7 + ' (<span class="delta-rise">+' + res.follow_delta.push7 + '</span>)');
133
- } else if (isset(res.follow_delta) && res.follow_delta.push7 < 0) {
134
- $("span[data-scc='fpush7']").html(res.follow_count.push7 + ' (<span class="delta-fall">' + res.follow_delta.push7 + '</span>)');
135
- } else {
136
- $("span[data-scc='fpush7']").html(res.follow_count.push7);
137
- }
138
- }
139
-
140
- if ( isset( res.follow_count ) ) {
141
- if (isset(res.follow_delta) && res.follow_delta.instagram > 0) {
142
- $("span[data-scc='finstagram']").html(res.follow_count.instagram + ' (<span class="delta-rise">+' + res.follow_delta.instagram + '</span>)');
143
- } else if (isset(res.follow_delta) && res.follow_delta.instagram < 0) {
144
- $("span[data-scc='finstagram']").html(res.follow_count.instagram + ' (<span class="delta-fall">' + res.follow_delta.instagram + '</span>)');
145
- } else {
146
- $("span[data-scc='finstagram']").html(res.follow_count.instagram);
147
- }
148
- }
149
-
150
- $(".loading").css('display', 'none');
151
- $("span[data-scc]").fadeIn();
152
- } else {
153
- $("span[data-scc]").text('?');
154
- }
155
- },
156
- error: function(res) {
157
- $("span[data-scc]").text('?');
158
- }
159
- });
160
- });
161
- });
 
 
 
 
 
 
 
 
1
+ /*
2
+ jquery.scc-cache-info.js
3
+ Author: Daisuke Maruyama
4
+ Author URI: http://marubon.info/
5
+ License: GPL2 or later
6
+ License URI: http://www.gnu.org/licenses/gpl-2.0.txt
7
+ */
8
+ ;jQuery(document).ready(function ($) {
9
+ return $('#scc-dashboard,#scc-dashboard-widget').each(function() {
10
+ $("span[data-scc]").css('display', 'none');
11
+
12
+ function isset( data ){
13
+ return ( typeof( data ) != 'undefined' );
14
+ }
15
+
16
+ $.ajax({
17
+ url: scc.endpoint + '?action=' + scc.action + '&nonce=' + scc.nonce,
18
+ dataType: 'jsonp',
19
+ cache: false,
20
+ success: function(res) {
21
+ if (res) {
22
+ console.log(res);
23
+ $("span[data-scc='spc']").text(res.share.post_count);
24
+ $("span[data-scc='spfcc']").text(res.share.primary.full_cache_count);
25
+ $("span[data-scc='sppcc']").text(res.share.primary.partial_cache_count);
26
+ $("span[data-scc='spncc']").text(res.share.primary.no_cache_count);
27
+ $("span[data-scc='spcs']").text(res.share.primary.cache_status);
28
+
29
+ $("span[data-scc='ssfcc']").text(res.share.secondary.full_cache_count);
30
+ $("span[data-scc='sspcc']").text(res.share.secondary.partial_cache_count);
31
+ $("span[data-scc='ssncc']").text(res.share.secondary.no_cache_count);
32
+ $("span[data-scc='sscs']").text(res.share.secondary.cache_status);
33
+
34
+ if ( res.share_delta.twitter > 0) {
35
+ $("span[data-scc='stwitter']").html(res.share_count.twitter + ' (<span class="delta-rise">+' + res.share_delta.twitter + '</span>)');
36
+ } else if (res.share_delta.twitter < 0) {
37
+ $("span[data-scc='stwitter']").html(res.share_count.twitter + ' (<span class="delta-fall">' + res.share_delta.twitter + '</span>)');
38
+ } else {
39
+ $("span[data-scc='stwitter']").html(res.share_count.twitter);
40
+ }
41
+ if (res.share_delta.facebook > 0) {
42
+ $("span[data-scc='sfacebook']").html(res.share_count.facebook + ' (<span class="delta-rise">+' + res.share_delta.facebook + '</span>)');
43
+ } else if (res.share_delta.facebook < 0) {
44
+ $("span[data-scc='sfacebook']").html(res.share_count.facebook + ' (<span class="delta-fall">' + res.share_delta.facebook + '</span>)');
45
+ } else {
46
+ $("span[data-scc='sfacebook']").html(res.share_count.facebook);
47
+ }
48
+
49
+ if (res.share_delta.gplus > 0) {
50
+ $("span[data-scc='sgplus']").html(res.share_count.gplus + ' (<span class="delta-rise">+' + res.share_delta.gplus + '</span>)');
51
+ } else if (res.share_delta.gplus < 0) {
52
+ $("span[data-scc='sgplus']").html(res.share_count.gplus + ' (<span class="delta-fall">' + res.share_delta.gplus + '</span>)');
53
+ } else {
54
+ $("span[data-scc='sgplus']").html(res.share_count.gplus);
55
+ }
56
+
57
+ if (res.share_delta.pocket > 0) {
58
+ $("span[data-scc='spocket']").html(res.share_count.pocket + ' (<span class="delta-rise">+' + res.share_delta.pocket + '</span>)');
59
+ } else if (res.share_delta.pocket < 0) {
60
+ $("span[data-scc='spocket']").html(res.share_count.pocket + ' (<span class="delta-fall">' + res.share_delta.pocket + '</span>)');
61
+ } else {
62
+ $("span[data-scc='spocket']").html(res.share_count.pocket);
63
+ }
64
+
65
+ if (res.share_delta.hatebu > 0) {
66
+ $("span[data-scc='shatebu']").html(res.share_count.hatebu + ' (<span class="delta-rise">+' + res.share_delta.hatebu + '</span>)');
67
+ } else if (res.share_delta.hatebu < 0) {
68
+ $("span[data-scc='shatebu']").html(res.share_count.hatebu + ' (<span class="delta-fall">' + res.share_delta.hatebu + '</span>)');
69
+ } else {
70
+ $("span[data-scc='shatebu']").html(res.share_count.hatebu);
71
+ }
72
+
73
+ if (res.share_delta.pinterest > 0) {
74
+ $("span[data-scc='spinterest']").html(res.share_count.pinterest + ' (<span class="delta-rise">+' + res.share_delta.pinterest + '</span>)');
75
+ } else if (res.share_delta.pinterest < 0) {
76
+ $("span[data-scc='spinterest']").html(res.share_count.pinterest + ' (<span class="delta-fall">' + res.share_delta.pinterest + '</span>)');
77
+ } else {
78
+ $("span[data-scc='spinterest']").html(res.share_count.pinterest);
79
+ }
80
+
81
+ if (res.share_delta.linkedin > 0) {
82
+ $("span[data-scc='slinkedin']").html(res.share_count.linkedin + ' (<span class="delta-rise">+' + res.share_delta.linkedin + '</span>)');
83
+ } else if (res.share_delta.linkedin < 0) {
84
+ $("span[data-scc='slinkedin']").html(res.share_count.linkedin + ' (<span class="delta-fall">' + res.share_delta.linkedin + '</span>)');
85
+ } else {
86
+ $("span[data-scc='slinkedin']").html(res.share_count.linkedin);
87
+ }
88
+
89
+ if (res.share_delta.total > 0) {
90
+ $("span[data-scc='stotal']").html(res.share_count.total + ' (<span class="delta-rise">+' + res.share_delta.total + '</span>)');
91
+ } else if (res.share_delta.total < 0) {
92
+ $("span[data-scc='stotal']").html(res.share_count.total + ' (<span class="delta-fall">' + res.share_delta.total + '</span>)');
93
+ } else {
94
+ $("span[data-scc='stotal']").html(res.share_count.total);
95
+ }
96
+
97
+ $("span[data-scc='fpc']").text(res.follow.post_count);
98
+ $("span[data-scc='fpfcc']").text(res.follow.primary.full_cache_count);
99
+ $("span[data-scc='fppcc']").text(res.follow.primary.partial_cache_count);
100
+ $("span[data-scc='fpncc']").text(res.follow.primary.no_cache_count);
101
+ $("span[data-scc='fpcs']").text(res.follow.primary.cache_status);
102
+
103
+ $("span[data-scc='fsfcc']").text(res.follow.secondary.full_cache_count);
104
+ $("span[data-scc='fspcc']").text(res.follow.secondary.partial_cache_count);
105
+ $("span[data-scc='fsncc']").text(res.follow.secondary.no_cache_count);
106
+ $("span[data-scc='fscs']").text(res.follow.secondary.cache_status);
107
+
108
+ if (isset(res.follow_count)) {
109
+ if (isset(res.follow_delta) && res.follow_delta.twitter > 0) {
110
+ $("span[data-scc='ftwitter']").html(res.follow_count.twitter + ' (<span class="delta-rise">+' + res.follow_delta.twitter + '</span>)');
111
+ } else if (isset(res.follow_delta) && res.follow_delta.twitter < 0) {
112
+ $("span[data-scc='ftwitter']").html(res.follow_count.twitter + ' (<span class="delta-fall">' + res.follow_delta.twitter + '</span>)');
113
+ } else {
114
+ $("span[data-scc='ftwitter']").html(res.follow_count.twitter);
115
+ }
116
+ }
117
+
118
+ if (isset(res.follow_count)) {
119
+ if (isset(res.follow_delta) && res.follow_delta.facebook > 0) {
120
+ $("span[data-scc='ffacebook']").html(res.follow_count.facebook + ' (<span class="delta-rise">+' + res.follow_delta.facebook + '</span>)');
121
+ } else if (isset(res.follow_delta) && res.follow_delta.facebook < 0) {
122
+ $("span[data-scc='ffacebook']").html(res.follow_count.facebook + ' (<span class="delta-fall">' + res.follow_delta.facebook + '</span>)');
123
+ } else {
124
+ $("span[data-scc='ffacebook']").html(res.follow_count.facebook);
125
+ }
126
+ }
127
+
128
+ if ( isset( res.follow_count ) ) {
129
+ if (isset(res.follow_delta) && res.follow_delta.feedly > 0) {
130
+ $("span[data-scc='ffeedly']").html(res.follow_count.feedly + ' (<span class="delta-rise">+' + res.follow_delta.feedly + '</span>)');
131
+ } else if (isset(res.follow_delta) && res.follow_delta.feedly < 0) {
132
+ $("span[data-scc='ffeedly']").html(res.follow_count.feedly + ' (<span class="delta-fall">' + res.follow_delta.feedly + '</span>)');
133
+ } else {
134
+ $("span[data-scc='ffeedly']").html(res.follow_count.feedly);
135
+ }
136
+ }
137
+
138
+ if ( isset( res.follow_count ) ) {
139
+ if (isset(res.follow_delta) && res.follow_delta.push7 > 0) {
140
+ $("span[data-scc='fpush7']").html(res.follow_count.push7 + ' (<span class="delta-rise">+' + res.follow_delta.push7 + '</span>)');
141
+ } else if (isset(res.follow_delta) && res.follow_delta.push7 < 0) {
142
+ $("span[data-scc='fpush7']").html(res.follow_count.push7 + ' (<span class="delta-fall">' + res.follow_delta.push7 + '</span>)');
143
+ } else {
144
+ $("span[data-scc='fpush7']").html(res.follow_count.push7);
145
+ }
146
+ }
147
+
148
+ if ( isset( res.follow_count ) ) {
149
+ if (isset(res.follow_delta) && res.follow_delta.instagram > 0) {
150
+ $("span[data-scc='finstagram']").html(res.follow_count.instagram + ' (<span class="delta-rise">+' + res.follow_delta.instagram + '</span>)');
151
+ } else if (isset(res.follow_delta) && res.follow_delta.instagram < 0) {
152
+ $("span[data-scc='finstagram']").html(res.follow_count.instagram + ' (<span class="delta-fall">' + res.follow_delta.instagram + '</span>)');
153
+ } else {
154
+ $("span[data-scc='finstagram']").html(res.follow_count.instagram);
155
+ }
156
+ }
157
+
158
+ $(".loading").css('display', 'none');
159
+ $("span[data-scc]").fadeIn();
160
+ } else {
161
+ $("span[data-scc]").text('?');
162
+ }
163
+ },
164
+ error: function(res) {
165
+ $("span[data-scc]").text('?');
166
+ }
167
+ });
168
+ });
169
+ });
js/jquery.scc-cache-info.min.js CHANGED
@@ -1,12 +1,13 @@
1
- ;jQuery(document).ready(function(b){return b("#scc-dashboard,#scc-dashboard-widget").each(function(){function c(a){return"undefined"!=typeof a}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?(console.log(a),b("span[data-scc='spc']").text(a.share.post_count),b("span[data-scc='spfcc']").text(a.share.primary.full_cache_count),b("span[data-scc='sppcc']").text(a.share.primary.partial_cache_count),
2
- b("span[data-scc='spncc']").text(a.share.primary.no_cache_count),b("span[data-scc='spcs']").text(a.share.primary.cache_status),b("span[data-scc='ssfcc']").text(a.share.secondary.full_cache_count),b("span[data-scc='sspcc']").text(a.share.secondary.partial_cache_count),b("span[data-scc='ssncc']").text(a.share.secondary.no_cache_count),b("span[data-scc='sscs']").text(a.share.secondary.cache_status),0<a.share_delta.twitter?b("span[data-scc='stwitter']").html(a.share_count.twitter+' (<span class="delta-rise">+'+
3
- a.share_delta.twitter+"</span>)"):0>a.share_delta.twitter?b("span[data-scc='stwitter']").html(a.share_count.twitter+' (<span class="delta-fall">'+a.share_delta.twitter+"</span>)"):b("span[data-scc='stwitter']").html(a.share_count.twitter),0<a.share_delta.facebook?b("span[data-scc='sfacebook']").html(a.share_count.facebook+' (<span class="delta-rise">+'+a.share_delta.facebook+"</span>)"):0>a.share_delta.facebook?b("span[data-scc='sfacebook']").html(a.share_count.facebook+' (<span class="delta-fall">'+
4
- a.share_delta.facebook+"</span>)"):b("span[data-scc='sfacebook']").html(a.share_count.facebook),0<a.share_delta.gplus?b("span[data-scc='sgplus']").html(a.share_count.gplus+' (<span class="delta-rise">+'+a.share_delta.gplus+"</span>)"):0>a.share_delta.gplus?b("span[data-scc='sgplus']").html(a.share_count.gplus+' (<span class="delta-fall">'+a.share_delta.gplus+"</span>)"):b("span[data-scc='sgplus']").html(a.share_count.gplus),0<a.share_delta.pocket?b("span[data-scc='spocket']").html(a.share_count.pocket+
5
- ' (<span class="delta-rise">+'+a.share_delta.pocket+"</span>)"):0>a.share_delta.pocket?b("span[data-scc='spocket']").html(a.share_count.pocket+' (<span class="delta-fall">'+a.share_delta.pocket+"</span>)"):b("span[data-scc='spocket']").html(a.share_count.pocket),0<a.share_delta.hatebu?b("span[data-scc='shatebu']").html(a.share_count.hatebu+' (<span class="delta-rise">+'+a.share_delta.hatebu+"</span>)"):0>a.share_delta.hatebu?b("span[data-scc='shatebu']").html(a.share_count.hatebu+' (<span class="delta-fall">'+
6
- a.share_delta.hatebu+"</span>)"):b("span[data-scc='shatebu']").html(a.share_count.hatebu),0<a.share_delta.pinterest?b("span[data-scc='spinterest']").html(a.share_count.pinterest+' (<span class="delta-rise">+'+a.share_delta.pinterest+"</span>)"):0>a.share_delta.pinterest?b("span[data-scc='spinterest']").html(a.share_count.pinterest+' (<span class="delta-fall">'+a.share_delta.pinterest+"</span>)"):b("span[data-scc='spinterest']").html(a.share_count.pinterest),0<a.share_delta.total?b("span[data-scc='stotal']").html(a.share_count.total+
7
- ' (<span class="delta-rise">+'+a.share_delta.total+"</span>)"):0>a.share_delta.total?b("span[data-scc='stotal']").html(a.share_count.total+' (<span class="delta-fall">'+a.share_delta.total+"</span>)"):b("span[data-scc='stotal']").html(a.share_count.total),b("span[data-scc='fpc']").text(a.follow.post_count),b("span[data-scc='fpfcc']").text(a.follow.primary.full_cache_count),b("span[data-scc='fppcc']").text(a.follow.primary.partial_cache_count),b("span[data-scc='fpncc']").text(a.follow.primary.no_cache_count),
8
- b("span[data-scc='fpcs']").text(a.follow.primary.cache_status),b("span[data-scc='fsfcc']").text(a.follow.secondary.full_cache_count),b("span[data-scc='fspcc']").text(a.follow.secondary.partial_cache_count),b("span[data-scc='fsncc']").text(a.follow.secondary.no_cache_count),b("span[data-scc='fscs']").text(a.follow.secondary.cache_status),c(a.follow_count)&&(c(a.follow_delta)&&0<a.follow_delta.twitter?b("span[data-scc='ftwitter']").html(a.follow_count.twitter+' (<span class="delta-rise">+'+a.follow_delta.twitter+
9
- "</span>)"):c(a.follow_delta)&&0>a.follow_delta.twitter?b("span[data-scc='ftwitter']").html(a.follow_count.twitter+' (<span class="delta-fall">'+a.follow_delta.twitter+"</span>)"):b("span[data-scc='ftwitter']").html(a.follow_count.twitter)),c(a.follow_count)&&(c(a.follow_delta)&&0<a.follow_delta.facebook?b("span[data-scc='ffacebook']").html(a.follow_count.facebook+' (<span class="delta-rise">+'+a.follow_delta.facebook+"</span>)"):c(a.follow_delta)&&0>a.follow_delta.facebook?b("span[data-scc='ffacebook']").html(a.follow_count.facebook+
10
- ' (<span class="delta-fall">'+a.follow_delta.facebook+"</span>)"):b("span[data-scc='ffacebook']").html(a.follow_count.facebook)),c(a.follow_count)&&(c(a.follow_delta)&&0<a.follow_delta.feedly?b("span[data-scc='ffeedly']").html(a.follow_count.feedly+' (<span class="delta-rise">+'+a.follow_delta.feedly+"</span>)"):c(a.follow_delta)&&0>a.follow_delta.feedly?b("span[data-scc='ffeedly']").html(a.follow_count.feedly+' (<span class="delta-fall">'+a.follow_delta.feedly+"</span>)"):b("span[data-scc='ffeedly']").html(a.follow_count.feedly)),
11
- c(a.follow_count)&&(c(a.follow_delta)&&0<a.follow_delta.push7?b("span[data-scc='fpush7']").html(a.follow_count.push7+' (<span class="delta-rise">+'+a.follow_delta.push7+"</span>)"):c(a.follow_delta)&&0>a.follow_delta.push7?b("span[data-scc='fpush7']").html(a.follow_count.push7+' (<span class="delta-fall">'+a.follow_delta.push7+"</span>)"):b("span[data-scc='fpush7']").html(a.follow_count.push7)),c(a.follow_count)&&(c(a.follow_delta)&&0<a.follow_delta.instagram?b("span[data-scc='finstagram']").html(a.follow_count.instagram+
12
- ' (<span class="delta-rise">+'+a.follow_delta.instagram+"</span>)"):c(a.follow_delta)&&0>a.follow_delta.instagram?b("span[data-scc='finstagram']").html(a.follow_count.instagram+' (<span class="delta-fall">'+a.follow_delta.instagram+"</span>)"):b("span[data-scc='finstagram']").html(a.follow_count.instagram)),b(".loading").css("display","none"),b("span[data-scc]").fadeIn()):b("span[data-scc]").text("?")},error:function(a){b("span[data-scc]").text("?")}})})});
 
1
+ ;jQuery(document).ready(function(b){return b("#scc-dashboard,#scc-dashboard-widget").each(function(){function c(a){return"undefined"!=typeof a}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?(console.log(a),b("span[data-scc='spc']").text(a.share.post_count),b("span[data-scc='spfcc']").text(a.share.primary.full_cache_count),b("span[data-scc='sppcc']").text(a.share.primary.partial_cache_count),
2
+ b("span[data-scc='spncc']").text(a.share.primary.no_cache_count),b("span[data-scc='spcs']").text(a.share.primary.cache_status),b("span[data-scc='ssfcc']").text(a.share.secondary.full_cache_count),b("span[data-scc='sspcc']").text(a.share.secondary.partial_cache_count),b("span[data-scc='ssncc']").text(a.share.secondary.no_cache_count),b("span[data-scc='sscs']").text(a.share.secondary.cache_status),0<a.share_delta.twitter?b("span[data-scc='stwitter']").html(a.share_count.twitter+' (<span class="delta-rise">+'+
3
+ a.share_delta.twitter+"</span>)"):0>a.share_delta.twitter?b("span[data-scc='stwitter']").html(a.share_count.twitter+' (<span class="delta-fall">'+a.share_delta.twitter+"</span>)"):b("span[data-scc='stwitter']").html(a.share_count.twitter),0<a.share_delta.facebook?b("span[data-scc='sfacebook']").html(a.share_count.facebook+' (<span class="delta-rise">+'+a.share_delta.facebook+"</span>)"):0>a.share_delta.facebook?b("span[data-scc='sfacebook']").html(a.share_count.facebook+' (<span class="delta-fall">'+
4
+ a.share_delta.facebook+"</span>)"):b("span[data-scc='sfacebook']").html(a.share_count.facebook),0<a.share_delta.gplus?b("span[data-scc='sgplus']").html(a.share_count.gplus+' (<span class="delta-rise">+'+a.share_delta.gplus+"</span>)"):0>a.share_delta.gplus?b("span[data-scc='sgplus']").html(a.share_count.gplus+' (<span class="delta-fall">'+a.share_delta.gplus+"</span>)"):b("span[data-scc='sgplus']").html(a.share_count.gplus),0<a.share_delta.pocket?b("span[data-scc='spocket']").html(a.share_count.pocket+
5
+ ' (<span class="delta-rise">+'+a.share_delta.pocket+"</span>)"):0>a.share_delta.pocket?b("span[data-scc='spocket']").html(a.share_count.pocket+' (<span class="delta-fall">'+a.share_delta.pocket+"</span>)"):b("span[data-scc='spocket']").html(a.share_count.pocket),0<a.share_delta.hatebu?b("span[data-scc='shatebu']").html(a.share_count.hatebu+' (<span class="delta-rise">+'+a.share_delta.hatebu+"</span>)"):0>a.share_delta.hatebu?b("span[data-scc='shatebu']").html(a.share_count.hatebu+' (<span class="delta-fall">'+
6
+ a.share_delta.hatebu+"</span>)"):b("span[data-scc='shatebu']").html(a.share_count.hatebu),0<a.share_delta.pinterest?b("span[data-scc='spinterest']").html(a.share_count.pinterest+' (<span class="delta-rise">+'+a.share_delta.pinterest+"</span>)"):0>a.share_delta.pinterest?b("span[data-scc='spinterest']").html(a.share_count.pinterest+' (<span class="delta-fall">'+a.share_delta.pinterest+"</span>)"):b("span[data-scc='spinterest']").html(a.share_count.pinterest),0<a.share_delta.linkedin?b("span[data-scc='slinkedin']").html(a.share_count.linkedin+
7
+ ' (<span class="delta-rise">+'+a.share_delta.linkedin+"</span>)"):0>a.share_delta.linkedin?b("span[data-scc='slinkedin']").html(a.share_count.linkedin+' (<span class="delta-fall">'+a.share_delta.linkedin+"</span>)"):b("span[data-scc='slinkedin']").html(a.share_count.linkedin),0<a.share_delta.total?b("span[data-scc='stotal']").html(a.share_count.total+' (<span class="delta-rise">+'+a.share_delta.total+"</span>)"):0>a.share_delta.total?b("span[data-scc='stotal']").html(a.share_count.total+' (<span class="delta-fall">'+
8
+ a.share_delta.total+"</span>)"):b("span[data-scc='stotal']").html(a.share_count.total),b("span[data-scc='fpc']").text(a.follow.post_count),b("span[data-scc='fpfcc']").text(a.follow.primary.full_cache_count),b("span[data-scc='fppcc']").text(a.follow.primary.partial_cache_count),b("span[data-scc='fpncc']").text(a.follow.primary.no_cache_count),b("span[data-scc='fpcs']").text(a.follow.primary.cache_status),b("span[data-scc='fsfcc']").text(a.follow.secondary.full_cache_count),b("span[data-scc='fspcc']").text(a.follow.secondary.partial_cache_count),
9
+ b("span[data-scc='fsncc']").text(a.follow.secondary.no_cache_count),b("span[data-scc='fscs']").text(a.follow.secondary.cache_status),c(a.follow_count)&&(c(a.follow_delta)&&0<a.follow_delta.twitter?b("span[data-scc='ftwitter']").html(a.follow_count.twitter+' (<span class="delta-rise">+'+a.follow_delta.twitter+"</span>)"):c(a.follow_delta)&&0>a.follow_delta.twitter?b("span[data-scc='ftwitter']").html(a.follow_count.twitter+' (<span class="delta-fall">'+a.follow_delta.twitter+"</span>)"):b("span[data-scc='ftwitter']").html(a.follow_count.twitter)),
10
+ c(a.follow_count)&&(c(a.follow_delta)&&0<a.follow_delta.facebook?b("span[data-scc='ffacebook']").html(a.follow_count.facebook+' (<span class="delta-rise">+'+a.follow_delta.facebook+"</span>)"):c(a.follow_delta)&&0>a.follow_delta.facebook?b("span[data-scc='ffacebook']").html(a.follow_count.facebook+' (<span class="delta-fall">'+a.follow_delta.facebook+"</span>)"):b("span[data-scc='ffacebook']").html(a.follow_count.facebook)),c(a.follow_count)&&(c(a.follow_delta)&&0<a.follow_delta.feedly?b("span[data-scc='ffeedly']").html(a.follow_count.feedly+
11
+ ' (<span class="delta-rise">+'+a.follow_delta.feedly+"</span>)"):c(a.follow_delta)&&0>a.follow_delta.feedly?b("span[data-scc='ffeedly']").html(a.follow_count.feedly+' (<span class="delta-fall">'+a.follow_delta.feedly+"</span>)"):b("span[data-scc='ffeedly']").html(a.follow_count.feedly)),c(a.follow_count)&&(c(a.follow_delta)&&0<a.follow_delta.push7?b("span[data-scc='fpush7']").html(a.follow_count.push7+' (<span class="delta-rise">+'+a.follow_delta.push7+"</span>)"):c(a.follow_delta)&&0>a.follow_delta.push7?
12
+ b("span[data-scc='fpush7']").html(a.follow_count.push7+' (<span class="delta-fall">'+a.follow_delta.push7+"</span>)"):b("span[data-scc='fpush7']").html(a.follow_count.push7)),c(a.follow_count)&&(c(a.follow_delta)&&0<a.follow_delta.instagram?b("span[data-scc='finstagram']").html(a.follow_count.instagram+' (<span class="delta-rise">+'+a.follow_delta.instagram+"</span>)"):c(a.follow_delta)&&0>a.follow_delta.instagram?b("span[data-scc='finstagram']").html(a.follow_count.instagram+' (<span class="delta-fall">'+
13
+ a.follow_delta.instagram+"</span>)"):b("span[data-scc='finstagram']").html(a.follow_count.instagram)),b(".loading").css("display","none"),b("span[data-scc]").fadeIn()):b("span[data-scc]").text("?")},error:function(a){b("span[data-scc]").text("?")}})})});
languages/sns-count-cache-ja.mo CHANGED
Binary file
languages/sns-count-cache-ja.po CHANGED
@@ -1,1520 +1,1824 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: SNS Count Cache\n"
4
- "POT-Creation-Date: 2016-09-26 01:16+0900\n"
5
- "PO-Revision-Date: 2016-09-26 01:17+0900\n"
6
- "Last-Translator: Daisuke Maruyama <marubon@gmail.com>\n"
7
- "Language-Team: Daisuke Maruyama <marubon@gmail.com>\n"
8
- "Language: ja\n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "X-Generator: Poedit 1.8.7\n"
13
- "X-Poedit-Basepath: ..\n"
14
- "X-Poedit-WPHeader: sns-count-cache.php\n"
15
- "Plural-Forms: nplurals=1; plural=0;\n"
16
- "X-Poedit-SourceCharset: UTF-8\n"
17
- "X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
18
- "esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
19
- "_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
20
- "X-Poedit-SearchPath-0: .\n"
21
- "X-Poedit-SearchPathExcluded-0: *.js\n"
22
-
23
- #. Plugin Name of the plugin/theme
24
- #: includes/admin-cache-status.php:65 includes/admin-dashboard.php:43
25
- #: includes/admin-help.php:34 includes/admin-hot-content.php:69
26
- #: includes/admin-setting.php:437 includes/admin-share-count.php:67
27
- #: sns-count-cache.php:1670
28
- msgid "SNS Count Cache"
29
- msgstr "SNS Count Cache"
30
-
31
- #: includes/admin-cache-status.php:68 includes/admin-dashboard.php:47
32
- #: includes/admin-help.php:37 includes/admin-hot-content.php:72
33
- #: includes/admin-setting.php:526 includes/admin-share-count.php:70
34
- #: sns-count-cache.php:1671
35
- msgid "Dashboard"
36
- msgstr "ダッシュボード"
37
-
38
- #: includes/admin-cache-status.php:69 includes/admin-cache-status.php:80
39
- #: includes/admin-dashboard-widget.php:47
40
- #: includes/admin-dashboard-widget.php:147 includes/admin-dashboard.php:48
41
- #: includes/admin-dashboard.php:61 includes/admin-dashboard.php:166
42
- #: includes/admin-help.php:38 includes/admin-help.php:64
43
- #: includes/admin-hot-content.php:73 includes/admin-setting.php:527
44
- #: includes/admin-share-count.php:71 sns-count-cache.php:1672
45
- msgid "Cache Status"
46
- msgstr "キャッシュ状況"
47
-
48
- #: includes/admin-cache-status.php:70 includes/admin-dashboard-widget.php:82
49
- #: includes/admin-dashboard.php:49 includes/admin-dashboard.php:96
50
- #: includes/admin-help.php:39 includes/admin-hot-content.php:74
51
- #: includes/admin-setting.php:528 includes/admin-share-count.php:72
52
- #: includes/admin-share-count.php:82 sns-count-cache.php:1673
53
- msgid "Share Count"
54
- msgstr "シェア数"
55
-
56
- #: includes/admin-cache-status.php:72 includes/admin-dashboard.php:51
57
- #: includes/admin-help.php:41 includes/admin-hot-content.php:75
58
- #: includes/admin-hot-content.php:82 includes/admin-setting.php:530
59
- #: includes/admin-share-count.php:74 sns-count-cache.php:1676
60
- msgid "Hot Content"
61
- msgstr "話題のコンテンツ"
62
-
63
- #: includes/admin-cache-status.php:74 includes/admin-dashboard.php:53
64
- #: includes/admin-help.php:43 includes/admin-hot-content.php:76
65
- #: includes/admin-setting.php:532 includes/admin-share-count.php:76
66
- #: sns-count-cache.php:1679
67
- msgid "Setting"
68
- msgstr "設定"
69
-
70
- #: includes/admin-cache-status.php:75 includes/admin-dashboard.php:54
71
- #: includes/admin-help.php:44 includes/admin-help.php:49
72
- #: includes/admin-hot-content.php:77 includes/admin-setting.php:533
73
- #: includes/admin-share-count.php:77 sns-count-cache.php:1680
74
- msgid "Help"
75
- msgstr "ヘルプ"
76
-
77
- #: includes/admin-cache-status.php:86 includes/admin-hot-content.php:88
78
- #: includes/admin-share-count.php:88
79
- msgid "Content"
80
- msgstr "コンテンツ"
81
-
82
- #: includes/admin-cache-status.php:87 includes/admin-dashboard-widget.php:61
83
- #: includes/admin-dashboard-widget.php:161 includes/admin-dashboard.php:75
84
- #: includes/admin-dashboard.php:180
85
- msgid "Primary Cache"
86
- msgstr "一次キャッシュ"
87
-
88
- #: includes/admin-cache-status.php:88 includes/admin-dashboard-widget.php:71
89
- #: includes/admin-dashboard-widget.php:171 includes/admin-dashboard.php:85
90
- #: includes/admin-dashboard.php:190
91
- msgid "Secondary Cache"
92
- msgstr "二次キャッシュ"
93
-
94
- #: includes/admin-cache-status.php:89
95
- msgid "Crawl Date"
96
- msgstr "クロール日時"
97
-
98
- #: includes/admin-cache-status.php:128 includes/admin-cache-status.php:167
99
- #: includes/admin-cache-status.php:225 includes/admin-cache-status.php:257
100
- #: includes/admin-help.php:69
101
- msgid "full cache"
102
- msgstr "完全キャッシュ"
103
-
104
- #: includes/admin-cache-status.php:132 includes/admin-cache-status.php:171
105
- #: includes/admin-cache-status.php:229 includes/admin-cache-status.php:261
106
- #: includes/admin-help.php:70
107
- msgid "partial cache"
108
- msgstr "部分キャッシュ"
109
-
110
- #: includes/admin-cache-status.php:136 includes/admin-cache-status.php:142
111
- #: includes/admin-cache-status.php:175 includes/admin-cache-status.php:207
112
- #: includes/admin-cache-status.php:233 includes/admin-cache-status.php:265
113
- #: includes/admin-help.php:71
114
- msgid "no cache"
115
- msgstr "未キャッシュ"
116
-
117
- #: includes/admin-cache-status.php:184 includes/admin-cache-status.php:284
118
- msgid "no data"
119
- msgstr "データなし"
120
-
121
- #: includes/admin-cache-status.php:191 includes/admin-cache-status.php:292
122
- #: includes/admin-setting.php:402 includes/admin-setting.php:1421
123
- msgid "Cache"
124
- msgstr "キャッシュ"
125
-
126
- #: includes/admin-dashboard-widget.php:46 includes/admin-dashboard.php:59
127
- msgid "Share"
128
- msgstr "Share"
129
-
130
- #: includes/admin-dashboard-widget.php:51
131
- #: includes/admin-dashboard-widget.php:151 includes/admin-dashboard.php:65
132
- #: includes/admin-dashboard.php:170
133
- msgid "Cache Type"
134
- msgstr "キャッシュタイプ"
135
-
136
- #: includes/admin-dashboard-widget.php:52
137
- #: includes/admin-dashboard-widget.php:152 includes/admin-dashboard.php:66
138
- #: includes/admin-dashboard.php:171
139
- msgid "Cache Progress"
140
- msgstr "キャッシュ進捗"
141
-
142
- #: includes/admin-dashboard-widget.php:53
143
- #: includes/admin-dashboard-widget.php:153 includes/admin-dashboard.php:67
144
- #: includes/admin-dashboard.php:172
145
- msgid "Total Content"
146
- msgstr "総コンテンツ数"
147
-
148
- #: includes/admin-dashboard-widget.php:54
149
- #: includes/admin-dashboard-widget.php:154 includes/admin-dashboard.php:68
150
- #: includes/admin-dashboard.php:173
151
- msgid "State - Full Cache"
152
- msgstr "状態 - 完全キャッシュ"
153
-
154
- #: includes/admin-dashboard-widget.php:55
155
- #: includes/admin-dashboard-widget.php:155 includes/admin-dashboard.php:69
156
- #: includes/admin-dashboard.php:174
157
- msgid "State - Partial Cache"
158
- msgstr "状態 - 部分キャッシュ"
159
-
160
- #: includes/admin-dashboard-widget.php:56
161
- #: includes/admin-dashboard-widget.php:156 includes/admin-dashboard.php:70
162
- #: includes/admin-dashboard.php:175
163
- msgid "State - No Cache"
164
- msgstr "状態 - 未キャッシュ"
165
-
166
- #: includes/admin-dashboard-widget.php:96
167
- #: includes/admin-dashboard-widget.php:196 includes/admin-dashboard.php:110
168
- #: includes/admin-dashboard.php:215 includes/admin-hot-content.php:104
169
- #: includes/admin-setting.php:934 includes/admin-setting.php:1407
170
- #: includes/admin-share-count.php:104
171
- msgid "Twitter"
172
- msgstr "Twitter"
173
-
174
- #: includes/admin-dashboard-widget.php:99
175
- #: includes/admin-dashboard-widget.php:199 includes/admin-dashboard.php:113
176
- #: includes/admin-dashboard.php:218 includes/admin-hot-content.php:107
177
- #: includes/admin-setting.php:914 includes/admin-setting.php:1395
178
- #: includes/admin-share-count.php:107
179
- msgid "Facebook"
180
- msgstr "Facebook"
181
-
182
- #: includes/admin-dashboard-widget.php:102 includes/admin-dashboard.php:116
183
- #: includes/admin-hot-content.php:110 includes/admin-setting.php:918
184
- #: includes/admin-share-count.php:110
185
- msgid "Google+"
186
- msgstr "Google+"
187
-
188
- #: includes/admin-dashboard-widget.php:105 includes/admin-dashboard.php:119
189
- #: includes/admin-hot-content.php:113 includes/admin-setting.php:930
190
- #: includes/admin-share-count.php:113
191
- msgid "Pocket"
192
- msgstr "Pocket"
193
-
194
- #: includes/admin-dashboard-widget.php:108 includes/admin-dashboard.php:122
195
- #: includes/admin-hot-content.php:116 includes/admin-share-count.php:116
196
- msgid "Hatebu"
197
- msgstr "はてブ"
198
-
199
- #: includes/admin-dashboard-widget.php:111 includes/admin-dashboard.php:125
200
- #: includes/admin-hot-content.php:119 includes/admin-setting.php:926
201
- #: includes/admin-share-count.php:119
202
- msgid "Pinterest"
203
- msgstr "Pinterest"
204
-
205
- #: includes/admin-dashboard-widget.php:114 includes/admin-dashboard.php:128
206
- #: includes/admin-hot-content.php:122 includes/admin-share-count.php:122
207
- msgid "Total"
208
- msgstr "合計"
209
-
210
- #: includes/admin-dashboard-widget.php:146 includes/admin-dashboard.php:164
211
- msgid "Follow"
212
- msgstr "Follow"
213
-
214
- #: includes/admin-dashboard-widget.php:182
215
- msgid "Follower Count"
216
- msgstr "フォロワー数"
217
-
218
- #: includes/admin-dashboard-widget.php:202 includes/admin-dashboard.php:221
219
- #: includes/admin-setting.php:1399
220
- msgid "Feedly"
221
- msgstr "Feedly"
222
-
223
- #: includes/admin-dashboard-widget.php:205 includes/admin-dashboard.php:224
224
- #: includes/admin-setting.php:1391
225
- msgid "Instagram"
226
- msgstr "Instagram"
227
-
228
- #: includes/admin-dashboard-widget.php:208 includes/admin-dashboard.php:227
229
- #: includes/admin-setting.php:1403
230
- msgid "Push7"
231
- msgstr "Push7"
232
-
233
- #: includes/admin-dashboard.php:201
234
- msgid "Follow Count"
235
- msgstr "フォロー数"
236
-
237
- #: includes/admin-help.php:51
238
- msgid "What is WordPress plugin SNS Cout Cache?"
239
- msgstr "WordPressプラグイン SNS Count Cacheとは何か?"
240
-
241
- #: includes/admin-help.php:52
242
- msgid ""
243
- "WordPress plugin SNS Count Cache is a plugin which helps you to shorten page "
244
- "loading time when your site displays share and follower counts. This plugin "
245
- "gets share counts such as Twitter and Facebook, Google+, Pocket, Pinterest "
246
- "and caches these counts in the background. This plugin alse caches follower "
247
- "counts such as Twitter and Facebook, Feedly, Instagram, Push7 in the same "
248
- "way. The share and follower counts can be retrieved quickly not through "
249
- "network but through the cache using given functions."
250
- msgstr ""
251
- "WordPressプラグイン SNS Count Cacheは、シェア数やフォロワー数を表示している場"
252
- "合にページの表示時間を高速化するプラグインです。このプラグインは、Twitter、"
253
- "Facebook、Google+、Pocket、Pinterest、はてなブックマークのシェア数をバックグ"
254
- "ラウンドで取得し、キャッシュします。またTwitter、Facebook、Feedly、"
255
- "Instagram、Push7のフォロワー数も同様の方法でキャッシュします。これらのシェア"
256
- "数とフォロワー数は、所定の関数を用いることでネットワークからではなくキャッ"
257
- "シュ経由で迅速に取得可能になります。"
258
-
259
- #: includes/admin-help.php:53
260
- msgid "How often does this plugin get and cache share counts?"
261
- msgstr "シェア数を取得、キャッシュする頻度は?"
262
-
263
- #: includes/admin-help.php:54
264
- msgid ""
265
- "Although this plugin gets share count of 20 posts at a time every 10 minutes "
266
- "by default, you can modify the setting in the \"Setting\" tab in the "
267
- "administration page."
268
- msgstr ""
269
- "デフォルトで10分ごとに20記事のシェア数を取得しますが、管理ページの「設定」タ"
270
- "ブにてその取得間隔と一度に取得対象とする記事数を変更できます。"
271
-
272
- #: includes/admin-help.php:55
273
- msgid "How can I know whether share count of each post is cached or not?"
274
- msgstr "各記事のシェア数のキャッシュ有無を確認する方法は?"
275
-
276
- #: includes/admin-help.php:56
277
- msgid ""
278
- "Cache status is described in the \"Cache Status\" tab in the administration "
279
- "page."
280
- msgstr "キャッシュ状況は、管理ページの「キャッシュ状況」タブにて確認可能です。"
281
-
282
- #: includes/admin-help.php:57
283
- msgid "How often does this plugin get and cache follower counts?"
284
- msgstr "フォロワー数を取得、キャッシュする頻度は?"
285
-
286
- #: includes/admin-help.php:58
287
- msgid ""
288
- "Although this plugin gets follower count once a day by default, you can "
289
- "modify the setting in the \"Setting\" tab in the administration page."
290
- msgstr ""
291
- "デフォルトで1日に一回フォロワー数を取得しますが、管理ページの「設定」タブにて"
292
- "その取得間隔を変更できます。"
293
-
294
- #: includes/admin-help.php:59
295
- msgid ""
296
- "What is cache status such as \"full cache\", \"partial cache\" and \"no cache"
297
- "\"?"
298
- msgstr ""
299
- "「完全キャッシュ」、「部分キャッシュ」、「未キャッシュ」等のキャッシュ状況と"
300
- "は何か?"
301
-
302
- #: includes/admin-help.php:60
303
- msgid "The following is the explanation of the cache status."
304
- msgstr "以下は、そのキャッシュ状況に関する説明です。"
305
-
306
- #: includes/admin-help.php:65 includes/admin-help.php:80
307
- #: includes/admin-help.php:99 includes/admin-help.php:170
308
- #: includes/admin-help.php:189
309
- msgid "Description"
310
- msgstr "説明"
311
-
312
- #: includes/admin-help.php:69
313
- msgid "Counts for selected all SNS are cached."
314
- msgstr "選択された全てのSNSのカウントがキャッシュされています。"
315
-
316
- #: includes/admin-help.php:70
317
- msgid "A subset of counts for selected SNS are cached."
318
- msgstr "選択された一部のSNSのカウントがキャッシュされています。"
319
-
320
- #: includes/admin-help.php:71
321
- msgid "Count for selected SNS are not cached at all."
322
- msgstr "選択されたSNSのカウントが全くキャッシュされていません。"
323
-
324
- #: includes/admin-help.php:74
325
- msgid "How can I get share count from the cache?"
326
- msgstr "キャッシュからSNSカウントを参照する方法は?"
327
-
328
- #: includes/admin-help.php:75
329
- msgid ""
330
- "The share count is retrieved from the cache using the following functions in "
331
- "the WordPress loop such as query_posts(), get_posts() and WP_Query()."
332
- msgstr ""
333
- "WordPressのquery_posts()、get_posts()、WP_Query()等のループ内で下記の関数を使"
334
- "うことでキャッシュからSNSカウントを参照できます。"
335
-
336
- #: includes/admin-help.php:79 includes/admin-help.php:98
337
- msgid "Function"
338
- msgstr "関数"
339
-
340
- #: includes/admin-help.php:84
341
- msgid "Twitter share count is returned from cache."
342
- msgstr "キャッシュからTwitterのシェア数を取得します。"
343
-
344
- #: includes/admin-help.php:85
345
- msgid "Facebook share count is returned from cache."
346
- msgstr "キャッシュからFacebookのシェア数を取得します。"
347
-
348
- #: includes/admin-help.php:86
349
- msgid "Google Plus share count is returned from cache."
350
- msgstr "キャッシュからGoogle+のシェア数を取得します。"
351
-
352
- #: includes/admin-help.php:87
353
- msgid "Hatena Bookmark share count is returned from cache."
354
- msgstr "キャッシュからはてなブックマークのシェア数を取得します。"
355
-
356
- #: includes/admin-help.php:88
357
- msgid "Pocket share count is returned from cache."
358
- msgstr "キャッシュからPocketのシェア数を取得します。"
359
-
360
- #: includes/admin-help.php:89
361
- msgid "Pinterest share count is returned from cache."
362
- msgstr "キャッシュからPinterestのシェア数を取得します。"
363
-
364
- #: includes/admin-help.php:90
365
- msgid "Total share count of selected SNS is returned from cache."
366
- msgstr "キャッシュから対象として設定されたSNSのカウントの総和を取得します。"
367
-
368
- #: includes/admin-help.php:93
369
- msgid "How can I get follower count from the cache?"
370
- msgstr "キャッシュからフォロワーの数を参照する方法は?"
371
-
372
- #: includes/admin-help.php:94
373
- msgid ""
374
- "The follower count is retrieved from the cache using the following functions."
375
- msgstr "フォロワーの数は、以下の関数を用いることでキャッシュから参照可能です。"
376
-
377
- #: includes/admin-help.php:103
378
- msgid "Feedly follower count is returned from cache."
379
- msgstr "キャッシュからFeedlyのフォロワーの数を取得します。"
380
-
381
- #: includes/admin-help.php:104
382
- msgid "Twitter follower count is returned from cache."
383
- msgstr "キャッシュからTwitterのフォロワーの数を取得します。"
384
-
385
- #: includes/admin-help.php:105
386
- msgid "Facebook follower count is returned from cache."
387
- msgstr "キャッシュからFacebookのフォロワーの数を取得します。"
388
-
389
- #: includes/admin-help.php:106
390
- msgid "Instagram follower count is returned from cache."
391
- msgstr "キャッシュからInstagramのフォロワーの数を取得します。"
392
-
393
- #: includes/admin-help.php:107
394
- msgid "Push7 follower count is returned from cache."
395
- msgstr "キャッシュからPush7のフォロワーの数を取得します。"
396
-
397
- #: includes/admin-help.php:110
398
- msgid "Example Code"
399
- msgstr "サンプルコード"
400
-
401
- #: includes/admin-help.php:111
402
- msgid ""
403
- "The code below describes a simple example which displays share count and "
404
- "follower count using the above functions."
405
- msgstr ""
406
- "以下のコードは、上述した関数を用いてシェア数やフォロワー数を表示する簡単な例"
407
- "です。"
408
-
409
- #: includes/admin-help.php:164
410
- msgid "How can I access specific custom field containing each share count?"
411
- msgstr "シェア数を含むカスタムフィールドにアクセスする方法は?"
412
-
413
- #: includes/admin-help.php:165
414
- msgid ""
415
- "Custom fields including share count are accessed using the following meta "
416
- "keys."
417
- msgstr ""
418
- "シェア数を含むカスタムフィールドは、以下のmeta keyを用いて参照可能です。"
419
-
420
- #: includes/admin-help.php:169 includes/admin-help.php:188
421
- msgid "Meta Key"
422
- msgstr "Meta Key"
423
-
424
- #: includes/admin-help.php:174
425
- msgid "A meta key to access Twitter share count"
426
- msgstr "Twitterのシェア数にアクセスするためのMeta Keyです。"
427
-
428
- #: includes/admin-help.php:175
429
- msgid "A meta key to access Facebook share count"
430
- msgstr "Facebookのシェア数にアクセスするためのMeta Keyです。"
431
-
432
- #: includes/admin-help.php:176
433
- msgid "A meta key to access Google+ share count"
434
- msgstr "Google+のシェア数にアクセスするためのMeta Keyです。"
435
-
436
- #: includes/admin-help.php:177
437
- msgid "A meta key to access Hatena Bookmark share count"
438
- msgstr "はてなブックマークのシェア数にアクセスするためのMeta Keyです。"
439
-
440
- #: includes/admin-help.php:178
441
- msgid "A meta key to access Pocket share count"
442
- msgstr "Pocketのシェア数にアクセスするためのMeta Keyです。"
443
-
444
- #: includes/admin-help.php:179
445
- msgid "A meta key to access Pinterest share count"
446
- msgstr "Pinterestのシェア数にアクセスするためのMeta Keyです。"
447
-
448
- #: includes/admin-help.php:180
449
- msgid "A meta key to access total share count"
450
- msgstr "シェア数の合計にアクセスするためのMeta Keyです。"
451
-
452
- #: includes/admin-help.php:183
453
- msgid ""
454
- "How can I access specific custom field containing each variation of share "
455
- "count?"
456
- msgstr "シェア数の増減を含むカスタムフィールドにアクセスする方法は?"
457
-
458
- #: includes/admin-help.php:184
459
- msgid ""
460
- "Custom fields including variation of share count are accessed using the "
461
- "following meta keys."
462
- msgstr ""
463
- "シェア数の増減を含むカスタムフィールドは、以下のmeta keyを用いて参照可能で"
464
- "す。"
465
-
466
- #: includes/admin-help.php:193
467
- msgid "A meta key to access variation of Twitter share count"
468
- msgstr "Twitterのシェア数の増減数にアクセスするためのMeta Keyです。"
469
-
470
- #: includes/admin-help.php:194
471
- msgid "A meta key to access variation of Facebook share count"
472
- msgstr "Facebookのシェア数の増減数にアクセスするためのMeta Keyです。"
473
-
474
- #: includes/admin-help.php:195
475
- msgid "A meta key to access variation of Google+ share count"
476
- msgstr "Google+のシェア数の増減数にアクセスするためのMeta Keyです。"
477
-
478
- #: includes/admin-help.php:196
479
- msgid "A meta key to access variation of Hatena Bookmark share count"
480
- msgstr "はてなブックマークのシェア数の増減数にアクセスするためのMeta Keyです。"
481
-
482
- #: includes/admin-help.php:197
483
- msgid "A meta key to access variation of Pocket share count"
484
- msgstr "Pocketのシェア数の増減数にアクセスするためのMeta Keyです。"
485
-
486
- #: includes/admin-help.php:198
487
- msgid "A meta key to access variation of Pinterest share count"
488
- msgstr "Pinterestのシェア数の増減数にアクセスするためのMeta Keyです。"
489
-
490
- #: includes/admin-help.php:199
491
- msgid "A meta key to access variation of total share count"
492
- msgstr "シェア数合計の増減数にアクセスするためのMeta Keyです。"
493
-
494
- #: includes/admin-hot-content.php:267 includes/admin-hot-content.php:296
495
- #: includes/admin-hot-content.php:314 includes/admin-setting.php:594
496
- #: includes/admin-setting.php:631 includes/admin-setting.php:784
497
- #: includes/admin-setting.php:799 includes/admin-share-count.php:191
498
- #: includes/admin-share-count.php:205 includes/admin-share-count.php:233
499
- #: includes/admin-share-count.php:247 includes/admin-share-count.php:257
500
- #: includes/admin-share-count.php:285 includes/admin-share-count.php:299
501
- #: includes/admin-share-count.php:327 includes/admin-share-count.php:341
502
- #: includes/admin-share-count.php:351 includes/admin-share-count.php:394
503
- #: includes/admin-share-count.php:425
504
- msgid "N/A"
505
- msgstr "N/A"
506
-
507
- #: includes/admin-hot-content.php:310
508
- msgid "No hot content."
509
- msgstr "話題のコンテンツはありません。"
510
-
511
- #: includes/admin-setting.php:37 includes/admin-setting.php:988
512
- #: includes/admin-setting.php:1027 includes/admin-setting.php:1067
513
- #: includes/admin-setting.php:1115 includes/admin-setting.php:1376
514
- #: includes/admin-setting.php:1420 includes/admin-setting.php:1478
515
- #: includes/admin-setting.php:1546 includes/admin-setting.php:1579
516
- #: includes/admin-setting.php:1600 includes/admin-setting.php:1658
517
- #: includes/admin-setting.php:1683 includes/admin-setting.php:1704
518
- #: includes/admin-setting.php:1740 includes/admin-setting.php:2028
519
- msgid "Update All Options"
520
- msgstr "設定の更新"
521
-
522
- #: includes/admin-setting.php:341 includes/admin-setting.php:2083
523
- msgid "Reset"
524
- msgstr "リセット"
525
-
526
- #: includes/admin-setting.php:349 includes/admin-setting.php:2065
527
- msgid "Export"
528
- msgstr "エクスポート"
529
-
530
- #: includes/admin-setting.php:361 includes/admin-setting.php:1377
531
- msgid "Update Basis of Comparison"
532
- msgstr "比較基準の更新"
533
-
534
- #: includes/admin-setting.php:373 includes/admin-setting.php:388
535
- #: includes/admin-setting.php:989 includes/admin-setting.php:1422
536
- msgid "Clear Cache"
537
- msgstr "キャッシュの消去"
538
-
539
- #: includes/admin-setting.php:414 includes/admin-setting.php:1636
540
- #: includes/admin-setting.php:1660
541
- msgid "Get Bearer Token"
542
- msgstr "Bearer Tokenの取得"
543
-
544
- #: includes/admin-setting.php:462
545
- msgid ""
546
- "There was a problem spawning a call to the WP-Cron system on your site. This "
547
- "means WP-Cron jobs on your site may not work. The problem was: "
548
- msgstr ""
549
- "あなたのサイト上でWP-Cronシステムの呼び出し処理に問題が見つかりました。あなた"
550
- "のサイト上でWP-Cronジョブが動作しない可能性があります。問題は次の通りです。"
551
-
552
- #: includes/admin-setting.php:472
553
- msgid ""
554
- "Configuratin is not enough to get share count. Please set required "
555
- "parameters at "
556
- msgstr ""
557
- "シェア数を取得するために必要な設定が不足しています。次のセクションで必要なパ"
558
- "ラメータを設定して下さい。"
559
-
560
- #: includes/admin-setting.php:473 includes/admin-setting.php:996
561
- msgid "Share Base Cache - Facebook"
562
- msgstr "シェア基本キャッシュ - Facebook"
563
-
564
- #: includes/admin-setting.php:483 includes/admin-setting.php:494
565
- #: includes/admin-setting.php:505 includes/admin-setting.php:516
566
- msgid ""
567
- "Configuratin is not enough to get follower count. Please set required "
568
- "parameters at "
569
- msgstr ""
570
- "フォロワー数を取得するために必要な設定が不足しています。次のセクションで必要"
571
- "なパラメータを設定して下さい。"
572
-
573
- #: includes/admin-setting.php:484 includes/admin-setting.php:1429
574
- msgid "Follow Base Cache - Instagram"
575
- msgstr "フォロー基本キャシュ機能 - Instagram"
576
-
577
- #: includes/admin-setting.php:495 includes/admin-setting.php:792
578
- #: includes/admin-setting.php:1489
579
- msgid "Follow Base Cache - Facebook"
580
- msgstr "フォロー基本キャッシュ機能 - Facebook"
581
-
582
- #: includes/admin-setting.php:506 includes/admin-setting.php:1587
583
- msgid "Follow Base Cache - Push7"
584
- msgstr "フォロー基本キャッシュ機能 - Push7"
585
-
586
- #: includes/admin-setting.php:517 includes/admin-setting.php:777
587
- #: includes/admin-setting.php:1608
588
- msgid "Follow Base Cache - Twitter"
589
- msgstr "フォロー基本キャッシュ機能 - Twitter"
590
-
591
- #: includes/admin-setting.php:536 includes/admin-setting.php:541
592
- msgid "Current Setting"
593
- msgstr "現在の設定"
594
-
595
- #: includes/admin-setting.php:536 includes/admin-setting.php:553
596
- #: includes/admin-setting.php:587 includes/admin-setting.php:600
597
- #: includes/admin-setting.php:605 includes/admin-setting.php:610
598
- #: includes/admin-setting.php:624 includes/admin-setting.php:906
599
- msgid "Share Base Cache"
600
- msgstr "シェア基本キャッシュ機能"
601
-
602
- #: includes/admin-setting.php:536 includes/admin-setting.php:656
603
- #: includes/admin-setting.php:669 includes/admin-setting.php:677
604
- #: includes/admin-setting.php:1074
605
- msgid "Share Rush Cache"
606
- msgstr "シェア臨時キャッシュ機能"
607
-
608
- #: includes/admin-setting.php:536 includes/admin-setting.php:683
609
- #: includes/admin-setting.php:704 includes/admin-setting.php:1121
610
- msgid "Share Variation Analysis"
611
- msgstr "シェア変動分析機能"
612
-
613
- #: includes/admin-setting.php:536 includes/admin-setting.php:712
614
- #: includes/admin-setting.php:737 includes/admin-setting.php:1383
615
- msgid "Follow Base Cache"
616
- msgstr "フォロー基本キャッシュ機能"
617
-
618
- #: includes/admin-setting.php:536 includes/admin-setting.php:806
619
- #: includes/admin-setting.php:1668
620
- msgid "Dynamic Cache"
621
- msgstr "動的キャッシュ機能"
622
-
623
- #: includes/admin-setting.php:536 includes/admin-setting.php:824
624
- #: includes/admin-setting.php:1689
625
- msgid "Fault Tolerance"
626
- msgstr "フォールトトレランス機能"
627
-
628
- #: includes/admin-setting.php:536 includes/admin-setting.php:842
629
- #: includes/admin-setting.php:858 includes/admin-setting.php:1710
630
- msgid "Data Crawler"
631
- msgstr "データクローラ機能"
632
-
633
- #: includes/admin-setting.php:536 includes/admin-setting.php:871
634
- #: includes/admin-setting.php:889 includes/admin-setting.php:1746
635
- msgid "Data Export"
636
- msgstr "データエクスポート機能"
637
-
638
- #: includes/admin-setting.php:536 includes/admin-setting.php:2037
639
- msgid "Exported File"
640
- msgstr "エクスポートされたファイル"
641
-
642
- #: includes/admin-setting.php:546
643
- msgid "Capability"
644
- msgstr "機能"
645
-
646
- #: includes/admin-setting.php:547
647
- msgid "Parameter"
648
- msgstr "パラメータ"
649
-
650
- #: includes/admin-setting.php:548
651
- msgid "Value"
652
- msgstr "値"
653
-
654
- #: includes/admin-setting.php:554 includes/admin-setting.php:713
655
- #: includes/admin-setting.php:910 includes/admin-setting.php:1387
656
- msgid "Target SNS"
657
- msgstr "対象SNS"
658
-
659
- #: includes/admin-setting.php:566 includes/admin-setting.php:922
660
- msgid "Hatena Bookmark"
661
- msgstr "はてなブックマーク"
662
-
663
- #: includes/admin-setting.php:588 includes/admin-setting.php:939
664
- msgid "Custom post types"
665
- msgstr "カスタム投稿タイプ"
666
-
667
- #: includes/admin-setting.php:601 includes/admin-setting.php:670
668
- #: includes/admin-setting.php:947 includes/admin-setting.php:1100
669
- msgid "Interval cheking share count (sec)"
670
- msgstr "シェア数のチェック間隔(秒)"
671
-
672
- #: includes/admin-setting.php:602 includes/admin-setting.php:673
673
- #: includes/admin-setting.php:739
674
- msgid "seconds"
675
- msgstr "秒"
676
-
677
- #: includes/admin-setting.php:606 includes/admin-setting.php:678
678
- #: includes/admin-setting.php:954 includes/admin-setting.php:1107
679
- msgid "Number of contents to check at a time"
680
- msgstr "一度にチェックするコンテンツ数"
681
-
682
- #: includes/admin-setting.php:607 includes/admin-setting.php:679
683
- msgid "contents"
684
- msgstr "コンテンツ"
685
-
686
- #: includes/admin-setting.php:611 includes/admin-setting.php:961
687
- msgid "Scheme migration mode from http to https"
688
- msgstr "HTTPからHTTPSへのスキーム移行モード"
689
-
690
- #: includes/admin-setting.php:615 includes/admin-setting.php:863
691
- #: includes/admin-setting.php:965 includes/admin-setting.php:1733
692
- msgid "On"
693
- msgstr "有効"
694
-
695
- #: includes/admin-setting.php:617 includes/admin-setting.php:865
696
- #: includes/admin-setting.php:964 includes/admin-setting.php:1732
697
- msgid "Off"
698
- msgstr "無効"
699
-
700
- #: includes/admin-setting.php:625 includes/admin-setting.php:972
701
- msgid "Scheme migration date from http to https"
702
- msgstr "HTTPからHTTPSへのスキーム移行日"
703
-
704
- #: includes/admin-setting.php:640 includes/admin-setting.php:1035
705
- msgid "Share Base Cache - Twitter"
706
- msgstr "シェア基本キャッシュ機能 - Twitter"
707
-
708
- #: includes/admin-setting.php:641 includes/admin-setting.php:1039
709
- msgid "Alternative Twitter API"
710
- msgstr "代替Twitter API"
711
-
712
- #: includes/admin-setting.php:657 includes/admin-setting.php:1078
713
- msgid "Term considering posted content as new content"
714
- msgstr "投稿日からコンテンツを新着とみなす期間"
715
-
716
- #: includes/admin-setting.php:661
717
- msgid "day"
718
- msgstr "日"
719
-
720
- #: includes/admin-setting.php:663
721
- msgid "days"
722
- msgstr "日"
723
-
724
- #: includes/admin-setting.php:684 includes/admin-setting.php:1125
725
- msgid "Method to update basis of comparison"
726
- msgstr "比較基準の更新方式"
727
-
728
- #: includes/admin-setting.php:688 includes/admin-setting.php:1128
729
- msgid "Disabled (None)"
730
- msgstr "無効(なし)"
731
-
732
- #: includes/admin-setting.php:691 includes/admin-setting.php:1129
733
- msgid "Enabled (Manual)"
734
- msgstr "有効(手動)"
735
-
736
- #: includes/admin-setting.php:694 includes/admin-setting.php:1130
737
- msgid "Enabled (Scheduler)"
738
- msgstr "有効(スケジューラ)"
739
-
740
- #: includes/admin-setting.php:705
741
- msgid "Schedule"
742
- msgstr "スケジュール"
743
-
744
- #: includes/admin-setting.php:738 includes/admin-setting.php:1412
745
- msgid "Interval cheking follower count (sec)"
746
- msgstr "フォロワー数のチェック間隔(秒)"
747
-
748
- #: includes/admin-setting.php:743 includes/admin-setting.php:770
749
- #: includes/admin-setting.php:1557
750
- msgid "Follow Base Cache - Feedly"
751
- msgstr "フォロー基本キャッシュ機能 - Feedly"
752
-
753
- #: includes/admin-setting.php:744 includes/admin-setting.php:1561
754
- msgid "Target feed type"
755
- msgstr "対象フィードタイプ"
756
-
757
- #: includes/admin-setting.php:749 includes/admin-setting.php:764
758
- #: includes/admin-setting.php:1564
759
- msgid "Default"
760
- msgstr "デフォルト"
761
-
762
- #: includes/admin-setting.php:752 includes/admin-setting.php:1565
763
- msgid "RSS"
764
- msgstr "RSS"
765
-
766
- #: includes/admin-setting.php:755 includes/admin-setting.php:1566
767
- msgid "RSS2"
768
- msgstr "RSS2"
769
-
770
- #: includes/admin-setting.php:758 includes/admin-setting.php:1567
771
- msgid "RDF"
772
- msgstr "RDF"
773
-
774
- #: includes/admin-setting.php:761 includes/admin-setting.php:1568
775
- msgid "ATOM"
776
- msgstr "ATOM"
777
-
778
- #: includes/admin-setting.php:771 includes/admin-setting.php:1574
779
- msgid "Target feed"
780
- msgstr "対象フィード"
781
-
782
- #: includes/admin-setting.php:778
783
- msgid "Target screen name"
784
- msgstr "対象スクリーンネーム"
785
-
786
- #: includes/admin-setting.php:793 includes/admin-setting.php:1493
787
- msgid "Page ID"
788
- msgstr "対象ページID"
789
-
790
- #: includes/admin-setting.php:807 includes/admin-setting.php:1672
791
- msgid "Dynamic caching based on user access"
792
- msgstr "ユーザアクセスをトリガとする動的キャッシュ"
793
-
794
- #: includes/admin-setting.php:811 includes/admin-setting.php:817
795
- #: includes/admin-setting.php:829 includes/admin-setting.php:835
796
- #: includes/admin-setting.php:1675 includes/admin-setting.php:1696
797
- msgid "Disabled"
798
- msgstr "無効"
799
-
800
- #: includes/admin-setting.php:814 includes/admin-setting.php:832
801
- #: includes/admin-setting.php:1676 includes/admin-setting.php:1697
802
- msgid "Enabled"
803
- msgstr "有効"
804
-
805
- #: includes/admin-setting.php:825
806
- msgid "Fault tolerance of count retrieval"
807
- msgstr "カウント取得における障害耐性"
808
-
809
- #: includes/admin-setting.php:843 includes/admin-setting.php:1714
810
- msgid "Crawl method"
811
- msgstr "クロールの方式"
812
-
813
- #: includes/admin-setting.php:848 includes/admin-setting.php:1719
814
- msgid "Normal (Sequential Retrieval)"
815
- msgstr "標準(逐次検索)"
816
-
817
- #: includes/admin-setting.php:851 includes/admin-setting.php:1722
818
- msgid "Extended (Parallel Retrieval)"
819
- msgstr "拡張(並列検索)"
820
-
821
- #: includes/admin-setting.php:859 includes/admin-setting.php:1729
822
- msgid "SSL verification"
823
- msgstr "SSL証明書の検証"
824
-
825
- #: includes/admin-setting.php:872 includes/admin-setting.php:1750
826
- msgid "Method of data export"
827
- msgstr "データのエクスポート方式"
828
-
829
- #: includes/admin-setting.php:876 includes/admin-setting.php:1753
830
- msgid "Manual"
831
- msgstr "手動"
832
-
833
- #: includes/admin-setting.php:879 includes/admin-setting.php:1165
834
- #: includes/admin-setting.php:1754 includes/admin-setting.php:1789
835
- msgid "Scheduler"
836
- msgstr "有効(スケジューラ)"
837
-
838
- #: includes/admin-setting.php:890
839
- msgid "Interval exporting share count to a csv file"
840
- msgstr "シェア数をCSVファイルにエクスポートする間隔"
841
-
842
- #: includes/admin-setting.php:891
843
- msgid "hours"
844
- msgstr "時間"
845
-
846
- #: includes/admin-setting.php:943
847
- msgid "e.g. aaa, bbb, ccc (comma-delimited)"
848
- msgstr "例. aaa, bbb, ccc(カンマ区切り)"
849
-
850
- #: includes/admin-setting.php:950 includes/admin-setting.php:1103
851
- msgid "Default: 600"
852
- msgstr "既定値: 600"
853
-
854
- #: includes/admin-setting.php:957 includes/admin-setting.php:1110
855
- msgid "Default: 20"
856
- msgstr "既定値: 20"
857
-
858
- #: includes/admin-setting.php:967
859
- msgid "Default: Off"
860
- msgstr "既定値: 無効"
861
-
862
- #: includes/admin-setting.php:975
863
- msgid "Default: N/A"
864
- msgstr "既定値: N/A"
865
-
866
- #: includes/admin-setting.php:1000 includes/admin-setting.php:1501
867
- msgid "App ID (Client ID)"
868
- msgstr "App ID (Client ID)"
869
-
870
- #: includes/admin-setting.php:1004 includes/admin-setting.php:1505
871
- msgid "Facebook app ID for OAuth"
872
- msgstr "OAuth認証のためのFacebook app ID"
873
-
874
- #: includes/admin-setting.php:1008 includes/admin-setting.php:1509
875
- msgid "App secret (Client secret)"
876
- msgstr "App secret (Client secret)"
877
-
878
- #: includes/admin-setting.php:1012 includes/admin-setting.php:1513
879
- msgid "Facebook app secret for OAuth"
880
- msgstr "OAuth認証のためのFacebook app secret"
881
-
882
- #: includes/admin-setting.php:1017 includes/admin-setting.php:1458
883
- #: includes/admin-setting.php:1468 includes/admin-setting.php:1526
884
- #: includes/admin-setting.php:1536
885
- msgid "Access token"
886
- msgstr "Access Token"
887
-
888
- #: includes/admin-setting.php:1021 includes/admin-setting.php:1540
889
- msgid "Facebook access token for OAuth"
890
- msgstr "OAuth認証のためのFacebook access token"
891
-
892
- #: includes/admin-setting.php:1046
893
- msgid "Default: "
894
- msgstr "規定値: "
895
-
896
- #: includes/admin-setting.php:1050
897
- msgid "Registration destination"
898
- msgstr "登録先"
899
-
900
- #: includes/admin-setting.php:1062
901
- msgid ""
902
- "You need to register information such as your domain with the above site in "
903
- "order to start counting."
904
- msgstr ""
905
- "カウントを開始するためには、上記サイトにドメイン等の情報を登録する必要があり"
906
- "ます。"
907
-
908
- #: includes/admin-setting.php:1081
909
- msgid "1 day"
910
- msgstr "1日"
911
-
912
- #: includes/admin-setting.php:1082
913
- msgid "2 days"
914
- msgstr "2日"
915
-
916
- #: includes/admin-setting.php:1083
917
- msgid "3 days"
918
- msgstr "3日"
919
-
920
- #: includes/admin-setting.php:1084
921
- msgid "4 days"
922
- msgstr "4日"
923
-
924
- #: includes/admin-setting.php:1085
925
- msgid "5 days"
926
- msgstr "5日"
927
-
928
- #: includes/admin-setting.php:1086
929
- msgid "6 days"
930
- msgstr "6日"
931
-
932
- #: includes/admin-setting.php:1087
933
- msgid "7 days"
934
- msgstr "7日"
935
-
936
- #: includes/admin-setting.php:1088
937
- msgid "8 days"
938
- msgstr "8日"
939
-
940
- #: includes/admin-setting.php:1089
941
- msgid "9 days"
942
- msgstr "9日"
943
-
944
- #: includes/admin-setting.php:1090
945
- msgid "10 days"
946
- msgstr "10日"
947
-
948
- #: includes/admin-setting.php:1091
949
- msgid "11 days"
950
- msgstr "11日"
951
-
952
- #: includes/admin-setting.php:1092
953
- msgid "12 days"
954
- msgstr "12日"
955
-
956
- #: includes/admin-setting.php:1093
957
- msgid "13 days"
958
- msgstr "13日"
959
-
960
- #: includes/admin-setting.php:1094
961
- msgid "14 days"
962
- msgstr "14日"
963
-
964
- #: includes/admin-setting.php:1096
965
- msgid "Default: 3 days"
966
- msgstr "既定値: 3日"
967
-
968
- #: includes/admin-setting.php:1132
969
- msgid "Default: None"
970
- msgstr "既定値: なし"
971
-
972
- #: includes/admin-setting.php:1170 includes/admin-setting.php:1794
973
- msgid "Type"
974
- msgstr "タイプ"
975
-
976
- #: includes/admin-setting.php:1175 includes/admin-setting.php:1799
977
- msgid "Hour"
978
- msgstr "時"
979
-
980
- #: includes/admin-setting.php:1178 includes/admin-setting.php:1802
981
- msgid "Minute"
982
- msgstr "分"
983
-
984
- #: includes/admin-setting.php:1184 includes/admin-setting.php:1808
985
- msgid "monthly"
986
- msgstr "毎月"
987
-
988
- #: includes/admin-setting.php:1195 includes/admin-setting.php:1819
989
- msgid "on 1."
990
- msgstr "1日"
991
-
992
- #: includes/admin-setting.php:1198 includes/admin-setting.php:1822
993
- msgid "on 2."
994
- msgstr "2日"
995
-
996
- #: includes/admin-setting.php:1201 includes/admin-setting.php:1825
997
- msgid "on 3."
998
- msgstr "3日"
999
-
1000
- #: includes/admin-setting.php:1204 includes/admin-setting.php:1828
1001
- msgid "on 4."
1002
- msgstr "4日"
1003
-
1004
- #: includes/admin-setting.php:1207 includes/admin-setting.php:1831
1005
- msgid "on 5."
1006
- msgstr "5日"
1007
-
1008
- #: includes/admin-setting.php:1210 includes/admin-setting.php:1834
1009
- msgid "on 6."
1010
- msgstr "6日"
1011
-
1012
- #: includes/admin-setting.php:1213 includes/admin-setting.php:1837
1013
- msgid "on 7."
1014
- msgstr "7日"
1015
-
1016
- #: includes/admin-setting.php:1216 includes/admin-setting.php:1840
1017
- msgid "on 8."
1018
- msgstr "8日"
1019
-
1020
- #: includes/admin-setting.php:1219 includes/admin-setting.php:1843
1021
- msgid "on 9."
1022
- msgstr "9日"
1023
-
1024
- #: includes/admin-setting.php:1222 includes/admin-setting.php:1846
1025
- msgid "on 10."
1026
- msgstr "10日"
1027
-
1028
- #: includes/admin-setting.php:1225 includes/admin-setting.php:1849
1029
- msgid "on 11."
1030
- msgstr "11日"
1031
-
1032
- #: includes/admin-setting.php:1228 includes/admin-setting.php:1852
1033
- msgid "on 12."
1034
- msgstr "12日"
1035
-
1036
- #: includes/admin-setting.php:1231 includes/admin-setting.php:1855
1037
- msgid "on 13."
1038
- msgstr "13日"
1039
-
1040
- #: includes/admin-setting.php:1234 includes/admin-setting.php:1858
1041
- msgid "on 14."
1042
- msgstr "14日"
1043
-
1044
- #: includes/admin-setting.php:1237 includes/admin-setting.php:1861
1045
- msgid "on 15."
1046
- msgstr "15日"
1047
-
1048
- #: includes/admin-setting.php:1240 includes/admin-setting.php:1864
1049
- msgid "on 16."
1050
- msgstr "16日"
1051
-
1052
- #: includes/admin-setting.php:1243 includes/admin-setting.php:1867
1053
- msgid "on 17."
1054
- msgstr "17日"
1055
-
1056
- #: includes/admin-setting.php:1246 includes/admin-setting.php:1870
1057
- msgid "on 18."
1058
- msgstr "18日"
1059
-
1060
- #: includes/admin-setting.php:1249 includes/admin-setting.php:1873
1061
- msgid "on 19."
1062
- msgstr "19日"
1063
-
1064
- #: includes/admin-setting.php:1252 includes/admin-setting.php:1876
1065
- msgid "on 20."
1066
- msgstr "20日"
1067
-
1068
- #: includes/admin-setting.php:1255 includes/admin-setting.php:1879
1069
- msgid "on 21."
1070
- msgstr "21日"
1071
-
1072
- #: includes/admin-setting.php:1258 includes/admin-setting.php:1882
1073
- msgid "on 22."
1074
- msgstr "22日"
1075
-
1076
- #: includes/admin-setting.php:1261 includes/admin-setting.php:1885
1077
- msgid "on 23."
1078
- msgstr "23日"
1079
-
1080
- #: includes/admin-setting.php:1264 includes/admin-setting.php:1888
1081
- msgid "on 24."
1082
- msgstr "24日"
1083
-
1084
- #: includes/admin-setting.php:1267 includes/admin-setting.php:1891
1085
- msgid "on 25."
1086
- msgstr "25日"
1087
-
1088
- #: includes/admin-setting.php:1270 includes/admin-setting.php:1894
1089
- msgid "on 26."
1090
- msgstr "26日"
1091
-
1092
- #: includes/admin-setting.php:1273 includes/admin-setting.php:1897
1093
- msgid "on 27."
1094
- msgstr "27日"
1095
-
1096
- #: includes/admin-setting.php:1276 includes/admin-setting.php:1900
1097
- msgid "on 28."
1098
- msgstr "28日"
1099
-
1100
- #: includes/admin-setting.php:1279 includes/admin-setting.php:1903
1101
- msgid "on 29."
1102
- msgstr "29日"
1103
-
1104
- #: includes/admin-setting.php:1282 includes/admin-setting.php:1906
1105
- msgid "on 30."
1106
- msgstr "30日"
1107
-
1108
- #: includes/admin-setting.php:1285 includes/admin-setting.php:1909
1109
- msgid "on 31."
1110
- msgstr "31日"
1111
-
1112
- #: includes/admin-setting.php:1312 includes/admin-setting.php:1940
1113
- msgid "weekly"
1114
- msgstr "毎週"
1115
-
1116
- #: includes/admin-setting.php:1318 includes/admin-setting.php:1946
1117
- msgid "Sunday"
1118
- msgstr "日曜日"
1119
-
1120
- #: includes/admin-setting.php:1319 includes/admin-setting.php:1947
1121
- msgid "Monday"
1122
- msgstr "月曜日"
1123
-
1124
- #: includes/admin-setting.php:1320 includes/admin-setting.php:1948
1125
- msgid "Tuesday"
1126
- msgstr "火曜日"
1127
-
1128
- #: includes/admin-setting.php:1321 includes/admin-setting.php:1949
1129
- msgid "Wednesday"
1130
- msgstr "水曜日"
1131
-
1132
- #: includes/admin-setting.php:1322 includes/admin-setting.php:1950
1133
- msgid "Thursday"
1134
- msgstr "木曜日"
1135
-
1136
- #: includes/admin-setting.php:1323 includes/admin-setting.php:1951
1137
- msgid "Friday"
1138
- msgstr "金曜日"
1139
-
1140
- #: includes/admin-setting.php:1324 includes/admin-setting.php:1952
1141
- msgid "Saturday"
1142
- msgstr "土曜日"
1143
-
1144
- #: includes/admin-setting.php:1346 includes/admin-setting.php:1978
1145
- msgid "daily"
1146
- msgstr "毎日"
1147
-
1148
- #: includes/admin-setting.php:1415
1149
- msgid "Default: 86400 Minimum: 3600"
1150
- msgstr "既定値: 86400 最小値: 3600"
1151
-
1152
- #: includes/admin-setting.php:1433
1153
- msgid "Client ID"
1154
- msgstr "Client ID"
1155
-
1156
- #: includes/admin-setting.php:1437
1157
- msgid "Instagram client ID for OAuth"
1158
- msgstr "OAuth認証のためのInstagram client ID"
1159
-
1160
- #: includes/admin-setting.php:1441
1161
- msgid "Client secret"
1162
- msgstr "Client secret"
1163
-
1164
- #: includes/admin-setting.php:1445
1165
- msgid "Instagram client secret for OAuth"
1166
- msgstr "OAuth認証のためのInstagram client secret"
1167
-
1168
- #: includes/admin-setting.php:1449 includes/admin-setting.php:1517
1169
- msgid "Redirect URI"
1170
- msgstr "Redirect URI"
1171
-
1172
- #: includes/admin-setting.php:1451 includes/admin-setting.php:1460
1173
- #: includes/admin-setting.php:1519 includes/admin-setting.php:1528
1174
- #: includes/admin-setting.php:1640
1175
- msgid "To copy, click the field then press Ctrl + C (PC) or Cmd + C (Mac)."
1176
- msgstr ""
1177
- "フィールドをクリック後、Ctrl + C (PC)、またはCmd + C (Mac)を押下しコピーして"
1178
- "下さい。"
1179
-
1180
- #: includes/admin-setting.php:1453
1181
- msgid ""
1182
- "Copy and set this to the field of \"Valid redirect URIs\" in the client "
1183
- "management page of Instagram developer page."
1184
- msgstr ""
1185
- "Instagram開発者向けページ内のクライアント管理ページにて「Valid redirect "
1186
- "URIs」フィールドにこのURIを設定して下さい。"
1187
-
1188
- #: includes/admin-setting.php:1462 includes/admin-setting.php:1530
1189
- #: includes/admin-setting.php:1642
1190
- msgid "Copy and pase this into the fields below."
1191
- msgstr "以下のフィールドにコピー&ペーストして下さい。"
1192
-
1193
- #: includes/admin-setting.php:1472
1194
- msgid "Instagram access token for OAuth"
1195
- msgstr "OAuth認証のためのInstagram access token"
1196
-
1197
- #: includes/admin-setting.php:1480 includes/admin-setting.php:1548
1198
- msgid "Get Acc