Rss file wrapper.
- Version
- 1.2
- Author
- DinuSV
The first thing when creating an rss file is setting up a channel ( Rss::setChannel ). The channel would next require tags of different types : title, link, description, language, item, copyright, managingEditor, webMaster, pubDate, lastBuiltDate, category, generator, docs, cloud, ttl, image, rating, textInput, skipHours, skipDays, image, cloud.
Here's an example of a small rss file :
'Rss feed title',
'http://link-to-rss-feed',
'Rss feed description'
);
$pubDate =
new Tag(
'pubDate');
$pubDate->append( date("D, d M Y H:i:s T") );
$rss->addChannelValue( $pubDate );
Adding unsupported values will result in an InvalidArgumentTypeException. To support more values, namespaces need to be added :
$rss->addNameSpace(
'xmlns:sy',
'http://purl.org/rss/1.0/modules/syndication/' );
$updatePeriod =
new Tag(
'sy:updatePeriod');
$updatePeriod->append('hourly');
$rss->addChannelValue( $updatePeriod );
Adding items
Items contain the actual feed data. They are also added as channel values. An item is required to have at least a title or content. Rss::newItem creates a new tag item. To add just one of the parameters, set the other one to 'null'. If both are null, an InvalidArgumentTypeException will be thrown.
$rss->addChannelValue(
$rss->newItem(
'My Feed', null ) );
$rss->addChannelValue(
$rss->newItem( null,
'About my feed' ) );
$pubDate =
new Tag(
'pubDate');
$pubDate->append( date("D, d M Y H:i:s T" );
$item =
$rss->newItem(
'My feed',
'About My Feed' );
$item->append( $pubDate );
$rss->addChannelValue( $item );
Images and text input fields can also be created :
$rss->addChannelValue(
$rss->newImage(
'myImage.jpg',
'My Image',
'http://image-href' ) );
$rss->addChannelValue(
$rss->newTextInput(
'My Label',
'About My Input',
'name',
'http://submit' ) );
Saving data
The object can either be echoed out, or written to a file :
$rss->outputToFile( 'rssFile.rss' );