#!/usr/bin/perl use CGI::Fast qw/:cgi/; use Blerg::Database; use URI::Escape; use POSIX qw/strftime/; use strict; my $baseurl = Blerg::Database::constant('BASEURL'); sub xml_escape { local $_ = shift; s/&/&/g; s//>/g; return $_; } sub print_404 { print header(-type => 'text/html', -status => '404 Not Found'); print <

404 Not Found

Not Found DOC } sub print_rss { my ($type, $name, @items) = @_; my ($title, $link); if ($type eq 'user') { $title = "${name}'s blërg"; $link = "${baseurl}#$name"; } elsif ($type eq 'tag' || $type eq 'ref') { $title = $name; my $basename = $name; $basename =~ s/^.//; $link = "${baseurl}#/$type/$basename"; } print < $title $link Textual vomit HEADER for my $i (@items) { my $data = xml_escape($i->{data}); my $post_time = strftime("%a, %d %b %Y %H:%M:%S %Z", localtime($i->{timestamp})); my $author = defined $i->{author} ? $i->{author} : $name; print < $post_time ${baseurl}get/$author/$i->{record} $data ITEM } print <<'FOOTER' FOOTER } REQUEST: while (my $q = new CGI::Fast) { my @path = split('/', $ENV{PATH_INFO}); shift @path; if (@path == 1) { # Assume this is a username; redirect to /user/ my $username = $path[0]; my $b = Blerg::Database->open_existing($username); if (!defined $b) { print_404; next REQUEST; } print header(-type => 'application/rss+xml', -charset => 'utf8', -status => '301 Moved Permanently', -location => "${baseurl}rss/user/$username"); # And present the content in case their client is broken my $i = { record => '?failed_redirect', 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); } elsif ($path[0] eq 'user') { my $username = $path[1]; my $b = Blerg::Database->open_existing($username); if (!defined $b) { print_404; next REQUEST; } print header(-type => 'application/rss+xml'); my $n = $b->record_count - 1; my @list = reverse map { { record => $_, data => $b->fetch($_), timestamp => $b->timestamp($_), } } ($n > 50 ? $n - 50 : 0)..$n; $b->close; print_rss(user => $username, @list); } elsif ($path[0] eq 'tag') { my $tag = $path[1]; $tag =~ s/^H/#/; my @list = Blerg::Database::tag_list($tag, 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; print header(-type => 'application/rss+xml'); if (substr($tag, 0, 1) eq '#') { print_rss(tag => $tag, @list); } else { print_rss(ref => $tag, @list); } } elsif ($path[0] eq 'ref') { } elsif ($path[0] eq 'feed') { } }