#!/usr/bin/perl -w # smoosh # a minimalist weblog program # Copyright (c) 2001 Steve Cook # This software is open source under the terms of the MIT License # as described at # It's free. Make something of your own with it. # version 0.4 -- working, but with not templating. # It's probably only useful for the specific application it was designed for. # currently takes three form inputs: password, newtitle, entry # To do: changing variables from some sort of flat file, seperation of # content and presentation. # 8 April 2001 use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use strict; use POSIX qw(strftime); # some variables for the nonce; we'll eventually want to load these from a confi g file of some sort. my $password = "password"; my $topic = "this and that"; my $previous_archive = "previous_filename.html"; my $archive_path = "PATH/$archive_target"; my $index_path = "PATH/index.html"; my $q = new CGI; # Let's figure out what action we should be handling if ($q->param("password")) { my ($entry, $title, $password, $action) = parse_values($q); if ($action eq "editselect") { editselect_form(); } elsif ($action eq "edit") { edit_form($entry); } elsif ($action eq "submitedit") { replace_entry($entry,$title); smoosh(); } else { add_entry_to_content($title, $entry); smoosh(); } } else { entry_form(); } # add the entry to the content file. sub add_entry_to_content { my($mytitle, $myentry) = @_; open (CONTENT, "smooshfiles/content.txt") || die "Sorry, I couldn't open the content file.\n"; open (CONTENTOUT, "> smooshfiles/content.temp") || die "Sorry, I couldn't start a temporary content file."; my $mydate = strftime "%m.%d.%Y", localtime; print CONTENTOUT <<"END_PRINT"; $mydate
$mytitle
$myentry

END_PRINT close(CONTENTOUT); open(CONTENTOUT, ">> smooshfiles/content.temp") || die "Something went awry with the content-appending process.\n"; while () { # now, append the current content.txt to content.temp print CONTENTOUT; } close(CONTENT); close(CONTENTOUT); rename("smooshfiles/content.temp","smooshfiles/content.txt") || die "Couldn't rename content.temp to content.txt"; } sub replace_entry { my($myentry,$mytitle) = @_; open (CONTENT, "smooshfiles/content.txt") || die "Sorry, I couldn't open the content file.\n"; open (CONTENTOUT, "> smooshfiles/content.temp") || die "Sorry, I couldn't start a temporary content file."; my $check = 0; while() { if (/ entry: $mytitle/) { print CONTENTOUT; $check = 1; print CONTENTOUT $myentry; } if (/\/entry: $mytitle/) {$check = 0;} ($check == 0) && (print CONTENTOUT); } close(CONTENTOUT); close(CONTENT); rename("smooshfiles/content.temp","smooshfiles/content.txt") || die "Couldn't rename content.temp to content.txt"; } # begin the smooshing sub smoosh { open (HEADER, "smooshfiles/header.txt") || die "Sorry, I couldn't open the header file.\n"; open (FOOTER, "smooshfiles/footer.txt") || die "Sorry, I couldn't open the footer file.\n"; open(INDEXOUT, "> $index_path") || die "Something went wrong opening up the temporary index file to write to.\n"; open(ARCHIVEOUT, "> $archive_path") || die "Couldn't open $archive_target"; open(CONTENT, "smooshfiles/content.txt") || die "Something went wrong opening content the second time.\n"; while (
) { s/{PREVIOUS}/$previous_archive/g; # replace {PREVIOUS} on a line-by-line basis s/{TOPIC}/$topic/g; # replace {TOPIC} on a line-by-line basis print INDEXOUT; print ARCHIVEOUT; print; } while () { print INDEXOUT; print ARCHIVEOUT; print; } while (