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  * @see Zend_Feed_Reader
0024  */
0025 // require_once 'Zend/Feed/Reader.php';
0026 
0027 /**
0028  * @see Zend_Feed_Reader_EntryInterface
0029  */
0030 // require_once 'Zend/Feed/Reader/EntryInterface.php';
0031 
0032 /**
0033  * @see Zend_Feed_Reader_EntryAbstract
0034  */
0035 // require_once 'Zend/Feed/Reader/EntryAbstract.php';
0036 
0037 /**
0038  * @see Zend_Feed_Reader_Extension_Atom_Entry
0039  */
0040 // require_once 'Zend/Feed/Reader/Extension/Atom/Entry.php';
0041 
0042 /**
0043  * @category   Zend
0044  * @package    Zend_Feed_Reader
0045  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0046  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0047  */
0048 class Zend_Feed_Reader_Entry_Atom extends Zend_Feed_Reader_EntryAbstract implements Zend_Feed_Reader_EntryInterface
0049 {
0050     /**
0051      * XPath query
0052      *
0053      * @var string
0054      */
0055     protected $_xpathQuery = '';
0056 
0057     /**
0058      * Constructor
0059      *
0060      * @param  DOMElement $entry
0061      * @param  int $entryKey
0062      * @param  string $type
0063      * @return void
0064      */
0065     public function __construct(DOMElement $entry, $entryKey, $type = null)
0066     {
0067         parent::__construct($entry, $entryKey, $type);
0068 
0069         // Everyone by now should know XPath indices start from 1 not 0
0070         $this->_xpathQuery = '//atom:entry[' . ($this->_entryKey + 1) . ']';
0071 
0072         $atomClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Atom_Entry');
0073         $this->_extensions['Atom_Entry'] = new $atomClass($entry, $entryKey, $type);
0074 
0075         $threadClass = Zend_Feed_Reader::getPluginLoader()->getClassName('Thread_Entry');
0076         $this->_extensions['Thread_Entry'] = new $threadClass($entry, $entryKey, $type);
0077 
0078         $threadClass = Zend_Feed_Reader::getPluginLoader()->getClassName('DublinCore_Entry');
0079         $this->_extensions['DublinCore_Entry'] = new $threadClass($entry, $entryKey, $type);
0080     }
0081 
0082     /**
0083      * Get the specified author
0084      *
0085      * @param  int $index
0086      * @return string|null
0087      */
0088     public function getAuthor($index = 0)
0089     {
0090         $authors = $this->getAuthors();
0091 
0092         if (isset($authors[$index])) {
0093             return $authors[$index];
0094         }
0095 
0096         return null;
0097     }
0098 
0099     /**
0100      * Get an array with feed authors
0101      *
0102      * @return array
0103      */
0104     public function getAuthors()
0105     {
0106         if (array_key_exists('authors', $this->_data)) {
0107             return $this->_data['authors'];
0108         }
0109 
0110         $people = $this->getExtension('Atom')->getAuthors();
0111 
0112         $this->_data['authors'] = $people;
0113 
0114         return $this->_data['authors'];
0115     }
0116 
0117     /**
0118      * Get the entry content
0119      *
0120      * @return string
0121      */
0122     public function getContent()
0123     {
0124         if (array_key_exists('content', $this->_data)) {
0125             return $this->_data['content'];
0126         }
0127 
0128         $content = $this->getExtension('Atom')->getContent();
0129 
0130         $this->_data['content'] = $content;
0131 
0132         return $this->_data['content'];
0133     }
0134 
0135     /**
0136      * Get the entry creation date
0137      *
0138      * @return string
0139      */
0140     public function getDateCreated()
0141     {
0142         if (array_key_exists('datecreated', $this->_data)) {
0143             return $this->_data['datecreated'];
0144         }
0145 
0146         $dateCreated = $this->getExtension('Atom')->getDateCreated();
0147 
0148         $this->_data['datecreated'] = $dateCreated;
0149 
0150         return $this->_data['datecreated'];
0151     }
0152 
0153     /**
0154      * Get the entry modification date
0155      *
0156      * @return string
0157      */
0158     public function getDateModified()
0159     {
0160         if (array_key_exists('datemodified', $this->_data)) {
0161             return $this->_data['datemodified'];
0162         }
0163 
0164         $dateModified = $this->getExtension('Atom')->getDateModified();
0165 
0166         $this->_data['datemodified'] = $dateModified;
0167 
0168         return $this->_data['datemodified'];
0169     }
0170 
0171     /**
0172      * Get the entry description
0173      *
0174      * @return string
0175      */
0176     public function getDescription()
0177     {
0178         if (array_key_exists('description', $this->_data)) {
0179             return $this->_data['description'];
0180         }
0181 
0182         $description = $this->getExtension('Atom')->getDescription();
0183 
0184         $this->_data['description'] = $description;
0185 
0186         return $this->_data['description'];
0187     }
0188 
0189     /**
0190      * Get the entry enclosure
0191      *
0192      * @return string
0193      */
0194     public function getEnclosure()
0195     {
0196         if (array_key_exists('enclosure', $this->_data)) {
0197             return $this->_data['enclosure'];
0198         }
0199 
0200         $enclosure = $this->getExtension('Atom')->getEnclosure();
0201 
0202         $this->_data['enclosure'] = $enclosure;
0203 
0204         return $this->_data['enclosure'];
0205     }
0206 
0207     /**
0208      * Get the entry ID
0209      *
0210      * @return string
0211      */
0212     public function getId()
0213     {
0214         if (array_key_exists('id', $this->_data)) {
0215             return $this->_data['id'];
0216         }
0217 
0218         $id = $this->getExtension('Atom')->getId();
0219 
0220         $this->_data['id'] = $id;
0221 
0222         return $this->_data['id'];
0223     }
0224 
0225     /**
0226      * Get a specific link
0227      *
0228      * @param  int $index
0229      * @return string
0230      */
0231     public function getLink($index = 0)
0232     {
0233         if (!array_key_exists('links', $this->_data)) {
0234             $this->getLinks();
0235         }
0236 
0237         if (isset($this->_data['links'][$index])) {
0238             return $this->_data['links'][$index];
0239         }
0240 
0241         return null;
0242     }
0243 
0244     /**
0245      * Get all links
0246      *
0247      * @return array
0248      */
0249     public function getLinks()
0250     {
0251         if (array_key_exists('links', $this->_data)) {
0252             return $this->_data['links'];
0253         }
0254 
0255         $links = $this->getExtension('Atom')->getLinks();
0256 
0257         $this->_data['links'] = $links;
0258 
0259         return $this->_data['links'];
0260     }
0261 
0262     /**
0263      * Get a permalink to the entry
0264      *
0265      * @return string
0266      */
0267     public function getPermalink()
0268     {
0269         return $this->getLink(0);
0270     }
0271 
0272     /**
0273      * Get the entry title
0274      *
0275      * @return string
0276      */
0277     public function getTitle()
0278     {
0279         if (array_key_exists('title', $this->_data)) {
0280             return $this->_data['title'];
0281         }
0282 
0283         $title = $this->getExtension('Atom')->getTitle();
0284 
0285         $this->_data['title'] = $title;
0286 
0287         return $this->_data['title'];
0288     }
0289 
0290     /**
0291      * Get the number of comments/replies for current entry
0292      *
0293      * @return integer
0294      */
0295     public function getCommentCount()
0296     {
0297         if (array_key_exists('commentcount', $this->_data)) {
0298             return $this->_data['commentcount'];
0299         }
0300 
0301         $commentcount = $this->getExtension('Thread')->getCommentCount();
0302 
0303         if (!$commentcount) {
0304             $commentcount = $this->getExtension('Atom')->getCommentCount();
0305         }
0306 
0307         $this->_data['commentcount'] = $commentcount;
0308 
0309         return $this->_data['commentcount'];
0310     }
0311 
0312     /**
0313      * Returns a URI pointing to the HTML page where comments can be made on this entry
0314      *
0315      * @return string
0316      */
0317     public function getCommentLink()
0318     {
0319         if (array_key_exists('commentlink', $this->_data)) {
0320             return $this->_data['commentlink'];
0321         }
0322 
0323         $commentlink = $this->getExtension('Atom')->getCommentLink();
0324 
0325         $this->_data['commentlink'] = $commentlink;
0326 
0327         return $this->_data['commentlink'];
0328     }
0329 
0330     /**
0331      * Returns a URI pointing to a feed of all comments for this entry
0332      *
0333      * @return string
0334      */
0335     public function getCommentFeedLink()
0336     {
0337         if (array_key_exists('commentfeedlink', $this->_data)) {
0338             return $this->_data['commentfeedlink'];
0339         }
0340 
0341         $commentfeedlink = $this->getExtension('Atom')->getCommentFeedLink();
0342 
0343         $this->_data['commentfeedlink'] = $commentfeedlink;
0344 
0345         return $this->_data['commentfeedlink'];
0346     }
0347 
0348     /**
0349      * Get category data as a Zend_Feed_Reader_Collection_Category object
0350      *
0351      * @return Zend_Feed_Reader_Collection_Category
0352      */
0353     public function getCategories()
0354     {
0355         if (array_key_exists('categories', $this->_data)) {
0356             return $this->_data['categories'];
0357         }
0358 
0359         $categoryCollection = $this->getExtension('Atom')->getCategories();
0360 
0361         if (count($categoryCollection) == 0) {
0362             $categoryCollection = $this->getExtension('DublinCore')->getCategories();
0363         }
0364 
0365         $this->_data['categories'] = $categoryCollection;
0366 
0367         return $this->_data['categories'];
0368     }
0369 
0370     /**
0371      * Get source feed metadata from the entry
0372      *
0373      * @return Zend_Feed_Reader_Feed_Atom_Source|null
0374      */
0375     public function getSource()
0376     {
0377         if (array_key_exists('source', $this->_data)) {
0378             return $this->_data['source'];
0379         }
0380 
0381         $source = $this->getExtension('Atom')->getSource();
0382 
0383         $this->_data['source'] = $source;
0384 
0385         return $this->_data['source'];
0386     }
0387 
0388     /**
0389      * Set the XPath query (incl. on all Extensions)
0390      *
0391      * @param DOMXPath $xpath
0392      */
0393     public function setXpath(DOMXPath $xpath)
0394     {
0395         parent::setXpath($xpath);
0396         foreach ($this->_extensions as $extension) {
0397             $extension->setXpath($this->_xpath);
0398         }
0399     }
0400 }