db backup prior to drupal security update
[yaffs-website] / vendor / zendframework / zend-feed / src / Reader / Extension / DublinCore / Feed.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\Extension\DublinCore;
11
12 use DateTime;
13 use Zend\Feed\Reader;
14 use Zend\Feed\Reader\Collection;
15 use Zend\Feed\Reader\Extension;
16
17 class Feed extends Extension\AbstractFeed
18 {
19     /**
20      * Get a single author
21      *
22      * @param  int $index
23      * @return string|null
24      */
25     public function getAuthor($index = 0)
26     {
27         $authors = $this->getAuthors();
28
29         if (isset($authors[$index])) {
30             return $authors[$index];
31         }
32
33         return;
34     }
35
36     /**
37      * Get an array with feed authors
38      *
39      * @return array
40      */
41     public function getAuthors()
42     {
43         if (array_key_exists('authors', $this->data)) {
44             return $this->data['authors'];
45         }
46
47         $authors = [];
48         $list    = $this->getXpath()->query('//dc11:creator');
49
50         if (! $list->length) {
51             $list = $this->getXpath()->query('//dc10:creator');
52         }
53         if (! $list->length) {
54             $list = $this->getXpath()->query('//dc11:publisher');
55
56             if (! $list->length) {
57                 $list = $this->getXpath()->query('//dc10:publisher');
58             }
59         }
60
61         if ($list->length) {
62             foreach ($list as $author) {
63                 $authors[] = [
64                     'name' => $author->nodeValue
65                 ];
66             }
67             $authors = new Collection\Author(
68                 Reader\Reader::arrayUnique($authors)
69             );
70         } else {
71             $authors = null;
72         }
73
74         $this->data['authors'] = $authors;
75
76         return $this->data['authors'];
77     }
78
79     /**
80      * Get the copyright entry
81      *
82      * @return string|null
83      */
84     public function getCopyright()
85     {
86         if (array_key_exists('copyright', $this->data)) {
87             return $this->data['copyright'];
88         }
89
90         $copyright = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:rights)');
91
92         if (! $copyright) {
93             $copyright = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:rights)');
94         }
95
96         if (! $copyright) {
97             $copyright = null;
98         }
99
100         $this->data['copyright'] = $copyright;
101
102         return $this->data['copyright'];
103     }
104
105     /**
106      * Get the feed description
107      *
108      * @return string|null
109      */
110     public function getDescription()
111     {
112         if (array_key_exists('description', $this->data)) {
113             return $this->data['description'];
114         }
115
116         $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)');
117
118         if (! $description) {
119             $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)');
120         }
121
122         if (! $description) {
123             $description = null;
124         }
125
126         $this->data['description'] = $description;
127
128         return $this->data['description'];
129     }
130
131     /**
132      * Get the feed ID
133      *
134      * @return string|null
135      */
136     public function getId()
137     {
138         if (array_key_exists('id', $this->data)) {
139             return $this->data['id'];
140         }
141
142         $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)');
143
144         if (! $id) {
145             $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:identifier)');
146         }
147
148         $this->data['id'] = $id;
149
150         return $this->data['id'];
151     }
152
153     /**
154      * Get the feed language
155      *
156      * @return string|null
157      */
158     public function getLanguage()
159     {
160         if (array_key_exists('language', $this->data)) {
161             return $this->data['language'];
162         }
163
164         $language = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:language)');
165
166         if (! $language) {
167             $language = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:language)');
168         }
169
170         if (! $language) {
171             $language = null;
172         }
173
174         $this->data['language'] = $language;
175
176         return $this->data['language'];
177     }
178
179     /**
180      * Get the feed title
181      *
182      * @return string|null
183      */
184     public function getTitle()
185     {
186         if (array_key_exists('title', $this->data)) {
187             return $this->data['title'];
188         }
189
190         $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)');
191
192         if (! $title) {
193             $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)');
194         }
195
196         if (! $title) {
197             $title = null;
198         }
199
200         $this->data['title'] = $title;
201
202         return $this->data['title'];
203     }
204
205     /**
206      *
207      *
208      * @return DateTime|null
209      */
210     public function getDate()
211     {
212         if (array_key_exists('date', $this->data)) {
213             return $this->data['date'];
214         }
215
216         $d = null;
217         $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)');
218
219         if (! $date) {
220             $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)');
221         }
222
223         if ($date) {
224             $d = new DateTime($date);
225         }
226
227         $this->data['date'] = $d;
228
229         return $this->data['date'];
230     }
231
232     /**
233      * Get categories (subjects under DC)
234      *
235      * @return Collection\Category
236      */
237     public function getCategories()
238     {
239         if (array_key_exists('categories', $this->data)) {
240             return $this->data['categories'];
241         }
242
243         $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc11:subject');
244
245         if (! $list->length) {
246             $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc10:subject');
247         }
248
249         if ($list->length) {
250             $categoryCollection = new Collection\Category;
251             foreach ($list as $category) {
252                 $categoryCollection[] = [
253                     'term' => $category->nodeValue,
254                     'scheme' => null,
255                     'label' => $category->nodeValue,
256                 ];
257             }
258         } else {
259             $categoryCollection = new Collection\Category;
260         }
261
262         $this->data['categories'] = $categoryCollection;
263         return $this->data['categories'];
264     }
265
266     /**
267      * Register the default namespaces for the current feed format
268      *
269      * @return void
270      */
271     protected function registerNamespaces()
272     {
273         $this->getXpath()->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/');
274         $this->getXpath()->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/');
275     }
276 }