From d7db5b3573849fd3a4993903526f60163057854d Mon Sep 17 00:00:00 2001 From: Hal Roberts Date: Fri, 13 Jun 2003 18:59:41 +0000 Subject: [PATCH] added the rss.url template variable to www_view, which points to www_viewRSS, which spits out an RSS feed of the blog contents --- lib/WebGUI/Wobject/USS.pm | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/lib/WebGUI/Wobject/USS.pm b/lib/WebGUI/Wobject/USS.pm index 1455b744a..b9b25b634 100644 --- a/lib/WebGUI/Wobject/USS.pm +++ b/lib/WebGUI/Wobject/USS.pm @@ -32,6 +32,29 @@ use WebGUI::Wobject; our @ISA = qw(WebGUI::Wobject); +# format the date according to rfc 822 (for RSS export) +my @_months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); +sub _get_rfc822_date { + my ($time) = @_; + + my ($year, $mon, $mday, $hour, $min, $sec) = WebGUI::DateTime::localtime($time); + + my $month = $_months[$mon - 1]; + + return sprintf("%02d %s %04d %02d:%02d:%02d GMT", + $mday, $month, $year, $hour, $min, $sec); +} + +# encode a string to include in xml (for RSS export) +sub _xml_encode { + + $_[0] =~ s/&/&/g; + $_[0] =~ s//\]\]>/g; + + return $_[0]; +} + #------------------------------------------------------------------- sub duplicate { my ($sth, $file, %row, $newSubmissionId, $w); @@ -350,6 +373,7 @@ sub www_view { $var{"search.label"} = WebGUI::International::get(364); $var{"search.Form"} = WebGUI::Search::form({wid=>$_[0]->get("wobjectId"),func=>'view',search=>1}); $var{"search.url"} = WebGUI::Search::toggleURL("wid=".$_[0]->get("wobjectId")."&func=view"); + $var{"rss.url"} = WebGUI::URL::page('func=viewRSS&wid='.$_[0]->get("wobjectId")); if ($session{scratch}{search}) { $numResults = $session{scratch}{numResults}; $constraints = WebGUI::Search::buildConstraints([qw(username title content)]); @@ -410,6 +434,64 @@ sub www_view { return $_[0]->processTemplate($_[0]->get("templateId"),\%var); } +#------------------------------------------------------------------- +# print out RSS 2.0 feed describing the items visible on the first page +sub www_viewRSS { + + my $wid = $_[0]->get("wobjectId"); + my $numResults = $_[0]->get("submissionsPerPage"); + + my $encTitle = _xml_encode($_[0]->get("title")); + my $encDescription = _xml_encode($_[0]->get("description")); + my $encUrl = _xml_encode(WebGUI::URL::page("wid=$wid")); + + my $xml = qq~ + + +$encTitle +$encUrl +$encDescription +~; + + my $res = WebGUI::SQL->read + ("select USS_submissionId, content, title, " . + "dateSubmitted, username from USS_submission " . + "where wobjectId = " .$session{dbh}->quote($wid) . " " . + "order by dateSubmitted desc limit " . $numResults); + + while (my $row = $res->{_sth}->fetchrow_arrayref()) { + my ($sid, $content, $title, $dateSubmitted, $username) = + @{$row}; + + my $encUrl = _xml_encode + (WebGUI::URL::page + ("wid=$wid&func=viewSubmission&sid=$sid")); + my $encTitle = _xml_encode($title); + my $encPubDate = _xml_encode + (_get_rfc822_date($dateSubmitted)); + my $encDescription = _xml_encode($content); + + $xml .= qq~ + +$encTitle +$encUrl +$encDescription +$encUrl +$encPubDate + +~; + } + + $xml .=qq~ + + +~; + + $session{header}{mimetype} = 'text/xml'; + + return $xml; +} + #------------------------------------------------------------------- sub www_viewSubmission { return "" unless ($session{form}{sid});