Commit 0db517b8 authored by Robert Ricci's avatar Robert Ricci

Add an RSS feed for Emulab news. This allows users to view Emulab news

from RSS aggregators such as Firefox and Google Reader.

This came out of an idea discussed with Chris Alfeld and Jay.
parent 8f87e35d
......@@ -678,7 +678,8 @@ function WRITESIMPLESIDEBAR($menudefs) {
#
# spits out beginning part of page
#
function PAGEBEGINNING( $title, $nobanner = 0, $nocontent = 0 ) {
function PAGEBEGINNING( $title, $nobanner = 0, $nocontent = 0,
$extra_headers = NULL ) {
global $BASEPATH, $TBMAINSITE, $THISHOMEBASE, $ELABINELAB;
global $TBDIR, $WWW;
global $MAINPAGE;
......@@ -716,6 +717,9 @@ function PAGEBEGINNING( $title, $nobanner = 0, $nocontent = 0 ) {
echo "<meta NAME=\"description\" ".
"CONTENT=\"emulab - network emulation testbed home\">\n";
}
if ($extra_headers) {
echo $extra_headers;
}
echo "</head>
<body bgcolor='#FFFFFF'
topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>\n";
......@@ -781,7 +785,7 @@ function FINISHSIDEBAR()
#
# Spit out a vanilla page header.
#
function PAGEHEADER($title, $view = NULL) {
function PAGEHEADER($title, $view = NULL, $extra_headers = NULL) {
global $login_status, $login_uid, $TBBASE, $TBDOCBASE, $THISHOMEBASE;
global $BASEPATH, $SSL_PROTOCOL, $drewheader, $autorefresh;
global $TBMAINSITE;
......@@ -854,7 +858,7 @@ function PAGEHEADER($title, $view = NULL) {
} else {
$nobanner = 0;
}
PAGEBEGINNING( $title, $nobanner, 0 );
PAGEBEGINNING( $title, $nobanner, 0, $extra_headers );
if (!isset($view['hide_sidebar'])) {
WRITESIDEBAR();
}
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
header("Content-type: text/xml");
$query_result=
DBQueryFatal("SELECT subject, author, body, msgid, ".
"date, usr_name, usr_email " .
"FROM webnews ".
"LEFT JOIN users on webnews.author = users.uid " .
"WHERE archived=0 " .
"ORDER BY date DESC " .
"LIMIT 5");
?>
<rss version="2.0"> <channel>
<title><? echo $THISHOMEBASE ?> News</title>
<link><? echo $TBBASE?>/news.php3</link>
<description>News items for <? echo $THISHOMEBASE ?></description>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<managingEditor><? echo $TBOPSEMAIL ?></managingEditor>
<webMaster><? echo $TBOPSEMAIL ?></webMaster>
<?
while ($row = mysql_fetch_array($query_result)) {
$subject = $row[subject];
$timestamp = $row['date'];
$author = $row[author];
$author_name = $row[usr_name];
$body = $row[body];
$msgid = $row[msgid];
# Strip HTML from the body
$stripped = strip_tags($body);
# Try to grab just the first two sentences of the body
preg_match("/^(([^.]+\.){0,2})\s*(.*)/",$stripped,$matches);
if ($matches[1]) {
$summary = $matches[1];
if ($matches[3] != "") {
$summary .= " ... ";
}
} else {
$summary = $stripped;
}
# Have to convert the date/time to RFC822 format
list($date, $hours) = split(' ', $timestamp);
list($year,$month,$day) = split('-',$date);
list($hour,$min,$sec) = split(':',$hours);
$rfc822date = date(r,mktime($hour, $min, $sec, $month, $day, $year));
echo " <item>\n";
echo " <title>$subject</title>\n";
echo " <link>$TBBASE/news.php3?single=$msgid</link>\n";
echo " <guid isPermaLink=\"true\">$TBBASE/news.php3?single=$msgid</guid>\n";
echo " <description>$summary</description>\n";
echo " <pubDate>$rfc822date</pubDate>\n";
echo " <author>$author_name</author>\n";
echo " </item>\n";
}
?>
</channel> </rss>
......@@ -205,26 +205,37 @@ if ($isadmin) {
}
}
else {
PAGEHEADER("News");
# This is so that smart browsers like Firefox can detect the presence
# of an RSS feed.
$rssAuto = "<link rel=\"alternate\" type=\"application/rss+xml\" " .
"title=\"Emulab News\" href=\"$TBDOCBASE/news-rss.php3\" />";
PAGEHEADER("News",NULL,$rssAuto);
}
?>
<table align=center class=stealth border=0>
<tr><td class=stealth align=center><h1>News</h1></td></tr>
<?php
if ($TBMAINSITE) {
if ($TBMAINSITE && !$single) {
echo "<tr><td class=stealth align=center>
<a href = 'doc/changelog.php3'>
(Changelog/Technical Details)</a></td></tr>\n";
}
if (!$single) {
echo "<tr><td class=stealth align=center>
<a href = '$TBDOCBASE/news-rss.php3'>
<img src='rss.png' width=27 height=14 border=0>
RSS Feed
</a></td></tr>";
}
echo "</table>
<br />\n";
# Allow admin caller to flip the archive bit.
$show_archive_clause = "where archived=0";
$show_archive_clause = "archived=0";
if ($isadmin) {
if ($show_archived) {
$show_archive_clause = "";
$show_archive_clause = "1";
echo "<a href='news.php3?show_archived=0'>Hide Archived Messages</a>\n";
}
else {
......@@ -232,6 +243,13 @@ if ($isadmin) {
}
}
# Allow users to view a single message
$which_msgid_clause = "1"; # MySQL will optimize this out
if (isset($single)) {
$which_msgid_clause = "msgid='$single'";
$show_archive_clause = 1;
}
$query_result=
DBQueryFatal("SELECT subject, author, body, msgid, ".
"DATE_FORMAT(date,'%W, %M %e, %Y, %l:%i%p') as prettydate, ".
......@@ -240,7 +258,10 @@ $query_result=
"DATE_FORMAT(archived_date,'%W, %M %e, %Y, %l:%i%p') as ".
" archived_date ".
"FROM webnews ".
"$show_archive_clause ".
"WHERE " .
"$show_archive_clause " .
"AND " .
"$which_msgid_clause ".
"ORDER BY date DESC" );
if (!mysql_num_rows($query_result)) {
......
www/rss.png

194 Bytes

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment