-
Notifications
You must be signed in to change notification settings - Fork 11
/
post.html
350 lines (280 loc) · 9.24 KB
/
post.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<%init>
use utf8;
use Encode;
use Text::Wrap;
use Data::Dumper;
</%init>
% unless( ($new && ($valsi || $natlangword)) || ($respond && $comment) ) {
<font size="+3">Couldn't locate what you wanted to post in regards to</font>
<hr />
Either jbovlaste generated an invalid URL for you to follow, or you're trying
to fiddle around with things you ought not be messing with! Either way, please
report this page's URL.
% $titlestr = "Couldn't locate what you wanted to post in regards to";
% return;
% }
<%perl>
# keep things clean for quoting.
sub fmtcomment {
my $cmt = shift;
my ($out, @lines);
$Text::Wrap::columns = 75;
$out = "";
utf8::upgrade($out);
@lines = split(/\r?\n/, $cmt);
foreach my $line (@lines) {
$out .= wrap("", "", $line) . "\n";
}
$out;
}
</%perl>
% unless( defined($session{'username'}) ) {
<font size="+3">Not logged in</font>
<hr />
I'm afraid you'll need to <a href="login.html">log in</a> in order to post.
% $titlestr = "Not logged in";
% return;
% }
% if($new) {
% if(!defined($content)) {
<%perl>
my $table = $valsi?"valsi":"natlangwords";
my $column = $valsi?"valsiid":"wordid";
my $query = $dbh->prepare("SELECT * FROM $table WHERE $column = ?");
$query->execute($valsi?$valsi:$natlangword);
my $wordtypestr = $valsi?"valsi":"natural language word";
my $theword = $query->fetchrow_hashref->{'word'};
$titlestr = sprintf('New post for %s "%s"',$wordtypestr, $theword);
</%perl>
<font size="+3">New Post</font><br />
<font size="+2">For <% $wordtypestr %> "<% $theword %>"</font>
<hr />
<form action="post.html" method="post">
<table>
<tr>
<td valign="top">Subject:</td>
<td><input type="text" name="subject" size="80"></td>
</tr>
<tr>
<td valign="top">Message:</td>
<td>
<textarea name="content" rows="12" cols="60"></textarea>
<input type="hidden" name="new" value="1">
<input type="hidden" name="valsi" value="<% $valsi %>">
<input type="hidden" name="natlangword" value="<% $natlangword %>">
<input type="hidden" name="definition" value="<% $definition %>">
</td>
</tr>
<tr>
<td></td><td align="right"><input type="submit"></td>
</tr>
</table>
</form>
% } else {
%if((length($subject)<=0) || (length($comment)<=0)) {
<font size="+3">You've got to write something</font>
<hr />
Sorry, you'll need to actually post something before I can let it through.
% $titlestr = "Must actually write something";
% return;
%}
<%perl>
$dbh->begin_work;
$dbh->do("LOCK TABLE threads IN ACCESS EXCLUSIVE MODE");
my $threadquery = $dbh->prepare("SELECT * FROM threads WHERE valsiid=? AND natlangwordid=? AND definitionId=?");
$threadquery->execute($valsi,$natlangword,$definition);
my $threadrow = $threadquery->fetchrow_hashref;
$threadquery->finish;
if(!defined($threadrow)) {
$dbh->do("INSERT INTO threads (valsiid, natlangwordid, definitionId ) VALUES (?,?,?)",
undef,
$valsi, $natlangword, $definition);
$threadquery->execute($valsi, $natlangword, $definition);
$threadrow = $threadquery->fetchrow_hashref;
if(!defined($threadrow)) {
$m->out("Something is really broken!");
return;
}
}
utf8::decode($subject);
utf8::decode($content);
$content = fmtcomment($content);
my $commentNum = $dbh->selectrow_array("SELECT max(commentNum) + 1 FROM comments
WHERE threadid=$threadrow->{'threadid'}\n");
if (! defined($commentNum))
{
$commentNum=1
}
$dbh->do(
"INSERT INTO comments (threadid, parentid, userid, time, subject,
content, commentNum) VALUES (?, ?, ?, ?, ?, ?, ?)",
undef,
$threadrow->{'threadid'}, 0, $session{'userid'},
time(), $subject, $content, $commentNum );
$dbh->commit;
$titlestr = "Post received";
</%perl>
<font size="+3">Post received</font>
<hr />
<p>I think I submitted your comment. You probably ought to check.</p>
<%perl>
$m->out("<p>Click <a href=\"comments.html?valsi=$valsi;".
"natlangword=$natlangword;commentid=$comment;definition=$definition\">".
"here</a> to get back to the thread.</p>\n\n");
# Here we send e-mail to the person who entered the word, if this is
# a per-definition comment.
my $email='';
if( $definition )
{
$email = $dbh->selectrow_array("SELECT u.email FROM
definitions d, users u WHERE d.userid = u.userid AND d.definitionid=$definition");
} elsif( $natlangword ) {
$email = $dbh->selectrow_array("SELECT u.email FROM
natlangwords n, users u WHERE n.userid = u.userid AND n.wordid=$natlangword");
}
if ( $email ) {
my $valsiwordword = $dbh->selectrow_array("SELECT word FROM valsi WHERE valsiid=$valsi");
my $natlangwordword = $dbh->selectrow_array("SELECT word FROM natlangwords WHERE wordid=$natlangword");
my $word = $valsiwordword ? $valsiwordword : $natlangwordword;
utils::sendemail( [ $email ], "Comment Response At Word $word", "
A jbovlaste thread you have commented in has had a reply added!
Please go to
<http://jbovlaste.lojban.org/comments.html?valsi=$valsi;natlangword=$natlangword;commentid=$comment;definition=$definition>
to see the thread.
Thank you.
-The jbovlaste Admin Team
", $session{'username'} );
$m->out("<p>Sent email.\n</p>");
} else {
$m->out("<p>No email sent.\n</p>");
}
</%perl>
% }
% return;
% }
% if($respond && $comment>0) {
% if(!defined($content)) {
<%perl>
# Acquire comment we're responding to
my $commentquery = $dbh->prepare("SELECT *
FROM convenientthreads t, convenientcomments c
WHERE t.threadid=c.threadid AND c.commentid=?");
$commentquery->execute($comment);
$comment = $commentquery->fetchrow_hashref;
my($wordtypestr,$theword);
if($comment->{'valsiid'}>0) {
$wordtypestr = "valsi";
$theword = $comment->{'valsi'};
} else {
$wordtypestr = "natural language word";
$theword = $comment->{'natlangword'};
}
$titlestr = sprintf('Responding to "%s"', $comment->{'subject'});
</%perl>
<font size="+3">Responding to: "<% $comment->{'subject'} %>"</font><br />
<font size="+2">In thread for <% $wordtypestr %> "<% $theword %>"</font>
<hr />
<%perl>
$comment->{'content'} =~ s/^/> /mg;
$comment->{'content'} =~ s/$//mg;
$comment->{'content'} = sprintf("%s wrote:\n",$comment->{'username'}).$comment->{'content'}."\n\n";
$comment->{'subject'} = "Re: ".$comment->{'subject'} unless $comment->{'subject'} =~ /Re:/;
</%perl>
<form action="post.html" method="post">
<table>
<tr>
<td valign="top">Subject:</td>
<td><input type="text" name="subject" size="80" value="<% $comment->{'subject'} %>"></td>
</tr>
<tr>
<td valign="top">Message:</td>
<td>
<textarea name="content" rows="12" cols="60"><% $comment->{'content'} %></textarea>
<input type="hidden" name="respond" value="1">
<input type="hidden" name="comment" value="<% $comment->{'commentid'} %>">
<input type="hidden" name="valsi" value="<% $valsi %>">
<input type="hidden" name="natlangword" value="<% $natlangword %>">
<input type="hidden" name="definition" value="<% $definition %>">
</td>
</tr>
<tr>
<td></td><td align="right"><input type="submit"></td>
</tr>
</table>
</form>
% } else {
<%perl>
utf8::decode($subject);
utf8::decode($content);
$content = fmtcomment($content);
my $commentNum = $dbh->selectrow_array("SELECT max(commentNum) + 1 FROM
comments WHERE threadid=(SELECT threadid FROM comments WHERE
commentid=$comment)\n");
if (! defined($commentNum))
{
$commentNum=1
}
$dbh->do("INSERT INTO comments (threadid, parentid, userid, time,
subject, content, commentNum)
VALUES ( (SELECT threadid FROM comments WHERE commentid=?), ?, ?, ?, ?, ?, ?)",
undef,
$comment, $comment, $session{'userid'}, time(), $subject, $content,
$commentNum);
$titlestr = "Post received";
</%perl>
<font size="+3">Post received</font>
<hr />
<p>I think I submitted your comment. You probably ought to check.</p>
<%perl>
$m->out("<p>Click <a href=\"comments.html?valsi=$valsi;".
"natlangword=$natlangword;commentid=$comment;definition=$definition\">".
"here</a> to get back to the thread.</p>\n\n");
# Here we send mail.
my $emails = $dbh->selectall_arrayref( "SELECT DISTINCT u.email from users u,
comments c WHERE u.userid = c.userid AND c.threadid = (SELECT threadid FROM
comments WHERE commentid=$comment)" );
my $selfemail = $dbh->selectrow_array("SELECT email FROM users WHERE userid=$session{'userid'}");
foreach my $email (@{$emails})
{
my $valsiwordword = $dbh->selectrow_array("SELECT word FROM valsi WHERE valsiid=$valsi");
my $natlangwordword = $dbh->selectrow_array("SELECT word FROM natlangwords WHERE wordid=$natlangword");
my $word = $valsiwordword ? $valsiwordword : $natlangwordword;
if( @{$email}[0] eq $selfemail )
{
next;
}
utils::sendemail( [ @{$email}[0] ], "Comment Response At Word $word", "
A jbovlaste thread you have commented in has had a reply added!
Please go to
<http://jbovlaste.lojban.org/comments.html?valsi=$valsi;natlangword=$natlangword;commentid=$comment;definition=$definition>
to see the thread.
Thank you.
-The jbovlaste Admin Team
", $session{'username'} );
$m->out("<p>Sent email.\n</p>");
}
</%perl>
% }
% return;
% }
% $titlestr = "Magical Bug!";
You've found a magical bug! Please report whatever you did.
<%init>
our($dbh,%session);
</%init>
<%args>
$new => 0
$respond => 0
$comment => 0
$valsi => 0
$natlangword => 0
$subject => undef
$content => undef
$definition => 0
</%args>
<%shared>
our $titlestr;
</%shared>
<%method title>
<% $titlestr %>
</%method>