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 Entry extends Extension\AbstractEntry
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()->evaluate($this->getXpathPrefix() . '//dc11:creator');
50 if (! $list->length) {
51 $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc10:creator');
53 if (! $list->length) {
54 $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc11:publisher');
56 if (! $list->length) {
57 $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//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 categories (subjects under DC)
82 * @return Collection\Category
84 public function getCategories()
86 if (array_key_exists('categories', $this->data)) {
87 return $this->data['categories'];
90 $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc11:subject');
92 if (! $list->length) {
93 $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc10:subject');
97 $categoryCollection = new Collection\Category;
98 foreach ($list as $category) {
99 $categoryCollection[] = [
100 'term' => $category->nodeValue,
102 'label' => $category->nodeValue,
106 $categoryCollection = new Collection\Category;
109 $this->data['categories'] = $categoryCollection;
110 return $this->data['categories'];
114 * Get the entry content
118 public function getContent()
120 return $this->getDescription();
124 * Get the entry description
128 public function getDescription()
130 if (array_key_exists('description', $this->data)) {
131 return $this->data['description'];
134 $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)');
136 if (! $description) {
137 $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)');
140 if (! $description) {
144 $this->data['description'] = $description;
146 return $this->data['description'];
154 public function getId()
156 if (array_key_exists('id', $this->data)) {
157 return $this->data['id'];
160 $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)');
163 $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:identifier)');
166 $this->data['id'] = $id;
168 return $this->data['id'];
172 * Get the entry title
176 public function getTitle()
178 if (array_key_exists('title', $this->data)) {
179 return $this->data['title'];
182 $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)');
185 $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)');
192 $this->data['title'] = $title;
194 return $this->data['title'];
200 * @return DateTime|null
202 public function getDate()
204 if (array_key_exists('date', $this->data)) {
205 return $this->data['date'];
209 $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)');
212 $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)');
216 $d = new DateTime($date);
219 $this->data['date'] = $d;
221 return $this->data['date'];
225 * Register DC namespaces
229 protected function registerNamespaces()
231 $this->getXpath()->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/');
232 $this->getXpath()->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/');