PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/application/libraries/Zend/Feed/Writer/Extension/Atom/Renderer/Feed.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 123 lines | 53 code | 7 blank | 63 comment | 7 complexity | 87f97a58c5b92235e3e60e03ab0db0e3 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_Writer
  17. * @copyright Copyright (c) 2005-2011 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 23775 2011-03-01 17:25:24Z ralph $
  20. */
  21. /**
  22. * @see Zend_Feed_Writer_Extension_RendererAbstract
  23. */
  24. require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Feed_Writer
  28. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Feed_Writer_Extension_Atom_Renderer_Feed
  32. extends Zend_Feed_Writer_Extension_RendererAbstract
  33. {
  34. /**
  35. * Set to TRUE if a rendering method actually renders something. This
  36. * is used to prevent premature appending of a XML namespace declaration
  37. * until an element which requires it is actually appended.
  38. *
  39. * @var bool
  40. */
  41. protected $_called = false;
  42. /**
  43. * Render feed
  44. *
  45. * @return void
  46. */
  47. public function render()
  48. {
  49. /**
  50. * RSS 2.0 only. Used mainly to include Atom links and
  51. * Pubsubhubbub Hub endpoint URIs under the Atom namespace
  52. */
  53. if (strtolower($this->getType()) == 'atom') {
  54. return;
  55. }
  56. $this->_setFeedLinks($this->_dom, $this->_base);
  57. $this->_setHubs($this->_dom, $this->_base);
  58. if ($this->_called) {
  59. $this->_appendNamespaces();
  60. }
  61. }
  62. /**
  63. * Append namespaces to root element of feed
  64. *
  65. * @return void
  66. */
  67. protected function _appendNamespaces()
  68. {
  69. $this->getRootElement()->setAttribute('xmlns:atom',
  70. 'http://www.w3.org/2005/Atom');
  71. }
  72. /**
  73. * Set feed link elements
  74. *
  75. * @param DOMDocument $dom
  76. * @param DOMElement $root
  77. * @return void
  78. */
  79. protected function _setFeedLinks(DOMDocument $dom, DOMElement $root)
  80. {
  81. $flinks = $this->getDataContainer()->getFeedLinks();
  82. if(!$flinks || empty($flinks)) {
  83. return;
  84. }
  85. foreach ($flinks as $type => $href) {
  86. $mime = 'application/' . strtolower($type) . '+xml';
  87. $flink = $dom->createElement('atom:link');
  88. $root->appendChild($flink);
  89. $flink->setAttribute('rel', 'self');
  90. $flink->setAttribute('type', $mime);
  91. $flink->setAttribute('href', $href);
  92. }
  93. $this->_called = true;
  94. }
  95. /**
  96. * Set PuSH hubs
  97. *
  98. * @param DOMDocument $dom
  99. * @param DOMElement $root
  100. * @return void
  101. */
  102. protected function _setHubs(DOMDocument $dom, DOMElement $root)
  103. {
  104. $hubs = $this->getDataContainer()->getHubs();
  105. if (!$hubs || empty($hubs)) {
  106. return;
  107. }
  108. foreach ($hubs as $hubUrl) {
  109. $hub = $dom->createElement('atom:link');
  110. $hub->setAttribute('rel', 'hub');
  111. $hub->setAttribute('href', $hubUrl);
  112. $root->appendChild($hub);
  113. }
  114. $this->_called = true;
  115. }
  116. }