news-rss.php3 3.41 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2005-2011 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25
#
include("defs.php3");

26 27 28 29 30 31 32 33 34 35
$optargs = OptionalPageArguments("protogeni", PAGEARG_BOOLEAN);

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

36 37 38 39
header("Content-type: text/xml");

$query_result=
    DBQueryFatal("SELECT subject, author, body, msgid, ".
40
    		 "date, usr_name " .
41
		 "FROM $db_table as w ".
42
                 "LEFT JOIN users on w.author_idx = users.uid_idx " .
43
		 "ORDER BY w.date DESC " .
44 45 46 47 48
                 "LIMIT 5");

?>
<rss version="2.0"> <channel>
    <title><? echo $THISHOMEBASE ?> News</title>
49 50 51
<?
echo "<link>$TBBASE/news.php3?protogeni=$protogeni</link>\n";
?>
52 53
    <description>News items for <? echo $THISHOMEBASE ?></description>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
54 55 56
    <managingEditor><? echo $TBMAILADDR_OPS ?></managingEditor>
    <webMaster><? echo $TBMAILADDR_OPS ?></webMaster>
    <pubDate><? echo date("r"); ?></pubDate>
57
<?
58 59

$first = 1;
60
while ($row = mysql_fetch_array($query_result)) {
61
    $subject     = $row["subject"];
62
    $timestamp   = $row['date'];
63 64 65 66
    $author      = $row["author"];
    $author_name = $row["usr_name"];
    $body        = $row["body"];
    $msgid       = $row["msgid"];
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

    # 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
83 84 85
    list($date, $hours) = preg_split('/ /', $timestamp);
    list($year,$month,$day) = preg_split('/-/',$date);
    list($hour,$min,$sec) = preg_split('/:/',$hours);
86
    $rfc822date = date("r",mktime($hour, $min, $sec, $month, $day, $year));
87

88 89 90 91 92 93
    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;
    }
94 95 96 97 98 99
    if ($protogeni) {
	$url = "$TBBASE/pgeninews.php?single=$msgid";
    }
    else {
	$url = "$TBBASE/news.php3?single=$msgid";
    }
100

101 102
    echo "    <item>\n";
    echo "        <title>$subject</title>\n";
103 104
    echo "        <link>$url</link>\n";
    echo "        <guid isPermaLink=\"true\">$url</guid>\n";
105 106 107 108 109 110 111
    echo "        <description>$summary</description>\n";
    echo "        <pubDate>$rfc822date</pubDate>\n";
    echo "        <author>$author_name</author>\n";
    echo "    </item>\n";
}
?>
</channel> </rss>