-
Notifications
You must be signed in to change notification settings - Fork 1
/
RSSItem.php
43 lines (40 loc) · 1.38 KB
/
RSSItem.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
<?php
class RSSItem {
public $title;
public $link;
public $guid;
public $author;
public $enclosureURL;
public $enclosureType;
private $pubDate; # The parsed date string in rfc-2822
public $description;
# Replace ']]>' in CDATA with 2 blocks of CDATA - first block inserting ']]', second block '>'
# http://stackoverflow.com/questions/223652/is-there-a-way-to-escape-a-cdata-end-token-in-xml/18405980#18405980
public static function escapeCDataString ($cDataString) {
return str_replace(']]>', ']]]]><![CDATA[>', $cDataString);
}
public function getPubDate () {return $this->pubDate;}
public function setPubDate (DateTime $pubDate) {$this->pubDate=$pubDate;}
public function getXMLSource() {
$src='
<item>
<title><![CDATA['.self::escapeCDataString($this->title).']]></title>
<link>'.htmlspecialchars($this->link).'</link>
<guid>'.htmlspecialchars($this->guid).'</guid>';
if (!empty($this->author)) {
$src .= '
<author><![CDATA['.self::escapeCDataString($this->author).']]></author>';
}
if (!empty($this->enclosure_url)) {
$src.='
<enclosure url="'.urlencode($rssItem->enclosureURL).'" type="'.htmlspecialchars($rssItems->enclosureType).'"/>';
}
$src.='
<pubDate>'.$this->pubDate->format(DateTime::RSS).'</pubDate>
<description><![CDATA['.self::escapeCDataString($this->description).']]></description>
</item>';
#return str_replace("\t",'',$src);
return $src;
}
}
?>