1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 13 14 15 16 17 18 19
20 class extends JDocumentRenderer
21 {
22 23 24 25 26 27
28 protected $_mime = 'application/rss+xml';
29
30 31 32 33 34 35 36 37 38 39 40 41
42 public function render($name = '', $params = null, $content = null)
43 {
44 $app = JFactory::getApplication();
45
46
47 $tz = new DateTimeZone($app->get('offset'));
48 $now = JFactory::getDate();
49 $now->setTimeZone($tz);
50
51 $data = $this->_doc;
52
53 $url = JUri::getInstance()->toString(array('scheme', 'user', 'pass', 'host', 'port'));
54 $syndicationURL = JRoute::_('&format=feed&type=rss');
55
56 $title = $data->getTitle();
57
58 if ($app->get('sitename_pagetitles', 0) == 1)
59 {
60 $title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $data->getTitle());
61 }
62 elseif ($app->get('sitename_pagetitles', 0) == 2)
63 {
64 $title = JText::sprintf('JPAGETITLE', $data->getTitle(), $app->get('sitename'));
65 }
66
67 $feed_title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
68
69 $datalink = $data->getLink();
70
71 if (preg_match('/[\x80-\xFF]/', $datalink))
72 {
73 $datalink = implode('/', array_map('rawurlencode', explode('/', $datalink)));
74 }
75
76 $feed = "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
77 $feed .= " <channel>\n";
78 $feed .= " <title>" . $feed_title . "</title>\n";
79 $feed .= " <description><![CDATA[" . $data->getDescription() . "]]></description>\n";
80 $feed .= " <link>" . str_replace(' ', '%20', $url . $datalink) . "</link>\n";
81 $feed .= " <lastBuildDate>" . htmlspecialchars($now->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</lastBuildDate>\n";
82 $feed .= " <generator>" . $data->getGenerator() . "</generator>\n";
83 $feed .= " <atom:link rel=\"self\" type=\"application/rss+xml\" href=\"" . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n";
84
85 if ($data->image != null)
86 {
87 $feed .= " <image>\n";
88 $feed .= " <url>" . $data->image->url . "</url>\n";
89 $feed .= " <title>" . htmlspecialchars($data->image->title, ENT_COMPAT, 'UTF-8') . "</title>\n";
90 $feed .= " <link>" . str_replace(' ', '%20', $data->image->link) . "</link>\n";
91
92 if ($data->image->width != '')
93 {
94 $feed .= " <width>" . $data->image->width . "</width>\n";
95 }
96
97 if ($data->image->height != '')
98 {
99 $feed .= " <height>" . $data->image->height . "</height>\n";
100 }
101
102 if ($data->image->description != '')
103 {
104 $feed .= " <description><![CDATA[" . $data->image->description . "]]></description>\n";
105 }
106
107 $feed .= " </image>\n";
108 }
109
110 if ($data->getLanguage() !== '')
111 {
112 $feed .= " <language>" . $data->getLanguage() . "</language>\n";
113 }
114
115 if ($data->copyright != '')
116 {
117 $feed .= " <copyright>" . htmlspecialchars($data->copyright, ENT_COMPAT, 'UTF-8') . "</copyright>\n";
118 }
119
120 if ($data->editorEmail != '')
121 {
122 $feed .= " <managingEditor>" . htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8') . ' ('
123 . htmlspecialchars($data->editor, ENT_COMPAT, 'UTF-8') . ")</managingEditor>\n";
124 }
125
126 if ($data->webmaster != '')
127 {
128 $feed .= " <webMaster>" . htmlspecialchars($data->webmaster, ENT_COMPAT, 'UTF-8') . "</webMaster>\n";
129 }
130
131 if ($data->pubDate != '')
132 {
133 $pubDate = JFactory::getDate($data->pubDate);
134 $pubDate->setTimeZone($tz);
135 $feed .= " <pubDate>" . htmlspecialchars($pubDate->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</pubDate>\n";
136 }
137
138 if (!empty($data->category))
139 {
140 if (is_array($data->category))
141 {
142 foreach ($data->category as $cat)
143 {
144 $feed .= " <category>" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "</category>\n";
145 }
146 }
147 else
148 {
149 $feed .= " <category>" . htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8') . "</category>\n";
150 }
151 }
152
153 if ($data->docs != '')
154 {
155 $feed .= " <docs>" . htmlspecialchars($data->docs, ENT_COMPAT, 'UTF-8') . "</docs>\n";
156 }
157
158 if ($data->ttl != '')
159 {
160 $feed .= " <ttl>" . htmlspecialchars($data->ttl, ENT_COMPAT, 'UTF-8') . "</ttl>\n";
161 }
162
163 if ($data->rating != '')
164 {
165 $feed .= " <rating>" . htmlspecialchars($data->rating, ENT_COMPAT, 'UTF-8') . "</rating>\n";
166 }
167
168 if ($data->skipHours != '')
169 {
170 $feed .= " <skipHours>" . htmlspecialchars($data->skipHours, ENT_COMPAT, 'UTF-8') . "</skipHours>\n";
171 }
172
173 if ($data->skipDays != '')
174 {
175 $feed .= " <skipDays>" . htmlspecialchars($data->skipDays, ENT_COMPAT, 'UTF-8') . "</skipDays>\n";
176 }
177
178 for ($i = 0, $count = count($data->items); $i < $count; $i++)
179 {
180 $itemlink = $data->items[$i]->link;
181
182 if (preg_match('/[\x80-\xFF]/', $itemlink))
183 {
184 $itemlink = implode('/', array_map('rawurlencode', explode('/', $itemlink)));
185 }
186
187 if ((strpos($itemlink, 'http://') === false) && (strpos($itemlink, 'https://') === false))
188 {
189 $itemlink = str_replace(' ', '%20', $url . $itemlink);
190 }
191
192 $feed .= " <item>\n";
193 $feed .= " <title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n";
194 $feed .= " <link>" . str_replace(' ', '%20', $itemlink) . "</link>\n";
195
196 if (empty($data->items[$i]->guid))
197 {
198 $feed .= " <guid isPermaLink=\"true\">" . str_replace(' ', '%20', $itemlink) . "</guid>\n";
199 }
200 else
201 {
202 $feed .= " <guid isPermaLink=\"false\">" . htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8') . "</guid>\n";
203 }
204
205 $feed .= " <description><![CDATA[" . $this->_relToAbs($data->items[$i]->description) . "]]></description>\n";
206
207 if ($data->items[$i]->authorEmail != '')
208 {
209 $feed .= ' <author>'
210 . htmlspecialchars($data->items[$i]->authorEmail . ' (' . $data->items[$i]->author . ')', ENT_COMPAT, 'UTF-8') . "</author>\n";
211 }
212
213 214 215 216 217 218 219
220
221 if (empty($data->items[$i]->category) === false)
222 {
223 if (is_array($data->items[$i]->category))
224 {
225 foreach ($data->items[$i]->category as $cat)
226 {
227 $feed .= " <category>" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "</category>\n";
228 }
229 }
230 else
231 {
232 $feed .= " <category>" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "</category>\n";
233 }
234 }
235
236 if ($data->items[$i]->comments != '')
237 {
238 $feed .= " <comments>" . htmlspecialchars($data->items[$i]->comments, ENT_COMPAT, 'UTF-8') . "</comments>\n";
239 }
240
241 if ($data->items[$i]->date != '')
242 {
243 $itemDate = JFactory::getDate($data->items[$i]->date);
244 $itemDate->setTimeZone($tz);
245 $feed .= " <pubDate>" . htmlspecialchars($itemDate->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</pubDate>\n";
246 }
247
248 if ($data->items[$i]->enclosure != null)
249 {
250 $feed .= " <enclosure url=\"";
251 $feed .= $data->items[$i]->enclosure->url;
252 $feed .= "\" length=\"";
253 $feed .= $data->items[$i]->enclosure->length;
254 $feed .= "\" type=\"";
255 $feed .= $data->items[$i]->enclosure->type;
256 $feed .= "\"/>\n";
257 }
258
259 $feed .= " </item>\n";
260 }
261
262 $feed .= " </channel>\n";
263 $feed .= "</rss>\n";
264
265 return $feed;
266 }
267 }
268