<? Php
/**
* Class name: RSS
*/
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: Constructor
// 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: Add a 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: generate the rss xml file content
/*************************************** ***********************************/
Function BuildRSS (){
$ S = "<? Xml version = \ "1.0 \" encoding = \ "gb2312 \"?>
\ N <rss version = \ "2.0 \"> \ n ";
// Start channel
$ S. = "<channel> \ n ";
$ S. = "<title> <! [CDATA [{$ this-> channel_title}]> </title> \ n ";
$ S. = "<link> <! [CDATA [{$ this-> channel_link}]> </link> \ n ";
$ S. = "<description> <! [CDATA [{$ this-> channel_description}]> </description> \ n ";
$ S. = "<language >{$ this-> language} </language> \ n ";
If (! Empty ($ this-> copyright )){
$ S. = "<copyright> <! [CDATA [{$ this-> copyright}]> </copyright> \ n ";
}
If (! Empty ($ this-> webMaster )){
$ S. = "<webMaster> <! [CDATA [{$ this-> webMaster}]> </webMaster> \ n ";
}
If (! Empty ($ this-> pubDate )){
$ S. = "<pubDate >{$ this-> pubDate} </pubDate> \ n ";
}
If (! Empty ($ this-> lastBuildDate )){
$ S. = "<lastBuildDate >{$ this-> lastBuildDate} </lastBuildDate> \ n ";
}
If (! Empty ($ this-> generator )){
$ S. = "<generator >{$ this-> generator }</generator> \ n ";
}
// Start items
For ($ I = 0; $ I <count ($ this-> items); $ I ++ ){
$ S. = "<item> \ n ";
$ S. = "<title> <! [CDATA [{$ this-> items [$ I] ['title']}]> </title> \ n ";
$ S. = "<link> <! [CDATA [{$ this-> items [$ I] ['link']}]> </link> \ n ";
$ S. = "<description> <! [CDATA [{$ this-> items [$ I] ['description']}]> </description> \ n ";
$ S. = "<pubDate >{$ this-> items [$ I] ['pubdate']} </pubDate> \ n ";
$ S. = "</item> \ n ";
}
// Close the channel
$ S. = "</channel> \ n </rss> ";
$ This-> content = $ s;
}
/*************************************** ***********************************/
// Function name: Show
// Function: print the generated rss content directly.
/*************************************** ***********************************/
Function Show (){
If (empty ($ this-> content) $ this-> BuildRSS ();
Echo ($ this-> content );
}
/*************************************** ***********************************/
// Function name: SaveToFile
// Function: Save the generated rss content to a file
// Parameter: $ fname file name to be saved
/*************************************** ***********************************/
Function SaveToFile ($ fname ){
$ Handle = fopen ($ fname, 'wb ');
If ($ handle = false) return false;
Fwrite ($ handle, $ this-> content );
Fclose ($ handle );
}
}
?>