Rss generation class [code]

Source: Internet
Author: User
Tags comments generator rfc822


<? Php
/*************************************** **
* RSS2.0 Generator
* Create by MagicBoy (darasion)
* Copyright? Magic Boy
**************************************** **/

/*----------------

Usage:
Add the following array to the corresponding function.

1. Channel subject
$ Channel = array (
Title => 'Channel name (required )',
Link => 'Channel URL (required )',
Description => 'Channel description (required )',
Language => 'language used for channel articles (optional )',
Webmaster => 'email (optional )',
ManagingEditor => 'email for responsible editing (optional )',
PubDate => 'Channel content release date. The format follows the RFC822 format (the year can be 2 or 4 bits) (optional )',
LastBuildDate => 'Last modified date of the channel content (Sat, 07 Sep 2002 09:42:31 GMT) (optional )',
SkipDays => 'indicates the news aggregator, which can be skipped in those days. (Optional )',
Copyright => 'copyright description of channel content (optional )',
Ttl => 'validity period, which indicates the maximum cache time for this channel (optional )',
);

2. Channel images
$ Image = array (
Url => 'image link (required )',
Title => 'image title, used for the http alt attribute (required )',
Link => 'website url (in reality, it is often replaced by the channel url) (required )',
Width => 'Maximum image width (in pixels): 144; default value: 88 (optional )',
Height => 'Maximum Image height (in pixels): 400; default value: 31 (optional )',
Description => 'Title attribute used for link (optional )'
);

3. Channel items
$ Item = array (
Title => 'item title (required )',
Description => 'item outline (required )',
Link => 'item URL (required )',
Comments => 'comments page URL (optional )',
Guid => '1 unique identifier string (optional )',
Author => 'author's email (optional )',
Enclosure => 'specifies the attached media object )',
Category => 'catogory (optional )',
Pubdate => 'item release time (optional )',
Source_url => 'RSS feed of this item (optional )',
Source_name => 'This item comes from the RSS feed (optional )'
);
----------------*/

