Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Feed / Reader / Feed / Atom.php
blobcc3943854111abeaec0575da50727d25f85568b2
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Feed\Reader\Feed;
12 use DOMDocument;
13 use Zend\Feed\Reader;
15 /**
17 class Atom extends AbstractFeed
20 /**
21 * Constructor
23 * @param DOMDocument $dom
24 * @param string $type
26 public function __construct(DOMDocument $dom, $type = null)
28 parent::__construct($dom, $type);
29 $manager = Reader\Reader::getExtensionManager();
31 $atomFeed = $manager->get('Atom\Feed');
32 $atomFeed->setDomDocument($dom);
33 $atomFeed->setType($this->data['type']);
34 $atomFeed->setXpath($this->xpath);
35 $this->extensions['Atom\\Feed'] = $atomFeed;
37 $atomFeed = $manager->get('DublinCore\Feed');
38 $atomFeed->setDomDocument($dom);
39 $atomFeed->setType($this->data['type']);
40 $atomFeed->setXpath($this->xpath);
41 $this->extensions['DublinCore\\Feed'] = $atomFeed;
43 foreach ($this->extensions as $extension) {
44 $extension->setXpathPrefix('/atom:feed');
48 /**
49 * Get a single author
51 * @param int $index
52 * @return string|null
54 public function getAuthor($index = 0)
56 $authors = $this->getAuthors();
58 if (isset($authors[$index])) {
59 return $authors[$index];
62 return null;
65 /**
66 * Get an array with feed authors
68 * @return array
70 public function getAuthors()
72 if (array_key_exists('authors', $this->data)) {
73 return $this->data['authors'];
76 $authors = $this->getExtension('Atom')->getAuthors();
78 $this->data['authors'] = $authors;
80 return $this->data['authors'];
83 /**
84 * Get the copyright entry
86 * @return string|null
88 public function getCopyright()
90 if (array_key_exists('copyright', $this->data)) {
91 return $this->data['copyright'];
94 $copyright = $this->getExtension('Atom')->getCopyright();
96 if (!$copyright) {
97 $copyright = null;
100 $this->data['copyright'] = $copyright;
102 return $this->data['copyright'];
106 * Get the feed creation date
108 * @return string|null
110 public function getDateCreated()
112 if (array_key_exists('datecreated', $this->data)) {
113 return $this->data['datecreated'];
116 $dateCreated = $this->getExtension('Atom')->getDateCreated();
118 if (!$dateCreated) {
119 $dateCreated = null;
122 $this->data['datecreated'] = $dateCreated;
124 return $this->data['datecreated'];
128 * Get the feed modification date
130 * @return string|null
132 public function getDateModified()
134 if (array_key_exists('datemodified', $this->data)) {
135 return $this->data['datemodified'];
138 $dateModified = $this->getExtension('Atom')->getDateModified();
140 if (!$dateModified) {
141 $dateModified = null;
144 $this->data['datemodified'] = $dateModified;
146 return $this->data['datemodified'];
150 * Get the feed lastBuild date. This is not implemented in Atom.
152 * @return string|null
154 public function getLastBuildDate()
156 return null;
160 * Get the feed description
162 * @return string|null
164 public function getDescription()
166 if (array_key_exists('description', $this->data)) {
167 return $this->data['description'];
170 $description = $this->getExtension('Atom')->getDescription();
172 if (!$description) {
173 $description = null;
176 $this->data['description'] = $description;
178 return $this->data['description'];
182 * Get the feed generator entry
184 * @return string|null
186 public function getGenerator()
188 if (array_key_exists('generator', $this->data)) {
189 return $this->data['generator'];
192 $generator = $this->getExtension('Atom')->getGenerator();
194 $this->data['generator'] = $generator;
196 return $this->data['generator'];
200 * Get the feed ID
202 * @return string|null
204 public function getId()
206 if (array_key_exists('id', $this->data)) {
207 return $this->data['id'];
210 $id = $this->getExtension('Atom')->getId();
212 $this->data['id'] = $id;
214 return $this->data['id'];
218 * Get the feed language
220 * @return string|null
222 public function getLanguage()
224 if (array_key_exists('language', $this->data)) {
225 return $this->data['language'];
228 $language = $this->getExtension('Atom')->getLanguage();
230 if (!$language) {
231 $language = $this->xpath->evaluate('string(//@xml:lang[1])');
234 if (!$language) {
235 $language = null;
238 $this->data['language'] = $language;
240 return $this->data['language'];
244 * Get a link to the source website
246 * @return string|null
248 public function getBaseUrl()
250 if (array_key_exists('baseUrl', $this->data)) {
251 return $this->data['baseUrl'];
254 $baseUrl = $this->getExtension('Atom')->getBaseUrl();
256 $this->data['baseUrl'] = $baseUrl;
258 return $this->data['baseUrl'];
262 * Get a link to the source website
264 * @return string|null
266 public function getLink()
268 if (array_key_exists('link', $this->data)) {
269 return $this->data['link'];
272 $link = $this->getExtension('Atom')->getLink();
274 $this->data['link'] = $link;
276 return $this->data['link'];
280 * Get feed image data
282 * @return array|null
284 public function getImage()
286 if (array_key_exists('image', $this->data)) {
287 return $this->data['image'];
290 $link = $this->getExtension('Atom')->getImage();
292 $this->data['image'] = $link;
294 return $this->data['image'];
298 * Get a link to the feed's XML Url
300 * @return string|null
302 public function getFeedLink()
304 if (array_key_exists('feedlink', $this->data)) {
305 return $this->data['feedlink'];
308 $link = $this->getExtension('Atom')->getFeedLink();
310 if ($link === null || empty($link)) {
311 $link = $this->getOriginalSourceUri();
314 $this->data['feedlink'] = $link;
316 return $this->data['feedlink'];
320 * Get the feed title
322 * @return string|null
324 public function getTitle()
326 if (array_key_exists('title', $this->data)) {
327 return $this->data['title'];
330 $title = $this->getExtension('Atom')->getTitle();
332 $this->data['title'] = $title;
334 return $this->data['title'];
338 * Get an array of any supported Pusubhubbub endpoints
340 * @return array|null
342 public function getHubs()
344 if (array_key_exists('hubs', $this->data)) {
345 return $this->data['hubs'];
348 $hubs = $this->getExtension('Atom')->getHubs();
350 $this->data['hubs'] = $hubs;
352 return $this->data['hubs'];
356 * Get all categories
358 * @return Reader\Collection\Category
360 public function getCategories()
362 if (array_key_exists('categories', $this->data)) {
363 return $this->data['categories'];
366 $categoryCollection = $this->getExtension('Atom')->getCategories();
368 if (count($categoryCollection) == 0) {
369 $categoryCollection = $this->getExtension('DublinCore')->getCategories();
372 $this->data['categories'] = $categoryCollection;
374 return $this->data['categories'];
378 * Read all entries to the internal entries array
380 * @return void
382 protected function indexEntries()
384 if ($this->getType() == Reader\Reader::TYPE_ATOM_10 ||
385 $this->getType() == Reader\Reader::TYPE_ATOM_03) {
386 $entries = array();
387 $entries = $this->xpath->evaluate('//atom:entry');
389 foreach ($entries as $index => $entry) {
390 $this->entries[$index] = $entry;
396 * Register the default namespaces for the current feed format
399 protected function registerNamespaces()
401 switch ($this->data['type']) {
402 case Reader\Reader::TYPE_ATOM_03:
403 $this->xpath->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_03);
404 break;
405 case Reader\Reader::TYPE_ATOM_10:
406 default:
407 $this->xpath->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_10);