Atom.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_Writer
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /** @see Zend_Feed_Writer_Feed */
  22. require_once 'Zend/Feed/Writer/Feed.php';
  23. /** @see Zend_Version */
  24. require_once 'Zend/Version.php';
  25. /** @see Zend_Feed_Writer_Renderer_RendererInterface */
  26. require_once 'Zend/Feed/Writer/Renderer/RendererInterface.php';
  27. /** @see Zend_Feed_Writer_Renderer_Entry_Atom */
  28. require_once 'Zend/Feed/Writer/Renderer/Entry/Atom.php';
  29. /** @see Zend_Feed_Writer_Renderer_Entry_Atom_Deleted */
  30. require_once 'Zend/Feed/Writer/Renderer/Entry/Atom/Deleted.php';
  31. /** @see Zend_Feed_Writer_Renderer_RendererAbstract */
  32. require_once 'Zend/Feed/Writer/Renderer/RendererAbstract.php';
  33. require_once 'Zend/Feed/Writer/Renderer/Feed/Atom/AtomAbstract.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Feed_Writer
  37. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Feed_Writer_Renderer_Feed_Atom
  41. extends Zend_Feed_Writer_Renderer_Feed_Atom_AtomAbstract
  42. implements Zend_Feed_Writer_Renderer_RendererInterface
  43. {
  44. /**
  45. * Constructor
  46. *
  47. * @param Zend_Feed_Writer_Feed $container
  48. * @return void
  49. */
  50. public function __construct (Zend_Feed_Writer_Feed $container)
  51. {
  52. parent::__construct($container);
  53. }
  54. /**
  55. * Render Atom feed
  56. *
  57. * @return Zend_Feed_Writer_Renderer_Feed_Atom
  58. */
  59. public function render()
  60. {
  61. if (!$this->_container->getEncoding()) {
  62. $this->_container->setEncoding('UTF-8');
  63. }
  64. $this->_dom = new DOMDocument('1.0', $this->_container->getEncoding());
  65. $this->_dom->formatOutput = true;
  66. $root = $this->_dom->createElementNS(
  67. Zend_Feed_Writer::NAMESPACE_ATOM_10, 'feed'
  68. );
  69. $this->setRootElement($root);
  70. $this->_dom->appendChild($root);
  71. $this->_setLanguage($this->_dom, $root);
  72. $this->_setBaseUrl($this->_dom, $root);
  73. $this->_setTitle($this->_dom, $root);
  74. $this->_setDescription($this->_dom, $root);
  75. $this->_setImage($this->_dom, $root);
  76. $this->_setIcon($this->_dom, $root);
  77. $this->_setDateCreated($this->_dom, $root);
  78. $this->_setDateModified($this->_dom, $root);
  79. $this->_setGenerator($this->_dom, $root);
  80. $this->_setLink($this->_dom, $root);
  81. $this->_setFeedLinks($this->_dom, $root);
  82. $this->_setId($this->_dom, $root);
  83. $this->_setAuthors($this->_dom, $root);
  84. $this->_setCopyright($this->_dom, $root);
  85. $this->_setCategories($this->_dom, $root);
  86. $this->_setHubs($this->_dom, $root);
  87. foreach ($this->_extensions as $ext) {
  88. $ext->setType($this->getType());
  89. $ext->setRootElement($this->getRootElement());
  90. $ext->setDomDocument($this->getDomDocument(), $root);
  91. $ext->render();
  92. }
  93. foreach ($this->_container as $entry) {
  94. if ($this->getDataContainer()->getEncoding()) {
  95. $entry->setEncoding($this->getDataContainer()->getEncoding());
  96. }
  97. if ($entry instanceof Zend_Feed_Writer_Entry) {
  98. $renderer = new Zend_Feed_Writer_Renderer_Entry_Atom($entry);
  99. } else {
  100. if (!$this->_dom->documentElement->hasAttribute('xmlns:at')) {
  101. $this->_dom->documentElement->setAttribute(
  102. 'xmlns:at', 'http://purl.org/atompub/tombstones/1.0'
  103. );
  104. }
  105. $renderer = new Zend_Feed_Writer_Renderer_Entry_Atom_Deleted($entry);
  106. }
  107. if ($this->_ignoreExceptions === true) {
  108. $renderer->ignoreExceptions();
  109. }
  110. $renderer->setType($this->getType());
  111. $renderer->setRootElement($this->_dom->documentElement);
  112. $renderer->render();
  113. $element = $renderer->getElement();
  114. $imported = $this->_dom->importNode($element, true);
  115. $root->appendChild($imported);
  116. }
  117. return $this;
  118. }
  119. }