{php} /** * 文章列表项组件 */ $cid = $post['cid']; $ptpuser = $post['ptpuser']; $ptpimg = getUserAvatar($ptpuser); $isAnonymousPost = isFlag($post['is_anonymous'] ?? 0) === 1; $displayName = $isAnonymousPost ? '匿名用户' : getUserDisplayName($ptpuser); if ($isAnonymousPost) { $ptpimg = '/assets/img/tx.png'; } $ptptext = renderArticleEmojis(cleanArticleHtml($post['ptptext'])); $ptpimag = $post['ptpimag']; $ptpvideo = $post['ptpvideo']; $ptpmusic = $post['ptpmusic']; $ptplx = $post['ptplx']; $ptpdw = $post['ptpdw']; $ptptime = $post['ptptime']; $ptpgg = isFlag($post['ptpgg'] ?? 0); $ptpggurl = $post['ptpggurl']; $ptpys = isFlag($post['ptpys'] ?? 1, 1); $commauth = isFlag($post['commauth'] ?? 1, 1); $ptpaud = isFlag($post['ptpaud'] ?? 1, 1); $tagsEnabled = \app\service\ContentFeatureService::tagsEnabled(); $tagList = $tagsEnabled ? array_values(array_filter(array_map('trim', explode(',', $post['tags'] ?? '')))) : []; $postLikes = $postLikes ?? []; $postComments = $postComments ?? []; $postLikedMap = $postLikedMap ?? []; $musicSource = ''; $topIds = !empty($siteConfig['topes']) ? array_filter(array_map('trim', explode("\n", $siteConfig['topes']))) : []; $isAdminPinned = in_array((string)$cid, $topIds, true); $isUserPinned = !empty($post['user_top']); $isPinned = $isAdminPinned || $isUserPinned; $isLongArticle = $ptplx === 'article'; $articleTitle = trim((string)($post['article_title'] ?? '')); $articleCover = assetUrl($post['article_cover'] ?? '/assets/img/thumbnailbg.svg'); if ($articleTitle === '') { $articleTitle = strCut(strip_tags($post['ptptext'] ?? ''), 30, ''); } // 封面色调 $coverColor = trim((string)($post['cover_color'] ?? '')); $coverColorStyle = ''; if ($coverColor !== '') { $hex = ltrim($coverColor, '#'); if (strlen($hex) === 3) { $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; } $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); $luma = 0.299 * $r + 0.587 * $g + 0.114 * $b; $textColor = $luma > 160 ? 'rgba(0,0,0,.78)' : 'rgba(255,255,255,.78)'; $titleColor = $luma > 160 ? '#111' : '#fff'; $coverColorStyle = 'background:rgb(' . $r . ',' . $g . ',' . $b . ');color:' . $textColor; } // 视频处理 $videoParts = explode("|", $ptpvideo); $ptpvideo = $videoParts[0]; $ptpvideofm = assetUrl($videoParts[1] ?? ''); // 图片处理 $imgArr = array_map('assetUrl', explode("(+@+)", $ptpimag)); $thumbArr = array_map('thumbUrl', $imgArr); $imgCount = count($imgArr); // 广告文章:用第一张图替换头像,图片网格中移除 if ($ptpgg === 1 && $imgCount > 0) { $ptpimg = $imgArr[0]; array_shift($imgArr); array_shift($thumbArr); $imgCount = count($imgArr); } // 图片网格样式 if ($imgCount === 1) { $gridStyle = "grid-template-columns:1fr;width: 55%;"; } elseif ($imgCount === 4 || $imgCount === 2) { $gridStyle = "grid-template-columns:1fr 1fr;width: 55%;"; } else { $gridStyle = "grid-template-columns:1fr 1fr 1fr;"; } // 广告样式 if ($ptpgg === 1) { $adStyle = "display: flex;"; $adUrl = '
进一步了解
'; $gps = ''; } else { $adStyle = "display: none;"; $adUrl = ''; $gps = '
' . sanitizeHtml($ptpdw) . '
'; } $pinStyle = 'background: var(--themetm);' . ($ptpgg === 1 ? 'margin-right: 5px;' : ''); // 时间处理 $time = strtotime($ptptime); $friendlyTime = formatFriendlyDate($time); // 用户链接 if ($isAnonymousPost) { $userUrl = ''; } else { $userUrl = 'onclick="location.href=\'/user/' . md5(md5($ptpuser)) . '\'"'; } // 内容截断 $contentText = preg_replace("/]+>/i", "", $ptptext); $contentText = preg_replace("/]+>/i", "", $contentText); $contentText = preg_replace("/]+>/i", "", $contentText); $contentText = str_replace(" ", "", $contentText); if (iconv_strlen($contentText, "UTF-8") > 100) { $ptptext = '' . $ptptext . '全文'; } else { $ptptext = '' . $ptptext . ''; } if ($isLongArticle) { $ptptext = ''; } // 点赞状态(由控制器通过 postLikedMap 预取) $dianzanText = "赞"; $dianzanClass = "iconfont icon-aixin ri-sxdzlike"; $liked = !empty($postLikedMap[$cid]); $currentLikeName = !empty($user) ? getUserDisplayName((string)($user['username'] ?? ''), (string)($user['name'] ?? '')) : ''; $currentLikeUser = !empty($user) ? (string)($user['username'] ?? '') : ''; if ($liked) { $dianzanText = "取消"; $dianzanClass = "iconfont icon-aixin2 ri-sxdzlikehs"; } // 评论按钮 if ($commauth === 1) { $commentBtn = '
评论
'; } else { $commentBtn = '
评论关闭
'; } {/php}
头像

