修复了一些小问题
This commit is contained in:
@@ -300,182 +300,55 @@ endif;
|
||||
|
||||
if (!function_exists('aksrt_single_render_author_card')) :
|
||||
/**
|
||||
* Compact author card used in the after-box stack.
|
||||
* After-article author card (legacy zib_get_user_card_box parity:
|
||||
* show_button=false / show_img_bg=false / class="author").
|
||||
*
|
||||
* @param array<string,mixed> $ctx Single context.
|
||||
*/
|
||||
function aksrt_single_render_author_card(array $ctx): void {
|
||||
$author_id = (int) get_the_author_meta('ID');
|
||||
if ($author_id <= 0) {
|
||||
return;
|
||||
}
|
||||
$author_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($author_id) : get_author_posts_url($author_id);
|
||||
$author_name = get_the_author();
|
||||
$bio = function_exists('aksrt_get_user_description') ? aksrt_get_user_description($author_id) : trim((string) get_the_author_meta('description'));
|
||||
$name_html = function_exists('aksrt_get_user_name')
|
||||
? aksrt_get_user_name([
|
||||
'id' => $author_id,
|
||||
'class' => 'user-name flex jc ac',
|
||||
'vip' => true,
|
||||
'medal' => true,
|
||||
'auth' => true,
|
||||
'level' => true,
|
||||
'follow' => false,
|
||||
])
|
||||
: '';
|
||||
$identity_chips = ($name_html === '' && function_exists('aksrt_render_user_identity_chips'))
|
||||
? aksrt_render_user_identity_chips($author_id, 'card')
|
||||
: '';
|
||||
$avatar = function_exists('aksrt_get_avatar_html')
|
||||
? aksrt_get_avatar_html($author_id, 80, ['class' => 'avatar avatar-lg'])
|
||||
: get_avatar($author_id, 80, '', esc_attr($author_name), ['class' => 'avatar avatar-lg']);
|
||||
$page_s = class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_post_page_settings')
|
||||
? \AKSRT\Settings\Settings::get_post_page_settings()
|
||||
: [];
|
||||
$card_limit = max(0, min(12, (int) ($page_s['author_card_limit'] ?? 6)));
|
||||
$card_orderby = sanitize_key((string) ($page_s['author_card_orderby'] ?? 'views'));
|
||||
$card_style = sanitize_key((string) ($page_s['author_card_style'] ?? 'card'));
|
||||
$recent = [];
|
||||
if ($card_limit > 0) {
|
||||
$q = [
|
||||
'author' => $author_id,
|
||||
'post_type' => 'post',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => $card_limit,
|
||||
'ignore_sticky_posts' => true,
|
||||
'no_found_rows' => true,
|
||||
];
|
||||
$cur = get_the_ID();
|
||||
if ($cur) {
|
||||
$q['post__not_in'] = [(int) $cur];
|
||||
}
|
||||
if ($card_orderby === 'views') {
|
||||
$q['meta_query'] = [
|
||||
'relation' => 'OR',
|
||||
'views_value' => [
|
||||
'key' => 'aksrt_post_views',
|
||||
'compare' => 'EXISTS',
|
||||
'type' => 'NUMERIC',
|
||||
],
|
||||
'views_missing' => [
|
||||
'key' => 'aksrt_post_views',
|
||||
'compare' => 'NOT EXISTS',
|
||||
],
|
||||
];
|
||||
$q['orderby'] = ['views_value' => 'DESC', 'date' => 'DESC'];
|
||||
} elseif ($card_orderby === 'comment_count') {
|
||||
$q['orderby'] = 'comment_count';
|
||||
$q['order'] = 'DESC';
|
||||
} elseif ($card_orderby === 'modified') {
|
||||
$q['orderby'] = 'modified';
|
||||
$q['order'] = 'DESC';
|
||||
} else {
|
||||
$q['orderby'] = 'date';
|
||||
$q['order'] = 'DESC';
|
||||
}
|
||||
$recent = get_posts($q);
|
||||
}
|
||||
$is_self = is_user_logged_in() && get_current_user_id() === $author_id;
|
||||
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
|
||||
$aksrt_post_settings = class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_post_page_settings')
|
||||
? \AKSRT\Settings\Settings::get_post_page_settings()
|
||||
: [];
|
||||
$rewards_on = !empty($aksrt_post_settings['rewards_enabled'])
|
||||
|| !empty($aksrt_post_settings['post_rewards_enabled'])
|
||||
|| !empty($aksrt_post_settings['post_rewards_s']);
|
||||
?>
|
||||
<div class="user-card author aksrt-panel">
|
||||
<div class="card-content mt10 relative">
|
||||
<div class="user-content">
|
||||
<div class="user-avatar"><?php echo $avatar; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
||||
<div class="user-info mt20 mb10">
|
||||
<?php if ($name_html !== '') : ?>
|
||||
<?php echo $name_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php else : ?>
|
||||
<div class="user-name flex jc ac">
|
||||
<a class="display-name" href="<?php echo esc_url($author_url); ?>"><?php echo esc_html($author_name); ?></a>
|
||||
<?php if ($identity_chips !== '') : ?>
|
||||
<?php echo $identity_chips; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($bio !== '') : ?>
|
||||
<div class="user-desc mt10 muted-2-color em09"><?php echo esc_html($bio); ?></div>
|
||||
<?php endif; ?>
|
||||
<div class="user-btns mt20">
|
||||
<?php if ($is_self) : ?>
|
||||
<?php
|
||||
$submit = function_exists('aksrt_get_new_post_url')
|
||||
? (string) aksrt_get_new_post_url()
|
||||
: (function_exists('aksrt_get_page_url_by_template')
|
||||
? (string) aksrt_get_page_url_by_template('templates/pages/page-submit.php')
|
||||
: '');
|
||||
$center = function_exists('aksrt_get_user_center_url')
|
||||
? (string) aksrt_get_user_center_url()
|
||||
: $author_url;
|
||||
if ($submit !== '') :
|
||||
?>
|
||||
<a class="but pw-1em mr6 jb-pink" href="<?php echo esc_url($submit); ?>"><?php esc_html_e('发布文章', 'aksrt'); ?></a>
|
||||
<?php endif; ?>
|
||||
<a class="but pw-1em mr6 jb-blue" href="<?php echo esc_url($center); ?>"><?php esc_html_e('用户中心', 'aksrt'); ?></a>
|
||||
<?php else : ?>
|
||||
<?php if (is_user_logged_in()) : ?>
|
||||
<button type="button" class="but pw-1em mr6 c-red follow" data-aksrt-follow="<?php echo (int) $author_id; ?>">
|
||||
<i class="fa fas fa-heart em09" aria-hidden="true"></i> <span><?php esc_html_e('关注', 'aksrt'); ?></span>
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<a href="<?php echo esc_url($login_url); ?>" class="but pw-1em mr6 c-red follow">
|
||||
<i class="fa fas fa-heart em09" aria-hidden="true"></i> <span><?php esc_html_e('关注', 'aksrt'); ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
$tip = function_exists('aksrt_get_rewards_button') ? aksrt_get_rewards_button($author_id, 'but pw-1em mr6 c-yellow', get_the_ID()) : '';
|
||||
if ($tip !== '') {
|
||||
echo $tip; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
if (function_exists('aksrt_render_rewards_modal_for_user')) {
|
||||
aksrt_render_rewards_modal_for_user($author_id, get_the_ID());
|
||||
}
|
||||
}
|
||||
?>
|
||||
<a class="but pw-1em mr6 jb-blue" href="<?php echo esc_url($author_url); ?>"><?php esc_html_e('个人主页', 'aksrt'); ?></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!empty($recent)) : ?>
|
||||
<div class="user-card-posts mt10">
|
||||
<?php if ($card_style === 'card') : ?>
|
||||
<div class="more-posts-mini flex hh">
|
||||
<?php foreach ($recent as $rp) : ?>
|
||||
<?php if ($rp instanceof WP_Post) :
|
||||
$thumb = get_the_post_thumbnail_url($rp, 'medium');
|
||||
?>
|
||||
<a class="item mr10 mb10" href="<?php echo esc_url(get_permalink($rp)); ?>" style="display:block;width:46%;">
|
||||
<?php if ($thumb) : ?>
|
||||
<img<?php echo aksrt_get_lazy_attr('lazy_posts_thumb', (string) $thumb, 'fit-cover radius8'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="" decoding="async" style="width:100%;aspect-ratio:16/10;object-fit:cover;">
|
||||
<?php endif; ?>
|
||||
<div class="em09 mt6 text-ellipsis"><?php echo esc_html(get_the_title($rp)); ?></div>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<ul class="no-thumb">
|
||||
<?php foreach ($recent as $rp) : ?>
|
||||
<?php if ($rp instanceof WP_Post) : ?>
|
||||
<li><a class="icon-circle" href="<?php echo esc_url(get_permalink($rp)); ?>"><?php echo esc_html(get_the_title($rp)); ?></a></li>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="user-card-posts mt10 muted-2-color em09 text-center"><?php esc_html_e('暂无更多文章', 'aksrt'); ?></div>
|
||||
<?php endif;
|
||||
?> </div>
|
||||
</div>
|
||||
<?php
|
||||
$author_id = (int) get_the_author_meta('ID');
|
||||
if ($author_id <= 0) {
|
||||
return;
|
||||
}
|
||||
$settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : [];
|
||||
|
||||
$avatar_box = aksrt_get_avatar_box($author_id, 'avatar-img avatar-lg');
|
||||
$name_html = aksrt_get_user_name([
|
||||
'id' => $author_id,
|
||||
'class' => 'flex1 flex ac',
|
||||
'vip' => false,
|
||||
'medal' => true,
|
||||
'auth' => true,
|
||||
'level' => true,
|
||||
'follow' => true,
|
||||
]);
|
||||
$badges = aksrt_get_user_badges($author_id);
|
||||
$desc = aksrt_get_user_description($author_id);
|
||||
$card_style = sanitize_key((string) ($settings['author_card_style'] ?? 'card')) === 'card' ? 'card' : 'mini';
|
||||
$posts_html = aksrt_render_user_card_posts([
|
||||
'user_id' => $author_id,
|
||||
'limit' => max(0, min(12, (int) ($settings['author_card_limit'] ?? 6))),
|
||||
'orderby' => sanitize_key((string) ($settings['author_card_orderby'] ?? 'views')),
|
||||
'post_type' => 'post',
|
||||
'post_style' => $card_style,
|
||||
'exclude' => (int) get_the_ID(),
|
||||
]);
|
||||
?>
|
||||
<div class="user-card zib-widget author">
|
||||
<div class="card-content mt10 relative">
|
||||
<div class="user-content">
|
||||
<div class="user-avatar"><?php echo $avatar_box; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
||||
<div class="user-info mt20 mb10">
|
||||
<div class="user-name flex jc"><?php echo $name_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
||||
<div class="author-tag mt10 mini-scrollbar"><?php echo $badges; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
||||
<div class="user-desc mt10 muted-2-color em09"><?php echo esc_html($desc); ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php echo $posts_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
@@ -534,7 +407,8 @@ endif;
|
||||
|
||||
if (!function_exists('aksrt_single_related_query_args')) :
|
||||
/**
|
||||
* Build related-posts WP_Query args (legacy-like multi-tax OR + orderby).
|
||||
* Build related-posts WP_Query args (legacy zib_posts_related parity:
|
||||
* category/topics/tag OR-terms, no current-post exclusion, meta orderby).
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
* @param array<string,mixed> $settings Single display settings.
|
||||
@@ -548,36 +422,25 @@ if (!function_exists('aksrt_single_related_query_args')) :
|
||||
}
|
||||
|
||||
$args = [
|
||||
'post_type' => get_post_type($post_id) ?: 'post',
|
||||
'post_status' => 'publish',
|
||||
'post__not_in' => [$post_id],
|
||||
'posts_per_page' => $count,
|
||||
'showposts' => $count,
|
||||
'ignore_sticky_posts' => true,
|
||||
'no_found_rows' => true,
|
||||
'post_type' => 'post',
|
||||
'post_status' => 'publish',
|
||||
'order' => 'DESC',
|
||||
'no_found_rows' => true,
|
||||
];
|
||||
|
||||
// legacy: all three term clauses are always present (even when empty).
|
||||
$tax_query = ['relation' => 'OR'];
|
||||
$cat_ids = wp_get_post_terms($post_id, 'category', ['fields' => 'ids']);
|
||||
if (!empty($cat_ids) && !is_wp_error($cat_ids)) {
|
||||
foreach (['category', 'topics', 'post_tag'] as $taxonomy) {
|
||||
$term_ids = wp_get_post_terms($post_id, $taxonomy, ['fields' => 'ids']);
|
||||
$tax_query[] = [
|
||||
'taxonomy' => 'category',
|
||||
'taxonomy' => $taxonomy,
|
||||
'field' => 'term_id',
|
||||
'terms' => array_map('intval', $cat_ids),
|
||||
'terms' => array_map('intval', (array) $term_ids),
|
||||
];
|
||||
}
|
||||
$tag_ids = wp_get_post_terms($post_id, 'post_tag', ['fields' => 'ids']);
|
||||
if (!empty($tag_ids) && !is_wp_error($tag_ids)) {
|
||||
$tax_query[] = [
|
||||
'taxonomy' => 'post_tag',
|
||||
'field' => 'term_id',
|
||||
'terms' => array_map('intval', $tag_ids),
|
||||
];
|
||||
}
|
||||
|
||||
if (count($tax_query) > 1) {
|
||||
$args['tax_query'] = $tax_query;
|
||||
}
|
||||
$args['tax_query'] = $tax_query;
|
||||
|
||||
switch ($orderby) {
|
||||
case 'rand':
|
||||
@@ -591,32 +454,19 @@ if (!function_exists('aksrt_single_related_query_args')) :
|
||||
break;
|
||||
case 'like':
|
||||
$args['meta_key'] = '_aksrt_like_count';
|
||||
$args['orderby'] = ['meta_value_num' => 'DESC', 'date' => 'DESC'];
|
||||
$args['orderby'] = 'meta_value_num';
|
||||
break;
|
||||
case 'favorite':
|
||||
$args['meta_key'] = '_aksrt_favorite_count';
|
||||
$args['orderby'] = ['meta_value_num' => 'DESC', 'date' => 'DESC'];
|
||||
$args['orderby'] = 'meta_value_num';
|
||||
break;
|
||||
case 'comment_count':
|
||||
$args['orderby'] = 'comment_count';
|
||||
break;
|
||||
case 'views':
|
||||
$args['meta_query'] = [
|
||||
'relation' => 'OR',
|
||||
'views_value' => [
|
||||
'key' => 'aksrt_post_views',
|
||||
'compare' => 'EXISTS',
|
||||
'type' => 'NUMERIC',
|
||||
],
|
||||
'views_missing' => [
|
||||
'key' => 'aksrt_post_views',
|
||||
'compare' => 'NOT EXISTS',
|
||||
],
|
||||
];
|
||||
$args['orderby'] = ['views_value' => 'DESC', 'date' => 'DESC'];
|
||||
break;
|
||||
default:
|
||||
$args['orderby'] = 'modified';
|
||||
$args['meta_key'] = 'aksrt_post_views';
|
||||
$args['orderby'] = 'meta_value_num';
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -626,7 +476,7 @@ endif;
|
||||
|
||||
if (!function_exists('aksrt_single_render_related')) :
|
||||
/**
|
||||
* Related posts — legacy-like list + optional shared mini renderer.
|
||||
* Related posts — legacy zib_posts_related parity (img/list/text).
|
||||
*
|
||||
* @param array<string,mixed> $ctx Single context.
|
||||
*/
|
||||
@@ -646,15 +496,7 @@ if (!function_exists('aksrt_single_render_related')) :
|
||||
$style = 'img';
|
||||
}
|
||||
|
||||
$args = function_exists('aksrt_single_related_query_args')
|
||||
? aksrt_single_related_query_args($post_id, $settings)
|
||||
: [
|
||||
'post_type' => get_post_type($post_id) ?: 'post',
|
||||
'post_status' => 'publish',
|
||||
'post__not_in' => [$post_id],
|
||||
'posts_per_page' => max(1, min(12, (int) ($settings['related_count'] ?? 6))),
|
||||
'ignore_sticky_posts' => true,
|
||||
];
|
||||
$args = aksrt_single_related_query_args($post_id, $settings);
|
||||
|
||||
$query = new WP_Query($args);
|
||||
$wrap_class = 'theme-box relates' . ($style === 'img' ? ' relates-thumb' : '');
|
||||
@@ -674,8 +516,8 @@ if (!function_exists('aksrt_single_render_related')) :
|
||||
if ($data) {
|
||||
$posts_html .= aksrt_renderer_mini($data, $mini_cfg);
|
||||
}
|
||||
} elseif ($style === 'img' && function_exists('aksrt_render_related_graphic_card')) {
|
||||
$posts_html .= aksrt_render_related_graphic_card($post);
|
||||
} elseif ($style === 'img') {
|
||||
$posts_html .= '<div class="swiper-slide mr10">' . aksrt_render_graphic_card_post($post) . '</div>';
|
||||
} else {
|
||||
$subtitle = class_exists('\AKSRT\Core\PostMetaBox')
|
||||
? (string) \AKSRT\Core\PostMetaBox::get_meta_value($post->ID, 'subtitle', '')
|
||||
@@ -692,7 +534,7 @@ if (!function_exists('aksrt_single_render_related')) :
|
||||
<div class="box-body notop">
|
||||
<div class="title-theme"><?php echo esc_html($title); ?></div>
|
||||
</div>
|
||||
<div class="aksrt-panel">
|
||||
<div class="zib-widget">
|
||||
<?php if ($style === 'img') : ?>
|
||||
<div class="swiper-container swiper-scroll">
|
||||
<div class="swiper-wrapper"><?php echo $posts_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
||||
|
||||
Reference in New Issue
Block a user