Entry.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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-2008 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-2008 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. public function render()
  35. {
  36. if (strtolower($this->getType()) == 'rss') {
  37. return; // Atom 1.0 only
  38. }
  39. $this->_appendNamespaces();
  40. $this->_setCommentLink($this->_dom, $this->_base);
  41. $this->_setCommentFeedLinks($this->_dom, $this->_base);
  42. $this->_setCommentCount($this->_dom, $this->_base);
  43. }
  44. protected function _appendNamespaces()
  45. {
  46. $this->getRootElement()->setAttribute('xmlns:thr',
  47. 'http://purl.org/syndication/thread/1.0');
  48. }
  49. protected function _setCommentLink(DOMDocument $dom, DOMElement $root)
  50. {
  51. $link = $this->getDataContainer()->getCommentLink();
  52. if (!$link) {
  53. return;
  54. }
  55. $clink = $this->_dom->createElement('link');
  56. $clink->setAttribute('rel', 'replies');
  57. $clink->setAttribute('type', 'text/html');
  58. $clink->setAttribute('href', $link);
  59. $count = $this->getDataContainer()->getCommentCount();
  60. if (!$count) {
  61. $count = 0;
  62. }
  63. $clink->setAttribute('thr:count', $count);
  64. $root->appendChild($clink);
  65. }
  66. protected function _setCommentFeedLinks(DOMDocument $dom, DOMElement $root)
  67. {
  68. $links = $this->getDataContainer()->getCommentFeedLinks();
  69. if (!$links || empty($links)) {
  70. return;
  71. }
  72. foreach ($links as $link) {
  73. $flink = $this->_dom->createElement('link');
  74. $flink->setAttribute('rel', 'replies');
  75. $flink->setAttribute('type', 'application/'. $link['type'] .'+xml');
  76. $flink->setAttribute('href', $link['uri']);
  77. $count = $this->getDataContainer()->getCommentCount();
  78. if (!$count) {
  79. $count = 0;
  80. }
  81. $flink->setAttribute('thr:count', $count);
  82. $root->appendChild($flink);
  83. }
  84. }
  85. protected function _setCommentCount(DOMDocument $dom, DOMElement $root)
  86. {
  87. $count = $this->getDataContainer()->getCommentCount();
  88. if (!$count) {
  89. $count = 0;
  90. }
  91. $tcount = $this->_dom->createElement('thr:total');
  92. $tcount->nodeValue = $count;
  93. $root->appendChild($tcount);
  94. }
  95. }