pHP / * * @ (#) rss2gen.inc.php (beta) 2005/2/19 * * Exblog RSS2 generates a class, which implements most of the contents of the RSS2 specification. * * Please use the method of this class (RSS2Gen class using a comment) information. * * This program is a free program, the source code user can be arbitrarily changed (do not use for commercial purposes), but please keep this copyright information! * * @Author hexuzhong * @version beta-2, 2005-03-11 * @since exblog-1.3.0 * * /
Class Rss2Gen {var $ rss_header; // rss document header, store a root element and its version attribute. Var $ item; // var $ items; var $ channel_header; // Channel head information, storage channel name, URL, description, language, copyright, etc. // --------------- The following elements are optional channel child elements -------------- // var $ channel_language; // channel use Language species, such as EN-US, EN-CN, etc. VAR $ CHANNEL_COPYRIGHT; // Copyright statement of the channel content. VAR $ channel_managingEditor; // The personal email address VAR $ CHANNEL_WEBMASTER is responsible for the content of the channel; / / The personal email address VAR $ CHANNEL_PUBDATE (/ /) content for the technical support of the channel; // Time VAR $ CHANNEL_CATEGORY; / / Description Channel belongs to which one or more classification var $ channel_generator = " EXBLOG RSS2 Builder generator>"; // Used to generate the channel VAR $ channel_docs; // rss file User's URL VAR $ CHANNEL_CLOUD; // Allows the process to register as "Cloud", the channel update notifies it VAR $ channel_ttl; // TTL represents the survival time, the survival time is A number, indicating that the number of minutes VAR $ channel_image before refresh; // specifies a GIF, JPEG or PNG image that can be displayed in the channel // var $ channel_Rating; / / About this channel PICS Rating // Var $ CHANNEL_TEXTINPUT; // Defines the input box // var $ channel_skiphours; // tells the aggregator Which hours of updates can ignore // var $ channel_skipdays; // Tell the aggregator The day update can ignore Var $ CHANNEL ; // The entire RSS2 document information is used to generate the entire page. VAR $ HALT_ON_ERROR = true; / ** * Constructor, its parameters are the channel child elements that must be RSS2, if not filling, the default content. * * @Param String $ TITLE Channel name, channel Title should be consistent with the TITLE of the Web site. * @Param String $ LINK The URL of the Web site associated with the channel. * @Param String $ Description For a brief description of the channel, if the introduction channel is doing. * @access public * / function} {$ this-> FillHeader ();} / ** * Generate an RSS document header, must be used as a root element with a element, there is a mandatory version of Version, specifying the current document Comply with RSS version.
* @access private * / function fillheader () {$ this-> rss_header = " / r / n"; $ this-> rss_header. = " / r / n";} / ** * Set the channel head, three of which are required. * @Param String $ TITLE Channel, the channel's title should be as consistent with the TITLE of the Web site. * @Param String $ LINK The URL of the Web site or site area associated with the channel. * @Param String $ Description For a simple description of the channel, what is the brief introduction to what the channel is doing. * / Function setChannel ($ title = "exblog", $ link = "http://www.exblog.org", $ description = "exblog") {$ this-> channel_Header = " title> / n "; $ this-> channel_header. =" ". $ link." link> / r / n "; $ this-> Channel_Header. = " Description> / r / n ";} Function Halt ($ msg) {= {$ this-> Halt_on_error) {$ this-> Haltmsg ($ msg);} Die ("EXBLOG RSS2 EXIT");} Function Haltmsg ($ msg) {sprintf (" EXBLOG RSS2 Builder Error:% S / R / N", $ msg);} / ** * Set the language of the RSS document, default is Simplified Chinese.
* @access public * / function setLanguage ($ tHIS-> CHANNEL_LANGUAGE = "". $ lang. " language> / r / n";} / ** * channel content Copyright * @access public * / function setcopyright ($ copyright = "exblog") {$ this-> channel_copyright = "". $ Copyright. " Copyright> / r / n";} / ** * Personal email address for the content of the channel * @access public * / function setmanagingEditor ($ email = null) {if (Empty ($ email) {$ this-> halt ("If you set the channel content The personal email address, please fill in her. ");} $ This-> Channel_managingEditor =" ". $ Email." ManagingEditor> / r / n ";} / ** * Support for personal email addresses * @access public * / function setWebmaster ($ email = null) {if ($ this-> halt ("If you set the technical support of the channel Email address, please fill in her. :) ");} $ this-> channel_webmaster =" ". $ Email." Webmaster> / r / n ";}
/ ** * The announcement date of the channel content. * @access public * / function setpubdate ($ DATE = NULL) {IF (Empty ($ DATE) {$ DATE = DATE ("Y / m / D"); $ this-> channel_pubdate = "". $ DATE. " pubdate> / r / n";} $ this-> channel_pubdate = "". $ DATE. " pubdate> / r / n";} / ** * Last Channel content Change time * @access public * / function setlastbuilddate ($ DATE = null) {if ($ DATE) {$ DATE = Date ("Y / m / D"); $ this-> channel_lastbuilddate = " "$ DATE." lastbuilddate> / r / n ";} $ this-> Channel_LastBuilddate =" ". $ date." lastbuilddate> / r / n ";} / ** * Which or more categories belong to the channel * @access public * / function setcategory ($ category) {$ this-> Channel_category = "". $ Category. " Category> / r / n";
/ ** * RSS file The format of the format of the document is located in the URL * @access public * / function setDocs ($ URL) {$ this-> channel_docs = "". $ URL. " Docs> / r / N ";
/ ** * TTL represents the survival time, the survival time is a number, indicating that the number of minutes before refreshing * @access public * / function settl ($ minute) {$ this-> channel_ttl = "". " ttl> / r / n";}
/ ** * Specifies a GIF, JPEG or PNG image * @Param string $ URL that can be displayed in the channel, is the URL * @Param string $ TIL * @Param string $ TIL * @Param string $ TIL * @Param string $ TIL * @Param String $ TIL Description of icons. When the channel is presented in HTML, it is used as an Alt property of the HTML tag. * @Param string $ link must be the URL of the site. If the channel is presented in HTML, the image is used as a link to this site. * @Param Integer $ width indicates the pixel wide image, must be set with $ HEIGHT, otherwise this property will not be displayed. * @Param Integer $ HEIGHT indicates that the image is high, must be set with $ WIDTH, otherwise this property will not be displayed. * @Param String $ Description The title attribute of the link element formed by the image. * * @Access public * / Function SetChannelImage ($ URL, $ TITLE, $ LINK, $ Width = NULL, $ TISRIGHT = NULL, $ Description = NULL) {if (! Isset ($ URL)) $ this-> Halt "If you want to set pictures, the image address attribute must be filled in."); If (! Isset ($ TITLE)) $ this-> halt ("If you want to set pictures, the image description property must be filled."); If (! isset) $ this-> halt ("If you want to set a picture, the image link attribute must be filled in. This URL is generally the same as the image address property"); $ this-> channel_image = " / R / N "; $ this-> channel_image. =" ". $ URL." url> / r / n "; $ this-> channel_image. =" title> / r / n"; $ this-> channel_image. = "". $ link. " link> / r / n"; // If the image is set Wide, high to add this property.
IF (! EMPTY ($ held)) {$ this-> channel_image. = "". $ width. " width> / r / n"; $ this-> channel_image. = "". $ Height. " Height> / r / n";} IF (! EMPTY ($ description)) $ this-> channel_image. = " description> / r / n"; $ this-> channel_image. = " image> / r / n";} / ** * Add a item to Channel, although Item Elements are optional, but at least there is at least a title or description * * @Param String $ Title item (Item) title * @Param String $ Description (Item) Outline * @Param String $ LINK Item (Item) URL * @Param String $ Author Item (Item) Author's email address * @Param string $ Category includes one or more categories of item (Item) * @Param String $ Comments About UNO (Item) Note Page URL * @Param String $ Enclosure Support and This (Item) related media object * @Param string $ GUID Unique permanent link to this (item) Contact * @Param string $ pubdate This (item) is when Published * @Param String $ source This (item) comes from which RSS channel, very useful when the item (item) is aggregated together * * @access public * / function additem ($ title = null, $ description = null, $ link = null, $ author = null, $ category = null, $ comments = n ULL, $ Enclosure = NULL, $ Guid = NULL, $ Pubdate = NULL, $ SOURCE = NULL) {// Judgment does at least add Title or Description if ($ TITLE) && Empty ($ description)) {$ THIS -> Halt ("Item: Please set at least the Title or Description property.
");} Else {$ this-> item =" / r / n "; if (! EMPTY ($ TITLE)) $ this-> item. =" title> / r / n"; if (! EMPTY ($ LINK)) $ this-> item. = "". $ link. " link> / r / n "; If (! EMPTY ($ description)) $ this-> item. =" Description> / r / n "; if (! EMPTY) ($ author)) $ this-> item. = " author> / r / n"; if (! Empty ($ category)) $ This-> item. = " category> / r / n"; if (! Empty ($ comments)) $ this-> item. = " Comments> / r / n"; if (! EMPTY ($ enclosure)) $ this-> item. = " Enclosure> / r / n "; if (! EMPTY ($ GUID)) $ this-> item. =" ". $ Guid." Guid> / r / n "; if (! EMPTY ($ Pubdate)) $ this-> item. =" ". $ Pubdate." pubdate> / r / n "; if (! EMPTY ($ Source)) $ this-> item. = " source> / r / n"; $ this-> item. = " item> / r / n";} $ this-> items. = $ this-> item;} / ** * Output RSS2 Document * / Function Builder () {$ this-> stuff (); Header ("Content-Type: Application / XML"); Print $ this-> channel;} / ** * Compatible with the old version RSS generation method, remove the write file function.
SetWebmaster ("Elliott@yeah.net"); // $ rss2gen-> setpubdate (); // $ rss2gen-> setlastbuilddate (); // $ rss2gen-> setcategory ("none"); // $ r s2gen-> SetDOCS ("http://www.exblog.org/rss_docs.html"); // $ r $ r 2 en-> setttl (600); //$Rss2GEN->SetChannelImage ("http://www.exblog.org/demo .gif "," demo ~~ :) "," http://www.exblog.org "); // ----------------------- - // - Add a record to the RSS document, at least one parameter, Title or Description $ RSS2GEN-> AddItem ("ITEM1", "Item1's Description", "http://www.exblog.org/?play = 1 "," Elliott "," Default Category "," Description. "," Support and Media Objects related to this (Item) "," Unique Permanent Link " "2005-03-12", "This (item) comes from which RSS channel is very useful when the item (ITEM) is aggregated"); $ RSS2GEN-> AddItem ("Item2", "Item2's Description") ; $ Rss2gen-> additem ("item3");
$ RSS2GEN-> Builder (); // Compatible with the old version Method // $ rss2gen-> buildrsSfeed (); * /?>