<?php

require_once __DIR__ . '/common.php';

admin_require_login();

$pdo       = db();
$adminUser = admin_current_user();
$siteTitle = get_setting('site.title', '六柱个人博客');


$counts = [
    'articles_total'        => 0,
    'articles_published'    => 0,
    'articles_pending'      => 0,
    'comments_total'        => 0,
    'comments_pending'      => 0,
    'users_total'           => 0,
    'users_verified'        => 0,
    'users_comment_banned'  => 0,
    'users_post_banned'     => 0,
    'links_pending'         => 0,
    'new_sites_total'       => 0,
];

$todayStats     = ['pv' => 0, 'uv' => 0, 'ip' => 0];
$yesterdayStats = ['pv' => 0, 'uv' => 0, 'ip' => 0];
$last7Stats     = ['pv' => 0, 'uv' => 0, 'ip' => 0];

$recentArticles    = [];
$recentComments    = [];
$pendingArticles   = [];
$pendingLinks      = [];
$last7NewOverview  = ['articles' => 0, 'comments' => 0, 'users' => 0];
$topHotArticles7d  = [];
$topActiveTags7d   = [];
$serverInfo        = [
    'php_version'   => PHP_VERSION,
    'server_software' => $_SERVER['SERVER_SOFTWARE'] ?? '',
    'os'            => PHP_OS_FAMILY . ' ' . PHP_OS,
    'db_path'       => DB_PATH,
    'db_size'       => 0,
];

$now          = time();
$todayDate    = date('Y-m-d', $now);
$yesterday    = date('Y-m-d', $now - 86400);
$sevenDaysAgo = date('Y-m-d', $now - 6 * 86400);

