/mvc/layouts/rss
[return to app]1
<?php
2 /**
3 * Generates an RSS 2.0 feed
4 *
5 * String variables are:
6 * $title, $baseUrl, $description (or alias $head['meta']['description'])
7 *
8 * The articles to syndicate should be sent in the $articles array, each article needs a key for:
9 * title, urlname, description, fullname, publishedDateTime
10 */
11
12 if (!isset($baseUrl)) {
13 $baseUrl = 'http://' . get::$config->SITE_DOMAIN;
14 } else if ($baseUrl[(strlen($baseUrl) - 1)] == '/') {
15 $baseUrl = substr($baseUrl, 0, -1);
16 }
17
18 //$logo = $baseUrl . '/images/YOURLOGO.jpg';
19
20 $feedUrl = $baseUrl . '/' . mvc::$controller;
21 if (mvc::$action != 'index') {
22 $feedUrl .= '/' . mvc::$action;
23 }
24 if (isset(mvc::$params[0])) {
25 $feedUrl .= '/' . implode('/', mvc::$params);
26 }
27 $atomFeed = '?feed=atom';
28 if (isset($_GET) && $_GET) {
29 $atomFeed .= '&' . http_build_query($_GET, '', '&');
30 }
31
32 if (!isset($description) && isset($head['meta']['description'])) {
33 $description = $head['meta']['description'];
34 }
35
36 if (!isset($_GET['feed']) || $_GET['feed'] != 'atom') {
37 header('Content-Type: application/rss+xml');
38 echo '<' . '?xml version="1.0" encoding="utf-8"?' . '>
39 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
40 <channel>
41 <title>' . $title . '</title>
42 <description><![CDATA[' . $description . ']]></description>
43 <link>' . $baseUrl . '</link>
44 <lastBuildDate>' . date('r') . '</lastBuildDate>
45 <atom:link href="' . $feedUrl . $atomFeed . '" rel="self" type="application/atom+xml" />';
46 if (isset($logo)) {
47 echo '
48 <image>
49 <url>' . $logo . '</url>
50 <title>' . $title . '</title>
51 <link>' . $baseUrl . '</link>
52 <description>' . $title . '</description>
53 </image>';
54 }
55
56 foreach ($articles as $article) {
57 echo '
58 <item>
59 <title>' . get::htmlentities($article['title']) . '</title>
60 <link>' . $baseUrl . '/' . $article['urlname'] . '</link>
61 <guid>' . $baseUrl . '/' . $article['urlname'] . '</guid>
62 <description><![CDATA[' . get::htmlentities($article['description']) . ']]></description>
63 <dc:creator>' . get::htmlentities($article['fullname']) . '</dc:creator>
64 <pubDate>' . date('r', strtotime($article['publishedDateTime'])) . '</pubDate>
65 </item>';
66 }
67 echo '
68 </channel>
69 </rss>';
70 } else {
71 header('Content-Type: application/atom+xml');
72 echo '<' . '?xml version="1.0" encoding="utf-8"?' . '>
73 <feed xmlns="http://www.w3.org/2005/Atom">
74 <title>' . $title . '</title>
75 <subtitle type="html"><![CDATA[' . $description . ']]></subtitle>
76 <link href="' . $baseUrl . '" />
77 <updated>' . date('Y-m-d\TH:i:s\Z') . '</updated>
78 <id>' . strtolower($feedUrl) . '</id>
79 <link href="' . $feedUrl . $atomFeed . '" rel="self" type="application/atom+xml" />
80 <link href="' . $baseUrl . '" rel="alternate" type="text/html" />';
81 if (isset($logo)) {
82 echo '
83 <logo>' . $logo . '</logo>';
84 }
85
86 foreach ($articles as $article) {
87 echo '
88 <entry>
89 <id>' . strtolower($baseUrl . '/' . $article['urlname']) . '</id>
90 <title>' . get::htmlentities($article['title']) . '</title>
91 <link href="' . $baseUrl . '/' . $article['urlname'] . '" />
92 <summary type="html"><![CDATA[' . get::htmlentities($article['description']) . ']]></summary>
93 <updated>' . date('Y-m-d\TH:i:s\Z', strtotime($article['publishedDateTime'])) . '</updated>
94 <author>
95 <name>' . get::htmlentities($article['fullname']) . '</name>
96 </author>
97 </entry>';
98 }
99 echo '
100 </feed>';
101 }