PluginProbe
codoc / 0.9.61
codoc v0.9.61
0.9.61 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 All 115 releases
← All changes | class-codoc.php +606 -143 0.9.9.1 → 0.9.61 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2 require_once(plugin_dir_path( __FILE__ ) .'class-codoc-util.php');
3 3 final class Codoc {
4 -
5 4 public function __construct() {
5 + add_action('plugins_loaded', [$this,'codoc_load_textdomain']);
6 6 if (is_admin()) {
7 7 // setting
8 8 $this->add_settings();
9 9 }
@@ -14,9 +14,10 @@
14 14 # the_content フィルタを実行しない状態
15 15 $this->do_not_filter_the_content = false;
16 16
17 17 // paywall用の本文非表示化とcodocタグへの属性追加
18 - $priority = 10;
18 + #$priority = 999999999;
19 + $priority = 100000; # フィルターは最後に実施する default 10
19 20 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
20 21 if (isset($CODOC_SETTINGS["debug_params"])) {
21 22 $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true);
22 23 if (isset($params_decoded["the_content_filter_priority"])) {
@@ -22,12 +23,21 @@
22 23 if (isset($params_decoded["the_content_filter_priority"])) {
23 24 $priority = $params_decoded["the_content_filter_priority"];
24 25 }
25 26 }
27 + // ショーココードの退避
28 + if (isset($CODOC_SETTINGS['shortcode_evacuation']) and $CODOC_SETTINGS['shortcode_evacuation']) {
29 + add_filter('the_content',[$this,'the_content_shortcode_evacuations'],0);
30 + }
26 31 add_filter('the_content',[$this,'the_content'],$priority);
32 + // 2021-09-24 the_content を利用しない場合は個別に呼び出ししてもらう
33 + add_filter('codoc_the_content',[$this,'the_content'],$priority);
27 34
28 35 // 2020-07-25 excerpt対応
29 36 add_filter('excerpt_allowed_blocks',[$this,'excerpt_allowed_blocks']);
37 +
38 + // テーマが allowed_block_types_all で制限している場合に codoc ブロックを許可リストに追加
39 + add_filter('allowed_block_types_all', [$this,'allowed_block_types_all'], 100, 2);
30 40
31 41 $auth_info = get_option(CODOC_AUTHINFO_OPTION_NAME);
32 42
33 43 if ($auth_info) {
@@ -35,37 +45,65 @@
35 45 add_action( 'save_post', [$this,'save_post'], 20, 3 );
36 46 add_action( 'added_post_meta', [$this,'updated_post_meta'], 10, 3 );
37 47 add_action( 'updated_post_meta',[$this,'updated_post_meta'], 10, 3 );
38 48 add_action( 'deleted_post_meta',[$this,'deleted_post_meta'], 10, 4 );
49 + // 文字数バリデーションエラーの管理画面通知
50 + add_action( 'admin_notices', [$this,'show_validation_notices'] );
39 51 }
40 - if (is_admin() and $auth_info) { //管理画面
52 + global $pagenow;
53 + //管理画面でcodoc認証があり投稿画面の場合
54 + if (is_admin() and $auth_info and preg_match('/^post/',$pagenow)) {
41 55 // Gutenberg のサポートがない場合は何もしない
42 56 if ( function_exists( 'register_block_type' ) ) {
43 - // gutenberg
57 + // gutenberg - init.php handles all block registration and script enqueuing
44 58 require_once 'src/init.php';
45 - add_action('wp_loaded', function() {
46 - wp_localize_script('wordpress-cgb-block-js', 'OPTIONS', array(
47 - 'codoc_url' => $this->get_codoc_url(),
48 - 'codoc_usercode' => get_option(CODOC_USERCODE_OPTION_NAME),
49 - 'codoc_plugin_version' => CODOC_PLUGIN_VERSION,
50 - 'codoc_sdk_path' => CODOC_SDK_PATH,
51 - ));
52 - });
53 59 }
54 60 // tinymce
55 61 $this->add_mce();
56 - } else { // ブログ画面
62 + } elseif(is_admin() and $auth_info and preg_match('/^edit/',$pagenow)) {
63 + // 記事編集ページ
64 + } elseif(!is_admin()) { // ブログ画面
57 65 // codocのJS登録
58 66 add_action( 'wp_enqueue_scripts', function() {
59 - wp_enqueue_script( 'codoc-injector-js', $this->get_codoc_url() . '/js/cms.js' );
67 + $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
68 + $load_script_condition = '';
69 + if (isset($CODOC_SETTINGS["debug_params"]) and
70 + $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true) and
71 + isset($params_decoded["load_script_condition"])
72 + ) {
73 + $load_script_condition = $params_decoded["load_script_condition"];
74 + }
75 + if ($load_script_condition == 'not_list_page') {
76 + // not_list_pageの場合はトップページ等でスクリプトをロードしない
77 + if (!(is_archive() or is_category() or is_home() or is_front_page())) {
78 + wp_enqueue_script( 'codoc-injector-js', $this->get_codoc_url() . '/js/cms.js' );
79 + }
80 + } else {
81 + wp_enqueue_script( 'codoc-injector-js', $this->get_codoc_url() . '/js/cms.js' );
82 + }
60 83 });
61 - // 登録したscriptタグに属性をつける
84 + //登録したscriptタグに属性をつける
62 85 add_filter('script_loader_tag', [$this,'modifier_script_tag'],10,2);
63 86 // tinymce用のショートコード
64 87 add_shortcode('codoc', [$this, 'injector_shortcode']);
88 + // テーマをbodyにも反映
89 + add_filter('body_class', function($classes) {
90 + $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
91 + // デフォルトを変更
92 + $css_path = 'rainbow-square';
93 + if (isset($CODOC_SETTINGS["css_path"]) and $CODOC_SETTINGS["css_path"]) {
94 + $css_path = $CODOC_SETTINGS["css_path"];
95 + }
96 + array_push($classes,sprintf( "codoc-theme-%s",$css_path));
97 + return $classes;
98 + });
99 +
65 100 }
66 101 return $this;
67 102 }
103 + function codoc_load_textdomain() {
104 + load_plugin_textdomain('codoc', false, dirname(plugin_basename( __FILE__ )) . '/languages/');
105 + }
68 106 public function get_codoc_url() {
69 107 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
70 108 if (isset($CODOC_SETTINGS["debug_params"])) {
71 109 $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true);
@@ -83,10 +121,32 @@
83 121 $data_css = '';
84 122 if ($css_path = $CODOC_SETTINGS['css_path']) {
85 123 $data_css = sprintf(' data-css="%s" ',$css_path);
86 124 }
125 + // connect用パラメータ
126 + $connect_attributes = '';
127 + if (isset($CODOC_SETTINGS["codoc_connect_code"])) {
128 + $connect_code = $CODOC_SETTINGS["codoc_connect_code"];
129 + $connect_attributes = sprintf(' data-connect-code="%s"',$connect_code);
130 + $tag = preg_replace('/cms\.js/','cms-connect.js',$tag);
131 + }
132 + if (isset($CODOC_SETTINGS["codoc_connect_registration_mode"]) and $CODOC_SETTINGS["codoc_connect_registration_mode"]) {
133 + $connect_attributes = $connect_attributes .
134 + sprintf(' data-connect-registration-mode="%s"',$CODOC_SETTINGS["codoc_connect_registration_mode"]);
135 + }
136 +
137 + $usercode_attributes = '';
138 + $user_code = get_option(CODOC_USERCODE_OPTION_NAME);
139 + if ($user_code) {
140 + $usercode_attributes = sprintf(' data-usercode="%s"',$user_code);
141 + }
142 +
143 + $setting_attributes = '';
144 + if (isset($CODOC_SETTINGS['codoc_script_tag_attributes']) and $CODOC_SETTINGS['codoc_script_tag_attributes']) {
145 + $setting_attributes = $CODOC_SETTINGS['codoc_script_tag_attributes'];
146 + }
87 147 //return str_replace(' src=', $data_css . ' defer src=', $tag);
88 - return preg_replace('/(src=[^>]+)/',' ${1} ' . $data_css . ' defer',$tag);
148 + return preg_replace('/(src=[^>]+)/',' ${1} ' . $data_css . $connect_attributes . $usercode_attributes . $setting_attributes . ' defer',$tag);
89 149 }
90 150 public function injector_shortcode($atts) {
91 151 global $post;
92 152 ob_start();
@@ -97,9 +157,9 @@
97 157 public function add_settings() {
98 158 global $CODOC_SETTINGS;
99 159 add_action( 'admin_menu' ,function(){
100 160 add_options_page(
101 - 'codoc の設定', //ページタイトル
161 + __('codoc Settings','codoc'), //ページタイトル
102 162 'codoc', //設定メニューに表示されるメニュータイトル
103 163 'edit_users', //権限
104 164 'codoc', //設定ページのURL。options-general.php?page=codoc
105 165 function() {
@@ -117,39 +177,70 @@
117 177 function codoc_admin_styles($hook) {
118 178 wp_enqueue_style('codoc-options-style', plugins_url( 'codoc/css/codoc-options.css', __DIR__ ));
119 179 }
120 180
181 + // notification を削除する Ajax 処理
182 + add_action('wp_ajax_dismiss_codoc_notification', function() {
183 + delete_transient('codoc_api_notification');
184 + wp_die();
185 + });
186 +
187 + // 管理画面で notification の dismiss を処理する JavaScript
188 + add_action('admin_footer', function() {
189 + ?>
190 + <script type="text/javascript">
191 + jQuery(document).ready(function($) {
192 + // codoc notification の×ボタンがクリックされたときの処理
193 + $(document).on('click', '.codoc-notification .notice-dismiss', function() {
194 + $.post(ajaxurl, {
195 + action: 'dismiss_codoc_notification'
196 + });
197 + });
198 + });
199 + </script>
200 + <?php
201 + });
202 +
121 203 add_action( "admin_init", function() {
204 + global $CODOC_USERCODE;
205 + global $CODOC_SETTINGS;
206 + global $CODOC_TOKEN;
207 + global $CODOC_AUTHINFO;
122 208 // codocからの認証データ処理
123 - if (isset($_GET['page']) and $_GET['page'] == 'codoc' and isset($_GET['fetch_token_key'])) {
209 + if (current_user_can('edit_posts') && !isset($_GET['confirm_token']) and isset($_GET['page']) and $_GET['page'] == 'codoc' and isset($_GET['fetch_token_key'])) {
210 + $current_url = admin_url('options-general.php') . '?page=codoc';
124 211 $key = sanitize_text_field($_GET['fetch_token_key']);
125 212 $usercode = sanitize_text_field($_GET['usercode']);
213 +
214 + // 確認画面の表示
215 + if (
216 + !isset($_GET['_wpnonce']) or
217 + (isset($_GET['_wpnonce']) and !wp_verify_nonce($_GET['_wpnonce'],'fetch_token_nonce'))
218 + ) {
219 + wp_redirect($current_url .
220 + sprintf("&confirm_token=1&fetch_token_key=%s&usercode=%s",$key,$usercode));
221 + exit;
222 + }
126 223 update_option(CODOC_USERCODE_OPTION_NAME,$usercode);
127 224 //$data = $this->callAPI('GET','/token',[ "fetch_token_key" => $key ]);
128 225 $data = $this->util->get_token([ "fetch_token_key" => $key ],["usercode" => $usercode, "token" => "1"]);
129 - if ($data->status and $token = $data->token) {
226 + if ($data->status and property_exists($data,'token') and $token = $data->token) {
130 227 update_option(CODOC_TOKEN_OPTION_NAME,$token);
131 228 //$data = $this->callAPI('GET','');
132 229 $data = $this->util->get_user_info([],["usercode" => $usercode, "token" => $token]);
230 +
133 231 if ($data->status and $user = $data->user) {
134 - update_option(CODOC_AUTHINFO_OPTION_NAME,[
135 - 'email' => $user->email,
136 - 'name' => $user->name,
137 - ]);
232 + $this->update_codoc_authinfo($user);
138 233 }
139 234 #$current_url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
140 235 #$current_url = preg_replace('/(.*)fetch_token_key.*/','${1}&codoc_auth_finished=1',$current_url);
141 236 //add_settings_error( 'general', 'settings_updated', __( 'OK' ), 'success' );
142 - $current_url = admin_url('options-general.php') . '?page=codoc&codoc_auth_finished=1';
143 237
238 + $current_url = $current_url . '&codoc_auth_finished=1';
144 239 wp_redirect( $current_url);
145 240 exit;
146 241 }
147 242 }
148 - global $CODOC_USERCODE;
149 - global $CODOC_SETTINGS;
150 - global $CODOC_TOKEN;
151 - global $CODOC_AUTHINFO;
152 243 $CODOC_USERCODE = get_option(CODOC_USERCODE_OPTION_NAME);
153 244 $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
154 245 $CODOC_TOKEN = get_option(CODOC_TOKEN_OPTION_NAME);
155 246 $CODOC_AUTHINFO = get_option(CODOC_AUTHINFO_OPTION_NAME);
@@ -187,8 +278,11 @@
187 278 }
188 279 if (!isset($CODOC_SETTINGS['do_not_filter_the_content'])) {
189 280 $CODOC_SETTINGS['do_not_filter_the_content'] = '0';
190 281 }
282 + if (!isset($CODOC_SETTINGS['shortcode_evacuation'])) {
283 + $CODOC_SETTINGS['shortcode_evacuation'] = '0';
284 + }
191 285
192 286 if (!isset($CODOC_SETTINGS['entry_button_text'])) {
193 287 $CODOC_SETTINGS['entry_button_text'] = '';
194 288 }
@@ -212,42 +306,84 @@
212 306 }
213 307 if (!isset($CODOC_SETTINGS['show_powered_by'])) {
214 308 $CODOC_SETTINGS['show_powered_by'] = '1';
215 309 }
216 -
310 + if (!isset($CODOC_SETTINGS['show_created_by'])) {
311 + $CODOC_SETTINGS['show_created_by'] = '1';
312 + }
313 + if (!isset($CODOC_SETTINGS['show_copyright'])) {
314 + $CODOC_SETTINGS['show_copyright'] = '1';
315 + }
217 316 if (!isset($CODOC_SETTINGS['codoc_tag_attributes'])) {
218 317 $CODOC_SETTINGS['codoc_tag_attributes'] = '';
219 318 }
319 + if (!isset($CODOC_SETTINGS['codoc_script_tag_attributes'])) {
320 + $CODOC_SETTINGS['codoc_script_tag_attributes'] = '';
321 + }
322 + if (!isset($CODOC_SETTINGS['codoc_connect_code'])) {
323 + $CODOC_SETTINGS['codoc_connect_code'] = '';
324 + }
325 + if (!isset($CODOC_SETTINGS['codoc_connect_registration_mode'])) {
326 + $CODOC_SETTINGS['codoc_connect_registration_mode'] = '';
327 + }
220 328 if (!isset($CODOC_SETTINGS['debug_params'])) {
221 329 $CODOC_SETTINGS['debug_params'] = '';
222 330 }
223 -
331 + if (!isset($CODOC_SETTINGS['block_defaults'])) {
332 + $CODOC_SETTINGS['block_defaults'] = '';
333 + }
224 334 add_settings_section(
225 335 'setting_section_id', // id
226 - 'codoc 設定ページ', // title
227 - function (){}, // callback
336 + __('codoc Settings','codoc'), // title
337 + [$this,'show_tadv_notice'],
228 338 'codoc' // page
229 339 );
340 +
230 341 // 認証がある場合
231 342 if ($CODOC_AUTHINFO) {
343 + // クリエイター情報だけ更新 (POST時に同期をとる)
344 + if (isset($_GET['page']) and $_GET['page'] == 'codoc' and isset($_GET['settings-updated'])) {
345 + $data = $this->util->get_user_info([],[
346 + "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
347 + "token" => get_option(CODOC_TOKEN_OPTION_NAME),
348 + ]);
349 + if ($data->status and $user = $data->user) {
350 + $this->update_codoc_authinfo($user);
351 + // 一度get_optionしてるのでリロードする
352 + $CODOC_AUTHINFO = get_option(CODOC_AUTHINFO_OPTION_NAME);
353 + }
354 + }
355 +
232 356 register_setting(
233 357 'codoc_option_group', // option group
234 - CODOC_SETTINGS_OPTION_NAME // option name(DB)
358 + CODOC_SETTINGS_OPTION_NAME, // option name(DB)
359 + array('sanitize_callback' => function($input) {
360 + if (isset($input['block_defaults']) && $input['block_defaults'] !== '') {
361 + if (json_decode($input['block_defaults'], true) === null && $input['block_defaults'] !== 'null') {
362 + $old = get_option(CODOC_SETTINGS_OPTION_NAME);
363 + $input['block_defaults'] = isset($old['block_defaults']) ? $old['block_defaults'] : '';
364 + add_settings_error('block_defaults', 'invalid_json', esc_html(__('Block Default Values: Invalid JSON format. The value was not saved.','codoc')), 'error');
365 + }
366 + }
367 + return $input;
368 + })
235 369 );
236 370 add_settings_field(
237 371 'css_path', // id
238 - 'テーマ', // title
372 + __('Theme','codoc'), // title
239 373 function() {
240 374 global $CODOC_SETTINGS;
241 - echo '<div class="excerpt">テーマを指定してペイウォールのデザインを変えることができます。<br>パスを指定を選択することでCSSを直接指定するこもと可能です。</div>';
242 - 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']);
375 + echo '<div class="excerpt">' . esc_html(__('You can change the design of the paywall by specifying a theme.<br />You can also specify CSS directly by selecting "Path Specification"','codoc')) . '</div>';
376 + echo sprintf('<div class="inputGroup"><input type="text" name="%s[css_path]" value="%s" id="codoc_css_path" readonly>',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['css_path']));
243 377 echo '' .
244 378 '<script type="text/javascript"> ' .
245 379 ' function gen_css_path(select) { ' .
246 - ' if (select.value == "dark") { ' .
380 + ' if (select.value == "dark" || select.value == "dark-square") { ' .
247 381 ' document.getElementById("darkmode-caution").style.display="block";' .
248 382 ' } else { ' .
249 - ' document.getElementById("darkmode-caution").style.display="none";' .
383 + ' if (document.getElementById("darkmode-caution")) { ' .
384 + ' document.getElementById("darkmode-caution").style.display="none";' .
385 + ' } ' .
250 386 ' } ' .
251 387 ' if (select.value == "path") { ' .
252 388 ' document.getElementById("codoc_css_path").readOnly=false; ' .
253 389 ' if (!document.getElementById("codoc_css_path").value.match(/\//g)) {' .
@@ -260,44 +396,50 @@
260 396 ' } ' .
261 397 '</script> ' ;
262 398
263 399 echo sprintf('<select name="theme_name" onChange="gen_css_path(this)" id="codoc_theme_select">');
264 - foreach (["blue","red","green","black","dark","blue-square","red-square","green-square","black-square","dark-square"] as $theme) {
400 + foreach (["rainbow","blue","red","green","black","dark","rainbow-square","blue-square","red-square","green-square","black-square","dark-square"] as $theme) {
401 + if ($theme == "rainbow") {
402 + echo sprintf('<option value="%s" %s>%s</option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "rainbow" ? "selected" : ""),esc_attr(__('Rainbow colors','codoc')));
403 + }
265 404 if ($theme == "blue") {
266 - echo sprintf('<option value="%s" %s>青</option>', $theme, ($CODOC_SETTINGS["css_path"] == "blue" ? "selected" : ""));
405 + echo sprintf('<option value="%s" %s>%s</option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "blue" ? "selected" : ""),esc_attr(__('Blue','codoc')));
267 406 }
268 407 if ($theme == "red") {
269 - echo sprintf('<option value="%s" %s>赤</option>', $theme, ($CODOC_SETTINGS["css_path"] == "red" ? "selected" : ""));
408 + echo sprintf('<option value="%s" %s>%s</option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "red" ? "selected" : ""),esc_attr(__('Red','codoc')));
270 409 }
271 410 if ($theme == "green") {
272 - echo sprintf('<option value="%s" %s>緑</option>', $theme, ($CODOC_SETTINGS["css_path"] == "green" ? "selected" : ""));
411 + echo sprintf('<option value="%s" %s>%s</option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "green" ? "selected" : ""),esc_attr(__('Green','codoc')));
273 412 }
274 413 if ($theme == "black") {
275 - echo sprintf('<option value="%s" %s>黒</option>', $theme, ($CODOC_SETTINGS["css_path"] == "black" ? "selected" : ""));
414 + echo sprintf('<option value="%s" %s>%s</option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "black" ? "selected" : ""),esc_attr(__('Black','codoc')));
276 415 }
277 416 if ($theme == "dark") {
278 - echo sprintf('<option value="%s" %s>ダークモード</option>', $theme, ($CODOC_SETTINGS["css_path"] == "dark" ? "selected" : ""));
417 + echo sprintf('<option value="%s" %s>%s</option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "dark" ? "selected" : ""),esc_attr(__('Dark mode','codoc')));
279 418 }
419 + if ($theme == "rainbow-square") {
420 + echo sprintf('<option value="%s" %s>%s</option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "rainbow-square" ? "selected" : ""),esc_attr(__("Rainbow Colors / Square design",'codoc')));
421 + }
280 422 if ($theme == "blue-square") {
281 - echo sprintf('<option value="%s" %s>青(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "blue-square" ? "selected" : ""));
423 + echo sprintf('<option value="%s" %s>%s</option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "blue-square" ? "selected" : ""),esc_attr(__('Blue / Square design','codoc')));
282 424 }
283 425 if ($theme == "red-square") {
284 - echo sprintf('<option value="%s" %s>赤(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "red-square" ? "selected" : ""));
426 + echo sprintf('<option value="%s" %s>%s/option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "red-square" ? "selected" : ""),esc_attr(__('Red / Square design','codoc')));
285 427 }
286 428 if ($theme == "green-square") {
287 - echo sprintf('<option value="%s" %s>緑(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "green-square" ? "selected" : ""));
429 + echo sprintf('<option value="%s" %s>%s</option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "green-square" ? "selected" : ""),esc_attr(__('Green / Square design','codoc')));
288 430 }
289 431 if ($theme == "black-square") {
290 - echo sprintf('<option value="%s" %s>黒(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "black-square" ? "selected" : ""));
432 + echo sprintf('<option value="%s" %s>%s</option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "black-square" ? "selected" : ""),esc_attr(__('Black / Square design','codoc')));
291 433 }
292 434 if ($theme == "dark-square") {
293 - echo sprintf('<option value="%s" %s>ダークモード(四角)</option>', $theme, ($CODOC_SETTINGS["css_path"] == "dark-square" ? "selected" : ""));
435 + echo sprintf('<option value="%s" %s>%s</option>', esc_attr($theme), esc_attr($CODOC_SETTINGS["css_path"] == "dark-square" ? "selected" : ""),esc_attr(__('Dark mode / Square design','codoc')));
294 436 }
295 437 }
296 - echo sprintf('<option value="path" %s>パス指定</option>', (preg_match("/\//",$CODOC_SETTINGS["css_path"]) ? "selected" : ""));
438 + echo sprintf('<option value="path" %s>%s</option>', esc_attr(preg_match("/\//",$CODOC_SETTINGS["css_path"]) ? "selected" : ""),esc_attr(__('Path Specification','codoc')));
297 439 echo '<script type="text/javascript">gen_css_path(document.getElementById(\'codoc_theme_select\'))</script>';
298 440 echo sprintf('</select></div>');
299 - echo '<p id="darkmode-caution" style="display:none">ダークモード向けテーマは文字色が白となり、背景色によっては文字が見えない状態となるためご注意ください。</p>';
441 + echo '<p id="darkmode-caution" style="display:none">' . esc_attr(__('Please note that the theme for dark mode has white text color, and depending on the background color, the text may not be visible.','codoc')). '</p>';
300 442 },
301 443 'codoc', //page
302 444 'setting_section_id' //Section
303 445 );
@@ -302,46 +444,49 @@
302 444 'setting_section_id' //Section
303 445 );
304 446 add_settings_field(
305 447 'paywall_text', // id
306 - '各種文言', // title
448 + __('Texts in paywall','codoc'), // title
307 449 function() {
308 450 global $CODOC_SETTINGS;
309 - echo '<div class="excerpt">ペイウォール内の一部文言を変更できます。</div>';
451 + global $CODOC_AUTHINFO;
452 + echo '<div class="excerpt">' . esc_html(__('You can change, show and hide texts in your paywall.','codoc')) . '</div>';
310 453 echo '<table class="innerTable"><tbody>';
311 - echo '<tr><th>いいねの表示</th><td>';
312 - 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" : ""));
313 - 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" : ""));
454 + echo '<tr><th>' . esc_html(__('Display of likes','codoc')) . '</th><td>';
455 + echo sprintf('<input type="radio" value="1" name="%s[show_like]" id="show_like_on" %s><label for="show_like_on">' . esc_html(__('Enable','codoc')) . '</label> ',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['show_like'] == '1' ? "checked" : ""));
456 + echo sprintf('<input type="radio" value="0" name="%s[show_like]" id="show_like_off" %s><label for="show_like_off">' . esc_html(__('Disable','codoc')) . '</label> <br / >',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['show_like'] == '0' ? "checked" : ""));
314 457 echo '</td></tr>';
315 458
316 - echo '<tr><th>codocについての表示</th><td>';
317 - 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" : ""));
318 - 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" : ""));
459 + echo '<tr><th>' . esc_html(__('Display of PoweredBy','codoc')) . '</th><td>';
460 + echo sprintf('<input type="hidden" value="1" name="%s[show_about_codoc]">',esc_attr(CODOC_SETTINGS_OPTION_NAME));
461 + echo sprintf('<input type="hidden" value="1" name="%s[show_created_by]">',esc_attr(CODOC_SETTINGS_OPTION_NAME));
462 + echo sprintf('<input type="hidden" value="1" name="%s[show_powered_by]">',esc_attr(CODOC_SETTINGS_OPTION_NAME));
463 + if (isset($CODOC_AUTHINFO['account_is_pro']) and $CODOC_AUTHINFO['account_is_pro']) {
464 + echo sprintf('<input type="radio" value="1" name="%s[show_copyright]" id="show_copyright_on" %s><label for="show_copyright_on">' . esc_html(__('Enable','codoc')) . '</label> ',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['show_copyright'] == '1' ? "checked" : ""));
465 + echo sprintf('<input type="radio" value="0" name="%s[show_copyright]" id="show_copyright_off" %s><label for="show_copyright_off">' . esc_html(__('Disable','codoc')) . '</label> <br / >',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['show_copyright'] == '0' ? "checked" : ""));
466 + } else {
467 + echo esc_html(__('Only PRO accounts can be disabled.','codoc'));
468 + }
319 469 echo '</td></tr>';
320 470
321 - echo '<tr><th>PoweredByの表示</th><td>';
322 - 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" : ""));
323 - 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" : ""));
471 + echo '<tr><th>' . esc_html(__('"Purchase Article" button text','codoc')) . '</th><td>';
472 + echo sprintf('<input type="text" name="%s[entry_button_text]" value="%s">',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['entry_button_text']));
324 473 echo '</td></tr>';
325 474
326 - echo '<tr><th>記事購入ボタンのテキスト</th><td>';
327 - echo sprintf('<input type="text" name="%s[entry_button_text]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['entry_button_text']));
475 + echo '<tr><th>' . esc_html(__('"Purchase Subscription" button text.','codoc')) . '</th><td>';
476 + echo sprintf('<input type="text" name="%s[subscription_button_text]" value="%s">',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['subscription_button_text']));
328 477 echo '</td></tr>';
329 -
330 - echo '<tr><th>サブスクリプション購入ボタンのテキスト</th><td>';
331 - echo sprintf('<input type="text" name="%s[subscription_button_text]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['subscription_button_text']));
332 - echo '</td></tr>';
333 478
334 - echo '<tr><th>サポートボタンのテキスト</th><td>';
335 - echo sprintf('<input type="text" name="%s[support_button_text]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['support_button_text']));
479 + echo '<tr><th>' . esc_html(__('Support button text','codoc')) . '</th><td>';
480 + echo sprintf('<input type="text" name="%s[support_button_text]" value="%s">',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['support_button_text']));
336 481 echo '</td></tr>';
337 482
338 - echo '<tr><th>「サブスクリプションに含まれる記事」のテキスト</th><td>';
339 - echo sprintf('<input type="text" name="%s[subscription_message]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['subscription_message']));
483 + echo '<tr><th>' . esc_html(__('Text for "Articles Included in Subscription".','codoc')) . '</th><td>';
484 + echo sprintf('<input type="text" name="%s[subscription_message]" value="%s">',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['subscription_message']));
340 485 echo '</td></tr>';
341 486
342 - echo '<tr><th>サポート説明のテキスト</th><td>';
343 - echo sprintf('<input type="text" name="%s[support_message]" value="%s">',CODOC_SETTINGS_OPTION_NAME,esc_html($CODOC_SETTINGS['support_message']));
487 + echo '<tr><th>' . esc_html(__('Text for support description','codoc')) . '</th><td>';
488 + echo sprintf('<input type="text" name="%s[support_message]" value="%s">',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['support_message']));
344 489 echo '</td></tr>';
345 490
346 491 echo '</tbody></table>';
347 492 },
@@ -350,28 +495,38 @@
350 495 );
351 496
352 497 add_settings_field(
353 498 'codoc_tag_attributes', // id
354 - 'codocタグの属性', // title
499 + __('Attributes for codoc tag','codoc'), // title
355 500 function() {
356 501 global $CODOC_SETTINGS;
357 - echo '<div class="excerpt">codocタグに特定の属性を追加することができます。</div>';
358 - echo sprintf('<input type="text" name="%s[codoc_tag_attributes]" value="%s">',CODOC_SETTINGS_OPTION_NAME,htmlspecialchars($CODOC_SETTINGS['codoc_tag_attributes']));
502 + echo '<div class="excerpt">' . esc_html(__('You can add specific attributes to codoc tags.','codoc')) . '</div>';
503 + echo sprintf('<input type="text" name="%s[codoc_tag_attributes]" value="%s">',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['codoc_tag_attributes']));
359 504 },
360 505 'codoc', //page
361 506 'setting_section_id' //Section
362 507 );
363 -
364 508 add_settings_field(
509 + 'codoc_script_tag_attributes', // id
510 + __('Attributes for codoc script tag','codoc'), // title
511 + function() {
512 + global $CODOC_SETTINGS;
513 + echo '<div class="excerpt">' . esc_html(__('You can add specific attributes to codoc script tags.','codoc')) . '</div>';
514 + echo sprintf('<input type="text" name="%s[codoc_script_tag_attributes]" value="%s">',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['codoc_script_tag_attributes']));
515 + },
516 + 'codoc', //page
517 + 'setting_section_id' //Section
518 + );
519 + add_settings_field(
365 520 'str_replace_binded_url', // id
366 - 'パーマリンク', // title
521 + __('Permalink','codoc'), // title
367 522 function() {
368 523 global $CODOC_SETTINGS;
369 - echo '<div class="excerpt">codoc側に登録するパーマリンクを置換することができます。</div>';
370 - 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']));
371 - echo ('<span class="suptext">を</span>');
372 - 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']));
373 - echo ('に変換');
524 + echo '<div class="excerpt">' . esc_html(__('You can replace the part of permalink registered on the codoc.','codoc')) . '</div>';
525 + echo sprintf('<input type="text" name="%s[str_replace_binded_url_from]" value="%s">',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['str_replace_binded_url_from']));
526 + echo ('<span class="suptext">→</span>');
527 + echo sprintf('<input type="text" name="%s[str_replace_binded_url_to]" value="%s">',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['str_replace_binded_url_to']));
528 +
374 529 },
375 530 'codoc', //page
376 531 'setting_section_id' //Section
377 532 );
@@ -377,16 +532,14 @@
377 532 );
378 533
379 534 add_settings_field(
380 535 'str_around_codoc_tag', // id
381 - 'HTMLの挿入', // title
536 + __('HTML insertion','codoc'), // title
382 537 function() {
383 538 global $CODOC_SETTINGS;
384 - echo '<div class="excerpt">codocタグの前後にHTMLを挿入することができます。</div>';
385 - 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']));
386 - echo ('を前に挿入</div>');
387 - 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']));
388 - echo ('を後に挿入</div>');
539 + echo '<div class="excerpt">' . esc_html(__('You can insert HTML before and after the codoc tag.','codoc')) . '</div>';
540 + echo sprintf('<div class="inputRow"><p>%s</p><textarea name="%s[str_before_codoc_tag]" cols="40">%s</textarea></div>',esc_html(__('Before HTML','codoc')),esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_html($CODOC_SETTINGS['str_before_codoc_tag']));
541 + echo sprintf('<div class="inputRow"><p>%s</p><textarea name="%s[str_after_codoc_tag]" cols="40">%s</textarea></div>',esc_html(__('After HTML','codoc')),esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_html($CODOC_SETTINGS['str_after_codoc_tag']));
389 542
390 543 },
391 544 'codoc', //page
392 545 'setting_section_id' //Section
@@ -393,26 +546,26 @@
393 546 );
394 547
395 548 add_settings_field(
396 549 'always_show_support_tag', // id
397 - 'サポートの自動挿入', // title
550 + __('Automatic support insertion','codoc'), // title
398 551 function() {
399 552 global $CODOC_SETTINGS;
400 - echo '<div class="excerpt">codocブロックを挿入することなく投稿にサポート機能を追加します</div>';
553 + echo '<div class="excerpt">' . esc_html(__('It adds support functions to the post without inserting a codoc block.','codoc')) . '</div>';
401 554 echo '<table class="innerTable"><tbody>';
402 - echo '<tr><th>自動挿入</th><td>';
403 - 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" : ""));
404 - 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" : ""));
555 + echo '<tr><th>' . esc_html(__('Automatic insertion','codoc')) . '</th><td>';
556 + echo sprintf('<input type="radio" value="1" name="%s[always_show_support]" id="always_show_support_on" %s><label for="always_show_support_on">' . esc_html(__('Enable','codoc')) . '</label> ',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['always_show_support'] == '1' ? "checked" : ""));
557 + echo sprintf('<input type="radio" value="0" name="%s[always_show_support]" id="always_show_support_off" %s><label for="always_show_support_off">' . esc_html(__('Disable','codoc')) . '</label> <br / >',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['always_show_support'] == '0' ? "checked" : ""));
405 558 echo '</td></tr>';
406 - echo '<tr><th>表示位置</th><td>';
407 - 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" : ""));
408 - 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" : ""));
559 + echo '<tr><th>'. esc_html(__('Position','codoc')) . '</th><td>';
560 + echo sprintf('<input type="radio" value="top" name="%s[show_support_location]" id="show_support_location_top" %s><label for="show_support_location_top">' . esc_html(__('TOP','codoc')) . '</label> ',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['show_support_location'] == 'top' ? "checked" : ""));
561 + echo sprintf('<input type="radio" value="bottom" name="%s[show_support_location]" id="show_support_location_bottom" %s><label for="show_support_location_bottom">' . esc_html(__('Bottom','codoc')) . '</label> <br / >',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['show_support_location'] == 'bottom' ? "checked" : ""));
409 562 echo '</td></tr>';
410 - echo '<tr><th>説明文</th><td>';
411 - 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']));
563 + echo '<tr><th>' . esc_html(__('Description','codoc')) . '</th><td>';
564 + echo sprintf('<input type="text" placeholder="' . esc_html(__('You can customize the description of the support.','codoc')) . '" size="50%%" name="%s[show_support_message]" value="%s">',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_html($CODOC_SETTINGS['show_support_message']));
412 565 echo '</td></tr>';
413 - echo '<tr><th>対象カテゴリ名</th><td>';
414 - 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']));
566 + echo '<tr><th>' . esc_html(__('Category names','codoc')) . '</th><td>';
567 + echo sprintf('<input placeholder="' . esc_html(__('Inserted into articles of categories, divided by &quot;|&quot;','codoc')) . '" type="text" size="50%%" name="%s[show_support_categories]" value="%s"><br />',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_html($CODOC_SETTINGS['show_support_categories']));
415 568 echo '</td></tr>';
416 569 echo '</tbody></table>';
417 570
418 571 },
@@ -420,31 +573,95 @@
420 573 'setting_section_id' //Section
421 574 );
422 575 add_settings_field(
423 576 'do_not_filter_the_content', // id
424 - '支障が出る処理を無効化', // title
577 + __('Disable plugin filter','codoc'), // title
425 578 function() {
426 579 global $CODOC_SETTINGS;
427 - echo '<div class="excerpt">codocの動作に支障が出る他のプラグインによる<strong>フィルター処理</strong>を無効化できます。codocが上手く動かない場合のみ利用してください。</div>';
428 - 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" : ""));
429 - 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" : ""));
580 + echo '<div class="excerpt">' . esc_html(__('You can disable filter processing that includes shortcodes from other plugins that interfere with the operation of codoc. Please use this only if codoc is not functioning properly.','codoc')) . '</div>';
581 + 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">' . esc_html(__('Enable','codoc')) .'</label> ',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['do_not_filter_the_content'] == '1' ? "checked" : ""));
582 + 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">' . esc_html(__('Disable','codoc')) . '</label> ',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['do_not_filter_the_content'] == '0' ? "checked" : ""));
430 583 },
431 584 'codoc', //page
432 585 'setting_section_id' //Section
433 586 );
587 +
434 588 add_settings_field(
589 + 'shortcode_evacuation', // id
590 + __('Shortcode evacuation','codoc'), // title
591 + function() {
592 + global $CODOC_SETTINGS;
593 + echo '<div class="excerpt">' . esc_html(__('The execution results of shortcodes written in the paid part are moved to the free part, and are used and displayed on the HTML during viewing of the paid part. Please use this if the shortcode does not work as expected in the paid part. Please note that the execution results of shortcodes in the paid part will be written in the source code.','codoc')). '</div>';
594 + echo sprintf('<input type="radio" value="1" name="%s[shortcode_evacuation]" id="shortcode_evacuation_on" %s><label for="shortcode_evacuation_on">' . esc_html(__('Enable','codoc')) . '</label> ',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['shortcode_evacuation'] == '1' ? "checked" : ""));
595 + echo sprintf('<input type="radio" value="0" name="%s[shortcode_evacuation]" id="shortcode_evacuation_off" %s><label for="shortcode_evacuation_off">' . esc_html(__('Disable','codoc')) . '</label> ',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_attr($CODOC_SETTINGS['shortcode_evacuation'] == '0' ? "checked" : ""));
596 + },
597 + 'codoc', //page
598 + 'setting_section_id' //Section
599 + );
600 +
601 + add_settings_field(
435 602 'debug_params', // id
436 - 'デバック用', // title
603 + __('Debug Parameters','codoc'), // title
437 604 function() {
438 605 global $CODOC_SETTINGS;
439 - echo '<div class="excerpt">デバック用のパラメーターを指定できます。codocサポートから依頼がある場合のみ利用してください。</div>';
440 - 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']));
606 + echo '<div class="excerpt">' . esc_html(__('You can specify parameters for debugging. Please use this only upon request from codoc support.','codoc')) . '</div>';
607 + echo sprintf('<input placeholder="" type="text" size="50%%" name="%s[debug_params]" value="%s"><br />',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_html($CODOC_SETTINGS['debug_params']));
441 608 },
442 609 'codoc', //page
443 610 'setting_section_id' //Section
444 611 );
445 612
613 + add_settings_field(
614 + 'block_defaults', // id
615 + __('Block Default Values','codoc'), // title
616 + function() {
617 + global $CODOC_SETTINGS;
618 + echo '<div class="excerpt">' . esc_html(__('You can specify default values for new codoc blocks in JSON format.','codoc')) . ' ' . esc_html(__('Specified values take precedence over the values last used in the editor.','codoc')) . '</div>';
619 + echo sprintf('<textarea placeholder=\'{"showPrice":false,"price":300}\' rows="3" cols="50" name="%s[block_defaults]">%s</textarea>',esc_attr(CODOC_SETTINGS_OPTION_NAME),esc_html($CODOC_SETTINGS['block_defaults']));
620 + echo '<p class="description">'
621 + . 'showPrice (bool: true), '
622 + . 'price (int: 500), '
623 + . 'limited (bool: false), '
624 + . 'limitedCount (int: 10), '
625 + . 'affiliateMode (bool: false), '
626 + . 'affiliateRate (string: "0.0500"), '
627 + . 'showSupport (bool: false), '
628 + . 'showPaywalledSupport (bool: false), '
629 + . 'showPayWithoutAccountButton (bool: true), '
630 + . 'statusLimited (bool: false), '
631 + . 'subscriptions (object: {})'
632 + . '</p>';
633 + },
634 + 'codoc', //page
635 + 'setting_section_id' //Section
636 + );
446 637
638 + add_settings_field(
639 + 'cretor_info', // id
640 + __('Creator\'s Information','codoc'), // title
641 + function() {
642 + global $CODOC_SETTINGS;
643 + global $CODOC_AUTHINFO;
644 + echo sprintf('<p><font id="codoc-update-creator-info-message"></font></p>',"");
645 + // 変更を保存時に常に同期するのでこの表示は必要ないがUI上保持しておく
646 + $script = "document.getElementById('codoc-update-creator-info-message').innerText='" . __("Please save changes to update the information.","codoc") . "';document.getElementById('codoc-update-creator-info-message').color='red';";
647 + if (isset($CODOC_AUTHINFO['profile_image_url'])) {
648 + echo sprintf('<img src="%s" width="40" height="40" />',esc_attr($CODOC_AUTHINFO['profile_image_url']));
649 + }
650 + echo sprintf('<p>%s %s %s</p>',esc_html($CODOC_AUTHINFO['name']),esc_html((isset($CODOC_AUTHINFO['account_is_pro']) and $CODOC_AUTHINFO['account_is_pro']) ? ' [PRO]' : ''),esc_html(isset($CODOC_AUTHINFO['country']) ? $CODOC_AUTHINFO['country'] : '' ));
651 + if ($connect_code = $CODOC_SETTINGS['codoc_connect_code']) {
652 + // Translators: %s is the integration code, and %s is additional information based on the registration mode.
653 + echo sprintf('<p>' . esc_html(__('Extensions integration completed (Extensions code: %1$s) %2$s','codoc')) . '</p>',
654 + esc_html($connect_code),
655 + esc_html($CODOC_SETTINGS['codoc_connect_registration_mode'] == 'dedicated' ? __('Set the audience as a private account.','codoc') : ''));
656 + }
657 + echo sprintf('<p><a href="javascript:void(0);" onClick="' . esc_attr($script) . '">' . esc_html(__('Update creator\'s Information','codoc')) . '</a></p>');
658 + echo ('<p>' . esc_html(__('Please update each time if you change the logo or cover image on the codoc side.','codoc')) . '</p>');
659 + },
660 + 'codoc', //page
661 + 'setting_section_id' //Section
662 + );
663 +
447 664 register_setting(
448 665 'codoc_option_group', // option group
449 666 CODOC_USERCODE_OPTION_NAME
450 667 );
@@ -453,25 +670,26 @@
453 670 CODOC_TOKEN_OPTION_NAME
454 671 );
455 672
456 673 if (isset($_GET['codoc_auth_finished']) and $_GET['codoc_auth_finished']) {
457 - add_settings_error( 'general', 'settings_updated', __( 'codocの認証が完了しました' ), 'success' );
674 + add_settings_error( 'general', 'settings_updated', esc_html(__( 'codoc authentication has been completed.' ,'codoc'), 'success' ));
458 675 }
459 676
460 677 add_settings_field(
461 678 'codoc_auth',
462 - '認証',
679 + __('Authentication','codoc'),
463 680 function() {
464 681 global $CODOC_USERCODE;
465 682 global $CODOC_TOKEN;
466 683 global $CODOC_AUTHINFO;
467 - $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';";
684 + $script = "javascript:document.getElementById('codoc-usercode').value='-';document.getElementById('codoc-token').value='-';document.getElementById('codoc-auth-message').innerText='" . __('Please save changes to complete the unbinding.','codoc') . "';document.getElementById('codoc-auth-message').color='red';";
468 685
469 - echo sprintf('<p><font color="green" id="codoc-auth-message"><strong>%s</strong> で認証済</font></p>',$CODOC_AUTHINFO['email']);
686 + // Translators: %s is the email address.
687 + echo sprintf('<p><font color="green" id="codoc-auth-message">' . esc_html(__('Authorized as %s','codoc')) . '</font></p>',esc_attr($CODOC_AUTHINFO['email']));
470 688
471 - echo sprintf('<input id="codoc-usercode" type="hidden" name="%s" value="%s">',CODOC_USERCODE_OPTION_NAME,$CODOC_USERCODE);
472 - echo sprintf('<input id="codoc-token" type="hidden" name="%s" value="%s">',CODOC_TOKEN_OPTION_NAME,$CODOC_TOKEN);
473 - echo sprintf('<p>認証を<a href="javascript:void(0);" onClick="' . $script . '">解除する</p>');
689 + echo sprintf('<input id="codoc-usercode" type="hidden" name="%s" value="%s">',esc_attr(CODOC_USERCODE_OPTION_NAME),esc_attr($CODOC_USERCODE));
690 + echo sprintf('<input id="codoc-token" type="hidden" name="%s" value="%s">',esc_attr(CODOC_TOKEN_OPTION_NAME),esc_attr($CODOC_TOKEN));
691 + echo sprintf('<p><a href="javascript:void(0);" onClick="' . esc_attr($script) . '">' . esc_html(__('Unbind authorization','codoc')) . '</p>');
474 692 },
475 693 'codoc',
476 694 'setting_section_id'
477 695 );
@@ -481,22 +699,40 @@
481 699 // ない場合
482 700 if (!$CODOC_AUTHINFO and !isset($_GET['auth_by_myself'])) {
483 701 add_settings_field(
484 702 'codoc_auth',
485 - '認証',
703 + __('Authentication','codoc'),
486 704 function() {
487 -
705 + $theme = wp_get_theme();
706 + $from = 'wp';
707 + if ($theme->get('Name') === 'codoc') {
708 + $from = 'wp_codoc';
709 + }
488 710 //$current_url = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
489 711 $current_url = admin_url('options-general.php') . '?page=codoc';
490 - $login_url = sprintf("location.href='%s'",$this->get_codoc_url() . '/me/token?from=wp&return_url=' . urlencode($current_url));
491 - $register_url = sprintf("location.href='%s'",$this->get_codoc_url() . '/register?from=wp&return_url=' . urlencode($current_url));
712 + $direct_url = sprintf("location.href='%s&auth_by_myself=1'",$current_url);
713 + $login_url = sprintf("location.href='%s'",$this->get_codoc_url() . '/me/token?from=' . $from . '&return_url=' . urlencode($current_url));
714 + $register_url = sprintf("location.href='%s'",$this->get_codoc_url() . '/register?from=' . $from . '&return_url=' . urlencode($current_url));
492 715 // submitを消しておく
493 - echo ('<script type="text/javascript">window.onload=function(){document.getElementById(\'submit\').style.display = \'none\'}</script>');
494 - echo ('codocをWordPressでご利用いただくには認証が必要です。<br />');
495 - echo sprintf('ユーザーコードとAPIトークンを<a href="%s&auth_by_myself=1">直接入力</a>することでも認証できます。<br /><br />',$current_url);
496 - 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);
716 + echo ('<script type="text/javascript">window.onload=function(){document.getElementById(\'submit\').style.display = \'none\'}</script>');
717 + if (isset($_GET['confirm_token'])) {
718 + $confirm_url = sprintf("location.href='%s&_wpnonce=%s&fetch_token_key=%s&usercode=%s'",$current_url,
719 + wp_create_nonce('fetch_token_nonce'),
720 + esc_attr($_GET['fetch_token_key']),
721 + esc_attr($_GET['usercode']));
722 + echo (esc_html(__('The authentication information has been obtained. Please click the confirmation button to complete the setup.','codoc')) . '<br />');
723 + echo sprintf('<input type="button" class="button button-primary" value="%s" onClick="%s"> ',esc_html(__('Confirm authentication','codoc')),esc_attr($confirm_url));
724 + } else {
725 +
726 + echo (esc_html(__('Authentication is required to use codoc on WordPress.','codoc')) . '<br />');
727 + echo (esc_html(__('You can authenticate by directly entering the user code and API token, or by logging in and registering with codoc.','codoc')) . '<br /><br />');
728 + echo sprintf('<input type="button" class="button button-primary" value="%s" onClick="%s"> ',esc_attr(__('Authenticate by direct input','codoc')),esc_attr($direct_url));
729 + echo sprintf('<input type="button" class="button button-primary" value="%s" onClick="%s"> <input type="button" class="button button-primary" value="%s" onClick="%s"><br /><br />',esc_attr(__('Login and authenticate','codoc')),esc_attr($login_url),esc_attr(__('Register and authenticate','codoc')),esc_attr($register_url));
730 + }
731 + if (!$this->util->health_check()) {
732 + echo sprintf('<p style="color: red;">Cannot communicate with the codoc server. Please allow communication to https://codoc.jp in your firewall settings on the server or WordPress side.</p>');
733 + }
497 734
498 -
499 735 },
500 736 'codoc',
501 737 'setting_section_id'
502 738 );
@@ -519,9 +755,9 @@
519 755 'ユーザーコード',
520 756 function() {
521 757 global $CODOC_USERCODE;
522 758 echo '<input type="hidden" name="auth_by_myself" value="1">';
523 - echo sprintf('<input type="text" name="%s" value="%s">',CODOC_USERCODE_OPTION_NAME,$CODOC_USERCODE);
759 + echo sprintf('<input type="text" name="%s" value="%s">',esc_attr(CODOC_USERCODE_OPTION_NAME),esc_attr($CODOC_USERCODE));
524 760 },
525 761 'codoc',
526 762 'setting_section_id'
527 763 );
@@ -529,9 +765,9 @@
529 765 'codoc_token',
530 766 'APIトークン',
531 767 function() {
532 768 global $CODOC_TOKEN;
533 - echo sprintf('<input type="text" name="%s" value="%s">',CODOC_TOKEN_OPTION_NAME,$CODOC_TOKEN);
769 + echo sprintf('<input type="text" name="%s" value="%s">',esc_attr(CODOC_TOKEN_OPTION_NAME),esc_attr($CODOC_TOKEN));
534 770 },
535 771 'codoc',
536 772 'setting_section_id'
537 773 );
@@ -553,9 +789,9 @@
553 789 $data = $this->util->get_support_entry([],[
554 790 "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
555 791 "token" => get_option(CODOC_TOKEN_OPTION_NAME),
556 792 ]);
557 - if ($data->status and $entry = $data->entry) {
793 + if ($data and $data->status and $entry = $data->entry) {
558 794 update_option(CODOC_SUPPORT_ENTRYCODE_OPTION_NAME,$entry->code);
559 795 } else {
560 796 update_option(CODOC_SUPPORT_ENTRYCODE_OPTION_NAME,'');
561 797 }
@@ -562,9 +798,9 @@
562 798 } elseif(isset($CODOC_SETTINGS['always_show_support']) and !$CODOC_SETTINGS['always_show_support']) {
563 799 update_option(CODOC_SUPPORT_ENTRYCODE_OPTION_NAME,'');
564 800 }
565 801 });
566 -
802 +
567 803 add_action('updated_option',function(){
568 804 global $CODOC_RE_AUTHORIZE;
569 805 if ($CODOC_RE_AUTHORIZE) {
570 806 //$data = $this->callAPI('GET','');
@@ -572,12 +808,9 @@
572 808 "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
573 809 "token" => get_option(CODOC_TOKEN_OPTION_NAME),
574 810 ]);
575 811 if ($data->status and $user = $data->user) {
576 - update_option(CODOC_AUTHINFO_OPTION_NAME,[
577 - 'email' => $user->email,
578 - 'name' => $user->name,
579 - ]);
812 + $this->update_codoc_authinfo($user);
580 813 } else {
581 814 update_option(CODOC_AUTHINFO_OPTION_NAME,'');
582 815 }
583 816 }
@@ -586,9 +819,9 @@
586 819 });
587 820 // プラグイン一覧に設定のリンクをいれる
588 821 add_filter( 'plugin_action_links_' . plugin_basename( plugin_dir_path( __FILE__ ) . 'codoc' . '.php' ),
589 822 function( $links ) {
590 - $setting_link = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( 'page', 'codoc', admin_url( 'options-general.php' ) ) ), esc_html( '設定' ) );
823 + $setting_link = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( 'page', 'codoc', admin_url( 'options-general.php' ) ) ), esc_html( __('Settings') ) );
591 824 array_unshift( $links, $setting_link );
592 825
593 826 return $links;
594 827 }
@@ -610,8 +843,13 @@
610 843 // プラグイン内で使うCSRF を生成
611 844 $path = plugins_url( 'codoc/src_mce/codoc-editor-onload.js', __DIR__ );
612 845 wp_enqueue_script( 'codoc-editor-onload', $path, array('jquery'), '', true );
613 846 // I just want to insert this global variables but i don't know how i can do it..
847 + $auth_info = get_option(CODOC_AUTHINFO_OPTION_NAME);
848 + $codoc_settings = get_option(CODOC_SETTINGS_OPTION_NAME);
849 + $block_defaults_raw = isset($codoc_settings['block_defaults']) ? $codoc_settings['block_defaults'] : '';
850 + $block_defaults_decoded = json_decode($block_defaults_raw, true);
851 + $block_defaults = is_array($block_defaults_decoded) ? $block_defaults_decoded : new stdClass();
614 852 wp_localize_script(
615 853 'codoc-editor-onload',
616 854 'CODOCEDITOR',
617 855 array(
@@ -621,8 +859,12 @@
621 859 'codoc_url' => $this->get_codoc_url(),
622 860 'codoc_usercode' => get_option(CODOC_USERCODE_OPTION_NAME),
623 861 'codoc_plugin_version' => CODOC_PLUGIN_VERSION,
624 862 'codoc_sdk_path' => CODOC_SDK_PATH,
863 + 'codoc_account_is_pro' => isset($auth_info['account_is_pro']) ? $auth_info['account_is_pro'] : 0,
864 + 'codoc_currency_code' => isset($auth_info['currency_code']) ? $auth_info['currency_code'] : 0,
865 + 'codoc_currency_decimal_places' => isset($auth_info['currency_decimal_places']) ? $auth_info['currency_decimal_places'] : 0,
866 + 'codoc_block_defaults' => $block_defaults,
625 867 )
626 868 );
627 869
628 870 // ここでtinymceのプラグイン追加
@@ -639,13 +881,58 @@
639 881 add_filter( 'mce_buttons', function( $buttons ) {
640 882 array_push( $buttons, "|", "codoc" );
641 883 return $buttons;
642 884 } );
885 + // 非SSL環境の場合、なぜかhttps -> httpsになってしまうので対策
886 + // コメントタグが除去されることがあるらしいのでvalid_elementsに必要なタグを追加 (EXPERIMENTAL)
887 + add_filter( 'tiny_mce_before_init', function($settings) {
888 + $settings['external_plugins'] = preg_replace('/"codoc":"http:/','"codoc":"https:',$settings['external_plugins']);
889 + foreach (['valid_elements','extended_valid_elements'] as $valid_elements) {
890 + if (isset($settings[$valid_elements])) {
891 + $settings[$valid_elements] = $settings[$valid_elements] . ',div[*],p[*],img[*],--[*]';
892 + }
893 + }
894 + $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
895 + if (isset($CODOC_SETTINGS["debug_params"])) {
896 + $params_decoded = json_decode($CODOC_SETTINGS["debug_params"],true);
897 + if (isset($params_decoded["mce_valid_elements"])) {
898 + $settings['valid_elements'] = $params_decoded["mce_valid_elements"];
899 + $settings['extended_valid_elements'] = $params_decoded["mce_valid_elements"];
900 + }
901 + }
643 902
903 + return $settings;
904 + },1000000);
644 905 }
645 906 }
646 907 } );
647 908 }
909 + function update_codoc_authinfo($user) {
910 + global $CODOC_SETTINGS;
911 + global $CODOC_AUTHINFO;
912 + if (property_exists($user,'connect_code') and $user->connect_code) {
913 + $CODOC_SETTINGS = get_option(CODOC_SETTINGS_OPTION_NAME);
914 + $CODOC_SETTINGS['codoc_connect_code'] = $user->connect_code;
915 + $CODOC_SETTINGS['codoc_connect_registration_mode'] = $user->connect_has_permission_dedicated_account ? 'dedicated' : '';
916 + update_option(CODOC_SETTINGS_OPTION_NAME,$CODOC_SETTINGS);
917 + }
918 + return update_option(CODOC_AUTHINFO_OPTION_NAME,[
919 + 'email' => $user->email,
920 + 'name' => $user->name,
921 + 'profile_image_url' => $user->profile_image_url,
922 + 'cover_image_url' => $user->cover_image_url,
923 + 'connect_code' => property_exists($user,'connect_code') ? $user->connect_code : '',
924 + 'connect_image_url' => property_exists($user,'connect_image_url') ? $user->connect_image_url : '',
925 + 'account_is_pro' => property_exists($user,'account_is_pro') ? $user->account_is_pro : '',
926 + 'created_at' => property_exists($user,'created_at') ? $user->created_at : 0,
927 + 'country' => property_exists($user,'country') ? $user->country : '',
928 + 'currency_code' => property_exists($user,'currency_code') ? $user->currency_code : '',
929 + 'currency_decimal_places' => property_exists($user,'currency_decimal_places') ? $user->currency_decimal_places : '',
930 + ]);
931 + $CODOC_AUTHINFO = get_option(CODOC_AUTHINFO_OPTION_NAME);
932 + return $CODOC_AUTHINFO;
933 + }
934 + // 保存用コンテンツにフィルターを実施する
648 935 public function get_filtered_content($post_emulated) {
649 936 // 記事ページであることをエミュレートしてフィルター実行
650 937 $post_backuped = null;
651 938 if (isset($GLOBALS['post'])) {
@@ -656,13 +943,18 @@
656 943 $wp_query_backuped = null;
657 944 if (isset($GLOBALS['wp_query'])) {
658 945 $wp_query_backuped = $GLOBALS['wp_query'];
659 946 $wp_query = $GLOBALS['wp_query'];
660 - $is_single_backuped = $wp_query->is_single;
661 947 $wp_query->is_single = true;
948 + $wp_query->is_singular = true;
949 + # in_the_loop は記事ページでは通常有効っぽいので true指定 ex: wp_ulike
950 + $wp_query->in_the_loop = true;
951 + # これも追加しておく
952 + $wp_query->is_main_query = true;
953 +
662 954 $wp_query->post = $post_emulated;
663 955 $wp_query->queried_object = $post_emulated;
664 - $wp_query->queried_object_id = $post_emulated->id;
956 + $wp_query->queried_object_id = $post_emulated->ID;
665 957
666 958 $GLOBALS['wp_query'] = $wp_query;
667 959 }
668 960 // $this->the_content でオリジナルを返してもらうため
@@ -670,8 +962,29 @@
670 962 $content = preg_replace(
671 963 '/ (\/)?wp:codoc\/codoc-block /',' \\1wptmp:codoc/codoc-block ',
672 964 $post_emulated->post_content
673 965 );
966 + // post_metaに内容を保存し、無料パートにショートコードの退避をおこなう
967 + $codoc_settings = get_option(CODOC_SETTINGS_OPTION_NAME);
968 + if (isset($codoc_settings['shortcode_evacuation']) and $codoc_settings['shortcode_evacuation']) {
969 + $splited = preg_split('/\/wptmp:codoc\/codoc-block/s',$content);
970 + if (isset($splited[0]) and isset($splited[1])) {
971 + // すべてのショートコードを $match_all にいれる
972 + preg_match_all('/\[[^\[\]]+?\](.+\[\/[^\[\]]+?\])?/',$splited[1],$match_all);
973 + // ショートコードをURLエンコードしてdivタグの中にいれておく(後でmetaの中のショートコードと付け合せ)
974 + $replaced = preg_replace_callback('/\[[^\[\]]+?\](.+\[\/[^\[\]]+?\])?/',function($matches) {
975 + return sprintf ('<div class="codoc-evacuation-dests" data-shortcode="%s"></div>', urlencode($matches[0]));
976 + },$splited[1]);
977 + // 0番目に配列で入っているのでそこを退避対象の配列とする
978 + $evacuations = $match_all[0];
979 + // ショートコードの中身をタグに退避
980 + $content = $splited[0] . '/wptmp:codoc/codoc-block' . $replaced;
981 + // 無料パートでショートコードを実行できるようにする
982 + update_post_meta($post_emulated->ID,'codoc_shortcode_evacuations',join('**codoc**',$evacuations));
983 + } else {
984 + update_post_meta($post_emulated->id,'codoc_shortcode_evacuations',"");
985 + }
986 + }
674 987 #$content = do_shortcode( $content );
675 988 $content_filtered = apply_filters( 'the_content', $content);
676 989 $this->do_not_filter_the_content = false;
677 990
@@ -684,9 +997,8 @@
684 997 $content_filtered = preg_replace(
685 998 '/ (\/)?wptmp:codoc\/codoc-block /',' \\1wp:codoc/codoc-block ',
686 999 $content_filtered
687 1000 );
688 -
689 1001 return $content_filtered;
690 1002 }
691 1003
692 1004 public function save_post($post_ID,$post,$update) {
@@ -693,15 +1005,52 @@
693 1005 if (preg_match('/^(auto-draft|inherit)$/',$post->post_status)) {
694 1006 return;
695 1007 }
696 1008 $entryCode = get_post_meta($post_ID,'codoc_entry_code',true);
1009 + $postId = get_post_meta($post_ID,'codoc_saved_post_id',true);
1010 + // 保存されているIDと違う場合は破棄(duplicate pageなどでmeta情報をコピーされた可能性がある)
1011 + if ($postId and $postId != $post_ID) {
1012 + $entryCode = '';
1013 + }
697 1014 $codoc_settings = get_option(CODOC_SETTINGS_OPTION_NAME);
698 1015 $post_content = (isset($codoc_settings['do_not_filter_the_content']) and $codoc_settings['do_not_filter_the_content']) ?
699 1016 $post->post_content : $this->get_filtered_content($post);
1017 +
1018 + // codoc タグ(span/div または Gutenberg ブロック)が含まれていれば API側と統一した文字数検証を行う
1019 + $has_codoc_tag = preg_match('/<(?:span|div)[^>]+data-id="codoc-tag"/', $post_content)
1020 + || preg_match('/wp:codoc\/codoc-block/', $post_content);
1021 + if ($has_codoc_tag) {
1022 + // codoc タグ位置で free / paywalled を分割
1023 + $gutenberg_split = '/(?:<(?:div|p)(?:[^>]+|)>|)<\!-- +wp:codoc\/codoc-block .*<\!-- +\/wp:codoc\/codoc-block +-->(?:<\/(?:div|p)>|)/s';
1024 + $tag_split = '/<(?:span|div)[^>]+data-id="codoc-tag"(?:[^>]+|)>(?:.+|)<\/(?:span|div)>/';
1025 + $end_tag_regex = '/<(?:div|p)>::CODOC_WP_END_PAYWALL::<\/(?:div|p)>/';
1026 + $for_split = preg_split($end_tag_regex, $post_content);
1027 + $for_split = $for_split[0];
1028 + if (preg_match('/wp:codoc\/codoc-block/', $for_split)) {
1029 + $splited = preg_split($gutenberg_split, $for_split);
1030 + } else {
1031 + $splited = preg_split($tag_split, $for_split);
1032 + }
1033 + $body_free = isset($splited[0]) ? $splited[0] : '';
1034 + $body_paywalled = isset($splited[1]) ? $splited[1] : '';
1035 + $errors = $this->util->validate_entry_lengths([
1036 + 'title' => $post->post_title,
1037 + 'body_free' => $body_free,
1038 + 'body_paywalled' => $body_paywalled,
1039 + 'binded_url' => get_permalink($post_ID),
1040 + ]);
1041 + if ($errors) {
1042 + set_transient('codoc_entry_validation_errors', $errors, MINUTE_IN_SECONDS * 5);
1043 + // 同期はスキップ
1044 + return true;
1045 + }
1046 + }
1047 +
700 1048 $res = $this->util->sync_entry([
701 1049 "post_title" => $post->post_title,
702 1050 "post_content" => $post_content,
703 - "post_status" => ($post->post_status == 'publish' ? 1 : 0),
1051 + // password が設定されてる場合は限定公開にする
1052 + "post_status" => $post->post_status == 'publish' ? ($post->post_password ? 2 : 1) : 0,
704 1053 "post_permalink" => get_permalink($post_ID),
705 1054 "codoc_entry_code" => $entryCode,
706 1055 "codoc_settings" => $codoc_settings,
707 1056 ],[
@@ -707,20 +1056,44 @@
707 1056 ],[
708 1057 "usercode" => get_option(CODOC_USERCODE_OPTION_NAME),
709 1058 "token" => get_option(CODOC_TOKEN_OPTION_NAME),
710 1059 ]);
711 -
1060 + $prudent_update_post_meta_entry_code = null;
1061 + if (isset($codoc_settings["debug_params"])) {
1062 + $params_decoded = json_decode($codoc_settings["debug_params"],true);
1063 + if (isset($params_decoded["prudent_update_post_meta_entry_code"])) {
1064 + $prudent_update_post_meta_entry_code = $params_decoded["prudent_update_post_meta_entry_code"];
1065 + }
1066 + }
1067 + if ($prudent_update_post_meta_entry_code == 2) {
1068 + error_log('CODOC:: ' . sprintf ("%s : %s : %s : %s", $post_ID, (is_object($res) ? "1" : 0),$res->status,$entryCode));
1069 + }
712 1070 if (is_object($res) and $res->status and !$entryCode) {
713 - update_post_meta($post_ID,'codoc_entry_code',$res->entry->code);
1071 + // 20230222 https://stackoverflow.com/questions/26640785/update-post-meta-not-work-only-when-save-data-not-for-update
1072 + if ($prudent_update_post_meta_entry_code) {
1073 + add_post_meta($post_ID,'codoc_entry_code',$res->entry->code);
1074 + add_post_meta($post_ID,'codoc_saved_post_id',$post_ID);
1075 + } else {
1076 + update_post_meta($post_ID,'codoc_entry_code',$res->entry->code);
1077 + update_post_meta($post_ID,'codoc_saved_post_id',$post_ID);
1078 + }
714 1079 }
715 -
716 1080 return true;
717 1081 }
718 1082 function updated_post_meta( $meta_ID, $post_ID, $meta_key ) {
719 - if ($meta_key != '_thumbnail_id') {
1083 + // スルーされてる場合は他のメタ情報更新のタイミングにサムネイルをアップロード
1084 + $has_to_resend = get_post_meta($post_ID,'codoc_post_thumbnail_invoking_entry_code',true);
1085 + if ($has_to_resend != 1 and $meta_key != '_thumbnail_id') {
720 1086 return;
721 1087 }
722 1088 if ( has_post_thumbnail($post_ID) ) {
1089 + // 新規投稿の場合、タイミングによってはcodocEntryCodeが取得できないので一旦スルーする
1090 + if (!get_post_meta($post_ID,'codoc_entry_code',true)) {
1091 + update_post_meta($post_ID,'codoc_post_thumbnail_invoking_entry_code',1);
1092 + return;
1093 + } else {
1094 + update_post_meta($post_ID,'codoc_post_thumbnail_invoking_entry_code',0);
1095 + }
723 1096 $attachment = wp_get_attachment_metadata( get_post_thumbnail_id($post_ID));
724 1097 $upload_dir = wp_upload_dir();
725 1098 $file_path = sprintf ('%s/%s',$upload_dir['basedir'],$attachment['file']);
726 1099
@@ -745,9 +1118,25 @@
745 1118 "token" => get_option(CODOC_TOKEN_OPTION_NAME),
746 1119 ]
747 1120 );
748 1121 }
749 -
1122 + // 退避されてるかどうかをmetaを使って確認し、無料エリアの一番最後にショートコードを追加
1123 + function the_content_shortcode_evacuations( $post_content ) {
1124 + if ($this->do_not_filter_the_content) {
1125 + return $post_content;
1126 + }
1127 + $post = get_post();
1128 + if (!$post) {
1129 + return $post_content;
1130 + }
1131 + $evacuations_meta = get_post_meta($post->ID,'codoc_shortcode_evacuations',true);
1132 + $evacuations = preg_split('/\*\*codoc\*\*/',$evacuations_meta);
1133 + foreach ($evacuations as $evacuation) {
1134 + $post_content = sprintf('<div class="codoc-evacuations" style="display:none;" data-shortcode="%s">%s</div>',
1135 + urlencode($evacuation),$evacuation) . $post_content;
1136 + }
1137 + return $post_content;
1138 + }
750 1139 function the_content( $post_content ) {
751 1140 if ( is_single() && in_the_loop() && is_main_query() ) {
752 1141 }
753 1142 // get_filtered_content から do_not_filter_the_contentを有効にされるパターン
@@ -755,8 +1144,12 @@
755 1144 if ($this->do_not_filter_the_content) {
756 1145 return $post_content;
757 1146 }
758 1147 $post = get_post();
1148 + // 20211215 null になる場合がある
1149 + if (!$post) {
1150 + return $post_content;
1151 + }
759 1152 # is_amp で実装しているテンプレート用
760 1153 $is_amp_endpoint = (function_exists('is_amp_endpoint') && is_amp_endpoint()) ? true :
761 1154 ((function_exists('is_amp') && is_amp()) ? true : false);
762 1155 return $this->util->filter_content([
@@ -774,6 +1167,76 @@
774 1167 if (is_array($allowed_blocks)) {
775 1168 array_push($allowed_blocks,'codoc/codoc-block');
776 1169 }
777 1170 return $allowed_blocks;
1171 + }
1172 +
1173 + function allowed_block_types_all ($allowed_block_types, $block_editor_context) {
1174 + // テーマ等がブロックを制限していない場合(true = 全ブロック許可)はそのまま返す
1175 + if ($allowed_block_types === true) {
1176 + return $allowed_block_types;
1177 + }
1178 + // 配列で制限されている場合、codoc ブロックを追加
1179 + if (is_array($allowed_block_types) && !in_array('codoc/codoc-block', $allowed_block_types)) {
1180 + $allowed_block_types[] = 'codoc/codoc-block';
1181 + }
1182 + return $allowed_block_types;
1183 + }
1184 +
1185 + function show_validation_notices() {
1186 + $errors = get_transient('codoc_entry_validation_errors');
1187 + if (!$errors || !is_array($errors)) {
1188 + return;
1189 + }
1190 + delete_transient('codoc_entry_validation_errors');
1191 + $header = __('codoc could not sync this entry due to length limits:', 'codoc');
1192 + echo '<div class="notice notice-error is-dismissible"><p><strong>' . esc_html($header) . '</strong></p><ul>';
1193 + foreach ($errors as $message) {
1194 + echo '<li>' . esc_html($message) . '</li>';
1195 + }
1196 + echo '</ul></div>';
1197 + }
1198 +
1199 + function show_tadv_notice() {
1200 + // API からの notification を表示
1201 + $api_notifications = get_transient('codoc_api_notification');
1202 + if ($api_notifications && is_array($api_notifications)) {
1203 + // notification 配列のキーと値を表示
1204 + foreach ($api_notifications as $key => $value) {
1205 + // 値が配列やオブジェクトの場合は json_encode で文字列化
1206 + if (is_array($value) || is_object($value)) {
1207 + $value = json_encode($value, JSON_UNESCAPED_UNICODE);
1208 + }
1209 + echo "<div class=\"notice notice-warning is-dismissible codoc-notification\"><p>" . esc_html($value) . "</p></div>";
1210 + }
1211 + //delete_transient('codoc_api_notification');
1212 + }
1213 +
1214 + $name = 'Advanced Editor Tools';
1215 + $name_escaped = preg_replace('/ /','+',$name);
1216 + $install_url = network_admin_url( "plugin-install.php?tab=search&s=" . $name );
1217 + $options_url = network_admin_url( "options-general.php?page=tinymce-advanced" );
1218 +
1219 + //<a href=\"%s\">%s</a> を有効にし、設定画面にて &quot;Keep paragraph tags in the Classic block and the Classic Editor&quot; を有効にしてください。
1220 + //<a href=\"%s\">%s</a> の設定画面にて &quot;Keep paragraph tags in the Classic block and the Classic Editor&quot; を有効にしてください。
1221 + // Translators: %s is a link to the installation page with the plugin name.
1222 + $tadv_message_for_install = sprintf(__("Please enable %s and enable &quot;Keep paragraph tags in the Classic block and the Classic Editor&quot; on the settings screen.","codoc"),sprintf("<a href=\"%s\">%s</a>",$install_url,$name));
1223 + // Translators: %s is a link to the options settings page with the plugin name.
1224 + $tadv_message_for_options = sprintf(__("Please enable &quot;Keep paragraph tags in the Classic block and the Classic Editor&quot; on the %s settings screen.","codoc"),sprintf("<a href=\"%s\">%s</a>",$options_url,$name));
1225 + // クラシックエディタで advanced editor tools を入れてない場合は notice
1226 + if (is_plugin_active('classic-editor/classic-editor.php') and
1227 + !is_plugin_active('tinymce-advanced/tinymce-advanced.php')) {
1228 + echo "<div class=\"notice notice-warning is-dismissible\"><p>" . esc_html($tadv_message_for_install) . "</p></div>";
1229 + }
1230 +
1231 + // advanced editor tools の設定を調査
1232 + $no_autop = false;
1233 + $tadv_admin_settings = get_option( 'tadv_admin_settings', false );
1234 + if (isset($tadv_admin_settings['options']) and preg_match('/no_autop/',$tadv_admin_settings['options'])) {
1235 + $no_autop = true;
1236 + }
1237 + // advanced editor tools が有効で no_autop (Keep paragraph tags in the Classic block and the Classic Editor) が無効
1238 + if (is_plugin_active('tinymce-advanced/tinymce-advanced.php') and !$no_autop) {
1239 + echo "<div class=\"notice notice-warning is-dismissible\"><p>" . esc_html($tadv_message_for_options) . "</p></div>";
1240 + }
778 1241 }
779 1242 }