Source for file RSS.php
Documentation is available at RSS.php
// vim: set expandtab tabstop=4 shiftwidth=4 fdm=marker:
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Martin Jansen <mj@php.net> |
// +----------------------------------------------------------------------+
// $Id: RSS.php,v 1.26 2005/05/25 20:48:46 mj Exp $
require_once 'XML/Parser.php';
* This class is a parser for Resource Description Framework (RDF) Site
* Summary (RSS) documents. For more information on RSS see the
* website of the RSS working group (http://www.purl.org/rss/).
* @author Martin Jansen <mj@php.net>
* @version $Revision: 1.26 $
class XML_RSS extends XML_Parser
var $insideTagStack = array ();
var $textinput = array ();
var $textinputs = array ();
var $parentTags = array ('CHANNEL', 'ITEM', 'IMAGE', 'TEXTINPUT');
var $channelTags = array ('TITLE', 'LINK', 'DESCRIPTION', 'IMAGE',
'ITEMS', 'TEXTINPUT', 'LANGUAGE', 'COPYRIGHT',
'MANAGINGEditor', 'WEBMASTER', 'PUBDATE', 'LASTBUILDDATE',
'CATEGORY', 'GENERATOR', 'DOCS', 'CLOUD', 'TTL',
var $itemTags = array ('TITLE', 'LINK', 'DESCRIPTION', 'PUBDATE', 'AUTHOR', 'CATEGORY',
'COMMENTS', 'ENCLOSURE', 'GUID', 'PUBDATE', 'SOURCE',
var $imageTags = array ('TITLE', 'URL', 'LINK', 'WIDTH', 'HEIGHT');
var $textinputTags = array ('TITLE', 'DESCRIPTION', 'NAME', 'LINK');
* List of allowed module tags
* Currently Dublin Core Metadata, blogChannel RSS module, CreativeCommons,
* Content and Syndication are supported.
var $moduleTags = array ('DC:TITLE', 'DC:CREATOR', 'DC:SUBJECT', 'DC:DESCRIPTION',
'DC:PUBLISHER', 'DC:CONTRIBUTOR', 'DC:DATE', 'DC:TYPE',
'DC:FORMAT', 'DC:IDENTIFIER', 'DC:SOURCE', 'DC:LANGUAGE',
'DC:RELATION', 'DC:COVERAGE', 'DC:RIGHTS',
'BLOGCHANNEL:BLOGROLL', 'BLOGCHANNEL:MYSUBSCRIPTIONS',
'BLOGCHANNEL:MYSUBSCRIPTIONS', 'BLOGCHANNEL:CHANGES',
'CC:LICENSE', 'CONTENT:ENCODED',
'SY:UPDATEPERIOD', 'SY:UPDATEFREQUENCY', 'SY:UPDATEBASE',
* @param mixed File pointer, name of the RSS file, or an RSS string.
* @param string Source charset encoding, use null (default) to use
* default encoding (ISO-8859-1)
* @param string Target charset encoding, use null (default) to use
* default encoding (ISO-8859-1)
function XML_RSS ($handle = '', $srcenc = null , $tgtenc = null )
if ($srcenc === null && $tgtenc === null ) {
$this->XML_Parser ($srcenc, 'event', $tgtenc);
$this->setInput ($handle);
$this->raiseError ('No input passed.');
* Start element handler for XML parser
* @param object XML parser object
* @param string XML element
* @param array Attributes of XML tag
function startHandler ($parser, $element, $attribs)
if (substr($element, 0 , 4 ) == "RSS:") {
$element = substr($element, 4 );
$this->insideTag = $element;
$this->attribs = $attribs;
$this->activeTag = $element;
* End element handler for XML parser
* If the end of <item>, <channel>, <image> or <textinput>
* is reached, this method updates the structure array
* $this->struct[] and adds the field "type" to this array,
* that defines the type of the current field.
* @param object XML parser object
function endHandler ($parser, $element)
if (substr($element, 0 , 4 ) == "RSS:") {
$element = substr($element, 4 );
if ($element == $this->insideTag) {
$this->insideTag = end($this->insideTagStack);
if ($element == 'ITEM') {
$this->items[] = $this->item;
if ($element == 'IMAGE') {
$this->images[] = $this->image;
if ($element == 'TEXTINPUT') {
$this->textinputs = $this->textinput;
if ($element == 'ENCLOSURE') {
if (!isset ($this->item['enclosures'])) {
$this->item['enclosures'] = array ();
$this->attribs = array ();
* Handler for character data
* @param object XML parser object
function cdataHandler ($parser, $cdata)
if (in_array($this->insideTag, $this->parentTags)) {
$var = $this->{$tagName . 'Tags'};
in_array($this->activeTag, $this->moduleTags)) {
$this->_add ($tagName, strtolower($this->activeTag),
* Default handler for XML parser
* @param object XML parser object
function defaultHandler ($parser, $cdata)
* Add element to internal result sets
* @param string Name of the result set
* @param string Fieldname
function _add ($type, $field, $value)
if (empty ($this->{$type}) || empty ($this->{$type}[$field])) {
$this->{$type}[$field] = $value;
$this->{$type}[$field] .= $value;
$this->last = $this->{$type};
* Get complete structure of RSS file
return (array) $this->struct;
* Get general information about current channel
* This method returns an array containing the information
* that has been extracted from the <channel>-tag while parsing
function getChannelInfo ()
return (array) $this->channel;
* Get items from RSS file
* This method returns an array containing the set of items
* that are provided by the RSS file.
return (array) $this->items;
* Get images from RSS file
* This method returns an array containing the set of images
* that are provided by the RSS file.
return (array) $this->images;
* Get text input fields from RSS file
return (array) $this->textinputs;
Documentation generated on Mon, 11 Mar 2019 14:12:09 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|