Feed.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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_Gdata
  17. * @subpackage Gdata
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Gdata
  24. */
  25. require_once 'Zend/Gdata.php';
  26. /**
  27. * @see Zend_Gdata_App_Feed
  28. */
  29. require_once 'Zend/Gdata/App/Feed.php';
  30. /**
  31. * @see Zend_Gdata_Entry
  32. */
  33. require_once 'Zend/Gdata/Entry.php';
  34. /**
  35. * @see Zend_Gdata_Extension_OpenSearchTotalResults
  36. */
  37. require_once 'Zend/Gdata/Extension/OpenSearchTotalResults.php';
  38. /**
  39. * @see Zend_Gdata_Extension_OpenSearchStartIndex
  40. */
  41. require_once 'Zend/Gdata/Extension/OpenSearchStartIndex.php';
  42. /**
  43. * @see Zend_Gdata_Extension_OpenSearchItemsPerPage
  44. */
  45. require_once 'Zend/Gdata/Extension/OpenSearchItemsPerPage.php';
  46. /**
  47. * The Gdata flavor of an Atom Feed
  48. *
  49. * @category Zend
  50. * @package Zend_Gdata
  51. * @subpackage Gdata
  52. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  53. * @license http://framework.zend.com/license/new-bsd New BSD License
  54. */
  55. class Zend_Gdata_Feed extends Zend_Gdata_App_Feed
  56. {
  57. /**
  58. * The classname for individual feed elements.
  59. *
  60. * @var string
  61. */
  62. protected $_entryClassName = 'Zend_Gdata_Entry';
  63. /**
  64. * The openSearch:totalResults element
  65. *
  66. * @var Zend_Gdata_Extension_OpenSearchTotalResults|null
  67. */
  68. protected $_totalResults = null;
  69. /**
  70. * The openSearch:startIndex element
  71. *
  72. * @var Zend_Gdata_Extension_OpenSearchStartIndex|null
  73. */
  74. protected $_startIndex = null;
  75. /**
  76. * The openSearch:itemsPerPage element
  77. *
  78. * @var Zend_Gdata_Extension_OpenSearchItemsPerPage|null
  79. */
  80. protected $_itemsPerPage = null;
  81. public function __construct($element = null)
  82. {
  83. $this->registerAllNamespaces(Zend_Gdata::$namespaces);
  84. parent::__construct($element);
  85. }
  86. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  87. {
  88. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  89. if ($this->_totalResults != null) {
  90. $element->appendChild($this->_totalResults->getDOM($element->ownerDocument));
  91. }
  92. if ($this->_startIndex != null) {
  93. $element->appendChild($this->_startIndex->getDOM($element->ownerDocument));
  94. }
  95. if ($this->_itemsPerPage != null) {
  96. $element->appendChild($this->_itemsPerPage->getDOM($element->ownerDocument));
  97. }
  98. // ETags are special. We only support them in protocol >= 2.X.
  99. // This will be duplicated by the HTTP ETag header.
  100. if ($majorVersion >= 2) {
  101. if ($this->_etag != null) {
  102. $element->setAttributeNS($this->lookupNamespace('gd'),
  103. 'gd:etag',
  104. $this->_etag);
  105. }
  106. }
  107. return $element;
  108. }
  109. /**
  110. * Creates individual Entry objects of the appropriate type and
  111. * stores them in the $_entry array based upon DOM data.
  112. *
  113. * @param DOMNode $child The DOMNode to process
  114. */
  115. protected function takeChildFromDOM($child)
  116. {
  117. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  118. switch ($absoluteNodeName) {
  119. case $this->lookupNamespace('openSearch') . ':' . 'totalResults':
  120. $totalResults = new Zend_Gdata_Extension_OpenSearchTotalResults();
  121. $totalResults->transferFromDOM($child);
  122. $this->_totalResults = $totalResults;
  123. break;
  124. case $this->lookupNamespace('openSearch') . ':' . 'startIndex':
  125. $startIndex = new Zend_Gdata_Extension_OpenSearchStartIndex();
  126. $startIndex->transferFromDOM($child);
  127. $this->_startIndex = $startIndex;
  128. break;
  129. case $this->lookupNamespace('openSearch') . ':' . 'itemsPerPage':
  130. $itemsPerPage = new Zend_Gdata_Extension_OpenSearchItemsPerPage();
  131. $itemsPerPage->transferFromDOM($child);
  132. $this->_itemsPerPage = $itemsPerPage;
  133. break;
  134. default:
  135. parent::takeChildFromDOM($child);
  136. break;
  137. }
  138. }
  139. /**
  140. * Given a DOMNode representing an attribute, tries to map the data into
  141. * instance members. If no mapping is defined, the name and value are
  142. * stored in an array.
  143. *
  144. * @param DOMNode $attribute The DOMNode attribute needed to be handled
  145. */
  146. protected function takeAttributeFromDOM($attribute)
  147. {
  148. switch ($attribute->localName) {
  149. case 'etag':
  150. // ETags are special, since they can be conveyed by either the
  151. // HTTP ETag header or as an XML attribute.
  152. $etag = $attribute->nodeValue;
  153. if ($this->_etag === null) {
  154. $this->_etag = $etag;
  155. }
  156. elseif ($this->_etag != $etag) {
  157. require_once('Zend/Gdata/App/IOException.php');
  158. throw new Zend_Gdata_App_IOException("ETag mismatch");
  159. }
  160. break;
  161. default:
  162. parent::takeAttributeFromDOM($attribute);
  163. break;
  164. }
  165. }
  166. /**
  167. * Set the value of the totalResults property.
  168. *
  169. * @param Zend_Gdata_Extension_OpenSearchTotalResults|null $value The
  170. * value of the totalResults property. Use null to unset.
  171. * @return Zend_Gdata_Feed Provides a fluent interface.
  172. */
  173. function setTotalResults($value) {
  174. $this->_totalResults = $value;
  175. return $this;
  176. }
  177. /**
  178. * Get the value of the totalResults property.
  179. *
  180. * @return Zend_Gdata_Extension_OpenSearchTotalResults|null The value of
  181. * the totalResults property, or null if unset.
  182. */
  183. function getTotalResults() {
  184. return $this->_totalResults;
  185. }
  186. /**
  187. * Set the start index property for feed paging.
  188. *
  189. * @param Zend_Gdata_Extension_OpenSearchStartIndex|null $value The value
  190. * for the startIndex property. Use null to unset.
  191. * @return Zend_Gdata_Feed Provides a fluent interface.
  192. */
  193. function setStartIndex($value) {
  194. $this->_startIndex = $value;
  195. return $this;
  196. }
  197. /**
  198. * Get the value of the startIndex property.
  199. *
  200. * @return Zend_Gdata_Extension_OpenSearchStartIndex|null The value of the
  201. * startIndex property, or null if unset.
  202. */
  203. function getStartIndex() {
  204. return $this->_startIndex;
  205. }
  206. /**
  207. * Set the itemsPerPage property.
  208. *
  209. * @param Zend_Gdata_Extension_OpenSearchItemsPerPage|null $value The
  210. * value for the itemsPerPage property. Use nul to unset.
  211. * @return Zend_Gdata_Feed Provides a fluent interface.
  212. */
  213. function setItemsPerPage($value) {
  214. $this->_itemsPerPage = $value;
  215. return $this;
  216. }
  217. /**
  218. * Get the value of the itemsPerPage property.
  219. *
  220. * @return Zend_Gdata_Extension_OpenSearchItemsPerPage|null The value of
  221. * the itemsPerPage property, or null if unset.
  222. */
  223. function getItemsPerPage() {
  224. return $this->_itemsPerPage;
  225. }
  226. }