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

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

while($Attribute = $Statement->fetchObject('Post\Attribute')) {
	try {
		$Post = Post\Factory::buildByAttribute($Attribute);
		$User = User\Factory::build($Post->attr('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;