try {
    
    $row = $pdo->query("SELECT COUNT(*) AS c FROM articles")->fetch();
    $counts['articles_total'] = (int)($row['c'] ?? 0);

    $row = $pdo->query("SELECT COUNT(*) AS c FROM articles WHERE status = 'published'")->fetch();
    $counts['articles_published'] = (int)($row['c'] ?? 0);

    $row = $pdo->query("SELECT COUNT(*) AS c FROM articles WHERE status = 'pending'")->fetch();
    $counts['articles_pending'] = (int)($row['c'] ?? 0);

    
    $row = $pdo->query("SELECT COUNT(*) AS c FROM comments")->fetch();
    $counts['comments_total'] = (int)($row['c'] ?? 0);

    $row = $pdo->query("SELECT COUNT(*) AS c FROM comments WHERE status = 'pending'")->fetch();
    $counts['comments_pending'] = (int)($row['c'] ?? 0);

    
    try {
        $row = $pdo->query("SELECT COUNT(*) AS c FROM users")->fetch();
        $counts['users_total'] = (int)($row['c'] ?? 0);

        $row = $pdo->query("SELECT COUNT(*) AS c FROM users WHERE email_verified = 1")->fetch();
        $counts['users_verified'] = (int)($row['c'] ?? 0);

        $row = $pdo->query("SELECT COUNT(*) AS c FROM users WHERE is_comment_banned = 1")->fetch();
        $counts['users_comment_banned'] = (int)($row['c'] ?? 0);

        $row = $pdo->query("SELECT COUNT(*) AS c FROM users WHERE is_post_banned = 1")->fetch();
        $counts['users_post_banned'] = (int)($row['c'] ?? 0);
    } catch (Throwable $e) {
        $counts['users_total']          = $counts['users_total']          ?? 0;
        $counts['users_verified']       = 0;
        $counts['users_comment_banned'] = 0;
        $counts['users_post_banned']    = 0;
    }

    try {
        $row = $pdo->query("SELECT COUNT(*) AS c FROM friend_links WHERE status = 'pending'")->fetch();
        $counts['links_pending'] = (int)($row['c'] ?? 0);
    } catch (Throwable $e) {
        $counts['links_pending'] = 0;
    }

    try {
        $row = $pdo->query("SELECT COUNT(*) AS c FROM new_sites")->fetch();
        $counts['new_sites_total'] = (int)($row['c'] ?? 0);
    } catch (Throwable $e) {
        $counts['new_sites_total'] = 0;
    }

    
    try {
        
        $stmt = $pdo->prepare("SELECT date, pv, uv, ip_count FROM visit_daily WHERE date IN (:d1, :d2)");
        $stmt->execute([':d1' => $todayDate, ':d2' => $yesterday]);
        while ($row = $stmt->fetch()) {
            if ($row['date'] === $todayDate) {
                $todayStats = [
                    'pv' => (int)$row['pv'],
                    'uv' => (int)$row['uv'],
                    'ip' => (int)$row['ip_count'],
                ];
            } elseif ($row['date'] === $yesterday) {
                $yesterdayStats = [
                    'pv' => (int)$row['pv'],
                    'uv' => (int)$row['uv'],
                    'ip' => (int)$row['ip_count'],
                ];
            }
        }

        
        $stmt = $pdo->prepare("
            SELECT
                SUM(pv)       AS pv_sum,
                SUM(uv)       AS uv_sum,
                SUM(ip_count) AS ip_sum
            FROM visit_daily
            WHERE date >= :d_start AND date <= :d_end
        ");
        $stmt->execute([':d_start' => $sevenDaysAgo, ':d_end' => $todayDate]);
        if ($row = $stmt->fetch()) {
            $last7Stats = [
                'pv' => (int)($row['pv_sum'] ?? 0),
                'uv' => (int)($row['uv_sum'] ?? 0),
                'ip' => (int)($row['ip_sum'] ?? 0),
            ];
        }
    } catch (Throwable $e) {
        
    }

    
    try {
        $sinceTs = $now - 6 * 86400;

        $stmt = $pdo->prepare("SELECT COUNT(*) AS c FROM articles WHERE status = 'published' AND published_at IS NOT NULL AND published_at >= :t");
        $stmt->execute([':t' => $sinceTs]);
        $last7NewOverview['articles'] = (int)($stmt->fetchColumn() ?: 0);

        $stmt = $pdo->prepare("SELECT COUNT(*) AS c FROM comments WHERE created_at >= :t");
        $stmt->execute([':t' => $sinceTs]);
        $last7NewOverview['comments'] = (int)($stmt->fetchColumn() ?: 0);

        $stmt = $pdo->prepare("SELECT COUNT(*) AS c FROM users WHERE created_at >= :t");
        $stmt->execute([':t' => $sinceTs]);
        $last7NewOverview['users'] = (int)($stmt->fetchColumn() ?: 0);
    } catch (Throwable $e) {
        $last7NewOverview = ['articles' => 0, 'comments' => 0, 'users' => 0];
    }

    
    try {
        $stmt = $pdo->query("
            SELECT id, title, view_count, like_count, comment_count, published_at
            FROM articles
            WHERE status = 'published'
            ORDER BY published_at DESC, id DESC
            LIMIT 5
        ");
        $recentArticles = $stmt->fetchAll() ?: [];
    } catch (Throwable $e) {
        $recentArticles = [];
    }

    
    try {
        $stmt = $pdo->query("
            SELECT
                c.id,
                c.article_id,
                c.content,
                c.status,
                c.is_guest,
                c.guest_name,
                c.created_at,
                a.title AS article_title,
                u.nickname
            FROM comments c
            LEFT JOIN articles a ON a.id = c.article_id
            LEFT JOIN users u ON u.id = c.user_id
            ORDER BY c.created_at DESC, c.id DESC
            LIMIT 5
        ");
        $recentComments = $stmt->fetchAll() ?: [];
    } catch (Throwable $e) {
        $recentComments = [];
    }

    
    try {
        $stmt = $pdo->query("
            SELECT id, title, created_at
            FROM articles
            WHERE status = 'pending'
            ORDER BY created_at DESC, id DESC
            LIMIT 5
        ");
        $pendingArticles = $stmt->fetchAll() ?: [];
    } catch (Throwable $e) {
        $pendingArticles = [];
    }

    
    try {
        $stmt = $pdo->query("
            SELECT id, name, url, created_at
            FROM friend_links
            WHERE status = 'pending'
            ORDER BY created_at DESC, id DESC
            LIMIT 5
        ");
        $pendingLinks = $stmt->fetchAll() ?: [];
    } catch (Throwable $e) {
        $pendingLinks = [];
    }

    
    try {
        if (is_file(DB_PATH)) {
            $serverInfo['db_size'] = filesize(DB_PATH);
        }
    } catch (Throwable $e) {
        $serverInfo['db_size'] = 0;
    }

    
    try {
        $sinceHot = $now - 6 * 86400;
        $stmt = $pdo->prepare("
            SELECT
                v.article_id,
                a.title,
                COUNT(*)                     AS pv,
                COUNT(DISTINCT v.visitor_id) AS uv,
                MAX(v.visit_time)            AS last_visit
            FROM visit_log v
            JOIN articles a ON a.id = v.article_id
            WHERE v.article_id IS NOT NULL
              AND v.visit_time >= :since
              AND a.status = 'published'
            GROUP BY v.article_id
            ORDER BY pv DESC
            LIMIT 5
        ");
        $stmt->execute([':since' => $sinceHot]);
        $topHotArticles7d = $stmt->fetchAll() ?: [];
    } catch (Throwable $e) {
        $topHotArticles7d = [];
    }

    
    try {
        $sinceTag = $now - 6 * 86400;
        $stmt = $pdo->prepare("
            SELECT
                t.id    AS tag_id,
                t.name  AS tag_name,
                COUNT(*)                     AS pv,
                COUNT(DISTINCT v.visitor_id) AS uv
            FROM visit_log v
            JOIN articles a      ON a.id = v.article_id
            JOIN article_tag at2 ON at2.article_id = a.id
            JOIN tags t          ON t.id = at2.tag_id
            WHERE v.article_id IS NOT NULL
              AND v.visit_time >= :since
              AND a.status = 'published'
            GROUP BY t.id
            ORDER BY pv DESC
            LIMIT 10
        ");
        $stmt->execute([':since' => $sinceTag]);
        $topActiveTags7d = $stmt->fetchAll() ?: [];
    } catch (Throwable $e) {
        $topActiveTags7d = [];
    }
} catch (Throwable $e) {
    
}

?><!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>后台仪表板 - <?php echo h($siteTitle); ?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        html, body { height:100%;  margin:0; padding:0; }
        body {
            margin: 0; padding:0;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
            background: #020617;
            color: #e5e7eb;
        }

        a {
            color: #60a5fa;
            text-decoration: none;
        }

        a:hover {
            text-decoration: underline;
        }

        .topbar {
            background: #0f172a;
            border-bottom: 1px solid #1f2937;
            padding:18px 16px 6px;
            display: flex;
            align-items:flex-start;
            justify-content: space-between;
         margin:0;  margin-top:-12px; }

        .topbar-title {
            font-size: 16px;
            font-weight: 600;
        }

        .topbar-user {
            font-size: 13px;
            color: #9ca3af;
        }

        .topbar-nav a {
            margin-left: 10px;
            font-size: 13px;
        }

        .layout {
            max-width: 1100px;
            margin: 0 auto;
            padding: 16px;
        }

        .cards {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
            gap: 12px;
        }

        .card {
            background: #020617;
            border-radius: 6px;
            border: 1px solid #1f2937;
            padding: 12px 14px;
        }

        .card-title {
            font-size: 13px;
            font-weight: 600;
            margin-bottom: 6px;
        }

        .stat-number {
            font-size: 20px;
            font-weight: 600;
            margin-right: 4px;
        }

        .stat-label {
            font-size: 12px;
            color: #9ca3af;
        }

        .small-text {
            font-size: 12px;
            color: #9ca3af;
            margin-top: 6px;
        }

        .cards-2col {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
            gap: 12px;
            margin-top: 16px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            font-size: 12px;
        }

        th, td {
            border-bottom: 1px solid #1f2937;
            padding: 4px 3px;
            text-align: left;
            vertical-align: top;
        }

        th {
            color: #9ca3af;
            font-weight: 500;
        }

        .badge-status {
            display: inline-block;
            padding: 1px 6px;
            border-radius: 999px;
            font-size: 11px;
        }

        .badge-pending { background: #78350f; color: #fed7aa; }
        .badge-approved { background: #14532d; color: #bbf7d0; }
        .badge-spam { background: #7f1d1d; color: #fecaca; }
        .badge-rejected { background: #4b5563; color: #e5e7eb; }

        .list-empty {
            font-size: 12px;
            color: #9ca3af;
        }

        .footer {
            margin-top: 20px;
            padding-top: 10px;
            border-top: 1px solid #111827;
            font-size: 12px;
            color: #6b7280;
            text-align: center;
        }
    </style>
</head>
<body style="margin:0;padding:0;"><div class="topbar">
        <div class="topbar-title">六柱博客 · 后台</div>
        <div class="topbar-user">
            管理员：<?php echo h($adminUser['nickname'] ?? $adminUser['email'] ?? ''); ?>
            <span class="topbar-nav">
                  <a href="index.php">仪表板</a>
                  <a href="articles.php">文章</a>
                  <a href="categories.php">分类</a>
                  <a href="tags.php">&#26631;&#31614;</a>
                  <a href="comments.php">评论</a>
                  <a href="links.php">友链</a>
                <a href="media.php">文件</a>
                  <a href="users.php">会员</a>
                  <a href="sensitive_words.php">敏感词</a>
                  <a href="stats.php">流量</a>
                  <a href="security.php">防护</a>
                  <a href="logs.php">日志</a>
                  <a href="settings.php">设置</a>
                  <a href="backup_sqlite.php">&#25968;&#25454;</a>
                  <a href="../index.php">前台</a>
                  <a href="../logout.php">退出</a>
              </span>
        </div>
    </div>

    <div class="layout">
        <div class="cards">
            <div class="card">
                <div class="card-title">文章概览</div>
                <div>
                    <span class="stat-number"><?php echo $counts['articles_total']; ?></span>
                    <span class="stat-label">篇文章</span>
                </div>
                <div class="small-text">
                    已发布：<?php echo $counts['articles_published']; ?> 篇；
                    待审核：<?php echo $counts['articles_pending']; ?> 篇
                </div>
            </div>

            <div class="card">
                <div class="card-title">评论与审核</div>
                <div>
                    <span class="stat-number"><?php echo $counts['comments_total']; ?></span>
                    <span class="stat-label">条评论</span>
                </div>
                <div class="small-text">
                    待审核评论：<?php echo $counts['comments_pending']; ?> 条。
                    <a href="comments.php?status=pending">前往审核</a>
                </div>
            </div>

            <div class="card">
                <div class="card-title">访问与流量</div>
                <div>
                    <span class="stat-number"><?php echo $todayStats['pv']; ?></span>
                    <span class="stat-label">PV（今日）</span>
                </div>
                <div class="small-text">
                    UV：<?php echo $todayStats['uv']; ?> ，IP：<?php echo $todayStats['ip']; ?>。
                    昨日 PV：<?php echo $yesterdayStats['pv']; ?>。<br>
                    最近 7 天 PV：<?php echo $last7Stats['pv']; ?> ，UV：<?php echo $last7Stats['uv']; ?> ，IP：<?php echo $last7Stats['ip']; ?>。
                    <a href="stats.php">查看详情</a>
                </div>
            </div>

            <div class="card">
                <div class="card-title">友链 / 新网址</div>
                <div>
                    <span class="stat-number"><?php echo $counts['links_pending']; ?></span>
                    <span class="stat-label">条友链待审核</span>
                </div>
                <div class="small-text">
                    最新网址总数：<?php echo $counts['new_sites_total']; ?> 条。
                    <a href="links.php">管理友链与最新网址</a>
                </div>
            </div>

            <div class="card">
                <div class="card-title">会员概览</div>
                <div>
                    <span class="stat-number"><?php echo $counts['users_total']; ?></span>
                    <span class="stat-label">个注册用户</span>
                </div>
                <div class="small-text">
                    已验证邮箱：<?php echo $counts['users_verified']; ?> 个；
                    禁止评论：<?php echo $counts['users_comment_banned']; ?> 个；
                    禁止投稿：<?php echo $counts['users_post_banned']; ?> 个。
                </div>
            </div>
        </div>

        <div class="cards-2col">
            <div class="card">
                <div class="card-title">待办事项</div>
                <div class="small-text">
                    · 待审核文章：<?php echo $counts['articles_pending']; ?> 篇
                    （<a href="articles.php?status=pending">去审核</a>）<br>
                    · 待审核评论：<?php echo $counts['comments_pending']; ?> 条
                    （<a href="comments.php?status=pending">去审核</a>）<br>
                    · 待审核友链：<?php echo $counts['links_pending']; ?> 条
                    （<a href="links.php?tab=pending">去审核</a>）
                </div>

                <div class="small-text" style="margin-top:8px;">最近 5 篇待审核文章：</div>
                <?php if ($pendingArticles): ?>
                    <table>
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>标题</th>
                                <th>时间</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($pendingArticles as $a): ?>
                                <tr>
                                    <td><?php echo (int)$a['id']; ?></td>
                                    <td>
                                        <a href="article_edit.php?id=<?php echo (int)$a['id']; ?>">
                                            <?php echo h(mb_substr($a['title'] ?? '', 0, 26, 'UTF-8')); ?>
                                        </a>
                                    </td>
                                    <td><?php echo date('m-d H:i', (int)$a['created_at']); ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                <?php else: ?>
                    <div class="list-empty">当前没有待审核文章。</div>
                <?php endif; ?>

                <div class="small-text" style="margin-top:8px;">最近 5 条友链申请：</div>
                <?php if ($pendingLinks): ?>
                    <table>
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>名称</th>
                                <th>网址</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($pendingLinks as $l): ?>
                                <tr>
                                    <td><?php echo (int)$l['id']; ?></td>
                                    <td><?php echo h($l['name']); ?></td>
                                    <td style="max-width:220px;word-break:break-all;"><?php echo h($l['url']); ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                <?php else: ?>
                    <div class="list-empty">当前没有待审核友链。</div>
                <?php endif; ?>
            </div>

            <div class="card">
                <div class="card-title">最近评论</div>
                <?php if ($recentComments): ?>
                    <table>
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>文章</th>
                                <th>内容</th>
                                <th>用户 / 状态</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($recentComments as $c): ?>
                                <tr>
                                    <td><?php echo (int)$c['id']; ?></td>
                                    <td>
                                        <?php if ($c['article_id']): ?>
                                            <a href="../post.php?id=<?php echo (int)$c['article_id']; ?>" target="_blank">
                                                <?php echo h(mb_substr($c['article_title'] ?? ('文章ID ' . $c['article_id']), 0, 16, 'UTF-8')); ?>
                                            </a>
                                        <?php else: ?>
                                            -
                                        <?php endif; ?>
                                    </td>
                                    <td><?php echo nl2br(h(mb_substr($c['content'] ?? '', 0, 32, 'UTF-8'))); ?></td>
                                    <td>
                                        <?php
                                        $isGuest = (int)$c['is_guest'] === 1;
                                        $userLabel = $isGuest
                                            ? ($c['guest_name'] !== null && $c['guest_name'] !== '' ? $c['guest_name'] : '匿名')
                                            : ($c['nickname'] ?? '会员');
                                        echo h($userLabel) . '<br>';
                                        $st = $c['status'] ?? 'pending';
                                        $badgeClass = 'badge-status badge-' . $st;
                                        $label = status_label_cn((string)$st, 'comment');
                                        echo '<span class="' . h($badgeClass) . '">' . h($label) . '</span>';
                                        ?>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                    <div class="small-text" style="margin-top:4px;">
                        <a href="comments.php">进入评论管理</a>
                    </div>
                <?php else: ?>
                    <div class="list-empty">还没有评论记录。</div>
                <?php endif; ?>
            </div>
        </div>

        <div class="card" style="margin-top: 16px;">
            <div class="card-title">服务器信息</div>
            <div class="small-text">
                PHP 版本：<?php echo h($serverInfo['php_version']); ?><br>
                Web 服务器：<?php echo h($serverInfo['server_software']); ?><br>
                操作系统：<?php echo h($serverInfo['os']); ?><br>
                数据库文件：<?php echo h($serverInfo['db_path']); ?><br>
                数据库大小：<?php
                    $size = (int)$serverInfo['db_size'];
                    if ($size <= 0) {
                        echo '未知';
                    } elseif ($size < 1024 * 1024) {
                        echo round($size / 1024, 1) . ' KB';
                    } else {
                        echo round($size / 1024 / 1024, 2) . ' MB';
                    }
                ?>
            </div>
        </div>

        <div class="card" style="margin-top: 16px;">
            <div class="card-title">最近 7 天站点概览</div>
            <div class="small-text">
                · 新发布文章：<?php echo $last7NewOverview['articles']; ?> 篇<br>
                · 新增评论：<?php echo $last7NewOverview['comments']; ?> 条<br>
                · 新注册用户：<?php echo $last7NewOverview['users']; ?> 个
            </div>

            <div class="small-text" style="margin-top:8px;">最近 7 天最热文章（Top 5）</div>
            <?php if ($topHotArticles7d): ?>
                <table>
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>标题</th>
                            <th>7 日 PV</th>
                            <th>7 日 UV</th>
                            <th>最近访问</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($topHotArticles7d as $a): ?>
                            <tr>
                                <td><?php echo (int)$a['article_id']; ?></td>
                                <td>
                                    <a href="../post.php?id=<?php echo (int)$a['article_id']; ?>" target="_blank">
                                        <?php echo h(mb_substr($a['title'] ?? '', 0, 30, 'UTF-8')); ?>
                                    </a>
                                </td>
                                <td><?php echo (int)$a['pv']; ?></td>
                                <td><?php echo (int)$a['uv']; ?></td>
                                <td><?php echo date('m-d H:i', (int)$a['last_visit']); ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php else: ?>
                <div class="small-text">最近 7 天还没有文章访问记录。</div>
            <?php endif; ?>

            <div class="small-text" style="margin-top:8px;">最近 7 天最活跃标签（Top 10）</div>
            <?php if ($topActiveTags7d): ?>
                <table>
                    <thead>
                        <tr>
                            <th>标签</th>
                            <th>7 日 PV</th>
                            <th>7 日 UV</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($topActiveTags7d as $t): ?>
                            <tr>
                                <td><?php echo h($t['tag_name']); ?></td>
                                <td><?php echo (int)$t['pv']; ?></td>
                                <td><?php echo (int)$t['uv']; ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php else: ?>
                <div class="small-text">最近 7 天标签还没有产生访问统计。</div>
            <?php endif; ?>
        </div>

        <div class="card" style="margin-top: 16px;">
            <div class="card-title">最近发布文章</div>
            <?php if ($recentArticles): ?>
                <table>
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>标题</th>
                            <th>时间</th>
                            <th>浏览</th>
                            <th>评论</th>
                            <th>点赞</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($recentArticles as $a): ?>
                            <tr>
                                <td><?php echo (int)$a['id']; ?></td>
                                <td>
                                    <a href="article_edit.php?id=<?php echo (int)$a['id']; ?>">
                                        <?php echo h(mb_substr($a['title'] ?? '', 0, 30, 'UTF-8')); ?>
                                    </a>
                                </td>
                                <td>
                                    <?php
                                    $ts = isset($a['published_at']) ? (int)$a['published_at'] : 0;
                                    echo $ts > 0 ? date('Y-m-d H:i', $ts) : '-';
                                    ?>
                                </td>
                                <td><?php echo (int)($a['view_count'] ?? 0); ?></td>
                                <td><?php echo (int)($a['comment_count'] ?? 0); ?></td>
                                <td><?php echo (int)($a['like_count'] ?? 0); ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php else: ?>
                <div class="small-text">
                    还没有已发布文章，你可以先在“文章”页面发布几篇，再回到这里查看效果。
                </div>
            <?php endif; ?>
        </div>

        <div class="footer">
            六柱 PHP 轻型博客源码 · 版权所有<br>
            官方网站：<a href="http://www.6zjz.com" target="_blank">www.6zjz.com</a>
        </div>
    </div>
</body>
</html>
