PluginProbe
codoc / 0.9.21
codoc v0.9.21
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.21, at class-codoc.php

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