The Php RSS2Writer class has been updated. Version 2.0 includes improved usability when using the RSS2Writer class to generate an RSS Feed from website or database content, as well as additional functionality required to generate valid RSS 2.0 Feeds.Download Php RSS2Writer - Version 2.0
The download page also provides some additional information about the class and sample controller.
Details of the Php RSS 2.0 Writer Package:
RSS2Writer.php
The package incudes the RSS2Writer class file that contains the functions and variables required to produce a valid RSS 2.0 compatible feed using Php.
sampleController.php
The sample controller script provides examples for using the class and functions, including additional information about optional elements that can be added to a feed channel or individual item. Basic instructions are provided in the sample controller to help get started using the class.
Php RSS2Writer Usage
The following are instructions with examples for using the Php RSS2Writer class to generate RSS 2.0 compatible feeds using Php. The data added to the feed could be from a website, database, etc. that is accessible using a Php script.
Download the PhpRSS2Writer Package and copy the RSS2Writer.php file to your web server.
In the Php script that will serve the RSS Feed:
1. Include the RSS2Writer Class:
require_once("RSS2Writer.php");
//or
//include("RSS2Writer.php");
2. Initiate the an RSS2Writer Object:
When the RSS2Writer Object is constructed, the Title, Description and link for the Feed channel are provided as parameters when constructing the object.
$rss2_writer = new RSS2Writer('Feed Title', 'Feed Description', 'feed url');
3. Add additional information to the Channel (optional ) such as categories, copyright information, or the generator used to generate the RSS feed content.
//Add channel data to the feed
$rss2_writer->addCategory("RSS Feed"); $rss2_writer->addCategory("Free Php Script");
$rss2_writer->addCategory("Php: Generate RSS 2.0");
//Optional Elements
$rss2_writer->addElement('copyright', '(c) Daniel Soutter 2010');
$rss2_writer->addElement('generator', 'Php RSS2Writer by Daniel Soutter');
4. Add Items to the Feed
Add items to the RSS feed using the addItem function, which takes the title, description and link for each item. Once the item has been added, the addCategory, or addElement functions can be called to add categories, or other optional elements to the feed item that sore information such as the name and email address of the author, and the date that the item was published.
//Example Item
$rss2_writer->addItem('item title', 'item content/description', 'item url');
//Add categories to the item
$rss2_writer->addCategory("Free Php Script");
$rss2_writer->addCategory("Php: Generate RSS 2.0");
$rss2_writer->addCategory("Php RSS2Writer Usage Instructions");
//Optional Elements
$rss2_writer->addElement('author', 'daniel@webmasterhub.net (Daniel Soutter)');
5. Output the RSS Feed XML
Output the RSS feed XML for use in a web browser or application that syndicates RSS feeds.
echo $rss2_writer->getXML();
Notes:
The addCategory and addElement functions can be used to add categories or additional elements to both the feed channel and individual feed items. To add additional information to the feed channel, call the functions before adding items to the feed. Once items have been added to the feed, calling the addCategory or addElement functions will add the specified information to the feed item most recently added to the feed.
There are a few functions which can be called at any time to associate an image to the RSS Feed Channel, or include channel Cloud data, for use by RSS Feed readers and other applications when retrieving and presenting data from your feed.
The channelImage() function associates an image with the RSS Feed Channel, passing a title, link, url, and the dimensions of the image (width, height).
$rss2_writer->channelImage($title, $link, $url, $width, $height);
The channelCloud() function adds cloud information to the Feed Channel. The domain, port, path, registerProcedure and protocol are passed to the function. The Port, registerProcedure and protocol paramaters use '80', 'pingMe' and 'soap' as defaults.
$rss2_writer->channelCloud($domain, $port, $path, $registerProcedure, $protocol);
If you have any queries about, or issues with using the Php RSS2Writer class, please leave a comment on this post. Suggestions for improvwement or additional functionality are welcome as well, and will be incorporated into new versions of the class if appropriate.


0 comments:
Post a Comment