| @@ -33,11 +33,8 @@ | ||
| 33 | 33 | add_filter('codoc_the_content',[$this,'the_content'],$priority); |
| 34 | 34 | |
| 35 | 35 | // 2020-07-25 excerpt対応 |
| 36 | 36 | add_filter('excerpt_allowed_blocks',[$this,'excerpt_allowed_blocks']); |
| 37 | - | |
| 38 | - // テーマが allowed_block_types_all で制限している場合に codoc ブロックを許可リストに追加 | |
| 39 | - add_filter('allowed_block_types_all', [$this,'allowed_block_types_all'], 100, 2); | |
| 40 | 37 | |
| 41 | 38 | $auth_info = get_option(CODOC_AUTHINFO_OPTION_NAME); |
| 42 | 39 | |
| 43 | 40 | if ($auth_info) { |
| @@ -45,10 +42,8 @@ | ||
| 45 | 42 | add_action( 'save_post', [$this,'save_post'], 20, 3 ); |
| 46 | 43 | add_action( 'added_post_meta', [$this,'updated_post_meta'], 10, 3 ); |
| 47 | 44 | add_action( 'updated_post_meta',[$this,'updated_post_meta'], 10, 3 ); |
| 48 | 45 | add_action( 'deleted_post_meta',[$this,'deleted_post_meta'], 10, 4 ); |
| 49 | - // 文字数バリデーションエラーの管理画面通知 | |
| 50 | - add_action( 'admin_notices', [$this,'show_validation_notices'] ); | |
| 51 | 46 | } |
| 52 | 47 | global $pagenow; |
| 53 | 48 | //管理画面でcodoc認証があり投稿画面の場合 |
| 54 | 49 | if (is_admin() and $auth_info and preg_match('/^post/',$pagenow)) { |
| @@ -327,11 +322,8 @@ | ||
| 327 | 322 | } |
| 328 | 323 | if (!isset($CODOC_SETTINGS['debug_params'])) { |
| 329 | 324 | $CODOC_SETTINGS['debug_params'] = ''; |
| 330 | 325 | } |
| 331 | - if (!isset($CODOC_SETTINGS['block_defaults'])) { | |
| 332 | - $CODOC_SETTINGS['block_defaults'] = ''; | |
| 333 | - } | |
| 334 | 326 | add_settings_section( |
| 335 | 327 | 'setting_section_id', // id |
| 336 | 328 | __('codoc Settings','codoc'), // title |
| 337 | 329 | [$this,'show_tadv_notice'], |
| @@ -354,19 +346,9 @@ | ||
| 354 | 346 | } |
| 355 | 347 | |
| 356 | 348 | register_setting( |
| 357 | 349 | 'codoc_option_group', // option group |
| 358 | - CODOC_SETTINGS_OPTION_NAME, // option name(DB) | |
| 359 | - array('sanitize_callback' => function($input) { | |
| 360 | - if (isset($input['block_defaults']) && $input['block_defaults'] !== '') { | |
| 361 | - if (json_decode($input['block_defaults'], true) === null && $input['block_defaults'] !== 'null') { | |
| 362 | - $old = get_option(CODOC_SETTINGS_OPTION_NAME); | |
| 363 | - $input['block_defaults'] = isset($old['block_defaults']) ? $old['block_defaults'] : ''; | |
| 364 | - add_settings_error('block_defaults', 'invalid_json', esc_html(__('Block Default Values: Invalid JSON format. The value was not saved.','codoc')), 'error'); | |
| 365 | - } | |
| 366 | - } | |
| 367 | - return $input; | |
| 368 | - }) | |
| 350 | + CODOC_SETTINGS_OPTION_NAME // option name(DB) | |
| 369 | 351 | ); |
| 370 | 352 | add_settings_field( |
| 371 | 353 | 'css_path', // id |
| 372 | 354 | __('Theme','codoc'), // title |
| @@ -610,32 +592,8 @@ | ||
| 610 | 592 | 'setting_section_id' //Section |
| 611 | 593 | ); |
| 612 | 594 | |
| 613 | 595 | add_settings_field( |
| 614 | - 'block_defaults', // id | |
| 615 | - __('Block Default Values','codoc'), // title | |
| 616 | - function() { | |
| 617 | - global $CODOC_SETTINGS; | |
| 618 | - echo '<div class="excerpt">' . esc_html(__('You can specify default values for new codoc blocks in JSON format.','codoc')) . '</div>'; | |
| 619 | - echo sprintf('<textarea placeholder=\'{"showPrice":false,"price":300}\' rows="3" cols="50" name="%s[block_defaults]">%s</textarea>',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_html($CODOC_SETTINGS['block_defaults'])); | |
| 620 | - echo '<p class="description">' | |
| 621 | - . 'showPrice (bool: true), ' | |
| 622 | - . 'price (int: 500), ' | |
| 623 | - . 'limited (bool: false), ' | |
| 624 | - . 'limitedCount (int: 10), ' | |
| 625 | - . 'affiliateMode (bool: false), ' | |
| 626 | - . 'affiliateRate (string: "0.0500"), ' | |
| 627 | - . 'showSupport (bool: false), ' | |
| 628 | - . 'showPaywalledSupport (bool: false), ' | |
| 629 | - . 'statusLimited (bool: false), ' | |
| 630 | - . 'subscriptions (object: {})' | |
| 631 | - . '</p>'; | |
| 632 | - }, | |
| 633 | - 'codoc', //page | |
| 634 | - 'setting_section_id' //Section | |
| 635 | - ); | |
| 636 | - | |
| 637 | - add_settings_field( | |
| 638 | 596 | 'cretor_info', // id |
| 639 | 597 | __('Creator\'s Information','codoc'), // title |
| 640 | 598 | function() { |
| 641 | 599 | global $CODOC_SETTINGS; |
| @@ -843,12 +801,8 @@ | ||
| 843 | 801 | $path = plugins_url( 'codoc/src_mce/codoc-editor-onload.js', __DIR__ ); |
| 844 | 802 | wp_enqueue_script( 'codoc-editor-onload', $path, array('jquery'), '', true ); |
| 845 | 803 | // I just want to insert this global variables but i don't know how i can do it.. |
| 846 | 804 | $auth_info = get_option(CODOC_AUTHINFO_OPTION_NAME); |
| 847 | - $codoc_settings = get_option(CODOC_SETTINGS_OPTION_NAME); | |
| 848 | - $block_defaults_raw = isset($codoc_settings['block_defaults']) ? $codoc_settings['block_defaults'] : ''; | |
| 849 | - $block_defaults_decoded = json_decode($block_defaults_raw, true); | |
| 850 | - $block_defaults = is_array($block_defaults_decoded) ? $block_defaults_decoded : new stdClass(); | |
| 851 | 805 | wp_localize_script( |
| 852 | 806 | 'codoc-editor-onload', |
| 853 | 807 | 'CODOCEDITOR', |
| 854 | 808 | array( |
| @@ -861,9 +815,8 @@ | ||
| 861 | 815 | 'codoc_sdk_path' => CODOC_SDK_PATH, |
| 862 | 816 | 'codoc_account_is_pro' => isset($auth_info['account_is_pro']) ? $auth_info['account_is_pro'] : 0, |
| 863 | 817 | 'codoc_currency_code' => isset($auth_info['currency_code']) ? $auth_info['currency_code'] : 0, |
| 864 | 818 | 'codoc_currency_decimal_places' => isset($auth_info['currency_decimal_places']) ? $auth_info['currency_decimal_places'] : 0, |
| 865 | - 'codoc_block_defaults' => $block_defaults, | |
| 866 | 819 | ) |
| 867 | 820 | ); |
| 868 | 821 | |
| 869 | 822 | // ここでtinymceのプラグイン追加 |
| @@ -1012,39 +965,8 @@ | ||
| 1012 | 965 | } |
| 1013 | 966 | $codoc_settings = get_option(CODOC_SETTINGS_OPTION_NAME); |
| 1014 | 967 | $post_content = (isset($codoc_settings['do_not_filter_the_content']) and $codoc_settings['do_not_filter_the_content']) ? |
| 1015 | 968 | $post->post_content : $this->get_filtered_content($post); |
| 1016 | - | |
| 1017 | - // codoc タグ(span/div または Gutenberg ブロック)が含まれていれば API側と統一した文字数検証を行う | |
| 1018 | - $has_codoc_tag = preg_match('/<(?:span|div)[^>]+data-id="codoc-tag"/', $post_content) | |
| 1019 | - || preg_match('/wp:codoc\/codoc-block/', $post_content); | |
| 1020 | - if ($has_codoc_tag) { | |
| 1021 | - // codoc タグ位置で free / paywalled を分割 | |
| 1022 | - $gutenberg_split = '/(?:<(?:div|p)(?:[^>]+|)>|)<\!-- +wp:codoc\/codoc-block .*<\!-- +\/wp:codoc\/codoc-block +-->(?:<\/(?:div|p)>|)/s'; | |
| 1023 | - $tag_split = '/<(?:span|div)[^>]+data-id="codoc-tag"(?:[^>]+|)>(?:.+|)<\/(?:span|div)>/'; | |
| 1024 | - $end_tag_regex = '/<(?:div|p)>::CODOC_WP_END_PAYWALL::<\/(?:div|p)>/'; | |
| 1025 | - $for_split = preg_split($end_tag_regex, $post_content); | |
| 1026 | - $for_split = $for_split[0]; | |
| 1027 | - if (preg_match('/wp:codoc\/codoc-block/', $for_split)) { | |
| 1028 | - $splited = preg_split($gutenberg_split, $for_split); | |
| 1029 | - } else { | |
| 1030 | - $splited = preg_split($tag_split, $for_split); | |
| 1031 | - } | |
| 1032 | - $body_free = isset($splited[0]) ? $splited[0] : ''; | |
| 1033 | - $body_paywalled = isset($splited[1]) ? $splited[1] : ''; | |
| 1034 | - $errors = $this->util->validate_entry_lengths([ | |
| 1035 | - 'title' => $post->post_title, | |
| 1036 | - 'body_free' => $body_free, | |
| 1037 | - 'body_paywalled' => $body_paywalled, | |
| 1038 | - 'binded_url' => get_permalink($post_ID), | |
| 1039 | - ]); | |
| 1040 | - if ($errors) { | |
| 1041 | - set_transient('codoc_entry_validation_errors', $errors, MINUTE_IN_SECONDS * 5); | |
| 1042 | - // 同期はスキップ | |
| 1043 | - return true; | |
| 1044 | - } | |
| 1045 | - } | |
| 1046 | - | |
| 1047 | 969 | $res = $this->util->sync_entry([ |
| 1048 | 970 | "post_title" => $post->post_title, |
| 1049 | 971 | "post_content" => $post_content, |
| 1050 | 972 | // password が設定されてる場合は限定公開にする |
| @@ -1166,34 +1088,8 @@ | ||
| 1166 | 1088 | if (is_array($allowed_blocks)) { |
| 1167 | 1089 | array_push($allowed_blocks,'codoc/codoc-block'); |
| 1168 | 1090 | } |
| 1169 | 1091 | return $allowed_blocks; |
| 1170 | - } | |
| 1171 | - | |
| 1172 | - function allowed_block_types_all ($allowed_block_types, $block_editor_context) { | |
| 1173 | - // テーマ等がブロックを制限していない場合(true = 全ブロック許可)はそのまま返す | |
| 1174 | - if ($allowed_block_types === true) { | |
| 1175 | - return $allowed_block_types; | |
| 1176 | - } | |
| 1177 | - // 配列で制限されている場合、codoc ブロックを追加 | |
| 1178 | - if (is_array($allowed_block_types) && !in_array('codoc/codoc-block', $allowed_block_types)) { | |
| 1179 | - $allowed_block_types[] = 'codoc/codoc-block'; | |
| 1180 | - } | |
| 1181 | - return $allowed_block_types; | |
| 1182 | - } | |
| 1183 | - | |
| 1184 | - function show_validation_notices() { | |
| 1185 | - $errors = get_transient('codoc_entry_validation_errors'); | |
| 1186 | - if (!$errors || !is_array($errors)) { | |
| 1187 | - return; | |
| 1188 | - } | |
| 1189 | - delete_transient('codoc_entry_validation_errors'); | |
| 1190 | - $header = __('codoc could not sync this entry due to length limits:', 'codoc'); | |
| 1191 | - echo '<div class="notice notice-error is-dismissible"><p><strong>' . esc_html($header) . '</strong></p><ul>'; | |
| 1192 | - foreach ($errors as $message) { | |
| 1193 | - echo '<li>' . esc_html($message) . '</li>'; | |
| 1194 | - } | |
| 1195 | - echo '</ul></div>'; | |
| 1196 | 1092 | } |
| 1197 | 1093 | |
| 1198 | 1094 | function show_tadv_notice() { |
| 1199 | 1095 | // API からの notification を表示 |