123 lines
4.8 KiB
PHP
123 lines
4.8 KiB
PHP
<?php
|
|
/**
|
|
* Resource Meta Box
|
|
*
|
|
* 统一资源/付费内容侧栏信息表。
|
|
*
|
|
* 由统一 single.php / 资源内容上下文调用:
|
|
* set_query_var('aksrt_resource_meta', $meta);
|
|
* get_template_part('templates/parts/resource-meta-box');
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$meta = get_query_var('aksrt_resource_meta', null);
|
|
if (!is_array($meta)) {
|
|
$meta = function_exists('aksrt_get_resource_meta') ? aksrt_get_resource_meta(get_the_ID()) : null;
|
|
}
|
|
if (!is_array($meta)) return;
|
|
|
|
// 字段定义及显示顺序
|
|
$rows = [
|
|
'version' => __('版本', 'aksrt'),
|
|
'size' => __('大小', 'aksrt'),
|
|
'compat' => __('兼容性', 'aksrt'),
|
|
'license' => __('授权', 'aksrt'),
|
|
];
|
|
|
|
// 至少要有一个非空字段才渲染
|
|
$has_any = false;
|
|
foreach ($rows as $k => $_label) {
|
|
if (!empty($meta[$k])) { $has_any = true; break; }
|
|
}
|
|
$has_demo = !empty($meta['demo_url']);
|
|
$has_downloads = ($meta['download_count'] ?? 0) > 0;
|
|
|
|
if (!$has_any && !$has_demo && !$has_downloads) return;
|
|
?>
|
|
|
|
<aside class="resource-meta-box" aria-label="<?php esc_attr_e('资源信息', 'aksrt'); ?>">
|
|
<header class="resource-meta-box__header">
|
|
<h2 class="resource-meta-box__title"><?php esc_html_e('资源信息', 'aksrt'); ?></h2>
|
|
</header>
|
|
|
|
<dl class="resource-meta-box__list">
|
|
<?php if (!empty($meta['version'])) : ?>
|
|
<div class="resource-meta-box__row">
|
|
<dt class="resource-meta-box__key">
|
|
<i class="<?php echo esc_attr(function_exists('aksrt_resource_meta_icon') ? aksrt_resource_meta_icon('version') : 'fa fas fa-code-branch'); ?>" aria-hidden="true"></i>
|
|
<?php echo esc_html($rows['version']); ?>
|
|
</dt>
|
|
<dd class="resource-meta-box__val"><?php echo esc_html((string) $meta['version']); ?></dd>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($meta['size'])) : ?>
|
|
<div class="resource-meta-box__row">
|
|
<dt class="resource-meta-box__key">
|
|
<i class="<?php echo esc_attr(function_exists('aksrt_resource_meta_icon') ? aksrt_resource_meta_icon('size') : 'fa fas fa-hdd'); ?>" aria-hidden="true"></i>
|
|
<?php echo esc_html($rows['size']); ?>
|
|
</dt>
|
|
<dd class="resource-meta-box__val"><?php echo esc_html((string) $meta['size']); ?></dd>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($meta['compat'])) : ?>
|
|
<div class="resource-meta-box__row">
|
|
<dt class="resource-meta-box__key">
|
|
<i class="<?php echo esc_attr(function_exists('aksrt_resource_meta_icon') ? aksrt_resource_meta_icon('compat') : 'fa fas fa-laptop'); ?>" aria-hidden="true"></i>
|
|
<?php echo esc_html($rows['compat']); ?>
|
|
</dt>
|
|
<dd class="resource-meta-box__val"><?php echo esc_html((string) $meta['compat']); ?></dd>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($has_demo) : ?>
|
|
<div class="resource-meta-box__row">
|
|
<dt class="resource-meta-box__key">
|
|
<i class="<?php echo esc_attr(function_exists('aksrt_resource_meta_icon') ? aksrt_resource_meta_icon('demo_url') : 'fa fas fa-external-link-alt'); ?>" aria-hidden="true"></i>
|
|
<?php esc_html_e('演示地址', 'aksrt'); ?>
|
|
</dt>
|
|
<dd class="resource-meta-box__val">
|
|
<a class="resource-meta-box__demo-link" href="<?php echo esc_url($meta['demo_url']); ?>" target="_blank" rel="noopener noreferrer">
|
|
<?php esc_html_e('打开演示', 'aksrt'); ?>
|
|
<i class="fa fas fa-external-link-alt" aria-hidden="true"></i>
|
|
</a>
|
|
</dd>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($meta['license'])) : ?>
|
|
<div class="resource-meta-box__row">
|
|
<dt class="resource-meta-box__key">
|
|
<i class="<?php echo esc_attr(function_exists('aksrt_resource_meta_icon') ? aksrt_resource_meta_icon('license') : 'fa fas fa-shield-alt'); ?>" aria-hidden="true"></i>
|
|
<?php echo esc_html($rows['license']); ?>
|
|
</dt>
|
|
<dd class="resource-meta-box__val"><?php echo esc_html((string) $meta['license']); ?></dd>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($has_downloads) : ?>
|
|
<div class="resource-meta-box__row">
|
|
<dt class="resource-meta-box__key">
|
|
<i class="<?php echo esc_attr(function_exists('aksrt_resource_meta_icon') ? aksrt_resource_meta_icon('download') : 'fa fas fa-download'); ?>" aria-hidden="true"></i>
|
|
<?php esc_html_e('下载次数', 'aksrt'); ?>
|
|
</dt>
|
|
<dd class="resource-meta-box__val"><?php echo esc_html(number_format_i18n((int) $meta['download_count'])); ?></dd>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (($meta['view_count'] ?? 0) > 0) : ?>
|
|
<div class="resource-meta-box__row">
|
|
<dt class="resource-meta-box__key">
|
|
<i class="<?php echo esc_attr(function_exists('aksrt_resource_meta_icon') ? aksrt_resource_meta_icon('views') : 'fa fas fa-eye'); ?>" aria-hidden="true"></i>
|
|
<?php esc_html_e('浏览次数', 'aksrt'); ?>
|
|
</dt>
|
|
<dd class="resource-meta-box__val"><?php echo esc_html(number_format_i18n((int) $meta['view_count'])); ?></dd>
|
|
</div>
|
|
<?php endif; ?>
|
|
</dl>
|
|
</aside>
|