######################### # includes ######################### use strict; use warnings; use CGI qw(:standard); use XML::RSS; ######################### # vars ######################### my $dateStamp; my $dirPath = "C:/Inetpub/wwwroot/mywebsite/rss/"; my $newName = ''; my $passName = ''; my $currentDate; my $fullOutfile; ######################### # make a date stamp ######################### my ($sec, $min, $hour, $mday, $mon, $year) = localtime; $mon += 1; #this will change the month from a 0-11 format to a useable 1-12 format $year += 1900; # year is number since 1900 - so we add 1900 to get the full year. $dateStamp = "$year$mon$mday$hour$min"; # datestamp to identify the entry ######################### # sub to get rss input from htm form and write it to a file ######################### sub getInput { my $title = param('title'); my $desc = param('desc'); my $full = param('full'); my $template = $dirPath. "rss_outtemplate.htm"; my $tempHTML =''; my $fullOutfile = "$dirPath.rss.htm"; $full =~ s/\r/

/g; # putting
's in where there were cr's in the input ######################### # format the form data using a template ######################### open(FILEFULL, $template) or die ("Couldn't open template file - $template - $!\n"); while () { s/xTitle/$title/g; s/xDesc/$desc/g; s/xfull/$full/g; $tempHTML .= $_; } close FILEFULL or die ("Couldn't close $template - $!\n"); ######################### # write the form data with template to the dump file ######################### open(FILESTOR,"> $fullOutfile") or die ("Couldn't open $fullOutfile - $!\n"); print FILESTOR $tempHTML; close FILESTOR or die ("Couldn't close $fullOutfile - $!\n"); return $fullOutfile } ######################### # rename the dump file with fileTag ######################### sub renameFile ($$){ my $fileTag = shift; my $fullOutfile = "$dirPath.rss.htm"; $passName = $fileTag. "rss.htm"; my $newName = $dirPath.$fileTag. "rss.htm"; rename $fullOutfile, $newName or die ("Couldn't rename rss out file - $fullOutfile - $!\n"); return $passName; } ######################### # sub to write the rss file ######################### sub writeRss ($) { my $rss = new XML::RSS (version => '1.0'); my $rss_output = "$dirPath/rss.xml"; my $title = param('title'); my $desc = param('desc'); my $rss_link = shift; $rss_link = "http://www.mywebsite.com/rss/$rss_link"; $rss->parsefile($rss_output); pop(@{$rss->{'items'}}) if (@{$rss->{'items'}} == 15); $rss->add_item(title => $title, link => $rss_link, description => $desc, mode => 'insert' ); $rss->save($rss_output); } ######################### # wrap it all up ######################### sub writeAfter { print "Content-type: text/html\n\n"; print "Sucess - put something in here later ... a page to link back to the site - stuff like that.\n" } ######################### # call subs ######################### getInput; renameFile ($dateStamp, $fullOutfile); writeRss ($passName); writeAfter; undef &main;