3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Feed\Reader\Entry;
16 class Atom extends AbstractEntry implements EntryInterface
23 protected $xpathQuery = '';
28 * @param DOMElement $entry
29 * @param int $entryKey
32 public function __construct(DOMElement $entry, $entryKey, $type = null)
34 parent::__construct($entry, $entryKey, $type);
36 // Everyone by now should know XPath indices start from 1 not 0
37 $this->xpathQuery = '//atom:entry[' . ($this->entryKey + 1) . ']';
39 $manager = Reader\Reader::getExtensionManager();
40 $extensions = ['Atom\Entry', 'Thread\Entry', 'DublinCore\Entry'];
42 foreach ($extensions as $name) {
43 $extension = $manager->get($name);
44 $extension->setEntryElement($entry);
45 $extension->setEntryKey($entryKey);
46 $extension->setType($type);
47 $this->extensions[$name] = $extension;
52 * Get the specified author
57 public function getAuthor($index = 0)
59 $authors = $this->getAuthors();
61 if (isset($authors[$index])) {
62 return $authors[$index];
69 * Get an array with feed authors
73 public function getAuthors()
75 if (array_key_exists('authors', $this->data)) {
76 return $this->data['authors'];
79 $people = $this->getExtension('Atom')->getAuthors();
81 $this->data['authors'] = $people;
83 return $this->data['authors'];
87 * Get the entry content
91 public function getContent()
93 if (array_key_exists('content', $this->data)) {
94 return $this->data['content'];
97 $content = $this->getExtension('Atom')->getContent();
99 $this->data['content'] = $content;
101 return $this->data['content'];
105 * Get the entry creation date
109 public function getDateCreated()
111 if (array_key_exists('datecreated', $this->data)) {
112 return $this->data['datecreated'];
115 $dateCreated = $this->getExtension('Atom')->getDateCreated();
117 $this->data['datecreated'] = $dateCreated;
119 return $this->data['datecreated'];
123 * Get the entry modification date
127 public function getDateModified()
129 if (array_key_exists('datemodified', $this->data)) {
130 return $this->data['datemodified'];
133 $dateModified = $this->getExtension('Atom')->getDateModified();
135 $this->data['datemodified'] = $dateModified;
137 return $this->data['datemodified'];
141 * Get the entry description
145 public function getDescription()
147 if (array_key_exists('description', $this->data)) {
148 return $this->data['description'];
151 $description = $this->getExtension('Atom')->getDescription();
153 $this->data['description'] = $description;
155 return $this->data['description'];
159 * Get the entry enclosure
163 public function getEnclosure()
165 if (array_key_exists('enclosure', $this->data)) {
166 return $this->data['enclosure'];
169 $enclosure = $this->getExtension('Atom')->getEnclosure();
171 $this->data['enclosure'] = $enclosure;
173 return $this->data['enclosure'];
181 public function getId()
183 if (array_key_exists('id', $this->data)) {
184 return $this->data['id'];
187 $id = $this->getExtension('Atom')->getId();
189 $this->data['id'] = $id;
191 return $this->data['id'];
195 * Get a specific link
200 public function getLink($index = 0)
202 if (! array_key_exists('links', $this->data)) {
206 if (isset($this->data['links'][$index])) {
207 return $this->data['links'][$index];
218 public function getLinks()
220 if (array_key_exists('links', $this->data)) {
221 return $this->data['links'];
224 $links = $this->getExtension('Atom')->getLinks();
226 $this->data['links'] = $links;
228 return $this->data['links'];
232 * Get a permalink to the entry
236 public function getPermalink()
238 return $this->getLink(0);
242 * Get the entry title
246 public function getTitle()
248 if (array_key_exists('title', $this->data)) {
249 return $this->data['title'];
252 $title = $this->getExtension('Atom')->getTitle();
254 $this->data['title'] = $title;
256 return $this->data['title'];
260 * Get the number of comments/replies for current entry
264 public function getCommentCount()
266 if (array_key_exists('commentcount', $this->data)) {
267 return $this->data['commentcount'];
270 $commentcount = $this->getExtension('Thread')->getCommentCount();
272 if (! $commentcount) {
273 $commentcount = $this->getExtension('Atom')->getCommentCount();
276 $this->data['commentcount'] = $commentcount;
278 return $this->data['commentcount'];
282 * Returns a URI pointing to the HTML page where comments can be made on this entry
286 public function getCommentLink()
288 if (array_key_exists('commentlink', $this->data)) {
289 return $this->data['commentlink'];
292 $commentlink = $this->getExtension('Atom')->getCommentLink();
294 $this->data['commentlink'] = $commentlink;
296 return $this->data['commentlink'];
300 * Returns a URI pointing to a feed of all comments for this entry
304 public function getCommentFeedLink()
306 if (array_key_exists('commentfeedlink', $this->data)) {
307 return $this->data['commentfeedlink'];
310 $commentfeedlink = $this->getExtension('Atom')->getCommentFeedLink();
312 $this->data['commentfeedlink'] = $commentfeedlink;
314 return $this->data['commentfeedlink'];
318 * Get category data as a Reader\Reader_Collection_Category object
320 * @return Reader\Collection\Category
322 public function getCategories()
324 if (array_key_exists('categories', $this->data)) {
325 return $this->data['categories'];
328 $categoryCollection = $this->getExtension('Atom')->getCategories();
330 if (count($categoryCollection) == 0) {
331 $categoryCollection = $this->getExtension('DublinCore')->getCategories();
334 $this->data['categories'] = $categoryCollection;
336 return $this->data['categories'];
340 * Get source feed metadata from the entry
342 * @return Reader\Feed\Atom\Source|null
344 public function getSource()
346 if (array_key_exists('source', $this->data)) {
347 return $this->data['source'];
350 $source = $this->getExtension('Atom')->getSource();
352 $this->data['source'] = $source;
354 return $this->data['source'];
358 * Set the XPath query (incl. on all Extensions)
360 * @param DOMXPath $xpath
363 public function setXpath(DOMXPath $xpath)
365 parent::setXpath($xpath);
366 foreach ($this->extensions as $extension) {
367 $extension->setXpath($this->xpath);