summaryrefslogtreecommitdiffstats
path: root/admin/index.php
blob: 1f8d9f60c644ca5db315712ab7a4ae92b6385db7 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
#===============================================================================
# DEFINE: Administration
#===============================================================================
define('ADMINISTRATION', TRUE);
define('AUTHENTICATION', TRUE);

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

#===============================================================================
# TRY: PDOException
#===============================================================================
try {
	$execute = 'SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1';

	$LastPageStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE));
	$LastPostStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE));
	$LastUserStatement = $Database->query(sprintf($execute, User\Attribute::TABLE));

	$execute = 'SELECT COUNT(*) FROM %s';

	$PageCountStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE));
	$PostCountStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE));
	$UserCountStatement = $Database->query(sprintf($execute, User\Attribute::TABLE));
}

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

#===============================================================================
# TRY: Template\Exception
#===============================================================================
try {
	try {
		$LastPage = Page\Factory::build($LastPageStatement->fetchColumn());
		$LastPageUser = User\Factory::build($LastPage->attr('user'));

		$PageItemTemplate = generatePageItemTemplate($LastPage, $LastPageUser);
	}

	catch(Page\Exception $Exception){}
	catch(User\Exception $Exception){}

	try {
		$LastPost = Post\Factory::build($LastPostStatement->fetchColumn());
		$LastPostUser = User\Factory::build($LastPost->attr('user'));

		$PostItemTemplate = generatePostItemTemplate($LastPost, $LastPostUser);
	}

	catch(Post\Exception $Exception){}
	catch(User\Exception $Exception){}

	try {
		$LastUser = User\Factory::build($LastUserStatement->fetchColumn());
		$UserItemTemplate = generateUserItemTemplate($LastUser);
	} catch(User\Exception $Exception){}

	$HomeTemplate = Template\Factory::build('home');
	$HomeTemplate->set('LAST', [
		'PAGE' => $PageItemTemplate ?? FALSE,
		'POST' => $PostItemTemplate ?? FALSE,
		'USER' => $UserItemTemplate ?? FALSE,

	]);

	$HomeTemplate->set('COUNT', [
		'PAGE' => $PageCountStatement->fetchColumn(),
		'POST' => $PostCountStatement->fetchColumn(),
		'USER' => $UserCountStatement->fetchColumn(),
	]);

	$MainTemplate = Template\Factory::build('main');
	$MainTemplate->set('NAME', 'Dashboard');
	$MainTemplate->set('HTML', $HomeTemplate);
	echo $MainTemplate;
}

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