-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch.php
43 lines (37 loc) · 1.11 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
include 'include/context.php';
$q = isset($_GET['q']) ? $_GET['q'] : '';
$notes = get_notes();
$results = array();
$limit = 24;
if ($q) {
foreach ($notes as $id => $note) {
$content = sprintf(
"%s %s %s %s",
$note['url'], $note['title'], $note['quote'], $note['note']
);
if (strpos(strtolower($content), strtolower($q))) {
$results[$id] = $note;
}
}
$label = count($results) . ' search results';
} else {
$results = $notes;
$label = $limit . ' recent notes';
}
$results = array_slice($results, 0, $limit, true);
?>
<?php include 'include/header.php'; ?>
<?php include 'include/menu.php'; ?>
<div class="main">
<div class="center">
<form class="search" action="/search.php" method="get" autocomplete="off">
<input name="q" type="text" value="<?= $q ?>" placeholder="Keywords" autofocus onfocus="this.selectionStart = this.selectionEnd = this.value.length" />
</form>
<?php foreach ($results as $id => $note): ?>
<?php include 'include/compact.php'; ?>
<?php endforeach; ?>
<div class="status"><?= $label ?></div>
</div>
</div>
<?php include 'include/footer.php'; ?>