3 * Zend Framework (http://framework.zend.com/)
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
10 namespace Zend\Feed\Reader\Extension\DublinCore;
14 use Zend\Feed\Reader\Collection;
15 use Zend\Feed\Reader\Extension;
17 class Feed extends Extension\AbstractFeed
25 public function getAuthor($index = 0)
27 $authors = $this->getAuthors();
29 if (isset($authors[$index])) {
30 return $authors[$index];
37 * Get an array with feed authors
41 public function getAuthors()
43 if (array_key_exists('authors', $this->data)) {
44 return $this->data['authors'];
48 $list = $this->getXpath()->query('//dc11:creator');
50 if (! $list->length) {
51 $list = $this->getXpath()->query('//dc10:creator');
53 if (! $list->length) {
54 $list = $this->getXpath()->query('//dc11:publisher');
56 if (! $list->length) {
57 $list = $this->getXpath()->query('//dc10:publisher');
62 foreach ($list as $author) {
64 'name' => $author->nodeValue
67 $authors = new Collection\Author(
68 Reader\Reader::arrayUnique($authors)
74 $this->data['authors'] = $authors;
76 return $this->data['authors'];
80 * Get the copyright entry
84 public function getCopyright()
86 if (array_key_exists('copyright', $this->data)) {
87 return $this->data['copyright'];
90 $copyright = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:rights)');
93 $copyright = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:rights)');
100 $this->data['copyright'] = $copyright;
102 return $this->data['copyright'];
106 * Get the feed description
108 * @return string|null
110 public function getDescription()
112 if (array_key_exists('description', $this->data)) {
113 return $this->data['description'];
116 $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)');
118 if (! $description) {
119 $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)');
122 if (! $description) {
126 $this->data['description'] = $description;
128 return $this->data['description'];
134 * @return string|null
136 public function getId()
138 if (array_key_exists('id', $this->data)) {
139 return $this->data['id'];
142 $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)');
145 $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:identifier)');
148 $this->data['id'] = $id;
150 return $this->data['id'];
154 * Get the feed language
156 * @return string|null
158 public function getLanguage()
160 if (array_key_exists('language', $this->data)) {
161 return $this->data['language'];
164 $language = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:language)');
167 $language = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:language)');
174 $this->data['language'] = $language;
176 return $this->data['language'];
182 * @return string|null
184 public function getTitle()
186 if (array_key_exists('title', $this->data)) {
187 return $this->data['title'];
190 $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)');
193 $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)');
200 $this->data['title'] = $title;
202 return $this->data['title'];
208 * @return DateTime|null
210 public function getDate()
212 if (array_key_exists('date', $this->data)) {
213 return $this->data['date'];
217 $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)');
220 $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)');
224 $d = new DateTime($date);
227 $this->data['date'] = $d;
229 return $this->data['date'];
233 * Get categories (subjects under DC)
235 * @return Collection\Category
237 public function getCategories()
239 if (array_key_exists('categories', $this->data)) {
240 return $this->data['categories'];
243 $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc11:subject');
245 if (! $list->length) {
246 $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc10:subject');
250 $categoryCollection = new Collection\Category;
251 foreach ($list as $category) {
252 $categoryCollection[] = [
253 'term' => $category->nodeValue,
255 'label' => $category->nodeValue,
259 $categoryCollection = new Collection\Category;
262 $this->data['categories'] = $categoryCollection;
263 return $this->data['categories'];
267 * Register the default namespaces for the current feed format
271 protected function registerNamespaces()
273 $this->getXpath()->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/');
274 $this->getXpath()->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/');