feat(comments): full 1:1 zibll comment kernel for posts, forum, shop

Extract shared comment helpers (content/item/form/geo/actions), port GIF
[g=] smilies + FixedInput/moveForm UX, wire close_comments/city/quick
settings, REST comment get, and align product review chrome with zibll.
This commit is contained in:
kate522 committed 2026-07-18 15:51:47 +08:00
1 parent 9edd39c33d
commit 276a2891ba
116 files changed
+2658 -1848

No files matched your search

+52
View File
@@ -92,6 +92,51 @@ class CommentActions {
'active' => ['required' => false, 'type' => 'boolean'],
],
]);
register_rest_route('aksrt/v1', '/comment/get', [
'methods' => \WP_REST_Server::READABLE,
'callback' => [$this, 'get_comment'],
'permission_callback' => [$this, 'check_get_permission'],
'args' => [
'comment_id' => ['required' => true, 'type' => 'integer', 'sanitize_callback' => 'absint'],
],
]);
}
/**
* Permission: can load raw content for edit?
*/
public function check_get_permission(\WP_REST_Request $request): bool {
$comment_id = (int) $request->get_param('comment_id');
if ($comment_id <= 0 || !is_user_logged_in()) {
return false;
}
$perms = $this->permissions($comment_id);
return !empty($perms['can_edit']);
}
/**
* Return raw comment content for moveForm edit.
*/
public function get_comment(\WP_REST_Request $request): \WP_REST_Response {
$comment_id = (int) $request->get_param('comment_id');
$comment = get_comment($comment_id);
if (!$comment) {
return new \WP_REST_Response([
'success' => false,
'code' => 'comment_not_found',
'message' => __('评论不存在。', 'aksrt'),
], 404);
}
return new \WP_REST_Response([
'success' => true,
'content' => (string) $comment->comment_content,
'data' => [
'content' => (string) $comment->comment_content,
'comment_id' => $comment_id,
'parent' => (int) $comment->comment_parent,
],
]);
}
/**
@@ -193,6 +238,13 @@ class CommentActions {
$params = [];
}
$edit_id = absint($params['edit_comment_ID'] ?? $params['edit_comment_id'] ?? 0);
if ($edit_id > 0) {
$request->set_param('comment_id', $edit_id);
$request->set_param('content', (string) ($params['comment'] ?? $params['content'] ?? ''));
return $this->edit_comment($request);
}
$post_id = absint($params['comment_post_ID'] ?? $params['post_id'] ?? 0);
$content = isset($params['comment']) ? (string) $params['comment'] : '';
$parent = absint($params['comment_parent'] ?? 0);
+16 -1
View File
@@ -226,7 +226,22 @@ trait ScriptsPart1b {
// Keep aggregator handle for any third-party deps that target it.
$enqueue_module('single-post');
$enqueue_module('post-card'); // 相关推荐使用 post-card 局部样式
$enqueue_module('comments');
// Comments pack (zibll 1:1 discrete files).
$comment_parts = ['comments/shell', 'comments/mobile-item'];
$comment_dep = $deps[0] ?? $core_dep;
foreach ($comment_parts as $part) {
$path = get_template_directory() . '/assets/css/frontend/' . $part . '.css';
if (!file_exists($path)) {
continue;
}
wp_enqueue_style(
'aksrt-' . str_replace('/', '-', $part),
$base_uri . '/assets/css/frontend/' . $part . '.css',
is_string($comment_dep) ? [$comment_dep] : (array) $deps,
filemtime($path) ?: $version
);
}
$enqueue_module('comments'); // aggregator handle for third-party deps
$enqueue_module('widgets');
$enqueue_module('sidebar');
$enqueue_module('breadcrumb');
+22 -7
View File
@@ -116,6 +116,8 @@ trait ScriptsPart1c {
'aksrt-core-slider' => 'slider.js',
'aksrt-core-article' => 'article.js',
'aksrt-core-comments' => 'comments.js',
'aksrt-core-comment-fixed' => 'comment-fixed-input.js',
'aksrt-core-comment-move' => 'comment-move-form.js',
'aksrt-core-pagination' => 'pagination.js',
'aksrt-core-archive' => 'archive.js',
'aksrt-core-footer-tabbar' => 'footer-tabbar.js',
@@ -424,28 +426,38 @@ trait ScriptsPart1c {
}
// Comment toolbar (emoji, code, bold, Ctrl+Enter) — only when the form is open.
if (is_singular() && comments_open()) {
// Comment toolbar (smilie/code/image/quick shortcodes) — post form or forum topic reply.
$load_comment_tools = (is_singular() && comments_open())
|| (is_singular('aksrt_forum_topic') || is_singular('forum_topic'));
if ($load_comment_tools) {
$comment_tools_path = get_template_directory() . '/assets/js/comment-tools.js';
wp_enqueue_script(
'aksrt-comment-tools',
$base_uri . '/assets/js/comment-tools.js',
['aksrt-script'],
['aksrt-script', 'aksrt-core-comment-fixed', 'aksrt-core-comment-move'],
file_exists($comment_tools_path) ? (string) filemtime($comment_tools_path) : $version,
true
);
$comment_tools_css = get_template_directory() . '/assets/css/frontend/comment-tools.css';
if (file_exists($comment_tools_css)) {
wp_enqueue_style(
'aksrt-comment-tools',
$base_uri . '/assets/css/frontend/comment-tools.css',
['aksrt-comments'],
(string) filemtime($comment_tools_css)
);
}
}
// Comment actions client (like / edit / delete / moderate / pin) — load
// wherever comments can exist, including closed-comment posts. Submission
// itself is handled by main.js initCommentSystem().
// Comment actions client (like / edit / delete / moderate / pin).
// Submit path lives in assets/js/core/comments.js (REST).
if (is_singular() && (comments_open() || (int) get_comments_number() > 0)) {
$comment_ajax_path = get_template_directory() . '/assets/js/comment-ajax.js';
if (file_exists($comment_ajax_path)) {
wp_enqueue_script(
'aksrt-comment-ajax',
$base_uri . '/assets/js/comment-ajax.js',
['aksrt-script'],
['aksrt-script', 'aksrt-core-comments'],
(string) filemtime($comment_ajax_path),
true
);
@@ -534,6 +546,9 @@ 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'] ?? []) : [],
'commentSmiliesBase' => function_exists('aksrt_comment_smilies_base_uri') ? aksrt_comment_smilies_base_uri() : (trailingslashit(get_template_directory_uri()) . 'assets/img/smilies/'),
'restUrl' => esc_url_raw(rest_url('aksrt/v1')),
'stickyEnabled' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_list_style_settings()['sticky_enabled'] : true,
'stickyPages' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_list_style_settings()['sticky_pages'] : ['home', 'cat'],
'badgeShow' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_list_style_settings()['badge_show'] : true,