3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Feed\Writer\Extension\Threading\Renderer;
14 use Zend\Feed\Writer\Extension;
18 class Entry extends Extension\AbstractRenderer
21 * Set to TRUE if a rendering method actually renders something. This
22 * is used to prevent premature appending of a XML namespace declaration
23 * until an element which requires it is actually appended.
27 protected $called = false;
34 public function render()
36 if (strtolower($this->getType()) == 'rss') {
37 return; // Atom 1.0 only
39 $this->_setCommentLink($this->dom, $this->base);
40 $this->_setCommentFeedLinks($this->dom, $this->base);
41 $this->_setCommentCount($this->dom, $this->base);
43 $this->_appendNamespaces();
48 * Append entry namespaces
52 // @codingStandardsIgnoreStart
53 protected function _appendNamespaces()
55 // @codingStandardsIgnoreEnd
56 $this->getRootElement()->setAttribute(
58 'http://purl.org/syndication/thread/1.0'
65 * @param DOMDocument $dom
66 * @param DOMElement $root
69 // @codingStandardsIgnoreStart
70 protected function _setCommentLink(DOMDocument $dom, DOMElement $root)
72 // @codingStandardsIgnoreEnd
73 $link = $this->getDataContainer()->getCommentLink();
77 $clink = $this->dom->createElement('link');
78 $clink->setAttribute('rel', 'replies');
79 $clink->setAttribute('type', 'text/html');
80 $clink->setAttribute('href', $link);
81 $count = $this->getDataContainer()->getCommentCount();
82 if ($count !== null) {
83 $clink->setAttribute('thr:count', $count);
85 $root->appendChild($clink);
90 * Set comment feed links
92 * @param DOMDocument $dom
93 * @param DOMElement $root
96 // @codingStandardsIgnoreStart
97 protected function _setCommentFeedLinks(DOMDocument $dom, DOMElement $root)
99 // @codingStandardsIgnoreEnd
100 $links = $this->getDataContainer()->getCommentFeedLinks();
101 if (! $links || empty($links)) {
104 foreach ($links as $link) {
105 $flink = $this->dom->createElement('link');
106 $flink->setAttribute('rel', 'replies');
107 $flink->setAttribute('type', 'application/' . $link['type'] . '+xml');
108 $flink->setAttribute('href', $link['uri']);
109 $count = $this->getDataContainer()->getCommentCount();
110 if ($count !== null) {
111 $flink->setAttribute('thr:count', $count);
113 $root->appendChild($flink);
114 $this->called = true;
119 * Set entry comment count
121 * @param DOMDocument $dom
122 * @param DOMElement $root
125 // @codingStandardsIgnoreStart
126 protected function _setCommentCount(DOMDocument $dom, DOMElement $root)
128 // @codingStandardsIgnoreEnd
129 $count = $this->getDataContainer()->getCommentCount();
130 if ($count === null) {
133 $tcount = $this->dom->createElement('thr:total');
134 $tcount->nodeValue = $count;
135 $root->appendChild($tcount);
136 $this->called = true;