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\Feed;
17 class Atom extends AbstractFeed
22 * @param DOMDocument $dom
25 public function __construct(DOMDocument $dom, $type = null)
27 parent::__construct($dom, $type);
28 $manager = Reader\Reader::getExtensionManager();
30 $atomFeed = $manager->get('Atom\Feed');
31 $atomFeed->setDomDocument($dom);
32 $atomFeed->setType($this->data['type']);
33 $atomFeed->setXpath($this->xpath);
34 $this->extensions['Atom\\Feed'] = $atomFeed;
36 $atomFeed = $manager->get('DublinCore\Feed');
37 $atomFeed->setDomDocument($dom);
38 $atomFeed->setType($this->data['type']);
39 $atomFeed->setXpath($this->xpath);
40 $this->extensions['DublinCore\\Feed'] = $atomFeed;
42 foreach ($this->extensions as $extension) {
43 $extension->setXpathPrefix('/atom:feed');
53 public function getAuthor($index = 0)
55 $authors = $this->getAuthors();
57 if (isset($authors[$index])) {
58 return $authors[$index];
65 * Get an array with feed authors
69 public function getAuthors()
71 if (array_key_exists('authors', $this->data)) {
72 return $this->data['authors'];
75 $authors = $this->getExtension('Atom')->getAuthors();
77 $this->data['authors'] = $authors;
79 return $this->data['authors'];
83 * Get the copyright entry
87 public function getCopyright()
89 if (array_key_exists('copyright', $this->data)) {
90 return $this->data['copyright'];
93 $copyright = $this->getExtension('Atom')->getCopyright();
99 $this->data['copyright'] = $copyright;
101 return $this->data['copyright'];
105 * Get the feed creation date
107 * @return \DateTime|null
109 public function getDateCreated()
111 if (array_key_exists('datecreated', $this->data)) {
112 return $this->data['datecreated'];
115 $dateCreated = $this->getExtension('Atom')->getDateCreated();
117 if (! $dateCreated) {
121 $this->data['datecreated'] = $dateCreated;
123 return $this->data['datecreated'];
127 * Get the feed modification date
129 * @return \DateTime|null
131 public function getDateModified()
133 if (array_key_exists('datemodified', $this->data)) {
134 return $this->data['datemodified'];
137 $dateModified = $this->getExtension('Atom')->getDateModified();
139 if (! $dateModified) {
140 $dateModified = null;
143 $this->data['datemodified'] = $dateModified;
145 return $this->data['datemodified'];
149 * Get the feed lastBuild date. This is not implemented in Atom.
151 * @return string|null
153 public function getLastBuildDate()
159 * Get the feed description
161 * @return string|null
163 public function getDescription()
165 if (array_key_exists('description', $this->data)) {
166 return $this->data['description'];
169 $description = $this->getExtension('Atom')->getDescription();
171 if (! $description) {
175 $this->data['description'] = $description;
177 return $this->data['description'];
181 * Get the feed generator entry
183 * @return string|null
185 public function getGenerator()
187 if (array_key_exists('generator', $this->data)) {
188 return $this->data['generator'];
191 $generator = $this->getExtension('Atom')->getGenerator();
193 $this->data['generator'] = $generator;
195 return $this->data['generator'];
201 * @return string|null
203 public function getId()
205 if (array_key_exists('id', $this->data)) {
206 return $this->data['id'];
209 $id = $this->getExtension('Atom')->getId();
211 $this->data['id'] = $id;
213 return $this->data['id'];
217 * Get the feed language
219 * @return string|null
221 public function getLanguage()
223 if (array_key_exists('language', $this->data)) {
224 return $this->data['language'];
227 $language = $this->getExtension('Atom')->getLanguage();
230 $language = $this->xpath->evaluate('string(//@xml:lang[1])');
237 $this->data['language'] = $language;
239 return $this->data['language'];
243 * Get a link to the source website
245 * @return string|null
247 public function getBaseUrl()
249 if (array_key_exists('baseUrl', $this->data)) {
250 return $this->data['baseUrl'];
253 $baseUrl = $this->getExtension('Atom')->getBaseUrl();
255 $this->data['baseUrl'] = $baseUrl;
257 return $this->data['baseUrl'];
261 * Get a link to the source website
263 * @return string|null
265 public function getLink()
267 if (array_key_exists('link', $this->data)) {
268 return $this->data['link'];
271 $link = $this->getExtension('Atom')->getLink();
273 $this->data['link'] = $link;
275 return $this->data['link'];
279 * Get feed image data
283 public function getImage()
285 if (array_key_exists('image', $this->data)) {
286 return $this->data['image'];
289 $link = $this->getExtension('Atom')->getImage();
291 $this->data['image'] = $link;
293 return $this->data['image'];
297 * Get a link to the feed's XML Url
299 * @return string|null
301 public function getFeedLink()
303 if (array_key_exists('feedlink', $this->data)) {
304 return $this->data['feedlink'];
307 $link = $this->getExtension('Atom')->getFeedLink();
309 if ($link === null || empty($link)) {
310 $link = $this->getOriginalSourceUri();
313 $this->data['feedlink'] = $link;
315 return $this->data['feedlink'];
321 * @return string|null
323 public function getTitle()
325 if (array_key_exists('title', $this->data)) {
326 return $this->data['title'];
329 $title = $this->getExtension('Atom')->getTitle();
331 $this->data['title'] = $title;
333 return $this->data['title'];
337 * Get an array of any supported Pusubhubbub endpoints
341 public function getHubs()
343 if (array_key_exists('hubs', $this->data)) {
344 return $this->data['hubs'];
347 $hubs = $this->getExtension('Atom')->getHubs();
349 $this->data['hubs'] = $hubs;
351 return $this->data['hubs'];
357 * @return Reader\Collection\Category
359 public function getCategories()
361 if (array_key_exists('categories', $this->data)) {
362 return $this->data['categories'];
365 $categoryCollection = $this->getExtension('Atom')->getCategories();
367 if (count($categoryCollection) == 0) {
368 $categoryCollection = $this->getExtension('DublinCore')->getCategories();
371 $this->data['categories'] = $categoryCollection;
373 return $this->data['categories'];
377 * Read all entries to the internal entries array
381 protected function indexEntries()
383 if ($this->getType() == Reader\Reader::TYPE_ATOM_10 ||
384 $this->getType() == Reader\Reader::TYPE_ATOM_03) {
385 $entries = $this->xpath->evaluate('//atom:entry');
387 foreach ($entries as $index => $entry) {
388 $this->entries[$index] = $entry;
394 * Register the default namespaces for the current feed format
397 protected function registerNamespaces()
399 switch ($this->data['type']) {
400 case Reader\Reader::TYPE_ATOM_03:
401 $this->xpath->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_03);
403 case Reader\Reader::TYPE_ATOM_10:
405 $this->xpath->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_10);