|
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-2010 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 22662 2010-07-24 17:37:36Z mabe $ |
|
20 */ |
|
21 |
|
22 /** |
|
23 * @see Zend_Feed_Writer_Extension_RendererAbstract |
|
24 */ |
|
25 require_once 'Zend/Feed/Writer/Extension/RendererAbstract.php'; |
|
26 |
|
27 /** |
|
28 * @category Zend |
|
29 * @package Zend_Feed_Writer |
|
30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
31 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
32 */ |
|
33 class Zend_Feed_Writer_Extension_Threading_Renderer_Entry |
|
34 extends Zend_Feed_Writer_Extension_RendererAbstract |
|
35 { |
|
36 |
|
37 /** |
|
38 * Set to TRUE if a rendering method actually renders something. This |
|
39 * is used to prevent premature appending of a XML namespace declaration |
|
40 * until an element which requires it is actually appended. |
|
41 * |
|
42 * @var bool |
|
43 */ |
|
44 protected $_called = false; |
|
45 |
|
46 /** |
|
47 * Render entry |
|
48 * |
|
49 * @return void |
|
50 */ |
|
51 public function render() |
|
52 { |
|
53 if (strtolower($this->getType()) == 'rss') { |
|
54 return; // Atom 1.0 only |
|
55 } |
|
56 $this->_setCommentLink($this->_dom, $this->_base); |
|
57 $this->_setCommentFeedLinks($this->_dom, $this->_base); |
|
58 $this->_setCommentCount($this->_dom, $this->_base); |
|
59 if ($this->_called) { |
|
60 $this->_appendNamespaces(); |
|
61 } |
|
62 } |
|
63 |
|
64 /** |
|
65 * Append entry namespaces |
|
66 * |
|
67 * @return void |
|
68 */ |
|
69 protected function _appendNamespaces() |
|
70 { |
|
71 $this->getRootElement()->setAttribute('xmlns:thr', |
|
72 'http://purl.org/syndication/thread/1.0'); |
|
73 } |
|
74 |
|
75 /** |
|
76 * Set comment link |
|
77 * |
|
78 * @param DOMDocument $dom |
|
79 * @param DOMElement $root |
|
80 * @return void |
|
81 */ |
|
82 protected function _setCommentLink(DOMDocument $dom, DOMElement $root) |
|
83 { |
|
84 $link = $this->getDataContainer()->getCommentLink(); |
|
85 if (!$link) { |
|
86 return; |
|
87 } |
|
88 $clink = $this->_dom->createElement('link'); |
|
89 $clink->setAttribute('rel', 'replies'); |
|
90 $clink->setAttribute('type', 'text/html'); |
|
91 $clink->setAttribute('href', $link); |
|
92 $count = $this->getDataContainer()->getCommentCount(); |
|
93 if ($count !== null) { |
|
94 $clink->setAttribute('thr:count', $count); |
|
95 } |
|
96 $root->appendChild($clink); |
|
97 $this->_called = true; |
|
98 } |
|
99 |
|
100 /** |
|
101 * Set comment feed links |
|
102 * |
|
103 * @param DOMDocument $dom |
|
104 * @param DOMElement $root |
|
105 * @return void |
|
106 */ |
|
107 protected function _setCommentFeedLinks(DOMDocument $dom, DOMElement $root) |
|
108 { |
|
109 $links = $this->getDataContainer()->getCommentFeedLinks(); |
|
110 if (!$links || empty($links)) { |
|
111 return; |
|
112 } |
|
113 foreach ($links as $link) { |
|
114 $flink = $this->_dom->createElement('link'); |
|
115 $flink->setAttribute('rel', 'replies'); |
|
116 $flink->setAttribute('type', 'application/'. $link['type'] .'+xml'); |
|
117 $flink->setAttribute('href', $link['uri']); |
|
118 $count = $this->getDataContainer()->getCommentCount(); |
|
119 if ($count !== null) { |
|
120 $flink->setAttribute('thr:count', $count); |
|
121 } |
|
122 $root->appendChild($flink); |
|
123 $this->_called = true; |
|
124 } |
|
125 } |
|
126 |
|
127 /** |
|
128 * Set entry comment count |
|
129 * |
|
130 * @param DOMDocument $dom |
|
131 * @param DOMElement $root |
|
132 * @return void |
|
133 */ |
|
134 protected function _setCommentCount(DOMDocument $dom, DOMElement $root) |
|
135 { |
|
136 $count = $this->getDataContainer()->getCommentCount(); |
|
137 if ($count === null) { |
|
138 return; |
|
139 } |
|
140 $tcount = $this->_dom->createElement('thr:total'); |
|
141 $tcount->nodeValue = $count; |
|
142 $root->appendChild($tcount); |
|
143 $this->_called = true; |
|
144 } |
|
145 } |