File indexing completed on 2025-03-02 05:29:21
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Feed_Reader 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @see Zend_Feed_Reader 0024 */ 0025 // require_once 'Zend/Feed/Reader.php'; 0026 0027 /** 0028 * @see Zend_Feed_Reader_Entry_Atom 0029 */ 0030 // require_once 'Zend/Feed/Reader/Entry/Atom.php'; 0031 0032 0033 /** 0034 * @see Zend_Feed_Reader_Entry_Rss 0035 */ 0036 // require_once 'Zend/Feed/Reader/Entry/Rss.php'; 0037 0038 /** 0039 * @category Zend 0040 * @package Zend_Feed_Reader 0041 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0042 * @license http://framework.zend.com/license/new-bsd New BSD License 0043 */ 0044 abstract class Zend_Feed_Reader_Extension_FeedAbstract 0045 { 0046 /** 0047 * Parsed feed data 0048 * 0049 * @var array 0050 */ 0051 protected $_data = array(); 0052 0053 /** 0054 * Parsed feed data in the shape of a DOMDocument 0055 * 0056 * @var DOMDocument 0057 */ 0058 protected $_domDocument = null; 0059 0060 /** 0061 * The base XPath query used to retrieve feed data 0062 * 0063 * @var DOMXPath 0064 */ 0065 protected $_xpath = null; 0066 0067 /** 0068 * The XPath prefix 0069 * 0070 * @var string 0071 */ 0072 protected $_xpathPrefix = ''; 0073 0074 /** 0075 * Constructor 0076 * 0077 * @param Zend_Feed_Abstract $feed The source Zend_Feed object 0078 * @param string $type Feed type 0079 * @return void 0080 */ 0081 public function __construct(DomDocument $dom, $type = null, DOMXPath $xpath = null) 0082 { 0083 $this->_domDocument = $dom; 0084 0085 if ($type !== null) { 0086 $this->_data['type'] = $type; 0087 } else { 0088 $this->_data['type'] = Zend_Feed_Reader::detectType($dom); 0089 } 0090 0091 if ($xpath !== null) { 0092 $this->_xpath = $xpath; 0093 } else { 0094 $this->_xpath = new DOMXPath($this->_domDocument); 0095 } 0096 0097 $this->_registerNamespaces(); 0098 } 0099 0100 /** 0101 * Get the DOM 0102 * 0103 * @return DOMDocument 0104 */ 0105 public function getDomDocument() 0106 { 0107 return $this->_domDocument; 0108 } 0109 0110 /** 0111 * Get the Feed's encoding 0112 * 0113 * @return string 0114 */ 0115 public function getEncoding() 0116 { 0117 $assumed = $this->getDomDocument()->encoding; 0118 return $assumed; 0119 } 0120 0121 /** 0122 * Get the feed type 0123 * 0124 * @return string 0125 */ 0126 public function getType() 0127 { 0128 return $this->_data['type']; 0129 } 0130 0131 0132 /** 0133 * Return the feed as an array 0134 * 0135 * @return array 0136 */ 0137 public function toArray() // untested 0138 { 0139 return $this->_data; 0140 } 0141 0142 /** 0143 * Set the XPath query 0144 * 0145 * @param DOMXPath $xpath 0146 * @return Zend_Feed_Reader_Extension_EntryAbstract 0147 */ 0148 public function setXpath(DOMXPath $xpath) 0149 { 0150 $this->_xpath = $xpath; 0151 $this->_registerNamespaces(); 0152 return $this; 0153 } 0154 0155 /** 0156 * Get the DOMXPath object 0157 * 0158 * @return string 0159 */ 0160 public function getXpath() 0161 { 0162 return $this->_xpath; 0163 } 0164 0165 /** 0166 * Get the XPath prefix 0167 * 0168 * @return string 0169 */ 0170 public function getXpathPrefix() 0171 { 0172 return $this->_xpathPrefix; 0173 } 0174 0175 /** 0176 * Set the XPath prefix 0177 * 0178 * @return Zend_Feed_Reader_Feed_Atom 0179 */ 0180 public function setXpathPrefix($prefix) 0181 { 0182 $this->_xpathPrefix = $prefix; 0183 } 0184 0185 /** 0186 * Register the default namespaces for the current feed format 0187 */ 0188 abstract protected function _registerNamespaces(); 0189 }