3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 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');
51 $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc10:creator');
54 $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc11:publisher');
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');
93 $list = $this->getXpath()->evaluate($this->getXpathPrefix() . '//dc10:subject');
97 $categoryCollection = new Collection\Category
;
98 foreach ($list as $category) {
99 $categoryCollection[] = array(
100 'term' => $category->nodeValue
,
102 'label' => $category->nodeValue
,
106 $categoryCollection = new Collection\Category
;
109 $this->data
['categories'] = $categoryCollection;
110 return $this->data
['categories'];
115 * Get the entry content
119 public function getContent()
121 return $this->getDescription();
125 * Get the entry description
129 public function getDescription()
131 if (array_key_exists('description', $this->data
)) {
132 return $this->data
['description'];
136 $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)');
139 $description = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)');
146 $this->data
['description'] = $description;
148 return $this->data
['description'];
156 public function getId()
158 if (array_key_exists('id', $this->data
)) {
159 return $this->data
['id'];
163 $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)');
166 $id = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:identifier)');
169 $this->data
['id'] = $id;
171 return $this->data
['id'];
175 * Get the entry title
179 public function getTitle()
181 if (array_key_exists('title', $this->data
)) {
182 return $this->data
['title'];
186 $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)');
189 $title = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)');
196 $this->data
['title'] = $title;
198 return $this->data
['title'];
204 * @return DateTime|null
206 public function getDate()
208 if (array_key_exists('date', $this->data
)) {
209 return $this->data
['date'];
213 $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)');
216 $date = $this->getXpath()->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)');
220 $d = new DateTime($date);
223 $this->data
['date'] = $d;
225 return $this->data
['date'];
229 * Register DC namespaces
233 protected function registerNamespaces()
235 $this->getXpath()->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/');
236 $this->getXpath()->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/');