X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=rss.cgi;h=3bc61725eebfaeadb35ccf36fcf72d40fe371f52;hb=e08a49eb8946cad54f34d0299303b28392831c26;hp=d7abe3df6de1db5930840f10a84b097ac868df7d;hpb=3405333d11155e31f48bcf9d913461edb1527f20;p=blerg.git diff --git a/rss.cgi b/rss.cgi index d7abe3d..3bc6172 100755 --- a/rss.cgi +++ b/rss.cgi @@ -19,7 +19,6 @@ sub xml_escape { sub decode_basic_auth { my ($q) = @_; - my $authorization = my ($method, $base64) = split(/\s+/, $q->http('Authorization')); if (!defined $method) { return; @@ -56,6 +55,30 @@ Not Found DOC } +sub fetch_records { + my @out; + local $_; + + foreach (@_) { + my $b = Blerg::Database->open_existing($_->{author}); + my $data = $b->fetch($_->{record}); + if (!defined $data) { + $b->close; + next; + } + my $timestamp = $b->timestamp($_->{record}); + $b->close; + push @out, { + author => $_->{author}, + record => $_->{record}, + data => $data, + timestamp => $timestamp, + }; + } + + return @out; +} + sub print_rss { my ($type, $name, @items) = @_; @@ -119,21 +142,9 @@ while (my $q = new CGI::Fast) { next REQUEST; } - my $bb = Blerg::Database->open_existing($username); - my @list = $bb->subscription_list(); - $bb->close; - @list = map { - my $b = Blerg::Database->open_existing($_->{author}); - my $data = $b->fetch($_->{record}); - my $timestamp = $b->timestamp($_->{record}); - $b->close; - { - author => $_->{author}, - record => $_->{record}, - data => $data, - timestamp => $timestamp, - }; - } @list; + my $b = Blerg::Database->open_existing($username); + my @list = fetch_records($b->subscription_list()); + $b->close; print header(-type => 'application/rss+xml'); print_rss(feed => $username, @list); @@ -152,7 +163,7 @@ while (my $q = new CGI::Fast) { # And present the content in case their client is broken my $i = { record => '?failed_redirect', - timestamp => time, + timestamp => time, data => qq{Your RSS aggregator is dumb and isn't following 301 redirects. Please manually redirect it here: ${baseurl}rss/user/$username} }; print_rss(user => $username, $i); @@ -183,19 +194,7 @@ while (my $q = new CGI::Fast) { $atag = '@' . $tag; } - my @list = Blerg::Database::tag_list($atag, 0, -1); - @list = map { - my $b = Blerg::Database->open_existing($_->{author}); - my $data = $b->fetch($_->{record}); - my $timestamp = $b->timestamp($_->{record}); - $b->close; - { - author => $_->{author}, - record => $_->{record}, - data => $data, - timestamp => $timestamp, - }; - } @list; + my @list = fetch_records(Blerg::Database::tag_list($atag, 0, -1)); print header(-type => 'application/rss+xml'); print_rss($path[0] => $atag, @list);