php Script to fetch RSS info
/**
* Class name: RSS
* Author : LeadStar Team
* website : http://www.leadstar.com.cn/
* CopyRight : LeadStar Team
*/
if (defined('_CLASS_RSS_PHP')) return;
define('_CLASS_RSS_PHP',1);
class RSS {
//public
var $rss_ver = "2.0";
var $channel_title = '';
var $channel_link = '';
var $channel_description = '';
var $language = 'zh_CN';
var $copyright = '';
var $webMaster = '';
var $pubDate = '';
var $lastBuildDate = '';
var $generator = 'RedFox RSS Generator';
var $content = '';
var $items = array();
/**************************************************************************/
// function name: RSS
// function description: construct
// parameter: $title
// $link
// $description
/**************************************************************************/
function RSS($title, $link, $description) {
$this->channel_title = $title;
$this->channel_link = $link;
$this->channel_description = $description;
$this->pubDate = Date('Y-m-d H:i:s',time());
$this->lastBuildDate = Date('Y-m-d H:i:s',time());
}
/**************************************************************************/
// function name: AddItem
// function description: add a new node
// parameter: $title
// $link
// $description $pubDate
/**************************************************************************/
function AddItem($title, $link, $description ,$pubDate) {
$this->items[] = array('title' => $title ,
'link' => $link,
'description' => $description,
'pubDate' => $pubDate);
}
/**************************************************************************/
// function name: BuildRSS
// function description: generate rss xml file content
/**************************************************************************/
function BuildRSS() {
$s = "
\n
// start channel
$s .= "
$s .= "
$s .= "<1ink>channel_link}]]>1ink>\n";
$s .= "
$s .= "
if (!empty($this->copyright)) {
$s .= "
}
if (!empty($this->webMaster)) {
$s .= "
}
if (!empty($this->pubDate)) {
$s .= "
}
if (!empty($this->lastBuildDate)) {
$s .= "
}
if (!empty($this->generator)) {
$s .= "
}
// start items
for ($i=0;$i
$s .= "
$s .= "
$s .= "<1ink>items[$i]['link']}]]>1ink>\n";
$s .= "
$s .= "
$s .= "
}
// close channel
$s .= "
$this->content = $s;
}
/**************************************************************************/
// function name: Show
// function description: print out the RSS xml file content
/**************************************************************************/
function Show() {
if (empty($this->content)) $this->BuildRSS();
echo($this->content);
}
/**************************************************************************/
// function name: SaveToFile
// function description: save the RSS content to a file
// parameter: $fname the file name to be saved
/**************************************************************************/
function SaveToFile($fname) {
$handle = fopen($fname, 'wb');
if ($handle === false) return false;
fwrite($handle, $this->content);
fclose($handle);
}
}