/library/Zend/Feed/Writer/Extension/Threading/Renderer/Entry.php

https://bitbucket.org/hamidrezas/melobit · PHP · 145 lines · 71 code · 8 blank · 66 comment · 9 complexity · 11fcea83f6d29759ebb234177f0e7aac 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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id: Entry.php 24594 2012-01-05 21:27:01Z matthew $
  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-2012 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. * 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 entry
  44. *
  45. * @return void
  46. */
  47. public function render()
  48. {
  49. if (strtolower($this->getType()) == 'rss') {
  50. return; // Atom 1.0 only
  51. }
  52. $this->_setCommentLink($this->_dom, $this->_base);
  53. $this->_setCommentFeedLinks($this->_dom, $this->_base);
  54. $this->_setCommentCount($this->_dom, $this->_base);
  55. if ($this->_called) {
  56. $this->_appendNamespaces();
  57. }
  58. }
  59. /**
  60. * Append entry namespaces
  61. *
  62. * @return void
  63. */
  64. protected function _appendNamespaces()
  65. {
  66. $this->getRootElement()->setAttribute('xmlns:thr',
  67. 'http://purl.org/syndication/thread/1.0');
  68. }
  69. /**
  70. * Set comment link
  71. *
  72. * @param DOMDocument $dom
  73. * @param DOMElement $root
  74. * @return void
  75. */
  76. protected function _setCommentLink(DOMDocument $dom, DOMElement $root)
  77. {
  78. $link = $this->getDataContainer()->getCommentLink();
  79. if (!$link) {
  80. return;
  81. }
  82. $clink = $this->_dom->createElement('link');
  83. $clink->setAttribute('rel', 'replies');
  84. $clink->setAttribute('type', 'text/html');
  85. $clink->setAttribute('href', $link);
  86. $count = $this->getDataContainer()->getCommentCount();
  87. if ($count !== null) {
  88. $clink->setAttribute('thr:count', $count);
  89. }
  90. $root->appendChild($clink);
  91. $this->_called = true;
  92. }
  93. /**
  94. * Set comment feed links
  95. *
  96. * @param DOMDocument $dom
  97. * @param DOMElement $root
  98. * @return void
  99. */
  100. protected function _setCommentFeedLinks(DOMDocument $dom, DOMElement $root)
  101. {
  102. $links = $this->getDataContainer()->getCommentFeedLinks();
  103. if (!$links || empty($links)) {
  104. return;
  105. }
  106. foreach ($links as $link) {
  107. $flink = $this->_dom->createElement('link');
  108. $flink->setAttribute('rel', 'replies');
  109. $flink->setAttribute('type', 'application/'. $link['type'] .'+xml');
  110. $flink->setAttribute('href', $link['uri']);
  111. $count = $this->getDataContainer()->getCommentCount();
  112. if ($count !== null) {
  113. $flink->setAttribute('thr:count', $count);
  114. }
  115. $root->appendChild($flink);
  116. $this->_called = true;
  117. }
  118. }
  119. /**
  120. * Set entry comment count
  121. *
  122. * @param DOMDocument $dom
  123. * @param DOMElement $root
  124. * @return void
  125. */
  126. protected function _setCommentCount(DOMDocument $dom, DOMElement $root)
  127. {
  128. $count = $this->getDataContainer()->getCommentCount();
  129. if ($count === null) {
  130. return;
  131. }
  132. $tcount = $this->_dom->createElement('thr:total');
  133. $tcount->nodeValue = $count;
  134. $root->appendChild($tcount);
  135. $this->_called = true;
  136. }
  137. }