| @@ -11,14 +11,11 @@ | ||
| 11 | 11 | require_once( ABSPATH . WPINC . '/class-http.php'); |
| 12 | 12 | require_once( ABSPATH . WPINC . '/class-wp-error.php'); |
| 13 | 13 | |
| 14 | 14 | final class CodocUtil { |
| 15 | - public $codoc_url = CODOC_URL; | |
| 16 | - public function __construct($params = ['usercode' => null, 'token' => null,'codoc_url' => null]) { | |
| 17 | - $this->setAuthInfo(['usercode' => $params['usercode'], 'token' => $params['token']]); | |
| 18 | - if (isset($params['codoc_url'])) { | |
| 19 | - $this->codoc_url = $params['codoc_url']; | |
| 20 | - } | |
| 15 | + | |
| 16 | + public function __construct($params = ['usercode' => null, 'token' => null]) { | |
| 17 | + $this->setAuthInfo($params); | |
| 21 | 18 | return $this; |
| 22 | 19 | } |
| 23 | 20 | |
| 24 | 21 | public function callAPI($method,$path,$body = [],$headers = []) { |
| @@ -25,12 +22,12 @@ | ||
| 25 | 22 | $usercode = $this->usercode; |
| 26 | 23 | $token = $this->token; |
| 27 | 24 | |
| 28 | 25 | $headers['X-CodocToken'] = $token; |
| 29 | - $host = $this->codoc_url; | |
| 26 | + $host = CODOC_URL; | |
| 30 | 27 | $sslverify = true; |
| 31 | 28 | |
| 32 | - if (preg_match('/local/',$this->codoc_url)) { | |
| 29 | + if (preg_match('/local/',CODOC_URL)) { | |
| 33 | 30 | $sslverify = false; |
| 34 | 31 | $host = 'https://host.docker.internal'; |
| 35 | 32 | } |
| 36 | 33 | $url = sprintf("%s/api/v1/cms/%s%s",$host,$usercode,$path); |
| @@ -79,12 +76,8 @@ | ||
| 79 | 76 | public function get_user_info($params = [] ,$auth_info = ["usercode" => null, "token" => null]) { |
| 80 | 77 | $this->setAuthInfo($auth_info); |
| 81 | 78 | return $this->callAPI('GET',''); |
| 82 | 79 | } |
| 83 | - public function get_support_entry($params = [] ,$auth_info = ["usercode" => null, "token" => null]) { | |
| 84 | - $this->setAuthInfo($auth_info); | |
| 85 | - return $this->callAPI('GET','/support_entry'); | |
| 86 | - } | |
| 87 | 80 | public function sync_entry($params = [ |
| 88 | 81 | "post_title" => null, |
| 89 | 82 | "post_content" => null, |
| 90 | 83 | "post_status" => null, # 0, 1 |
| @@ -138,9 +131,8 @@ | ||
| 138 | 131 | 'limited_count' => isset($codoc_info['limitedCount']) ? $codoc_info['limitedCount'] : 1, |
| 139 | 132 | 'affiliate_mode' => isset($codoc_info['affiliateMode']) ? ($codoc_info['affiliateMode'] ? 1 : 0) : 0, |
| 140 | 133 | 'affiliate_rate' => isset($codoc_info['affiliateRate']) ? $codoc_info['affiliateRate'] : '0.0500', |
| 141 | 134 | 'show_support' => isset($codoc_info['showSupport']) ? ($codoc_info['showSupport'] ? 1 : 0) : 0, |
| 142 | - 'show_paywalled_support' => isset($codoc_info['showPaywalledSupport']) ? ($codoc_info['showPaywalledSupport'] ? 1 : 0) : 0, | |
| 143 | 135 | 'subscriptions' => isset($codoc_info['subscriptions']) ? array_keys($codoc_info['subscriptions']) : [], |
| 144 | 136 | ]; |
| 145 | 137 | $entryCode = $params['codoc_entry_code']; |
| 146 | 138 | $res = null; |
| @@ -208,53 +200,16 @@ | ||
| 208 | 200 | "post_content" => null, |
| 209 | 201 | "preview" => null, |
| 210 | 202 | "codoc_entry_code" => null, |
| 211 | 203 | "codoc_settings" => null, |
| 212 | - "is_amp_endpoint" => null, | |
| 213 | - "post_permalink" => null, | |
| 214 | - "codoc_support_entry_code" => null, | |
| 215 | 204 | ]) { |
| 216 | - $CODOC_SETTINGS = $params['codoc_settings']; | |
| 217 | - | |
| 218 | - $has_codoc_tag = '/(<(span|div)[^>]+data-id="codoc-tag"(?:[^>]+|)>(?:.+|)<\/(?:div|span)>)/'; | |
| 219 | 205 | $post_content = $params['post_content']; |
| 220 | 206 | // codoc タグがあるかどうか (202001:span -> div に変更) |
| 221 | - preg_match($has_codoc_tag,$post_content,$matches); | |
| 222 | - | |
| 223 | - $show_support_message = ''; | |
| 224 | - if (isset($CODOC_SETTINGS['show_support_message'])) { | |
| 225 | - $show_support_message = $CODOC_SETTINGS['show_support_message']; | |
| 226 | - } | |
| 227 | - $show_support_categories = ''; | |
| 228 | - if (isset($CODOC_SETTINGS['show_support_categories'])) { | |
| 229 | - $show_support_categories = $CODOC_SETTINGS['show_support_categories']; | |
| 230 | - } | |
| 231 | - $show_support_location = 'bottom'; | |
| 232 | - if (isset($CODOC_SETTINGS['show_support_location'])) { | |
| 233 | - $show_support_location = $CODOC_SETTINGS['show_support_location']; | |
| 234 | - } | |
| 235 | - | |
| 236 | - $show_support_entry = (is_single() && preg_grep("/(?:$show_support_categories)/",array_map( function($c) { return $c->name; },get_the_category(get_post()->ID)))); | |
| 237 | - if (!$matches && ($support_entry_code = $params['codoc_support_entry_code']) && $show_support_entry) { | |
| 238 | - $support_tag = sprintf( | |
| 239 | - '<div class="codoc-entries" data-without-body="1" data-support-message="%s" id="codoc-entry-%s" data-support-button-text="%s" data-show-like="%s" data-show-about-codoc="%s" data-show-powered-by="%s"></div>', | |
| 240 | - htmlspecialchars($show_support_message,ENT_QUOTES), | |
| 241 | - $support_entry_code, | |
| 242 | - $CODOC_SETTINGS['support_button_text'], | |
| 243 | - $CODOC_SETTINGS['show_like'], | |
| 244 | - $CODOC_SETTINGS['show_about_codoc'], | |
| 245 | - $CODOC_SETTINGS['show_powered_by'] | |
| 246 | - ); | |
| 247 | - $post_content = $show_support_location == 'bottom' ? | |
| 248 | - $post_content . $support_tag : | |
| 249 | - $support_tag . $post_content ; | |
| 250 | - } | |
| 251 | - | |
| 207 | + preg_match('/(<(span|div)[^>]+data-id="codoc-tag"(?:[^>]+|)>(?:.+|)<\/(?:div|span)>)/',$post_content,$matches); | |
| 252 | 208 | // data-wp-plugin-ver が無いタグは分割しない |
| 253 | 209 | if (!$matches) { |
| 254 | 210 | return $post_content; |
| 255 | 211 | } |
| 256 | - | |
| 257 | 212 | // codocタグで分割 (202001: gutenbergで直前のdivタグを削除) |
| 258 | 213 | $tag_regex = '/(?:<div(?:[^>]+|)>|)<(?:span|div)[^>]+data-id="codoc-tag"(?:[^>]+|)>(?:.+|)<\/(?:span|div)>(?:<\/div>|)/'; |
| 259 | 214 | if ( $params['preview'] ) { |
| 260 | 215 | $post_content = preg_replace($tag_regex,'<div class="codoc-continue">ここから上は無料で表示されます</div>',$post_content); |
| @@ -263,53 +218,15 @@ | ||
| 263 | 218 | // codoc タグの前後で分ける |
| 264 | 219 | $splited = preg_split($tag_regex,$post_content); |
| 265 | 220 | // codoc タグにID属性のentrycodeとdata-without-body(無料分を非表示)をつける |
| 266 | 221 | $entryCodeFormated = sprintf('"codoc-entry-%s" ',$params['codoc_entry_code']); |
| 267 | - | |
| 268 | - // 文言系の設定をつける | |
| 269 | - $tagAttributes = ''; | |
| 270 | - if (isset($CODOC_SETTINGS['show_like']) and $CODOC_SETTINGS['show_like'] != 1) { | |
| 271 | - $tagAttributes = $tagAttributes . sprintf(' data-show-like="%s"',$CODOC_SETTINGS['show_like']); | |
| 272 | - } | |
| 273 | - if (isset($CODOC_SETTINGS['show_about_codoc']) and $CODOC_SETTINGS['show_about_codoc'] != 1) { | |
| 274 | - $tagAttributes = $tagAttributes . sprintf(' data-show-about-codoc="%s"',$CODOC_SETTINGS['show_about_codoc']); | |
| 275 | - } | |
| 276 | - if (isset($CODOC_SETTINGS['show_powered_by']) and $CODOC_SETTINGS['show_powered_by'] != 1) { | |
| 277 | - $tagAttributes = $tagAttributes . sprintf(' data-show-powered-by="%s"',$CODOC_SETTINGS['show_powered_by']); | |
| 278 | - } | |
| 279 | - if ($CODOC_SETTINGS['entry_button_text']) { | |
| 280 | - $tagAttributes = $tagAttributes . sprintf(' data-entry-button-text="%s"',$CODOC_SETTINGS['entry_button_text']); | |
| 281 | - } | |
| 282 | - if ($CODOC_SETTINGS['subscription_button_text']) { | |
| 283 | - $tagAttributes = $tagAttributes . sprintf(' data-subscription-button-text="%s"',$CODOC_SETTINGS['subscription_button_text']); | |
| 284 | - } | |
| 285 | - if ($CODOC_SETTINGS['support_button_text']) { | |
| 286 | - $tagAttributes = $tagAttributes . sprintf(' data-support-button-text="%s"',$CODOC_SETTINGS['support_button_text']); | |
| 287 | - } | |
| 288 | - if ($CODOC_SETTINGS['subscription_message']) { | |
| 289 | - $tagAttributes = $tagAttributes . sprintf(' data-subscription-message="%s"',$CODOC_SETTINGS['subscription_message']); | |
| 290 | - } | |
| 291 | - if ($CODOC_SETTINGS['support_message']) { | |
| 292 | - $tagAttributes = $tagAttributes . sprintf(' data-support-message="%s"',$CODOC_SETTINGS['support_message']); | |
| 293 | - } | |
| 294 | - if ($CODOC_SETTINGS['codoc_tag_attributes']) { | |
| 295 | - $tagAttributes = $tagAttributes . sprintf(' %s',$CODOC_SETTINGS['codoc_tag_attributes']); | |
| 296 | - } | |
| 297 | - | |
| 298 | - $codoc_tag = preg_replace('/<((?:span|div)[^>]+)data-id="[^"]+"((?:[^>]+|))>/','<${1} ${2} data-without-body="1" id=' . $entryCodeFormated . $tagAttributes . ">", $matches[1]); | |
| 222 | + $codoc_tag = preg_replace('/<((?:span|div)[^>]+)data-id="[^"]+"((?:[^>]+|))>/','<${1} ${2} data-without-body="1" id=' . $entryCodeFormated . ">", $matches[1]); | |
| 299 | 223 | # THE THOR の page-lp.php が " " をけずるための対策 |
| 300 | 224 | # "div class" -> "div class" |
| 301 | 225 | $codoc_tag = preg_replace('/div +class/','div class',$codoc_tag); |
| 302 | - | |
| 303 | - if ($params['is_amp_endpoint']) { | |
| 304 | - $format = preg_replace_callback('/(<(?:span|div)[^>]+>)((?:[^<>]+|))(<\/(?:span|div)>)/',function($matches) { | |
| 305 | - $format = $matches[1] . '<a href="%%s">%s</a>' . $matches[3]; | |
| 306 | - return sprintf($format,($matches[2] ? $matches[2] : '続きを読む')); | |
| 307 | - },$codoc_tag); | |
| 308 | - $codoc_tag = sprintf($format,$params["post_permalink"]); | |
| 309 | - } | |
| 310 | - | |
| 226 | + | |
| 311 | 227 | # タグの前後にHTMLを挿入 |
| 228 | + $CODOC_SETTINGS = $params['codoc_settings']; | |
| 312 | 229 | if (!isset($CODOC_SETTINGS['str_before_codoc_tag'])) { |
| 313 | 230 | $CODOC_SETTINGS['str_before_codoc_tag'] = ''; |
| 314 | 231 | } |
| 315 | 232 | if (!isset($CODOC_SETTINGS['str_after_codoc_tag'])) { |