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

9 10 11 12 13 14 15 16 17 18
$optargs = OptionalPageArguments("protogeni", PAGEARG_BOOLEAN);

if (! isset($protogeni) || !$protogeni) {
    $protogeni = 0;
}
else {
    $protogeni = 1;
}
$db_table = ($protogeni ? "webnews_protogeni" : "webnews");

19 20 21 22
header("Content-type: text/xml");

$query_result=
    DBQueryFatal("SELECT subject, author, body, msgid, ".
23
    		 "date, usr_name " .
24
		 "FROM $db_table as w ".
25
                 "LEFT JOIN users on w.author_idx = users.uid_idx " .
26
		 "ORDER BY w.date DESC " .
27 28 29 30 31
                 "LIMIT 5");

?>
<rss version="2.0"> <channel>
    <title><? echo $THISHOMEBASE ?> News</title>
32 33 34
<?
echo "<link>$TBBASE/news.php3?protogeni=$protogeni</link>\n";
?>
35 36
    <description>News items for <? echo $THISHOMEBASE ?></description>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
37 38 39
    <managingEditor><? echo $TBMAILADDR_OPS ?></managingEditor>
    <webMaster><? echo $TBMAILADDR_OPS ?></webMaster>
    <pubDate><? echo date("r"); ?></pubDate>
40
<?
41 42

$first = 1;
43
while ($row = mysql_fetch_array($query_result)) {
44
    $subject     = $row["subject"];
45
    $timestamp   = $row['date'];
46 47 48 49
    $author      = $row["author"];
    $author_name = $row["usr_name"];
    $body        = $row["body"];
    $msgid       = $row["msgid"];
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

    # 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
66 67 68
    list($date, $hours) = preg_split('/ /', $timestamp);
    list($year,$month,$day) = preg_split('/-/',$date);
    list($hour,$min,$sec) = preg_split('/:/',$hours);
69
    $rfc822date = date("r",mktime($hour, $min, $sec, $month, $day, $year));
70

71 72 73 74 75 76
    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;
    }
77 78 79 80 81 82
    if ($protogeni) {
	$url = "$TBBASE/pgeninews.php?single=$msgid";
    }
    else {
	$url = "$TBBASE/news.php3?single=$msgid";
    }
83

84 85
    echo "    <item>\n";
    echo "        <title>$subject</title>\n";
86 87
    echo "        <link>$url</link>\n";
    echo "        <guid isPermaLink=\"true\">$url</guid>\n";
88 89 90 91 92 93 94
    echo "        <description>$summary</description>\n";
    echo "        <pubDate>$rfc822date</pubDate>\n";
    echo "        <author>$author_name</author>\n";
    echo "    </item>\n";
}
?>
</channel> </rss>