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 / Entry / Atom.php
blobfcd5f60f90f8c4022ea510e61a09e073afb12cd2
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\Entry;
12 use DOMElement;
13 use DOMXPath;
14 use Zend\Feed\Reader;
16 class Atom extends AbstractEntry implements EntryInterface
18 /**
19 * XPath query
21 * @var string
23 protected $xpathQuery = '';
25 /**
26 * Constructor
28 * @param DOMElement $entry
29 * @param int $entryKey
30 * @param string $type
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 = array('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;
51 /**
52 * Get the specified author
54 * @param int $index
55 * @return string|null
57 public function getAuthor($index = 0)
59 $authors = $this->getAuthors();
61 if (isset($authors[$index])) {
62 return $authors[$index];
65 return null;
68 /**
69 * Get an array with feed authors
71 * @return array
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'];
86 /**
87 * Get the entry content
89 * @return string
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
107 * @return string
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
125 * @return string
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
143 * @return string
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
161 * @return string
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'];
177 * Get the entry ID
179 * @return string
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
197 * @param int $index
198 * @return string
200 public function getLink($index = 0)
202 if (!array_key_exists('links', $this->data)) {
203 $this->getLinks();
206 if (isset($this->data['links'][$index])) {
207 return $this->data['links'][$index];
210 return null;
214 * Get all links
216 * @return array
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
234 * @return string
236 public function getPermalink()
238 return $this->getLink(0);
242 * Get the entry title
244 * @return string
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
262 * @return int
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
284 * @return string
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
302 * @return string
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
361 * @return void
363 public function setXpath(DOMXPath $xpath)
365 parent::setXpath($xpath);
366 foreach ($this->extensions as $extension) {
367 $extension->setXpath($this->xpath);