RSSFeed package documentation

Introduction

Author

Hugo 'Emacs' HAMON - webmaster@apprendre-php.com - http://www.apprendre-php.com

Presentation

The RSSFeed was built to power valid and complete RSS 2.0 feeds for your website. Generated feeds can be as minimal as possible or very complete. Indeed, every RSS 2.0 tag is supported in this classes package.

The biggest pros of this package is to create RSS 2.0 feeds very easily without to write one XML code line. The programm does it for you !

Environment

The RSSFeed library needs to run on a PHP5 web server because it uses the PHP5 Object Model.

License

The RSSFeed package source is completely open. You can edit, improve or sell it with your web applications.

Installation

Unzip the RSSFeed package on your web server.

Include the RSSFeed.class.php file in your script like this :

Generate your RSS 2.0 feed like example scripts.

RSSFeed package

Let's see more in details the five classes, which compose this package.

RSSFeedException

This class provides RSS Feed Exceptions (errors). It herits the native PHP Exception class properties.

RSSFeedTools

The abstract RSSFeedTools class contains a serie of static methods which allow to validate some information for the feed.

RSSFeedBase

The RSSFeedBase script is an abstract class which contains properties and methods that are shared by the two RSSFeed and RSSFeedItem classes. Indeed, both of the feed or item can have a title, description, link, pubDate element and one or more category elements. That's why theses properties are placed in this superclass.

RSSFeed

The RSSFeed file is the main class of the package. It's a concrete class which allows to instanciate a new RSSFeed object. It herits the properties and methods of the RSSFeedBase abstract superclass. Below are listed the public methods that you can apply on the RSSFeed object.

See a method documentation :


RSSFeed::__construct()

Introduction

This is the constructor of the class. It allows to create the new RSSFeed object.

Parameters

(string) $encoding : the feed encoding.

Example

RSSFeed::setProtectString()

Introduction

This method allows to set the protect string policy. If the $protectString parameter is set to true, all feed information will be protected. Special characters will be transformed into their html entity equivalent.

Parameters

(boolean) $protectString : false by default, true to enable the string protection.

Example

RSSFeedBase::setTitle()

Introduction

Set the feed title.

Parameters

(string) $title : the feed title.

Example

RSSFeedBase::setDescription()

Introduction

Set the feed description.

Parameters

(string) $description : the feed description.

Example

Introduction

Set the feed link.

Parameters

(string) $link : the feed URI link.

Example

RSSFeedBase::setCategory()

Introduction

Set a new feed category. Note that a feed can have 0 or more categories elements.

Parameters

(string) $domain : the category URI.
(string) $content : the category content.

Example

RSSFeed::setImage()

Introduction

Set the feed image.

Parameters

(string) $url : the image URI.
(string) $title : the image caption.
(string) $link : the image link. Note that it's recommanded to provide the same string that the feed link.
(string) $description : the image description.
(int) $width : the image width : 0px < $width < 144px
(int) $height : the image height : 0px < $height < 400px

Example

RSSFeed::setLastBuildDate()

Introduction

Set the feed last build date.

Parameters

(string) $lastBuildDate : the last build date. Attempt formats : AAAA-MM-DD or AAAA-MM-DD HH:II:SS.

Example

RSSFeedBase::setPubDate()

Introduction

Set the feed publication date.

Parameters

(string) $setPubDate : the feed publication date. Attempt formats : AAAA-MM-DD or AAAA-MM-DD HH:II:SS.

Example

RSSFeed::setTimeToLive()

Introduction

Set the feed time to live. This is the time (in seconds) during the feed is stored in client cache.

Parameters

(int) $ttl : the feed time to live.

Example

RSSFeed::setManagingEditor()

Introduction

Set the managing editor of the feed.

Parameters

(string) $email : the manager email.
(string) $name : the manager name.

Example

RSSFeed::setWebMaster()

Introduction

Set the website webmaster.

Parameters

(string) $email : the webmaster email.
(string) $name : the webmaster name.

Example

RSSFeed::setCopyright()

Introduction

Set the feed copyright.

Parameters

(string) $copyright : the feed copyright.

