评论区硬切换实现
This commit is contained in:
1 parent
ed914d2eec
commit
b8ef4d81a4
32 files changed
+946
-1008
No files matched your search
@@ -93,35 +93,33 @@ if (!function_exists('aksrt_comments_build_context')) :
|
||||
? $settings['toolbar']
|
||||
: ['code' => true, 'image' => true];
|
||||
|
||||
$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)),
|
||||
'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()
|
||||
: [],
|
||||
];
|
||||
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)),
|
||||
'empty_text' => (string) ($settings['empty_text'] ?? __('暂无评论,来做第一个评论的人吧~', 'aksrt')),
|
||||
'toolbar' => $toolbar,
|
||||
'upload_enabled' => !empty($toolbar['upload_img']),
|
||||
'link_enabled' => !empty($toolbar['link']),
|
||||
'user_url_enabled' => !empty($settings['user_url']),
|
||||
'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']),
|
||||
'oauth_providers' => class_exists('\AKSRT\Auth\OAuth')
|
||||
? \AKSRT\Auth\OAuth::get_instance()->get_auth_providers_data()
|
||||
: [],
|
||||
];
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -409,7 +407,7 @@ if (!function_exists('aksrt_comments_render_signarea')) :
|
||||
<?php if (get_option('users_can_register')) :
|
||||
$register_url = function_exists('aksrt_get_register_url') ? aksrt_get_register_url() : wp_registration_url();
|
||||
?>
|
||||
<a href="javascript:;" data-register-url="<?php echo esc_url($register_url); ?>" class="signup-loader ml10 but c-yellow padding-lg"><i class="fa fa-fw fa-user-plus mr10" aria-hidden="true"></i><?php esc_html_e('注册', 'aksrt'); ?></a>
|
||||
<a href="javascript:;" data-register-url="<?php echo esc_url($register_url); ?>" class="signup-loader ml10 but c-yellow padding-lg"><?php echo aksrt_get_comment_icon('signup', 'icon mr10'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- 固定 sprite 标记。 ?><?php esc_html_e('注册', 'aksrt'); ?></a>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<?php if (!empty($oauth_providers)) : ?>
|
||||
@@ -448,6 +446,9 @@ if (!function_exists('aksrt_comments_render_form')) :
|
||||
$comment_email = isset($_COOKIE['comment_author_email_' . COOKIEHASH])
|
||||
? sanitize_text_field(wp_unslash((string) $_COOKIE['comment_author_email_' . COOKIEHASH]))
|
||||
: '';
|
||||
$comment_author_url = isset($_COOKIE['comment_author_url_' . COOKIEHASH])
|
||||
? esc_url_raw(wp_unslash((string) $_COOKIE['comment_author_url_' . COOKIEHASH]))
|
||||
: '';
|
||||
$placeholder = (string) $ctx['box_placeholder'];
|
||||
$post_id = (int) get_the_ID();
|
||||
$can_comment = function_exists('aksrt_user_can')
|
||||
@@ -471,13 +472,13 @@ if (!function_exists('aksrt_comments_render_form')) :
|
||||
<div class="fixed-body"></div>
|
||||
<form id="commentform" 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) : ?>
|
||||
<div class="comt-avatar mb10">
|
||||
<?php echo get_avatar($current_user->ID, 60, '', '', ['class' => '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="comt-title text-center flex0 mr10">
|
||||
<?php if ($is_logged_in && $current_user instanceof WP_User) : ?>
|
||||
<div class="comt-avatar mb10">
|
||||
<?php echo get_avatar($current_user->ID, 60, '', '', ['class' => 'avatar']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
<p class="text-ellipsis muted-2-color"><?php echo function_exists('aksrt_render_user_identity_chips') ? aksrt_render_user_identity_chips($current_user->ID, 'comment') : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- chips 内部已转义。 ?><?php echo esc_html($current_user->display_name); ?></p>
|
||||
<?php else : ?>
|
||||
<div class="comt-avatar mb10">
|
||||
<?php echo get_avatar(0, 60, '', '', ['class' => 'avatar']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
@@ -524,6 +525,14 @@ if (!function_exists('aksrt_comments_render_form')) :
|
||||
<div class="abs-right muted-color"><i class="fa fa-fw fa-envelope-o" aria-hidden="true"></i></div>
|
||||
<i class="line-form-line"></i>
|
||||
</li>
|
||||
<?php if (!empty($ctx['user_url_enabled'])) : ?>
|
||||
<li class="line-form">
|
||||
<input type="text" name="url" class="line-form-input" tabindex="3" value="<?php echo esc_attr($comment_author_url); ?>" placeholder="">
|
||||
<div class="scale-placeholder"><?php esc_html_e('博客地址', 'aksrt'); ?></div>
|
||||
<div class="abs-right muted-color"><i class="fa fa-fw fa-link" aria-hidden="true"></i></div>
|
||||
<i class="line-form-line"></i>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
@@ -623,7 +632,7 @@ if (!function_exists('aksrt_comments_render')) :
|
||||
* Compose the full comments surface.
|
||||
*/
|
||||
function aksrt_comments_render(): void {
|
||||
if (post_password_required()) {
|
||||
if (post_password_required() || !comments_open()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -652,12 +661,10 @@ if (!function_exists('aksrt_comments_render')) :
|
||||
</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 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; ?>
|
||||
|
||||
<div id="postcomments">
|
||||
@@ -670,7 +677,7 @@ if (!function_exists('aksrt_comments_render')) :
|
||||
|
||||
if (have_comments()) {
|
||||
aksrt_comments_render_list_items($ctx);
|
||||
} elseif (!post_password_required()) {
|
||||
} else {
|
||||
aksrt_comments_render_empty($ctx);
|
||||
echo '<div class="pagenav hide"><div class="next-page ajax-next"><a href="#"></a></div></div>';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user