PHP Class FeedWriter\Feed

Generate RSS 1.0, RSS2.0 and ATOM Feeds
Author: Anis uddin Ahmad ([email protected])
Afficher le fichier Open project: mibe/feedwriter Class Usage Examples

Méthodes publiques

Méthode Description
addCDATAEncoding ( array $tags ) : self Add one or more tags to the list of CDATA encoded tags
addGenerator ( ) : self Add a channel element indicating the program used to generate the feed.
addItem ( Item $feedItem ) : self Add a FeedItem to the main class
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.
createNewItem ( ) : Item Create a new Item.
filterInvalidXMLChars ( string $string, string $replacement = '_' ) : string Replace invalid XML characters.
generateFeed ( ) : string Generate the feed.
getCDATAEncoding ( ) : array Get list of CDATA encoded properties
getMIMEType ( ) : string Get the appropriate MIME type string for the current feed.
printFeed ( $useGenericContentType = false ) : void Print the actual RSS/ATOM file
removeCDATAEncoding ( array $tags ) : void Remove tags from the list of CDATA encoded tags
setAtomLink ( string $href, string $rel = null, string $type = null, string $hreflang = null, string $title = null, integer $length = null ) : self Set custom 'link' channel elements.
setChannelAbout ( string $url ) : self Set the channel 'rdf:about' attribute, which is used in RSS1 feeds only.
setChannelElement ( string $elementName, string $content, array $attributes = null, $multiple = false ) : self Add a channel element to the feed.
setChannelElementsFromArray ( array $elementArray ) : self Set multiple channel elements from an array. Array elements should be 'channelName' => 'channelContent' format.
setDate ( $date ) : self Set the date when the feed was lastly updated.
setDescription ( string $description ) : self Set a phrase or sentence describing the feed.
setEncoding ( string $encoding ) : self Set the 'encoding' attribute in the XML prolog.
setImage ( string $url, string $title = null, string $link = null ) : self Set the 'image' channel element
setLink ( string $link ) : self Set the 'link' channel element
setPagination ( string $nextURL = null, string $previousURL = null, string $firstURL = null, string $lastURL = null ) : self Set the URLs for feed pagination.
setSelfLink ( string $url ) : self Set an 'atom:link' channel element with relation=self attribute.
setTitle ( string $title ) : self Set the 'title' channel element
uuid ( string $key = null, string $prefix = '' ) : string Generate an UUID.

Méthodes protégées

Méthode Description
__construct ( string $version = Feed::RSS2 ) Constructor

Private Methods

Méthode Description
endItem ( ) : string Closes feed item tag
getNamespacePrefixes ( ) : array Returns all used XML namespace prefixes in this instance.
makeChannels ( ) : string Make the channels.
makeFooter ( ) : string Closes the open tags at the end of file
makeHeader ( ) : string Returns the XML header and root element, depending on the feed type.
makeItems ( ) : string Prints formatted feed items
makeNode ( string $tagName, mixed $tagContent, array $attributes = null, boolean $omitEndTag = false ) : string Creates a single node in XML format
sanitizeCDATA ( string $text ) : string Sanitizes data which will be later on returned as CDATA in the feed.
startItem ( string $about = false ) : string Make the starting tag of channels

Method Details

__construct() protected méthode

If no version is given, a feed in RSS 2.0 format will be generated.
protected __construct ( string $version = Feed::RSS2 )
$version string the version constant (RSS1/RSS2/ATOM).

addCDATAEncoding() public méthode

Add one or more tags to the list of CDATA encoded tags
public addCDATAEncoding ( array $tags ) : self
$tags array An array of tag names that are merged into the list of tags which should be encoded as CDATA
Résultat self

addGenerator() public méthode

Add a channel element indicating the program used to generate the feed.
public addGenerator ( ) : self
Résultat self

addItem() public méthode

Add a FeedItem to the main class
public addItem ( Item $feedItem ) : self
$feedItem Item instance of Item class
Résultat self

addNamespace() public méthode

Add a XML namespace to the internal list of namespaces. After that, custom channel elements can be used properly to generate a valid feed.
public addNamespace ( string $prefix, string $uri ) : self
$prefix string namespace prefix
$uri string namespace name (URI)
Résultat self

createNewItem() public méthode

Create a new Item.
public createNewItem ( ) : Item
Résultat Item instance of Item class

filterInvalidXMLChars() public static méthode

Replace invalid XML characters.
public static filterInvalidXMLChars ( string $string, string $replacement = '_' ) : string
$string string string which should be filtered
$replacement string replace invalid characters with this string
Résultat string the filtered string

generateFeed() public méthode

Generate the feed.
public generateFeed ( ) : string
Résultat string The complete feed XML.

getCDATAEncoding() public méthode

Get list of CDATA encoded properties
public getCDATAEncoding ( ) : array
Résultat array Return an array of CDATA properties that are to be encoded as CDATA

getMIMEType() public méthode

Get the appropriate MIME type string for the current feed.
public getMIMEType ( ) : string
Résultat string The MIME type string.

printFeed() public méthode

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.
public printFeed ( $useGenericContentType = false ) : void
Résultat void

removeCDATAEncoding() public méthode

Remove tags from the list of CDATA encoded tags
public removeCDATAEncoding ( array $tags ) : void
$tags array An array of tag names that should be removed.
Résultat void

setChannelAbout() public méthode

Set the channel 'rdf:about' attribute, which is used in RSS1 feeds only.
public setChannelAbout ( string $url ) : self
$url string value of 'rdf:about' attribute of the channel element
Résultat self

setChannelElement() public méthode

Add a channel element to the feed.
public setChannelElement ( string $elementName, string $content, array $attributes = null, $multiple = false ) : self
$elementName string name of the channel tag
$content string content of the channel tag
$attributes array
Résultat self

setChannelElementsFromArray() public méthode

Set multiple channel elements from an array. Array elements should be 'channelName' => 'channelContent' format.
public setChannelElementsFromArray ( array $elementArray ) : self
$elementArray array
Résultat self

setDate() public méthode

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.
public setDate ( $date ) : self
Résultat self

setDescription() public méthode

Set a phrase or sentence describing the feed.
public setDescription ( string $description ) : self
$description string Description of the feed.
Résultat self

setEncoding() public méthode

Set the 'encoding' attribute in the XML prolog.
public setEncoding ( string $encoding ) : self
$encoding string value of 'encoding' attribute
Résultat self

setImage() public méthode

Set the 'image' channel element
public setImage ( string $url, string $title = null, string $link = null ) : self
$url string URL of the image
$title string Title of the image. RSS only.
$link string Link target URL of the image. RSS only.
Résultat self

setPagination() public méthode

See RFC 5005, chapter 3. At least one page URL must be specified.
public setPagination ( string $nextURL = null, string $previousURL = null, string $firstURL = null, string $lastURL = null ) : self
$nextURL string The URL to the next page of this feed. Optional.
$previousURL string The URL to the previous page of this feed. Optional.
$firstURL string The URL to the first page of this feed. Optional.
$lastURL string The URL to the last page of this feed. Optional.
Résultat self

setTitle() public méthode

Set the 'title' channel element
public setTitle ( string $title ) : self
$title string value of 'title' channel tag
Résultat self

uuid() public static méthode

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.
Author: Anis uddin Ahmad ([email protected])
public static uuid ( string $key = null, string $prefix = '' ) : string
$key string optional key on which the UUID is generated
$prefix string an optional prefix
Résultat string the formatted UUID