mirror of
https://git.code.sf.net/p/quake/website
synced 2025-01-31 04:30:44 +00:00
Generate a basic RSS feed from the news
It's for Ohloh.
This commit is contained in:
parent
e08e580e9a
commit
4e36640c23
3 changed files with 69 additions and 10 deletions
10
lib/date.inc
10
lib/date.inc
|
@ -37,7 +37,15 @@
|
|||
|
||||
return substr ($date, 3) . ' ' . $shortMonths[substr ($date, 1, 2)];
|
||||
}
|
||||
|
||||
|
||||
function RFCDateFromSQLDateTime ($sqlDateTime)
|
||||
{
|
||||
$dtime = explode ( ' ', $sqlDateTime);
|
||||
$date = explode ( '-', $dtime[0]);
|
||||
$time = explode ( ':', $dtime[1]);
|
||||
return strftime ( '%a, %d %b %Y %R GMT', mktime ($time[0], $time[1], $time[2], $date[1], $date[2], $date[0]));
|
||||
}
|
||||
|
||||
function dateFromSQLDateTime ($sqlDateTime)
|
||||
{
|
||||
$time = explode ( ' ', $sqlDateTime);
|
||||
|
|
49
lib/news.inc
49
lib/news.inc
|
@ -37,6 +37,10 @@ $createQuery="CREATE TABLE news_main ("
|
|||
|
||||
function formatNews ($date, $user, $text)
|
||||
{
|
||||
need ('date');
|
||||
|
||||
$date = dateFromSQLDateTime ($date);
|
||||
|
||||
return "<DL>\n"
|
||||
.' <DT>'
|
||||
. "<EM>Posted on </EM>$date<EM> by </EM><STRONG>$user</STRONG>"
|
||||
|
@ -45,12 +49,29 @@ function formatNews ($date, $user, $text)
|
|||
."</DL>\n";
|
||||
}
|
||||
|
||||
|
||||
function formatNewsArray ($a)
|
||||
function formatNewsRSS ($date, $user, $text)
|
||||
{
|
||||
need ('date');
|
||||
|
||||
return formatNews (dateFromSQLDateTime ($a['n_date']), $a['n_user'], stripSlashes($a['n_news']));
|
||||
$rfcDate = RFCDateFromSQLDateTime ($date);
|
||||
$humanDate = dateFromSQLDateTime ($date);
|
||||
|
||||
return "<item><title>QF News for $humanDate (posted by $user)</title>\n"
|
||||
."<link>http://www.quakeforge.net/</link>\n"
|
||||
."<pubDate>$rfcDate</pubDate>"
|
||||
."<author>$user</author>"
|
||||
."<description><![CDATA[$text]]></description>"
|
||||
."</item>\n";
|
||||
}
|
||||
|
||||
function formatNewsArray ($a)
|
||||
{
|
||||
return formatNews ($a['n_date'], $a['n_user'], stripSlashes($a['n_news']));
|
||||
}
|
||||
|
||||
function formatNewsArrayRSS ($a)
|
||||
{
|
||||
return formatNewsRSS ($a['n_date'], $a['n_user'], stripSlashes($a['n_news']));
|
||||
}
|
||||
|
||||
|
||||
|
@ -79,17 +100,27 @@ function latestNews ($max=5)
|
|||
|
||||
function printLatestNews ($max=5)
|
||||
{
|
||||
$filler = date ('d M Y');
|
||||
$filler = date ('d-M-Y H:i:s');
|
||||
$entries = latestNews ($max);
|
||||
global $newsFormat;
|
||||
|
||||
if ($newsFormat && strtolower($newsFormat) == 'rss') {
|
||||
$fmt = 'formatNewsRSS';
|
||||
} else {
|
||||
$fmt = 'formatNews';
|
||||
}
|
||||
|
||||
if ($entries === true) { // success, but no data
|
||||
printNews ($filler, 'Web Server', 'Nobody has posted news yet, so I got nothing to say right now.');
|
||||
echo $fmt($filler, 'Web Server', 'Nobody has posted news yet, so I got nothing to say right now.');
|
||||
} elseif ($entries === false) { // bad query
|
||||
printNews ($filler, 'Web Server', 'Got an error while finding news. Bug a project administrator, eh?');
|
||||
echo $fmt($filler, 'Web Server', 'Got an error while finding news. Bug a project administrator, eh?');
|
||||
} elseif ($entries === null) { // boom
|
||||
printNews ($filler, 'Web Server', 'Couldn\'t connect to the project news server...Sorry.');
|
||||
} else for ($i = 0; $i < count ($entries); $i++) {
|
||||
printNewsArray ($entries[$i]);
|
||||
echo $fmt($filler, 'Web Server', 'Couldn\'t connect to the project news server...Sorry.');
|
||||
} else {
|
||||
for ($i = 0; $i < count ($entries); $i++) {
|
||||
echo $fmt($entries[$i]['n_date'], $entries[$i]['n_user'],
|
||||
stripSlashes($entries[$i]['n_news']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
20
rss.php
Normal file
20
rss.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?
|
||||
define ('siteHome', "/home/project-web/quake/htdocs");
|
||||
require siteHome . "/parts/library.inc"; // Load function library
|
||||
|
||||
header ("Content-Type: text/xml");
|
||||
echo('<?xml version="1.0" encoding="utf-8"?>' . "\n");
|
||||
?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>QuakeForge News</title>
|
||||
<description>Latest QuakeForge Project news</description>
|
||||
<link>http://www.quakeforge.net/</link>
|
||||
<copyright>Copyright 1999-2011 Contributors of the QuakeForge Project</copyright>
|
||||
<?
|
||||
$newsFormat = "RSS";
|
||||
|
||||
need ('news');
|
||||
printLatestNews (5);
|
||||
?>
|
||||
</rss>
|
Loading…
Reference in a new issue