db backup prior to drupal security update
[yaffs-website] / vendor / zendframework / zend-feed / src / Reader / Feed / Atom.php
1 <?php
2 /**
3  * Zend Framework (http://framework.zend.com/)
4  *
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
8  */
9
10 namespace Zend\Feed\Reader\Feed;
11
12 use DOMDocument;
13 use Zend\Feed\Reader;
14
15 /**
16 */
17 class Atom extends AbstractFeed
18 {
19     /**
20      * Constructor
21      *
22      * @param  DOMDocument $dom
23      * @param  string $type
24      */
25     public function __construct(DOMDocument $dom, $type = null)
26     {
27         parent::__construct($dom, $type);
28         $manager = Reader\Reader::getExtensionManager();
29
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;
35
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;
41
42         foreach ($this->extensions as $extension) {
43             $extension->setXpathPrefix('/atom:feed');
44         }
45     }
46
47     /**
48      * Get a single author
49      *
50      * @param  int $index
51      * @return string|null
52      */
53     public function getAuthor($index = 0)
54     {
55         $authors = $this->getAuthors();
56
57         if (isset($authors[$index])) {
58             return $authors[$index];
59         }
60
61         return;
62     }
63
64     /**
65      * Get an array with feed authors
66      *
67      * @return array
68      */
69     public function getAuthors()
70     {
71         if (array_key_exists('authors', $this->data)) {
72             return $this->data['authors'];
73         }
74
75         $authors = $this->getExtension('Atom')->getAuthors();
76
77         $this->data['authors'] = $authors;
78
79         return $this->data['authors'];
80     }
81
82     /**
83      * Get the copyright entry
84      *
85      * @return string|null
86      */
87     public function getCopyright()
88     {
89         if (array_key_exists('copyright', $this->data)) {
90             return $this->data['copyright'];
91         }
92
93         $copyright = $this->getExtension('Atom')->getCopyright();
94
95         if (! $copyright) {
96             $copyright = null;
97         }
98
99         $this->data['copyright'] = $copyright;
100
101         return $this->data['copyright'];
102     }
103
104     /**
105      * Get the feed creation date
106      *
107      * @return \DateTime|null
108      */
109     public function getDateCreated()
110     {
111         if (array_key_exists('datecreated', $this->data)) {
112             return $this->data['datecreated'];
113         }
114
115         $dateCreated = $this->getExtension('Atom')->getDateCreated();
116
117         if (! $dateCreated) {
118             $dateCreated = null;
119         }
120
121         $this->data['datecreated'] = $dateCreated;
122
123         return $this->data['datecreated'];
124     }
125
126     /**
127      * Get the feed modification date
128      *
129      * @return \DateTime|null
130      */
131     public function getDateModified()
132     {
133         if (array_key_exists('datemodified', $this->data)) {
134             return $this->data['datemodified'];
135         }
136
137         $dateModified = $this->getExtension('Atom')->getDateModified();
138
139         if (! $dateModified) {
140             $dateModified = null;
141         }
142
143         $this->data['datemodified'] = $dateModified;
144
145         return $this->data['datemodified'];
146     }
147
148     /**
149      * Get the feed lastBuild date. This is not implemented in Atom.
150      *
151      * @return string|null
152      */
153     public function getLastBuildDate()
154     {
155         return;
156     }
157
158     /**
159      * Get the feed description
160      *
161      * @return string|null
162      */
163     public function getDescription()
164     {
165         if (array_key_exists('description', $this->data)) {
166             return $this->data['description'];
167         }
168
169         $description = $this->getExtension('Atom')->getDescription();
170
171         if (! $description) {
172             $description = null;
173         }
174
175         $this->data['description'] = $description;
176
177         return $this->data['description'];
178     }
179
180     /**
181      * Get the feed generator entry
182      *
183      * @return string|null
184      */
185     public function getGenerator()
186     {
187         if (array_key_exists('generator', $this->data)) {
188             return $this->data['generator'];
189         }
190
191         $generator = $this->getExtension('Atom')->getGenerator();
192
193         $this->data['generator'] = $generator;
194
195         return $this->data['generator'];
196     }
197
198     /**
199      * Get the feed ID
200      *
201      * @return string|null
202      */
203     public function getId()
204     {
205         if (array_key_exists('id', $this->data)) {
206             return $this->data['id'];
207         }
208
209         $id = $this->getExtension('Atom')->getId();
210
211         $this->data['id'] = $id;
212
213         return $this->data['id'];
214     }
215
216     /**
217      * Get the feed language
218      *
219      * @return string|null
220      */
221     public function getLanguage()
222     {
223         if (array_key_exists('language', $this->data)) {
224             return $this->data['language'];
225         }
226
227         $language = $this->getExtension('Atom')->getLanguage();
228
229         if (! $language) {
230             $language = $this->xpath->evaluate('string(//@xml:lang[1])');
231         }
232
233         if (! $language) {
234             $language = null;
235         }
236
237         $this->data['language'] = $language;
238
239         return $this->data['language'];
240     }
241
242     /**
243      * Get a link to the source website
244      *
245      * @return string|null
246      */
247     public function getBaseUrl()
248     {
249         if (array_key_exists('baseUrl', $this->data)) {
250             return $this->data['baseUrl'];
251         }
252
253         $baseUrl = $this->getExtension('Atom')->getBaseUrl();
254
255         $this->data['baseUrl'] = $baseUrl;
256
257         return $this->data['baseUrl'];
258     }
259
260     /**
261      * Get a link to the source website
262      *
263      * @return string|null
264      */
265     public function getLink()
266     {
267         if (array_key_exists('link', $this->data)) {
268             return $this->data['link'];
269         }
270
271         $link = $this->getExtension('Atom')->getLink();
272
273         $this->data['link'] = $link;
274
275         return $this->data['link'];
276     }
277
278     /**
279      * Get feed image data
280      *
281      * @return array|null
282      */
283     public function getImage()
284     {
285         if (array_key_exists('image', $this->data)) {
286             return $this->data['image'];
287         }
288
289         $link = $this->getExtension('Atom')->getImage();
290
291         $this->data['image'] = $link;
292
293         return $this->data['image'];
294     }
295
296     /**
297      * Get a link to the feed's XML Url
298      *
299      * @return string|null
300      */
301     public function getFeedLink()
302     {
303         if (array_key_exists('feedlink', $this->data)) {
304             return $this->data['feedlink'];
305         }
306
307         $link = $this->getExtension('Atom')->getFeedLink();
308
309         if ($link === null || empty($link)) {
310             $link = $this->getOriginalSourceUri();
311         }
312
313         $this->data['feedlink'] = $link;
314
315         return $this->data['feedlink'];
316     }
317
318     /**
319      * Get the feed title
320      *
321      * @return string|null
322      */
323     public function getTitle()
324     {
325         if (array_key_exists('title', $this->data)) {
326             return $this->data['title'];
327         }
328
329         $title = $this->getExtension('Atom')->getTitle();
330
331         $this->data['title'] = $title;
332
333         return $this->data['title'];
334     }
335
336     /**
337      * Get an array of any supported Pusubhubbub endpoints
338      *
339      * @return array|null
340      */
341     public function getHubs()
342     {
343         if (array_key_exists('hubs', $this->data)) {
344             return $this->data['hubs'];
345         }
346
347         $hubs = $this->getExtension('Atom')->getHubs();
348
349         $this->data['hubs'] = $hubs;
350
351         return $this->data['hubs'];
352     }
353
354     /**
355      * Get all categories
356      *
357      * @return Reader\Collection\Category
358      */
359     public function getCategories()
360     {
361         if (array_key_exists('categories', $this->data)) {
362             return $this->data['categories'];
363         }
364
365         $categoryCollection = $this->getExtension('Atom')->getCategories();
366
367         if (count($categoryCollection) == 0) {
368             $categoryCollection = $this->getExtension('DublinCore')->getCategories();
369         }
370
371         $this->data['categories'] = $categoryCollection;
372
373         return $this->data['categories'];
374     }
375
376     /**
377      * Read all entries to the internal entries array
378      *
379      * @return void
380      */
381     protected function indexEntries()
382     {
383         if ($this->getType() == Reader\Reader::TYPE_ATOM_10 ||
384             $this->getType() == Reader\Reader::TYPE_ATOM_03) {
385             $entries = $this->xpath->evaluate('//atom:entry');
386
387             foreach ($entries as $index => $entry) {
388                 $this->entries[$index] = $entry;
389             }
390         }
391     }
392
393     /**
394      * Register the default namespaces for the current feed format
395      *
396      */
397     protected function registerNamespaces()
398     {
399         switch ($this->data['type']) {
400             case Reader\Reader::TYPE_ATOM_03:
401                 $this->xpath->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_03);
402                 break;
403             case Reader\Reader::TYPE_ATOM_10:
404             default:
405                 $this->xpath->registerNamespace('atom', Reader\Reader::NAMESPACE_ATOM_10);
406         }
407     }
408 }