aboutsummaryrefslogtreecommitdiffstats
path: root/admin/page/search.php
blob: e71a8b837b72b080c937da0d54d38d7c53bac552 (plain)
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
46
47
48
49
50
51
<?php
#===============================================================================
# DEFINE: Administration
#===============================================================================
define('ADMINISTRATION', TRUE);
define('AUTHENTICATION', TRUE);

#===============================================================================
# INCLUDE: Initialization
#===============================================================================
require '../../core/application.php';

#===============================================================================
# IF: Handle search request
#===============================================================================
if($search = HTTP::GET('q')) {
	if($pageIDs = Page\Item::getSearchResultIDs($search, $Database)) {
		foreach($pageIDs as $pageID) {
			try {
				$Page = Page\Factory::build($pageID);
				$User = User\Factory::build($Page->attr('user'));

				$pages[] = generatePageItemTemplate($Page, $User);
			}
			catch(Page\Exception $Exception){}
			catch(User\Exception $Exception){}
		}
	}
}

#===============================================================================
# TRY: Template\Exception
#===============================================================================
try {
	$SearchTemplate = Template\Factory::build('page/search');
	$SearchTemplate->set('QUERY', $search);
	$SearchTemplate->set('PAGES', $pages ?? []);

	$MainTemplate = Template\Factory::build('main');
	$MainTemplate->set('NAME', $Language->text('title_page_search'));
	$MainTemplate->set('HTML', $SearchTemplate);

	echo $MainTemplate;
}

#===============================================================================
# CATCH: Template\Exception
#===============================================================================
catch(Template\Exception $Exception) {
	Application::exit($Exception->getMessage());
}