# HG changeset patch
# User Steve Kemp
# Date 1199059311 0
# Node ID 4a882ba147e47c6d39ef934cad8b8837e13998a1
# Parent 88d1f5caebd7872f0c69bcc7a7da287e5c98ba12
Updated to allow Ajax to be used for comment submission.
diff -r 88d1f5caebd7 -r 4a882ba147e4 cgi-bin/comments.cgi
--- a/cgi-bin/comments.cgi Sun Dec 30 01:37:27 2007 +0000
+++ b/cgi-bin/comments.cgi Mon Dec 31 00:01:51 2007 +0000
@@ -44,11 +44,9 @@
#
# The notification addresses - leave blank to disable
#
-# my $TO = 'weblog@steve.org.uk';
-# my $FROM = 'weblog@steve.org.uk';
+my $TO = 'weblog@steve.org.uk';
+my $FROM = 'weblog@steve.org.uk';
#
-my $TO = '';
-my $FROM = '';
@@ -63,7 +61,7 @@
my $body = $cgi->param('body') || undef;
my $id = $cgi->param('id') || undef;
my $cap = $cgi->param('captcha') || undef;
-
+my $ajax = $cgi->param( "ajax" ) || 0;
#
# If any are missing just redirect back to the blog homepage.
@@ -73,7 +71,15 @@
!defined( $body ) || !length( $body ) ||
!defined( $id ) || !length( $id ) )
{
- print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n";
+ if ( $ajax )
+ {
+ print "Content-type: text/html\n\n";
+ print "Missing fields.\n";
+ }
+ else
+ {
+ print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n";
+ }
exit;
}
@@ -82,7 +88,15 @@
#
if ( defined( $cap ) && length( $cap ) )
{
- print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n";
+ if ( $ajax )
+ {
+ print "Content-type: text/html\n\n";
+ print "Missing fields.\n";
+ }
+ else
+ {
+ print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n";
+ }
exit;
}
@@ -134,7 +148,7 @@
#
if ( length($TO) && length($FROM) )
{
- open ( SENDMAIL, "|/usr/lib/sendmail -t");
+ open ( SENDMAIL, "|/usr/lib/sendmail -t -f $FROM");
print SENDMAIL "To: $TO\n";
print SENDMAIL "From: $FROM\n";
print SENDMAIL "Subject: New Comment [$id]\n";
@@ -143,12 +157,21 @@
close ( SENDMAIL );
}
-
#
# Now show the user the thanks message..
#
+if ( $cgi->param( "ajax" ) )
+{
+ print <Thanks for your comment, it will be made live when the queue is moderated next.
+
+EOF
+ exit;
+}
+else
+{
+ print <
Thanks For Your Comment
@@ -160,4 +183,4 @@