-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.php
148 lines (144 loc) · 6.09 KB
/
index.php
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
header('Content-type: application/atom+xml');
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
?>
<feed xmlns="http://www.w3.org/2005/Atom">
<?php
$path = "./";
require_once($path."autoloader.php");
require_once($path."functions.php");
require_once($path."db/SQLiteManager.php");
$id = $_REQUEST["id"];
if(!$id) {
die("no id");
}
$db = SQLiteManager\SQLiteManager::getInstance();
$result = $db->select("feeds", null, ["ID"=>$id]);
$feedInfo = $db->fetchArray($result)[0];
if(!$feedInfo) {
die("bad id ".$id);
}
$result = $db->select("filters", null, ["feedID"=>$feedInfo["ID"]]);
$feedInfo["patterns"] = $db->fetchArray($result);
$feed = new SimplePie();
$feed->enable_cache(false);
$feed->set_feed_url($feedInfo["feed"]);
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
?>
<title><?= $feed->get_title(); ?></title>
<?php
$protocol = 'http';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$protocol = 'https';
}
?>
<link href="<?= $protocol.'://'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI] ?>" rel="self"/>
<link href="<?= $feed->get_base(); ?>" />
<id><?= $feed->get_permalink(); ?></id>
<?php if($feed->get_authors()) { ?>
<?php foreach($feed->get_authors() as $author) { ?>
<author>
<?php if($author->get_name()) { ?>
<name><?= $author->get_name(); ?></name>
<?php } ?>
<?php if($author->get_email()) { ?>
<email><?= $author->get_email(); ?></email>
<?php } ?>
<?php if($author->get_link()) { ?>
<uri><?= $author->get_link(); ?></uri>
<?php } ?>
</author>
<?php } ?>
<?php } ?>
<?php if($feed->get_contributors()) { ?>
<?php foreach($feed->get_contributors() as $acontributor) { ?>
<contributor>
<?php if($contributor->get_name()) { ?>
<name><?= $contributor->get_name(); ?></name>
<?php } ?>
<?php if($contributor->get_email()) { ?>
<email><?= $contributor->get_email(); ?></email>
<?php } ?>
<?php if($contributor->get_link()) { ?>
<uri><?= $contributor->get_link(); ?></uri>
<?php } ?>
</contributor>
<?php } ?>
<?php } ?>
<?php if($feed->get_categories()) { ?>
<?php foreach($feed->get_categories() as $category) { ?>
<category term="<?= $category; ?>"/>
<?php } ?>
<?php } ?>
<?php if($feed->get_copyright()) { ?>
<rights><?= $feed->get_copyright(); ?></rights>
<?php } ?>
<?php if($feed->get_image_url()) { ?>
<logo><?= $feed->get_image_url(); ?></logo>
<?php } ?>
<updated><?= date("c"); ?></updated> <?php /* WARNING: simplepie doesn't provide ANY feed-level date */ ?>
<?php $i = 0; ?>
<?php foreach($feed->get_items() as $item) { ?>
<?php
if(!filter($item, $feedInfo)) {
continue;
}
?>
<entry>
<title><?= $item->get_title(); ?></title>
<link href="<?= $item->get_permalink(); ?>"/>
<id><?= $item->get_id(); ?></id>
<?php if($item->get_date()) { ?>
<published><?= $item->get_date("c"); ?></published>
<?php } ?>
<?php if($item->get_updated_date()) { ?>
<updated><?= $item->get_updated_date("c"); ?></updated>
<?php } ?>
<summary type="html"><![CDATA[<?= $item->get_description(); ?>]]></summary>
<?php if($item->get_content(true)) { ?>
<content type="html"><![CDATA[<?= $item->get_content(true); ?>]]></content>
<?php } ?>
<?php if($item->get_authors()) { ?>
<?php foreach($item->get_authors() as $author) { ?>
<author>
<?php if($author->get_name()) { ?>
<name><?= $author->get_name(); ?></name>
<?php } ?>
<?php if($author->get_email()) { ?>
<email><?= $author->get_email(); ?></email>
<?php } ?>
<?php if($author->get_link()) { ?>
<uri><?= $author->get_link(); ?></uri>
<?php } ?>
</author>
<?php } ?>
<?php } ?>
<?php if($item->get_contributors()) { ?>
<?php foreach($item->get_contributors() as $acontributor) { ?>
<contributor>
<?php if($contributor->get_name()) { ?>
<name><?= $contributor->get_name(); ?></name>
<?php } ?>
<?php if($contributor->get_email()) { ?>
<email><?= $contributor->get_email(); ?></email>
<?php } ?>
<?php if($contributor->get_link()) { ?>
<uri><?= $contributor->get_link(); ?></uri>
<?php } ?>
</contributor>
<?php } ?>
<?php } ?>
<?php if($item->get_categories()) { ?>
<?php foreach($item->get_categories() as $category) { ?>
<category<?php if($category->get_scheme()) { ?> scheme="<?= $category->get_scheme(); ?>"<?php } ?><?php if($category->get_term()) { ?> term="<?= $category->get_term(); ?>"<?php } ?><?php if($category->get_label()) { ?> label="<?= $category->get_label(); ?>"<?php } ?>/>
<?php } ?>
<?php } ?>
<?php if($item->get_copyright()) { ?>
<rights><?= $item->get_copyright(); ?></rights>
<?php } ?>
</entry>
<?php if(++$i == $feedInfo["maxItems"]) { break; } ?>
<?php } ?>
</feed>