-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.php
63 lines (57 loc) · 2.55 KB
/
news.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
<?php
$json = file_get_contents("../cron-data/news.json");
$obj = json_decode($json);
$html = "";
if(isset($_GET["format"]) && $_GET["format"] == "xml") {
header('Content-Type: application/rss+xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"';
?>
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
<channel>
<title>Le beau jeu</title>
<atom:link href="https://lebeaujeu.com/news.php?format=xml" rel="self" type="application/rss+xml" />
<link>https://lebeaujeu.com/news</link>
<description>Le beau jeu</description>
<lastBuildDate><?php echo date("r"); ?></lastBuildDate>
<language>fr-FR</language>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<?php
if(isset($obj->news)) {
foreach ($obj->news as $news){
if($news->slack == 'true') {
$html = $html."<item>\n" .
"<title><![CDATA[".$news->title."]]></title>\n" .
"<link>".htmlentities($news->link)."</link>\n" .
"<pubDate>".date("r",$news->timestamp)."</pubDate>\n<dc:creator><![CDATA[Todo]]></dc:creator>\n";
foreach ($news->categories as $cat){
$html = $html."<category><![CDATA[".$cat."]]></category>\n";
}
$html = $html."<description><![CDATA[".substr(trim(str_replace(" ","",strip_tags($news->description))), 0, 1000)."]]></description>\n</item>\n";
}
}
echo $html;
}
?>
</channel>
</rss><?php
} else {
if(isset($obj->news)) {
foreach ($obj->news as $news){
$cats = implode(', ',$news->categories);
if(!empty($cats)) $cats = "(".$cats.")";
$html = $html."<article><img class='logo' src='".$news->flux->logo."' /><h1>".$news->title."</h1>" .
"<h2>".$news->date." - ".$news->flux->name." ".$cats." ".($news->slack == "true" ? "(Slacké)" : "")."</h2>" .
"<h2><a href='".$news->link."'>".$news->link."</a></h2>" .
"<div class='description'><p>".substr(trim(str_replace(" ","",strip_tags($news->description))), 0, 1000)."</p></div></article>";
}
}
//file_put_contents("toto.txt",$html);
echo $html;
}