forked from srobo/srweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createfeed.inc.php
74 lines (45 loc) · 1.91 KB
/
createfeed.inc.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
<?php
/*
* Returns the content of the feed to be served. This function is
* used both with and without caching functionality (see above).
*/
function getFeedContent(){
require_once('config.inc.php');
require_once('classes/Content.class.php');
$newsItems = array();
if ($d = opendir(CONTENT_DIR . '/en/news')){
//get the files
while (false !== ($file = readdir($d)))
if (substr($file, 0, 1) != ".")//ignore {., .., .gitignore, etc...}
$newsItems[] = new Content(CONTENT_DIR . '/en/news/' . $file);
closedir($d);
//build output based on the Content objects
if (count($newsItems) > 0){
$output = "<?xml version='1.0'?><rss version='2.0'><channel>";
$output .= "<title>Student Robotics Latest News</title>";
$output .= "<link>" . BASE_URI . "news/</link>";
$output .= "<lastBuildDate>" . date(DATE_RSS) . "</lastBuildDate>";
$output .= "<description>All the latest news from Student Robotics</description>";
usort($newsItems, "dateStrCmp");
foreach ($newsItems as $newsItem){
$output .= "<item>";
$output .= "<title><![CDATA[" . $newsItem->getMeta('TITLE') . "]]></title>";
$output .= "<link>" . BASE_URI . str_replace(CONTENT_DIR . '/en/', '', $newsItem->filename) . "</link>";
$output .= "<guid>" . BASE_URI . str_replace(CONTENT_DIR . '/en/', '', $newsItem->filename) . "</guid>";
$output .= "<description><![CDATA[" . $newsItem->getMeta('DESCRIPTION') . "]]></description>";
$output .= "<pubDate>" . date(DATE_RSS, strtotime($newsItem->getPubDate())) . "</pubDate>";
$output .= "</item>";
}//foreach
$output .= "</channel></rss>";
return $output;
}
}
//return NULL if no success
return NULL;
}//getFeedContent
function dateStrCmp($a, $b){
if (strtotime($a->getPubDate()) == strtotime($b->getPubDate()))
return 0;
return strtotime($a->getPubDate()) > strtotime($b->getPubDate()) ? -1 : 1;
}//dateStrCmp
?>