Modify backend to use new auth cookie format
[blerg.git] / rss.cgi
diff --git a/rss.cgi b/rss.cgi
index d7abe3d..3eed7e2 100755 (executable)
--- 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{<a href="${baseurl}#$author"><strong>\@$author</strong></a><br> $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 <<ITEM;
     <item>
+      <title>$title</title>
       <pubDate>$post_time</pubDate>
       <guid>${baseurl}get/$author/$i->{record}</guid>
       <link>${baseurl}#$author/$i->{record}</link>
@@ -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);