File indexing completed on 2025-01-19 05:21:05
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 * @category Zend 0024 * @package Zend_Feed_Reader 0025 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0026 * @license http://framework.zend.com/license/new-bsd New BSD License 0027 */ 0028 abstract class Zend_Feed_Reader_Extension_EntryAbstract 0029 { 0030 /** 0031 * Feed entry data 0032 * 0033 * @var array 0034 */ 0035 protected $_data = array(); 0036 0037 /** 0038 * DOM document object 0039 * 0040 * @var DOMDocument 0041 */ 0042 protected $_domDocument = null; 0043 0044 /** 0045 * Entry instance 0046 * 0047 * @var Zend_Feed_Entry_Abstract 0048 */ 0049 protected $_entry = null; 0050 0051 /** 0052 * Pointer to the current entry 0053 * 0054 * @var int 0055 */ 0056 protected $_entryKey = 0; 0057 0058 /** 0059 * XPath object 0060 * 0061 * @var DOMXPath 0062 */ 0063 protected $_xpath = null; 0064 0065 /** 0066 * XPath query 0067 * 0068 * @var string 0069 */ 0070 protected $_xpathPrefix = ''; 0071 0072 /** 0073 * Constructor 0074 * 0075 * @param Zend_Feed_Entry_Abstract $entry 0076 * @param int $entryKey 0077 * @param string $type 0078 * @return void 0079 */ 0080 public function __construct(DOMElement $entry, $entryKey, $type = null) 0081 { 0082 $this->_entry = $entry; 0083 $this->_entryKey = $entryKey; 0084 $this->_domDocument = $entry->ownerDocument; 0085 0086 if ($type !== null) { 0087 $this->_data['type'] = $type; 0088 } else { 0089 $this->_data['type'] = Zend_Feed_Reader::detectType($entry->ownerDocument, true); 0090 } 0091 // set the XPath query prefix for the entry being queried 0092 if ($this->getType() == Zend_Feed_Reader::TYPE_RSS_10 0093 || $this->getType() == Zend_Feed_Reader::TYPE_RSS_090 0094 ) { 0095 $this->setXpathPrefix('//rss:item[' . ($this->_entryKey+1) . ']'); 0096 } elseif ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10 0097 || $this->getType() == Zend_Feed_Reader::TYPE_ATOM_03 0098 ) { 0099 $this->setXpathPrefix('//atom:entry[' . ($this->_entryKey+1) . ']'); 0100 } else { 0101 $this->setXpathPrefix('//item[' . ($this->_entryKey+1) . ']'); 0102 } 0103 } 0104 0105 /** 0106 * Get the DOM 0107 * 0108 * @return DOMDocument 0109 */ 0110 public function getDomDocument() 0111 { 0112 return $this->_domDocument; 0113 } 0114 0115 /** 0116 * Get the Entry's encoding 0117 * 0118 * @return string 0119 */ 0120 public function getEncoding() 0121 { 0122 $assumed = $this->getDomDocument()->encoding; 0123 return $assumed; 0124 } 0125 0126 /** 0127 * Get the entry type 0128 * 0129 * @return string 0130 */ 0131 public function getType() 0132 { 0133 return $this->_data['type']; 0134 } 0135 0136 /** 0137 * Set the XPath query 0138 * 0139 * @param DOMXPath $xpath 0140 * @return Zend_Feed_Reader_Extension_EntryAbstract 0141 */ 0142 public function setXpath(DOMXPath $xpath) 0143 { 0144 $this->_xpath = $xpath; 0145 $this->_registerNamespaces(); 0146 return $this; 0147 } 0148 0149 /** 0150 * Get the XPath query object 0151 * 0152 * @return DOMXPath 0153 */ 0154 public function getXpath() 0155 { 0156 if (!$this->_xpath) { 0157 $this->setXpath(new DOMXPath($this->getDomDocument())); 0158 } 0159 return $this->_xpath; 0160 } 0161 0162 /** 0163 * Serialize the entry to an array 0164 * 0165 * @return array 0166 */ 0167 public function toArray() 0168 { 0169 return $this->_data; 0170 } 0171 0172 /** 0173 * Get the XPath prefix 0174 * 0175 * @return string 0176 */ 0177 public function getXpathPrefix() 0178 { 0179 return $this->_xpathPrefix; 0180 } 0181 0182 /** 0183 * Set the XPath prefix 0184 * 0185 * @param string $prefix 0186 * @return Zend_Feed_Reader_Extension_EntryAbstract 0187 */ 0188 public function setXpathPrefix($prefix) 0189 { 0190 $this->_xpathPrefix = $prefix; 0191 return $this; 0192 } 0193 0194 /** 0195 * Register XML namespaces 0196 * 0197 * @return void 0198 */ 0199 protected abstract function _registerNamespaces(); 0200 }