Class RSS { Var $ title; Var $ link; Var $ description; Var $ language = "en-us "; Var $ pubDate; Var $ items; Var $ tags; Function RSS () { $ This-> items = array (); $ This-> tags = array (); } Function addItem ($ item) { $ This-> items [] = $ item; } Function setPubDate ($ when) { If (strtotime ($ when) = false) $ This-> pubDate = date ("D, d m y h: I: s", $ when). "GMT "; Else $ This-> pubDate = date ("D, d m y h: I: s", strtotime ($ when). "GMT "; } Function getPubDate () { If (empty ($ this-> pubDate )) Return date ("D, d m y h: I: s"). "GMT "; Else Return $ this-> pubDate; } Function addTag ($ tag, $ value) { $ This-> tags [$ tag] = $ value; } Function out () { $ Out = $ this-> header (); $ Out. = "<channel> \ n "; $ Out. = "<title>". $ this-> title. "</title> \ n "; $ Out. = "<link>". $ this-> link. "</link> \ n "; $ Out. = "<description>". $ this-> description. "</description> \ n "; $ Out. = "<language>". $ this-> language. "</language> \ n "; $ Out. = "<pubDate>". $ this-> getPubDate (). "</pubDate> \ n "; Foreach ($ this-> tags as $ key => $ val) $ out. = "<$ key> $ val </$ key> \ n "; Foreach ($ this-> items as $ item) $ out. = $ item-> out (); $ Out. = "</channel> \ n "; $ Out. = $ this-> footer (); $ Out = str_replace ("&", "&", $ out ); Return $ out; } Function serve ($ contentType = "application/xml ") { $ Xml = $ this-> out (); Header ("Content-type: $ contentType "); Echo $ xml; } Function header () { $ Out = '<? Xml version = "1.0" encoding = "UTF-8"?> '. "\ N "; $ Out. = '<rss version = "2.0" xmlns: dc = "http://purl.org/dc/elements/1.1/">'. "\ n "; Return $ out; } Function footer () { Return '</rss> '; } } Class RSSItem { Var $ title; Var $ link; Var $ description; Var $ pubDate; Var $ guid; Var $ tags; Var $ attachment; Var $ length; Var $ mimetype; Function RSSItem () { $ This-> tags = array (); } Function setPubDate ($ when) { If (strtotime ($ when) = false) $ This-> pubDate = date ("D, d m y h: I: s", $ when). "GMT "; Else $ This-> pubDate = date ("D, d m y h: I: s", strtotime ($ when). "GMT "; } Function getPubDate () { If (empty ($ this-> pubDate )) Return date ("D, d m y h: I: s"). "GMT "; Else Return $ this-> pubDate; } Function addTag ($ tag, $ value) { $ This-> tags [$ tag] = $ value; } Function out () { $ Out. = "<item> \ n "; $ Out. = "<title>". $ this-> title. "</title> \ n "; $ Out. = "<link>". $ this-> link. "</link> \ n "; $ Out. = "<description>". $ this-> description. "</description> \ n "; $ Out. = "<pubDate>". $ this-> getPubDate (). "</pubDate> \ n "; If ($ this-> attachment! = "") $ Out. = "<enclosure url = '{$ this-> attachment}' length = '{$ this-> length}' type = '{$ this-> mimetype}'/>"; If (empty ($ this-> guid) $ this-> guid = $ this-> link; $ Out. = "<guid>". $ this-> guid. "</guid> \ n "; Foreach ($ this-> tags as $ key => $ val) $ out. = "<$ key> $ val </$ key \ n> "; $ Out. = "</item> \ n "; Return $ out; } Function enclosure ($ url, $ mimetype, $ length) { $ This-> attachment = $ url; $ This-> mimetype = $ mimetype; $ This-> length = $ length; } } |