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:
1 parent
7cc25ef68c
commit
6bd7676b73
5 files changed
+402
-164
No files matched your search
@@ -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;
|
||||
Reference in new issue
Block a user