PluginProbe
codoc / 0.9.3
codoc v0.9.3
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.php +130 -239 0.8.90.9.3 View file →
@@ -1,6 +1,6 @@
1 1 <?php
2 -
2 +require_once(plugin_dir_path( __FILE__ ) .'class-codoc-util.php');
3 3 final class Codoc {
4 4
5 5 public function __construct() {
6 6 if (is_admin()) {
@@ -6,20 +6,25 @@
6 6 if (is_admin()) {
7 7 // setting
8 8 $this->add_settings();
9 9 }
10 +
11 + // usercode, token はadminページのみDBから取得する
12 + $this->util = new CodocUtil();
13 +
14 + // paywall用の本文非表示化とcodocタグへの属性追加
15 + add_filter('the_content',[$this,'the_content']);
16 +
10 17 $auth_info = get_option(CODOC_AUTHINFO_OPTION_NAME);
11 - if (!$auth_info) {
12 - return $this;
13 - }
14 18
15 - // データ同期 (save_postはis_adminで実行されないケースがある)
16 - add_action( 'save_post', [$this,'save_post'], 20, 3 );
17 - add_action( 'added_post_meta', [$this,'updated_post_meta'], 10, 3 );
18 - add_action( 'updated_post_meta',[$this,'updated_post_meta'], 10, 3 );
19 - add_action( 'deleted_post_meta',[$this,'deleted_post_meta'], 10, 4 );
20 -
21 - if (is_admin()) {
19 + if ($auth_info) {
20 + // データ同期 (save_postはis_adminで実行されないケースがある)
21 + add_action( 'save_post', [$this,'save_post'], 20, 3 );
22 + add_action( 'added_post_meta', [$this,'updated_post_meta'], 10, 3 );
23 + add_action( 'updated_post_meta',[$this,'updated_post_meta'], 10, 3 );
24 + add_action( 'deleted_post_meta',[$this,'deleted_post_meta'], 10, 4 );
25 + }
26 + if (is_admin() and $auth_info) { //管理画面
22 27 // Gutenberg のサポートがない場合は何もしない
23 28 if ( function_exists( 'register_block_type' ) ) {
24 29 // gutenberg
25 30 require_once 'src/init.php';
@@ -33,25 +38,19 @@
33 38 });
34 39 }
35 40 // tinymce
36 41 $this->add_mce();
37 -
38 - return $this;
39 - }
40 -
41 - // codocのJS登録
42 -
43 - add_action( 'wp_enqueue_scripts', function() {
44 - wp_enqueue_script( 'codoc-injector-js', CODOC_URL . '/js/cms.js' );
45 - });
46 - // 登録したscriptタグに属性をつける
47 - add_filter('script_loader_tag', [$this,'modifier_script_tag'],10,2);
48 - // tinymce用のショートコード
49 - add_shortcode('codoc', [$this, 'injector_shortcode']);
50 -
51 - // paywall用の本文非表示化とcodocタグへの属性追加
52 - add_filter('the_content',[$this,'the_content']);
53 - return $this;
42 + } else { // ブログ画面
43 + // codocのJS登録
44 + add_action( 'wp_enqueue_scripts', function() {
45 + wp_enqueue_script( 'codoc-injector-js', CODOC_URL . '/js/cms.js' );
46 + });
47 + // 登録したscriptタグに属性をつける
48 + add_filter('script_loader_tag', [$this,'modifier_script_tag'],10,2);
49 + // tinymce用のショートコード
50 + add_shortcode('codoc', [$this, 'injector_shortcode']);
51 + }
52 + return $this;
54 53 }
55 54
56 55 public function modifier_script_tag($tag,$handle) {
57 56 if($handle !== 'codoc-injector-js') {
@@ -70,50 +69,8 @@
70 69 ob_start();
71 70 require 'views/codoc-injector.php';
72 71 return ob_get_clean();
73 72 }
74 - public function callAPI($method,$path,$body = [],$headers = []) {
75 - $usercode = get_option(CODOC_USERCODE_OPTION_NAME);
76 - $token = get_option(CODOC_TOKEN_OPTION_NAME);
77 -
78 - $headers['X-CodocToken'] = $token;
79 - $host = CODOC_URL;
80 - $sslverify = true;
81 -
82 - if (preg_match('/local/',CODOC_URL)) {
83 - $sslverify = false;
84 - $host = 'https://host.docker.internal';
85 - }
86 - $url = sprintf("%s/api/v1/cms/%s%s",$host,$usercode,$path);
87 - $http = new WP_Http();
88 - try {
89 - $response = $http->request(
90 - $url,
91 - [
92 - 'sslverify' => $sslverify,
93 - 'method' => $method,
94 - 'timeout' => 10,
95 - 'headers' => $headers,
96 - 'body' => $body,
97 - ]
98 - );
99 - if ( is_wp_error($response) || $response['response']['code'] != 200 ) {
100 - //何もしない
101 - //var_dump( $response );
102 - }
103 - } catch(Exception $e) {
104 - }
105 -
106 - if (!is_wp_error($response) and
107 - isset($response['body']) and
108 - is_string($response['body']) and
109 - is_array(json_decode($response['body'], true)) and
110 - (json_last_error() == JSON_ERROR_NONE)) {
111 - return json_decode($response['body']);
112 - } else {
113 - return null;
114 - }
115 - }
116 73 # settings / 設定関連
117 74 public function add_settings() {
118 75 global $CODOC_SETTINGS;
119 76 add_action( 'admin_menu' ,function(){
@@ -127,9 +84,9 @@
127 84 echo '<form method="post" action="options.php">';
128 85 settings_fields( 'codoc_option_group' );
129 86 do_settings_sections( 'codoc' );
130 87 submit_button(); // 送信ボタン
131 - echo '</div>';
88 + echo '</form></div>';
132 89 }
133 90 );
134 91 });
135 92
@@ -138,12 +95,14 @@
138 95 if (isset($_GET['page']) and $_GET['page'] == 'codoc' and isset($_GET['fetch_token_key'])) {
139 96 $key = sanitize_text_field($_GET['fetch_token_key']);
140 97 $usercode = sanitize_text_field($_GET['usercode']);
141 98 update_option(CODOC_USERCODE_OPTION_NAME,$usercode);
142 - $data = $this->callAPI('GET','/token',[ "fetch_token_key" => $key ]);
99 + //$data = $this->callAPI('GET','/token',[ "fetch_token_key" => $key ]);
100 + $data = $this->util->get_token([ "fetch_token_key" => $key ],["usercode" => $usercode, "token" => "1"]);
143 101 if ($data->status and $token = $data->token) {
144 102 update_option(CODOC_TOKEN_OPTION_NAME,$token);
145 - $data = $this->callAPI('GET','');
103 + //$data = $this->callAPI('GET','');
104 + $data = $this->util->get_user_info([],["usercode" => $usercode, "token" => $token]);
146 105 if ($data->status and $user = $data->user) {
147 106 update_option(CODOC_AUTHINFO_OPTION_NAME,[
148 107 'email' => $user->email,
149 108 'name' => $user->name,
@@ -257,9 +216,9 @@
257 216 function() {
258 217 global $CODOC_USERCODE;
259 218 global $CODOC_TOKEN;
260 219 global $CODOC_AUTHINFO;
261 - $script = "javascript:document.getElementById('codoc-usercode').value='';document.getElementById('codoc-token').value=' ';document.getElementById('codoc-auth-message').innerText='解除を完了するには変更を保存してください';document.getElementById('codoc-auth-message').color='red';";
220 + $script = "javascript:document.getElementById('codoc-usercode').value='-';document.getElementById('codoc-token').value='-';document.getElementById('codoc-auth-message').innerText='解除を完了するには変更を保存してください';document.getElementById('codoc-auth-message').color='red';";
262 221
263 222 echo sprintf('<p><font color="green" id="codoc-auth-message"><strong>%s</strong> で認証済</font></p>',$CODOC_AUTHINFO['email']);
264 223
265 224 echo sprintf('<input id="codoc-usercode" type="hidden" name="%s" value="%s">',CODOC_USERCODE_OPTION_NAME,$CODOC_USERCODE);
@@ -295,27 +254,31 @@
295 254 'setting_section_id'
296 255 );
297 256 }
298 257 // ない場合かつ自分で認証する場合
299 - if (!$CODOC_AUTHINFO and (isset($_GET['auth_by_myself']) and $_GET['auth_by_myself'])) {
258 + if (!$CODOC_AUTHINFO and (
259 + (isset($_GET['auth_by_myself']) and $_GET['auth_by_myself']) or
260 + (isset($_POST['auth_by_myself']) and $_POST['auth_by_myself'])
261 + )) {
300 262 register_setting(
301 263 'codoc_option_group', // option group
302 264 CODOC_USERCODE_OPTION_NAME
303 265 );
266 + register_setting(
267 + 'codoc_option_group', // option group
268 + CODOC_TOKEN_OPTION_NAME
269 + );
304 270 add_settings_field(
305 271 'codoc_usercode',
306 272 'ユーザーコード',
307 273 function() {
308 274 global $CODOC_USERCODE;
275 + echo '<input type="hidden" name="auth_by_myself" value="1">';
309 276 echo sprintf('<input type="text" name="%s" value="%s">',CODOC_USERCODE_OPTION_NAME,$CODOC_USERCODE);
310 277 },
311 278 'codoc',
312 279 'setting_section_id'
313 280 );
314 - register_setting(
315 - 'codoc_option_group', // option group
316 - CODOC_TOKEN_OPTION_NAME
317 - );
318 281 add_settings_field(
319 282 'codoc_token',
320 283 'APIトークン',
321 284 function() {
@@ -338,9 +301,13 @@
338 301 },10,2);
339 302 add_action('updated_option',function(){
340 303 global $CODOC_RE_AUTHORIZE;
341 304 if ($CODOC_RE_AUTHORIZE) {
342 - $data = $this->callAPI('GET','');
305 + //$data = $this->callAPI('GET','');
306 + $data = $this->util->get_user_info([],[
307 + "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
308 + "token" => get_option(CODOC_TOKEN_OPTION_NAME),
309 + ]);
343 310 if ($data->status and $user = $data->user) {
344 311 update_option(CODOC_AUTHINFO_OPTION_NAME,[
345 312 'email' => $user->email,
346 313 'name' => $user->name,
@@ -363,51 +330,55 @@
363 330 );
364 331
365 332 }
366 333 public function add_mce() {
367 - // Add Shortcode options in the WordPres visual editors
368 - //wp_enqueue_script( 'codoc-editor-script', CODOC_URL . 'codoc/src_mce/codoc-editor.js');
369 -
370 - add_action( 'init', function() {
334 + add_action( 'admin_enqueue_scripts', function() {
371 335 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
372 336 return;
373 337 }
374 - if ( get_user_option( 'rich_editing' ) == 'true' ) {
375 - // プラグイン内で使うCSRF を生成
376 - $path = plugins_url( 'codoc/src_mce/codoc-editor-onload.js', __DIR__ );
377 - wp_enqueue_script( 'codoc-editor-onload', $path, array('jquery'), '', true );
378 - // I just want to insert this global variables but i don't know how i can do it..
379 - wp_localize_script(
380 - 'codoc-editor-onload',
381 - 'CODOCEDITOR',
382 - array(
383 - 'action' => 'codoc_shortcodes',
384 - 'nonce' => wp_create_nonce( 'codoc_shortcodes' ),
338 + $current_screen = get_current_screen();
339 + if ( ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) || ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) ) {
340 + // Gutenberg Editor
341 + // なにもしない
342 + } else {
343 + // tinymce
344 + if ( get_user_option( 'rich_editing' ) == 'true' ) {
345 + // プラグイン内で使うCSRF を生成
346 + $path = plugins_url( 'codoc/src_mce/codoc-editor-onload.js', __DIR__ );
347 + wp_enqueue_script( 'codoc-editor-onload', $path, array('jquery'), '', true );
348 + // I just want to insert this global variables but i don't know how i can do it..
349 + wp_localize_script(
350 + 'codoc-editor-onload',
351 + 'CODOCEDITOR',
352 + array(
353 + 'action' => 'codoc_shortcodes',
354 + 'nonce' => wp_create_nonce( 'codoc_shortcodes' ),
385 355
386 - 'codoc_url' => CODOC_URL,
387 - 'codoc_usercode' => get_option(CODOC_USERCODE_OPTION_NAME),
388 - 'codoc_plugin_version' => CODOC_PLUGIN_VERSION,
389 - 'codoc_sdk_path' => CODOC_SDK_PATH,
390 - )
391 - );
356 + 'codoc_url' => CODOC_URL,
357 + 'codoc_usercode' => get_option(CODOC_USERCODE_OPTION_NAME),
358 + 'codoc_plugin_version' => CODOC_PLUGIN_VERSION,
359 + 'codoc_sdk_path' => CODOC_SDK_PATH,
360 + )
361 + );
392 362
393 - // ここでtinymceのプラグイン追加
394 - //wp_enqueue_style( 'codoc-admin-style', plugins_url( 'codoc/src_mce/codoc-admin.css', __DIR__ ) );
395 - //add_editor_style( plugins_url( 'codoc/src_mce/codoc-admin.css', __DIR__ ) );
396 - wp_enqueue_style( 'codoc-admin-style', CODOC_URL . CODOC_SDK_PATH . '.tinymce.css?c=' . date('Ymd') );
397 - add_editor_style( CODOC_URL . CODOC_SDK_PATH . '.tinymce.css' );
398 -
399 - add_filter( 'mce_external_plugins', function( $plugin_array ) {
400 - //$plugin_array['codoc'] = plugins_url( 'codoc/src_mce/codoc-editor.js', __DIR__ );
401 - $plugin_array['codoc'] = CODOC_URL . CODOC_SDK_PATH . '.tinymce.js?c=' . date('Ymd');
402 - return $plugin_array;
403 - } );
404 - add_filter( 'mce_buttons', function( $buttons ) {
405 - array_push( $buttons, "|", "codoc" );
406 - return $buttons;
407 - } );
408 -
409 - }
363 + // ここでtinymceのプラグイン追加
364 + //wp_enqueue_style( 'codoc-admin-style', plugins_url( 'codoc/src_mce/codoc-admin.css', __DIR__ ) );
365 + //add_editor_style( plugins_url( 'codoc/src_mce/codoc-admin.css', __DIR__ ) );
366 + wp_enqueue_style( 'codoc-admin-style', CODOC_URL . CODOC_SDK_PATH . '.tinymce.css?c=' . date('Ymd') );
367 + add_editor_style( CODOC_URL . CODOC_SDK_PATH . '.tinymce.css' );
368 +
369 + add_filter( 'mce_external_plugins', function( $plugin_array ) {
370 + //$plugin_array['codoc'] = plugins_url( 'codoc/src_mce/codoc-editor.js', __DIR__ );
371 + $plugin_array['codoc'] = CODOC_URL . CODOC_SDK_PATH . '.tinymce.js?c=' . date('Ymd');
372 + return $plugin_array;
373 + } );
374 + add_filter( 'mce_buttons', function( $buttons ) {
375 + array_push( $buttons, "|", "codoc" );
376 + return $buttons;
377 + } );
378 +
379 + }
380 + }
410 381 } );
411 382 }
412 383 public function save_post($post_ID,$post,$update) {
413 384 if (preg_match('/^(auto-draft|inherit)$/',$post->post_status)) {
@@ -412,66 +383,25 @@
412 383 public function save_post($post_ID,$post,$update) {
413 384 if (preg_match('/^(auto-draft|inherit)$/',$post->post_status)) {
414 385 return;
415 386 }
416 -
417 - $post_content = $post->post_content;
418 - preg_match('/wp:codoc\/codoc-block +?({.*})/',$post_content,$matches);
419 - // GUTENBERG で指定されたjson(記事情報)がない場合
420 - if (!$matches) {
421 - return;
422 - }
423 - // GUTENBERG で保存している内容を取得
424 - $codoc_info = json_decode($matches[1],true);
425 - // codoc タグがない場合はなにもしない
426 - //preg_match('/(<span +data-id="codoc-tag"[^>]+>(?:.+|)<\/span>)/',$post_content,$matches);
427 - preg_match('/(<(?:span|div)[^>]+data-id="codoc-tag"(?:[^>]+|)>(?:.+|)<\/(?:span|div)>)/',$post_content,$matches);
428 - if (!$matches) {
429 - return;
430 - }
431 - // TODO: split or html parse? HTMLがつながってる場合はおかしくなる
432 - // classic(tinymce)版の場合p、もしくはdivにかこまれている
433 - $splited = preg_split('/(?:<(?:div|p)(?:[^>]+|)>|)<\!-- +wp:codoc\/codoc-block .*<\!-- +\/wp:codoc\/codoc-block +-->(?:<\/(?:div|p)>|)/s',$post_content);
434 - $status = $post->post_status == 'publish' ? 1 : 0;
435 - # $body_free = '';
436 - # $body_paywalled = '';
437 - # if (count($splited) >= 2) {
438 - #
439 - # }
440 - $binded_url = get_permalink($post_ID);
441 - $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
442 - if (isset($CODOC_SETTINGS['str_replace_binded_url_from']) and
443 - isset($CODOC_SETTINGS['str_replace_binded_url_to']) and
444 - $CODOC_SETTINGS['str_replace_binded_url_from']) {
445 - $binded_url = str_replace(sanitize_text_field($CODOC_SETTINGS['str_replace_binded_url_from']),
446 - sanitize_text_field($CODOC_SETTINGS['str_replace_binded_url_to']),
447 - $binded_url);
448 - }
449 -
450 - $params = [
451 - 'title' => $post->post_title,
452 - 'body_free' => $splited[0],
453 - 'body_paywalled' => $splited[1],
454 - 'status' => $status,
455 - 'binded_url' => $binded_url,
456 - 'show_price' => isset($codoc_info['showPrice']) ? ($codoc_info['showPrice'] ? 1 : 0) : 0,
457 - 'price' => isset($codoc_info['price']) ? $codoc_info['price'] : 100,
458 - 'limited' => isset($codoc_info['limited']) ? ($codoc_info['limited'] ? 1 : 0) : 0,
459 - 'limited_count' => isset($codoc_info['limitedCount']) ? $codoc_info['limitedCount'] : 1,
460 - 'affiliate_mode' => isset($codoc_info['affiliateMode']) ? ($codoc_info['affiliateMode'] ? 1 : 0) : 0,
461 - 'affiliate_rate' => isset($codoc_info['affiliateRate']) ? $codoc_info['affiliateRate'] : '0.0500',
462 - 'show_support' => isset($codoc_info['showSupport']) ? ($codoc_info['showSupport'] ? 1 : 0) : 0,
463 - 'subscriptions' => isset($codoc_info['subscriptions']) ? array_keys($codoc_info['subscriptions']) : [],
464 - ];
387 +
465 388 $entryCode = get_post_meta($post_ID,'codoc_entry_code',true);
466 - if ($entryCode) {
467 - $res = $this->callAPI('PUT','/entries/' . $entryCode ,$params);
468 - } else {
469 - $res = $this->callAPI('POST', '/entries', $params);
470 - if (is_object($res) and $res->status) {
471 - update_post_meta($post_ID,'codoc_entry_code',$res->entry->code);
472 - }
389 + $res = $this->util->sync_entry([
390 + "post_title" => $post->post_title,
391 + "post_content" => $post->post_content,
392 + "post_status" => ($post->post_status == 'publish' ? 1 : 0),
393 + "post_permalink" => get_permalink($post_ID),
394 + "codoc_entry_code" => $entryCode,
395 + ],[
396 + "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
397 + "token" => get_option(CODOC_TOKEN_OPTION_NAME),
398 + ]);
399 +
400 + if (is_object($res) and $res->status and !$entryCode) {
401 + update_post_meta($post_ID,'codoc_entry_code',$res->entry->code);
473 402 }
403 +
474 404 return true;
475 405 }
476 406 function updated_post_meta( $meta_ID, $post_ID, $meta_key ) {
477 407 if ($meta_key != '_thumbnail_id') {
@@ -480,35 +410,17 @@
480 410 if ( has_post_thumbnail($post_ID) ) {
481 411 $attachment = wp_get_attachment_metadata( get_post_thumbnail_id($post_ID));
482 412 $upload_dir = wp_upload_dir();
483 413 $file_path = sprintf ('%s/%s',$upload_dir['basedir'],$attachment['file']);
484 -
485 - if (is_readable($file_path)) {
486 - $name = 'file';
487 -
488 - $boundary = wp_generate_password(24);
489 -
490 - $payload = '';
491 - $payload .= '--' . $boundary;
492 - $payload .= "\r\n";
493 - $payload .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . basename( $file_path ) . '"' . "\r\n";
494 - $payload .= "Content-Type: application/octet-stream\r\n";
495 - $payload .= "Content-Transfer-Encoding: binary\r\n";
496 - $payload .= "\r\n";
497 - $payload .= file_get_contents( $file_path );
498 - $payload .= "\r\n";
499 -
500 - $payload .= '--' . $boundary . '--';
501 -
502 -
503 - $entryCode = get_post_meta($post_ID,'codoc_entry_code',true);
504 - $res = $this->callAPI(
505 - 'POST',
506 - '/entries/' . $entryCode . '/thumbnail',
507 - $payload,
508 - ['content-type' => 'multipart/form-data; boundary=' . $boundary]
509 - );
510 - }
414 +
415 + return $this->util->post_thumbnail([
416 + "file_path" => $file_path,
417 + "boundary" => wp_generate_password(24),
418 + "codoc_entry_code" => get_post_meta($post_ID,'codoc_entry_code',true),
419 + ],[
420 + "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
421 + "token" => get_option(CODOC_TOKEN_OPTION_NAME),
422 + ]);
511 423 }
512 424 }
513 425 function deleted_post_meta( $meta_ids, $post_ID, $meta_key,$meta_value ) {
514 426 if ($meta_key != '_thumbnail_id') {
@@ -513,48 +425,27 @@
513 425 function deleted_post_meta( $meta_ids, $post_ID, $meta_key,$meta_value ) {
514 426 if ($meta_key != '_thumbnail_id') {
515 427 return;
516 428 }
517 - $entryCode = get_post_meta($post_ID,'codoc_entry_code',true);
518 - $res = $this->callAPI(
519 - 'POST',
520 - '/entries/' . $entryCode . '/thumbnail',
521 - [ "reset" => 1 ]
522 - );
523 - }
429 + return $this->util->reset_thumbnail(
430 + ["codoc_entry_code" => get_post_meta($post_ID,'codoc_entry_code',true)],
431 + [
432 + "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
433 + "token" => get_option(CODOC_TOKEN_OPTION_NAME),
434 + ]
435 + );
436 + }
437 +
524 438 function the_content( $post_content ) {
525 - if ( is_single() && in_the_loop() && is_main_query() ) {
526 - }
527 - // codoc タグがあるかどうか (202001:span -> div に変更)
528 - preg_match('/(<(span|div)[^>]+data-id="codoc-tag"(?:[^>]+|)>(?:.+|)<\/(?:div|span)>)/',$post_content,$matches);
529 - // data-wp-plugin-ver が無いタグは分割しない
530 - if (!$matches) {
531 - return $post_content;
532 - }
533 - // codocタグで分割 (202001: gutenbergで直前のdivタグを削除)
534 - $tag_regex = '/(?:<div(?:[^>]+|)>|)<(?:span|div)[^>]+data-id="codoc-tag"(?:[^>]+|)>(?:.+|)<\/(?:span|div)>(?:<\/div>|)/';
535 - if ( is_preview() ) {
536 - $post_content = preg_replace($tag_regex,'<div class="codoc-continue">ここから上は無料で表示されます</div>',$post_content);
537 - return $post_content;
538 - }
539 - // codoc タグの前後で分ける
540 - $splited = preg_split($tag_regex,$post_content);
541 - // codoc タグにID属性のentrycodeとdata-without-body(無料分を非表示)をつける
439 + if ( is_single() && in_the_loop() && is_main_query() ) {
440 + }
542 441 $post = get_post();
543 - $entryCode = sprintf('"codoc-entry-%s" ',get_post_meta($post->ID,'codoc_entry_code',true));
544 - $codoc_tag = preg_replace('/<((?:span|div)[^>]+)data-id="[^"]+"((?:[^>]+|))>/','<${1} ${2} data-without-body="1" id=' . $entryCode . ">", $matches[1]);
545 -
546 - # THE THOR の page-lp.php が " " をけずるための対策
547 - # "div class" -> "div class"
548 - $codoc_tag = preg_replace('/div +class/','div class',$codoc_tag);
549 -
550 - $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
551 - $before = $CODOC_SETTINGS['str_before_codoc_tag'] or "";
552 - $after = $CODOC_SETTINGS['str_after_codoc_tag'] or "";
553 -
554 - // 無料部分のみ表示
555 - return $splited[0] . sprintf('%s<div class="wp-block-codoc-codoc-block">%s</div>%s',$before,$codoc_tag,$after);
442 + return $this->util->filter_content([
443 + "post_content" => $post_content,
444 + "preview" => is_preview(),
445 + "codoc_entry_code" => get_post_meta($post->ID,'codoc_entry_code',true),
446 + "codoc_settings" => get_option(CODOC_SETTINGS_OPTION_NAME),
447 + ]);
556 448 }
557 -
558 449
559 450 }
560 451