diff --git a/assets/js/buttons/images/reply.png b/assets/js/buttons/images/reply.png new file mode 100644 index 0000000..392c44a Binary files /dev/null and b/assets/js/buttons/images/reply.png differ diff --git a/assets/js/buttons/more.js b/assets/js/buttons/more.js index 930e973..9502af5 100644 --- a/assets/js/buttons/more.js +++ b/assets/js/buttons/more.js @@ -207,6 +207,22 @@ }) tinymce.PluginManager.add('bdbtn', tinymce.plugins.bdbtn) + tinymce.create('tinymce.plugins.reply', { + init: function (ed, url) { + ed.addButton('reply', { + title: '回复可见', + image: url + '/images/reply.png', + onclick: function () { + ed.selection.setContent('[reply]' + ed.selection.getContent() + '[/reply]') + } + }) + }, + createControl: function (n, cm) { + return null + }, + }) + tinymce.PluginManager.add('reply', tinymce.plugins.reply) + tinymce.create('tinymce.plugins.music', { init: function (ed, url) { ed.addButton('music', { diff --git a/inc/theme-shortcode.php b/inc/theme-shortcode.php index 19298b2..d35a860 100644 --- a/inc/theme-shortcode.php +++ b/inc/theme-shortcode.php @@ -3,7 +3,7 @@ * 文章短代码 * @author Seaton Jiang * @license MIT License - * @version 2020.04.12 + * @version 2020.06.21 */ function h2title($atts, $content = null, $code = "") @@ -178,6 +178,44 @@ function bilibili($atts, $content = null, $code = "") } add_shortcode('bilibili', 'bilibili'); +function reply($atts, $content = null) +{ + extract(shortcode_atts(array("notice" => ''), $atts)); + $userEmail = null; + $user_ID = (int) wp_get_current_user()->ID; + if ($user_ID > 0) { + $userEmail = get_userdata($user_ID)->user_email; + $adminUsers = get_users('role=Administrator'); + $adminEmails = array(); + foreach ($adminUsers as $user) { + $adminEmails[] = $user->user_email; + } + $authorEmail = get_the_author_meta('user_email'); + array_push($adminEmails, $authorEmail); + if (in_array($userEmail, $adminEmails)) { + return $content; + } + } else { + if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) { + $userEmail = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]); + } else { + return $notice; + } + } + if (empty($userEmail)) { + return $notice; + } + global $wpdb; + $post_id = get_the_ID(); + $query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$userEmail}' LIMIT 1"; + if ($wpdb->get_results($query)) { + return do_shortcode($content); + } else { + return $notice; + } +} +add_shortcode('reply', 'reply'); + add_action('init', 'more_button'); function more_button() { @@ -206,6 +244,7 @@ function register_button($buttons) array_push($buttons, " ", "mark"); array_push($buttons, " ", "striped"); array_push($buttons, " ", "bdbtn"); + array_push($buttons, " ", "reply"); array_push($buttons, " ", "music"); array_push($buttons, " ", "vqq"); array_push($buttons, " ", "youtube"); @@ -228,6 +267,7 @@ function add_plugin($plugin_array) $plugin_array['mark'] = ASSET_PATH . '/assets/js/buttons/more.js'; $plugin_array['striped'] = ASSET_PATH . '/assets/js/buttons/more.js'; $plugin_array['bdbtn'] = ASSET_PATH . '/assets/js/buttons/more.js'; + $plugin_array['reply'] = ASSET_PATH . '/assets/js/buttons/more.js'; $plugin_array['music'] = ASSET_PATH . '/assets/js/buttons/more.js'; $plugin_array['vqq'] = ASSET_PATH . '/assets/js/buttons/more.js'; $plugin_array['youtube'] = ASSET_PATH . '/assets/js/buttons/more.js'; diff --git a/languages/kratos.pot b/languages/kratos.pot index ff85da2..b0f793a 100644 --- a/languages/kratos.pot +++ b/languages/kratos.pot @@ -3,7 +3,7 @@ msgid "" msgstr "" "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" "Project-Id-Version: Kratos\n" -"POT-Creation-Date: 2020-06-13 13:30+0800\n" +"POT-Creation-Date: 2020-06-21 11:42+0800\n" "PO-Revision-Date: 2020-02-14 23:32+0800\n" "Last-Translator: \n" "Language-Team: \n" @@ -837,6 +837,10 @@ msgstr "" msgid "标题内容" msgstr "" +#: inc/theme-shortcode.php:183 +msgid "温馨提示:此处内容已隐藏,回复后刷新页面即可查看!" +msgstr "" + #: inc/theme-smtp.php:38 msgid "[通知]您的留言已经通过审核" msgstr ""