File indexing completed on 2025-01-19 05:21:05
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Feed_Reader 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @see Zend_Feed_Reader_Extension_FeedAbstract 0024 */ 0025 // require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php'; 0026 0027 /** 0028 * @see Zend_Date 0029 */ 0030 // require_once 'Zend/Date.php'; 0031 0032 /** 0033 * @see Zend_Feed_Reader_Collection_Author 0034 */ 0035 // require_once 'Zend/Feed/Reader/Collection/Author.php'; 0036 0037 /** 0038 * @category Zend 0039 * @package Zend_Feed_Reader 0040 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0041 * @license http://framework.zend.com/license/new-bsd New BSD License 0042 */ 0043 class Zend_Feed_Reader_Extension_DublinCore_Feed 0044 extends Zend_Feed_Reader_Extension_FeedAbstract 0045 { 0046 /** 0047 * Get a single author 0048 * 0049 * @param int $index 0050 * @return string|null 0051 */ 0052 public function getAuthor($index = 0) 0053 { 0054 $authors = $this->getAuthors(); 0055 0056 if (isset($authors[$index])) { 0057 return $authors[$index]; 0058 } 0059 0060 return null; 0061 } 0062 0063 /** 0064 * Get an array with feed authors 0065 * 0066 * @return array 0067 */ 0068 public function getAuthors() 0069 { 0070 if (array_key_exists('authors', $this->_data)) { 0071 return $this->_data['authors']; 0072 } 0073 0074 $authors = array(); 0075 $list = $this->_xpath->query('//dc11:creator'); 0076 0077 if (!$list->length) { 0078 $list = $this->_xpath->query('//dc10:creator'); 0079 } 0080 if (!$list->length) { 0081 $list = $this->_xpath->query('//dc11:publisher'); 0082 0083 if (!$list->length) { 0084 $list = $this->_xpath->query('//dc10:publisher'); 0085 } 0086 } 0087 0088 if ($list->length) { 0089 foreach ($list as $author) { 0090 $authors[] = array( 0091 'name' => $author->nodeValue 0092 ); 0093 } 0094 $authors = new Zend_Feed_Reader_Collection_Author( 0095 Zend_Feed_Reader::arrayUnique($authors) 0096 ); 0097 } else { 0098 $authors = null; 0099 } 0100 0101 $this->_data['authors'] = $authors; 0102 0103 return $this->_data['authors']; 0104 } 0105 0106 /** 0107 * Get the copyright entry 0108 * 0109 * @return string|null 0110 */ 0111 public function getCopyright() 0112 { 0113 if (array_key_exists('copyright', $this->_data)) { 0114 return $this->_data['copyright']; 0115 } 0116 0117 $copyright = null; 0118 $copyright = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:rights)'); 0119 0120 if (!$copyright) { 0121 $copyright = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:rights)'); 0122 } 0123 0124 if (!$copyright) { 0125 $copyright = null; 0126 } 0127 0128 $this->_data['copyright'] = $copyright; 0129 0130 return $this->_data['copyright']; 0131 } 0132 0133 /** 0134 * Get the feed description 0135 * 0136 * @return string|null 0137 */ 0138 public function getDescription() 0139 { 0140 if (array_key_exists('description', $this->_data)) { 0141 return $this->_data['description']; 0142 } 0143 0144 $description = null; 0145 $description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)'); 0146 0147 if (!$description) { 0148 $description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)'); 0149 } 0150 0151 if (!$description) { 0152 $description = null; 0153 } 0154 0155 $this->_data['description'] = $description; 0156 0157 return $this->_data['description']; 0158 } 0159 0160 /** 0161 * Get the feed ID 0162 * 0163 * @return string|null 0164 */ 0165 public function getId() 0166 { 0167 if (array_key_exists('id', $this->_data)) { 0168 return $this->_data['id']; 0169 } 0170 0171 $id = null; 0172 $id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)'); 0173 0174 if (!$id) { 0175 $id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:identifier)'); 0176 } 0177 0178 $this->_data['id'] = $id; 0179 0180 return $this->_data['id']; 0181 } 0182 0183 /** 0184 * Get the feed language 0185 * 0186 * @return string|null 0187 */ 0188 public function getLanguage() 0189 { 0190 if (array_key_exists('language', $this->_data)) { 0191 return $this->_data['language']; 0192 } 0193 0194 $language = null; 0195 $language = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:language)'); 0196 0197 if (!$language) { 0198 $language = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:language)'); 0199 } 0200 0201 if (!$language) { 0202 $language = null; 0203 } 0204 0205 $this->_data['language'] = $language; 0206 0207 return $this->_data['language']; 0208 } 0209 0210 /** 0211 * Get the feed title 0212 * 0213 * @return string|null 0214 */ 0215 public function getTitle() 0216 { 0217 if (array_key_exists('title', $this->_data)) { 0218 return $this->_data['title']; 0219 } 0220 0221 $title = null; 0222 $title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)'); 0223 0224 if (!$title) { 0225 $title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)'); 0226 } 0227 0228 if (!$title) { 0229 $title = null; 0230 } 0231 0232 $this->_data['title'] = $title; 0233 0234 return $this->_data['title']; 0235 } 0236 0237 /** 0238 * 0239 * 0240 * @return Zend_Date|null 0241 */ 0242 public function getDate() 0243 { 0244 if (array_key_exists('date', $this->_data)) { 0245 return $this->_data['date']; 0246 } 0247 0248 $d = null; 0249 $date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)'); 0250 0251 if (!$date) { 0252 $date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)'); 0253 } 0254 0255 if ($date) { 0256 $d = new Zend_Date; 0257 $d->set($date, Zend_Date::ISO_8601); 0258 } 0259 0260 $this->_data['date'] = $d; 0261 0262 return $this->_data['date']; 0263 } 0264 0265 /** 0266 * Get categories (subjects under DC) 0267 * 0268 * @return Zend_Feed_Reader_Collection_Category 0269 */ 0270 public function getCategories() 0271 { 0272 if (array_key_exists('categories', $this->_data)) { 0273 return $this->_data['categories']; 0274 } 0275 0276 $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:subject'); 0277 0278 if (!$list->length) { 0279 $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:subject'); 0280 } 0281 0282 if ($list->length) { 0283 $categoryCollection = new Zend_Feed_Reader_Collection_Category; 0284 foreach ($list as $category) { 0285 $categoryCollection[] = array( 0286 'term' => $category->nodeValue, 0287 'scheme' => null, 0288 'label' => $category->nodeValue, 0289 ); 0290 } 0291 } else { 0292 $categoryCollection = new Zend_Feed_Reader_Collection_Category; 0293 } 0294 0295 $this->_data['categories'] = $categoryCollection; 0296 return $this->_data['categories']; 0297 } 0298 0299 /** 0300 * Register the default namespaces for the current feed format 0301 * 0302 * @return void 0303 */ 0304 protected function _registerNamespaces() 0305 { 0306 $this->_xpath->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/'); 0307 $this->_xpath->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/'); 0308 } 0309 }