Jeremy Newman : rss feed updates
Jeremy Newman
jnewman at winehq.org
Tue Jun 7 16:00:24 CDT 2022
Module: website
Branch: master
Commit: 3ec9ef1e73cffb14c0a4001d6400281fcddaecd2
URL: https://source.winehq.org/git/website.git/?a=commit;h=3ec9ef1e73cffb14c0a4001d6400281fcddaecd2
Author: Jeremy Newman <jnewman at codeweavers.com>
Date: Tue Jun 7 15:59:16 2022 -0500
rss feed updates
* add etag based on last modified
* stream news items
* use RSS 2.0 XML format
---
include/plugins/news.php | 72 +++++++++++++++++++++++++--------------
templates/global/xml/rss.template | 11 ++----
2 files changed, 49 insertions(+), 34 deletions(-)
diff --git a/include/plugins/news.php b/include/plugins/news.php
index e05dfeb6..f305f5b2 100644
--- a/include/plugins/news.php
+++ b/include/plugins/news.php
@@ -98,21 +98,52 @@ switch ($flag)
// RSS view
case 'rss':
-
// get list of news items
$news = get_files($config->news_xml_path."/".$config->lang, $feed);
- $news = array_reverse ($news);
+ $news = array_reverse($news);
- // clear cache and output the rss file
- $rss_rows = "";
- $c = 0;
- foreach ($news as $key => $item)
+ // get last modified
+ $f = get_xml_tags($config->news_xml_path.'/'.$html->lang.'/'.$news[0], array('date'));
+ $last_modified = strtotime($f['date']);
+
+ // if etag set in header, and matches timestamp, send 304
+ if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified || trim($_SERVER['HTTP_IF_NONE_MATCH']) == $last_modified)
+ {
+ header("HTTP/1.1 304 Not Modified");
+ exit();
+ }
+
+ // clear cache
+ $html->clear_buffer();
+
+ // headers
+ header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified)." GMT");
+ header("Expires: ".gmdate("D, d M Y H:i:s", (time()+86400))." GMT");
+ header("Etag: \"{$last_modified}\"");
+ header("Pragma: public");
+ header("Cache-Control: public, max-age=86400");
+ header("Content-Type: application/xml");
+ header('Content-Disposition: inline; filename="winehq_news.xml";');
+
+ // rss header
+ $rss = array(
+ 'rss_title' => "{$config->site_name} News",
+ 'rss_link' => "{$config->base_url}news/rss/",
+ 'rss_img' => "https://media.codeweavers.com/pub/crossover/marketing/og/wine-hq-announcement.png",
+ 'rss_desc' => 'News and information about Wine',
+ 'rss_crt' => '(C) '.$config->site_name.' '.date("Y", time()),
+ 'atom_link' => "https://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}rss"
+ );
+ $rss_head = $html->template('global', 'xml/rss', $rss, 1);
+ list($rss_head, $rss_foot) = preg_split('/\{\$rss_rows\}/', $rss_head, 2);
+ echo $rss_head;
+
+ // rss rows
+ foreach ($news as $c => $item)
{
- $c++;
-
// limit to 10 most recent articles
- if ($c > 10)
- continue;
+ if ($c == 10)
+ break;
// get data from XML file
if (file_exists($config->news_xml_path.'/'.$html->lang.'/'.$item))
@@ -139,25 +170,14 @@ switch ($flag)
'item_guid' => $config->base_url.'?news='.$item,
'item_date' => date("r", strtotime($vars['date']))
);
- $rss_rows .= $html->template('global', 'xml/rss_row', $rss_row, 1);
- $html->set_last_modified($vars['date'], true);
+ echo $html->template('global', 'xml/rss_row', $rss_row, 1);
}
- unset($c);
- $rss = array(
- 'rss_date' => date("r", $top_date),
- 'rss_title' => "{$config->site_name} News",
- 'rss_link' => "{$config->base_url}news/rss/",
- 'rss_img' => "https://media.codeweavers.com/pub/crossover/marketing/og/wine-hq-announcement.png",
- 'rss_desc' => 'News and information about Wine',
- 'rss_crt' => '(C) '.$config->site_name.' '.date("Y", time()),
- 'rss_rows' => $rss_rows
- );
- $html->http_header("application/xml");
- header('Content-Disposition: inline; filename="winehq_news.xml";');
- echo $html->template('global', 'xml/rss', $rss);
+
+ // rss footer
+ echo $rss_foot;
exit();
break;
- // end rss
+ // end rss
// default view
default:
diff --git a/templates/global/xml/rss.template b/templates/global/xml/rss.template
index 92c68a93..60329b89 100644
--- a/templates/global/xml/rss.template
+++ b/templates/global/xml/rss.template
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<?xml-stylesheet href="http://feeds.gawker.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?>
-<?xml-stylesheet href="http://feeds.gawker.com/~d/styles/itemcontent.css" type="text/css" media="screen"?>
-<rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
+<rss version="2.0" xmlns:atom="https://www.w3.org/2005/Atom">
<channel>
<title>{$rss_title}</title>
<image>
@@ -11,12 +9,9 @@
</image>
<link>{$rss_link}</link>
<description>{$rss_desc}</description>
- <language>en</language>
+ <language>{$html_lang}</language>
<copyright>{$rss_crt}</copyright>
- <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="{$rss_link}" type="application/rss+xml" />
- <feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site.</feedburner:browserFriendly>
-
+ <atom:link href="{$atom_link}" rel="self" type="application/rss+xml" />
{$rss_rows}
-
</channel>
</rss>
More information about the wine-cvs
mailing list