PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/application/libraries/Zend/Feed/Reader/Extension/DublinCore/Feed.php

https://github.com/grandison/budo16
PHP | 265 lines | 137 code | 49 blank | 79 comment | 23 complexity | 20e4f45fc4925823941ce91ef6766f18 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Feed_Reader
  17. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Feed.php 16711 2009-07-14 16:10:54Z matthew $
  20. */
  21. /**
  22. * @see Zend_Feed_Reader_Extension_FeedAbstract
  23. */
  24. // require_once 'Zend/Feed/Reader/Extension/FeedAbstract.php';
  25. /**
  26. * @see Zend_Date
  27. */
  28. // require_once 'Zend/Date.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Feed_Reader
  32. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Feed_Reader_Extension_DublinCore_Feed
  36. extends Zend_Feed_Reader_Extension_FeedAbstract
  37. {
  38. /**
  39. * Get a single author
  40. *
  41. * @param int $index
  42. * @return string|null
  43. */
  44. public function getAuthor($index = 0)
  45. {
  46. $authors = $this->getAuthors();
  47. if (isset($authors[$index])) {
  48. return $authors[$index];
  49. }
  50. return null;
  51. }
  52. /**
  53. * Get an array with feed authors
  54. *
  55. * @return array
  56. */
  57. public function getAuthors()
  58. {
  59. if (array_key_exists('authors', $this->_data)) {
  60. return $this->_data['authors'];
  61. }
  62. $authors = array();
  63. $list = $this->_xpath->query('//dc11:creator');
  64. if (!$list->length) {
  65. $list = $this->_xpath->query('//dc10:creator');
  66. }
  67. if (!$list->length) {
  68. $list = $this->_xpath->query('//dc11:publisher');
  69. if (!$list->length) {
  70. $list = $this->_xpath->query('//dc10:publisher');
  71. }
  72. }
  73. foreach ($list as $authorObj) {
  74. $authors[] = $authorObj->nodeValue;
  75. }
  76. if (!empty($authors)) {
  77. $authors = array_unique($authors);
  78. }
  79. $this->_data['authors'] = $authors;
  80. return $this->_data['authors'];
  81. }
  82. /**
  83. * Get the copyright entry
  84. *
  85. * @return string|null
  86. */
  87. public function getCopyright()
  88. {
  89. if (array_key_exists('copyright', $this->_data)) {
  90. return $this->_data['copyright'];
  91. }
  92. $copyright = null;
  93. $copyright = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:rights)');
  94. if (!$copyright) {
  95. $copyright = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:rights)');
  96. }
  97. if (!$copyright) {
  98. $copyright = null;
  99. }
  100. $this->_data['copyright'] = $copyright;
  101. return $this->_data['copyright'];
  102. }
  103. /**
  104. * Get the feed description
  105. *
  106. * @return string|null
  107. */
  108. public function getDescription()
  109. {
  110. if (array_key_exists('description', $this->_data)) {
  111. return $this->_data['description'];
  112. }
  113. $description = null;
  114. $description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)');
  115. if (!$description) {
  116. $description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)');
  117. }
  118. if (!$description) {
  119. $description = null;
  120. }
  121. $this->_data['description'] = $description;
  122. return $this->_data['description'];
  123. }
  124. /**
  125. * Get the feed ID
  126. *
  127. * @return string|null
  128. */
  129. public function getId()
  130. {
  131. if (array_key_exists('id', $this->_data)) {
  132. return $this->_data['id'];
  133. }
  134. $id = null;
  135. $id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)');
  136. if (!$id) {
  137. $id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:identifier)');
  138. }
  139. $this->_data['id'] = $id;
  140. return $this->_data['id'];
  141. }
  142. /**
  143. * Get the feed language
  144. *
  145. * @return string|null
  146. */
  147. public function getLanguage()
  148. {
  149. if (array_key_exists('language', $this->_data)) {
  150. return $this->_data['language'];
  151. }
  152. $language = null;
  153. $language = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:language)');
  154. if (!$language) {
  155. $language = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:language)');
  156. }
  157. if (!$language) {
  158. $language = null;
  159. }
  160. $this->_data['language'] = $language;
  161. return $this->_data['language'];
  162. }
  163. /**
  164. * Get the feed title
  165. *
  166. * @return string|null
  167. */
  168. public function getTitle()
  169. {
  170. if (array_key_exists('title', $this->_data)) {
  171. return $this->_data['title'];
  172. }
  173. $title = null;
  174. $title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)');
  175. if (!$title) {
  176. $title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)');
  177. }
  178. if (!$title) {
  179. $title = null;
  180. }
  181. $this->_data['title'] = $title;
  182. return $this->_data['title'];
  183. }
  184. /**
  185. *
  186. *
  187. * @return Zend_Date|null
  188. */
  189. public function getDate()
  190. {
  191. if (array_key_exists('date', $this->_data)) {
  192. return $this->_data['date'];
  193. }
  194. $d = null;
  195. $date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)');
  196. if (!$date) {
  197. $date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)');
  198. }
  199. if ($date) {
  200. $d = new Zend_Date;
  201. $d->set($date, Zend_Date::ISO_8601);
  202. }
  203. $this->_data['date'] = $d;
  204. return $this->_data['date'];
  205. }
  206. /**
  207. * Register the default namespaces for the current feed format
  208. *
  209. * @return void
  210. */
  211. protected function _registerNamespaces()
  212. {
  213. $this->_xpath->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/');
  214. $this->_xpath->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/');
  215. }
  216. }