¾(可选) $main_image = schema_extract_image($first['message_fmt']); if (empty($main_image)) { $main_image = !empty($thread['user_avatar_url']) ? schema_absolute_url($thread['user_avatar_url']) : ''; } $main_entity = [ "@context" => "https://schema.org", "@type" => "DiscussionForumPosting", "headline" => htmlspecialchars(isset($thread_subject_display) ? $thread_subject_display : $thread['subject'], ENT_QUOTES), "url" => schema_absolute_url(url("thread-$tid")), "datePublished" => (new DateTime('@' . intval($thread['create_date'])))->setTimezone(new DateTimeZone('Asia/Shanghai'))->format('Y-m-d\TH:i:sP'), "dateModified" => (new DateTime('@' . intval($thread['last_date'])))->setTimezone(new DateTimeZone('Asia/Shanghai'))->format('Y-m-d\TH:i:sP'), "image" => $main_image, "text" => $main_text, "author" => [ "@type" => "Person", "name" => htmlspecialchars($thread['username'], ENT_QUOTES), "url" => schema_absolute_url(url("user-$thread[uid]")) ], "interactionStatistic" => [ "@type" => "InteractionCounter", "interactionType" => "https://schema.org/CommentAction", "userInteractionCount" => intval($thread['posts']) ] ]; // 2. 构建评论 (Replies) $comments_array = []; if (!empty($postlist)) { foreach ($postlist as $_post) { // 跳过主贴自己 if ($_post['pid'] == $thread['firstpid']) continue; $comment_guest_login_only = empty($uid) && !empty($_post['guest_login_only']); $comment_quote_guest_login_only = false; if (empty($uid) && !empty($_post['quotepid'])) { $comment_quote_post = post__read(intval($_post['quotepid'])); $comment_quote_guest_login_only = !empty($comment_quote_post['guest_login_only']); } $comment_text = ($comment_guest_login_only || $comment_quote_guest_login_only) ? '该内容需登录可见' : schema_clean_text($_post['message_fmt']); if (empty($comment_text)) $comment_text = "(图片或多媒体内容)"; $comment_data = [ "@type" => "Comment", "text" => $comment_text, "url" => schema_absolute_url(url("thread-$tid") . "#" . $_post['pid']), "datePublished" => (new DateTime('@' . intval($_post['create_date'])))->setTimezone(new DateTimeZone('Asia/Shanghai'))->format('Y-m-d\TH:i:sP'), "author" => [ "@type" => "Person", "name" => htmlspecialchars($_post['username'], ENT_QUOTES), "url" => schema_absolute_url(url("user-$_post[uid]")) ] ]; // 提取评论图片 $comment_image = ($comment_guest_login_only || $comment_quote_guest_login_only) ? '' : schema_extract_image($_post['message_fmt']); if (!empty($comment_image)) { $comment_data['image'] = $comment_image; } $comments_array[] = $comment_data; } } if (!empty($comments_array)) { $main_entity['comment'] = $comments_array; } echo json_encode($main_entity, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); ?>