Entry.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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-2009 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. /**
  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-2009 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_Threading_Renderer_Entry
  32. extends Zend_Feed_Writer_Extension_RendererAbstract
  33. {
  34. /**
  35. * Render entry
  36. *
  37. * @return void
  38. */
  39. public function render()
  40. {
  41. if (strtolower($this->getType()) == 'rss') {
  42. return; // Atom 1.0 only
  43. }
  44. $this->_appendNamespaces();
  45. $this->_setCommentLink($this->_dom, $this->_base);
  46. $this->_setCommentFeedLinks($this->_dom, $this->_base);
  47. $this->_setCommentCount($this->_dom, $this->_base);
  48. }
  49. /**
  50. * Append entry namespaces
  51. *
  52. * @return void
  53. */
  54. protected function _appendNamespaces()
  55. {
  56. $this->getRootElement()->setAttribute('xmlns:thr',
  57. 'http://purl.org/syndication/thread/1.0');
  58. }
  59. /**
  60. * Set comment link
  61. *
  62. * @param DOMDocument $dom
  63. * @param DOMElement $root
  64. * @return void
  65. */
  66. protected function _setCommentLink(DOMDocument $dom, DOMElement $root)
  67. {
  68. $link = $this->getDataContainer()->getCommentLink();
  69. if (!$link) {
  70. return;
  71. }
  72. $clink = $this->_dom->createElement('link');
  73. $clink->setAttribute('rel', 'replies');
  74. $clink->setAttribute('type', 'text/html');
  75. $clink->setAttribute('href', $link);
  76. $count = $this->getDataContainer()->getCommentCount();
  77. if (!$count) {
  78. $count = 0;
  79. }
  80. $clink->setAttribute('thr:count', $count);
  81. $root->appendChild($clink);
  82. }
  83. /**
  84. * Set comment feed links
  85. *
  86. * @param DOMDocument $dom
  87. * @param DOMElement $root
  88. * @return void
  89. */
  90. protected function _setCommentFeedLinks(DOMDocument $dom, DOMElement $root)
  91. {
  92. $links = $this->getDataContainer()->getCommentFeedLinks();
  93. if (!$links || empty($links)) {
  94. return;
  95. }
  96. foreach ($links as $link) {
  97. $flink = $this->_dom->createElement('link');
  98. $flink->setAttribute('rel', 'replies');
  99. $flink->setAttribute('type', 'application/'. $link['type'] .'+xml');
  100. $flink->setAttribute('href', $link['uri']);
  101. $count = $this->getDataContainer()->getCommentCount();
  102. if (!$count) {
  103. $count = 0;
  104. }
  105. $flink->setAttribute('thr:count', $count);
  106. $root->appendChild($flink);
  107. }
  108. }
  109. /**
  110. * Set entry comment count
  111. *
  112. * @param DOMDocument $dom
  113. * @param DOMElement $root
  114. * @return void
  115. */
  116. protected function _setCommentCount(DOMDocument $dom, DOMElement $root)
  117. {
  118. $count = $this->getDataContainer()->getCommentCount();
  119. if (!$count) {
  120. $count = 0;
  121. }
  122. $tcount = $this->_dom->createElement('thr:total');
  123. $tcount->nodeValue = $count;
  124. $root->appendChild($tcount);
  125. }
  126. }