PluginProbe
codoc / 0.9.17
codoc v0.9.17
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.17, at class-codoc.php

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