web/lib/Zend/Feed/Entry/Abstract.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * Zend Framework
       
     5  *
       
     6  * LICENSE
       
     7  *
       
     8  * This source file is subject to the new BSD license that is bundled
       
     9  * with this package in the file LICENSE.txt.
       
    10  * It is also available through the world-wide-web at this URL:
       
    11  * http://framework.zend.com/license/new-bsd
       
    12  * If you did not receive a copy of the license and are unable to
       
    13  * obtain it through the world-wide-web, please send an email
       
    14  * to license@zend.com so we can send you a copy immediately.
       
    15  *
       
    16  * @category   Zend
       
    17  * @package    Zend_Feed
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: Abstract.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 
       
    24 /**
       
    25  * @see Zend_Feed
       
    26  */
       
    27 require_once 'Zend/Feed.php';
       
    28 
       
    29 /**
       
    30  * @see Zend_Feed_Element
       
    31  */
       
    32 require_once 'Zend/Feed/Element.php';
       
    33 
       
    34 
       
    35 /**
       
    36  * Zend_Feed_Entry_Abstract represents a single entry in an Atom or RSS
       
    37  * feed.
       
    38  *
       
    39  * @category   Zend
       
    40  * @package    Zend_Feed
       
    41  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    42  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    43  */
       
    44 abstract class Zend_Feed_Entry_Abstract extends Zend_Feed_Element
       
    45 {
       
    46     /**
       
    47      * Root XML element for entries. Subclasses must define this to a
       
    48      * non-null value.
       
    49      *
       
    50      * @var string
       
    51      */
       
    52     protected $_rootElement;
       
    53 
       
    54     /**
       
    55      * Root namespace for entries. Subclasses may define this to a
       
    56      * non-null value.
       
    57      *
       
    58      * @var string
       
    59      */
       
    60     protected $_rootNamespace = null;
       
    61 
       
    62 
       
    63     /**
       
    64      * Zend_Feed_Entry_Abstract constructor
       
    65      *
       
    66      * The Zend_Feed_Entry_Abstract constructor takes the URI of the feed the entry
       
    67      * is part of, and optionally an XML construct (usually a
       
    68      * SimpleXMLElement, but it can be an XML string or a DOMNode as
       
    69      * well) that contains the contents of the entry.
       
    70      *
       
    71      * @param  string $uri
       
    72      * @param  SimpleXMLElement|DOMNode|string  $element
       
    73      * @return void
       
    74      * @throws Zend_Feed_Exception
       
    75      */
       
    76     public function __construct($uri = null, $element = null)
       
    77     {
       
    78         if (!($element instanceof DOMElement)) {
       
    79             if ($element) {
       
    80                 // Load the feed as an XML DOMDocument object
       
    81                 @ini_set('track_errors', 1);
       
    82                 $doc = new DOMDocument();
       
    83                 $status = @$doc->loadXML($element);
       
    84                 @ini_restore('track_errors');
       
    85 
       
    86                 if (!$status) {
       
    87                     // prevent the class to generate an undefined variable notice (ZF-2590)
       
    88                     if (!isset($php_errormsg)) {
       
    89                         if (function_exists('xdebug_is_enabled')) {
       
    90                             $php_errormsg = '(error message not available, when XDebug is running)';
       
    91                         } else {
       
    92                             $php_errormsg = '(error message not available)';
       
    93                         }
       
    94                     }
       
    95 
       
    96                     /**
       
    97                      * @see Zend_Feed_Exception
       
    98                      */
       
    99                     require_once 'Zend/Feed/Exception.php';
       
   100                     throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg");
       
   101                 }
       
   102 
       
   103                 $element = $doc->getElementsByTagName($this->_rootElement)->item(0);
       
   104                 if (!$element) {
       
   105                     /**
       
   106                      * @see Zend_Feed_Exception
       
   107                      */
       
   108                     require_once 'Zend/Feed/Exception.php';
       
   109                     throw new Zend_Feed_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
       
   110                 }
       
   111             } else {
       
   112                 $doc = new DOMDocument('1.0', 'utf-8');
       
   113                 if ($this->_rootNamespace !== null) {
       
   114                     $element = $doc->createElementNS(Zend_Feed::lookupNamespace($this->_rootNamespace), $this->_rootElement);
       
   115                 } else {
       
   116                     $element = $doc->createElement($this->_rootElement);
       
   117                 }
       
   118             }
       
   119         }
       
   120 
       
   121         parent::__construct($element);
       
   122     }
       
   123 
       
   124 }