forked from htmlacademy-php/1415187-readme-12
-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.php
45 lines (35 loc) · 891 Bytes
/
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
44
45
<?php
require_once __DIR__ . '/libs/base.php';
$user = get_user();
$title = $site_name . ': Cтраница результатов поиска';
if ($user === null) {
header("Location: index.php");
exit();
}
if (!isset($_GET['keywords'])) {
display_404_page();
exit();
}
$keywords = trim($_GET['keywords']);
$search_results = search_posts($connection, $keywords) ?? null;
if (count($search_results) === 0) {
$title .= ' (нет результатов)';
}
$page_content = include_template(
'search-template.php',
[
'keywords' => $keywords,
'posts' => $search_results,
'now_time' => $now_time,
]
);
$layout_content = include_template(
'layout.php',
[
'title' => $title,
'user' => $user,
'content' => $page_content,
'active_section' => $active_section,
]
);
print($layout_content);