Class FeedReader

Description

Parses feeds from external URLs

Transforms the parsed data into a tree of objects (FeedChannel and FeedItem). Supports caching of feed data (based on a lifetime), and supports RSS 0.9x, 1.0, 2.0 and ATOM 0.x formats.

Example:

  1.  $reader new FeedReader();
  2.  $reader->setCacheProperties('cache/feeds/'60*30);
  3.  $feed =$reader->fetch('http://www.php2go.com.br/rss.php');
  4.  $iterator =$feed->Channel->itemIterator();
  5.  while ($iterator->hasNext()) {
  6.    $item $iterator->next();
  7.    println($item->title);
  8.  }

Located in /core/xml/feed/FeedReader.class.php (line 68)

PHP2Go
   |
   --FeedReader
Variable Summary
Method Summary
FeedChannel &fetch (string $url)
array getLastResponse ()
void setCacheProperties (string $dir, [int $lifeTime = NULL], [string $group = NULL])
void setTargetEncoding (string $encoding)
void setUserAgent (string $userAgent)
void _characterData (resource $parser, string $text)
void _endElement (resource $parser, string $element)
bool _fetchFeed ()
bool _parseFeed (string $content)
void _parseNodeName (string $qualifiedName, string &$name, string &$ns)
void _reset ()
void _startElement (resource $parser, string $element, array $attrs)
Variables
array $cacheOptions = array() (line 96)

Cache options

string $targetEncoding (line 75)

Target encoding, to be used when parsing feeds

Url $Url = NULL (line 89)

Last fetched feed URL

string $userAgent (line 82)

User agent to be sent when fetching feeds

array $_currentAttrs (line 144)

Controls attributes while parsing the feed

  • access: private
array $_currentCompElement (line 128)

Controls composite elements while parsing the feed

  • access: private
array $_currentElement (line 136)

Controls elements while parsing the feed

  • access: private
Feed $_currentFeed (line 112)

Current feed being processed

  • access: private
FeedItem $_currentItem (line 120)

Controls items while parsing the feed

  • access: private
array $_lastResponse = NULL (line 104)

Last HTTP response

  • access: private
Methods
Constructor FeedReader (line 151)

Class constructor

FeedReader FeedReader ()
fetch (line 222)

Fetch a feed from an external URL

When caching is enabled, the method tries to load the feed from cache. If not found, or if cache is not enabled, the feed is fetched using an HTTP connection and parsed through an expat parser.

FeedChannel &fetch (string $url)
  • string $url: URL
getLastResponse (line 171)

Gets the response produced from the last request

Returns a hash array containing 2 keys: headers (response headers) and body (response body). If a feed is loaded from cache, the headers represent the last time the feed was fetched from its original source.

array getLastResponse ()
setCacheProperties (line 203)

Set cache properties

void setCacheProperties (string $dir, [int $lifeTime = NULL], [string $group = NULL])
  • string $dir: Base dir
  • int $lifeTime: Lifetime, in seconds
  • string $group: Cache group
setTargetEncoding (line 183)

Set target encoding

Defines which encoding must be used by PHP's expat parser when parsing the contents of feeds.

void setTargetEncoding (string $encoding)
  • string $encoding: Encoding
setUserAgent (line 192)

Set user agent to be used when fetching feeds

void setUserAgent (string $userAgent)
  • string $userAgent: User agent
_characterData (line 437)

CDATA handler of the feed parser

  • access: private
void _characterData (resource $parser, string $text)
  • resource $parser: Parser
  • string $text: CDATA contents
_endElement (line 376)

End element handler of the feed parser

  • access: private
void _endElement (resource $parser, string $element)
  • resource $parser: Parser
  • string $element: Element name
_fetchFeed (line 264)

Internal method used to fetch feed contents through an HTTP connection

  • access: private
bool _fetchFeed ()
_parseFeed (line 291)

Internal method used to parse the XML contents of a feed

bool _parseFeed (string $content)
  • string $content: Feed contents
_parseNodeName (line 450)

Retrieves the namespace and the local name from a qualified name

  • access: private
void _parseNodeName (string $qualifiedName, string &$name, string &$ns)
  • string $qualifiedName: Qualified name
  • string &$name: Used to return the local name
  • string &$ns: Used to return the namespace prefix
_reset (line 463)

Resets all control variables before fetching a new feed

  • access: private
void _reset ()
_startElement (line 319)

Start element handler of the feed parser

  • access: private
void _startElement (resource $parser, string $element, array $attrs)
  • resource $parser: Parser
  • string $element: Element name
  • array $attrs: Element attributes

Inherited Methods

Inherited From PHP2Go

PHP2Go::PHP2Go()
PHP2Go::equals()
PHP2Go::generateUniqueId()
PHP2Go::getClassName()
PHP2Go::getConfigVal()
PHP2Go::getLangVal()
PHP2Go::getObjectName()
PHP2Go::getParentName()
PHP2Go::hasDestructor()
PHP2Go::hashCode()
PHP2Go::isA()
PHP2Go::isSubclassOf()
PHP2Go::logError()
PHP2Go::raiseError()
PHP2Go::registerDestructor()
PHP2Go::registerShutdownFunc()
PHP2Go::retrieve()
PHP2Go::store()
PHP2Go::__toString()

Documentation generated on Sun, 07 Oct 2007 19:24:11 -0300 by phpDocumentor 1.3.2