10 defined(
'JPATH_PLATFORM') or die;
28 protected $_mime =
"application/rss+xml";
42 public function render($name =
'', $params = null, $content = null)
47 $tz =
new DateTimeZone($app->getCfg(
'offset'));
49 $now->setTimeZone($tz);
54 $url = $uri->toString(array(
'scheme',
'user',
'pass',
'host',
'port'));
55 $syndicationURL =
JRoute::_(
'&format=feed&type=rss');
57 if ($app->getCfg(
'sitename_pagetitles', 0) == 1)
59 $title =
JText::sprintf(
'JPAGETITLE', $app->getCfg(
'sitename'), $data->title);
61 elseif ($app->getCfg(
'sitename_pagetitles', 0) == 2)
63 $title =
JText::sprintf(
'JPAGETITLE', $data->title, $app->getCfg(
'sitename'));
67 $title = $data->title;
70 $feed_title = htmlspecialchars($title, ENT_COMPAT,
'UTF-8');
72 $feed =
"<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
73 $feed .=
" <channel>\n";
74 $feed .=
" <title>" . $feed_title .
"</title>\n";
75 $feed .=
" <description><![CDATA[" . $data->description .
"]]></description>\n";
76 $feed .=
" <link>" . str_replace(
' ',
'%20', $url . $data->link) .
"</link>\n";
77 $feed .=
" <lastBuildDate>" . htmlspecialchars($now->toRFC822(
true), ENT_COMPAT,
'UTF-8') .
"</lastBuildDate>\n";
78 $feed .=
" <generator>" . $data->getGenerator() .
"</generator>\n";
79 $feed .=
' <atom:link rel="self" type="application/rss+xml" href="' . str_replace(
' ',
'%20', $url . $syndicationURL) .
"\"/>\n";
81 if ($data->image != null)
83 $feed .=
" <image>\n";
84 $feed .=
" <url>" . $data->image->url .
"</url>\n";
85 $feed .=
" <title>" . htmlspecialchars($data->image->title, ENT_COMPAT,
'UTF-8') .
"</title>\n";
86 $feed .=
" <link>" . str_replace(
' ',
'%20', $data->image->link) .
"</link>\n";
87 if ($data->image->width !=
"")
89 $feed .=
" <width>" . $data->image->width .
"</width>\n";
91 if ($data->image->height !=
"")
93 $feed .=
" <height>" . $data->image->height .
"</height>\n";
95 if ($data->image->description !=
"")
97 $feed .=
" <description><![CDATA[" . $data->image->description .
"]]></description>\n";
99 $feed .=
" </image>\n";
101 if ($data->language !=
"")
103 $feed .=
" <language>" . $data->language .
"</language>\n";
105 if ($data->copyright !=
"")
107 $feed .=
" <copyright>" . htmlspecialchars($data->copyright, ENT_COMPAT,
'UTF-8') .
"</copyright>\n";
109 if ($data->editorEmail !=
"")
111 $feed .=
" <managingEditor>" . htmlspecialchars($data->editorEmail, ENT_COMPAT,
'UTF-8') .
' ('
112 . htmlspecialchars($data->editor, ENT_COMPAT,
'UTF-8') .
")</managingEditor>\n";
114 if ($data->webmaster !=
"")
116 $feed .=
" <webMaster>" . htmlspecialchars($data->webmaster, ENT_COMPAT,
'UTF-8') .
"</webMaster>\n";
118 if ($data->pubDate !=
"")
121 $pubDate->setTimeZone($tz);
122 $feed .=
" <pubDate>" . htmlspecialchars($pubDate->toRFC822(
true), ENT_COMPAT,
'UTF-8') .
"</pubDate>\n";
124 if (empty($data->category) ===
false)
126 if (is_array($data->category))
128 foreach ($data->category as $cat)
130 $feed .=
" <category>" . htmlspecialchars($cat, ENT_COMPAT,
'UTF-8') .
"</category>\n";
135 $feed .=
" <category>" . htmlspecialchars($data->category, ENT_COMPAT,
'UTF-8') .
"</category>\n";
138 if ($data->docs !=
"")
140 $feed .=
" <docs>" . htmlspecialchars($data->docs, ENT_COMPAT,
'UTF-8') .
"</docs>\n";
142 if ($data->ttl !=
"")
144 $feed .=
" <ttl>" . htmlspecialchars($data->ttl, ENT_COMPAT,
'UTF-8') .
"</ttl>\n";
146 if ($data->rating !=
"")
148 $feed .=
" <rating>" . htmlspecialchars($data->rating, ENT_COMPAT,
'UTF-8') .
"</rating>\n";
150 if ($data->skipHours !=
"")
152 $feed .=
" <skipHours>" . htmlspecialchars($data->skipHours, ENT_COMPAT,
'UTF-8') .
"</skipHours>\n";
154 if ($data->skipDays !=
"")
156 $feed .=
" <skipDays>" . htmlspecialchars($data->skipDays, ENT_COMPAT,
'UTF-8') .
"</skipDays>\n";
159 for ($i = 0, $count = count($data->items); $i < $count; $i++)
161 if ((strpos($data->items[$i]->link,
'http://') ===
false) && (strpos($data->items[$i]->link,
'https://') ===
false))
163 $data->items[$i]->link = str_replace(
' ',
'%20', $url . $data->items[$i]->link);
165 $feed .=
" <item>\n";
166 $feed .=
" <title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT,
'UTF-8') .
"</title>\n";
167 $feed .=
" <link>" . str_replace(
' ',
'%20', $data->items[$i]->link) .
"</link>\n";
169 if (empty($data->items[$i]->guid) ===
true)
171 $feed .=
" <guid isPermaLink=\"true\">" . str_replace(
' ',
'%20', $data->items[$i]->link) .
"</guid>\n";
175 $feed .=
" <guid isPermaLink=\"false\">" . htmlspecialchars($data->items[$i]->guid, ENT_COMPAT,
'UTF-8') .
"</guid>\n";
178 $feed .=
" <description><![CDATA[" . $this->_relToAbs($data->items[$i]->description) .
"]]></description>\n";
180 if ($data->items[$i]->authorEmail !=
"")
183 . htmlspecialchars($data->items[$i]->authorEmail .
' (' . $data->items[$i]->author .
')', ENT_COMPAT,
'UTF-8') .
"</author>\n";
193 if (empty($data->items[$i]->category) ===
false)
195 if (is_array($data->items[$i]->category))
197 foreach ($data->items[$i]->category as $cat)
199 $feed .=
" <category>" . htmlspecialchars($cat, ENT_COMPAT,
'UTF-8') .
"</category>\n";
204 $feed .=
" <category>" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT,
'UTF-8') .
"</category>\n";
207 if ($data->items[$i]->comments !=
"")
209 $feed .=
" <comments>" . htmlspecialchars($data->items[$i]->comments, ENT_COMPAT,
'UTF-8') .
"</comments>\n";
211 if ($data->items[$i]->date !=
"")
214 $itemDate->setTimeZone($tz);
215 $feed .=
" <pubDate>" . htmlspecialchars($itemDate->toRFC822(
true), ENT_COMPAT,
'UTF-8') .
"</pubDate>\n";
217 if ($data->items[$i]->enclosure != null)
219 $feed .=
" <enclosure url=\"";
220 $feed .= $data->items[$i]->enclosure->url;
221 $feed .=
"\" length=\"";
222 $feed .= $data->items[$i]->enclosure->length;
223 $feed .=
"\" type=\"";
224 $feed .= $data->items[$i]->enclosure->type;
228 $feed .=
" </item>\n";
230 $feed .=
" </channel>\n";
244 public function _relToAbs($text)
247 $text = preg_replace(
"/(href|src)=\"(?!http|ftp|https|mailto|data)([^\"]*)\"/",
"$1=\"$base\$2\"", $text);