Chris@0
|
1 <?php
|
Chris@0
|
2 /**
|
Chris@0
|
3 * Zend Framework (http://framework.zend.com/)
|
Chris@0
|
4 *
|
Chris@0
|
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
|
Chris@0
|
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
Chris@0
|
7 * @license http://framework.zend.com/license/new-bsd New BSD License
|
Chris@0
|
8 */
|
Chris@0
|
9
|
Chris@0
|
10 namespace Zend\Feed\Reader\Entry;
|
Chris@0
|
11
|
Chris@0
|
12 use DOMElement;
|
Chris@0
|
13 use DOMXPath;
|
Chris@0
|
14 use Zend\Feed\Reader;
|
Chris@0
|
15
|
Chris@0
|
16 class Atom extends AbstractEntry implements EntryInterface
|
Chris@0
|
17 {
|
Chris@0
|
18 /**
|
Chris@0
|
19 * XPath query
|
Chris@0
|
20 *
|
Chris@0
|
21 * @var string
|
Chris@0
|
22 */
|
Chris@0
|
23 protected $xpathQuery = '';
|
Chris@0
|
24
|
Chris@0
|
25 /**
|
Chris@0
|
26 * Constructor
|
Chris@0
|
27 *
|
Chris@0
|
28 * @param DOMElement $entry
|
Chris@0
|
29 * @param int $entryKey
|
Chris@0
|
30 * @param string $type
|
Chris@0
|
31 */
|
Chris@0
|
32 public function __construct(DOMElement $entry, $entryKey, $type = null)
|
Chris@0
|
33 {
|
Chris@0
|
34 parent::__construct($entry, $entryKey, $type);
|
Chris@0
|
35
|
Chris@0
|
36 // Everyone by now should know XPath indices start from 1 not 0
|
Chris@0
|
37 $this->xpathQuery = '//atom:entry[' . ($this->entryKey + 1) . ']';
|
Chris@0
|
38
|
Chris@0
|
39 $manager = Reader\Reader::getExtensionManager();
|
Chris@0
|
40 $extensions = ['Atom\Entry', 'Thread\Entry', 'DublinCore\Entry'];
|
Chris@0
|
41
|
Chris@0
|
42 foreach ($extensions as $name) {
|
Chris@0
|
43 $extension = $manager->get($name);
|
Chris@0
|
44 $extension->setEntryElement($entry);
|
Chris@0
|
45 $extension->setEntryKey($entryKey);
|
Chris@0
|
46 $extension->setType($type);
|
Chris@0
|
47 $this->extensions[$name] = $extension;
|
Chris@0
|
48 }
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 /**
|
Chris@0
|
52 * Get the specified author
|
Chris@0
|
53 *
|
Chris@0
|
54 * @param int $index
|
Chris@0
|
55 * @return string|null
|
Chris@0
|
56 */
|
Chris@0
|
57 public function getAuthor($index = 0)
|
Chris@0
|
58 {
|
Chris@0
|
59 $authors = $this->getAuthors();
|
Chris@0
|
60
|
Chris@0
|
61 if (isset($authors[$index])) {
|
Chris@0
|
62 return $authors[$index];
|
Chris@0
|
63 }
|
Chris@0
|
64
|
Chris@0
|
65 return;
|
Chris@0
|
66 }
|
Chris@0
|
67
|
Chris@0
|
68 /**
|
Chris@0
|
69 * Get an array with feed authors
|
Chris@0
|
70 *
|
Chris@0
|
71 * @return array
|
Chris@0
|
72 */
|
Chris@0
|
73 public function getAuthors()
|
Chris@0
|
74 {
|
Chris@0
|
75 if (array_key_exists('authors', $this->data)) {
|
Chris@0
|
76 return $this->data['authors'];
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79 $people = $this->getExtension('Atom')->getAuthors();
|
Chris@0
|
80
|
Chris@0
|
81 $this->data['authors'] = $people;
|
Chris@0
|
82
|
Chris@0
|
83 return $this->data['authors'];
|
Chris@0
|
84 }
|
Chris@0
|
85
|
Chris@0
|
86 /**
|
Chris@0
|
87 * Get the entry content
|
Chris@0
|
88 *
|
Chris@0
|
89 * @return string
|
Chris@0
|
90 */
|
Chris@0
|
91 public function getContent()
|
Chris@0
|
92 {
|
Chris@0
|
93 if (array_key_exists('content', $this->data)) {
|
Chris@0
|
94 return $this->data['content'];
|
Chris@0
|
95 }
|
Chris@0
|
96
|
Chris@0
|
97 $content = $this->getExtension('Atom')->getContent();
|
Chris@0
|
98
|
Chris@0
|
99 $this->data['content'] = $content;
|
Chris@0
|
100
|
Chris@0
|
101 return $this->data['content'];
|
Chris@0
|
102 }
|
Chris@0
|
103
|
Chris@0
|
104 /**
|
Chris@0
|
105 * Get the entry creation date
|
Chris@0
|
106 *
|
Chris@0
|
107 * @return \DateTime
|
Chris@0
|
108 */
|
Chris@0
|
109 public function getDateCreated()
|
Chris@0
|
110 {
|
Chris@0
|
111 if (array_key_exists('datecreated', $this->data)) {
|
Chris@0
|
112 return $this->data['datecreated'];
|
Chris@0
|
113 }
|
Chris@0
|
114
|
Chris@0
|
115 $dateCreated = $this->getExtension('Atom')->getDateCreated();
|
Chris@0
|
116
|
Chris@0
|
117 $this->data['datecreated'] = $dateCreated;
|
Chris@0
|
118
|
Chris@0
|
119 return $this->data['datecreated'];
|
Chris@0
|
120 }
|
Chris@0
|
121
|
Chris@0
|
122 /**
|
Chris@0
|
123 * Get the entry modification date
|
Chris@0
|
124 *
|
Chris@0
|
125 * @return \DateTime
|
Chris@0
|
126 */
|
Chris@0
|
127 public function getDateModified()
|
Chris@0
|
128 {
|
Chris@0
|
129 if (array_key_exists('datemodified', $this->data)) {
|
Chris@0
|
130 return $this->data['datemodified'];
|
Chris@0
|
131 }
|
Chris@0
|
132
|
Chris@0
|
133 $dateModified = $this->getExtension('Atom')->getDateModified();
|
Chris@0
|
134
|
Chris@0
|
135 $this->data['datemodified'] = $dateModified;
|
Chris@0
|
136
|
Chris@0
|
137 return $this->data['datemodified'];
|
Chris@0
|
138 }
|
Chris@0
|
139
|
Chris@0
|
140 /**
|
Chris@0
|
141 * Get the entry description
|
Chris@0
|
142 *
|
Chris@0
|
143 * @return string
|
Chris@0
|
144 */
|
Chris@0
|
145 public function getDescription()
|
Chris@0
|
146 {
|
Chris@0
|
147 if (array_key_exists('description', $this->data)) {
|
Chris@0
|
148 return $this->data['description'];
|
Chris@0
|
149 }
|
Chris@0
|
150
|
Chris@0
|
151 $description = $this->getExtension('Atom')->getDescription();
|
Chris@0
|
152
|
Chris@0
|
153 $this->data['description'] = $description;
|
Chris@0
|
154
|
Chris@0
|
155 return $this->data['description'];
|
Chris@0
|
156 }
|
Chris@0
|
157
|
Chris@0
|
158 /**
|
Chris@0
|
159 * Get the entry enclosure
|
Chris@0
|
160 *
|
Chris@0
|
161 * @return string
|
Chris@0
|
162 */
|
Chris@0
|
163 public function getEnclosure()
|
Chris@0
|
164 {
|
Chris@0
|
165 if (array_key_exists('enclosure', $this->data)) {
|
Chris@0
|
166 return $this->data['enclosure'];
|
Chris@0
|
167 }
|
Chris@0
|
168
|
Chris@0
|
169 $enclosure = $this->getExtension('Atom')->getEnclosure();
|
Chris@0
|
170
|
Chris@0
|
171 $this->data['enclosure'] = $enclosure;
|
Chris@0
|
172
|
Chris@0
|
173 return $this->data['enclosure'];
|
Chris@0
|
174 }
|
Chris@0
|
175
|
Chris@0
|
176 /**
|
Chris@0
|
177 * Get the entry ID
|
Chris@0
|
178 *
|
Chris@0
|
179 * @return string
|
Chris@0
|
180 */
|
Chris@0
|
181 public function getId()
|
Chris@0
|
182 {
|
Chris@0
|
183 if (array_key_exists('id', $this->data)) {
|
Chris@0
|
184 return $this->data['id'];
|
Chris@0
|
185 }
|
Chris@0
|
186
|
Chris@0
|
187 $id = $this->getExtension('Atom')->getId();
|
Chris@0
|
188
|
Chris@0
|
189 $this->data['id'] = $id;
|
Chris@0
|
190
|
Chris@0
|
191 return $this->data['id'];
|
Chris@0
|
192 }
|
Chris@0
|
193
|
Chris@0
|
194 /**
|
Chris@0
|
195 * Get a specific link
|
Chris@0
|
196 *
|
Chris@0
|
197 * @param int $index
|
Chris@0
|
198 * @return string
|
Chris@0
|
199 */
|
Chris@0
|
200 public function getLink($index = 0)
|
Chris@0
|
201 {
|
Chris@0
|
202 if (!array_key_exists('links', $this->data)) {
|
Chris@0
|
203 $this->getLinks();
|
Chris@0
|
204 }
|
Chris@0
|
205
|
Chris@0
|
206 if (isset($this->data['links'][$index])) {
|
Chris@0
|
207 return $this->data['links'][$index];
|
Chris@0
|
208 }
|
Chris@0
|
209
|
Chris@0
|
210 return;
|
Chris@0
|
211 }
|
Chris@0
|
212
|
Chris@0
|
213 /**
|
Chris@0
|
214 * Get all links
|
Chris@0
|
215 *
|
Chris@0
|
216 * @return array
|
Chris@0
|
217 */
|
Chris@0
|
218 public function getLinks()
|
Chris@0
|
219 {
|
Chris@0
|
220 if (array_key_exists('links', $this->data)) {
|
Chris@0
|
221 return $this->data['links'];
|
Chris@0
|
222 }
|
Chris@0
|
223
|
Chris@0
|
224 $links = $this->getExtension('Atom')->getLinks();
|
Chris@0
|
225
|
Chris@0
|
226 $this->data['links'] = $links;
|
Chris@0
|
227
|
Chris@0
|
228 return $this->data['links'];
|
Chris@0
|
229 }
|
Chris@0
|
230
|
Chris@0
|
231 /**
|
Chris@0
|
232 * Get a permalink to the entry
|
Chris@0
|
233 *
|
Chris@0
|
234 * @return string
|
Chris@0
|
235 */
|
Chris@0
|
236 public function getPermalink()
|
Chris@0
|
237 {
|
Chris@0
|
238 return $this->getLink(0);
|
Chris@0
|
239 }
|
Chris@0
|
240
|
Chris@0
|
241 /**
|
Chris@0
|
242 * Get the entry title
|
Chris@0
|
243 *
|
Chris@0
|
244 * @return string
|
Chris@0
|
245 */
|
Chris@0
|
246 public function getTitle()
|
Chris@0
|
247 {
|
Chris@0
|
248 if (array_key_exists('title', $this->data)) {
|
Chris@0
|
249 return $this->data['title'];
|
Chris@0
|
250 }
|
Chris@0
|
251
|
Chris@0
|
252 $title = $this->getExtension('Atom')->getTitle();
|
Chris@0
|
253
|
Chris@0
|
254 $this->data['title'] = $title;
|
Chris@0
|
255
|
Chris@0
|
256 return $this->data['title'];
|
Chris@0
|
257 }
|
Chris@0
|
258
|
Chris@0
|
259 /**
|
Chris@0
|
260 * Get the number of comments/replies for current entry
|
Chris@0
|
261 *
|
Chris@0
|
262 * @return int
|
Chris@0
|
263 */
|
Chris@0
|
264 public function getCommentCount()
|
Chris@0
|
265 {
|
Chris@0
|
266 if (array_key_exists('commentcount', $this->data)) {
|
Chris@0
|
267 return $this->data['commentcount'];
|
Chris@0
|
268 }
|
Chris@0
|
269
|
Chris@0
|
270 $commentcount = $this->getExtension('Thread')->getCommentCount();
|
Chris@0
|
271
|
Chris@0
|
272 if (!$commentcount) {
|
Chris@0
|
273 $commentcount = $this->getExtension('Atom')->getCommentCount();
|
Chris@0
|
274 }
|
Chris@0
|
275
|
Chris@0
|
276 $this->data['commentcount'] = $commentcount;
|
Chris@0
|
277
|
Chris@0
|
278 return $this->data['commentcount'];
|
Chris@0
|
279 }
|
Chris@0
|
280
|
Chris@0
|
281 /**
|
Chris@0
|
282 * Returns a URI pointing to the HTML page where comments can be made on this entry
|
Chris@0
|
283 *
|
Chris@0
|
284 * @return string
|
Chris@0
|
285 */
|
Chris@0
|
286 public function getCommentLink()
|
Chris@0
|
287 {
|
Chris@0
|
288 if (array_key_exists('commentlink', $this->data)) {
|
Chris@0
|
289 return $this->data['commentlink'];
|
Chris@0
|
290 }
|
Chris@0
|
291
|
Chris@0
|
292 $commentlink = $this->getExtension('Atom')->getCommentLink();
|
Chris@0
|
293
|
Chris@0
|
294 $this->data['commentlink'] = $commentlink;
|
Chris@0
|
295
|
Chris@0
|
296 return $this->data['commentlink'];
|
Chris@0
|
297 }
|
Chris@0
|
298
|
Chris@0
|
299 /**
|
Chris@0
|
300 * Returns a URI pointing to a feed of all comments for this entry
|
Chris@0
|
301 *
|
Chris@0
|
302 * @return string
|
Chris@0
|
303 */
|
Chris@0
|
304 public function getCommentFeedLink()
|
Chris@0
|
305 {
|
Chris@0
|
306 if (array_key_exists('commentfeedlink', $this->data)) {
|
Chris@0
|
307 return $this->data['commentfeedlink'];
|
Chris@0
|
308 }
|
Chris@0
|
309
|
Chris@0
|
310 $commentfeedlink = $this->getExtension('Atom')->getCommentFeedLink();
|
Chris@0
|
311
|
Chris@0
|
312 $this->data['commentfeedlink'] = $commentfeedlink;
|
Chris@0
|
313
|
Chris@0
|
314 return $this->data['commentfeedlink'];
|
Chris@0
|
315 }
|
Chris@0
|
316
|
Chris@0
|
317 /**
|
Chris@0
|
318 * Get category data as a Reader\Reader_Collection_Category object
|
Chris@0
|
319 *
|
Chris@0
|
320 * @return Reader\Collection\Category
|
Chris@0
|
321 */
|
Chris@0
|
322 public function getCategories()
|
Chris@0
|
323 {
|
Chris@0
|
324 if (array_key_exists('categories', $this->data)) {
|
Chris@0
|
325 return $this->data['categories'];
|
Chris@0
|
326 }
|
Chris@0
|
327
|
Chris@0
|
328 $categoryCollection = $this->getExtension('Atom')->getCategories();
|
Chris@0
|
329
|
Chris@0
|
330 if (count($categoryCollection) == 0) {
|
Chris@0
|
331 $categoryCollection = $this->getExtension('DublinCore')->getCategories();
|
Chris@0
|
332 }
|
Chris@0
|
333
|
Chris@0
|
334 $this->data['categories'] = $categoryCollection;
|
Chris@0
|
335
|
Chris@0
|
336 return $this->data['categories'];
|
Chris@0
|
337 }
|
Chris@0
|
338
|
Chris@0
|
339 /**
|
Chris@0
|
340 * Get source feed metadata from the entry
|
Chris@0
|
341 *
|
Chris@0
|
342 * @return Reader\Feed\Atom\Source|null
|
Chris@0
|
343 */
|
Chris@0
|
344 public function getSource()
|
Chris@0
|
345 {
|
Chris@0
|
346 if (array_key_exists('source', $this->data)) {
|
Chris@0
|
347 return $this->data['source'];
|
Chris@0
|
348 }
|
Chris@0
|
349
|
Chris@0
|
350 $source = $this->getExtension('Atom')->getSource();
|
Chris@0
|
351
|
Chris@0
|
352 $this->data['source'] = $source;
|
Chris@0
|
353
|
Chris@0
|
354 return $this->data['source'];
|
Chris@0
|
355 }
|
Chris@0
|
356
|
Chris@0
|
357 /**
|
Chris@0
|
358 * Set the XPath query (incl. on all Extensions)
|
Chris@0
|
359 *
|
Chris@0
|
360 * @param DOMXPath $xpath
|
Chris@0
|
361 * @return void
|
Chris@0
|
362 */
|
Chris@0
|
363 public function setXpath(DOMXPath $xpath)
|
Chris@0
|
364 {
|
Chris@0
|
365 parent::setXpath($xpath);
|
Chris@0
|
366 foreach ($this->extensions as $extension) {
|
Chris@0
|
367 $extension->setXpath($this->xpath);
|
Chris@0
|
368 }
|
Chris@0
|
369 }
|
Chris@0
|
370 }
|