| | 3 | class RssRenderer |
| | 4 | { |
| | 5 | function render(RssResponse $r) |
| | 6 | { |
| | 7 | header('Content-type: text/xml; charset=UTF-8'); |
| | 8 | |
| | 9 | list($title, $link, $desc) = $r->getChannel(); |
| | 10 | echo '<?xml version="1.0" encoding="UTF-8" ?> |
| | 11 | <rss version="2.0"> |
| | 12 | <channel> |
| | 13 | <title>' . h($title) . '</title> |
| | 14 | <link>' . h($link) . '</link> |
| | 15 | <description>' . h($desc) . '</description> |
| | 16 | '; |
| | 17 | foreach ($r->getItems() as $item) { |
| | 18 | list($title, $desc, $link, $author) = $item; |
| | 19 | echo '<item> |
| | 20 | <title>' . h($title) . '</title> |
| | 21 | <description>' . $this->toCdata($desc) . '</description> |
| | 22 | <link>' . h($link) . '</link> |
| | 23 | <author>' . h($author) . '</author> |
| | 24 | </item> |
| | 25 | '; |
| | 26 | } |
| | 27 | |
| | 28 | echo '</channel> |
| | 29 | </rss> |
| | 30 | '; |
| | 31 | } |
| | 32 | protected function toCdata($v) |
| | 33 | { |
| | 34 | $v = str_replace(']]>', ']]>]]<![CDATA[>', $v); |
| | 35 | return '<![CDATA[' . $v . ']]>'; |
| | 36 | } |
| | 37 | } |