*/ 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 */ 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 . */ 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 ''; } endif; if (!function_exists('aksrt_render_comment_content')) : /** * Filter comment body: smilies, images, code blocks (zibll parity). */ function aksrt_render_comment_content(string $content): string { // [img=url] $rendered = preg_replace_callback( '/\[img=(https?:\/\/[^\s\[\]]+)\]/i', static function (array $matches): string { return ''; }, $content ); // [code]...[/code] $rendered = str_replace( ['[code]', '[/code]'], ['
', '
'], (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'] = []; } $allowed['img'] = array_merge($allowed['img'], [ 'class' => true, 'src' => true, 'alt' => true, 'title' => true, 'width' => true, 'height' => true, 'data-src' => true, 'decoding' => true, 'data-smilie' => true, 'data-src' => true, ]); $allowed['pre'] = array_merge($allowed['pre'] ?? [], ['class' => true]); $allowed['code'] = $allowed['code'] ?? []; return wp_kses((string) $rendered, $allowed); } endif;