forked from fossar/selfoss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRss.php
More file actions
87 lines (72 loc) · 2.7 KB
/
Rss.php
File metadata and controls
87 lines (72 loc) · 2.7 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?PHP
namespace controllers;
/**
* Controller for rss access
*
* @package controllers
* @copyright Copyright (c) Tobias Zeising (http://www.aditu.de)
* @license GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
* @author Tobias Zeising <tobias.zeising@aditu.de>
*/
class Rss extends BaseController {
/**
* rss feed
*
* @return void
*/
public function rss() {
$feedWriter = new \FeedWriter(\RSS2);
$feedWriter->setTitle(\F3::get('rss_title'));
$feedWriter->setLink($this->view->base);
// get sources
$sourceDao = new \daos\Sources();
$lastSourceId = 0;
$lastSourceName = "";
// set options
$options = array();
if(count($_GET)>0)
$options = $_GET;
$options['items'] = \F3::get('rss_max_items');
if(\F3::get('PARAMS["tag"]')!=null)
$options['tag'] = \F3::get('PARAMS["tag"]');
// get items
$newestEntryDate = false;
$lastid = -1;
$itemDao = new \daos\Items();
foreach($itemDao->get($options) as $item) {
if($newestEntryDate===false)
$newestEntryDate = $item['datetime'];
$newItem = $feedWriter->createNewItem();
// get Source Name
if ($item['source'] != $lastSourceId){
foreach($sourceDao->get() as $source) {
if ($source['id'] == $item['source']) {
$lastSourceId = $source['id'];
$lastSourceName = $source['title'];
break;
}
}
}
$newItem->setTitle(str_replace('&', '&', html_entity_decode(utf8_decode($item['title'] . " (" . $lastSourceName . ")"))));
@$newItem->setLink($item['link']);
$newItem->setDate($item['datetime']);
$newItem->setDescription(str_replace('"', '"', $item['content']));
// add tags in category node
$itemsTags = explode(",",$item['tags']);
foreach($itemsTags as $tag) {
$tag = trim($tag);
if(strlen($tag)>0)
$newItem->addElement('category', $tag);
}
$feedWriter->addItem($newItem);
$lastid = $item['id'];
}
if($newestEntryDate===false)
$newestEntryDate = date(\DATE_ATOM , time());
$feedWriter->setChannelElement('updated', $newestEntryDate);
// mark as read
if(\F3::get('rss_mark_as_read')==1 && $lastid!=-1)
$itemDao->mark($lastid);
$feedWriter->genarateFeed();
}
}