Public Member Functions | Data Fields
Rss Class Reference

Rss file wrapper. More...

Public Member Functions

 Rss ()
 
 addNameSpace ($namespace, $link)
 
 setChannel ($title, $link, $description)
 
 addChannelValue (Tag $value)
 
 newTextInput ($title, $description, $name, $link)
 
 newImage ($url, $title, $link, $width=null, $height=null, $description=null)
 
 newItem ($title=null, $description=null)
 
 __toString ()
 
 outputToFile ($filename)
 

Data Fields

 $xml
 
 $rss
 
 $channel
 
 $channel_allowed_items = array()
 
 $namespaces = array()
 
 $items = array()
 

Detailed Description

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 = new Rss();
$rss->setChannel(
'Rss feed title',
'http://link-to-rss-feed',
'Rss feed description'
);
// Create a pubDate tag
$pubDate = new Tag('pubDate');
$pubDate->append( date("D, d M Y H:i:s T") );
// Add tag to Rss
$rss->addChannelValue( $pubDate );

Adding unsupported values will result in an InvalidArgumentTypeException. To support more values, namespaces need to be added :

// Adding the follwing namespace will allow you to add 'sy' type tags
$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.

// Add item with set title
$rss->addChannelValue( $rss->newItem( 'My Feed', null ) );
// Add item with set content
$rss->addChannelValue( $rss->newItem( null, 'About my feed' ) );
// Custom values can also be added to items
$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 :

// Output content on screen
echo $rss;
// Output content to a file
$rss->outputToFile( 'rssFile.rss' );

Member Function Documentation

Rss ( )

Constructor

addNameSpace (   $namespace,
  $link 
)

Function to be used for adding a namespace

Parameters
string$namespace
string$link: the link to the namespace
setChannel (   $title,
  $link,
  $description 
)

Set the channel field

Parameters
string$title
string$link
string$description
addChannelValue ( Tag  $value)

Add an optional channel field

Parameters
Tag$value
newTextInput (   $title,
  $description,
  $name,
  $link 
)

Create a new rss text input field

Parameters
string$title
string$description
string$name
string$link
Returns
Tag : returns the new text input field
newImage (   $url,
  $title,
  $link,
  $width = null,
  $height = null,
  $description = null 
)

Create a new rss image field

Parameters
string$url
string$title
string$link
string$width: optional
string$height: optional
string$description: optional
Returns
Tag : returns the new image field
newItem (   $title = null,
  $description = null 
)

Create a new item

Parameters
string$title: optional if $description is added
string$description: optional if $title is added
Returns
Tag : return the new item
__toString ( )

toString method

Exceptions
InvalidArgumentTypeException
outputToFile (   $filename)

Output the object to the specified file

Parameters
string$filename: the full path of the file

Field Documentation

$xml

string : Rss header

$rss

Tag : Rss main tag

$channel

Tag : Channel tag

$channel_allowed_items = array()

array : Allowed nested items for the channel tag

$namespaces = array()

array : Added namespaces

$items = array()

array : Channel tag items