aboutsummaryrefslogtreecommitdiffstats
path: root/core/include/home.php
blob: 507db7a65bbb1e30400122251cfe0be38ed549bb (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
<?php
#===============================================================================
# Get instances
#===============================================================================
$Database = Application::getDatabase();
$Language = Application::getLanguage();

$execSQL = 'SELECT id FROM %s ORDER BY '.Application::get('POST.LIST_SORT').' LIMIT '.Application::get('POST.LIST_SIZE');
$Statement = $Database->query(sprintf($execSQL, Post\Attribute::TABLE));

$postIDs = $Statement->fetchAll($Database::FETCH_COLUMN);

foreach($postIDs as $postID) {
	try {
		$Post = Post\Factory::build($postID);
		$User = User\Factory::build($Post->get('user'));

		$ItemTemplate = generatePostItemTemplate($Post, $User);

		$posts[] = $ItemTemplate;
	}
	catch(Post\Exception $Exception){}
	catch(User\Exception $Exception){}
}

#===============================================================================
# Build document
#===============================================================================
$HomeTemplate = Template\Factory::build('home');
$HomeTemplate->set('PAGINATION', [
	'HTML' => generatePostNaviTemplate(1)
]);
$HomeTemplate->set('LIST', [
	'POSTS' => $posts ?? []
]);

$MainTemplate = Template\Factory::build('main');
$MainTemplate->set('HTML', $HomeTemplate);
$MainTemplate->set('HEAD', [
	'NAME' => Application::get('BLOGMETA.HOME'),
	'DESC' => Application::get('BLOGMETA.NAME').' – '.Application::get('BLOGMETA.DESC'),
	'PERM' => Application::getURL()
]);

echo $MainTemplate;