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