#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper::Simple; use FindBin; use lib "$FindBin::Bin/../../modules"; use SlapPhone; use CGI; use Time::localtime; my $cgi = CGI->new(); my $tm = localtime; my $raw_year = $tm->year; #my $raw_year = (localtime)[5]; my $year = ( $raw_year + 1900); my $epoch = time(); #read the conf file open (CONFIG,") { chomp; # no newline s/#.*//; # no comments s/^\s+//; # no leading white s/\s+$//; # no trailing white next unless length; # anything left? my ($var, $value) = split(/\s*=\s*/, $_, 2); $CONFIG{$var} = $value; } close CONFIG; #connect to the db my $dbh = DBI->connect("dbi:mysql:database=$CONFIG{'DB_NAME'};host=$CONFIG{'DB_HOST'}", $CONFIG{'DB_USER'}, $CONFIG{'DB_PASS'}) or die "Cannot connectto database: $!"; #get the category info my @cats; my @faqs; my %parent_cats; { my $query = $dbh->prepare("select * from book b, node n where b.nid=n.nid and b.parent = 198 and n.status=1 order by weight"); $query->execute(); while ( my $row = $query->fetchrow_hashref() ) { push (@cats, $row->{'nid'}); $row->{'description'} = $row->{'title'}; push (@faqs, $row); $parent_cats{ $row->{'nid'} } = $row->{'title'}; } } #get the faqs { my $sql_cats = commify (\@cats); my $query = $dbh->prepare("select b.parent, n.nid, title, body, log from book b, node n where b.nid=n.nid and b.parent in ($sql_cats) and n.status=1 order by created desc"); $query->execute(); while ( my $row = $query->fetchrow_hashref() ) { $row->{'description'} = $parent_cats{ $row->{'parent'} } . ":
\n
\n"; $row->{'title'} = $parent_cats{ $row->{'parent'} } . ": " . $row->{'title'}; push (@faqs, $row); } } #print $cgi->header; #print "
";
#print Dumper(@cats);
#print Dumper(@faqs);

# create an RSS 2.0 file
use XML::RSS;
my $rss = new XML::RSS (version => '2.0');
my $link = "http://slapcast.com/features";
my $gmt = rfc822date($epoch);
$rss->channel(
	title          => "Slapcast.com Features",
	link           => $link,
	language       => 'en-us',
	description    => "Slapcast.com Features: RSS feed",

	copyright      => "Copyright $year",
	pubDate        => $gmt,
	lastBuildDate  => $gmt,
	docs           => 'http://blogs.law.harvard.edu/tech/rss',
	generator      => 'http://slapcast.com/',
);

foreach my $faq (@faqs) {
	my $guid = $faq->{'nid'};
	my $faq_url = "http://slapcast.com/features";
	my $permalink = "http://slapcast.com/features" . "#" . $guid;

	my $description;
	$description .= $faq->{'description'} . "\n";
	#$description =~ s/\n/
/g; #add the message to the rss $rss->add_item( title => $faq->{'title'}, link => $faq_url, permaLink => $permalink, #enclosure => { url=>$mp3_url, length=>$message->{'mp3_bytes'}, type=>"audio/mpeg" }, description => $description ); } # print the RSS as a string my $rss_string = $rss->as_string; #$rss_string =~ s/header(-type => 'text/xml'); print $rss_string; #print "
"; sub commify { my($rarrInput) = $_[0]; (@{$rarrInput} == 0) ? '' : (@{$rarrInput} == 1) ? $$rarrInput[0] : join(", ", @{$rarrInput}[0 .. ($#{$rarrInput}-1)], "$$rarrInput[-1]"); } sub rfc822date { my $time = shift; my ($sec, $min, $hour, $mday, $mon, $year, $wday) = (gmtime($time))[0..6]; my $day = (qw(Sun Mon Tue Wed Thu Fri Sat))[$wday]; my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon]; return sprintf "%s, %02d %s %d %02d:%02d:%02d GMT", $day, $mday, $month, $year+1900, $hour, $min, $sec; }