{$displayName}

{if condition="$isPinned || $ptpgg === 1"}
{if condition="$isPinned"}

置顶

{/if}

广告

{/if}
{$ptptext|raw} {notempty name="tagList"} {/notempty} {if condition="$isLongArticle"} {$articleTitle} {:date('Y年m月d日', strtotime($ptptime))} {elseif condition="$ptplx == 'img'" /}
{php} for ($i = 0; $i < $imgCount; $i++) { $safeImg = htmlspecialchars($imgArr[$i], ENT_QUOTES, 'UTF-8'); $safeThumb = htmlspecialchars($thumbArr[$i], ENT_QUOTES, 'UTF-8'); if ($i > 7 && $imgCount > 9) { $duoimg = $imgCount - $i - 1; if ($imgCount > 9 && $i == 8) { echo ' +' . $duoimg . ' '; } else { echo ''; } } else { echo ' '; } } {/php}
{elseif condition="$ptplx == 'video'" /} {php}$isBilibili = strpos($ptpvideo, "player.bilibili.com") !== false;{/php} {if condition="$isBilibili"}
BiliBili
{else/}
MP4
{/if} {elseif condition="$ptplx == 'music'" /} {php} $musicSource = ''; if (!is_numeric($ptpmusic)) { $mus = explode("|", $ptpmusic); echo \think\facade\View::fetch('component/music_play', ['mus' => $mus, 'cid' => $cid]); $mu = $mus[0] ?? ''; if (stripos($mu, 'qq-proxy') !== false || stripos($mu, 'qq.com') !== false) { $musicSource = 'QQ音乐'; } elseif (stripos($mu, 'kugou') !== false) { $musicSource = '酷狗音乐'; } elseif (stripos($mu, 'kuwo') !== false) { $musicSource = '酷我音乐'; } elseif (stripos($mu, '163.com') !== false || stripos($mu, '/api/music/proxy') !== false) { $musicSource = '网易云音乐'; } } {/php} {/if}
{notempty name="ptpdw"} {$gps|raw} {/notempty} {$adUrl|raw}
{$friendlyTime}{if condition="$musicSource"}来自 {$musicSource}{/if}
{$dianzanText}

{$commentBtn|raw}

{php} // 点赞列表 $likes = $postLikes[$cid] ?? []; {/php} {notempty name="likes"}
    {php} $visitorCount = 0; $likeNames = []; foreach ($likes as $like) { $likeUser = (string)$like['luser']; $likeName = getLikeDisplayName($like); if (isVisitorUser($likeUser) && trim((string)($like['lname'] ?? '')) === '') { $visitorCount++; } else { $likeNames[] = ['user' => $likeUser, 'name' => $likeName]; } } foreach ($likeNames as $likeItem) { echo ''; } echo ''; $totalLikeCount = count($likeNames) + $visitorCount; $summaryNames = implode(',', array_map(function ($likeItem) { return sanitizeHtml($likeItem['name']); }, $likeNames)); if (!empty($likeNames)) { echo '
  • ' . $summaryNames . ',等' . $totalLikeCount . '人觉得很赞
  • '; } elseif ($totalLikeCount > 0) { echo '
  • 有' . $totalLikeCount . '人觉得很赞
  • '; } {/php}
{else/} {/notempty} {php} $commgs = $siteConfig['commgs'] ?? 10; $comments = $postComments[$cid] ?? []; $commentCount = 0; $showMore = "display:none"; {/php} {notempty name="comments"}
    {volist name="comments" id="comment"} {php} $commentCount++; $commentName = getUserDisplayName((string)($comment['couser'] ?? ''), (string)($comment['coname'] ?? '')); $replyName = getUserDisplayName((string)($comment['bcouser'] ?? ''), (string)($comment['bconame'] ?? '')); if ($commgs < $commentCount) { $showMore = "display:flex"; break; } else { $showMore = "display:none"; } {/php}
  • {notempty name="comment.courl"} {$commentName} {else/} {$commentName} {/notempty} {if condition="(!empty($comment['bcouser']) && $comment['bcouser'] != 'false') || (!empty($comment['bconame']) && $comment['bconame'] != 'false')"} 回复 {$replyName} {/if}: {php}echo renderArticleEmojis(sanitizeHtml($comment['cotext']));{/php}
  • {/volist}
{else/} {/notempty}