PluginProbe
codoc / 0.9.15
codoc v0.9.15
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.15, at class-codoc.php

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