| @@ -135,38 +135,8 @@ | ||
| 135 | 135 | public function get_support_entry($params = [] ,$auth_info = ["usercode" => null, "token" => null]) { |
| 136 | 136 | $this->setAuthInfo($auth_info); |
| 137 | 137 | return $this->callAPI('GET','/support_entry'); |
| 138 | 138 | } |
| 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 | 139 | public function sync_entry($params = [ |
| 170 | 140 | "post_title" => null, |
| 171 | 141 | "post_content" => null, |
| 172 | 142 | "post_status" => null, # 0, 1 |
| @@ -230,14 +200,8 @@ | ||
| 230 | 200 | 'show_support' => isset($codoc_info['showSupport']) ? ($codoc_info['showSupport'] ? 1 : 0) : 0, |
| 231 | 201 | 'show_paywalled_support' => isset($codoc_info['showPaywalledSupport']) ? ($codoc_info['showPaywalledSupport'] ? 1 : 0) : 0, |
| 232 | 202 | 'subscriptions' => isset($codoc_info['subscriptions']) ? array_keys($codoc_info['subscriptions']) : [], |
| 233 | 203 | ]; |
| 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 | 204 | $entryCode = $params['codoc_entry_code']; |
| 241 | 205 | $res = null; |
| 242 | 206 | if ($entryCode) { |
| 243 | 207 | $res = $this->callAPI('PUT','/entries/' . $entryCode ,$api_params); |