xgit simple git

nexus

nexus

clone git clone https://kb.hax.al/nexus

forum/category.php

1 <?php
2 require_once __DIR__ . '/../includes/bootstrap.php';
3 
4 $slug = get('slug');
5 $cat  = DB::row('SELECT * FROM categories WHERE slug=?', [$slug]);
6 if (!$cat) render_404();
7 if (!can_read_category($cat)) render_403();
8 
9 $page = max(1, (int)get('page','1'));
10 $pp   = (int)cfg('topics_per_page','30');
11 $off  = ($page - 1) * $pp;
12 
13 $topics = DB::rows("
14     SELECT t.*, u.username, u.avatar,
15       (SELECT u2.username FROM posts p2 JOIN users u2 ON u2.id=p2.user_id
16        WHERE p2.topic_id=t.id ORDER BY p2.created_at DESC LIMIT 1) AS last_poster,
17       (SELECT COUNT(*)-1 FROM posts p WHERE p.topic_id=t.id AND p.deleted=0) AS replies
18     FROM topics t JOIN users u ON u.id=t.user_id
19     WHERE t.category_id=? AND t.archived=0
20     ORDER BY t.pinned DESC, t.last_post_at DESC
21     LIMIT ? OFFSET ?
22 ", [$cat['id'], $pp, $off]);
23 
24 $total = (int) DB::val('SELECT COUNT(*) FROM topics WHERE category_id=? AND archived=0', [$cat['id']]);
25 $pages = max(1, (int)ceil($total / $pp));
26 $subs  = DB::rows('SELECT * FROM categories WHERE parent_id=? ORDER BY position', [$cat['id']]);
27 
28 $PAGE_TITLE = $cat['name'];
29 include __DIR__ . '/../views/partials/layout.php';
30 ?>
31 <nav class="bc"><a href="<?= u('/') ?>">Home</a> โ€บ <span><?= e($cat['name']) ?></span></nav>
32 
33 <div class="cat-hdr" style="border-left:4px solid <?= e($cat['color']) ?>">
34   <span class="cat-hdr-icon"><?= e($cat['icon']) ?></span>
35   <div>
36     <h1><?= e($cat['name']) ?></h1>
37     <p><?= e($cat['description']) ?></p>
38     <div class="cat-hdr-meta"><?= $total ?> topics ยท <?= $cat['post_count'] ?> posts</div>
39   </div>
40   <?php if ($USER): ?>
41     <a href="<?= u('forum/new-topic.php?cat=' . $cat['id']) ?>" class="btn-primary">+ New Topic</a>
42   <?php endif; ?>
43 </div>
44 
45 <?php if ($subs): ?>
46   <div class="subcats">
47     <?php foreach ($subs as $s): ?>
48       <a href="<?= u('forum/category.php?slug=' . urlencode($s['slug'])) ?>" class="subcat" style="border-color:<?= e($s['color']) ?>"><?= e($s['icon']) ?> <?= e($s['name']) ?></a>
49     <?php endforeach; ?>
50   </div>
51 <?php endif; ?>
52 
53 <div class="topic-list">
54   <div class="tl-hdr"><span>Topic</span><span class="tl-r">Replies</span><span class="tl-r">Views</span><span class="tl-r">Activity</span></div>
55   <?php foreach ($topics as $t): ?>
56     <div class="tl-row <?= $t['pinned'] ? 'is-pinned' : '' ?>">
57       <div class="tl-main">
58         <?php if ($t['avatar']): ?>
59           <img src="<?= e($t['avatar']) ?>" class="av-sm" alt="">
60         <?php else: ?>
61           <span class="av-sm av-init"><?= strtoupper($t['username'][0]) ?></span>
62         <?php endif; ?>
63         <div>
64           <div class="tl-title">
65             <?php if ($t['pinned']): ?><span title="Pinned">๐Ÿ“Œ</span><?php endif; ?>
66             <?php if ($t['closed']): ?><span title="Closed">๐Ÿ”’</span><?php endif; ?>
67             <a href="<?= u('forum/topic.php?slug=' . urlencode($t['slug'])) ?>"><?= e($t['title']) ?></a>
68           </div>
69           <div class="tl-meta">
70             by <a href="<?= u('users/profile.php?u=' . urlencode($t['username'])) ?>">@<?= e($t['username']) ?></a>
71             <?php if ($t['last_poster'] && $t['last_poster'] !== $t['username']): ?>
72               ยท last by @<?= e($t['last_poster']) ?>
73             <?php endif; ?>
74           </div>
75         </div>
76       </div>
77       <div class="tl-r"><?= max(0,(int)$t['replies']) ?></div>
78       <div class="tl-r"><?= $t['views'] ?></div>
79       <div class="tl-r"><span class="ago" data-ts="<?= e($t['last_post_at']) ?>"></span></div>
80     </div>
81   <?php endforeach; ?>
82   <?php if (empty($topics)): ?>
83     <div class="empty-state">
84       <p>No topics yet.</p>
85       <?php if ($USER): ?>
86         <a href="<?= u('forum/new-topic.php?cat=' . $cat['id']) ?>" class="btn-primary">Start the first one!</a>
87       <?php endif; ?>
88     </div>
89   <?php endif; ?>
90 </div>
91 
92 <?php if ($pages > 1): ?>
93   <nav class="pager">
94     <?php if ($page > 1): ?><a href="?slug=<?= urlencode($slug) ?>&page=<?= $page-1 ?>" class="pg-btn">โ† Prev</a><?php endif; ?>
95     <?php for ($i=max(1,$page-2); $i<=min($pages,$page+2); $i++): ?>
96       <a href="?slug=<?= urlencode($slug) ?>&page=<?= $i ?>" class="pg-btn <?= $i===$page?'active':'' ?>"><?= $i ?></a>
97     <?php endfor; ?>
98     <?php if ($page < $pages): ?><a href="?slug=<?= urlencode($slug) ?>&page=<?= $page+1 ?>" class="pg-btn">Next โ†’</a><?php endif; ?>
99   </nav>
100 <?php endif; ?>
101 
102 <?php include __DIR__ . '/../views/partials/layout_end.php'; ?>