PageRenderTime 59ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/app/lib/core/Zend/Feed/Reader/Extension/DublinCore/Entry.php

https://bitbucket.org/Sinfin/pawtucket
PHP | 266 lines | 142 code | 44 blank | 80 comment | 22 complexity | ef4df0c79a9e23f4a752fed5e2aa3025 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0
  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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $
  20. */
  21. /**
  22. * @see Zend_Feed_Reader
  23. */
  24. require_once 'Zend/Feed/Reader.php';
  25. /**
  26. * @see Zend_Feed_Reader_Extension_EntryAbstract
  27. */
  28. require_once 'Zend/Feed/Reader/Extension/EntryAbstract.php';
  29. /**
  30. * @see Zend_Date
  31. */
  32. require_once 'Zend/Date.php';
  33. /**
  34. * @category Zend
  35. * @package Zend_Feed_Reader
  36. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. class Zend_Feed_Reader_Extension_DublinCore_Entry
  40. extends Zend_Feed_Reader_Extension_EntryAbstract
  41. {
  42. /**
  43. * Get an author entry
  44. *
  45. * @param DOMElement $element
  46. * @return string
  47. */
  48. public function getAuthor($index = 0)
  49. {
  50. $authors = $this->getAuthors();
  51. if (isset($authors[$index])) {
  52. return $authors[$index];
  53. }
  54. return null;
  55. }
  56. /**
  57. * Get an array with feed authors
  58. *
  59. * @return array
  60. */
  61. public function getAuthors()
  62. {
  63. if (array_key_exists('authors', $this->_data)) {
  64. return $this->_data['authors'];
  65. }
  66. $authors = array();
  67. $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:creator');
  68. if (!$list->length) {
  69. $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:creator');
  70. }
  71. if (!$list->length) {
  72. $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:publisher');
  73. if (!$list->length) {
  74. $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:publisher');
  75. }
  76. }
  77. if ($list->length) {
  78. foreach ($list as $author) {
  79. $authors[] = array(
  80. 'name' => $author->nodeValue
  81. );
  82. }
  83. $authors = new Zend_Feed_Reader_Collection_Author(
  84. Zend_Feed_Reader::arrayUnique($authors)
  85. );
  86. } else {
  87. $authors = null;
  88. }
  89. $this->_data['authors'] = $authors;
  90. return $this->_data['authors'];
  91. }
  92. /**
  93. * Get categories (subjects under DC)
  94. *
  95. * @return Zend_Feed_Reader_Collection_Category
  96. */
  97. public function getCategories()
  98. {
  99. if (array_key_exists('categories', $this->_data)) {
  100. return $this->_data['categories'];
  101. }
  102. $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc11:subject');
  103. if (!$list->length) {
  104. $list = $this->_xpath->evaluate($this->getXpathPrefix() . '//dc10:subject');
  105. }
  106. if ($list->length) {
  107. $categoryCollection = new Zend_Feed_Reader_Collection_Category;
  108. foreach ($list as $category) {
  109. $categoryCollection[] = array(
  110. 'term' => $category->nodeValue,
  111. 'scheme' => null,
  112. 'label' => $category->nodeValue,
  113. );
  114. }
  115. } else {
  116. $categoryCollection = new Zend_Feed_Reader_Collection_Category;
  117. }
  118. $this->_data['categories'] = $categoryCollection;
  119. return $this->_data['categories'];
  120. }
  121. /**
  122. * Get the entry content
  123. *
  124. * @return string
  125. */
  126. public function getContent()
  127. {
  128. return $this->getDescription();
  129. }
  130. /**
  131. * Get the entry description
  132. *
  133. * @return string
  134. */
  135. public function getDescription()
  136. {
  137. if (array_key_exists('description', $this->_data)) {
  138. return $this->_data['description'];
  139. }
  140. $description = null;
  141. $description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:description)');
  142. if (!$description) {
  143. $description = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:description)');
  144. }
  145. if (!$description) {
  146. $description = null;
  147. }
  148. $this->_data['description'] = $description;
  149. return $this->_data['description'];
  150. }
  151. /**
  152. * Get the entry ID
  153. *
  154. * @return string
  155. */
  156. public function getId()
  157. {
  158. if (array_key_exists('id', $this->_data)) {
  159. return $this->_data['id'];
  160. }
  161. $id = null;
  162. $id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:identifier)');
  163. if (!$id) {
  164. $id = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:identifier)');
  165. }
  166. $this->_data['id'] = $id;
  167. return $this->_data['id'];
  168. }
  169. /**
  170. * Get the entry title
  171. *
  172. * @return string
  173. */
  174. public function getTitle()
  175. {
  176. if (array_key_exists('title', $this->_data)) {
  177. return $this->_data['title'];
  178. }
  179. $title = null;
  180. $title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:title)');
  181. if (!$title) {
  182. $title = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:title)');
  183. }
  184. if (!$title) {
  185. $title = null;
  186. }
  187. $this->_data['title'] = $title;
  188. return $this->_data['title'];
  189. }
  190. /**
  191. *
  192. *
  193. * @return Zend_Date|null
  194. */
  195. public function getDate()
  196. {
  197. if (array_key_exists('date', $this->_data)) {
  198. return $this->_data['date'];
  199. }
  200. $d = null;
  201. $date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc11:date)');
  202. if (!$date) {
  203. $date = $this->_xpath->evaluate('string(' . $this->getXpathPrefix() . '/dc10:date)');
  204. }
  205. if ($date) {
  206. $d = new Zend_Date;
  207. $d->set($date, Zend_Date::ISO_8601);
  208. }
  209. $this->_data['date'] = $d;
  210. return $this->_data['date'];
  211. }
  212. /**
  213. * Register DC namespaces
  214. *
  215. * @return void
  216. */
  217. protected function _registerNamespaces()
  218. {
  219. $this->_xpath->registerNamespace('dc10', 'http://purl.org/dc/elements/1.0/');
  220. $this->_xpath->registerNamespace('dc11', 'http://purl.org/dc/elements/1.1/');
  221. }
  222. }