-
Notifications
You must be signed in to change notification settings - Fork 1
/
RSSFeed.php
48 lines (41 loc) · 1.09 KB
/
RSSFeed.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
<?php
require_once("RSSItem.php");
class RSSFeed {
public $title;
public $link;
public $description;
private $lastBuildDate;
private $rssItems=array();
public function __construct ($title, $link=null, $description=null) {
$this->title=$title;
$this->link=$link;
$this->description=$description;
}
public function setLastBuildDate (DateTime $lastBuildDate) {$this->lastBuildDate=$lastBuildDate;}
public function reverseRSSItems () {
$this->rssItems=array_reverse($this->rssItems);
}
public function addRSSItem (RSSItem $rssItem) {
$this->rssItems[]=$rssItem;
}
public function getXMLSource () {
$src=
'<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>'.htmlspecialchars($this->title).'</title>
<link>'.htmlspecialchars($this->link).'</link>
<description>'.htmlspecialchars($this->description).'</description>
<lastBuildDate>'.$this->lastBuildDate->format(DateTime::RSS).'</lastBuildDate>';
# <item>-s
for ($i=0; $i<sizeof($this->rssItems); $i++) {
$src.=$this->rssItems[$i]->getXMLSource();
}
$src.='
</channel>
</rss>
';
return $src;
}
}
?>