Constants

RSS1

RSS1

RSS2

RSS2

ATOM

ATOM

VERSION

VERSION

Properties

$channels

$channels : 

Collection of all channel elements

Type

$items

$items : 

Collection of items as object of \FeedWriter\Item class.

Type

$data

$data : 

Collection of other version wise data.

Currently used to store the 'rdf:about' attribute and image element of the channel (both RSS1 only).

Type

$CDATAEncoding

$CDATAEncoding : 

The tag names which have to encoded as CDATA

Type

$namespaces

$namespaces : 

Collection of XML namespaces

Type

$version

$version : 

Contains the format of this feed.

Type

Methods

setPagination()

setPagination(string  $nextURL = null, string  $previousURL = null, string  $firstURL = null, string  $lastURL = null) : self

Set the URLs for feed pagination.

See RFC 5005, chapter 3. At least one page URL must be specified.

Parameters

string $nextURL

The URL to the next page of this feed. Optional.

string $previousURL

The URL to the previous page of this feed. Optional.

string $firstURL

The URL to the first page of this feed. Optional.

string $lastURL

The URL to the last page of this feed. Optional.

Throws

\LogicException

if none of the parameters are set.

Returns

self

addGenerator()

addGenerator() : self

Add a channel element indicating the program used to generate the feed.

Throws

\FeedWriter\InvalidOperationException

if this method is called on an RSS1 feed.

Returns

self

addNamespace()

addNamespace(string  $prefix, string  $uri) : self

Add a XML namespace to the internal list of namespaces. After that, custom channel elements can be used properly to generate a valid feed.

Parameters

string $prefix

namespace prefix

string $uri

namespace name (URI)

Throws

\InvalidArgumentException

if the prefix or uri is empty or NULL.

Returns

self

setChannelElement()

setChannelElement(string  $elementName, string  $content, array  $attributes = null,   $multiple = false) : self

Add a channel element to the feed.

Parameters

string $elementName

name of the channel tag

string $content

content of the channel tag

array $attributes
$multiple

Throws

\InvalidArgumentException

if the element name is not a string, empty or NULL.

Returns

self

setChannelElementsFromArray()

setChannelElementsFromArray(array  $elementArray) : self

Set multiple channel elements from an array. Array elements should be 'channelName' => 'channelContent' format.

Parameters

array $elementArray

Returns

self

getMIMEType()

getMIMEType() : string

Get the appropriate MIME type string for the current feed.

Returns

string —

The MIME type string.

printFeed()

printFeed(  $useGenericContentType = false) : void

Print the actual RSS/ATOM file

Sets a Content-Type header and echoes the contents of the feed. Should only be used in situations where direct output is desired; if you need to pass a string around, use generateFeed() instead.

Parameters

$useGenericContentType

Throws

\InvalidArgumentException

if the useGenericContentType parameter is not boolean.

generateFeed()

generateFeed() : string

Generate the feed.

Throws

\FeedWriter\InvalidOperationException

if the link element of the feed is not set.

Returns

string —

The complete feed XML.

createNewItem()

createNewItem() : \FeedWriter\Item

Create a new Item.

Returns

\FeedWriter\Item

instance of Item class

addCDATAEncoding()

addCDATAEncoding(array  $tags) : self

Add one or more tags to the list of CDATA encoded tags

Parameters

array $tags

An array of tag names that are merged into the list of tags which should be encoded as CDATA

Returns

self

getCDATAEncoding()

getCDATAEncoding() : array

Get list of CDATA encoded properties

Returns

array —

Return an array of CDATA properties that are to be encoded as CDATA

removeCDATAEncoding()

removeCDATAEncoding(array  $tags) : void

Remove tags from the list of CDATA encoded tags

Parameters

array $tags

An array of tag names that should be removed.

addItem()

addItem(\FeedWriter\Item  $feedItem) : self

Add a FeedItem to the main class

Parameters

\FeedWriter\Item $feedItem

instance of Item class

Throws

\InvalidArgumentException

if the given item version mismatches.

Returns

self

setEncoding()

setEncoding(string  $encoding) : self

Set the 'encoding' attribute in the XML prolog.

Parameters

string $encoding

value of 'encoding' attribute

Throws

\InvalidArgumentException

if the encoding is not a string, empty or NULL.

Returns

self

setTitle()

setTitle(string  $title) : self

Set the 'title' channel element

Parameters

string $title

value of 'title' channel tag

Returns

self

setDate()

setDate(  $date) : self

Set the date when the feed was lastly updated.

This adds the 'updated' element to the feed. The value of the date parameter can be either an instance of the DateTime class, an integer containing a UNIX timestamp or a string which is parseable by PHP's 'strtotime' function.

Not supported in RSS1 feeds.

Parameters

$date

Throws

\InvalidArgumentException

if the given date is not an instance of DateTime, a UNIX timestamp or a date string.

\FeedWriter\InvalidOperationException

if this method is called on an RSS1 feed.

