PluginProbe
codoc / 0.9.58
codoc v0.9.58
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 +0 -62 trunk0.9.58 View file →
@@ -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)) {
@@ -1012,39 +1007,8 @@
1012 1007 }
1013 1008 $codoc_settings = get_option(CODOC_SETTINGS_OPTION_NAME);
1014 1009 $post_content = (isset($codoc_settings['do_not_filter_the_content']) and $codoc_settings['do_not_filter_the_content']) ?
1015 1010 $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 1011 $res = $this->util->sync_entry([
1048 1012 "post_title" => $post->post_title,
1049 1013 "post_content" => $post_content,
1050 1014 // password が設定されてる場合は限定公開にする
@@ -1166,34 +1130,8 @@
1166 1130 if (is_array($allowed_blocks)) {
1167 1131 array_push($allowed_blocks,'codoc/codoc-block');
1168 1132 }
1169 1133 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 1134 }
1197 1135
1198 1136 function show_tadv_notice() {
1199 1137 // API からの notification を表示