X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;ds=sidebyside;f=rss.cgi;h=3eed7e26bd90408dc44cb10c240e29d0164b8820;hb=948ce5be6ef6bba36edfb544565ca22e316afb0a;hp=d7abe3df6de1db5930840f10a84b097ac868df7d;hpb=3405333d11155e31f48bcf9d913461edb1527f20;p=blerg.git diff --git a/rss.cgi b/rss.cgi index d7abe3d..3eed7e2 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) = @_; @@ -85,9 +108,11 @@ HEADER for my $i (@items) { my $author = defined $i->{author} ? $i->{author} : $name; my $data = xml_escape(qq{\@$author
$i->{data}}); + my $title = xml_escape(substr($i->{data}, 0, 27)) . "..."; my $post_time = strftime("%a, %d %b %Y %H:%M:%S %Z", localtime($i->{timestamp})); print < + $title $post_time ${baseurl}get/$author/$i->{record} ${baseurl}#$author/$i->{record} @@ -119,21 +144,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 +165,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 +196,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);