--- a/branches/2.6/cgi-bin/yabb2/Sources/RSS.pm
+++ b/branches/2.6/cgi-bin/yabb2/Sources/RSS.pm
@@ -15,7 +15,7 @@
 use CGI::Carp qw(fatalsToBrowser);
 our $VERSION = '2.6.0';
 
-$rsspmver = 'YaBB 2.6.0 $Revision: 1418 $';
+$rsspmver = 'YaBB 2.6.0 $Revision: 1419 $';
 if ( $action eq 'detailedversion' ) { return 1; }
 
 # Change the error routine for here.
@@ -241,11 +241,11 @@
     my ( @threadlist, $i );    # Variables for the messages
 
     # Settings
-    $topics = $INFO{'topics'} || $rss_limit;
+    $topics = $INFO{'topics'} || $rss_limit || 5;
     if ( $rss_limit && $topics > $rss_limit ) { $topics = $rss_limit; }
 
     # If this is just a single category, handle it.
-    if ( $catinfo{ $INFO{'catselect'} } ) {
+    if ( $INFO{'catselect'} ) {
         @categoryorder = ( $INFO{'catselect'} );
     }
 
@@ -448,6 +448,216 @@
     return;
 }
 
+sub RSS_cat {
+    ### Arguments:
+    # catselect: use a specific category instead of the whole forum (optional)
+    # topics: Number of topics to show. Defaults to 5.
+    ###
+
+    # Local variables
+    my ($topics);    # Variables for settings
+    my ( @threadlist, $i );    # Variables for the messages
+
+    # Settings
+    $topics = $INFO{'topics'} || $rss_limit || 5;
+    if ( $rss_limit && $topics > $rss_limit ) { $topics = $rss_limit; }
+
+    $catid = $INFO{'catselect'};
+    my $boardlist = $cat{$catid};
+
+    my @bdlist = split /\,/xsm, $boardlist;
+    my ( $catname, $catperms ) = split /\|/xsm, $catinfo{$catid};
+    my $cataccess = CatAccess($catperms);
+    if ( !$cataccess ) { next; }
+    $yytitle = $catname;
+
+    foreach my $curboard (@bdlist) {
+        ( $boardname{$curboard}, $boardperms, $boardview ) = split /\|/xsm,
+          $board{$curboard};
+
+        my $access = AccessCheck( $curboard, q{}, $boardperms );
+        if ( !$iamadmin && $access ne 'granted' ) { next; }
+        if ( ${ $uid . $curboard }{'brdpasswr'} ) {
+            my $cookiename = "$cookiepassword$curboard$username";
+            my $crypass    = ${ $uid . $curboard }{'brdpassw'};
+            if ( !$staff && $yyCookies{$cookiename} ne $crypass ) { next; }
+        }
+
+        fopen( BOARD, "$boardsdir/$curboard.txt" )
+          || RSS_error( 'cannot_open', "$boardsdir/$curboard.txt", 1 );
+        for my $i ( 0 .. ( $topics - 1 ) ) {
+            my $buffer = <BOARD>;
+            if ( !$buffer ) { last; }
+            chomp $buffer;
+
+            my (
+                $mnum, undef, undef, undef, $mdate,
+                undef, undef, undef, $mstate
+            ) = split /\|/xsm, $buffer;
+            $mdate = sprintf '%010d', $mdate;
+            if ( $rss_message == 2 ) {
+                $mdate = $mnum;
+            }    # Sort by topic creation if requested.
+
+            # Check if it's hidden. If so, don't show it
+            if ( $mstate =~ /h/sm && !$iamadmin && !$iamgmod ) { next; }
+
+     # Add it to an array, using $mdate as the first value so we can easily sort
+            push @threadlist, "$mdate|$curboard|$buffer";
+        }
+        fclose(BOARD);
+            # Clean out the extra entries in the threadlist
+        @threadlist = reverse sort @threadlist;
+        my $threadcount = @threadlist;
+        if ( $threadcount < $topics ) { $topics = $threadcount; }
+        @threadlist = @threadlist[ 0 .. ($topics - 1) ];
+    }
+
+
+    for my $i ( 0 .. ( @threadlist - 1 ) ) {
+
+        # Opening item stuff
+        (
+            $mdate,     $board,  $mnum,   $msub,
+            $mname,     $memail, $modate, $mreplies,
+            $musername, $micon,  $mstate
+        ) = split /\|/xsm, $threadlist[$i];
+        $curnum = $mnum;
+
+        ( $msub, undef ) = Split_Splice_Move( $msub, 0 );
+        FromHTML($msub);
+        ToChars($msub);
+
+        # Censor the subject of the thread.
+        $msub = Censor($msub);
+
+        # Does it need to be returned as a 304?
+        if ( $i == 0 ) {    # Do this for the first request only
+            $cachedate = RFC822Date($mdate);
+            if (   $ENV{'HTTP_IF_NONE_MATCH'} eq qq~"$cachedate"~
+                || $ENV{'HTTP_IF_MODIFIED_SINCE'} eq $cachedate )
+            {
+                Send304NotModified();
+                # Comment this out to test with caching disabled
+            }
+        }
+
+        my $postid = "$mreplies#$mreplies";
+        if ( $rss_message == 2 ) { $postid = '0#0'; }
+
+        my $category = "$mbname/$catname";
+        FromHTML($category);
+        my $bn = $boardname{$board};
+        FromHTML($bn);
+        if ($accept_permalink) {
+            my $permsub = $msub;
+            $permdate = permtimer($curnum);
+            $permsub =~ s/ /$perm_spacer/gsm;
+            $yymain .= q~           <item>
+            <title>~ . RSSDescriptionTrim("$bn - $msub") . q~</title>
+            <link>~
+              . RSSDescriptionTrim(
+                "http://$perm_domain/$symlink$permdate/$board/$curnum")
+              . q~</link>
+            <category>~ . RSSDescriptionTrim($category) . q~</category>
+            <guid isPermaLink="true">~
+              . RSSDescriptionTrim(
+                "http://$perm_domain/$symlink$permdate/$board/$curnum")
+              . qq~</guid>\n~;
+        }
+        else {
+            $yymain .= q~       <item>
+            <title>~ . RSSDescriptionTrim("$bn - $msub") . q~</title>
+            <link>~
+              . RSSDescriptionTrim("$scripturl?num=$curnum/$postid") . q~</link>
+            <category>~ . RSSDescriptionTrim($category) . q~</category>
+            <guid>~
+              . RSSDescriptionTrim("$scripturl?num=$curnum/$postid")
+              . qq~</guid>\n~;
+        }
+
+        my $post;
+        fopen( TOPIC, "$datadir/$curnum.txt" )
+          || RSS_error( 'cannot_open', "$datadir/$curnum.txt, $bn, testing, $category, $catname", 1 );
+        if ( $rss_message == 1 ) {
+
+            # Open up the thread and read the last post.
+            while (<TOPIC>) {
+                chomp $_;
+                if ($_) { $post = $_; }
+            }
+        }
+        elsif ( $rss_message == 2 ) {
+
+            # Open up the thread and read the first post.
+            $post = <TOPIC>;
+        }
+        fclose(TOPIC);
+
+        if ( $post ne q{} ) {
+            (
+                undef, undef, undef, undef,    $musername,
+                undef, undef, undef, $message, $ns
+            ) = split /\|/xsm, $post;
+        }
+
+        if ($showauthor) {
+
+# The spec really wants us to include their email.
+# That's not advisable for us (spambots anyone?). So we skip author if the email hidden flag is on for that user.
+            if ( -e "$memberdir/$musername.vars" ) {
+                LoadUser($musername);
+                if ( !${ $uid . $musername }{'hidemail'} ) {
+                    $yymain .=
+                      q~           <author>~
+                      . RSSDescriptionTrim(
+"${$uid.$musername}{'email'} (${$uid.$musername}{'realname'})"
+                      ) . qq~</author>\n~;
+                }
+                else {
+                    $yymain .=
+                        q~           <author><name>~
+                      . RSSDescriptionTrim("${$uid.$musername}{'realname'}")
+                      . qq~</name></author>\n~;
+                }
+            }
+        }
+
+        if ($showdate) {
+            if ( $rss_message == 2 ) {
+                $mdate = $curnum;
+            }    # Sort by topic creation if requested.
+                 # Get the date how the user wants it.
+            my $realdate = RFC822Date($mdate);
+            $yymain .= qq~          <pubDate>$realdate</pubDate>\n~;
+        }
+
+        if ( $message ne q{} ) {
+            ( $message, undef ) = Split_Splice_Move( $message, $curnum );
+            if ($enable_ubbc) {
+                LoadUser($musername);
+                $displayname = ${ $uid . $musername }{'realname'};
+                DoUBBC();
+            }
+            FromHTML($message);
+            ToChars($message);
+            $message = Censor($message);
+            $yymain .=
+                q~           <description>~
+              . RSSDescriptionTrim($message)
+              . qq~</description>\n~;
+        }
+
+        $yymain .= qq~      </item>\n~;
+    }
+
+    ToChars($boardname);
+    $yydesc  = ${ $uid . $curboard }{'description'};
+
+    RSS_template();
+    return;
+}
+
 sub RSS_template {    # print RSS output
                       # Generate the lastBuildDate
     my $rssdate = RFC822Date($date);
@@ -465,21 +675,25 @@
 #my $docs = "       <docs>http://$perm_domain</docs>\n" if $perm_domain;
 
     my $mainlink = $scripturl;
-    if ( $INFO{'board'} )     { $mainlink .= "?board=$INFO{'board'}"; }
-    if ( $INFO{'catselect'} ) { $mainlink .= "?catselect=$INFO{'catselect'}"; }
-
     my $tit = "$yytitle - $mbname";
+    if ( $INFO{'board'} )     { $mainlink .= "?board=$INFO{'board'}";
+        $descr = ( $boardname ? "$boardname - " : q{} ) . $mbname;
+    }
+    elsif ( $INFO{'catselect'} ) { $mainlink .= "?catselect=$INFO{'catselect'}";
+        $descr = ( $catselect ? "$catselect - " : q{} ) . $mbname;
+    }
+
+
     FromHTML($tit);
-    my $descr = ( $boardname ? "$boardname - " : q{} ) . $mbname;
     FromHTML($descr);
     my $mn = $mbname;
     FromHTML($mn);
-    $output = qq~<?xml version="1.0" encoding="$mycharset" ?>
+    $output = qq~<?xml version="1.0" encoding="$yymycharset" ?>
 <!-- Generated by YaBB on $rssdate -->
 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
     <channel>
         <atom:link href="$scripturl?action=$INFO{'action'}~
-      . ( $INFO{'board'} ? ";board=$INFO{'board'}" : q{} )
+      . ( $INFO{'board'} ? ";board=$INFO{'board'}" : q{} ) . ( $INFO{'catselect'} ? ";catselect=$INFO{'catselect'}" : q{} )
       . q~" rel="self" type="application/rss+xml" />
         <title>~ . RSSDescriptionTrim($tit) . q~</title>
         <link>~ . RSSDescriptionTrim($mainlink) . q~</link>