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:
1 parent
9edd39c33d
commit
276a2891ba
116 files changed
+2658
-1848
No files matched your search
+175
-128
@@ -94,31 +94,36 @@ if (!function_exists('aksrt_comments_build_context')) :
|
||||
? $settings['toolbar']
|
||||
: ['smilie' => true, 'code' => true, 'image' => true];
|
||||
|
||||
return [
|
||||
'settings' => $settings,
|
||||
'comment_count' => (int) get_comments_number(),
|
||||
'is_logged_in' => is_user_logged_in(),
|
||||
'current_user' => wp_get_current_user(),
|
||||
'require_login' => !empty($settings['require_login']),
|
||||
'order' => $order,
|
||||
'reverse_comments' => $order === 'newest',
|
||||
'is_hottest' => $order === 'hottest',
|
||||
'author_only' => isset($_GET['aksrt_author_only']) && (int) $_GET['aksrt_author_only'] === 1,
|
||||
'post_author_id' => (int) get_the_author_meta('ID'),
|
||||
'avatar_size' => $avatar_size,
|
||||
'max_depth' => max(1, (int) ($settings['nested_depth'] ?? 3)),
|
||||
'allow_reply' => !empty($settings['allow_reply']),
|
||||
'empty_text' => (string) ($settings['empty_text'] ?? __('暂无评论,来做第一个评论的人吧~', 'aksrt')),
|
||||
'toolbar' => $toolbar,
|
||||
'upload_enabled' => !empty($toolbar['upload_img']),
|
||||
'box_placeholder' => (string) ($settings['box_placeholder'] ?? __('说点什么吧...', 'aksrt')),
|
||||
'submit_text' => (string) ($settings['submit_text'] ?? __('提交评论', 'aksrt')),
|
||||
'title_text' => (string) ($settings['title'] ?? __('评论', 'aksrt')),
|
||||
'corderby_enabled' => !empty($settings['corderby']),
|
||||
'oauth_providers' => class_exists('\AKSRT\Auth\OAuth')
|
||||
? \AKSRT\Auth\OAuth::get_instance()->get_auth_providers_data()
|
||||
: [],
|
||||
];
|
||||
$phrases = is_array($settings['quick_phrases'] ?? null) ? $settings['quick_phrases'] : [];
|
||||
|
||||
return [
|
||||
'settings' => $settings,
|
||||
'comment_count' => (int) get_comments_number(),
|
||||
'is_logged_in' => is_user_logged_in(),
|
||||
'current_user' => wp_get_current_user(),
|
||||
'require_login' => !empty($settings['require_login']),
|
||||
'order' => $order,
|
||||
'reverse_comments' => $order === 'newest',
|
||||
'is_hottest' => $order === 'hottest',
|
||||
'author_only' => isset($_GET['aksrt_author_only']) && (int) $_GET['aksrt_author_only'] === 1,
|
||||
'post_author_id' => (int) get_the_author_meta('ID'),
|
||||
'avatar_size' => $avatar_size,
|
||||
'max_depth' => max(1, (int) ($settings['nested_depth'] ?? 3)),
|
||||
'allow_reply' => !empty($settings['allow_reply']),
|
||||
'empty_text' => (string) ($settings['empty_text'] ?? __('暂无评论,来做第一个评论的人吧~', 'aksrt')),
|
||||
'toolbar' => $toolbar,
|
||||
'upload_enabled' => !empty($toolbar['upload_img']),
|
||||
'box_placeholder' => (string) ($settings['box_placeholder'] ?? __('说点什么吧...', 'aksrt')),
|
||||
'submit_text' => (string) ($settings['submit_text'] ?? __('提交评论', 'aksrt')),
|
||||
'title_text' => (string) ($settings['title'] ?? __('评论', 'aksrt')),
|
||||
'corderby_enabled' => !empty($settings['corderby']),
|
||||
'close_comments' => !empty($settings['close_comments']),
|
||||
'quick_s' => !isset($settings['quick_s']) || !empty($settings['quick_s']),
|
||||
'quick_phrases' => $phrases,
|
||||
'oauth_providers' => class_exists('\AKSRT\Auth\OAuth')
|
||||
? \AKSRT\Auth\OAuth::get_instance()->get_auth_providers_data()
|
||||
: [],
|
||||
];
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -440,73 +445,105 @@ if (!function_exists('aksrt_comments_render_form')) :
|
||||
* @param array<string,mixed> $ctx Comments context.
|
||||
*/
|
||||
function aksrt_comments_render_form(array $ctx): void {
|
||||
$is_logged_in = !empty($ctx['is_logged_in']);
|
||||
$current_user = $ctx['current_user'] ?? null;
|
||||
$avatar_size = (int) $ctx['avatar_size'];
|
||||
$toolbar = is_array($ctx['toolbar'] ?? null) ? $ctx['toolbar'] : [];
|
||||
$upload_enabled = !empty($ctx['upload_enabled']);
|
||||
?>
|
||||
<div id="respond" class="comment-respond mobile-fixed">
|
||||
<form id="commentform" class="comment-form" method="post" action="<?php echo esc_url(site_url('/wp-comments-post.php')); ?>">
|
||||
<div class="fixed-body">
|
||||
<div class="comment-form__inner">
|
||||
<div class="comment-form__avatar">
|
||||
$is_logged_in = !empty($ctx['is_logged_in']);
|
||||
$current_user = $ctx['current_user'] ?? null;
|
||||
$avatar_size = max(40, (int) $ctx['avatar_size']);
|
||||
$require_name_email = (bool) get_option('require_name_email');
|
||||
$comment_author = isset($_COOKIE['comment_author_' . COOKIEHASH])
|
||||
? sanitize_text_field(wp_unslash((string) $_COOKIE['comment_author_' . COOKIEHASH]))
|
||||
: '';
|
||||
$comment_email = isset($_COOKIE['comment_author_email_' . COOKIEHASH])
|
||||
? sanitize_text_field(wp_unslash((string) $_COOKIE['comment_author_email_' . COOKIEHASH]))
|
||||
: '';
|
||||
$placeholder = (string) $ctx['box_placeholder'];
|
||||
|
||||
if (function_exists('aksrt_get_comment_virtual_input_html')) {
|
||||
echo aksrt_get_comment_virtual_input_html($placeholder, '#respond'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
?>
|
||||
<div id="respond" class="comment-respond mobile-fixed">
|
||||
<div class="fixed-body"></div>
|
||||
<form id="commentform" class="comment-form" method="post" action="<?php echo esc_url(site_url('/wp-comments-post.php')); ?>">
|
||||
<div class="flex ac">
|
||||
<div class="comt-title text-center flex0 mr10">
|
||||
<?php if ($is_logged_in && $current_user instanceof WP_User) : ?>
|
||||
<img src="<?php echo esc_url(get_avatar_url($current_user->ID, ['size' => $avatar_size])); ?>" alt="" width="<?php echo esc_attr((string) $avatar_size); ?>" height="<?php echo esc_attr((string) $avatar_size); ?>" class="avatar-img comt-avatar">
|
||||
<div class="comt-avatar mb10">
|
||||
<?php echo get_avatar($current_user->ID, $avatar_size, '', '', ['class' => 'avatar-img comt-avatar']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
<p class="text-ellipsis muted-2-color"><?php echo esc_html($current_user->display_name); ?></p>
|
||||
<?php else : ?>
|
||||
<div class="comment-form__avatar-placeholder"><i class="fas fa-user"></i></div>
|
||||
<div class="comt-avatar mb10">
|
||||
<?php echo get_avatar(0, $avatar_size, '', '', ['class' => 'avatar-img comt-avatar']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
<p data-toggle-class="open" data-target="#comment-user-info" title="<?php esc_attr_e('填写用户信息', 'aksrt'); ?>">
|
||||
<?php echo $comment_author !== '' ? esc_html($comment_author) : esc_html__('昵称', 'aksrt'); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="grow1 comt-box">
|
||||
<div class="comt-tips" id="comment-reply-info" style="display:none;">
|
||||
<span class="comt-tips-left comment-form__reply-text"></span>
|
||||
<span class="comt-tips-right"><a href="javascript:;" id="cancel-comment-reply-link" class="comment-form__cancel-reply"><i class="fas fa-times"></i> <?php esc_html_e('取消', 'aksrt'); ?></a></span>
|
||||
</div>
|
||||
<textarea id="comment" name="comment" class="form-control grin comt-textarea" rows="2" placeholder="<?php echo esc_attr((string) $ctx['box_placeholder']); ?>" required></textarea>
|
||||
<div class="comt-ctrl">
|
||||
<div class="comment-toolbar" role="toolbar" aria-label="<?php esc_attr_e('评论工具栏', 'aksrt'); ?>">
|
||||
<button type="button" class="comment-toolbar__btn"<?php echo empty($toolbar['smilie']) ? ' hidden' : ''; ?> title="<?php esc_attr_e('表情', 'aksrt'); ?>" data-toolbar-action="emoji"><i class="far fa-smile"></i></button>
|
||||
<button type="button" class="comment-toolbar__btn"<?php echo empty($toolbar['code']) ? ' hidden' : ''; ?> title="<?php esc_attr_e('插入代码', 'aksrt'); ?>" data-toolbar-action="code"><i class="fas fa-code"></i></button>
|
||||
<button type="button" class="comment-toolbar__btn"<?php echo empty($toolbar['image']) ? ' hidden' : ''; ?> title="<?php esc_attr_e('图片', 'aksrt'); ?>" data-toolbar-action="image"><i class="fas fa-image"></i></button>
|
||||
<button type="button" class="comment-toolbar__btn"<?php echo $upload_enabled ? '' : ' hidden'; ?> title="<?php esc_attr_e('上传图片', 'aksrt'); ?>" data-toolbar-action="upload-image"><i class="fas fa-cloud-upload-alt"></i></button>
|
||||
<button type="button" class="comment-toolbar__btn" title="<?php esc_attr_e('快捷回复', 'aksrt'); ?>" data-toolbar-action="quick-reply"><i class="fas fa-bolt"></i></button>
|
||||
</div>
|
||||
<div class="comment-form__submit-area">
|
||||
<?php if (!$is_logged_in) : ?>
|
||||
<div class="comment-form__guest">
|
||||
<button type="button" class="comment-form__guest-toggle muted-color em09" data-aksrt-guest-toggle aria-expanded="false">
|
||||
<i class="fa fa-user-edit em09" aria-hidden="true"></i> <?php esc_html_e('填写昵称邮箱', 'aksrt'); ?>
|
||||
</button>
|
||||
<div class="comment-form__guest-fields" data-aksrt-guest-fields hidden>
|
||||
<input type="text" name="author" class="form-control form-control-sm comment-form__guest-field" placeholder="<?php esc_attr_e('昵称', 'aksrt'); ?>" required>
|
||||
<input type="email" name="email" class="form-control form-control-sm comment-form__guest-field" placeholder="<?php esc_attr_e('邮箱', 'aksrt'); ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<button type="submit" class="btn btn-primary btn-sm comment-form__submit" id="comment-submit">
|
||||
<i class="fas fa-paper-plane" aria-hidden="true"></i>
|
||||
<?php echo esc_html((string) $ctx['submit_text']); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="comt-box grow1">
|
||||
<div class="action-text mb10 em09 muted-2-color" id="comment-reply-info" style="display:none;"></div>
|
||||
<textarea placeholder="<?php echo esc_attr($placeholder); ?>" autoheight="true" maxheight="188" class="form-control grin comt-textarea" name="comment" id="comment" cols="100%" rows="4" tabindex="1" required></textarea>
|
||||
<?php if (function_exists('aksrt_is_captcha_enabled_for') && function_exists('aksrt_render_captcha') && aksrt_is_captcha_enabled_for('comment')) : ?>
|
||||
<div class="comment-form__captcha">
|
||||
<?php aksrt_render_captcha('comment'); ?>
|
||||
</div>
|
||||
<div class="comment-form__captcha" style="width:230px;margin-top:8px;"><?php aksrt_render_captcha('comment'); ?></div>
|
||||
<?php endif; ?>
|
||||
<div class="comt-ctrl relative">
|
||||
<div class="comt-tips">
|
||||
<?php comment_id_fields(); ?>
|
||||
<?php wp_nonce_field('aksrt_comment_nonce', '_aksrt_comment_nonce'); ?>
|
||||
<input type="hidden" name="comment_post_ID" value="<?php echo esc_attr((string) get_the_ID()); ?>">
|
||||
<?php do_action('comment_form', get_the_ID()); ?>
|
||||
</div>
|
||||
<div class="comt-tips-right pull-right">
|
||||
<a class="but c-red" id="cancel-comment-reply-link" href="javascript:;" style="display:none;"><?php esc_html_e('取消', 'aksrt'); ?></a>
|
||||
<button class="but c-blue pw-1em input-expand-submit comment-send comment-form__submit" name="submit" id="submit" type="submit" tabindex="5"><?php echo esc_html((string) $ctx['submit_text']); ?></button>
|
||||
</div>
|
||||
<div class="comt-tips-left">
|
||||
<?php if (!$is_logged_in) :
|
||||
$req_mark = $require_name_email ? '(' . __('必填', 'aksrt') . ')' : '';
|
||||
?>
|
||||
<span class="dropup relative" id="comment-user-info"<?php echo $require_name_email ? ' require_name_email="true"' : ''; ?>>
|
||||
<a class="but mr6" data-toggle-class="open" data-target="#comment-user-info" href="javascript:;"><i class="fa fa-fw fa-user" aria-hidden="true"></i><span class="hide-sm"><?php esc_html_e('昵称', 'aksrt'); ?></span></a>
|
||||
<div class="dropdown-menu box-body" style="width:250px;">
|
||||
<div class="mb20">
|
||||
<p><?php esc_html_e('请填写用户信息:', 'aksrt'); ?></p>
|
||||
<ul>
|
||||
<li class="line-form mb10">
|
||||
<input type="text" name="author" class="line-form-input" tabindex="1" value="<?php echo esc_attr($comment_author); ?>" placeholder="" <?php echo $require_name_email ? 'required' : ''; ?> />
|
||||
<div class="scale-placeholder"><?php echo esc_html__('昵称', 'aksrt') . esc_html($req_mark); ?></div>
|
||||
</li>
|
||||
<li class="line-form">
|
||||
<input type="email" name="email" class="line-form-input" tabindex="2" value="<?php echo esc_attr($comment_email); ?>" placeholder="" <?php echo $require_name_email ? 'required' : ''; ?> />
|
||||
<div class="scale-placeholder"><?php echo esc_html__('邮箱', 'aksrt') . esc_html($req_mark); ?></div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
$oauth = is_array($ctx['oauth_providers'] ?? null) ? $ctx['oauth_providers'] : [];
|
||||
if (!empty($oauth)) :
|
||||
?>
|
||||
<div class="comment-signarea__oauth flex ac" style="flex-wrap:wrap;gap:6px;">
|
||||
<?php foreach ($oauth as $provider) :
|
||||
$label = (string) ($provider['label'] ?? $provider['name'] ?? '');
|
||||
$url = (string) ($provider['url'] ?? '#');
|
||||
?>
|
||||
<a href="<?php echo esc_url($url); ?>" class="but hollow social-login-item"><?php echo esc_html($label); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if (function_exists('aksrt_render_comment_expand_toolbar')) { aksrt_render_comment_expand_toolbar($ctx); } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
|
||||
<?php comment_id_fields(); ?>
|
||||
<?php wp_nonce_field('aksrt_comment_nonce', '_aksrt_comment_nonce'); ?>
|
||||
<input type="hidden" name="comment_post_ID" value="<?php echo esc_attr((string) get_the_ID()); ?>">
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_comments_render_filter')) :
|
||||
/**
|
||||
@@ -612,55 +649,65 @@ if (!function_exists('aksrt_comments_render')) :
|
||||
* Compose the full comments surface.
|
||||
*/
|
||||
function aksrt_comments_render(): void {
|
||||
if (post_password_required()) {
|
||||
return;
|
||||
}
|
||||
if (post_password_required()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ctx = aksrt_comments_build_context();
|
||||
if (!empty($ctx['is_hottest'])) {
|
||||
aksrt_comments_apply_hottest_order();
|
||||
}
|
||||
$ctx = aksrt_comments_build_context();
|
||||
if (!empty($ctx['close_comments'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep callback/pagination contracts that still read these query vars.
|
||||
set_query_var('aksrt_comment_order', (string) $ctx['order']);
|
||||
set_query_var('aksrt_comment_settings', $ctx['settings']);
|
||||
if (!empty($ctx['is_hottest'])) {
|
||||
aksrt_comments_apply_hottest_order();
|
||||
}
|
||||
|
||||
$avatar_size = (int) $ctx['avatar_size'];
|
||||
?>
|
||||
<div class="theme-box" id="comments" style="<?php echo esc_attr('--aksrt-comment-avatar:' . $avatar_size . 'px;--aksrt-comment-avatar-form:' . max(40, $avatar_size) . 'px;--aksrt-comment-indent:' . $avatar_size . 'px;'); ?>">
|
||||
<div class="box-body notop">
|
||||
<div class="title-theme">
|
||||
<?php echo esc_html((string) $ctx['title_text']); ?>
|
||||
<small class="comments-count"><?php echo esc_html(sprintf(__('共 %d 条', 'aksrt'), (int) $ctx['comment_count'])); ?></small>
|
||||
set_query_var('aksrt_comment_order', (string) $ctx['order']);
|
||||
set_query_var('aksrt_comment_settings', $ctx['settings']);
|
||||
|
||||
$avatar_size = max(45, (int) $ctx['avatar_size']);
|
||||
$count = (int) $ctx['comment_count'];
|
||||
$count_label = $count > 0
|
||||
? sprintf(__('共%s条', 'aksrt'), (string) $count)
|
||||
: __('抢沙发', 'aksrt');
|
||||
?>
|
||||
<div class="theme-box" id="comments" style="<?php echo esc_attr('--aksrt-comment-avatar:' . $avatar_size . 'px;--aksrt-comment-avatar-form:' . $avatar_size . 'px;--aksrt-comment-indent:86px;'); ?>">
|
||||
<div class="box-body notop">
|
||||
<div class="title-theme">
|
||||
<?php echo esc_html((string) $ctx['title_text']); ?>
|
||||
<small class="comments-count"><?php echo esc_html($count_label); ?></small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="no_webshot main-bg theme-box box-body radius8 main-shadow">
|
||||
<?php if (comments_open()) : ?>
|
||||
<?php if (!empty($ctx['require_login']) && empty($ctx['is_logged_in'])) : ?>
|
||||
<?php aksrt_comments_render_signarea($ctx); ?>
|
||||
<?php else : ?>
|
||||
<?php aksrt_comments_render_form($ctx); ?>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
$show_filter = !empty($ctx['corderby_enabled']) && ($count > 0 || !empty($ctx['author_only']) || have_comments());
|
||||
if ($show_filter) {
|
||||
aksrt_comments_render_filter($ctx);
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if (have_comments()) : ?>
|
||||
<?php aksrt_comments_render_list($ctx); ?>
|
||||
<?php elseif (!post_password_required()) : ?>
|
||||
<?php aksrt_comments_render_empty($ctx); ?>
|
||||
<div class="pagenav hide"><div class="next-page ajax-next"><a href="#"></a></div></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!comments_open() && $count && post_type_supports(get_post_type(), 'comments')) : ?>
|
||||
<p class="comments-closed separator text-muted em12"><?php esc_html_e('评论已关闭。', 'aksrt'); ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (comments_open()) : ?>
|
||||
<?php if (!empty($ctx['require_login']) && empty($ctx['is_logged_in'])) : ?>
|
||||
<?php aksrt_comments_render_signarea($ctx); ?>
|
||||
<?php else : ?>
|
||||
<?php aksrt_comments_render_form($ctx); ?>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
// Keep filter visible under author-only empty results.
|
||||
$show_filter = !empty($ctx['corderby_enabled']) && ((int) $ctx['comment_count'] > 0 || !empty($ctx['author_only']) || have_comments());
|
||||
if ($show_filter) {
|
||||
aksrt_comments_render_filter($ctx);
|
||||
}
|
||||
?>
|
||||
}
|
||||
endif;
|
||||
|
||||
<?php if (have_comments()) : ?>
|
||||
<?php aksrt_comments_render_list($ctx); ?>
|
||||
<?php elseif (!post_password_required()) : ?>
|
||||
<?php aksrt_comments_render_empty($ctx); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!comments_open() && get_comments_number() && post_type_supports(get_post_type(), 'comments')) : ?>
|
||||
<p class="comments-closed"><?php esc_html_e('评论已关闭。', 'aksrt'); ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
Reference in new issue
Block a user