This repository was archived by the owner on Jun 9, 2022. It is now read-only.
forked from getkirby-v2/feed-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
73 lines (63 loc) · 2.57 KB
/
index.php
File metadata and controls
73 lines (63 loc) · 2.57 KB
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
<?php
/**
* Feed Plugin
*
* @version 3.0.0
*/
Kirby::plugin('the-streamable/feed', [
'pagesMethods' => [
'feed' => function ($params = []) {
// set all default values
$defaults = [
'url' => url(),
'title' => 'Feed',
'description' => '',
'link' => url(),
'datefield' => 'date',
'textfield' => 'text',
'descriptionfield' => 'description',
'itemtextoverride' => null, // function ($item) { return $item->text()->kirbytext(); }
'itemdescriptionoverride' => null, // function ($item) { return $item->description()->kti(); }
'modified' => time(),
'excerpt' => false,
'generator' => kirby()->option('feed.generator', 'Kirby'),
'header' => true,
'snippet' => false,
'creatorfield' => false,
'enclosurefield' => false,
'languagecode' => kirby()->language() ? kirby()->language()->code() : 'en',
];
// merge them with the user input
$options = array_merge($defaults, $params);
// sort by date
$items = $this->sortBy($options['datefield'], 'desc');
// add the items
$options['items'] = $items;
$options['link'] = url($options['link']);
// fetch the modification date
if ($items->count()) {
if ($options['datefield'] == 'modified') {
$options['modified'] = $items->first()->modified();
}
else {
$dateFieldName = $options['datefield'];
$options['modified'] = $items->first()->$dateFieldName()->toDate();
}
}
// send the xml header
if ($options['header']) {
header::type('text/xml');
}
// echo the doctype
$html = '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL;
// custom snippet
if ($options['snippet']) {
$html .= snippet($options['snippet'], $options, true);
}
else {
$html .= tpl::load(__DIR__ . '/template.php', $options);
}
return $html;
}
]
]);