进行了一些小修复
This commit is contained in:
1 parent
2e7cc56043
commit
d37c34f71c
114 files changed
+86
-181
No files matched your search
@@ -91,7 +91,7 @@ if (!function_exists('aksrt_comments_build_context')) :
|
||||
$avatar_size = max(24, (int) ($settings['avatar_size'] ?? 48));
|
||||
$toolbar = is_array($settings['toolbar'] ?? null)
|
||||
? $settings['toolbar']
|
||||
: ['smilie' => true, 'code' => true, 'image' => true];
|
||||
: ['code' => true, 'image' => true];
|
||||
|
||||
$phrases = is_array($settings['quick_phrases'] ?? null) ? $settings['quick_phrases'] : [];
|
||||
|
||||
|
||||
@@ -2,101 +2,16 @@
|
||||
/**
|
||||
* Comment content filters — legacy-compatible shortcodes.
|
||||
*
|
||||
* Supports [g=key] GIF smilies, [img=url], [code]...[/code].
|
||||
* Supports [img=url] and [code]...[/code].
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_comment_smilie_keys')) :
|
||||
/**
|
||||
* Canonical legacy smilie keys (filename without .gif).
|
||||
*
|
||||
* @return array<int,string>
|
||||
*/
|
||||
function aksrt_comment_smilie_keys(): array {
|
||||
return [
|
||||
'aoman', 'baiyan', 'bishi', 'bizui', 'cahan', 'ciya', 'dabing', 'daku', 'deyi', 'doge',
|
||||
'fadai', 'fanu', 'fendou', 'ganga', 'guzhang', 'haixiu', 'hanxiao', 'zuohengheng', 'zhuakuang',
|
||||
'zhouma', 'zhemo', 'zhayanjian', 'zaijian', 'yun', 'youhengheng', 'yiwen', 'yinxian', 'xu',
|
||||
'xieyanxiao', 'xiaoku', 'xiaojiujie', 'xia', 'wunai', 'wozuimei', 'weixiao', 'weiqu', 'tuosai',
|
||||
'tu', 'touxiao', 'tiaopi', 'shui', 'se', 'saorao', 'qiudale', 'qinqin', 'qiaoda', 'piezui',
|
||||
'penxue', 'nanguo', 'liulei', 'liuhan', 'lenghan', 'leiben', 'kun', 'kuaikule', 'ku', 'koubi',
|
||||
'kelian', 'keai', 'jingya', 'jingxi', 'jingkong', 'jie', 'huaixiao', 'haqian', 'aini', 'OK',
|
||||
'qiang', 'quantou', 'shengli', 'woshou', 'gouyin', 'baoquan', 'aixin', 'bangbangtang',
|
||||
'xiaoyanger', 'xigua', 'hexie', 'pijiu', 'lanqiu', 'juhua', 'hecai', 'haobang', 'caidao',
|
||||
'baojin', 'chi', 'dan', 'kulou', 'shuai', 'shouqiang', 'yangtuo', 'youling',
|
||||
];
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_comment_smilie_map')) :
|
||||
/**
|
||||
* Smilie key => URL map (GIF under assets/img/smilies).
|
||||
*
|
||||
* @return array<string,string>
|
||||
*/
|
||||
function aksrt_comment_smilie_map(): array {
|
||||
static $map = null;
|
||||
if (is_array($map)) {
|
||||
return $map;
|
||||
}
|
||||
$base = trailingslashit(get_template_directory_uri()) . 'assets/img/smilies/';
|
||||
$map = [];
|
||||
foreach (aksrt_comment_smilie_keys() as $key) {
|
||||
$map[$key] = $base . rawurlencode($key) . '.gif';
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_comment_smilies_base_uri')) :
|
||||
/**
|
||||
* Base URI for smilie GIFs (localized to JS).
|
||||
*/
|
||||
function aksrt_comment_smilies_base_uri(): string {
|
||||
return trailingslashit(get_template_directory_uri()) . 'assets/img/smilies/';
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_render_comment_smilie')) :
|
||||
/**
|
||||
* Render a single [g=key] smilie as <img class="smilie-icon">.
|
||||
*/
|
||||
function aksrt_render_comment_smilie(string $key): string {
|
||||
// Preserve case for OK.gif; sanitize other keys.
|
||||
$raw = trim($key);
|
||||
if ($raw === '') {
|
||||
return '';
|
||||
}
|
||||
$lookup = $raw === 'OK' ? 'OK' : sanitize_key($raw);
|
||||
// Allow original casing match for files like OK.gif.
|
||||
$map = aksrt_comment_smilie_map();
|
||||
if (!isset($map[$lookup]) && isset($map[$raw])) {
|
||||
$lookup = $raw;
|
||||
}
|
||||
if (!isset($map[$lookup])) {
|
||||
// Fallback: try case-insensitive.
|
||||
foreach ($map as $k => $url) {
|
||||
if (strcasecmp((string) $k, $raw) === 0) {
|
||||
$lookup = (string) $k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isset($map[$lookup])) {
|
||||
return '[g=' . esc_html($raw) . ']';
|
||||
}
|
||||
$label = esc_attr('[' . $lookup . ']');
|
||||
return '<img' . aksrt_get_lazy_attr('lazy_comment', (string) $map[$lookup], 'smilie-icon', aksrt_get_lazy_thumb('sm'))
|
||||
. ' alt="' . $label . '" title="' . $label . '" width="30" height="30" decoding="async" data-smilie="' . esc_attr($lookup) . '">';
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_render_comment_content')) :
|
||||
/**
|
||||
* Filter comment body: smilies, images, code blocks (legacy parity).
|
||||
* Filter comment body: images and code blocks (legacy parity).
|
||||
*/
|
||||
function aksrt_render_comment_content(string $content): string {
|
||||
// [img=url]
|
||||
@@ -125,15 +40,6 @@ if (!function_exists('aksrt_render_comment_content')) :
|
||||
'<a href="$1" rel="nofollow">$2</a>',
|
||||
(string) $rendered
|
||||
);
|
||||
// [g=key]
|
||||
$rendered = preg_replace_callback(
|
||||
'/\[g=([^\]]+)\]/i',
|
||||
static function (array $matches): string {
|
||||
return aksrt_render_comment_smilie(trim((string) $matches[1]));
|
||||
},
|
||||
(string) $rendered
|
||||
);
|
||||
|
||||
$allowed = wp_kses_allowed_html('post');
|
||||
if (!isset($allowed['img'])) {
|
||||
$allowed['img'] = [];
|
||||
@@ -147,7 +53,6 @@ if (!function_exists('aksrt_render_comment_content')) :
|
||||
'height' => true,
|
||||
'data-src' => true,
|
||||
'decoding' => true,
|
||||
'data-smilie' => true,
|
||||
'data-src' => true,
|
||||
]);
|
||||
$allowed['pre'] = array_merge($allowed['pre'] ?? [], ['class' => true]);
|
||||
|
||||
@@ -39,12 +39,12 @@ if (!function_exists('aksrt_get_input_expand_but')) :
|
||||
/**
|
||||
* legacy-style expand toolbar button + dropdown (legacy: legacy).
|
||||
*
|
||||
* @param string $type smilie|code|image|quick|link.
|
||||
* @param string $type code|image|quick|link.
|
||||
* @param mixed $arg1 Type-specific arg.
|
||||
* @param array<string,mixed> $ctx Optional context (upload, phrases).
|
||||
* @return string
|
||||
*/
|
||||
function aksrt_get_input_expand_but(string $type = 'smilie', $arg1 = null, array $ctx = []): string {
|
||||
function aksrt_get_input_expand_but(string $type, $arg1 = null, array $ctx = []): string {
|
||||
$but = '';
|
||||
$dropdown = '';
|
||||
|
||||
@@ -78,16 +78,6 @@ if (!function_exists('aksrt_get_input_expand_but')) :
|
||||
$dropdown = '<div class="relative dropdown-quick-often"><div class="quick-often-box scroll-y mini-scrollbar">' . $sys_lists . '</div></div>';
|
||||
break;
|
||||
|
||||
case 'smilie':
|
||||
$map = function_exists('aksrt_comment_smilie_map') ? aksrt_comment_smilie_map() : [];
|
||||
$smilie_icon = '';
|
||||
foreach ($map as $key => $url) {
|
||||
$smilie_icon .= '<a class="smilie-icon" href="javascript:;" data-smilie="' . esc_attr((string) $key) . '"><img src="' . esc_url((string) $url) . '" alt="[' . esc_attr((string) $key) . ']" /></a>';
|
||||
}
|
||||
$but = '<a class="but btn-input-expand input-smilie mr6" href="javascript:;"><i class="fa fa-fw fa-smile-o" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('表情', 'aksrt') . '</span></a>';
|
||||
$dropdown = '<div class="dropdown-smilie scroll-y mini-scrollbar">' . $smilie_icon . '</div>';
|
||||
break;
|
||||
|
||||
case 'code':
|
||||
$but = '<a class="but btn-input-expand input-code mr6" href="javascript:;"><i class="fa fa-fw fa-code" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('代码', 'aksrt') . '</span></a>';
|
||||
$dropdown = '<div class="dropdown-code">';
|
||||
@@ -124,7 +114,7 @@ endif;
|
||||
|
||||
if (!function_exists('aksrt_render_comment_expand_toolbar')) :
|
||||
/**
|
||||
* Render left-side expand tools based on settings (legacy order: smilie/code/image/link/quick).
|
||||
* Render left-side expand tools based on settings (legacy order: code/image/link/quick).
|
||||
*
|
||||
* @param array<string,mixed> $ctx Comments context.
|
||||
*/
|
||||
@@ -134,9 +124,6 @@ if (!function_exists('aksrt_render_comment_expand_toolbar')) :
|
||||
$phrases = is_array($ctx['quick_phrases'] ?? null) ? $ctx['quick_phrases'] : [];
|
||||
$quick_s = !isset($ctx['quick_s']) || !empty($ctx['quick_s']);
|
||||
|
||||
if (!empty($toolbar['smilie'])) {
|
||||
echo aksrt_get_input_expand_but('smilie'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
if (!empty($toolbar['code'])) {
|
||||
echo aksrt_get_input_expand_but('code'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user