diff --git a/comment/index.php b/comment/index.php index c02e0cf..4beff28 100644 --- a/comment/index.php +++ b/comment/index.php @@ -1,22 +1,22 @@ getMessages($contentId, $category, 20); + $messages = $messageService->getMessages($contentId, $category, 20, null, $skp); $target = $messages['Data']['Target'] ?? []; $comments = $messages['Data']['Comments'] ?? []; $totalComments = $messages['Data']['Count'] ?? 0; } catch (Exception $e) { - echo "错误: " . $e->getMessage(); + $error = $e->getMessage(); } // 生成头像URL函数 @@ -181,35 +181,99 @@ function formatCommentTime($timestamp) { return "{$date} {$period}{$displayHour}:{$minute}"; } -// 处理回复内容中的@用户标签 -function processReplyContent($content) { - // 匹配 @用户名 格式 - $pattern = '/([^<]+)<\/user>/'; - $replacement = '$2'; +// 自定义标签解析器类 +class CustomTagParser { - return preg_replace($pattern, $replacement, $content); -} -?> - -
- -
- 加载失败: -
- - - -
-

暂无评论

-
- - $comment): ?> -
-
-
- <?= htmlspecialchars($comment['Nickname'] ?? '用户') ?> + + + +
+
+ +
+ 加载失败: +
+ + + +
+

暂无评论

+
+ + $comment): ?> +
+
+
+ <?= htmlspecialchars($comment['Nickname'] ?? '用户') ?> +
+
+
+
+
-
-
-
-
-
-
-
- -
+
+
+
- - - -
- - -
- -
+ + + + +
+ + +
+
+ + diff --git a/med.php b/med.php index f43b79e..af07d23 100644 --- a/med.php +++ b/med.php @@ -93,6 +93,120 @@ function formatDate($timestamp) { ]; $pageTitle = $pageTitles[$type] ?? '作品详情'; +// 自定义标签解析器类 +class CustomTagParser { + + /** + * 解析包含自定义标签的文本 + */ + public static function parse(string $text): string { + if (empty($text)) { + return ''; + } + + // 先转义HTML特殊字符,防止XSS攻击 + $text = htmlspecialchars($text); + + // 先解析Markdown标题(在换行转换之前) + $text = self::parseMarkdownHeadings($text); + + // 将换行符转换为
+ $text = nl2br($text); + + // 解析自定义标签 + $patterns = [ + // user标签 - 保持原有格式 + '/<user=([a-f0-9]+)>(.*?)<\/user>/i', + // experiment标签 - 跳转链接 + '/<experiment=([a-f0-9]+)>(.*?)<\/experiment>/i', + // discussion标签 - 跳转链接 + '/<discussion=([a-f0-9]+)>(.*?)<\/discussion>/i', + // model标签 - 跳转链接 + '/<model=([a-f0-9]+)>(.*?)<\/model>/i', + // external标签 - 外部链接 + '/<external=([^&]+)>(.*?)<\/external>/i', + // size标签 + '/<size=([^&]+)>(.*?)<\/size>/i', + // color标签 - 新增 + '/<color=([^&]+)>(.*?)<\/color>/i', + // b标签 + '/<b>(.*?)<\/b>/i', + // i标签 + '/<i>(.*?)<\/i>/i', + // a标签 - 深蓝色标签 + '/<a>(.*?)<\/a>/i' + ]; + + $replacements = [ + // user标签 + '$2', + // experiment标签 + '$2', + // discussion标签 + '$2', + // model标签 + '$2', + // external标签 + '$2', + // size标签 + '$2', + // color标签 - 新增 + '$2', + // b标签 + '$1', + // i标签 + '$1', + // a标签 + '$1' + ]; + + $text = preg_replace($patterns, $replacements, $text); + + // 解析简单的Markdown格式 + $text = self::parseSimpleMarkdown($text); + + return $text; + } + + /** + * 解析Markdown标题 + */ + private static function parseMarkdownHeadings(string $text): string { + // 支持1-6级标题 + // 一级标题: # 标题 + $text = preg_replace('/^# (.+)$/m', '$1', $text); + + // 二级标题: ## 标题 + $text = preg_replace('/^## (.+)$/m', '$1', $text); + + // 三级标题: ### 标题 + $text = preg_replace('/^### (.+)$/m', '$1', $text); + + // 四级标题: #### 标题 + $text = preg_replace('/^#### (.+)$/m', '$1', $text); + + return $text; + } + + /** + * 解析简单的Markdown格式 + */ + private static function parseSimpleMarkdown(string $text): string { + // 粗体 + $text = preg_replace('/\*\*(.*?)\*\*/', '$1', $text); + + // 斜体 + $text = preg_replace('/\*(.*?)\*/', '$1', $text); + + // 删除线 + $text = preg_replace('/~~(.*?)~~/', '$1', $text); + + // 行内代码 + $text = preg_replace('/`([^`]+)`/', '$1', $text); + + return $text; + } +} ?> @@ -107,6 +221,103 @@ function formatDate($timestamp) { +
@@ -189,9 +400,9 @@ function formatDate($timestamp) {

作品介绍

- + - ', $content['Description']) ?> + ', array_map(function($a) {return CustomTagParser::parse($a);}, $content['Description'])) ?>
@@ -632,6 +843,16 @@ function handleEscapeKey(e) { } }); }); +const rUsers = document.querySelectorAll('.RUser'); + rUsers.forEach(rUser => { + rUser.addEventListener('click', function(e) { + e.stopPropagation(); + const userId = this.getAttribute('data-user'); + if (userId) { + window.location.href = 'user.php?id=' + userId; + } + }); + });