XML_Feed_Parser
[ class tree: XML_Feed_Parser ] [ index: XML_Feed_Parser ] [ all elements ]

Source for file RSS11Element.php

Documentation is available at RSS11Element.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * RSS1 Element class for XML_Feed_Parser
  6.  *
  7.  * PHP versions 5
  8.  *
  9.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  10.  * that is available through the world-wide-web at the following URI:
  11.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  12.  * the PHP License and are unable to obtain it through the web, please
  13.  * send a note to license@php.net so we can mail you a copy immediately.
  14.  *
  15.  * @category   XML
  16.  * @package    XML_Feed_Parser
  17.  * @author     James Stewart <james@jystewart.net>
  18.  * @copyright  2005 James Stewart <james@jystewart.net>
  19.  * @license    http://www.gnu.org/copyleft/lesser.html  GNU LGPL 2.1
  20.  * @version    CVS: $Id: RSS11Element.php,v 1.4 2006/06/30 17:41:56 jystewart Exp $
  21.  * @link       http://pear.php.net/package/XML_Feed_Parser/
  22.  */
  23.  
  24. /*
  25.  * This class provides support for RSS 1.1 entries. It will usually be called by
  26.  * XML_Feed_Parser_RSS11 with which it shares many methods.
  27.  *
  28.  * @author    James Stewart <james@jystewart.net>
  29.  * @version    Release: 1.0.3
  30.  * @package XML_Feed_Parser
  31.  */
  32. {
  33.     /**
  34.      * This will be a reference to the parent object for when we want
  35.      * to use a 'fallback' rule
  36.      * @var XML_Feed_Parser_RSS1 
  37.      */
  38.     protected $parent;
  39.  
  40.     /**
  41.      * Our specific element map
  42.      * @var array 
  43.      */
  44.     protected $map = array(
  45.         'id' => array('Id'),
  46.         'title' => array('Text'),
  47.         'link' => array('Link'),
  48.         'description' => array('Text')# or dc:description
  49.         'category' => array('Category'),
  50.         'rights' => array('Text')# dc:rights
  51.         'creator' => array('Text')# dc:creator
  52.         'publisher' => array('Text')# dc:publisher
  53.         'contributor' => array('Text')# dc:contributor
  54.         'date' => array('Date')# dc:date
  55.         'content' => array('Content')
  56.         );
  57.  
  58.     /**
  59.      * Here we map some elements to their atom equivalents. This is going to be
  60.      * quite tricky to pull off effectively (and some users' methods may vary)
  61.      * but is worth trying. The key is the atom version, the value is RSS1.
  62.      * @var array 
  63.      */
  64.     protected $compatMap = array(
  65.         'content' => array('content'),
  66.         'updated' => array('lastBuildDate'),
  67.         'published' => array('pubdate'),
  68.         'subtitle' => array('description'),
  69.         'updated' => array('date'),
  70.         'author' => array('creator'),
  71.         'contributor' => array('contributor')
  72.     );
  73.  
  74.     /**
  75.      * Store useful information for later.
  76.      *
  77.      * @param   DOMElement  $element - this item as a DOM element
  78.      * @param   XML_Feed_Parser_RSS1 $parent - the feed of which this is a member
  79.      */
  80.     function __construct(DOMElement $element$parent$xmlBase '')
  81.     {
  82.         $this->model = $element;
  83.         $this->parent = $parent;
  84.     }
  85.  
  86.     /**
  87.      * If an rdf:about attribute is specified, return that as an ID
  88.      *
  89.      * There is no established way of showing an ID for an RSS1 entry. We will
  90.      * simulate it using the rdf:about attribute of the entry element. This cannot
  91.      * be relied upon for unique IDs but may prove useful.
  92.      *
  93.      * @return  string|false
  94.      */
  95.     function getId()
  96.     {
  97.         if ($this->model->attributes->getNamedItem('about')) {
  98.             return $this->model->attributes->getNamedItem('about')->nodeValue;
  99.         }
  100.         return false;
  101.     }
  102.  
  103.     /**
  104.      * Return the entry's content
  105.      *
  106.      * The official way to include full content in an RSS1 entry is to use
  107.      * the content module's element 'encoded'. Often, however, the 'description'
  108.      * element is used instead. We will offer that as a fallback.
  109.      *
  110.      * @return  string|false
  111.      */
  112.     function getContent()
  113.     {
  114.         $options = array('encoded''description');
  115.         foreach ($options as $element{
  116.             $test $this->model->getElementsByTagName($element);
  117.             if ($test->length == 0{
  118.                 continue;
  119.             }
  120.             if ($test->item(0)->hasChildNodes()) {
  121.                 $value '';
  122.                 foreach ($test->item(0)->childNodes as $child{
  123.                     if ($child instanceof DOMText{
  124.                         $value .= $child->nodeValue;
  125.                     else {
  126.                         $simple simplexml_import_dom($child);
  127.                         $value .= $simple->asXML();
  128.                     }
  129.                 }
  130.                 return $value;
  131.             else if ($test->length > 0{
  132.                 return $test->item(0)->nodeValue;
  133.             }
  134.         }
  135.         return false;
  136.     }
  137.     
  138.     /**
  139.      * How RSS1.1 should support for enclosures is not clear. For now we will return
  140.      * false.
  141.      *
  142.      * @return  false 
  143.      */
  144.     function getEnclosure()
  145.     {
  146.         return false;
  147.     }
  148. }
  149.  
  150. ?>

Documentation generated on Wed, 19 Nov 2008 08:30:12 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.