Upload via GUI (340 Dateien)

This commit is contained in:
2026-10-26 21:19:21 +00:00
parent d6df75ad64
commit 12699f0918
5 changed files with 117 additions and 24 deletions
+28 -13
View File
@@ -10,19 +10,35 @@ $pdo = get_db();
$q = trim($_GET['q'] ?? '');
if ($q !== '') {
$stmt = $pdo->prepare(
"SELECT a.*, c.name AS category_name FROM kb_articles a
JOIN kb_categories c ON c.id = a.category_id
WHERE a.is_published = 1 AND (a.title LIKE ? OR a.body LIKE ?)
ORDER BY a.views DESC"
);
$like = '%' . $q . '%';
$stmt->execute([$like, $like]);
$articles = $stmt->fetchAll();
$loadSearch = static function () use ($pdo, $q): array {
$stmt = $pdo->prepare(
"SELECT a.*, c.name AS category_name FROM kb_articles a
JOIN kb_categories c ON c.id = a.category_id
WHERE a.is_published = 1 AND (a.title LIKE ? OR a.body LIKE ?)
ORDER BY a.views DESC"
);
$like = '%' . $q . '%';
$stmt->execute([$like, $like]);
return $stmt->fetchAll();
};
$articles = function_exists('dhcm_cache_remember')
? dhcm_cache_remember('kb.search.' . $q, $loadSearch)
: $loadSearch();
$categories = [];
} else {
$categories = $pdo->query('SELECT * FROM kb_categories ORDER BY sort_order, name')->fetchAll();
$artStmt = $pdo->prepare('SELECT * FROM kb_articles WHERE category_id = ? AND is_published = 1 ORDER BY title');
$loadIndex = static function () use ($pdo): array {
$categories = $pdo->query('SELECT * FROM kb_categories ORDER BY sort_order, name')->fetchAll();
$articlesByCategory = [];
foreach ($pdo->query('SELECT * FROM kb_articles WHERE is_published = 1 ORDER BY title')->fetchAll() as $article) {
$articlesByCategory[(int) $article['category_id']][] = $article;
}
return ['categories' => $categories, 'articles' => $articlesByCategory];
};
$kbIndex = function_exists('dhcm_cache_remember')
? dhcm_cache_remember('kb.index', $loadIndex)
: $loadIndex();
$categories = $kbIndex['categories'] ?? [];
$articlesByCategory = $kbIndex['articles'] ?? [];
$articles = null;
}
@@ -54,8 +70,7 @@ require __DIR__ . '/includes/header_customer.php';
<div class="kb-category-grid">
<?php foreach ($categories as $i => $cat): ?>
<?php
$artStmt->execute([$cat['id']]);
$arts = $artStmt->fetchAll();
$arts = $articlesByCategory[(int) $cat['id']] ?? [];
if (!$arts) continue;
$anyArticles = true;
?>