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

#===============================================================================
# TRY: Post\Exception
#===============================================================================
try {
	if(Application::get('POST.SLUG_URLS')) {
		$Post = Post\Factory::buildBySlug($param);
	}

	else {
		$Post = Post\Factory::build($param);
	}

	$User = User\Factory::build($Post->attr('user'));

	$post_data = generateItemTemplateData($Post);
	$user_data = generateItemTemplateData($User);

	#===============================================================================
	# Add post data for previous and next post
	#===============================================================================
	try {
		$PrevPost = Post\Factory::build($Post->getPrevID());
		$post_data['PREV'] = generateItemTemplateData($PrevPost);
	} catch(Post\Exception $Exception){}

	try {
		$NextPost = Post\Factory::build($Post->getNextID());
		$post_data['NEXT'] = generateItemTemplateData($NextPost);
	} catch(Post\Exception $Exception){}

	#===============================================================================
	# Build document
	#===============================================================================
	$PostTemplate = Template\Factory::build('post/main');
	$PostTemplate->set('POST', $post_data);
	$PostTemplate->set('USER', $user_data);

	$MainTemplate = Template\Factory::build('main');
	$MainTemplate->set('HTML', $PostTemplate);
	$MainTemplate->set('HEAD', [
		'NAME' => $post_data['ATTR']['NAME'],
		'DESC' => description($post_data['BODY']['HTML'](), Application::get('POST.DESCRIPTION_SIZE')),
		'PERM' => $post_data['URL'],
		'OG_IMAGES' => $post_data['FILE']['LIST']
	]);

	# Get access to the current item data from main template
	$MainTemplate->set('TYPE', 'POST');
	$MainTemplate->set('POST', $post_data);
	$MainTemplate->set('USER', $user_data);

	echo $MainTemplate;
}

#===============================================================================
# CATCH: Post\Exception
#===============================================================================
catch(Post\Exception $Exception) {
	try {
		if(Application::get('POST.SLUG_URLS') === FALSE) {
			$Post = Post\Factory::buildBySlug($param);
		} else {
			$Post = Post\Factory::build($param);
		}

		HTTP::redirect(Application::getEntityURL($Post));
	}

	catch(Post\Exception $Exception) {
		Application::error404();
	}
}