PluginProbe
codoc / 0.9.40
codoc v0.9.40
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
codoc / class-codoc.php

class-codoc.php in codoc 0.9.40, at class-codoc.php

966 lines 55.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require_once(plugin_dir_path( __FILE__ ) .'class-codoc-util.php');
3 final class Codoc {
4
5 public function __construct() {
6 if (is_admin()) {
7 // setting
8 $this->add_settings();
9 }
10
11 // usercode, token はadminページのみDBから取得する
12 $this->util = new CodocUtil([ 'usercode' => null, 'token' => null, 'codoc_url' => $this->get_codoc_url() ]);
13
14 # the_content フィルタを実行しない状�
15
16 $this->do_not_filter_the_content = false;
17
18 // paywall用の本文非表示化とcodocタグへの属性追加
19 #$priority = 999999999;
20 $priority = 100000; # フィルターは最後に実施する default 10
21 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
22 if (isset($CODOC_SETTINGS["debug_params"])) {
23 $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true);
24 if (isset($params_decoded["the_content_filter_priority"])) {
25 $priority = $params_decoded["the_content_filter_priority"];
26 }
27 }
28 add_filter('the_content',[$this,'the_content'],$priority);
29 // 2021-09-24 the_content を利用しない場合は個別に呼び出ししてもらう
30 add_filter('codoc_the_content',[$this,'the_content'],$priority);
31
32 // 2020-07-25 excerpt対応
33 add_filter('excerpt_allowed_blocks',[$this,'excerpt_allowed_blocks']);
34
35 $auth_info = get_option(CODOC_AUTHINFO_OPTION_NAME);
36
37 if ($auth_info) {
38 // データ同期 (save_postはis_adminで実行されないケースがある)
39 add_action( 'save_post', [$this,'save_post'], 20, 3 );
40 add_action( 'added_post_meta', [$this,'updated_post_meta'], 10, 3 );
41 add_action( 'updated_post_meta',[$this,'updated_post_meta'], 10, 3 );
42 add_action( 'deleted_post_meta',[$this,'deleted_post_meta'], 10, 4 );
43 }
44 global $pagenow;
45 //管理画面でcodoc認証があり投稿画面の場合
46 if (is_admin() and $auth_info and preg_match('/^post/',$pagenow)) {
47 // Gutenberg のサポートがない場合は何もしない
48 if ( function_exists( 'register_block_type' ) ) {
49 // WPに登録ブロックとして認識させる(cgbは登録しないっぽい)
50 \WP_Block_Type_Registry::get_instance()->register('codoc/codoc-block');
51 // gutenberg
52 require_once 'src/init.php';
53 add_action('wp_loaded', function() {
54 wp_localize_script('wordpress-cgb-block-js', 'OPTIONS', array(
55 'codoc_url' => $this->get_codoc_url(),
56 'codoc_usercode' => get_option(CODOC_USERCODE_OPTION_NAME),
57 'codoc_plugin_version' => CODOC_PLUGIN_VERSION,
58 'codoc_sdk_path' => CODOC_SDK_PATH,
59 ));
60 });
61 }
62 // tinymce
63 $this->add_mce();
64 } elseif(is_admin() and $auth_info and preg_match('/^edit/',$pagenow)) {
65 // 記事編集ページ
66 } elseif(!is_admin()) { // ブログ画面
67 // codocのJS登録
68 add_action( 'wp_enqueue_scripts', function() {
69 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
70 $load_script_condition = '';
71 if (isset($CODOC_SETTINGS["debug_params"]) and
72 $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true) and
73 isset($params_decoded["load_script_condition"])
74 ) {
75 $load_script_condition = $params_decoded["load_script_condition"];
76 }
77 if ($load_script_condition == 'not_list_page') {
78 // not_list_pageの場合はトップページ等でスクリプトをロードしない
79 if (!(is_archive() or is_category() or is_home() or is_front_page())) {
80 wp_enqueue_script( 'codoc-injector-js', $this->get_codoc_url() . '/js/cms.js' );
81 }
82 } else {
83 wp_enqueue_script( 'codoc-injector-js', $this->get_codoc_url() . '/js/cms.js' );
84 }
85 });
86 //登録したscriptタグに属性をつける
87 add_filter('script_loader_tag', [$this,'modifier_script_tag'],10,2);
88 // tinymce用のショートコード
89 add_shortcode('codoc', [$this, 'injector_shortcode']);
90 // テーマをbodyにも反映
91 add_filter('body_class', function($classes) {
92 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
93 $css_path = 'blue';
94 if (isset($CODOC_SETTINGS["css_path"]) and $CODOC_SETTINGS["css_path"]) {
95 $css_path = $CODOC_SETTINGS["css_path"];
96 }
97 array_push($classes,sprintf( "codoc-theme-%s",$css_path));
98 return $classes;
99 });
100
101 }
102 return $this;
103 }
104 public function get_codoc_url() {
105 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
106 if (isset($CODOC_SETTINGS["debug_params"])) {
107 $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true);
108 if (isset($params_decoded["codoc_url"])) {
109 return $params_decoded["codoc_url"];
110 }
111 }
112 return CODOC_URL;
113 }
114 public function modifier_script_tag($tag,$handle) {
115 if($handle !== 'codoc-injector-js') {
116 return $tag;
117 }
118 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
119 $data_css = '';
120 if ($css_path = $CODOC_SETTINGS['css_path']) {
121 $data_css = sprintf(' data-css="%s" ',$css_path);
122 }
123 // connect用パラメータ
124 $connect_attributes = '';
125 if (isset($CODOC_SETTINGS["codoc_connect_code"])) {
126 $connect_code = $CODOC_SETTINGS["codoc_connect_code"];
127 $connect_attributes = sprintf(' data-connect-code="%s"',$connect_code);
128 $tag = preg_replace('/cms\.js/','cms-connect.js',$tag);
129 }
130 if (isset($CODOC_SETTINGS["codoc_connect_registration_mode"]) and $CODOC_SETTINGS["codoc_connect_registration_mode"]) {
131 $connect_attributes = $connect_attributes .
132 sprintf(' data-connect-registration-mode="%s"',$CODOC_SETTINGS["codoc_connect_registration_mode"]);
133 }
134
135 $usercode_attributes = '';
136 $user_code = get_option(CODOC_USERCODE_OPTION_NAME);
137 if ($user_code) {
138 $usercode_attributes = sprintf(' data-usercode="%s"',$user_code);
139 }
140
141 $setting_attributes = '';
142 if (isset($CODOC_SETTINGS['codoc_script_tag_attributes']) and $CODOC_SETTINGS['codoc_script_tag_attributes']) {
143 $setting_attributes = $CODOC_SETTINGS['codoc_script_tag_attributes'];
144 }
145 //return str_replace(' src=', $data_css . ' defer src=', $tag);
146 return preg_replace('/(src=[^>]+)/',' ${1} ' . $data_css . $connect_attributes . $usercode_attributes . $setting_attributes . ' defer',$tag);
147 }
148 public function injector_shortcode($atts) {
149 global $post;
150 ob_start();
151 require 'views/codoc-injector.php';
152 return ob_get_clean();
153 }
154 # settings / 設定関連
155 public function add_settings() {
156 global $CODOC_SETTINGS;
157 add_action( 'admin_menu' ,function(){
158 add_options_page(
159 'codoc の設定', //ページタイトル
160 'codoc', //設定メニューに表示されるメニュータイトル
161 'edit_users', //権限
162 'codoc', //設定ページのURL。options-general.php?page=codoc
163 function() {
164 echo '<div class="codoc-settings">';
165 echo '<form method="post" action="options.php">';
166 settings_fields( 'codoc_option_group' );
167 do_settings_sections( 'codoc' );
168 submit_button(); // 送信ボタン
169 echo '</form></div>';
170 }
171 );
172 });
173
174 add_action('admin_print_styles', 'codoc_admin_styles');
175 function codoc_admin_styles($hook) {
176 wp_enqueue_style('codoc-options-style', plugins_url( 'codoc/css/codoc-options.css', __DIR__ ));
177 }
178 add_action( "admin_init", function() {
179 // codocからの認証データ処理
180 if (isset($_GET['page']) and $_GET['page'] == 'codoc' and isset($_GET['fetch_token_key'])) {
181 $key = sanitize_text_field($_GET['fetch_token_key']);
182 $usercode = sanitize_text_field($_GET['usercode']);
183 update_option(CODOC_USERCODE_OPTION_NAME,$usercode);
184 //$data = $this->callAPI('GET','/token',[ "fetch_token_key" => $key ]);
185 $data = $this->util->get_token([ "fetch_token_key" => $key ],["usercode" => $usercode, "token" => "1"]);
186 if ($data->status and $token = $data->token) {
187 update_option(CODOC_TOKEN_OPTION_NAME,$token);
188 //$data = $this->callAPI('GET','');
189 $data = $this->util->get_user_info([],["usercode" => $usercode, "token" => $token]);
190 if ($data->status and $user = $data->user) {
191 $this->update_codoc_authinfo($user);
192 }
193 #$current_url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
194 #$current_url = preg_replace('/(.*)fetch_token_key.*/','${1}&codoc_auth_finished=1',$current_url);
195 //add_settings_error( 'general', 'settings_updated', __( 'OK' ), 'success' );
196 $current_url = admin_url('options-general.php') . '?page=codoc&codoc_auth_finished=1';
197
198 wp_redirect( $current_url);
199 exit;
200 }
201 }
202 global $CODOC_USERCODE;
203 global $CODOC_SETTINGS;
204 global $CODOC_TOKEN;
205 global $CODOC_AUTHINFO;
206 $CODOC_USERCODE = get_option(CODOC_USERCODE_OPTION_NAME);
207 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
208 $CODOC_TOKEN = get_option(CODOC_TOKEN_OPTION_NAME);
209 $CODOC_AUTHINFO = get_option(CODOC_AUTHINFO_OPTION_NAME);
210 if( !$CODOC_SETTINGS ) {
211 //デフォルト値
212 $CODOC_SETTINGS = array(
213 'css_path' => '',
214 );
215 update_option( CODOC_SETTINGS_OPTION_NAME, $CODOC_SETTINGS );
216 }
217 if (!isset($CODOC_SETTINGS['str_replace_binded_url_from'])) {
218 $CODOC_SETTINGS['str_replace_binded_url_from'] = '';
219 }
220 if (!isset($CODOC_SETTINGS['str_replace_binded_url_to'])) {
221 $CODOC_SETTINGS['str_replace_binded_url_to'] = '';
222 }
223 if (!isset($CODOC_SETTINGS['str_before_codoc_tag'])) {
224 $CODOC_SETTINGS['str_before_codoc_tag'] = '';
225 }
226 if (!isset($CODOC_SETTINGS['str_after_codoc_tag'])) {
227 $CODOC_SETTINGS['str_after_codoc_tag'] = '';
228 }
229
230 if (!isset($CODOC_SETTINGS['always_show_support'])) {
231 $CODOC_SETTINGS['always_show_support'] = '0';
232 }
233 if (!isset($CODOC_SETTINGS['show_support_message'])) {
234 $CODOC_SETTINGS['show_support_message'] = '';
235 }
236 if (!isset($CODOC_SETTINGS['show_support_categories'])) {
237 $CODOC_SETTINGS['show_support_categories'] = '';
238 }
239 if (!isset($CODOC_SETTINGS['show_support_location'])) {
240 $CODOC_SETTINGS['show_support_location'] = 'bottom';
241 }
242 if (!isset($CODOC_SETTINGS['do_not_filter_the_content'])) {
243 $CODOC_SETTINGS['do_not_filter_the_content'] = '0';
244 }
245
246 if (!isset($CODOC_SETTINGS['entry_button_text'])) {
247 $CODOC_SETTINGS['entry_button_text'] = '';
248 }
249 if (!isset($CODOC_SETTINGS['subscription_button_text'])) {
250 $CODOC_SETTINGS['subscription_button_text'] = '';
251 }
252 if (!isset($CODOC_SETTINGS['support_button_text'])) {
253 $CODOC_SETTINGS['support_button_text'] = '';
254 }
255 if (!isset($CODOC_SETTINGS['subscription_message'])) {
256 $CODOC_SETTINGS['subscription_message'] = '';
257 }
258 if (!isset($CODOC_SETTINGS['support_message'])) {
259 $CODOC_SETTINGS['support_message'] = '';
260 }
261 if (!isset($CODOC_SETTINGS['show_like'])) {
262 $CODOC_SETTINGS['show_like'] = '1';
263 }
264 if (!isset($CODOC_SETTINGS['show_about_codoc'])) {
265 $CODOC_SETTINGS['show_about_codoc'] = '1';
266 }
267 if (!isset($CODOC_SETTINGS['show_powered_by'])) {
268 $CODOC_SETTINGS['show_powered_by'] = '1';
269 }
270
271 if (!isset($CODOC_SETTINGS['codoc_tag_attributes'])) {
272 $CODOC_SETTINGS['codoc_tag_attributes'] = '';
273 }
274 if (!isset($CODOC_SETTINGS['codoc_script_tag_attributes'])) {
275 $CODOC_SETTINGS['codoc_script_tag_attributes'] = '';
276 }
277 if (!isset($CODOC_SETTINGS['codoc_connect_code'])) {
278 $CODOC_SETTINGS['codoc_connect_code'] = '';
279 }
280 if (!isset($CODOC_SETTINGS['codoc_connect_registration_mode'])) {
281 $CODOC_SETTINGS['codoc_connect_registration_mode'] = '';
282 }
283 if (!isset($CODOC_SETTINGS['debug_params'])) {
284 $CODOC_SETTINGS['debug_params'] = '';
285 }
286 add_settings_section(
287 'setting_section_id', // id
288 'codoc 設定ページ', // title
289 function (){}, // callback
290 'codoc' // page
291 );
292 // 認証がある場合
293 if ($CODOC_AUTHINFO) {
294 // クリエイター�
295 報だけ更新 (POST時に同期をとる)
296 if (isset($_GET['page']) and $_GET['page'] == 'codoc' and isset($_GET['settings-updated'])) {
297 $data = $this->util->get_user_info([],[
298 "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
299 "token" => get_option(CODOC_TOKEN_OPTION_NAME),
300 ]);
301 if ($data->status and $user = $data->user) {
302 $this->update_codoc_authinfo($user);
303 }
304 }
305
306 register_setting(
307 'codoc_option_group', // option group
308 CODOC_SETTINGS_OPTION_NAME // option name(DB)
309 );
310 add_settings_field(
311 'css_path', // id
312 'テーマ', // title
313 function() {
314 global $CODOC_SETTINGS;
315 echo '<div class="excerpt">テーマを指定してペイウォールのデザインを変えることができます。<br>パスを指定を選択することでCSSを直接指定するこもと可能です。</div>';
316 echo sprintf('<div class="inputGroup"><input type="text" name="%s[css_path]" value="%s" id="codoc_css_path" readonly>',CODOC_SETTINGS_OPTION_NAME,$CODOC_SETTINGS['css_path']);
317 echo '' .
318 '<script type="text/javascript"> ' .
319 ' function gen_css_path(select) { ' .
320 ' if (select.value == "dark") { ' .
321 ' document.getElementById("darkmode-caution").style.display="block";' .
322 ' } else { ' .
323 ' if (document.getElementById("darkmode-caution")) { ' .
324 ' document.getElementById("darkmode-caution").style.display="none";' .
325 ' } ' .
326 ' } ' .
327 ' if (select.value == "path") { ' .
328 ' document.getElementById("codoc_css_path").readOnly=false; ' .
329 ' if (!document.getElementById("codoc_css_path").value.match(/\//g)) {' .
330 ' document.getElementById("codoc_css_path").value=""; ' .
331 ' } ' .
332 ' } else { ' .
333 ' document.getElementById("codoc_css_path").readOnly=true; ' .
334 ' document.getElementById("codoc_css_path").value=select.value; ' .
335 ' } ' .
336 ' } ' .
337 '</script> ' ;
338
339 echo sprintf('<select name="theme_name" onChange="gen_css_path(this)" id="codoc_theme_select">');
340 foreach (["blue","red","green","black","dark","blue-square","red-square","green-square","black-square","dark-square"] as $theme) {
341 if ($theme == "blue") {
342 echo sprintf('<option value="%s" %s>青</option>', $theme, ($CODOC_SETTINGS["css_path"] == "blue" ? "selected" : ""));
343 }
344 if ($theme == "red") {
345 echo sprintf('<option value="%s" %s>赤</option>', $theme, ($CODOC_SETTINGS["css_path"] == "red" ? "selected" : ""));
346 }
347 if ($theme == "green") {
348 echo sprintf('<option value="%s" %s>緑</option>', $theme, ($CODOC_SETTINGS["css_path"] == "green" ? "selected" : ""));
349 }
350 if ($theme == "black") {
351 echo sprintf('<option value="%s" %s>黒</option>', $theme, ($CODOC_SETTINGS["css_path"] == "black" ? "selected" : ""));
352 }
353 if ($theme == "dark") {
354 echo sprintf('<option value="%s" %s>ダークモード</option>', $theme, ($CODOC_SETTINGS["css_path"] == "dark" ? "selected" : ""));
355 }
356 if ($theme == "blue-square") {
357 echo sprintf('<option value="%s" %s>青(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "blue-square" ? "selected" : ""));
358 }
359 if ($theme == "red-square") {
360 echo sprintf('<option value="%s" %s>赤(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "red-square" ? "selected" : ""));
361 }
362 if ($theme == "green-square") {
363 echo sprintf('<option value="%s" %s>緑(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "green-square" ? "selected" : ""));
364 }
365 if ($theme == "black-square") {
366 echo sprintf('<option value="%s" %s>黒(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "black-square" ? "selected" : ""));
367 }
368 if ($theme == "dark-square") {
369 echo sprintf('<option value="%s" %s>ダークモード(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "dark-square" ? "selected" : ""));
370 }
371 }
372 echo sprintf('<option value="path" %s>パス指定</option>', (preg_match("/\//",$CODOC_SETTINGS["css_path"]) ? "selected" : ""));
373 echo '<script type="text/javascript">gen_css_path(document.getElementById(\'codoc_theme_select\'))</script>';
374 echo sprintf('</select></div>');
375 echo '<p id="darkmode-caution" style="display:none">ダークモード向けテーマは文字色が白となり、背景色によっては文字が見えない状�
376 �となるためご注意ください。</p>';
377 },
378 'codoc', //page
379 'setting_section_id' //Section
380 );
381 add_settings_field(
382 'paywall_text', // id
383 '各種文言', // title
384 function() {
385 global $CODOC_SETTINGS;
386 echo '<div class="excerpt">ペイウォール�
387 の一部文言を変更できます。</div>';
388 echo '<table class="innerTable"><tbody>';
389 echo '<tr><th>いいねの表示</th><td>';
390 echo sprintf('<input type="radio" value="1" name="%s[show_like]" id="show_like_on" %s><label for="show_like_on">する</label> ',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['show_like'] == '1' ? "checked" : ""));
391 echo sprintf('<input type="radio" value="0" name="%s[show_like]" id="show_like_off" %s><label for="show_like_off">しない</label> <br / >',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['show_like'] == '0' ? "checked" : ""));
392 echo '</td></tr>';
393
394 echo '<tr><th>codocについての表示</th><td>';
395 echo sprintf('<input type="radio" value="1" name="%s[show_about_codoc]" id="show_about_codoc_on" %s><label for="show_about_codoc_on">する</label> ',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['show_about_codoc'] == '1' ? "checked" : ""));
396 echo sprintf('<input type="radio" value="0" name="%s[show_about_codoc]" id="show_about_codoc_off" %s><label for="show_about_codoc_off">しない</label> <br / >',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['show_about_codoc'] == '0' ? "checked" : ""));
397 echo '</td></tr>';
398
399 echo '<tr><th>PoweredByの表示</th><td>';
400 echo sprintf('<input type="radio" value="1" name="%s[show_powered_by]" id="show_powered_by_on" %s><label for="show_powered_by_on">する</label> ',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['show_powered_by'] == '1' ? "checked" : ""));
401 echo sprintf('<input type="radio" value="0" name="%s[show_powered_by]" id="show_powered_by_off" %s><label for="show_powered_by_off">しない</label> <br / >',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['show_powered_by'] == '0' ? "checked" : ""));
402 echo '</td></tr>';
403
404 echo '<tr><th>記事購�
405 �ボタンのテキスト</th><td>';
406 echo sprintf('<input type="text" name="%s[entry_button_text]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['entry_button_text']));
407 echo '</td></tr>';
408
409 echo '<tr><th>サブスクリプション購�
410 �ボタンのテキスト</th><td>';
411 echo sprintf('<input type="text" name="%s[subscription_button_text]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['subscription_button_text']));
412 echo '</td></tr>';
413
414 echo '<tr><th>サポートボタンのテキスト</th><td>';
415 echo sprintf('<input type="text" name="%s[support_button_text]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['support_button_text']));
416 echo '</td></tr>';
417
418 echo '<tr><th>「サブスクリプションに含まれる記事」のテキスト</th><td>';
419 echo sprintf('<input type="text" name="%s[subscription_message]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['subscription_message']));
420 echo '</td></tr>';
421
422 echo '<tr><th>サポート説明のテキスト</th><td>';
423 echo sprintf('<input type="text" name="%s[support_message]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['support_message']));
424 echo '</td></tr>';
425
426 echo '</tbody></table>';
427 },
428 'codoc', //page
429 'setting_section_id' //Section
430 );
431
432 add_settings_field(
433 'codoc_tag_attributes', // id
434 'codocタグの属性', // title
435 function() {
436 global $CODOC_SETTINGS;
437 echo '<div class="excerpt">codocタグに特定の属性を追加することができます。</div>';
438 echo sprintf('<input type="text" name="%s[codoc_tag_attributes]" value="%s">',CODOC_SETTINGS_OPTION_NAME,htmlspecialchars($CODOC_SETTINGS['codoc_tag_attributes']));
439 },
440 'codoc', //page
441 'setting_section_id' //Section
442 );
443 add_settings_field(
444 'codoc_script_tag_attributes', // id
445 'codoc scriptタグの属性', // title
446 function() {
447 global $CODOC_SETTINGS;
448 echo '<div class="excerpt">codoc scriptタグに特定の属性を追加することができます。</div>';
449 echo sprintf('<input type="text" name="%s[codoc_script_tag_attributes]" value="%s">',CODOC_SETTINGS_OPTION_NAME,htmlspecialchars($CODOC_SETTINGS['codoc_script_tag_attributes']));
450 },
451 'codoc', //page
452 'setting_section_id' //Section
453 );
454 add_settings_field(
455 'str_replace_binded_url', // id
456 'パーマリンク', // title
457 function() {
458 global $CODOC_SETTINGS;
459 echo '<div class="excerpt">codoc側に登録するパーマリンクを置換することができます。</div>';
460 echo sprintf('<input type="text" name="%s[str_replace_binded_url_from]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['str_replace_binded_url_from']));
461 echo ('<span class="suptext"></span>');
462 echo sprintf('<input type="text" name="%s[str_replace_binded_url_to]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['str_replace_binded_url_to']));
463 echo ('に変換');
464 },
465 'codoc', //page
466 'setting_section_id' //Section
467 );
468
469 add_settings_field(
470 'str_around_codoc_tag', // id
471 'HTMLの挿�
472 �', // title
473 function() {
474 global $CODOC_SETTINGS;
475 echo '<div class="excerpt">codocタグの前後にHTMLを挿�
476 �することができます。</div>';
477 echo sprintf('<div class="inputRow"><textarea name="%s[str_before_codoc_tag]" cols="40">%s</textarea>',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['str_before_codoc_tag']));
478 echo ('を前に挿�
479 �</div>');
480 echo sprintf('<div class="inputRow"><textarea name="%s[str_after_codoc_tag]" cols="40">%s</textarea>',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['str_after_codoc_tag']));
481 echo ('を後に挿�
482 �</div>');
483
484 },
485 'codoc', //page
486 'setting_section_id' //Section
487 );
488
489 add_settings_field(
490 'always_show_support_tag', // id
491 'サポートの自動挿�
492 �', // title
493 function() {
494 global $CODOC_SETTINGS;
495 echo '<div class="excerpt">codocブロックを挿�
496 �することなく投稿にサポート機能を追加します</div>';
497 echo '<table class="innerTable"><tbody>';
498 echo '<tr><th>自動挿�
499 �</th><td>';
500 echo sprintf('<input type="radio" value="1" name="%s[always_show_support]" id="always_show_support_on" %s><label for="always_show_support_on">する</label> ',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['always_show_support'] == '1' ? "checked" : ""));
501 echo sprintf('<input type="radio" value="0" name="%s[always_show_support]" id="always_show_support_off" %s><label for="always_show_support_off">しない</label> <br / >',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['always_show_support'] == '0' ? "checked" : ""));
502 echo '</td></tr>';
503 echo '<tr><th>表示位置</th><td>';
504 echo sprintf('<input type="radio" value="top" name="%s[show_support_location]" id="show_support_location_top" %s><label for="show_support_location_top">冒頭</label> ',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['show_support_location'] == 'top' ? "checked" : ""));
505 echo sprintf('<input type="radio" value="bottom" name="%s[show_support_location]" id="show_support_location_bottom" %s><label for="show_support_location_bottom">末尾</label> <br / >',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['show_support_location'] == 'bottom' ? "checked" : ""));
506 echo '</td></tr>';
507 echo '<tr><th>説明文</th><td>';
508 echo sprintf('<input type="text" placeholder="サポートの説明文をカスタマイズできます" size="50%%" name="%s[show_support_message]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['show_support_message']));
509 echo '</td></tr>';
510 echo '<tr><th>対象カテゴリ名</th><td>';
511 echo sprintf('<input placeholder="&quot;|&quot;区切りで複数指定できます" type="text" size="50%%" name="%s[show_support_categories]" value="%s"><br />',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['show_support_categories']));
512 echo '</td></tr>';
513 echo '</tbody></table>';
514
515 },
516 'codoc', //page
517 'setting_section_id' //Section
518 );
519 add_settings_field(
520 'do_not_filter_the_content', // id
521 '支障が出る処理を無効化', // title
522 function() {
523 global $CODOC_SETTINGS;
524 echo '<div class="excerpt">codocの動作に支障が出る他のプラグインによる<strong>フィルター処理</strong>を無効化できます。codocが上手く動かない場合のみ利用してください。</div>';
525 echo sprintf('<input type="radio" value="1" name="%s[do_not_filter_the_content]" id="do_not_filter_the_content_on" %s><label for="do_not_filter_the_content_on">する</label> ',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['do_not_filter_the_content'] == '1' ? "checked" : ""));
526 echo sprintf('<input type="radio" value="0" name="%s[do_not_filter_the_content]" id="do_not_filter_the_content_off" %s><label for="do_not_filter_the_content_off">しない</label> ',CODOC_SETTINGS_OPTION_NAME,($CODOC_SETTINGS['do_not_filter_the_content'] == '0' ? "checked" : ""));
527 },
528 'codoc', //page
529 'setting_section_id' //Section
530 );
531 add_settings_field(
532 'debug_params', // id
533 'デバック用', // title
534 function() {
535 global $CODOC_SETTINGS;
536 echo '<div class="excerpt">デバック用のパラメーターを指定できます。codocサポートから依頼がある場合のみ利用してください。</div>';
537 echo sprintf('<input placeholder="" type="text" size="50%%" name="%s[debug_params]" value="%s"><br />',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['debug_params']));
538 },
539 'codoc', //page
540 'setting_section_id' //Section
541 );
542
543 add_settings_field(
544 'cretor_info', // id
545 'クリエイター�
546 ', // title
547 function() {
548 global $CODOC_SETTINGS;
549 global $CODOC_AUTHINFO;
550 echo sprintf('<p><font id="codoc-update-creator-info-message"></font></p>',"");
551 // 変更を保存時に常に同期するのでこの表示は�
552 要ないがUI上保持しておく
553 $script = "document.getElementById('codoc-update-creator-info-message').innerText='�
554 報を更新するには変更を保存してください';document.getElementById('codoc-update-creator-info-message').color='red';";
555 if (isset($CODOC_AUTHINFO['profile_image_url'])) {
556 echo sprintf('<img src="%s" width="40" height="40" />',$CODOC_AUTHINFO['profile_image_url']);
557 }
558 echo sprintf('<p>%s</p>',$CODOC_AUTHINFO['name']);
559 if ($connect_code = $CODOC_SETTINGS['codoc_connect_code']) {
560 echo sprintf('<p>%s外部サービス連携済(連携コード:%s)</p>',
561 ($CODOC_SETTINGS['codoc_connect_registration_mode'] == 'dedicated' ? '専用ユーザーモードで' : ''),
562 $connect_code);
563 }
564 echo sprintf('<p>�
565 報を<a href="javascript:void(0);" onClick="' . $script . '">更新する</a></p>');
566 echo ('<p>codoc側でロゴやカバー画像を変更した場合は都度更新を行ってください</p>');
567 },
568 'codoc', //page
569 'setting_section_id' //Section
570 );
571
572 register_setting(
573 'codoc_option_group', // option group
574 CODOC_USERCODE_OPTION_NAME
575 );
576 register_setting(
577 'codoc_option_group', // option group
578 CODOC_TOKEN_OPTION_NAME
579 );
580
581 if (isset($_GET['codoc_auth_finished']) and $_GET['codoc_auth_finished']) {
582 add_settings_error( 'general', 'settings_updated', __( 'codocの認証が完了しました' ), 'success' );
583 }
584
585 add_settings_field(
586 'codoc_auth',
587 '認証',
588 function() {
589 global $CODOC_USERCODE;
590 global $CODOC_TOKEN;
591 global $CODOC_AUTHINFO;
592 $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';";
593
594 echo sprintf('<p><font color="green" id="codoc-auth-message"><strong>%s</strong> で認証済</font></p>',$CODOC_AUTHINFO['email']);
595
596 echo sprintf('<input id="codoc-usercode" type="hidden" name="%s" value="%s">',CODOC_USERCODE_OPTION_NAME,$CODOC_USERCODE);
597 echo sprintf('<input id="codoc-token" type="hidden" name="%s" value="%s">',CODOC_TOKEN_OPTION_NAME,$CODOC_TOKEN);
598 echo sprintf('<p>認証を<a href="javascript:void(0);" onClick="' . $script . '">解除する</p>');
599 },
600 'codoc',
601 'setting_section_id'
602 );
603
604 }
605
606 // ない場合
607 if (!$CODOC_AUTHINFO and !isset($_GET['auth_by_myself'])) {
608 add_settings_field(
609 'codoc_auth',
610 '認証',
611 function() {
612 $theme = wp_get_theme();
613 $from = 'wp';
614 if ($theme->get('Name') === 'codoc') {
615 $from = 'wp_codoc';
616 }
617 //$current_url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
618 $current_url = admin_url('options-general.php') . '?page=codoc';
619 $login_url = sprintf("location.href='%s'",$this->get_codoc_url() . '/me/token?from=' . $from . '&return_url=' . urlencode($current_url));
620 $register_url = sprintf("location.href='%s'",$this->get_codoc_url() . '/register?from=' . $from . '&return_url=' . urlencode($current_url));
621 // submitを消しておく
622 echo ('<script type="text/javascript">window.onload=function(){document.getElementById(\'submit\').style.display = \'none\'}</script>');
623 echo ('codocをWordPressでご利用いただくには認証が�
624 要です。<br />');
625 echo sprintf('ユーザーコードとAPIトークンを<a href="%s&auth_by_myself=1">直接�
626 �力</a>することでも認証できます。<br /><br />',$current_url);
627 echo sprintf('<input type="button" class="button button-primary" value="ログインして認証" onClick="%s"> <input type="button" class="button button-primary" value="登録して認証" onClick="%s"><br /><br />',$login_url,$register_url);
628
629
630 },
631 'codoc',
632 'setting_section_id'
633 );
634 }
635 // ない場合かつ自分で認証する場合
636 if (!$CODOC_AUTHINFO and (
637 (isset($_GET['auth_by_myself']) and $_GET['auth_by_myself']) or
638 (isset($_POST['auth_by_myself']) and $_POST['auth_by_myself'])
639 )) {
640 register_setting(
641 'codoc_option_group', // option group
642 CODOC_USERCODE_OPTION_NAME
643 );
644 register_setting(
645 'codoc_option_group', // option group
646 CODOC_TOKEN_OPTION_NAME
647 );
648 add_settings_field(
649 'codoc_usercode',
650 'ユーザーコード',
651 function() {
652 global $CODOC_USERCODE;
653 echo '<input type="hidden" name="auth_by_myself" value="1">';
654 echo sprintf('<input type="text" name="%s" value="%s">',CODOC_USERCODE_OPTION_NAME,$CODOC_USERCODE);
655 },
656 'codoc',
657 'setting_section_id'
658 );
659 add_settings_field(
660 'codoc_token',
661 'APIトークン',
662 function() {
663 global $CODOC_TOKEN;
664 echo sprintf('<input type="text" name="%s" value="%s">',CODOC_TOKEN_OPTION_NAME,$CODOC_TOKEN);
665 },
666 'codoc',
667 'setting_section_id'
668 );
669 }
670
671 // 認証�
672 報を保存
673 add_action( 'update_option_' . CODOC_USERCODE_OPTION_NAME, function( $old_value, $new_value ) {
674 global $CODOC_RE_AUTHORIZE;
675 $CODOC_RE_AUTHORIZE = 1;
676 },9,2); // $hook, $function_to_add, $priority, $accepted_args
677 add_action( 'update_option_' . CODOC_TOKEN_OPTION_NAME, function( $old_value, $new_value ) {
678 global $CODOC_RE_AUTHORIZE;
679 $CODOC_RE_AUTHORIZE = 1;
680 },10,2);
681
682 add_action('update_option_' . CODOC_SETTINGS_OPTION_NAME,function(){
683 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
684 if (isset($CODOC_SETTINGS['always_show_support']) and $CODOC_SETTINGS['always_show_support']) {
685 $data = $this->util->get_support_entry([],[
686 "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
687 "token" => get_option(CODOC_TOKEN_OPTION_NAME),
688 ]);
689 if ($data->status and $entry = $data->entry) {
690 update_option(CODOC_SUPPORT_ENTRYCODE_OPTION_NAME,$entry->code);
691 } else {
692 update_option(CODOC_SUPPORT_ENTRYCODE_OPTION_NAME,'');
693 }
694 } elseif(isset($CODOC_SETTINGS['always_show_support']) and !$CODOC_SETTINGS['always_show_support']) {
695 update_option(CODOC_SUPPORT_ENTRYCODE_OPTION_NAME,'');
696 }
697 });
698
699 add_action('updated_option',function(){
700 global $CODOC_RE_AUTHORIZE;
701 if ($CODOC_RE_AUTHORIZE) {
702 //$data = $this->callAPI('GET','');
703 $data = $this->util->get_user_info([],[
704 "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
705 "token" => get_option(CODOC_TOKEN_OPTION_NAME),
706 ]);
707 if ($data->status and $user = $data->user) {
708 $this->update_codoc_authinfo($user);
709 } else {
710 update_option(CODOC_AUTHINFO_OPTION_NAME,'');
711 }
712 }
713 });
714
715 });
716 // プラグイン一覧に設定のリンクをいれる
717 add_filter( 'plugin_action_links_' . plugin_basename( plugin_dir_path( __FILE__ ) . 'codoc' . '.php' ),
718 function( $links ) {
719 $setting_link = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( 'page', 'codoc', admin_url( 'options-general.php' ) ) ), esc_html( '設定' ) );
720 array_unshift( $links, $setting_link );
721
722 return $links;
723 }
724 );
725
726 }
727 public function add_mce() {
728 add_action( 'admin_enqueue_scripts', function() {
729 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
730 return;
731 }
732 $current_screen = get_current_screen();
733 if ( ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) || ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) ) {
734 // Gutenberg Editor
735 // なにもしない
736 } else {
737 // tinymce
738 if ( get_user_option( 'rich_editing' ) == 'true' ) {
739 // プラグイン�
740 で使うCSRF を生成
741 $path = plugins_url( 'codoc/src_mce/codoc-editor-onload.js', __DIR__ );
742 wp_enqueue_script( 'codoc-editor-onload', $path, array('jquery'), '', true );
743 // I just want to insert this global variables but i don't know how i can do it..
744 wp_localize_script(
745 'codoc-editor-onload',
746 'CODOCEDITOR',
747 array(
748 'action' => 'codoc_shortcodes',
749 'nonce' => wp_create_nonce( 'codoc_shortcodes' ),
750
751 'codoc_url' => $this->get_codoc_url(),
752 'codoc_usercode' => get_option(CODOC_USERCODE_OPTION_NAME),
753 'codoc_plugin_version' => CODOC_PLUGIN_VERSION,
754 'codoc_sdk_path' => CODOC_SDK_PATH,
755 )
756 );
757
758 // ここでtinymceのプラグイン追加
759 //wp_enqueue_style( 'codoc-admin-style', plugins_url( 'codoc/src_mce/codoc-admin.css', __DIR__ ) );
760 //add_editor_style( plugins_url( 'codoc/src_mce/codoc-admin.css', __DIR__ ) );
761 wp_enqueue_style( 'codoc-admin-style', $this->get_codoc_url() . CODOC_SDK_PATH . '.tinymce.css?c=' . date('Ymd') );
762 add_editor_style( $this->get_codoc_url() . CODOC_SDK_PATH . '.tinymce.css' );
763
764 add_filter( 'mce_external_plugins', function( $plugin_array ) {
765 //$plugin_array['codoc'] = plugins_url( 'codoc/src_mce/codoc-editor.js', __DIR__ );
766 $plugin_array['codoc'] = $this->get_codoc_url() . CODOC_SDK_PATH . '.tinymce.js?c=' . date('Ymd');
767 return $plugin_array;
768 } );
769 add_filter( 'mce_buttons', function( $buttons ) {
770 array_push( $buttons, "|", "codoc" );
771 return $buttons;
772 } );
773 // 非SSL環境の場合、なぜかhttps -> httpsになってしまうので対策
774 // コメントタグが除去されることがあるらしいのでvalid_elementsに�
775 要なタグを追加 (EXPERIMENTAL)
776 add_filter( 'tiny_mce_before_init', function($settings) {
777 $settings['external_plugins'] = preg_replace('/"codoc":"http:/','"codoc":"https:',$settings['external_plugins']);
778 foreach (['valid_elements','extended_valid_elements'] as $valid_elements) {
779 if (isset($settings[$valid_elements])) {
780 $settings[$valid_elements] = $settings[$valid_elements] . ',div[*],p[*],img[*],--[*]';
781 }
782 }
783 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
784 if (isset($CODOC_SETTINGS["debug_params"])) {
785 $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true);
786 if (isset($params_decoded["mce_valid_elements"])) {
787 $settings['valid_elements'] = $params_decoded["mce_valid_elements"];
788 $settings['extended_valid_elements'] = $params_decoded["mce_valid_elements"];
789 }
790 }
791
792 return $settings;
793 },1000000);
794 }
795 }
796 } );
797 }
798 function update_codoc_authinfo($user) {
799 global $CODOC_SETTINGS;
800 global $CODOC_AUTHINFO;
801 if (property_exists($user,'connect_code') and $user->connect_code) {
802 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
803 $CODOC_SETTINGS['codoc_connect_code'] = $user->connect_code;
804 $CODOC_SETTINGS['codoc_connect_registration_mode'] = $user->connect_has_permission_dedicated_account ? 'dedicated' : '';
805 update_option(CODOC_SETTINGS_OPTION_NAME,$CODOC_SETTINGS);
806 }
807 return update_option(CODOC_AUTHINFO_OPTION_NAME,[
808 'email' => $user->email,
809 'name' => $user->name,
810 'profile_image_url' => $user->profile_image_url,
811 'cover_image_url' => $user->cover_image_url,
812 'connect_code' => property_exists($user,'connect_code') ? $user->connect_code : '',
813 'connect_image_url' => property_exists($user,'connect_image_url') ? $user->connect_image_url : '',
814 ]);
815 $CODOC_AUTHINFO = get_option(CODOC_AUTHINFO_OPTION_NAME);
816 }
817 public function get_filtered_content($post_emulated) {
818 // 記事ページであることをエミュレートしてフィルター実行
819 $post_backuped = null;
820 if (isset($GLOBALS['post'])) {
821 $post_backuped = $GLOBALS['post'];
822 }
823 $GLOBALS['post'] = $post_emulated;
824
825 $wp_query_backuped = null;
826 if (isset($GLOBALS['wp_query'])) {
827 $wp_query_backuped = $GLOBALS['wp_query'];
828 $wp_query = $GLOBALS['wp_query'];
829 $wp_query->is_single = true;
830 $wp_query->is_singular = true;
831 # in_the_loop は記事ページでは通常有効っぽいので true指定 ex: wp_ulike
832 $wp_query->in_the_loop = true;
833 # これも追加しておく
834 $wp_query->is_main_query = true;
835
836 $wp_query->post = $post_emulated;
837 $wp_query->queried_object = $post_emulated;
838 $wp_query->queried_object_id = $post_emulated->id;
839
840 $GLOBALS['wp_query'] = $wp_query;
841 }
842 // $this->the_content でオリジナルを返してもらうため
843 $this->do_not_filter_the_content = true;
844 $content = preg_replace(
845 '/ (\/)?wp:codoc\/codoc-block /',' \\1wptmp:codoc/codoc-block ',
846 $post_emulated->post_content
847 );
848 #$content = do_shortcode( $content );
849 $content_filtered = apply_filters( 'the_content', $content);
850 $this->do_not_filter_the_content = false;
851
852 $GLOBALS['post'] = $post_backuped;
853
854 if ($wp_query_backuped) {
855 $GLOBALS['wp_query'] = $wp_query_backuped;
856 }
857
858 $content_filtered = preg_replace(
859 '/ (\/)?wptmp:codoc\/codoc-block /',' \\1wp:codoc/codoc-block ',
860 $content_filtered
861 );
862 return $content_filtered;
863 }
864
865 public function save_post($post_ID,$post,$update) {
866 if (preg_match('/^(auto-draft|inherit)$/',$post->post_status)) {
867 return;
868 }
869 $entryCode = get_post_meta($post_ID,'codoc_entry_code',true);
870 $codoc_settings = get_option(CODOC_SETTINGS_OPTION_NAME);
871 $post_content = (isset($codoc_settings['do_not_filter_the_content']) and $codoc_settings['do_not_filter_the_content']) ?
872 $post->post_content : $this->get_filtered_content($post);
873 $res = $this->util->sync_entry([
874 "post_title" => $post->post_title,
875 "post_content" => $post_content,
876 // password が設定されてる場合は限定�
877 �開にする
878 "post_status" => $post->post_status == 'publish' ? ($post->post_password ? 2 : 1) : 0,
879 "post_permalink" => get_permalink($post_ID),
880 "codoc_entry_code" => $entryCode,
881 "codoc_settings" => $codoc_settings,
882 ],[
883 "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
884 "token" => get_option(CODOC_TOKEN_OPTION_NAME),
885 ]);
886
887 if (is_object($res) and $res->status and !$entryCode) {
888 update_post_meta($post_ID,'codoc_entry_code',$res->entry->code);
889 }
890 return true;
891 }
892 function updated_post_meta( $meta_ID, $post_ID, $meta_key ) {
893 // スルーされてる場合は他のメタ�
894 報更新のタイミングにサムネイルをアップロード
895 $has_to_resend = get_post_meta($post_ID,'codoc_post_thumbnail_invoking_entry_code',true);
896 $has_to_resendi = get_post_meta($post_ID,'icodoc_post_thumbnail_invoking_entry_code',true);
897 if ($has_to_resend != 1 and $meta_key != '_thumbnail_id') {
898 return;
899 }
900 if ( has_post_thumbnail($post_ID) ) {
901 // 新規投稿の場合、タイミングによってはcodocEntryCodeが取得できないので一旦スルーする
902 if (!get_post_meta($post_ID,'codoc_entry_code',true)) {
903 update_post_meta($post_ID,'codoc_post_thumbnail_invoking_entry_code',1);
904 return;
905 } else {
906 update_post_meta($post_ID,'codoc_post_thumbnail_invoking_entry_code',0);
907 }
908 $attachment = wp_get_attachment_metadata( get_post_thumbnail_id($post_ID));
909 $upload_dir = wp_upload_dir();
910 $file_path = sprintf ('%s/%s',$upload_dir['basedir'],$attachment['file']);
911
912 return $this->util->post_thumbnail([
913 "file_path" => $file_path,
914 "boundary" => wp_generate_password(24),
915 "codoc_entry_code" => get_post_meta($post_ID,'codoc_entry_code',true),
916 ],[
917 "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
918 "token" => get_option(CODOC_TOKEN_OPTION_NAME),
919 ]);
920 }
921 }
922 function deleted_post_meta( $meta_ids, $post_ID, $meta_key,$meta_value ) {
923 if ($meta_key != '_thumbnail_id') {
924 return;
925 }
926 return $this->util->reset_thumbnail(
927 ["codoc_entry_code" => get_post_meta($post_ID,'codoc_entry_code',true)],
928 [
929 "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
930 "token" => get_option(CODOC_TOKEN_OPTION_NAME),
931 ]
932 );
933 }
934
935 function the_content( $post_content ) {
936 if ( is_single() && in_the_loop() && is_main_query() ) {
937 }
938 // get_filtered_content から do_not_filter_the_contentを有効にされるパターン
939 // オプションの設定値の意味合い(他のフィルタを無視)とは違うため注意
940 if ($this->do_not_filter_the_content) {
941 return $post_content;
942 }
943 $post = get_post();
944 # is_amp で実�
945 しているテンプレート用
946 $is_amp_endpoint = (function_exists('is_amp_endpoint') && is_amp_endpoint()) ? true :
947 ((function_exists('is_amp') && is_amp()) ? true : false);
948 return $this->util->filter_content([
949 "post_content" => $post_content,
950 "preview" => is_preview(),
951 "codoc_entry_code" => get_post_meta($post->ID,'codoc_entry_code',true),
952 "codoc_settings" => get_option(CODOC_SETTINGS_OPTION_NAME),
953 "is_amp_endpoint" => $is_amp_endpoint,
954 "post_permalink" => get_permalink($post->ID),
955 "codoc_support_entry_code" => get_option(CODOC_SUPPORT_ENTRYCODE_OPTION_NAME),
956 ]);
957 }
958
959 function excerpt_allowed_blocks ($allowed_blocks) {
960 if (is_array($allowed_blocks)) {
961 array_push($allowed_blocks,'codoc/codoc-block');
962 }
963 return $allowed_blocks;
964 }
965 }
966