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 21 22 23
24 class JDocumentRendererFeedAtom extends JDocumentRenderer
25 {
26 27 28 29 30 31
32 protected $_mime = 'application/atom+xml';
33
34 35 36 37 38 39 40 41 42 43 44 45
46 public function render($name = '', $params = null, $content = null)
47 {
48 $app = JFactory::getApplication();
49
50
51 $tz = new DateTimeZone($app->get('offset'));
52 $now = JFactory::getDate();
53 $now->setTimeZone($tz);
54
55 $data = $this->_doc;
56
57 $url = JUri::getInstance()->toString(array('scheme', 'user', 'pass', 'host', 'port'));
58 $syndicationURL = JRoute::_('&format=feed&type=atom');
59
60 $title = $data->getTitle();
61
62 if ($app->get('sitename_pagetitles', 0) == 1)
63 {
64 $title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $data->getTitle());
65 }
66 elseif ($app->get('sitename_pagetitles', 0) == 2)
67 {
68 $title = JText::sprintf('JPAGETITLE', $data->getTitle(), $app->get('sitename'));
69 }
70
71 $feed_title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
72
73 $feed = "<feed xmlns=\"http://www.w3.org/2005/Atom\" ";
74
75 if ($data->getLanguage() != '')
76 {
77 $feed .= " xml:lang=\"" . $data->getLanguage() . "\"";
78 }
79
80 $feed .= ">\n";
81 $feed .= " <title type=\"text\">" . $feed_title . "</title>\n";
82 $feed .= " <subtitle type=\"text\">" . htmlspecialchars($data->getDescription(), ENT_COMPAT, 'UTF-8') . "</subtitle>\n";
83
84 if (!empty($data->category))
85 {
86 if (is_array($data->category))
87 {
88 foreach ($data->category as $cat)
89 {
90 $feed .= " <category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n";
91 }
92 }
93 else
94 {
95 $feed .= " <category term=\"" . htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8') . "\" />\n";
96 }
97 }
98
99 $feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"" . $url . "\"/>\n";
100 $feed .= " <id>" . str_replace(' ', '%20', $data->getBase()) . "</id>\n";
101 $feed .= " <updated>" . htmlspecialchars($now->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n";
102
103 if ($data->editor != '')
104 {
105 $feed .= " <author>\n";
106 $feed .= " <name>" . $data->editor . "</name>\n";
107
108 if ($data->editorEmail != '')
109 {
110 $feed .= " <email>" . htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
111 }
112
113 $feed .= " </author>\n";
114 }
115
116 $versionHtmlEscaped = '';
117
118 if ($app->get('MetaVersion', 0))
119 {
120 $versionHtmlEscaped = ' version="' . htmlspecialchars(JVersion::RELEASE, ENT_COMPAT, 'UTF-8') . '"';
121 }
122
123 $feed .= " <generator uri=\"https://www.joomla.org\"" . $versionHtmlEscaped . ">" . $data->getGenerator() . "</generator>\n";
124 $feed .= " <link rel=\"self\" type=\"application/atom+xml\" href=\"" . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n";
125
126 for ($i = 0, $count = count($data->items); $i < $count; $i++)
127 {
128 $itemlink = $data->items[$i]->link;
129
130 if (preg_match('/[\x80-\xFF]/', $itemlink))
131 {
132 $itemlink = implode('/', array_map('rawurlencode', explode('/', $itemlink)));
133 }
134
135 $feed .= " <entry>\n";
136 $feed .= " <title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n";
137 $feed .= " <link rel=\"alternate\" type=\"text/html\" href=\"" . $url . $itemlink . "\"/>\n";
138
139 if ($data->items[$i]->date == '')
140 {
141 $data->items[$i]->date = $now->toUnix();
142 }
143
144 $itemDate = JFactory::getDate($data->items[$i]->date);
145 $itemDate->setTimeZone($tz);
146 $feed .= " <published>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</published>\n";
147 $feed .= " <updated>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n";
148
149 if (empty($data->items[$i]->guid))
150 {
151 $itemGuid = str_replace(' ', '%20', $url . $itemlink);
152 }
153 else
154 {
155 $itemGuid = htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8');
156 }
157
158 $feed .= " <id>" . $itemGuid . "</id>\n";
159
160 if ($data->items[$i]->author != '')
161 {
162 $feed .= " <author>\n";
163 $feed .= " <name>" . htmlspecialchars($data->items[$i]->author, ENT_COMPAT, 'UTF-8') . "</name>\n";
164
165 if (!empty($data->items[$i]->authorEmail))
166 {
167 $feed .= " <email>" . htmlspecialchars($data->items[$i]->authorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
168 }
169
170 $feed .= " </author>\n";
171 }
172
173 if (!empty($data->items[$i]->description))
174 {
175 $feed .= " <summary type=\"html\">" . htmlspecialchars($this->_relToAbs($data->items[$i]->description), ENT_COMPAT, 'UTF-8') . "</summary>\n";
176 $feed .= " <content type=\"html\">" . htmlspecialchars($this->_relToAbs($data->items[$i]->description), ENT_COMPAT, 'UTF-8') . "</content>\n";
177 }
178
179 if (!empty($data->items[$i]->category))
180 {
181 if (is_array($data->items[$i]->category))
182 {
183 foreach ($data->items[$i]->category as $cat)
184 {
185 $feed .= " <category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n";
186 }
187 }
188 else
189 {
190 $feed .= " <category term=\"" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "\" />\n";
191 }
192 }
193
194 if ($data->items[$i]->enclosure != null)
195 {
196 $feed .= " <link rel=\"enclosure\" href=\"" . $data->items[$i]->enclosure->url . "\" type=\""
197 . $data->items[$i]->enclosure->type . "\" length=\"" . $data->items[$i]->enclosure->length . "\" />\n";
198 }
199
200 $feed .= " </entry>\n";
201 }
202
203 $feed .= "</feed>\n";
204
205 return $feed;
206 }
207 }
208