open(">> $writeback_dir$path/$fn.$file_extension") ) {
foreach ( @fields ) {
my $p = param($_);
#if ( $_ == "url" ) {
# $p =~ s/^($email)/mailto:$1/;
#}
$p =~ s/\r?\n\r?/\r/mg;
# should remove the need to undef $param{url} in the story section.
if ( $_ eq "url" ) {
undef $p if $p =~ m!^http://$!;
}
if ( $_ eq "ip" ) {
# Log IP address of poster
$p = $ENV{'REMOTE_ADDR'};
}
if ( $_ eq "date" ) {
my @now = split ' ', localtime();
$p = "$now[2] $now[1] $now[4]"
}
if ( $_ eq "time" ) {
my @now = split ' ', localtime();
$p = $now[3];
}
if ( $_ eq "comment" ) {
# first, convert any ampersands - we'll add other entities later we don't want double encoded:
$p =~ s!\&!\&\;!g;
# Convert all "$" to entities to prevent variables being included:
$p =~ s/\$/$/g;
# neutralise html:
$p =~ s/\<\;/g;
$p =~ s/>/\>\;/g;
# replace any \r's with
tags to retain line breaks:
$p =~ s/\r/
/g;
# wrap the comment in tags:
$p = "
$p
";
}
if ( $_ eq "id" ) {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon += 1;
if ( length($mon) == 1 ){ $mon = "0$mon"; }
if ( length($mday) == 1 ) { $mday = "0$mday"; }
$p = "$fn$year$mon$mday$hour$min$sec";
}
print $fh "$_: $p\n";
}
print $fh "-----\n";
$fh->close();
chmod (0777,"$writeback_dir$path/$fn.$file_extension");
$trackback_response =~ s!!0!m;
$trackback_response =~ s!\n!!s;
$writeback_response = "Thanks for the comment!
";
# Make a note to save Name and URL/Email if save_preferences checked
param('save_preferences') and $cookie++;
# Pre-set Name and URL/Email based on submitted values
$pref_name = param('name') || '';
$pref_url = param('url') || '';
$pref_email = param('email') || '';
}
else {
warn "couldn't >> $writeback_dir$path/$fn.$file_extension\n";
$trackback_response =~ s!!1!m;
$trackback_response =~ s!trackback error!!m;
$writeback_response = "There was a problem posting your comment.";
}
#}
#else {
#$writeback_response = "Sorry, you can't include links in your comment.";
#}
}
else {
$writeback_response = "Sorry, writebacks are closed on this post.";
}
}
1;
}
sub story {
my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
# Only display writebacks under these condtions:
# - $do_seewritebacks is set AND
# - we've ben passed ?seewritebacks=y OR
# - we've been passed plugin=writeback OR
# - $blosxom::path_info contains a "." (ie, this is single entry view)
if ( $do_seewritebacks && (
(CGI::param("seewritebacks")) ||
(CGI::param("plugin") eq 'writeback') ||
($blosxom::path_info =~ /\./)
)
) {
$path =~ s!^/*!!; $path &&= "/$path";
($writebacks, $count) = ('', 0);
my %param = ();
my($open, $fl);
$fl = "$blosxom::datadir$path/$filename.$blosxom::file_extension";
if ( stat($fl)->mtime >= ( time() - 14*60*60*24 ) ) {
$open = 1;
}
# Prepopulate Name and URL/Email with cookie-baked preferences, if any
$pref_url ||= 'http://';
if ( $blosxom::plugins{cookies} > 0 and my $cookie = &cookies::get('writeback') ) {
$pref_name ||= $cookie->{'name'};
$pref_url ||= $cookie->{'url'};
$pref_email ||= $cookie->{'email'};
}
if ( $fh->open("$writeback_dir$path/$filename.$file_extension") ) {
foreach my $line (<$fh>) {
$line =~ /^(.+?): (.*)$/ and $param{$1} = $2;
if ( $line =~ /^-----$/ ) {
# lose useless $param{url}:
#undef $param{url} if $param{url} =~ m!^http://$!;
# Is our poster identified?
$param{name} = 'anonymous' if ( !$param{name} and !$param{blog_name} );
my $writeback = &$blosxom::template($path,'writeback',$blosxom::flavour) || &$blosxom::template($path,'writeback','general') || 'Name/Blog: $writeback::name$writeback::blog_name
URL: $writeback::url
Title: $writeback::title
Comment/Excerpt: $writeback::comment$writeback::excerpt
';
# Build a contact link:
if ( $param{name} ) { # It must be a comment, not a TB:
if ( !$param{url} and !$param{email} ) { # there is no contact data for a link:
$param{attribution} = "$param{name} commented:";
}
elsif ( !$param{url} ) { # there is an email address, but not a URL:
$param{attribution} = "