Example

RSSFeed::setRating()

Introduction

Set the feed rating.

Parameters

(string) $rating : the feed rating.

Example

RSSFeed::setGenerator()

Introduction

Set the feed generator.

Parameters

(string) $generator : the feed generator.

Example

RSSFeed::setLanguage()

Introduction

Set the feed language.

Parameters

(string) $language : the feed language with 2 characters.

Example

RSSFeed::setDocs()

Introduction

Set the feed documentation.

Parameters

(string) $docs : the feed documentation.

Example

RSSFeed::setSkipDay()

Introduction

Set a new skip day. A skip day indicates a day when the feed hasn't to be refreshed. A feed can have more than one skip day. Note that if you provide the seven week days, your RSS 2.0 feed won't be refreshed anymore.

Parameters

(string) $day : the skip day. Attempt values : Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.

Example

RSSFeed::setSkipHour()

Introduction

Set a new skip hour. A skip hour indicates a time when the feed hasn't to be refreshed in a day. A feed can have more than one skip hour.

Parameters

(int) $hour : the skip hour. Attempt values : from 0 to 23.

Example

RSSFeed::setCloud()

Introduction

Set the feed cloud.

Parameters

(string) $domain : the host domain name of the server to register.
(int) $port : port tu use.
(string) $path : path of the script on the web server.
(string) $registerProcedure : name of the register procedure.
(string) $protocol : the protocol : xml-rpc or soap.

Example

RSSFeed::appendItem()

Introduction

Add a new RSSFeedItem object to the feed.

Parameters

(RSSFeedItem) $item : the item object.

Example

RSSFeed::display()

Introduction

Display the generated feed.

Parameters

No parameter for this method.

Example

RSSFeed::regenerate()

Introduction

Regenerate the feed.

Parameters

No parameter for this method.

Example

RSSFeed::save()

Introduction

Save the feed in a XML file on the web server.

Parameters

(string) $xmlFileName : the xml file name.

Example

RSSFeedItem

The RSSFeedItem file is the second important class of the package. It's a concrete class which allows to instanciate a new RSSFeedItem object. It herits the properties and methods of the RSSFeedBase abstract superclass. Below are listed the public methods that you can apply on the RSSFeedItem object.

See a method documentation :


RSSFeedItem::__construct()

Introduction

This is the constructor of the class. It allows to create the new RSSFeedItem object.

Parameters

No parameter for this method.

Example

RSSFeedBase::setTitle()

Introduction

Set the item title.

Parameters

(string) $title : the item title.

Example

RSSFeedBase::setDescription()

Introduction

Set the item description.

Parameters

(string) $description : the item description.

Example

Introduction

Set the item link.

Parameters

(string) $link : the item URI link.

Example

RSSFeedBase::setCategory()

Introduction

Set a new item category. Note that an item can have 0 or more categories elements.

Parameters

(string) $domain : the category URI.
(string) $content : the category content.

Example

RSSFeedBase::setPubDate()

Introduction

Set the item publication date.

Parameters

(string) $setPubDate : the item publication date. Attempt formats : AAAA-MM-DD or AAAA-MM-DD HH:II:SS.

Example

RSSFeedItem::setAuthor()

Introduction

Set the item author.

Parameters

(string) $email : the author email.
(string) $name : the author name.

Example

RSSFeedItem::setComments()

Introduction

Set the item comments URI of a post.

Parameters

(string) $comments : the comments URI.

Example

RSSFeedItem::setEnclosure()

Introduction

Set the item enclosure element.

Parameters

(string) $url : the media URI.
(int) $length : the length in bytes of the media.
(string) $mimeType : the media mimeType.

Example

RSSFeedItem::setGuid()

Introduction

Set the unique item guid element.

Parameters

(string) $url : the guid link.
(boolean) $isPermaLink : specify if the link is permanent or not

Example

RSSFeedItem::setSource()

Introduction

Set the item source element.

Parameters

(string) $url : the source link.
(string) $content : ths source name link

Example

Examples

See the scripts in the RSSFeed/examples/ directory.

Generate a minimal RSS 2.0 feed from MySQL