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 0024 */ 0025 // require_once 'Zend/Feed/Reader.php'; 0026 0027 /** 0028 * @see Zend_Feed_Reader_Extension_EntryAbstract 0029 */ 0030 // require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php'; 0031 0032 /** 0033 * @see Zend_Date 0034 */ 0035 // require_once 'Zend/Date.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_Entry 0044 extends Zend_Feed_Reader_Extension_EntryAbstract 0045 { 0046 /** 0047 * Get an author entry 0048 * 0049 * @param DOMElement $element 0050 * @return string 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->evaluate($this->getXpathPrefix() . '//dc11:creator'); 0076 0077 if (!$list->length) { 0078 $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:creator'); 0079 } 0080 if (!$list->length) { 0081 $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:publisher'); 0082 0083 if (!$list->length) { 0084 $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//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 categories (subjects under DC) 0108 * 0109 * @return Zend_Feed_Reader_Collection_Category 0110 */ 0111 public function getCategories() 0112 { 0113 if (array_key_exists('categories', $this->_data)) { 0114 return $this->_data['categories']; 0115 } 0116 0117 $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:subject'); 0118 0119 if (!$list->length) { 0120 $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:subject'); 0121 } 0122 0123 if ($list->length) { 0124 $categoryCollection = new Zend_Feed_Reader_Collection_Category; 0125 foreach ($list as $category) { 0126 $categoryCollection[] = array( 0127 'term' => $category->nodeValue, 0128 'scheme' => null, 0129 'label' => $category->nodeValue, 0130 ); 0131 } 0132 } else { 0133 $categoryCollection = new Zend_Feed_Reader_Collection_Category; 0134 } 0135 0136 $this->_data['categories'] = $categoryCollection; 0137 return $this->_data['categories']; 0138 } 0139 0140 0141 /** 0142 * Get the entry content 0143 * 0144 * @return string 0145 */ 0146 public function getContent() 0147 { 0148 return $this->getDescription(); 0149 } 0150 0151 /** 0152 * Get the entry description 0153 * 0154 * @return string 0155 */ 0156 public function getDescription() 0157 { 0158 if (array_key_exists('description', $this->_data)) { 0159 return $this->_data['description']; 0160 } 0161 0162 $description = null; 0163 $description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)'); 0164 0165 if (!$description) { 0166 $description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)'); 0167 } 0168 0169 if (!$description) { 0170 $description = null; 0171 } 0172 0173 $this->_data['description'] = $description; 0174 0175 return $this->_data['description']; 0176 } 0177 0178 /** 0179 * Get the entry ID 0180 * 0181 * @return string 0182 */ 0183 public function getId() 0184 { 0185 if (array_key_exists('id', $this->_data)) { 0186 return $this->_data['id']; 0187 } 0188 0189 $id = null; 0190 $id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)'); 0191 0192 if (!$id) { 0193 $id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:identifier)'); 0194 } 0195 0196 $this->_data['id'] = $id; 0197 0198 return $this->_data['id']; 0199 } 0200 0201 /** 0202 * Get the entry title 0203 * 0204 * @return string 0205 */ 0206 public function getTitle() 0207 { 0208 if (array_key_exists('title', $this->_data)) { 0209 return $this->_data['title']; 0210 } 0211 0212 $title = null; 0213 $title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)'); 0214 0215 if (!$title) { 0216 $title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)'); 0217 } 0218 0219 if (!$title) { 0220 $title = null; 0221 } 0222 0223 $this->_data['title'] = $title; 0224 0225 return $this->_data['title']; 0226 } 0227 0228 /** 0229 * 0230 * 0231 * @return Zend_Date|null 0232 */ 0233 public function getDate() 0234 { 0235 if (array_key_exists('date', $this->_data)) { 0236 return $this->_data['date']; 0237 } 0238 0239 $d = null; 0240 $date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)'); 0241 0242 if (!$date) { 0243 $date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)'); 0244 } 0245 0246 if ($date) { 0247 $d = new Zend_Date; 0248 $d->set($date, Zend_Date::ISO_8601); 0249 } 0250 0251 $this->_data['date'] = $d; 0252 0253 return $this->_data['date']; 0254 } 0255 0256 /** 0257 * Register DC namespaces 0258 * 0259 * @return void 0260 */ 0261 protected function _registerNamespaces() 0262 { 0263 $this->_xpath->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/'); 0264 $this->_xpath->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/'); 0265 } 0266 }