Returns

self

setDescription()

setDescription(string  $description) : self

Set a phrase or sentence describing the feed.

Parameters

string $description

Description of the feed.

Returns

self

setLink()

setLink(string  $link) : self

Set the 'link' channel element

Parameters

string $link

value of 'link' channel tag

Returns

self

setAtomLink()

setAtomLink(string  $href, string  $rel = null, string  $type = null, string  $hreflang = null, string  $title = null, integer  $length = null) : self

Set custom 'link' channel elements.

In ATOM feeds, only one link with alternate relation and the same combination of type and hreflang values.

Parameters

string $href

URI of this link

string $rel

relation type of the resource

string $type

MIME type of the target resource

string $hreflang

language of the resource

string $title

human-readable information about the resource

integer $length

length of the resource in bytes

Throws

\InvalidArgumentException

on multiple occasions.

\FeedWriter\InvalidOperationException

if the same link with the same attributes was already added to the feed.

Returns

self

setSelfLink()

setSelfLink(string  $url) : self

Set an 'atom:link' channel element with relation=self attribute.

Needs the full URL to this feed.

Parameters

string $url

URL to this feed

Returns

self

setImage()

setImage(string  $url, string  $title = null, string  $link = null) : self

Set the 'image' channel element

Parameters

string $url

URL of the image

string $title

Title of the image. RSS only.

string $link

Link target URL of the image. RSS only.

Throws

\InvalidArgumentException

if the url is invalid.

\InvalidArgumentException

if the title and link parameter are not a string or empty.

Returns

self

setChannelAbout()

setChannelAbout(string  $url) : self

Set the channel 'rdf:about' attribute, which is used in RSS1 feeds only.

Parameters

string $url

value of 'rdf:about' attribute of the channel element

Throws

\FeedWriter\InvalidOperationException

if this method is called and the feed is not of type RSS1.

\InvalidArgumentException

if the given URL is invalid.

Returns

self

uuid()

uuid(string  $key = null, string  $prefix = '') : string

Generate an UUID.

The UUID is based on an MD5 hash. If no key is given, a unique ID as the input for the MD5 hash is generated.

Parameters

string $key

optional key on which the UUID is generated

string $prefix

an optional prefix

Returns

string —

the formatted UUID

filterInvalidXMLChars()

filterInvalidXMLChars(string  $string, string  $replacement = '_') : string

Replace invalid XML characters.

Parameters

string $string

string which should be filtered

string $replacement

replace invalid characters with this string

Returns

string —

the filtered string

__construct()

__construct(string  $version = \FeedWriter\Feed::RSS2) 

Constructor

If no version is given, a feed in RSS 2.0 format will be generated.

Parameters

string $version

the version constant (RSS1/RSS2/ATOM).

getNamespacePrefixes()

getNamespacePrefixes() : array

Returns all used XML namespace prefixes in this instance.

This includes all channel elements and feed items. Unfortunately some namespace prefixes are not included, because they are hardcoded, e.g. rdf.

Returns

array —

Array with namespace prefix as value.

makeHeader()

makeHeader() : string

Returns the XML header and root element, depending on the feed type.

Throws

\FeedWriter\InvalidOperationException

if an unknown XML namespace prefix is encountered.

Returns

string —

The XML header of the feed.

makeFooter()

makeFooter() : string

Closes the open tags at the end of file

Returns

string —

The XML footer of the feed.

makeNode()

makeNode(string  $tagName, mixed  $tagContent, array  $attributes = null, boolean  $omitEndTag = false) : string

Creates a single node in XML format

Parameters

string $tagName

name of the tag

mixed $tagContent

tag value as string or array of nested tags in 'tagName' => 'tagValue' format

array $attributes

Attributes (if any) in 'attrName' => 'attrValue' format

boolean $omitEndTag

True if the end tag should be omitted. Defaults to false.

Throws

\InvalidArgumentException

if the tagContent is not an array and not a string.

Returns

string —

formatted xml tag

makeChannels()

makeChannels() : string

Make the channels.

Returns

string —

The feed header as XML containing all the feed metadata.

makeItems()

makeItems() : string

Prints formatted feed items

Returns

string —

The XML of every feed item.

startItem()

startItem(string  $about = false) : string

Make the starting tag of channels

Parameters

string $about

The value of about attribute which is used for RSS 1.0 only.

Throws

\FeedWriter\InvalidOperationException

if this object misses the data for the about attribute.

Returns

string —

The starting XML tag of an feed item.

endItem()

endItem() : string

Closes feed item tag

Returns

string —

The ending XML tag of an feed item.

sanitizeCDATA()

sanitizeCDATA(string  $text) : string

Sanitizes data which will be later on returned as CDATA in the feed.

A "]]>" respectively "<![CDATA" in the data would break the CDATA in the XML, so the brackets are converted to a HTML entity.

Parameters

string $text

Data to be sanitized

Returns

string —

Sanitized data