1<?php
2require_once __DIR__ . '/includes/bootstrap.php';
3
4$PAGE_TITLE = cfg('site_name', 'Nexus Forum');
5
6$cats = DB::rows("
7 SELECT c.*,
8 (SELECT t.title FROM topics t WHERE t.category_id=c.id ORDER BY t.last_post_at DESC LIMIT 1) AS last_title,
9 (SELECT t.slug FROM topics t WHERE t.category_id=c.id ORDER BY t.last_post_at DESC LIMIT 1) AS last_slug
10 FROM categories c WHERE c.parent_id IS NULL ORDER BY c.position, c.id
11");
12
13$recent = DB::rows("
14 SELECT t.*, u.username, u.avatar, c.name AS cat_name, c.slug AS cat_slug, c.color AS cat_color
15 FROM topics t
16 JOIN users u ON u.id = t.user_id
17 JOIN categories c ON c.id = t.category_id
18 WHERE t.archived = 0
19 ORDER BY t.last_post_at DESC LIMIT 15
20");
21
22$stats = [
23 'topics' => (int) DB::val('SELECT COUNT(*) FROM topics'),
24 'posts' => (int) DB::val('SELECT COUNT(*) FROM posts WHERE deleted=0'),
25 'users' => (int) DB::val('SELECT COUNT(*) FROM users'),
26 'newest' => DB::row('SELECT username FROM users ORDER BY joined_at DESC LIMIT 1'),
27];
28
29include __DIR__ . '/views/partials/layout.php';
30?>
31
32<div class="home-hero">
33 <h1><?= e(cfg('site_name','Nexus Forum')) ?></h1>
34 <p><?= e(cfg('site_desc','A community for discussion.')) ?></p>
35 <?php if (!$USER): ?>
36 <div class="hero-btns">
37 <a href="<?= u('auth/register.php') ?>" class="btn-primary btn-lg">Join the Community</a>
38 <a href="<?= u('auth/login.php') ?>" class="btn-ghost btn-lg">Log In</a>
39 </div>
40 <?php else: ?>
41 <a href="<?= u('forum/new-topic.php') ?>" class="btn-primary btn-lg">+ New Topic</a>
42 <?php endif; ?>
43</div>
44
45<div class="stats-row">
46 <div class="stat"><strong><?= number_format($stats['topics']) ?></strong><span>Topics</span></div>
47 <div class="stat-div"></div>
48 <div class="stat"><strong><?= number_format($stats['posts']) ?></strong><span>Posts</span></div>
49 <div class="stat-div"></div>
50 <div class="stat"><strong><?= number_format($stats['users']) ?></strong><span>Members</span></div>
51 <?php if ($stats['newest']): ?>
52 <div class="stat-div"></div>
53 <div class="stat"><span>Newest: <a href="<?= u('users/profile.php?u=' . urlencode($stats['newest']['username'])) ?>">@<?= e($stats['newest']['username']) ?></a></span></div>
54 <?php endif; ?>
55</div>
56
57<div class="home-grid">
58 <section>
59 <h2 class="sec-title">Categories</h2>
60 <?php foreach ($cats as $c): ?>
61 <a href="<?= u('forum/category.php?slug=' . urlencode($c['slug'])) ?>" class="cat-card">
62 <div class="cat-stripe" style="background:<?= e($c['color']) ?>"></div>
63 <div class="cat-icon" style="color:<?= e($c['color']) ?>"><?= e($c['icon']) ?></div>
64 <div class="cat-body">
65 <div class="cat-name"><?= e($c['name']) ?></div>
66 <div class="cat-desc"><?= e($c['description']) ?></div>
67 <div class="cat-stats"><?= $c['topic_count'] ?> topics · <?= $c['post_count'] ?> posts</div>
68 </div>
69 <div class="cat-chevron">›</div>
70 </a>
71 <?php endforeach; ?>
72 <?php if (empty($cats)): ?>
73 <p class="empty-msg">No categories yet.</p>
74 <?php endif; ?>
75 </section>
76
77 <section>
78 <h2 class="sec-title">Latest Activity</h2>
79 <?php foreach ($recent as $t): ?>
80 <div class="topic-row">
81 <?php if ($t['avatar']): ?>
82 <img src="<?= e($t['avatar']) ?>" class="av-sm" alt="">
83 <?php else: ?>
84 <span class="av-sm av-init"><?= strtoupper($t['username'][0]) ?></span>
85 <?php endif; ?>
86 <div class="tr-body">
87 <a href="<?= u('forum/topic.php?slug=' . urlencode($t['slug'])) ?>" class="tr-title">
88 <?= e($t['title']) ?>
89 </a>
90 <div class="tr-meta">
91 <a href="<?= u('forum/category.php?slug=' . urlencode($t['cat_slug'])) ?>" class="cat-tag" style="--cc:<?= e($t['cat_color']) ?>"><?= e($t['cat_name']) ?></a>
92 by <a href="<?= u('users/profile.php?u=' . urlencode($t['username'])) ?>">@<?= e($t['username']) ?></a>
93 <span class="ago" data-ts="<?= e($t['last_post_at']) ?>"></span>
94 </div>
95 </div>
96 <div class="tr-counts">
97 <span>💬 <?= $t['reply_count'] ?></span>
98 </div>
99 </div>
100 <?php endforeach; ?>
101 <?php if (empty($recent)): ?>
102 <p class="empty-msg">No topics yet. <a href="<?= u('forum/new-topic.php') ?>">Start one!</a></p>
103 <?php endif; ?>
104 </section>
105</div>
106
107<?php include __DIR__ . '/views/partials/layout_end.php'; ?>