#!/usr/bin/perl ########################## #$Id: postblog 35 2003-01-25 19:49:52Z steve $ #$Log$ #Revision 1.3 2003/01/25 19:49:52 steve #removed site-specific include # #Revision 1.2 2002/12/13 21:53:30 steve #added changes from warehaus and cleaned up much of the code # ########################## use XML::Weblog::Simple; use Getopt::Std; getopts('hc:'); usage() if $opt_h || !@ARGV; ## initial variables my $interactive = 1; my $comment = $opt_c; my $blogfile = $ENV{'BLOG_FILE'}; # interactive text editor my $editor = 'vi'; my $user = $ENV{'USER'}; ## command line/userland overrides $editor = $ENV{'EDITOR'} if exists $ENV{'EDITOR'}; $blogfile = $ARGV[0] if defined $ARGV[0]; ##### my $blog = new XML::Weblog::Simple($blogfile); if( $post_file ){ post_from_file( $post_file, $blog, $user ); exit; } if( $interactive ){ my $tempfile = `tempfile`; chomp $tempfile; open TMP, ">$tempfile" or die "Cannot open temp file $tempfile for writing: $!"; my $entryno = $blog->get_latest_id() + 1; print TMP <get_latest_id() + 1; open TMP, $post_file or die "Cannot open temp file $tempfile: $!"; while( $line = ){ if( $line =~ /^TITLE:(.+)/ ){ $title = $1; }elsif( $line =~ /^BLOG:/ ){ }else{ $body .= $line; } } close TMP; # clean trailing whitespace $title =~ s/^\s*(.+?)\s*$/$1/s; $body =~ s/^\s*(.+?)\s*$/$1/s; if( exists $opts{'comment'} ){ print "posting comment on entry $opts{'comment'}: \"$title\"\n"; $blog->post_comment( $opts{'comment'}, $title, $user, $body ); }else{ print "posting entry $entryno: \"$title\"\n"; $blog->post( $title, $user, $body ); } } sub usage(){ die<