351 lines
16 KiB
PHP
351 lines
16 KiB
PHP
<?php
|
|
/**
|
|
* Single resource template.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
get_header();
|
|
|
|
while (have_posts()) :
|
|
the_post();
|
|
|
|
$post_id = get_the_ID();
|
|
$resource_meta = function_exists('aksrt_get_resource_meta') ? aksrt_get_resource_meta($post_id) : aksrt_default_resource_meta();
|
|
$single_settings = function_exists('aksrt_resolve_single_post_display_settings')
|
|
? aksrt_resolve_single_post_display_settings($post_id)
|
|
: [];
|
|
$show_toc = !empty($single_settings['toc_enabled']);
|
|
$show_cover = !empty($single_settings['show_cover']);
|
|
$cover_url = (string) ($single_settings['cover_url'] ?? '');
|
|
$views = isset($resource_meta['view_count']) ? (int) $resource_meta['view_count'] : 0;
|
|
$downloads = isset($resource_meta['download_count']) ? (int) $resource_meta['download_count'] : 0;
|
|
$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;
|
|
$is_liked = function_exists('aksrt_is_post_liked') ? aksrt_is_post_liked($post_id) : false;
|
|
$is_favorited = function_exists('aksrt_is_post_favorited') ? aksrt_is_post_favorited($post_id) : false;
|
|
$word_count = function_exists('aksrt_post_word_count') && !empty($single_settings['word_count_enabled'])
|
|
? aksrt_post_word_count($post_id)
|
|
: 0;
|
|
$reading_minutes = function_exists('aksrt_reading_minutes') && !empty($single_settings['reading_time_enabled'])
|
|
? aksrt_reading_minutes($post_id)
|
|
: 0;
|
|
$author_meta_items = [];
|
|
if (empty($single_settings['hide_time'])) {
|
|
$author_meta_items[] = [
|
|
'icon' => 'far fa-clock',
|
|
'text' => sprintf(__('发布于 %s', 'aksrt'), get_the_date()),
|
|
];
|
|
}
|
|
$author_meta_items[] = [
|
|
'icon' => 'far fa-eye',
|
|
'text' => sprintf(__('浏览 %s', 'aksrt'), function_exists('aksrt_format_number') ? aksrt_format_number($views) : number_format_i18n($views)),
|
|
];
|
|
$author_meta_items[] = [
|
|
'icon' => 'fas fa-download',
|
|
'text' => sprintf(__('下载 %s', 'aksrt'), number_format_i18n($downloads)),
|
|
];
|
|
if ($word_count > 0) {
|
|
$author_meta_items[] = [
|
|
'icon' => 'far fa-file-word',
|
|
'text' => sprintf(__('约 %s 字', 'aksrt'), number_format_i18n($word_count)),
|
|
];
|
|
}
|
|
if ($reading_minutes > 0) {
|
|
$author_meta_items[] = [
|
|
'icon' => 'far fa-hourglass-half',
|
|
'text' => sprintf(_n('约 %d 分钟', '约 %d 分钟', $reading_minutes, 'aksrt'), $reading_minutes),
|
|
];
|
|
}
|
|
|
|
$show_action_card = !empty($single_settings['like_enabled'])
|
|
|| !empty($single_settings['favorite_enabled'])
|
|
|| !empty($single_settings['share_enabled'])
|
|
|| !empty($single_settings['print_enabled'])
|
|
|| !empty($single_settings['pdf_export_enabled']);
|
|
$copyright_text = trim((string) ($single_settings['copyright_text'] ?? ''));
|
|
if ($copyright_text === '') {
|
|
$copyright_text = sprintf(
|
|
/* translators: %s: author display name */
|
|
__('本文由 %s 原创发布,转载请注明出处。', 'aksrt'),
|
|
get_the_author()
|
|
);
|
|
}
|
|
|
|
set_query_var('aksrt_resource_meta', $resource_meta);
|
|
?>
|
|
|
|
<?php if (!empty($single_settings['reading_progress'])) : ?>
|
|
<div id="reading-progress-global" class="reading-progress-bar" role="progressbar" aria-label="<?php esc_attr_e('阅读进度', 'aksrt'); ?>" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"></div>
|
|
<?php endif; ?>
|
|
|
|
<main id="main-content" class="site-main container" tabindex="-1">
|
|
<div class="content-wrap">
|
|
<div class="content-layout">
|
|
<div class="content-layout__primary">
|
|
<?php if (!empty($single_settings['breadcrumbs']) && function_exists('aksrt_breadcrumbs')) : ?>
|
|
<div class="post-breadcrumbs"><?php aksrt_breadcrumbs($single_settings['breadcrumbs_home'] ?? ''); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<article <?php post_class('article main-bg theme-box box-body radius8 main-shadow article-resource'); ?>>
|
|
<a href="#resource-mobile-download" class="resource-mobile-fab" aria-label="<?php esc_attr_e('前往下载区', 'aksrt'); ?>">
|
|
<i class="fas fa-download" aria-hidden="true"></i>
|
|
</a>
|
|
|
|
<?php if ($show_cover && $cover_url !== '') : ?>
|
|
<div class="single-head-cover single-cover graphic imgbox-container">
|
|
<img src="<?php echo esc_url($cover_url); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" class="fit-cover" loading="eager">
|
|
<div class="single-cover__overlay"></div>
|
|
<div class="single-cover__content">
|
|
<h1 class="article-title title-h-left"><?php the_title(); ?></h1>
|
|
<div class="single-metabox cover-meta abs-right">
|
|
<?php foreach ($author_meta_items as $meta_item) : ?>
|
|
<item class="meta-view"><?php if (!empty($meta_item['icon'])) : ?><i class="<?php echo esc_attr($meta_item['icon']); ?>" aria-hidden="true"></i> <?php endif; ?><?php echo esc_html((string) $meta_item['text']); ?></item>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!$show_cover) : ?>
|
|
<div class="article-header theme-box clearfix relative">
|
|
<h1 class="article-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($single_settings['authordesc'])) : ?>
|
|
<?php
|
|
set_query_var('aksrt_author_bar_class', 'article-author-bar');
|
|
set_query_var('aksrt_author_bar_meta_items', $author_meta_items);
|
|
set_query_var('aksrt_author_bar_bio', false);
|
|
set_query_var('aksrt_author_bar_actions', false);
|
|
get_template_part('templates/parts/single-author-bar');
|
|
set_query_var('aksrt_author_bar_class', '');
|
|
set_query_var('aksrt_author_bar_meta_items', []);
|
|
set_query_var('aksrt_author_bar_bio', false);
|
|
set_query_var('aksrt_author_bar_actions', false);
|
|
?>
|
|
<?php endif; ?>
|
|
|
|
<div class="theme-box wp-posts-content"
|
|
data-nav="posts"
|
|
data-aksrt-toc="<?php echo $show_toc ? '1' : '0'; ?>"
|
|
data-aksrt-toc-depth="<?php echo esc_attr((string) ((int) ($single_settings['toc_depth'] ?? 3))); ?>"
|
|
data-aksrt-lightbox="<?php echo !empty($single_settings['lightbox']) ? '1' : '0'; ?>">
|
|
<?php
|
|
the_content();
|
|
wp_link_pages([
|
|
'before' => '<p class="text-center post-nav-links radius8 padding-6">',
|
|
'after' => '</p>',
|
|
]);
|
|
?>
|
|
</div>
|
|
|
|
<div class="article-footer">
|
|
<?php if (!empty($single_settings['copyright_enabled'])) : ?>
|
|
<div class="em09 muted-3-color">
|
|
<div><span>©</span> <?php esc_html_e('版权声明', 'aksrt'); ?></div>
|
|
<div class="posts-copyright"><?php echo esc_html($copyright_text); ?></div>
|
|
</div>
|
|
<?php endif; ?>
|
|
<div class="text-center theme-box muted-3-color box-body separator em09">THE END</div>
|
|
<div class="theme-box article-tags">
|
|
<?php foreach (get_the_category() ?: [] as $cat) : ?>
|
|
<a href="<?php echo esc_url(get_category_link($cat->term_id)); ?>" class="but"><i class="far fa-folder-open" aria-hidden="true"></i> <?php echo esc_html($cat->name); ?></a>
|
|
<?php endforeach; ?>
|
|
<br>
|
|
<?php foreach (get_the_tags() ?: [] as $tag) : ?>
|
|
<a href="<?php echo esc_url(get_tag_link($tag->term_id)); ?>" class="but"># <?php echo esc_html($tag->name); ?></a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($show_action_card) : ?>
|
|
<div class="theme-box box-body radius8 main-shadow">
|
|
<div class="text-center muted-3-color box-body em09"><?php echo esc_html($single_settings['button_toptext'] ?? __('喜欢就支持一下吧', 'aksrt')); ?></div>
|
|
<div class="text-center post-actions">
|
|
<?php if (!empty($single_settings['like_enabled'])) : ?>
|
|
<button type="button" class="action action-like<?php echo $is_liked ? ' is-active' : ''; ?>" id="action-like" data-post-id="<?php echo esc_attr((string) $post_id); ?>" data-initial-active="<?php echo $is_liked ? '1' : '0'; ?>">
|
|
<i class="<?php echo $is_liked ? 'fas' : 'far'; ?> fa-heart" aria-hidden="true"></i>
|
|
<span class="action-btn__count" data-stat-count="likes" data-base-count="<?php echo esc_attr((string) $like_count); ?>"><?php echo esc_html((string) $like_count); ?></span>
|
|
</button>
|
|
<?php endif; ?>
|
|
<?php if (!empty($single_settings['share_enabled'])) : ?>
|
|
<button type="button" class="action action-share" id="action-share-trigger" aria-haspopup="true" aria-expanded="false">
|
|
<i class="fas fa-share-alt" aria-hidden="true"></i>
|
|
<span><?php esc_html_e('分享', 'aksrt'); ?></span>
|
|
</button>
|
|
<?php endif; ?>
|
|
<?php if (!empty($single_settings['favorite_enabled'])) : ?>
|
|
<button type="button" class="action action-favorite<?php echo $is_favorited ? ' is-active' : ''; ?>" id="action-favorite" data-post-id="<?php echo esc_attr((string) $post_id); ?>" data-initial-active="<?php echo $is_favorited ? '1' : '0'; ?>">
|
|
<i class="<?php echo $is_favorited ? 'fas' : 'far'; ?> fa-star" aria-hidden="true"></i>
|
|
<span class="action-btn__count" data-stat-count="favorites" data-base-count="<?php echo esc_attr((string) $favorite_count); ?>"><?php echo esc_html((string) $favorite_count); ?></span>
|
|
</button>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if (!empty($single_settings['share_enabled'])) : ?>
|
|
<div class="share-dropdown" id="share-dropdown" aria-hidden="true">
|
|
<div class="share-dropdown__grid">
|
|
<button type="button" class="share-item" data-platform="qq"><i class="fab fa-qq"></i><span>QQ</span></button>
|
|
<button type="button" class="share-item" data-platform="weibo"><i class="fab fa-weibo"></i><span>微博</span></button>
|
|
<button type="button" class="share-item" data-platform="twitter"><i class="fab fa-x-twitter"></i><span>X</span></button>
|
|
<button type="button" class="share-item" data-platform="wechat"><i class="fab fa-weixin"></i><span>微信</span></button>
|
|
<button type="button" class="share-item" data-platform="copy"><i class="fas fa-link"></i><span><?php esc_html_e('复制链接', 'aksrt'); ?></span></button>
|
|
</div>
|
|
<div id="share-qrcode-box" aria-hidden="true">
|
|
<img id="share-qrcode-image" src="" alt="QR Code">
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="resource-mobile-download-bar" id="resource-mobile-download">
|
|
<?php get_template_part('templates/parts/resource-download-box'); ?>
|
|
</div>
|
|
|
|
<?php if (comments_open() || get_comments_number()) : ?>
|
|
<div class="theme-box box-body radius8 main-shadow comments-card">
|
|
<?php comments_template(); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
$related_resource_query = null;
|
|
$resource_cat_ids = wp_get_post_categories($post_id, ['fields' => 'ids']);
|
|
if (!empty($single_settings['related_enabled']) && !empty($resource_cat_ids)) {
|
|
$post_types = function_exists('aksrt_resource_post_types') ? aksrt_resource_post_types() : ['post'];
|
|
$args = [
|
|
'post_type' => $post_types,
|
|
'posts_per_page' => (int) ($single_settings['related_count'] ?? 6),
|
|
'post__not_in' => [$post_id],
|
|
'category__in' => array_map('intval', $resource_cat_ids),
|
|
'meta_key' => '_aksrt_res_download_count',
|
|
'orderby' => 'meta_value_num',
|
|
'order' => 'DESC',
|
|
'no_found_rows' => true,
|
|
];
|
|
if (!post_type_exists('aksrt_resource')) {
|
|
$args['meta_query'] = [[
|
|
'key' => '_aksrt_is_resource',
|
|
'value' => '1',
|
|
'compare' => '=',
|
|
]];
|
|
}
|
|
$related_resource_query = new WP_Query($args);
|
|
}
|
|
if ($related_resource_query instanceof WP_Query && $related_resource_query->have_posts()) :
|
|
?>
|
|
<section class="resource-related" aria-label="<?php esc_attr_e('相关资源', 'aksrt'); ?>">
|
|
<header class="resource-related__header">
|
|
<h2 class="resource-related__title"><?php esc_html_e('相关资源', 'aksrt'); ?></h2>
|
|
</header>
|
|
<?php
|
|
aksrt_render_post_list($related_resource_query, [
|
|
'context' => 'archive',
|
|
'mode' => 'card',
|
|
'card_style' => 'standard',
|
|
'show_excerpt' => false,
|
|
'wrapper_class' => 'resource-related__grid',
|
|
]);
|
|
wp_reset_postdata();
|
|
?>
|
|
</section>
|
|
<?php endif; ?>
|
|
</article>
|
|
</div>
|
|
|
|
<div class="sidebar aksrt-resource__aside" role="complementary" aria-label="<?php esc_attr_e('侧栏', 'aksrt'); ?>">
|
|
<?php get_template_part('templates/parts/resource-download-box'); ?>
|
|
|
|
<?php if ($show_toc) : ?>
|
|
<div class="posts-nav-box toc-widget" data-title="<?php esc_attr_e('资源目录', 'aksrt'); ?>">
|
|
<ol class="toc-list"></ol>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
$attributes = [];
|
|
if (!empty($resource_meta['version'])) {
|
|
$attributes[__('版本', 'aksrt')] = $resource_meta['version'];
|
|
}
|
|
if (!empty($resource_meta['size'])) {
|
|
$attributes[__('大小', 'aksrt')] = $resource_meta['size'];
|
|
}
|
|
if (!empty($resource_meta['compat'])) {
|
|
$attributes[__('兼容性', 'aksrt')] = $resource_meta['compat'];
|
|
}
|
|
if (!empty($resource_meta['demo_url'])) {
|
|
$attributes[__('演示地址', 'aksrt')] = sprintf(
|
|
'<a href="%s" target="_blank" rel="noopener noreferrer"><i class="fas fa-external-link-alt" aria-hidden="true"></i> %s</a>',
|
|
esc_url($resource_meta['demo_url']),
|
|
__('打开演示', 'aksrt')
|
|
);
|
|
}
|
|
if (!empty($resource_meta['license'])) {
|
|
$attributes[__('授权', 'aksrt')] = $resource_meta['license'];
|
|
}
|
|
if (!empty($attributes)) :
|
|
?>
|
|
<div class="widget widget-card resource-meta-card">
|
|
<h3><?php esc_html_e('资源信息', 'aksrt'); ?></h3>
|
|
<dl class="resource-meta-card__list">
|
|
<?php foreach ($attributes as $key => $value) : ?>
|
|
<div class="resource-meta-card__row">
|
|
<dt><?php echo esc_html($key); ?></dt>
|
|
<dd><?php echo wp_kses_post((string) $value); ?></dd>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</dl>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="widget widget-card resource-guarantee-card">
|
|
<div class="resource-guarantee-card__list">
|
|
<span><i class="fas fa-shield-alt" aria-hidden="true"></i> <?php esc_html_e('安全检测', 'aksrt'); ?></span>
|
|
<span><i class="fas fa-sync-alt" aria-hidden="true"></i> <?php esc_html_e('持续更新', 'aksrt'); ?></span>
|
|
<span><i class="fas fa-headset" aria-hidden="true"></i> <?php esc_html_e('售后支持', 'aksrt'); ?></span>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if (is_active_sidebar('sidebar-article')) : ?>
|
|
<?php dynamic_sidebar('sidebar-article'); ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<?php if ($show_toc) : ?>
|
|
<button type="button" class="toc-float-btn" aria-label="<?php esc_attr_e('打开目录', 'aksrt'); ?>">
|
|
<i class="fas fa-list-ul" aria-hidden="true"></i>
|
|
</button>
|
|
<div class="toc-drawer-overlay"></div>
|
|
<aside class="toc-drawer posts-nav-box" aria-label="<?php esc_attr_e('资源目录', 'aksrt'); ?>">
|
|
<div class="toc-drawer__head">
|
|
<h3><?php esc_html_e('资源目录', 'aksrt'); ?></h3>
|
|
<button type="button" class="toc-drawer__close" aria-label="<?php esc_attr_e('关闭目录', 'aksrt'); ?>">
|
|
<i class="fas fa-times" aria-hidden="true"></i>
|
|
</button>
|
|
</div>
|
|
<ol class="toc-list"></ol>
|
|
</aside>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($single_settings['lightbox'])) : ?>
|
|
<div class="lightbox-overlay" id="lightbox-overlay" role="dialog" aria-modal="true" aria-label="<?php esc_attr_e('图片预览', 'aksrt'); ?>">
|
|
<button type="button" class="lightbox-close" aria-label="<?php esc_attr_e('关闭', 'aksrt'); ?>"><i class="fas fa-times"></i></button>
|
|
<img src="" alt="" class="lightbox-img">
|
|
<div class="lightbox-caption" aria-live="polite"></div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="toast-container" id="toast-container"></div>
|
|
<?php endwhile; ?>
|
|
|
|
<?php
|
|
get_footer();
|