xgit simple git

nexus

nexus

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

api/search.php

1 <?php
2 require_once __DIR__ . '/../includes/bootstrap.php';
3 
4 $q = get('q');
5 if (mb_strlen($q) < 2) json_out(['topics' => [], 'posts' => []]);
6 
7 $like = '%' . $q . '%';
8 
9 // Topic title matches
10 $topics = DB::rows(
11     "SELECT t.id, t.title, t.slug, c.name AS cat, c.color AS cat_color
12      FROM topics t
13      JOIN categories c ON c.id = t.category_id
14      WHERE t.title LIKE ?
15      ORDER BY t.last_post_at DESC
16      LIMIT 6",
17     [$like]
18 );
19 
20 // Post content matches — include post_id for goto link
21 $posts = DB::rows(
22     "SELECT p.id AS post_id, p.content, p.post_num,
23             t.title AS topic_title, t.slug AS topic_slug,
24             u.username
25      FROM posts p
26      JOIN topics t ON t.id = p.topic_id
27      JOIN users u  ON u.id = p.user_id
28      WHERE p.content LIKE ? AND p.deleted = 0
29      ORDER BY p.created_at DESC
30      LIMIT 5",
31     [$like]
32 );
33 
34 json_out(['topics' => $topics, 'posts' => $posts]);