Ticket #8551: rss20.php

File rss20.php, 1.7 KB (added by SF/musuruan, 18 years ago)

PHP file to generate an RSS 2.0 feed

Line 
1<?php
2$file_root = ".";
3
4// load libraries
5require($file_root."/include/"."incl.php");
6
7//display News
8
9// get list of news items
10$news = get_files($file_root."/news","xml");
11$news = array_reverse ($news);
12
13header("Content-type: text/xml");
14?>
15<rss version="2.0">
16 <channel>
17 <title>ScummVM</title>
18 <link>http://www.scummvm.org/</link>
19 <description>ScummVM - http://www.scummvm.org/</description>
20 <language>en</language>
21
22<?
23
24// loop and display news
25$c = 0;
26while (list($key,$item) = each($news)) {
27 $c++;
28
29 // Load news item (it's in a pseudo XML format).
30 $file = $file_root."/news/".$item;
31 if (file_exists($file)) {
32 $fp = @fopen($file, "r");
33 $data = fread($fp, filesize($file));
34 @fclose($fp);
35
36 $news_date = "";
37 if (eregi("<DATE>(.*)</DATE>", $data, $out)) {
38 $news_date = strtotime($out[1]);
39 }
40
41 $news_author = "";
42 if (eregi("<AUTHOR>(.*)</AUTHOR>", $data, $out)) {
43 $news_author = "Posted by ".$out[1];
44 }
45
46 $news_title = "";
47 if (eregi("<NAME>(.*)</NAME>", $data, $out)) {
48 $news_title = $out[1];
49 }
50
51 $news_img = "";
52 if (eregi("<IMG>(.*)</IMG>", $data, $out)) {
53 $news_img = $out[1];
54 }
55
56 $news_body = "";
57 if (eregi("<BODY>(.*)</BODY>", $data, $out)) {
58 $news_body = $out[1];
59 }
60 }
61
62 // Display news item
63
64 echo '<item>'.
65 '<title>'.htmlentities($news_title).'</title>'.
66 '<link>http://www.scummvm.org/index.php#'.date("Y-m-d", $news_date).'</link>'.
67 '<description>'.htmlentities($news_body).'</description>'.
68 '<pubDate>'.date("r", $news_date).'</pubDate>'.
69 '</item>';
70
71
72 // Only show first five records
73 if ($c == 4) {
74 break;
75 }
76} // end of news loop
77?>
78
79 </channel>
80</rss>