Class rss { // Public $ Rss_ver = "2.0 "; $ Channel_title = ''; $ Channel_link = ''; $ Channel_description = ''; $ Language = 'zh _ cn '; $ Copyright = ''; $ Webmaster = ''; $ Pubdate = ''; $ Lastbuilddate = ''; $ Generator = 'redfox rss generator '; $ Content = ''; $ Items = array ();
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 additem ($ title, $ link, $ description, $ pubdate ){ $ This-> items [] = array ('tile' => $ title, 'Link' => $ link, 'Description' => $ description, 'Pubdate' => $ pubdate ); }
Function buildrss (){ $ S = "<! -- L version = "1.0" encoding = "gb2312" --> "; // Start channel $ S. = ""; $ S. = "" $ S. = "<link/>{$ this-> channel_link }"; $ S. = "{$ this-> channel_description }"; $ S. = "{$ this-> language }"; If (! Empty ($ this-> copyright )){ $ S. = "{$ this-> copyright }"; } If (! Empty ($ this-> webmaster )){ $ S. = "{$ this-> webmaster }"; } If (! Empty ($ this-> pubdate )){ $ S. = "{$ this-> pubdate }"; }
If (! Empty ($ this-> lastbuilddate )){ $ S. = "{$ this-> lastbuilddate }"; }
If (! Empty ($ this-> generator )){ $ S. = "{$ this-> generator }"; } // Start items For ($ I = 0; $ iitems), $ I ++ ){ $ S. = ""; $ S. = ""; $ S. = "<link/>{$ this-> items [$ I] ['link']}"; $ S. = "<! -- Data [{$ thi --> items [$ I] ['description']}]> "; $ S. = "{$ this-> items [$ I] ['pubdate']}"; $ S. = ""; } // Close the channel $ S. = ""; $ This-> content = $ s; }
Function show (){ If (empty ($ this-> content) $ this-> buildrss (); Header ('content-type: text/XML '); Echo ($ this-> content ); }
Function savetofile ($ fname ){ If (empty ($ this-> content) $ this-> buildrss (); $ Handle = fopen ($ fname, 'wb '); If ($ handle = false) return false; Fwrite ($ handle, $ this-> content ); Fclose ($ handle ); } }
|