news-rss.php3 2.41 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2005, 2007 University of Utah and the Flux Group.
5 6 7 8 9 10 11 12
# All rights reserved.
#
include("defs.php3");

header("Content-type: text/xml");

$query_result=
    DBQueryFatal("SELECT subject, author, body, msgid, ".
13
    		 "date, usr_name " .
14 15 16 17 18 19 20 21 22 23 24 25
		 "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>
26 27 28
    <managingEditor><? echo $TBMAILADDR_OPS ?></managingEditor>
    <webMaster><? echo $TBMAILADDR_OPS ?></webMaster>
    <pubDate><? echo date("r"); ?></pubDate>
29
<?
30 31

$first = 1;
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
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));

60 61 62 63 64 65 66
    if ($first) {
        # If this is the 'first' article (the most recent), include it as
        # the date the channel was last updated
        echo "    <lastBuildDate>" . $rfc822date . "</lastBuildDate>\n";
        $first = 0;
    }

67 68 69 70 71 72 73 74 75 76 77
    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>