| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Feed_Reader
- * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /**
- * @category Zend
- * @package Zend_Feed_Reader
- * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- abstract class Zend_Feed_Reader_Extension_EntryAbstract
- {
- /**
- * Feed entry data
- *
- * @var array
- */
- protected $_data = array();
- /**
- * DOM document object
- *
- * @var DOMDocument
- */
- protected $_domDocument = null;
- /**
- * Entry instance
- *
- * @var Zend_Feed_Entry_Abstract
- */
- protected $_entry = null;
- /**
- * Pointer to the current entry
- *
- * @var int
- */
- protected $_entryKey = 0;
- /**
- * XPath object
- *
- * @var DOMXPath
- */
- protected $_xpath = null;
- /**
- * XPath query
- *
- * @var string
- */
- protected $_xpathPrefix = '';
- /**
- * Constructor
- *
- * @param Zend_Feed_Entry_Abstract $entry
- * @param int $entryKey
- * @param string $type
- * @return void
- */
- public function __construct(DOMElement $entry, $entryKey, $type = null)
- {
- $this->_entry = $entry;
- $this->_entryKey = $entryKey;
- $this->_domDocument = $entry->ownerDocument;
- if ($type !== null) {
- $this->_data['type'] = $type;
- } else {
- $this->_data['type'] = Zend_Feed_Reader::detectType($entry->ownerDocument, true);
- }
- // set the XPath query prefix for the entry being queried
- if ($this->getType() == Zend_Feed_Reader::TYPE_RSS_10
- || $this->getType() == Zend_Feed_Reader::TYPE_RSS_090
- ) {
- $this->setXpathPrefix('//rss:item[' . ($this->_entryKey+1) . ']');
- } elseif ($this->getType() == Zend_Feed_Reader::TYPE_ATOM_10
- || $this->getType() == Zend_Feed_Reader::TYPE_ATOM_03
- ) {
- $this->setXpathPrefix('//atom:entry[' . ($this->_entryKey+1) . ']');
- } else {
- $this->setXpathPrefix('//item[' . ($this->_entryKey+1) . ']');
- }
- }
- /**
- * Get the DOM
- *
- * @return DOMDocument
- */
- public function getDomDocument()
- {
- return $this->_domDocument;
- }
- /**
- * Get the Entry's encoding
- *
- * @return string
- */
- public function getEncoding()
- {
- $assumed = $this->getDomDocument()->encoding;
- return $assumed;
- }
- /**
- * Get the entry type
- *
- * @return string
- */
- public function getType()
- {
- return $this->_data['type'];
- }
- /**
- * Set the XPath query
- *
- * @param DOMXPath $xpath
- * @return Zend_Feed_Reader_Extension_EntryAbstract
- */
- public function setXpath(DOMXPath $xpath)
- {
- $this->_xpath = $xpath;
- $this->_registerNamespaces();
- return $this;
- }
- /**
- * Get the XPath query object
- *
- * @return DOMXPath
- */
- public function getXpath()
- {
- if (!$this->_xpath) {
- $this->setXpath(new DOMXPath($this->getDomDocument()));
- }
- return $this->_xpath;
- }
- /**
- * Serialize the entry to an array
- *
- * @return array
- */
- public function toArray()
- {
- return $this->_data;
- }
- /**
- * Get the XPath prefix
- *
- * @return string
- */
- public function getXpathPrefix()
- {
- return $this->_xpathPrefix;
- }
- /**
- * Set the XPath prefix
- *
- * @param string $prefix
- * @return Zend_Feed_Reader_Extension_EntryAbstract
- */
- public function setXpathPrefix($prefix)
- {
- $this->_xpathPrefix = $prefix;
- return $this;
- }
- /**
- * Register XML namespaces
- *
- * @return void
- */
- protected abstract function _registerNamespaces();
- }
|