1<?php
2/**
3 * Title: Search
4 * Icon: fa-search
5 * Group: Overview
6 * Order: 5
7 * Hidden: true
8 * Description: Everything in the panel, by name or by what a setting does.
9 */
10
11if (!defined('ACP_ROOT')) {
12 http_response_code(403);
13 die('Direct access denied.');
14}
15
16$query = trim((string)($_GET['q'] ?? ''));
17$results = acp_search($query);
18
19$pages = array_values(array_filter($results, static fn(array $r): bool => $r['kind'] === 'page'));
20$settings = array_values(array_filter($results, static fn(array $r): bool => $r['kind'] === 'setting'));
21
22$highlight = static function (string $text, string $q): string {
23 $text = h($text);
24 foreach (preg_split('/\s+/', trim($q)) ?: [] as $term) {
25 if ($term === '') continue;
26 $text = preg_replace('/(' . preg_quote(h($term), '/') . ')/i', '<mark>$1</mark>', $text);
27 }
28 return $text;
29};
30?>
31
32<form class="acp-search-page" method="get">
33 <input type="hidden" name="p" value="search">
34 <div class="acp-field">
35 <input class="acp-input acp-input--lg" type="search" name="q" value="<?= h($query) ?>"
36 placeholder="<?= h(t('acp.search.placeholder')) ?>" autofocus>
37 </div>
38</form>
39
40<?php if ($query === ''): ?>
41 <div class="acp-flash acp-flash--info">
42 <i class="fa fa-info-circle"></i>
43 <span>
44 <?= str_replace(
45 ['{download}', '{paypal}', '{auction}'],
46 ['<code>download</code>', '<code>paypal</code>', '<code>auction</code>'],
47 h(t('acp.search.hint'))
48 ) ?>
49 </span>
50 </div>
51<?php elseif (!$results): ?>
52 <div class="acp-flash acp-flash--error">
53 <i class="fa fa-exclamation-triangle"></i>
54 <span><?= t('acp.search.nothing') ?> <strong><?= h($query) ?></strong>.</span>
55 </div>
56<?php else: ?>
57
58 <p class="acp-hint">
59 <?= t('acp.search.results_line', [
60 'count' => count($results),
61 'noun' => (count($results) === 1) ? t('acp.search.result_one') : t('acp.search.result_many'),
62 ]) ?> <strong><?= h($query) ?></strong>
63 </p>
64
65 <?php foreach (array(t('acp.search.section_pages') => $pages, t('acp.search.section_settings') => $settings) as $heading => $rows): ?>
66 <?php if (!$rows) continue; ?>
67 <section class="acp-card">
68 <header class="acp-card-head"><h2><?= h($heading) ?></h2></header>
69 <div class="acp-card-body is-flush">
70 <ul class="acp-search-results">
71 <?php foreach ($rows as $row): ?>
72 <li>
73 <a href="<?= h($row['url']) ?>">
74 <i class="fa <?= h($row['icon']) ?>"></i>
75 <span class="acp-search-main">
76 <span class="acp-search-title"><?= $highlight($row['title'], $query) ?></span>
77 <span class="acp-search-ctx"><?= $row['context'] ?></span>
78 <?php if (!empty($row['detail'])): ?>
79 <span class="acp-search-detail"><?= $highlight($row['detail'], $query) ?></span>
80 <?php endif; ?>
81 </span>
82 <i class="fa fa-angle-right acp-search-go"></i>
83 </a>
84 </li>
85 <?php endforeach; ?>
86 </ul>
87 </div>
88 </section>
89 <?php endforeach; ?>
90
91<?php endif; ?>
92