esc_html__('仅在文章页 - 侧边栏展示当前文章的紧凑购买卡。', 'aksrt'), 'classname' => 'widget_aksrt_post_pay_box', ] ); } /** * @param array $instance */ public static function render_html(array $instance = []): string { if (!is_single() || get_post_type() !== 'post') { return ''; } $post = get_queried_object(); if (!($post instanceof \WP_Post) || !function_exists('aksrt_get_pay_meta') || !function_exists('aksrt_is_paid_post') || !aksrt_is_paid_post($post)) { return ''; } $meta = aksrt_get_pay_meta($post); $pay_type = (string) ($meta['pay_type'] ?? 'no'); if ($pay_type === '' || $pay_type === 'no') { return ''; } $theme = sanitize_html_class((string) ($instance['theme'] ?? 'jb-red')); $allowed_themes = ['jb-red', 'jb-yellow', 'jb-blue', 'jb-green', 'jb-purple', 'jb-vip1', 'jb-vip2']; if (!in_array($theme, $allowed_themes, true)) { $theme = 'jb-red'; } $price = function_exists('aksrt_get_user_pay_price') ? aksrt_get_user_pay_price($post) : [ 'amount' => (float) ($meta['price'] ?? 0), 'base' => (float) ($meta['price'] ?? 0), 'original' => (float) ($meta['original_price'] ?? 0), 'modo' => '0', 'currency' => '¥', ]; $amount = max(0.0, (float) ($price['amount'] ?? 0)); $base = max(0.0, (float) ($price['base'] ?? $amount)); $original = max(0.0, (float) ($price['original'] ?? 0)); $pay_modo = (($price['modo'] ?? '0') === 'points') ? 'points' : '0'; $currency = (string) ($price['currency'] ?? ($pay_modo === 'points' ? __('积分', 'aksrt') : '¥')); $format = static function (float $value) use ($pay_modo, $currency): string { $number = function_exists('aksrt_format_price') ? aksrt_format_price($value) : number_format($value, 2, '.', ''); return $pay_modo === 'points' ? $number . ' ' . $currency : $currency . $number; }; $has_access = function_exists('aksrt_has_paid_access') && aksrt_has_paid_access($post); $is_logged_in = is_user_logged_in(); $login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink($post)); $demo = trim((string) ($meta['demo_url'] ?? '')); $sales = 0; if (function_exists('aksrt_get_download_box_meta')) { $box = aksrt_get_download_box_meta($post); $sales = max(0, (int) ($box['sales_count'] ?? 0)); } $type_labels = [ 'reading' => __('付费阅读', 'aksrt'), 'download' => __('付费下载', 'aksrt'), 'gallery' => __('付费图库', 'aksrt'), 'video' => __('付费视频', 'aksrt'), 'vip' => __('会员专属', 'aksrt'), ]; $type_label = $type_labels[$pay_type] ?? __('付费内容', 'aksrt'); $action_labels = [ 'reading' => __('查看内容', 'aksrt'), 'download' => __('前往下载', 'aksrt'), 'gallery' => __('查看图片', 'aksrt'), 'video' => __('查看视频', 'aksrt'), 'vip' => __('查看内容', 'aksrt'), ]; $action_label = $action_labels[$pay_type] ?? __('查看内容', 'aksrt'); $show_original = $original > $amount && $original > 0; $show_member_discount = !$has_access && $amount > 0 && $base > $amount; ob_start(); ?>
0) : ?>
0) : ?>

0 && $pay_modo !== 'points' && function_exists('aksrt_allow_guest_content_pay') && aksrt_allow_guest_content_pay($post)) : ?>
__('红', 'aksrt'), 'jb-yellow' => __('橙', 'aksrt'), 'jb-blue' => __('蓝', 'aksrt'), 'jb-green' => __('绿', 'aksrt'), 'jb-purple' => __('紫', 'aksrt'), 'jb-vip1' => __('会员金', 'aksrt'), 'jb-vip2' => __('会员灰', 'aksrt'), ]; ?>

$theme]; } }