ClassRss2
{
Var $ channel_pre = "";
Var $ str_image = "";
Var $ str_item = "";
Var $ channel_end = "";
/* Constructor */
Function rss2 ($ channel, $ encoding = "GB2312")
  {
$ This-> channel ($ channel, $ encoding);
  }
/* Generate a channel subject */
Function channel ($ channel, $ encoding = "GB2312")
  {
$ This-> channel_pre. = "<? Xml version = \ "1.0 \" encoding = \ "$ encoding \"?> \ N";
$ This-> channel_pre. = "<rss version = \" 2.0 \ "> \ n";

$ This-> channel_pre. = "<channel> \ n";

$ This-> channel_pre. = "<title>". $ channel ['title']. "</title> \ n ";// Channel name (required)
$ This-> channel_pre. = "<link>". $ channel ['link']. "</link> \ n ";// Channel URL (required)
$ This-> channel_pre. = "<description>". $ channel ['description']. "</description> \ n ";// Channel description (required)
$ This-> channel_pre. = "<generator> MagicBoy RSS Generator v1.0 </generator> \ n ";// Create a program for this document (optional)

If (isset ($ channel ['language']) $ this-> channel_pre. = "<language> ". $ channel ['language']. "</language> \ n ";// Language used for channel articles (optional)
If (isset ($ channel ['webmaster']) $ this-> channel_pre. = "<webMaster> ". $ channel ['webmaster']. "</webMaster> \ n ";// Email of the website administrator responsible for channel Technical Affairs (optional)
If (isset ($ channel ['managingeditor']) $ this-> channel_pre. = "<managingEditor> ". $ channel ['managingeditor']. "</managingEditor> \ n ";// Email for responsible editing (optional)
If (isset ($ channel ['pubdate']) $ this-> channel_pre. = "<pubDate> ". $ channel ['pubdate']. "</pubDate> \ n ";// Channel content release date. The format follows the RFC822 format (the year can be 2 or 4 digits) (optional)
If (isset ($ channel ['lastbuilddate']) $ this-> channel_pre. = "<lastBuildDate> ". $ channel ['lastbuilddate']. "</lastBuildDate> \ n ";// The Last modified date of the channel content (Sat, 07 Sep 2002 09:42:31 GMT) (optional)
If (isset ($ channel ['skipdays']) $ this-> channel_pre. = "<skipDays> ". $ channel ['skipdays']. "</skipDays> \ n ";// Prompt the news aggregator, which can be skipped in those days. (Optional)
If (isset ($ channel ['copyright']) $ this-> channel_pre. = "<copyright> ". $ channel ['copyright']. "</copyright> \ n ";// Channel content copyright description (optional)
If (isset ($ channel ['ttl ']) $ this-> channel_pre. = "<ttl> ". $ channel ['ttl ']. "</ttl> \ n ";// Validity period, which indicates the maximum cache time for this channel (optional)

$ This-> channel_end. = "</channel> \ n";
$ This-> channel_end. = "</rss> \ n";
}
/* Generate a channel image */
Function image ($ image)
{
If (isset ($ this-> str_image) unset ($ this-> str_image);
$ This-> str_image. = "<image> \ n";
If (isset ($ image ['URL']) $ this-> str_image. = "<url> ". $ image ['URL']. "</url> \ n ";// Url of the image (required)
If (isset ($ image ['title']) $ this-> str_image. = "<title> ". $ image ['title']. "</title> \ n ";// The Image title, used for the http alt attribute (required)
If (isset ($ image ['link']) $ this-> str_image. = "<link> ". $ image ['link']. "</link> \ n ";// Website url (in reality, it is often replaced by the channel url) (required)
If (isset ($ image ['width']) $ this-> str_image. = "<width> ". $ image ['width']. "</width> \ n ";// The maximum width (in pixels) of the image is 144. The default value is 88 (optional)
If (isset ($ image ['height']) $ this-> str_image. = "// The Image height (in pixels) is up to 400. The default value is 31 (optional)
If (isset ($ image ['description']) $ this-> str_image. = "<description> ". $ image ['description']. "</description> \ n ";// The title attribute used for link (optional)
$ This-> str_image. = "</image> \ n";
}
/* Channel item */
Function item ($ item)
{
$ This-> str_item. = "<item> \ n";
$ This-> str_item. = "<title>". $ item ['title']. "</title> \ n ";// Item title (required)
$ This-> str_item. = "<description>". $ item ['description']. "</description> \ n ";// Outline of the item (required)
$ This-> str_item. = "<link>". $ item ['link']. "</link> \ n ";// The URL of the item (required)

If (isset ($ item ['comments']) $ this-> str_item. = "<comments> ". $ item ['comments']. "</comments> \ n ";// The URL of the comments page (optional)
If (isset ($ item ['Guid ']) $ this-> str_item. = "<guid> ". $ item ['Guid ']. "</guid> \ n ";// Unique identifier string of item 1 (optional)
If (isset ($ item ['autor']) $ this-> str_item. = "<author> ". $ item ['author']. "</author> \ n ";// The Author's email (optional)
If (isset ($ item ['enablesure ']) $ this-> str_item. = "<enclosure> ". $ item ['enablesure ']. "</enclosure> \ n ";// Description of the attached media object (optional)
If (isset ($ item ['Category ']) $ this-> str_item. = "<category> ". $ item ['Category ']. "</category> \ n ";// One or more categories containing the item (optional)
If (isset ($ item ['pubdate']) $ this-> str_item. = "<pubDate> ". $ item ['pubdate']. "</pubDate> \ n ";// Item release time (optional)
If (isset ($ item ['Source _ url']) $ this-> str_item. = "<source url = \"". $ item ['Source _ url']. "\"> ". $ item ['Source _ name']. "</source> \ n ";// This item comes from the RSS feed (optional)
$ This-> str_item. = "</item> \ n";
}
/* Output xml */
Function generate()
{
If (isset ($ this-> channel_pre) & isset ($ this-> channel_end) & isset ($ this-> str_item))
  {
Header ("Content-type: text/xml");
Echo $ this-> channel_pre;
Echo $ this-> str_image;
Echo $ this-> str_item;
Echo $ this-> channel_end;
  }
}
/* Erase the channel */
Function erase_channel()
{
Unset ($ this-> channel_pre);
Unset ($ this-> channel_end);
}
/* Erase the channel image */
Function erase_image()
{
Unset ($ this-> str_image);
}
/* Erase the project */
Function erase_item()
{
Unset ($ this-> str_item);
}
/* Erase all */
Function erase()
{
$ This-> erase_channel();
$ This-> erase_image();
$ This-> erase_item();
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.