-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed.php
38 lines (33 loc) · 1.15 KB
/
feed.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
<?php
header("Content-type: text/xml; charset=utf-8");
$API_BASE_URL = "https://metropole.rennes.fr/";
$ITEMS_LIMIT = 20;
$content = file_get_contents(
$API_BASE_URL . "articles?maxResultsByPage=" . $ITEMS_LIMIT,
false,
stream_context_create(array("ssl" => array('cafile' => './cert.pem'))),
);
if (!$content) {
http_response_code(404);
print("Error");
return;
}
$data = json_decode($content, $assoc = true);
print('<?xml version="1.0" encoding="UTF-8"?>');
?>
<rss version="2.0">
<channel>
<title>Ici Rennes Off</title>
<description>Flux non officiel d'Ici Rennes</description>
<link>https://metropole.rennes.fr/</link>
<lastBuildDate><?php echo (new DateTime())->format("r") ?></lastBuildDate>
<?php foreach ($data["articles"] as $article) { ?>
<item>
<title><?php echo $article["title"] ?></title>
<link><?php echo $article["url"] ?></link>
<pubDate><?php echo (new DateTime())->setTimestamp($article["date"])->format("r") ?></pubDate>
<description></description>
</item>
<?php } ?>
</channel>
</rss>