Mercurial > hg > chronicle
comparison cgi-bin/comments.cgi @ 150:4a882ba147e4
Updated to allow Ajax to be used for comment submission.
author | Steve Kemp <steve@steve.org.uk> |
---|---|
date | Mon, 31 Dec 2007 00:01:51 +0000 |
parents | 412506c2de6b |
children | 9f91d9377d1a |
comparison
equal
deleted
inserted
replaced
149:88d1f5caebd7 | 150:4a882ba147e4 |
---|---|
42 my $COMMENT = $ENV{'DOCUMENT_ROOT'} . "../comments/"; | 42 my $COMMENT = $ENV{'DOCUMENT_ROOT'} . "../comments/"; |
43 | 43 |
44 # | 44 # |
45 # The notification addresses - leave blank to disable | 45 # The notification addresses - leave blank to disable |
46 # | 46 # |
47 # my $TO = 'weblog@steve.org.uk'; | 47 my $TO = 'weblog@steve.org.uk'; |
48 # my $FROM = 'weblog@steve.org.uk'; | 48 my $FROM = 'weblog@steve.org.uk'; |
49 # | 49 # |
50 my $TO = ''; | |
51 my $FROM = ''; | |
52 | 50 |
53 | 51 |
54 | 52 |
55 | 53 |
56 | 54 |
61 my $name = $cgi->param('name') || undef; | 59 my $name = $cgi->param('name') || undef; |
62 my $mail = $cgi->param('mail') || undef; | 60 my $mail = $cgi->param('mail') || undef; |
63 my $body = $cgi->param('body') || undef; | 61 my $body = $cgi->param('body') || undef; |
64 my $id = $cgi->param('id') || undef; | 62 my $id = $cgi->param('id') || undef; |
65 my $cap = $cgi->param('captcha') || undef; | 63 my $cap = $cgi->param('captcha') || undef; |
66 | 64 my $ajax = $cgi->param( "ajax" ) || 0; |
67 | 65 |
68 # | 66 # |
69 # If any are missing just redirect back to the blog homepage. | 67 # If any are missing just redirect back to the blog homepage. |
70 # | 68 # |
71 if ( !defined( $name ) || !length( $name ) || | 69 if ( !defined( $name ) || !length( $name ) || |
72 !defined( $mail ) || !length( $mail ) || | 70 !defined( $mail ) || !length( $mail ) || |
73 !defined( $body ) || !length( $body ) || | 71 !defined( $body ) || !length( $body ) || |
74 !defined( $id ) || !length( $id ) ) | 72 !defined( $id ) || !length( $id ) ) |
75 { | 73 { |
76 print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n"; | 74 if ( $ajax ) |
75 { | |
76 print "Content-type: text/html\n\n"; | |
77 print "Missing fields.\n"; | |
78 } | |
79 else | |
80 { | |
81 print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n"; | |
82 } | |
77 exit; | 83 exit; |
78 } | 84 } |
79 | 85 |
80 # | 86 # |
81 # Does the captcha value contain text? If so spam. | 87 # Does the captcha value contain text? If so spam. |
82 # | 88 # |
83 if ( defined( $cap ) && length( $cap ) ) | 89 if ( defined( $cap ) && length( $cap ) ) |
84 { | 90 { |
85 print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n"; | 91 if ( $ajax ) |
92 { | |
93 print "Content-type: text/html\n\n"; | |
94 print "Missing fields.\n"; | |
95 } | |
96 else | |
97 { | |
98 print "Location: http://" . $ENV{'HTTP_HOST'} . "/\n\n"; | |
99 } | |
86 exit; | 100 exit; |
87 } | 101 } |
88 | 102 |
89 | 103 |
90 # | 104 # |
132 # | 146 # |
133 # Send a mail. | 147 # Send a mail. |
134 # | 148 # |
135 if ( length($TO) && length($FROM) ) | 149 if ( length($TO) && length($FROM) ) |
136 { | 150 { |
137 open ( SENDMAIL, "|/usr/lib/sendmail -t"); | 151 open ( SENDMAIL, "|/usr/lib/sendmail -t -f $FROM"); |
138 print SENDMAIL "To: $TO\n"; | 152 print SENDMAIL "To: $TO\n"; |
139 print SENDMAIL "From: $FROM\n"; | 153 print SENDMAIL "From: $FROM\n"; |
140 print SENDMAIL "Subject: New Comment [$id]\n"; | 154 print SENDMAIL "Subject: New Comment [$id]\n"; |
141 print SENDMAIL "\n\n"; | 155 print SENDMAIL "\n\n"; |
142 print ( SENDMAIL `cat $file` ); | 156 print ( SENDMAIL `cat $file` ); |
143 close ( SENDMAIL ); | 157 close ( SENDMAIL ); |
144 } | 158 } |
145 | 159 |
146 | |
147 # | 160 # |
148 # Now show the user the thanks message.. | 161 # Now show the user the thanks message.. |
149 # | 162 # |
163 if ( $cgi->param( "ajax" ) ) | |
164 { | |
165 print <<EOF; | |
150 | 166 |
151 print <<EOF; | 167 <p>Thanks for your comment, it will be made live when the queue is moderated next.</p> |
168 | |
169 EOF | |
170 exit; | |
171 } | |
172 else | |
173 { | |
174 print <<EOF; | |
152 <html> | 175 <html> |
153 <head> | 176 <head> |
154 <title>Thanks For Your Comment</title> | 177 <title>Thanks For Your Comment</title> |
155 </head> | 178 </head> |
156 <body> | 179 <body> |
158 <p>Your comment will be included the next time this blog is rebuilt.</p> | 181 <p>Your comment will be included the next time this blog is rebuilt.</p> |
159 <p><a href="http://$ENV{'HTTP_HOST'}/">Return to blog</a>.</p> | 182 <p><a href="http://$ENV{'HTTP_HOST'}/">Return to blog</a>.</p> |
160 </body> | 183 </body> |
161 </html> | 184 </html> |
162 EOF | 185 EOF |
163 | 186 } |