1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Feed_Reader
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Feed.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Feed_Reader_Extension_FeedAbstract
*/
require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php';
/**
* @see Zend_Date
*/
require_once 'Zend/Date.php';
/**
* @see Zend_Feed_Reader_Collection_Author
*/
require_once 'Zend/Feed/Reader/Collection/Author.php';
/**
* @category Zend
* @package Zend_Feed_Reader
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Feed_Reader_Extension_DublinCore_Feed
extends Zend_Feed_Reader_Extension_FeedAbstract
{
/**
* Get a single author
*
* @param int $index
* @return string|null
*/
public function getAuthor($index = 0)
{
$authors = $this->getAuthors();
if (isset($authors[$index])) {
return $authors[$index];
}
return null;
}
/**
* Get an array with feed authors
*
* @return array
*/
public function getAuthors()
{
if (array_key_exists('authors', $this->_data)) {
return $this->_data['authors'];
}
$authors = array();
$list = $this->_xpath->query('//dc11:creator');
if (!$list->length) {
$list = $this->_xpath->query('//dc10:creator');
}
if (!$list->length) {
$list = $this->_xpath->query('//dc11:publisher');
if (!$list->length) {
$list = $this->_xpath->query('//dc10:publisher');
}
}
if ($list->length) {
foreach ($list as $author) {
$authors[] = array(
'name' => $author->nodeValue
);
}
$authors = new Zend_Feed_Reader_Collection_Author(
Zend_Feed_Reader::arrayUnique($authors)
);
} else {
$authors = null;
}
$this->_data['authors'] = $authors;
return $this->_data['authors'];
}
/**
* Get the copyright entry
*
* @return string|null
*/
public function getCopyright()
{
if (array_key_exists('copyright', $this->_data)) {
return $this->_data['copyright'];
}
$copyright = null;
$copyright = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:rights)');
if (!$copyright) {
$copyright = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:rights)');
}
if (!$copyright) {
$copyright = null;
}
$this->_data['copyright'] = $copyright;
return $this->_data['copyright'];
}
/**
* Get the feed description
*
* @return string|null
*/
public function getDescription()
{
if (array_key_exists('description', $this->_data)) {
return $this->_data['description'];
}
$description = null;
$description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)');
if (!$description) {
$description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)');
}
if (!$description) {
$description = null;
}
$this->_data['description'] = $description;
return $this->_data['description'];
}
/**
* Get the feed ID
*
* @return string|null
*/
public function getId()
{
if (array_key_exists('id', $this->_data)) {
return $this->_data['id'];
}
$id = null;
$id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)');
if (!$id) {
$id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:identifier)');
}
$this->_data['id'] = $id;
return $this->_data['id'];
}
/**
* Get the feed language
*
* @return string|null
*/
public function getLanguage()
{
if (array_key_exists('language', $this->_data)) {
return $this->_data['language'];
}
$language = null;
$language = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:language)');
if (!$language) {
$language = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:language)');
}
if (!$language) {
$language = null;
}
$this->_data['language'] = $language;
return $this->_data['language'];
}
/**
* Get the feed title
*
* @return string|null
*/
public function getTitle()
{
if (array_key_exists('title', $this->_data)) {
return $this->_data['title'];
}
$title = null;
$title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)');
if (!$title) {
$title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)');
}
if (!$title) {
$title = null;
}
$this->_data['title'] = $title;
return $this->_data['title'];
}
/**
*
*
* @return Zend_Date|null
*/
public function getDate()
{
if (array_key_exists('date', $this->_data)) {
return $this->_data['date'];
}
$d = null;
$date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)');
if (!$date) {
$date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)');
}
if ($date) {
$d = new Zend_Date;
$d->set($date, Zend_Date::ISO_8601);
}
$this->_data['date'] = $d;
return $this->_data['date'];
}
/**
* Get categories (subjects under DC)
*
* @return Zend_Feed_Reader_Collection_Category
*/
public function getCategories()
{
if (array_key_exists('categories', $this->_data)) {
return $this->_data['categories'];
}
$list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:subject');
if (!$list->length) {
$list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:subject');
}
if ($list->length) {
$categoryCollection = new Zend_Feed_Reader_Collection_Category;
foreach ($list as $category) {
$categoryCollection[] = array(
'term' => $category->nodeValue,
'scheme' => null,
'label' => $category->nodeValue,
);
}
} else {
$categoryCollection = new Zend_Feed_Reader_Collection_Category;
}
$this->_data['categories'] = $categoryCollection;
return $this->_data['categories'];
}
/**
* Register the default namespaces for the current feed format
*
* @return void
*/
protected function _registerNamespaces()
{
$this->_xpath->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/');
$this->_xpath->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/');
}
}
|