fix(yiyan): stop invalid Hitokoto category requests

Public hitokoto v1 rejects c=hitokoto (and ignores batch count). Whitelist
categories a–l, multi-fetch for carousel, and share full markup via
aksrt_render_yiyan_block so single-post shells actually render quotes.
This commit is contained in:
kate522 committed 2026-07-17 10:33:00 +08:00
1 parent 7cc25ef68c
commit 6bd7676b73
5 files changed
+402 -164

No files matched your search

+13 -5
View File
@@ -313,7 +313,11 @@ if (!function_exists('aksrt_single_render_content_footer')) :
$post_id = (int) $ctx['post_id'];
?>
<?php if (!empty($settings['yiyan_footer'])) : ?>
<div class="article-yiyan yiyan-box aksrt-yiyan yiyan--footer" data-aksrt-yiyan data-type="hitokoto"></div>
<?php
aksrt_render_yiyan_block([
'class' => 'article-yiyan yiyan-box aksrt-yiyan yiyan--footer',
]);
?>
<?php endif; ?>
<?php if (!empty($settings['copyright_enabled'])) : ?>
@@ -855,7 +859,11 @@ if (!function_exists('aksrt_single_render_article')) :
<div class="article-content">
<?php if (!empty($settings['yiyan_header'])) : ?>
<div class="article-yiyan yiyan-box aksrt-yiyan yiyan--header theme-box text-center radius8 main-shadow" data-aksrt-yiyan data-type="hitokoto"></div>
<?php
aksrt_render_yiyan_block([
'class' => 'article-yiyan yiyan-box aksrt-yiyan yiyan--header theme-box text-center radius8 main-shadow',
]);
?>
<?php endif; ?>
<?php do_action('aksrt_single_content_before', get_post()); ?>
@@ -910,9 +918,9 @@ if (!function_exists('aksrt_single_render_after_box')) :
$settings = is_array($ctx['settings'] ?? null) ? $ctx['settings'] : [];
if (!empty($settings['yiyan_box'])) {
?>
<div class="yiyan-box main-bg theme-box text-center box-body radius8 main-shadow aksrt-yiyan" data-aksrt-yiyan data-type="hitokoto"></div>
<?php
aksrt_render_yiyan_block([
'class' => 'yiyan-box main-bg theme-box text-center box-body radius8 main-shadow aksrt-yiyan',
]);
}
// Accept both `authordesc` (Settings DTO) and legacy `authordesc_s`.
+55
View File
@@ -0,0 +1,55 @@
<?php
/**
* 一言 (Hitokoto) markup helper.
*
* Shared shell for single-post placements and the yiyan widget.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (!function_exists('aksrt_render_yiyan_block')) :
/**
* Shared 一言 shell for single-post placements (and reusable markup).
*
* Hitokoto category `c` must be a letter a–l, or empty for mixed random.
* Client loads quotes via parallel fetches when count > 1.
*
* @param array<string,mixed> $args {
* @type string $class Extra CSS classes on the root.
* @type string $type Category letter a–l, or empty for random.
* @type int $count Number of quotes to load (1–10).
* @type int $interval Rotation interval in seconds.
* @type string $icon Optional FA icon class; empty = no icon.
* }
*/
function aksrt_render_yiyan_block(array $args = []): void {
$class = trim((string) ($args['class'] ?? 'aksrt-yiyan'));
$type_raw = strtolower(trim((string) ($args['type'] ?? '')));
$type = preg_match('/^[a-l]$/', $type_raw) ? $type_raw : '';
$count = max(1, min(10, (int) ($args['count'] ?? 5)));
$interval = max(3, min(30, (int) ($args['interval'] ?? 8)));
$icon = sanitize_text_field((string) ($args['icon'] ?? ''));
if (strpos($class, 'aksrt-yiyan') === false) {
$class = trim($class . ' aksrt-yiyan');
}
?>
<div class="<?php echo esc_attr($class); ?>"
data-aksrt-yiyan
data-count="<?php echo esc_attr((string) $count); ?>"
data-interval="<?php echo esc_attr((string) $interval); ?>"
<?php echo $type !== '' ? ' data-type="' . esc_attr($type) . '"' : ''; ?>>
<div class="aksrt-yiyan__content">
<?php if ($icon !== '') : ?>
<i class="<?php echo esc_attr($icon); ?> aksrt-yiyan__icon" aria-hidden="true"></i>
<?php endif; ?>
<p class="aksrt-yiyan__text"><?php esc_html_e('加载中…', 'aksrt'); ?></p>
<p class="aksrt-yiyan__from"></p>
</div>
<div class="aksrt-yiyan__dots" aria-hidden="true"></div>
</div>
<?php
}
endif;