File indexing completed on 2024-06-16 05:30:01

0001 <?php
0002 
0003 /**
0004  * Zend Framework
0005  *
0006  * LICENSE
0007  *
0008  * This source file is subject to the new BSD license that is bundled
0009  * with this package in the file LICENSE.txt.
0010  * It is also available through the world-wide-web at this URL:
0011  * http://framework.zend.com/license/new-bsd
0012  * If you did not receive a copy of the license and are unable to
0013  * obtain it through the world-wide-web, please send an email
0014  * to license@zend.com so we can send you a copy immediately.
0015  *
0016  * @category   Zend
0017  * @package    Zend_Feed
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 
0024 /**
0025  * @see Zend_Feed
0026  */
0027 // require_once 'Zend/Feed.php';
0028 
0029 /**
0030  * @see Zend_Feed_Element
0031  */
0032 // require_once 'Zend/Feed/Element.php';
0033 
0034 /** @see Zend_Xml_Security */
0035 // require_once 'Zend/Xml/Security.php';
0036 
0037 /**
0038  * Zend_Feed_Entry_Abstract represents a single entry in an Atom or RSS
0039  * feed.
0040  *
0041  * @category   Zend
0042  * @package    Zend_Feed
0043  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0044  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0045  */
0046 abstract class Zend_Feed_Entry_Abstract extends Zend_Feed_Element
0047 {
0048     /**
0049      * Root XML element for entries. Subclasses must define this to a
0050      * non-null value.
0051      *
0052      * @var string
0053      */
0054     protected $_rootElement;
0055 
0056     /**
0057      * Root namespace for entries. Subclasses may define this to a
0058      * non-null value.
0059      *
0060      * @var string
0061      */
0062     protected $_rootNamespace = null;
0063 
0064 
0065     /**
0066      * Zend_Feed_Entry_Abstract constructor
0067      *
0068      * The Zend_Feed_Entry_Abstract constructor takes the URI of the feed the entry
0069      * is part of, and optionally an XML construct (usually a
0070      * SimpleXMLElement, but it can be an XML string or a DOMNode as
0071      * well) that contains the contents of the entry.
0072      *
0073      * @param  string $uri
0074      * @param  SimpleXMLElement|DOMNode|string  $element
0075      * @return void
0076      * @throws Zend_Feed_Exception
0077      */
0078     public function __construct($uri = null, $element = null)
0079     {
0080         if (!($element instanceof DOMElement)) {
0081             if ($element) {
0082                 // Load the feed as an XML DOMDocument object
0083                 @ini_set('track_errors', 1);
0084                 $doc = new DOMDocument();
0085                 $doc = @Zend_Xml_Security::scan($element, $doc);
0086                 @ini_restore('track_errors');
0087 
0088                 if (!$doc) {
0089                     // prevent the class to generate an undefined variable notice (ZF-2590)
0090                     if (!isset($php_errormsg)) {
0091                         if (function_exists('xdebug_is_enabled')) {
0092                             $php_errormsg = '(error message not available, when XDebug is running)';
0093                         } else {
0094                             $php_errormsg = '(error message not available)';
0095                         }
0096                     }
0097 
0098                     /**
0099                      * @see Zend_Feed_Exception
0100                      */
0101                     // require_once 'Zend/Feed/Exception.php';
0102                     throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg");
0103                 }
0104 
0105                 $element = $doc->getElementsByTagName($this->_rootElement)->item(0);
0106                 if (!$element) {
0107                     /**
0108                      * @see Zend_Feed_Exception
0109                      */
0110                     // require_once 'Zend/Feed/Exception.php';
0111                     throw new Zend_Feed_Exception('No root <' . $this->_rootElement . '> element found, cannot parse feed.');
0112                 }
0113             } else {
0114                 $doc = new DOMDocument('1.0', 'utf-8');
0115                 if ($this->_rootNamespace !== null) {
0116                     $element = $doc->createElementNS(Zend_Feed::lookupNamespace($this->_rootNamespace), $this->_rootElement);
0117                 } else {
0118                     $element = $doc->createElement($this->_rootElement);
0119                 }
0120             }
0121         }
0122 
0123         parent::__construct($element);
0124     }
0125 
0126 }