aboutsummaryrefslogtreecommitdiffstats
path: root/core/include/feed/main.php
blob: 9f1e4d47097257d9f9a0353869638be187275f33 (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
<?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');
	}

	$post_data = generateItemTemplateData($Post);
	$post_data['GUID'] = sha1($Post->getID().$Post->get('time_insert'));

	$ItemTemplate->set('POST', $post_data);
	$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;