aboutsummaryrefslogtreecommitdiffstats
path: root/core/include/feed/main.php
blob: cbabb2c98ddfd1ce67380535d61313be7f41a586 (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
<?php
#===============================================================================
# HEADER: Content-Type for XML document
#===============================================================================
HTTP::responseHeader(HTTP::HEADER_CONTENT_TYPE, HTTP::CONTENT_TYPE_XML);

#===============================================================================
# Get repositories
#===============================================================================
$PostRepository = Application::getRepository('Post');
$UserRepository = Application::getRepository('User');

#===============================================================================
# Get list of posts to show in the feed
#===============================================================================
$posts = $PostRepository->getPaginated(
	Application::get('POST.FEED_SORT'),
	Application::get('POST.FEED_SIZE')
);

#===============================================================================
# Build item templates
#===============================================================================
foreach($posts as $Post) {
	$User = $UserRepository->find($Post->get('user'));

	try {
		$ItemTemplate = Template\Factory::build('feed/item');
	} catch(Template\Exception $Exception) {
		# Backward compatibility if feed/item.php does not exist.
		$ItemTemplate = Template\Factory::build('feed/item_post');
	}

	$ItemTemplate->set('POST', generateItemTemplateData($Post));
	$ItemTemplate->set('USER', generateItemTemplateData($User));

	$templates[] = $ItemTemplate;
}

#===============================================================================
# Build document
#===============================================================================
$FeedTemplate = Template\Factory::build('feed/main');
$FeedTemplate->set('FEED', [
	'TYPE' => 'post',
	'LIST' => [
		'POSTS' => $templates ?? [],
		'PAGES' => [],
	]
]);

echo $FeedTemplate;