bf7cde51a4cb570966463e2d707389790766f995
[yaffs-website] / vendor / zendframework / zend-feed / src / Writer / Extension / Threading / Renderer / Entry.php
1 <?php
2 /**
3  * Zend Framework (http://framework.zend.com/)
4  *
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
8  */
9
10 namespace Zend\Feed\Writer\Extension\Threading\Renderer;
11
12 use DOMDocument;
13 use DOMElement;
14 use Zend\Feed\Writer\Extension;
15
16 /**
17 */
18 class Entry extends Extension\AbstractRenderer
19 {
20     /**
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.
24      *
25      * @var bool
26      */
27     protected $called = false;
28
29     /**
30      * Render entry
31      *
32      * @return void
33      */
34     public function render()
35     {
36         if (strtolower($this->getType()) == 'rss') {
37             return; // Atom 1.0 only
38         }
39         $this->_setCommentLink($this->dom, $this->base);
40         $this->_setCommentFeedLinks($this->dom, $this->base);
41         $this->_setCommentCount($this->dom, $this->base);
42         if ($this->called) {
43             $this->_appendNamespaces();
44         }
45     }
46
47     /**
48      * Append entry namespaces
49      *
50      * @return void
51      */
52     // @codingStandardsIgnoreStart
53     protected function _appendNamespaces()
54     {
55         // @codingStandardsIgnoreEnd
56         $this->getRootElement()->setAttribute(
57             'xmlns:thr',
58             'http://purl.org/syndication/thread/1.0'
59         );
60     }
61
62     /**
63      * Set comment link
64      *
65      * @param  DOMDocument $dom
66      * @param  DOMElement $root
67      * @return void
68      */
69     // @codingStandardsIgnoreStart
70     protected function _setCommentLink(DOMDocument $dom, DOMElement $root)
71     {
72         // @codingStandardsIgnoreEnd
73         $link = $this->getDataContainer()->getCommentLink();
74         if (! $link) {
75             return;
76         }
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);
84         }
85         $root->appendChild($clink);
86         $this->called = true;
87     }
88
89     /**
90      * Set comment feed links
91      *
92      * @param  DOMDocument $dom
93      * @param  DOMElement $root
94      * @return void
95      */
96     // @codingStandardsIgnoreStart
97     protected function _setCommentFeedLinks(DOMDocument $dom, DOMElement $root)
98     {
99         // @codingStandardsIgnoreEnd
100         $links = $this->getDataContainer()->getCommentFeedLinks();
101         if (! $links || empty($links)) {
102             return;
103         }
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);
112             }
113             $root->appendChild($flink);
114             $this->called = true;
115         }
116     }
117
118     /**
119      * Set entry comment count
120      *
121      * @param  DOMDocument $dom
122      * @param  DOMElement $root
123      * @return void
124      */
125     // @codingStandardsIgnoreStart
126     protected function _setCommentCount(DOMDocument $dom, DOMElement $root)
127     {
128         // @codingStandardsIgnoreEnd
129         $count = $this->getDataContainer()->getCommentCount();
130         if ($count === null) {
131             return;
132         }
133         $tcount = $this->dom->createElement('thr:total');
134         $tcount->nodeValue = $count;
135         $root->appendChild($tcount);
136         $this->called = true;
137     }
138 }