# 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 @@ EOF - +} diff -r 88d1f5caebd7 -r 4a882ba147e4 themes/blog.steve.org.uk/ajax.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/blog.steve.org.uk/ajax.js Mon Dec 31 00:01:51 2007 +0000 @@ -0,0 +1,44 @@ + +function submitAjax() +{ + var xhr; + try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); } + catch (e) + { + try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); } + catch (e2) + { + try { xhr = new XMLHttpRequest(); } + catch (e3) { xhr = false; } + } + } + + xhr.onreadystatechange = function() + { + if(xhr.readyState == 4) + { + if(xhr.status == 200) + { + var o = document.getElementById( "output" ); + o.innerHTML = xhr.responseText; + } + else + { + var o = document.getElementById( "output" ); + o.innerHTML = "Failed HTTP code " + xhr.status + " " + xhr.responseText; + } + } + }; + + data = 'ajax=1'; + data = data + '&id=' + escape(document.forms[0].id.value ); + data = data + '&captcha=' + escape( document.forms[0].captcha.value ); + data = data + '&id=' + escape(document.forms[0].id.value ); + data = data + '&captcha=' + escape( document.forms[0].captcha.value ); + data = data + '&name=' + escape( document.forms[0].name.value ); + data = data + '&mail=' + escape( document.forms[0].mail.value ); + data = data + '&body=' + escape( document.forms[0].body.value ); + xhr.open("POST", "/cgi-bin/comments.cgi", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send(data); +} diff -r 88d1f5caebd7 -r 4a882ba147e4 themes/blog.steve.org.uk/comment-form.inc --- a/themes/blog.steve.org.uk/comment-form.inc Sun Dec 30 01:37:27 2007 +0000 +++ b/themes/blog.steve.org.uk/comment-form.inc Mon Dec 31 00:01:51 2007 +0000 @@ -1,6 +1,7 @@

Add A Comment

+
@@ -12,9 +13,10 @@ Your Comment
- +

Your submission will be ignored if any field is left blank. But your email address will not be displayed.

+
diff -r 88d1f5caebd7 -r 4a882ba147e4 themes/blog.steve.org.uk/entry.template --- a/themes/blog.steve.org.uk/entry.template Sun Dec 30 01:37:27 2007 +0000 +++ b/themes/blog.steve.org.uk/entry.template Mon Dec 31 00:01:51 2007 +0000 @@ -6,6 +6,9 @@ + + +