进行了一些小修复
This commit is contained in:
@@ -1,60 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* 前端模板标签:阅读时长、面包屑、评论回调
|
||||
* 前端模板标签:文章展示设置、面包屑与统计辅助
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
defined('ABSPATH') || exit;
|
||||
if (!function_exists('aksrt_reading_minutes')) :
|
||||
/**
|
||||
* 估算文章阅读分钟数
|
||||
*
|
||||
* @param int|null $post_id 文章 ID,默认当前文章
|
||||
* @return int
|
||||
*/
|
||||
function aksrt_reading_minutes($post_id = null) {
|
||||
$post = get_post($post_id);
|
||||
if (!$post) {
|
||||
return 1;
|
||||
}
|
||||
$text = wp_strip_all_tags($post->post_content);
|
||||
$han = 0;
|
||||
if (preg_match_all('/\p{Han}/u', $text, $m)) {
|
||||
$han = count($m[0]);
|
||||
}
|
||||
$words = str_word_count($text) + (int) ceil($han / 2);
|
||||
if ($words < 1) {
|
||||
$words = (int) max(1, strlen($text) / 4);
|
||||
}
|
||||
$minutes = (int) ceil($words / 220);
|
||||
return max(1, $minutes);
|
||||
}
|
||||
endif;
|
||||
if (!function_exists('aksrt_post_word_count')) :
|
||||
/**
|
||||
* Approximate visible word count for single-post meta display.
|
||||
*
|
||||
* @param int|null $post_id Post ID.
|
||||
* @return int
|
||||
*/
|
||||
function aksrt_post_word_count($post_id = null): int {
|
||||
$post = get_post($post_id);
|
||||
if (!($post instanceof WP_Post)) {
|
||||
return 0;
|
||||
}
|
||||
$text = wp_strip_all_tags((string) $post->post_content);
|
||||
$han = 0;
|
||||
if (preg_match_all('/\p{Han}/u', $text, $matches)) {
|
||||
$han = count($matches[0]);
|
||||
}
|
||||
$latin_words = str_word_count($text);
|
||||
$total = $latin_words + $han;
|
||||
if ($total <= 0) {
|
||||
$total = (int) ceil(strlen($text) / 2);
|
||||
}
|
||||
return max(0, $total);
|
||||
}
|
||||
endif;
|
||||
if (!function_exists('aksrt_resolve_single_post_display_settings')) :
|
||||
/**
|
||||
* Resolve single post/resource display settings, including post-meta overrides.
|
||||
@@ -104,8 +54,6 @@ if (!function_exists('aksrt_resolve_single_post_display_settings')) :
|
||||
'yiyan_box' => false,
|
||||
'print_enabled' => true,
|
||||
'pdf_export_enabled' => false,
|
||||
'word_count_enabled' => true,
|
||||
'reading_time_enabled' => true,
|
||||
];
|
||||
// Normalize legacy aliases → canonical render keys (idempotent).
|
||||
if (!array_key_exists('share_enabled', $settings) && array_key_exists('share_s', $settings)) {
|
||||
|
||||
@@ -99,11 +99,9 @@ if (!function_exists('aksrt_get_single_meta_box')) :
|
||||
/**
|
||||
* legacy equivalent.
|
||||
*
|
||||
* @param string $class Extra class on wrapper.
|
||||
* @param string $direction Unused (kept for API parity).
|
||||
* @param int|null $post_id Post ID.
|
||||
*/
|
||||
function aksrt_get_single_meta_box(string $class = 'abs-right', string $direction = 'down', $post_id = null): string {
|
||||
function aksrt_get_single_meta_box($post_id = null): string {
|
||||
if (!is_single() && !is_singular()) {
|
||||
return '';
|
||||
}
|
||||
@@ -128,11 +126,12 @@ if (!function_exists('aksrt_get_single_meta_box')) :
|
||||
}
|
||||
$permalink = get_permalink($post_id);
|
||||
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url($permalink ?: home_url('/'));
|
||||
$menu_id = 'post-drop-meta-menu-' . $post_id;
|
||||
|
||||
$more .= '<div class="clearfix ml6 post-drop-meta">';
|
||||
$more .= '<button type="button" class="but cir post-drop-meta__toggle" aria-haspopup="true" aria-expanded="false" aria-label="' . esc_attr__('更多', 'aksrt') . '">';
|
||||
$more .= '<button type="button" class="but cir post-drop-meta__toggle" aria-haspopup="true" aria-controls="' . esc_attr($menu_id) . '" aria-expanded="false" aria-label="' . esc_attr__('更多', 'aksrt') . '">';
|
||||
$more .= '<i class="fa fas fa-ellipsis-h" aria-hidden="true"></i></button>';
|
||||
$more .= '<div class="post-drop-meta__menu" aria-hidden="true">';
|
||||
$more .= '<div id="' . esc_attr($menu_id) . '" class="post-drop-meta__menu" aria-hidden="true">';
|
||||
if ($edit_link) {
|
||||
$more .= '<a href="' . esc_url($edit_link) . '" class="post-drop-meta__item"><i class="fa fas fa-edit" aria-hidden="true"></i><span>' . esc_html__('编辑文章', 'aksrt') . '</span></a>';
|
||||
}
|
||||
@@ -144,7 +143,7 @@ if (!function_exists('aksrt_get_single_meta_box')) :
|
||||
}
|
||||
$more .= '</div></div>';
|
||||
|
||||
return '<div class="flex ac single-metabox ' . esc_attr($class) . '"><div class="post-metas">' . $meta . '</div>' . $more . '</div>';
|
||||
return '<div class="flex ac single-metabox"><div class="post-metas">' . $meta . '</div>' . $more . '</div>';
|
||||
}
|
||||
endif;
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ if (!function_exists('aksrt_single_render_cover')) :
|
||||
<div class="post-breadcrumbs"><?php echo $crumbs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($meta_box !== '') : ?>
|
||||
<?php echo str_replace('abs-right', 'mb10 ml10 shrink0', $meta_box); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php echo str_replace('single-metabox', 'single-metabox mb10 ml10 shrink0', $meta_box); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<h1 class="article-title">
|
||||
@@ -96,7 +96,7 @@ if (!function_exists('aksrt_single_render_cover')) :
|
||||
. ($crumbs !== '' ? $crumbs : '')
|
||||
. $badge
|
||||
. '</div>'
|
||||
. ($meta_box !== '' ? str_replace('abs-right', 'cover-meta abs-right', $meta_box) : '');
|
||||
. ($meta_box !== '' ? str_replace('single-metabox', 'single-metabox cover-meta abs-right', $meta_box) : '');
|
||||
$slider_html = '';
|
||||
if (function_exists('aksrt_render_slider')) {
|
||||
$slider_html = aksrt_render_slider([
|
||||
@@ -143,7 +143,7 @@ if (!function_exists('aksrt_single_render_cover')) :
|
||||
<?php echo $badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
<?php if ($meta_box !== '') : ?>
|
||||
<?php echo str_replace('abs-right', 'cover-meta abs-right', $meta_box); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php echo str_replace('single-metabox', 'single-metabox cover-meta abs-right', $meta_box); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -174,15 +174,7 @@ if (!function_exists('aksrt_single_render_box_header')) :
|
||||
'show_time' => empty($settings['hide_time']),
|
||||
'meta_html' => empty($ctx['show_cover']) ? (string) ($ctx['meta_box_html'] ?? '') : '',
|
||||
]);
|
||||
$reading_meta = is_array($ctx['meta_items_secondary'] ?? null) ? $ctx['meta_items_secondary'] : [];
|
||||
if ($reading_meta !== []) :
|
||||
?>
|
||||
<div class="article-reading-meta" aria-label="<?php esc_attr_e('阅读信息', 'aksrt'); ?>">
|
||||
<?php foreach ($reading_meta as $item) : ?>
|
||||
<span><i class="<?php echo esc_attr((string) ($item['icon'] ?? 'fa fas fa-file-alt')); ?>" aria-hidden="true"></i><?php echo esc_html((string) ($item['text'] ?? '')); ?></span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
@@ -26,31 +26,12 @@ if (!function_exists('aksrt_single_build_context')) :
|
||||
$comment_count = (int) get_comments_number($post_id);
|
||||
$like_count = function_exists('aksrt_get_post_likes') ? (int) aksrt_get_post_likes($post_id) : 0;
|
||||
$favorite_count = function_exists('aksrt_get_post_favorites') ? (int) aksrt_get_post_favorites($post_id) : 0;
|
||||
$word_count = function_exists('aksrt_post_word_count') && !empty($settings['word_count_enabled'])
|
||||
? aksrt_post_word_count($post_id)
|
||||
: 0;
|
||||
$reading_minutes = function_exists('aksrt_reading_minutes') && !empty($settings['reading_time_enabled'])
|
||||
? aksrt_reading_minutes($post_id)
|
||||
: 0;
|
||||
|
||||
// legacy primary meta = comment/views/likes via meta_box_html.
|
||||
$meta_items = [];
|
||||
$meta_box_html = function_exists('aksrt_get_single_meta_box')
|
||||
? aksrt_get_single_meta_box('abs-right', 'down', $post_id)
|
||||
? aksrt_get_single_meta_box($post_id)
|
||||
: '';
|
||||
$meta_items_secondary = [];
|
||||
if ($word_count > 0) {
|
||||
$meta_items_secondary[] = [
|
||||
'icon' => 'fa fas fa-file-word',
|
||||
'text' => sprintf(__('约 %s 字', 'aksrt'), number_format_i18n($word_count)),
|
||||
];
|
||||
}
|
||||
if ($reading_minutes > 0) {
|
||||
$meta_items_secondary[] = [
|
||||
'icon' => 'fa fas fa-hourglass',
|
||||
'text' => sprintf(_n('约 %d 分钟', '约 %d 分钟', $reading_minutes, 'aksrt'), $reading_minutes),
|
||||
];
|
||||
}
|
||||
|
||||
$copyright = trim((string) ($settings['copyright_text'] ?? ''));
|
||||
if ($copyright === '') {
|
||||
@@ -121,7 +102,6 @@ if (!function_exists('aksrt_single_build_context')) :
|
||||
'video_episodes' => is_array($settings['video_episodes'] ?? null) ? array_values($settings['video_episodes']) : [],
|
||||
'video_poster' => (string) ($settings['video_poster'] ?? ''),
|
||||
'meta_items' => $meta_items,
|
||||
'meta_items_secondary' => $meta_items_secondary,
|
||||
'meta_box_html' => $meta_box_html,
|
||||
'title_html' => function_exists('aksrt_get_single_title_html') ? aksrt_get_single_title_html($post_id) : esc_html(get_the_title($post_id)),
|
||||
'allow_view' => $allow_view,
|
||||
|
||||
Reference in New Issue
Block a user