class RSS {
var $ver;
var $items;
var $channel;
var $encoding;
function RSS($version = 2, $encoding = 'utf-8') {
if ($version != 2) $version = 1;
$this->ver = $version;
$this->items = array();
$this->channel = array();
$this->encoding = $encoding;
}
function channel($params) {
$this->channel = $params;
}
function addItem($params) {
$this->items[] = $params;
}
function addErrorItem($title, $url, $author, $description) {
$this->items[] = array(
'title' => RSS::pl2utf(htmlspecialchars($title)),
'link' => $url,
'guid' => $url,
'author' => RSS::pl2utf(htmlspecialchars($author)),
'date' => time(),
'description' => RSS::pl2utf(htmlspecialchars($description)));
}
function chDate( $date )
{
preg_match( '#^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$#', $date, $sp );
return date( 'r', mktime( $sp[4], $sp[5], $sp[6], $sp[2], $sp[3], $sp[1] ) );
}
function output() {
header("Content-Type: text/xml");
header("Cache-Control: no-cache");
echo("encoding."\"?>\n");
if ($this->ver == 2) {
echo("\n");
echo("\t\n");
echo("\t\t".$this->channel['title']."\n");
echo("\t\t".$this->channel['link']."\n");
echo("\t\t".$this->channel['description']."\n");
echo("\t\t".$this->channel['generator']."\n");
echo("\t\t".date("r")."\n");
foreach ($this->items as $item) {
echo("\t\t- \n");
echo("\t\t\t".RSS::rment($item['title'])."\n");
echo("\t\t\t".$item['link']."\n");
echo("\t\t\t".$item['guid']."\n");
echo("\t\t\t".RSS::rment($item['author'])."\n");
echo("\t\t\t".$this->chDate($item['date'])."\n");
if (isset ($item['description']))
echo("\t\t\t".$item['description']."\n");
echo("\t\t
\n");
}
echo("\t\n");
echo("");
} else {
echo("\n");
echo("\tchannel['link']."\">\n");
echo("\t\t".$this->channel['title']."\n");
echo("\t\t".$this->channel['link']."\n");
echo("\t\t".$this->channel['description']."\n");
echo("\t\t".$this->channel['generator']."\n");
echo("\t\t\n");
echo("\t\t\t\n");
foreach ($this->items as $item) {
echo("\t\t\t\t\n");
}
echo("\t\t\t\n");
echo("\t\t\n");
echo("\t\n");
foreach ($this->items as $item) {
echo("\t- \n");
echo("\t\t".RSS::rment($item['title'])."\n");
echo("\t\t".$item['link']."\n");
echo("\t\t".date("Y-m-d\TH:i:s\Z", $item['date'])."\n");
if ($item['description'] != '')
echo("\t\t".$item['description']."\n");
echo("\t
\n");
}
echo("");
}
}
function rment($text) {
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
if (isset($trans_tbl['<'])) unset($trans_tbl['<']);
if (isset($trans_tbl['>'])) unset($trans_tbl['>']);
if (isset($trans_tbl['&'])) unset($trans_tbl['&']);
if (isset($trans_tbl['''])) unset($trans_tbl[''']);
if (isset($trans_tbl['"'])) unset($trans_tbl['"']);
return strtr($text, $trans_tbl);
}
}
?>