Files
kate522 6bd7676b73 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.
2026-07-17 10:33:00 +08:00

56 lines
2.0 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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;