评论区硬切换实现

This commit is contained in:
2026-08-30 17:34:29 +08:00
parent ed914d2eec
commit b8ef4d81a4
32 changed files with 946 additions and 1008 deletions
+2 -4
View File
@@ -225,20 +225,18 @@ class SchemaPostList {
['key' => 'toolbar', 'title' => '评论工具栏', 'fields' => [
['key' => 'comment_code', 'label' => '代码插入', 'type' => 'switch', 'default' => true],
['key' => 'comment_img', 'label' => '图片上传', 'type' => 'switch', 'default' => true],
['key' => 'comment_link', 'label' => '链接按钮', 'type' => 'switch', 'default' => false],
]],
['key' => 'interaction', 'title' => '互动功能', 'fields' => [
['key' => 'comment_hot_threshold', 'label' => '神评点赞阈值', 'type' => 'number', 'default' => 10, 'min' => 1, 'max' => 999],
['key' => 'comment_like_s', 'label' => '评论点赞', 'type' => 'switch', 'default' => true],
['key' => 'comment_quick_s', 'label' => '快捷回复', 'type' => 'switch', 'default' => true],
['key' => 'comment_user_url_s', 'label' => '匿名者网址', 'type' => 'switch', 'default' => false, 'description' => '用户未登录评论时,允许输入用户博客地址'],
['key' => 'comment_city_s', 'label' => '评论城市', 'type' => 'switch', 'default' => true],
['key' => 'comment_city_type', 'label' => '城市显示格式', 'type' => 'radio', 'default' => 'province_city', 'options' => [
['label' => '省份+城市', 'value' => 'province_city'],
['label' => '仅省份', 'value' => 'province'],
['label' => '国家+省份', 'value' => 'country_province'],
]],
['key' => 'comment_quick_often', 'label' => '快捷回复短语', 'type' => 'textarea', 'default' => "不错,学习了
感谢分享
期待更新"],
['key' => 'comment_author_tag', 'label' => '作者标签', 'type' => 'switch', 'default' => true],
['key' => 'comment_corderby', 'label' => '评论排序切换', 'type' => 'switch', 'default' => true, 'description' => '前台显示最新/最早/最热切换按钮'],
]],
+1 -2
View File
@@ -368,7 +368,7 @@ trait ScriptsPart1c {
}
// Comment toolbar (code/image/quick shortcodes) — post form.
// Comment toolbar (code/image/link shortcodes) — post form.
$load_comment_tools = !empty($singular_assets['needs_comment_tools']);
if ($load_comment_tools) {
$comment_tools_path = get_template_directory() . '/assets/js/comment-tools.js';
@@ -481,7 +481,6 @@ trait ScriptsPart1c {
'commentUploadUrl' => esc_url_raw(rest_url('aksrt/v1/comment/upload-image')),
'commentUploadMaxSize' => 2 * 1024 * 1024,
'commentIasMax' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_comment_display_settings()['paging_ajax_ias_max'] : 3,
'commentQuickPhrases' => class_exists('\AKSRT\Settings\Settings') ? (\AKSRT\Settings\Settings::get_comment_display_settings()['quick_phrases'] ?? []) : [],
'restUrl' => esc_url_raw(rest_url('aksrt/v1')),
// Alias used by modal-auth / follow / report (same value as restUrl).
'apiUrl' => esc_url_raw(rest_url('aksrt/v1')),
+2 -20
View File
@@ -385,6 +385,7 @@ class PostDisplay {
'toolbar' => [
'code' => !isset($settings['comment_code']) || !empty($settings['comment_code']),
'image' => !isset($settings['comment_img']) || !empty($settings['comment_img']),
'link' => !empty($settings['comment_link']),
'upload_img' => function_exists('aksrt_user_can') && aksrt_user_can('upload_comment_image', get_current_user_id()),
],
'like_enabled' => !isset($settings['comment_like_s']) || !empty($settings['comment_like_s']),
@@ -397,31 +398,12 @@ class PostDisplay {
// Extended legacy-parity settings.
'close_comments' => !empty($settings['comment_close_comments']),
'hot_threshold' => max(1, min(999, (int) ($settings['comment_hot_threshold'] ?? 10))),
'quick_s' => !isset($settings['comment_quick_s']) || !empty($settings['comment_quick_s']),
'quick_phrases' => self::parse_comment_quick_phrases((string) ($settings['comment_quick_often'] ?? '')),
'user_url' => !empty($settings['comment_user_url_s']),
'city_s' => !isset($settings['comment_city_s']) || !empty($settings['comment_city_s']),
'city_type' => self::normalize_comment_city_type((string) ($settings['comment_city_type'] ?? 'province_city')),
];
}
/**
* @return array<int,string>
*/
private static function parse_comment_quick_phrases(string $raw): array {
if (trim($raw) === '') {
$raw = "不错,学习了\n感谢分享\n期待更新";
}
$lines = preg_split('/\r\n|\r|\n/', $raw) ?: [];
$out = [];
foreach ($lines as $line) {
$line = trim((string) $line);
if ($line !== '') {
$out[] = $line;
}
}
return array_values(array_unique($out));
}
private static function normalize_comment_city_type(string $type): string {
$type = sanitize_key($type);
// Map legacy legacy pro/city labels.