PluginProbe
codoc / 0.9.51
codoc v0.9.51
0.9.8.8 0.9.8.9 0.9.9 0.9.9.1 trunk 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.8.1 0.8.2 0.8.3 0.8.4 0.8.6 0.8.7 0.8.8 0.8.9 0.9 0.9.1 0.9.10 0.9.11 All 114 releases
← All changes | class-codoc-util.php +2 -53 trunk0.9.51 View file →
@@ -50,14 +50,8 @@
50 50 'headers' => $headers,
51 51 'body' => $body,
52 52 ]
53 53 );
54 - // notification を処理
55 - $body = json_decode($response['body'],true);
56 - if (isset($body['notification']) && !empty($body['notification'])) {
57 - // notification をトランジェントに保存(24時間保持)
58 - set_transient('codoc_api_notification', $body['notification'], DAY_IN_SECONDS);
59 - }
60 54 if ( is_wp_error($response) || $response['response']['code'] != 200 ) {
61 55 //何もしない
62 56 //var_dump( $response );
63 57 }
@@ -135,38 +129,8 @@
135 129 public function get_support_entry($params = [] ,$auth_info = ["usercode" => null, "token" => null]) {
136 130 $this->setAuthInfo($auth_info);
137 131 return $this->callAPI('GET','/support_entry');
138 132 }
139 - // API側と統一した文字数上限のバリデーション。エラーメッセージの配列を返す (エラー無しなら空配列)
140 - public function validate_entry_lengths($api_params) {
141 - $errors = [];
142 - $title = isset($api_params['title']) ? $api_params['title'] : '';
143 - $body_free = isset($api_params['body_free']) ? $api_params['body_free'] : '';
144 - $body_paywalled = isset($api_params['body_paywalled']) ? $api_params['body_paywalled'] : '';
145 - $binded_url = isset($api_params['binded_url']) ? $api_params['binded_url'] : '';
146 -
147 - if (mb_strlen($title) > CODOC_MAX_TITLE_LENGTH) {
148 - // Translators: %1$d is the max length, %2$d is the current length.
149 - $errors[] = sprintf(__('Title exceeds the maximum length of %1$d characters (current: %2$d).', 'codoc'), CODOC_MAX_TITLE_LENGTH, mb_strlen($title));
150 - }
151 - $len_body_free = mb_strlen($body_free);
152 - $len_body_paywalled = mb_strlen($body_paywalled);
153 - if ($len_body_free > CODOC_MAX_BODY_FREE_LENGTH) {
154 - $errors[] = sprintf(__('Free area exceeds the maximum length of %1$d characters (current: %2$d).', 'codoc'), CODOC_MAX_BODY_FREE_LENGTH, $len_body_free);
155 - }
156 - if ($len_body_paywalled > CODOC_MAX_BODY_PAYWALLED_LENGTH) {
157 - $errors[] = sprintf(__('Paid area exceeds the maximum length of %1$d characters (current: %2$d).', 'codoc'), CODOC_MAX_BODY_PAYWALLED_LENGTH, $len_body_paywalled);
158 - }
159 - $len_body_total = $len_body_free + $len_body_paywalled;
160 - if ($len_body_total > CODOC_MAX_BODY_LENGTH) {
161 - $errors[] = sprintf(__('Total body exceeds the maximum length of %1$d characters (current: %2$d).', 'codoc'), CODOC_MAX_BODY_LENGTH, $len_body_total);
162 - }
163 - if (mb_strlen($binded_url) > CODOC_MAX_BINDED_URL_LENGTH) {
164 - $errors[] = sprintf(__('URL exceeds the maximum length of %1$d characters (current: %2$d).', 'codoc'), CODOC_MAX_BINDED_URL_LENGTH, mb_strlen($binded_url));
165 - }
166 - return $errors;
167 - }
168 -
169 133 public function sync_entry($params = [
170 134 "post_title" => null,
171 135 "post_content" => null,
172 136 "post_status" => null, # 0, 1
@@ -230,14 +194,8 @@
230 194 'show_support' => isset($codoc_info['showSupport']) ? ($codoc_info['showSupport'] ? 1 : 0) : 0,
231 195 'show_paywalled_support' => isset($codoc_info['showPaywalledSupport']) ? ($codoc_info['showPaywalledSupport'] ? 1 : 0) : 0,
232 196 'subscriptions' => isset($codoc_info['subscriptions']) ? array_keys($codoc_info['subscriptions']) : [],
233 197 ];
234 - // API側と統一した文字数バリデーション
235 - $errors = $this->validate_entry_lengths($api_params);
236 - if ($errors) {
237 - set_transient('codoc_entry_validation_errors', $errors, MINUTE_IN_SECONDS * 5);
238 - return null;
239 - }
240 198 $entryCode = $params['codoc_entry_code'];
241 199 $res = null;
242 200 if ($entryCode) {
243 201 $res = $this->callAPI('PUT','/entries/' . $entryCode ,$api_params);
@@ -467,13 +425,8 @@
467 425 /*
468 426
469 427 $_CODOC->util->check_login($mode); // cookie / strict
470 428
471 - $response = $_CODOC->util->check_login('strict_with_data');
472 - if ($response->status and $response->user) {
473 - echo $reponse->user->code;
474 - }
475 -
476 429 */
477 430 function check_login($mode = 'cookie') {
478 431 if ($codocTokenCode = $this->get_paywall_token_code()) {
479 432 if ($mode == 'cookie') {
@@ -479,17 +432,13 @@
479 432 if ($mode == 'cookie') {
480 433 // cookieの中にtokenがあればOK
481 434 return true;
482 435 }
483 - if ($mode == 'strict' or $mode == 'strict_with_data') {
436 + if ($mode == 'strict') {
484 437 // ログイン状態を問い合わせ
485 438 $res = $this->callPaywallAPI('GET','/users',["paywall_token_code" => $codocTokenCode ]);
486 439 if ($res->status) {
487 - if ($mode == 'strict_with_data') {
488 - return $res;
489 - } else {
490 - return true;
491 - }
440 + return true;
492 441 } else {
493 442 return false;
494 443 }
495 444 }