#!/usr/bin/perl # Agnews Poster: sort.pl # This script takes an article generated by parse.pl and posts it to the # agnews web site. It maintains links, and archives to the data. # # Author: James Dean Palmer # # Revision 1: 11-21-96 # Revision 2: 05-09-97 # Revision 3: 01-27-98 # Revision 4: 10-09-98 # Any number of articles per category can be added in a single day # (the limit was 5). Adds link in the archive.html when first article. # for that month is posted. # Configuration variables: $logfile = "/user/home/jpalmer/agnmore/agnmorelog"; $top_story_name = "/user/www/agnews/top_story.txt"; $top_story_mod_name = "/user/www/agnews/top_story_mod.txt"; $storydir = "/user/www/agnews/stories/"; # The link name (the only global variable) $link = ""; use Date::Format qw(time2str); # DumpFile(filename, text) writes a file to disk. sub DumpFile { if (!open(OUTFILE, $_[0])) { print STDERR "Can't open output file for $_[0].\n"; exit(0); } print OUTFILE $_[1]; close (OUTFILE); } # SnarfFile(filename) writes a file to disk. sub SnarfFile { my ($output); if (!open(INFILE, "< $_[0]")) { print STDERR "Can't open input file for $_[0].\n"; exit(0); } else { while () { $output .= $_; } } close (INFILE); return($output); } # CreateTopPage($string) uses the formatted string to create a top # page story for inclusion on the main page. sub CreateTopPage { my ($top_page, $top_story_mod); $_ = $_[0]; $top_page = ""; # Grab the first six paragraphs or so. for ($i=1; $i<=6; $i++) { s/^.*?

//is; $top_page .= $&; } $top_page =~ s/(^.*?)(

)/$2/is; $top_page .= "


For the rest of the story, " . "click here.\n

"; &DumpFile("> $top_story_name", $top_page); &DumpFile(">> $logfile", "\n" . time2str("%b%d%y", time, 'GMT') . " Created top page.\n"); $top_story_mod = time2str("%A %I:%M %p %B %d, %Y", time, 'CDT'); &DumpFile("> $top_story_mod_name", $top_story_mod); } # Process the file. sub process { my($directory, $title, $text, $revision, $filename, $null, $update, $updatefile, $newlink); $directory = $_[0]; $title = $_[1]; $text = $_[2]; # This procedure checks to see if this is the first time we have # processed the file. If so then we assign it a file name based # on the date and then process2 the file. If we have processed # this file before then we just process2 it. if ($process_count == 0) { $date = time2str("%b%d%y", time, 'GMT'); $revision = "a"; $filename = $storydir . $directory . "/" . $date . $revision . ".htm"; $link = "/stories/" . $directory . "/" . $date . $revision . ".htm"; stat($filename); while (-e _) { $revision++; $filename = $storydir . $directory . "/" . $date . $revision . ".htm"; $link = "/stories/" . $directory . "/" . $date . $revision . ".htm"; stat($filename); } # Copy the article to it's final location. &DumpFile("> $filename", $text); # Add a log file entry that indicates where the file was added. &DumpFile(">> $logfile", "\n" . time2str("%b%d%y", time, 'GMT') . " Created $filename\n"); # Change the permissions for this file. $null = `chmod g+w $filename`; $null = `chmod g+r $filename`; $null = `chmod o+r $filename`; $null = `chgrp agnews $filename`; # Add link to top page process2 ($directory, $link, $title); # Update / Create the monthly archive of articles: # This bit of code can't distinguish articles from 1996, 2096, 3096, etc.. # I'm not too worried about it. $thismonth = time2str("%B", time, 'GMT'); $thisyear = time2str("%y", time, 'GMT'); $update = $storydir . "NEWS/" . $thismonth . $thisyear . ".htm"; # Create a monthly archive page if one doesn't already exist. stat($update); if (not(-e _)) { $whatsnew = "\n" . " \n" . " News Archived by Date - " . $thismonth . "" . " \n" . " " . "

" . $thismonth . " AgNews Links

\n" . " \n

\n" . "


" . "

Agricultural Communications News and Public Affairs WWW Server\n" . " \n" . " (http://agnews.tamu.edu/)
\n" . " The Texas A&M University System / College Station, Texas 77843-2112
" . " URL=http://agnews.tamu.edu/stories/NEWS/
\n" . " \n" . ""; &DumpFile("> $update", $whatsnew); `chmod g+w $update`; `chgrp agnews $update`; } # Done making our what's new page, if one didn't exist. # Read the old archive file (or the one we just made): $updatefile = &SnarfFile("$update"); # Add the current link. $idate = $thismonth . " " . time2str("%d", time, 'GMT') . ", " . time2str("%Y", time, 'GMT'); $newlink = "

  • $title\n
    - " . $idate . " -
  • \n"; $updatefile =~ s|