This repository has been archived by the owner on Jul 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobile.pl
executable file
·613 lines (504 loc) · 17.4 KB
/
mobile.pl
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
#!/usr/bin/env perl
BEGIN{
use strict;
require 'config.pl';
}
use PerlHP;
<%
use DBI;
use PerlHP::Utils;
use Digest::SHA;
use lib '.';
my $has_encode=0;
eval 'use Encode qw(decode)';
$has_encode=1 unless $@;
my $dbh;
open_db();
my $threads=get_threads();
BEGIN {
our $lang;
our $c_lang;
$lang=$c_lang unless $lang;
my %langs=LANGS;
if(!$lang){
my @accept_langs=split(/[^a-z-]+/,$ENV{HTTP_ACCEPT_LANGUAGE});
for(@accept_langs){
if($langs{$_}){
$lang=$_;
last;
}
}
}
$lang=LANG_DEFAULT unless $langs{$lang};
cookie('c_lang',$lang,time()+315360000);
require "strings_$lang.pl";
}
our $task;
if($task eq 'post'){
die S_HAX if $ENV{REQUEST_METHOD} ne 'POST';
our $thread;
our $field1;
our $field2;
our $comment;
our $title;
our $name;
our $link;
our $file;
die S_SPAM if $name or $link;
$thread=0 unless $thread;
make_post($thread,$field1,$field2,$comment,$title,$file);
}else{
my $thread=0;
if($ENV{PATH_INFO}=~/^\/+([0-9]+)\/?/){
$thread=$1;
}
my $sth;
if($thread){
$sth=$dbh->prepare('SELECT UNIX_TIMESTAMP(lastmod) FROM threads WHERE id=?;')
or die S_DBERR;
$sth->execute($thread) or die S_DBERR;
}else{
$sth=$dbh->prepare('SELECT UNIX_TIMESTAMP(lastmod) FROM threads ORDER BY '.
'lastmod DESC LIMIT 1;') or die S_DBERR;
$sth->execute() or die S_DBERR;
}
my($modified)=$sth->fetchrow_array();
my $ifmod=parse_http_date($ENV{HTTP_IF_MODIFIED_SINCE});
if($modified <= $ifmod){
header('Status: 304 Not modified');
}else{
header('Content-Type: '.($ENV{HTTP_ACCEPT}=~/application\/xhtml\+xml/?
'application/xhtml+xml':'text/html').'; charset=utf-8');
header('Date: '.make_date(time(),'http'));
header('Last-Modified: '.make_date($modified,'http'));
%>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
"http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%= TITLE %></title>
<link rel="stylesheet" type="text/css" href="<%= expand_filename(STYLESHEET) %>" />
<link rel="shortcut icon" type="image/x-ico" href="<%= expand_filename(FAVICON) %>" />
</head>
<body>
<% if($ENV{PATH_INFO}=~/\/subback\/?.*/){ %>
<div id="navigation">
*: <a accesskey="*" href="<%= $ENV{SCRIPT_NAME} %>"><%= S_RETURN %></a>
</div>
<div id="allthreads">
<% full_thread_list() %>
</div>
<% }elsif($ENV{PATH_INFO}=~/^\/+([0-9]+)\/+([lr0-9,\-]+)\/?.*/){ %>
<div id="navigation">
*: <a accesskey="*" href="<%= $ENV{SCRIPT_NAME} %>"><%= S_RETURN %></a>
<br />
0: <a accesskey="0" href="<%= $ENV{SCRIPT_NAME} %>/<%= $1 %>"><%= S_ENTIRE %></a><br />
#: <a accesskey="#" href="#replyform"><%= S_REPLY %></a>
</div>
<% show_thread_posts($1,$2) %>
<% }elsif($ENV{PATH_INFO}=~/^\/+([0-9]+)\/?.*/){ %>
<div id="navigation">
*: <a accesskey="*" href="<%= $ENV{SCRIPT_NAME} %>"><%= S_RETURN %></a><br />
#: <a accesskey="#" href="#replyform"><%= S_REPLY %></a>
</div>
<% show_thread($1) %>
<% }else{ %>
<div id="threadlistbox">
<% main_page_thread_list() %>
</div>
<form id="threadform" class="postform" method="post" action="<%= $ENV{SCRIPT_NAME} %>">
<p>
<input type="hidden" name="task" value="post" />
<span style="display:none">
<label for="name">Spam: </label>
<input type="text" name="name" id="name" /><br />
<label for="link">Spam: </label>
<input type="text" name="link" id="link" /><br />
</span>
<label for="field1"><%= S_NAME %></label>
<input type="text" name="field1" id="field1" /><br />
<label for="field2"><%= S_LINK %></label>
<input type="text" name="field2" id="field2" /><br />
<label for="title"><%= S_TITLE %></label>
<input type="text" name="title" id="title" /><br />
<label for="comment"><%= S_COMMENT %></label>
<textarea name="comment" id="comment" rows="6" cols="60"></textarea><br />
<label for="file"><%= S_IMAGE %></label>
<input type="file" name="file" id="file" />
<input type="submit" value="<%= S_CREATETHR %>" />
</p>
</form>
<% } %>
</body>
</html>
<%
}
}
close_db();
sub main_page_thread_list(){
my $thread;
my $i=1;
for $thread (@$threads){
my($id,$title,$lasthit,$postcount,$permasaged,$deleted)=@$thread;
%>
<p>
<%= $i==10?0:$i %>:
<a accesskey="<%= $i==10?0:$i %>" href="<%= $ENV{SCRIPT_NAME} %>/<%= $id %>">
<%= $title %> (<%= $postcount %><%= $permasaged?', '.S_PERMASAGED:'' %>)
</a>
</p>
<%
++$i;
last if $i>10;
}
%>
<p>*: <a href="<%= $ENV{SCRIPT_NAME} %>/subback/"><%= S_ALLTHR %></a></p>
<%
}
sub full_thread_list(){
my $thread;
my $i=1;
for $thread (@$threads){
my($id,$title,$lasthit,$postcount,$permasaged,$deleted)=@$thread;
%>
<p>
<% if($i<11){ %><%= $i==10?0:$i %>:<% } %>
<a
<% if($i<11){ %> accesskey="<%= $i==10?0:$i %>" <% } %>
href="<%= $ENV{SCRIPT_NAME} %>/<%= $id %>"
>
<%= $title %> (<%= $postcount %><%= $permasaged?', '.S_PERMASAGED:'' %>)
</a>
</p>
<%
++$i;
}
}
sub show_thread($){
my($thread)=@_;
my $sth=$dbh->prepare('SELECT * FROM threads WHERE id=? AND deleted=0;') or
die S_DBERR;
$sth->execute($thread) or die S_DBERR;
my($id,$title,$lasthit,$postcount,$permasaged,$deleted)=$sth->fetchrow_array();
die S_NOTHR if $deleted or !$title;
$sth=$dbh->prepare('SELECT * FROM posts WHERE thread=?;') or die S_DBERR;
$sth->execute($thread) or die S_DBERR;
my $posts=$sth->fetchall_arrayref();
%>
<div class="<%= $permasaged?'permasaged':'' %>thread">
<p class="threadtitle">
<%= $title %> (<%= $postcount %><%= $permasaged?', '.S_PERMASAGED:'' %>)
</p>
<%
my $post;
for $post (@$posts){
show_post(@$post);
}
reply_form($thread,$postcount);
%>
</div>
<%
}
sub show_thread_posts($$){
my($thread,$specs)=@_;
my $sth=$dbh->prepare('SELECT * FROM threads WHERE id=? AND deleted=0;') or
die S_DBERR;
$sth->execute($thread) or die S_DBERR;
my($id,$title,$lasthit,$postcount,$permasaged,$deleted)=
$sth->fetchrow_array();
die S_NOTHR if $deleted or !$title;
%>
<div class="<%= $permasaged?'permasaged':'' %>thread">
<p class="threadtitle">
<%= $title %> (<%= $postcount %><%= $permasaged?', '.S_PERMASAGED:'' %>)
</p>
<%
my @specs=split(/,/,$specs);
my @posts;
my $spec;
for $spec (@specs){
if($spec=~/^[0-9]{1,4}$/ and $spec<=$postcount){
push(@posts,$spec);
}elsif($spec=~/^([0-9]{0,4})\-([0-9]{0,4})$/){
if(!$1 and !$2){
push(@posts,1..$postcount);
}elsif($1 and !$2 and $1<$postcount){
push(@posts,($1||1)..$postcount);
}elsif($2 and !$1 and $2<1001){
push(@posts,1..(($postcount<$2)?$postcount:$2));
}elsif($1<$2 and $2<1001){
push(@posts,($1||1)..(($postcount<$2)?$postcount:$2));
}elsif($1>$2 and $1<1001){
push(@posts,reverse(($2||1)..(($postcount<$1)?$postcount:$1)));
}elsif($1==$2 and $1<=$postcount and $1){
push(@posts,$1);
}
}elsif($spec=~/^l([0-9]{0,4})$/){
my $start=1+$postcount-$1;
$start=1 if $start<1;
push(@posts,$start..$postcount);
}elsif($spec=~/^r([0-9]{0,4})$/){
push(@posts,map{int(rand($postcount)+1)}1..($1||1));
}
}
@posts=(1..$postcount) unless @posts;
die 'too many posts' if scalar(@posts)>2000;
$sth=$dbh->prepare('SELECT * FROM posts WHERE thread=?;') or die S_DBERR;
$sth->execute($thread) or die S_DBERR;
my $all_posts=$sth->fetchall_arrayref();
my $post;
for $post (@posts){
show_post(@{$$all_posts[$post-1]});
}
reply_form($thread,$postcount);
%>
</div>
<%
}
sub show_post($$$$$$$$$$$){
my($num,$thread,$time,$name,$trip,$link,$comment,$ip,$file,$filename,$deleted)=@_;
my @fileparts=split /\./,$file if $file;
my $ext=pop @fileparts if $file;
$file=join '.',@fileparts if @fileparts;
if($deleted){
%>
<div class="post">
<p class="deleted"><%= S_DELETEDPOST %></p>
</div>
<%
}else{
%>
<div class="post">
<p class="postheader">
<span class="postnum"><%= $num %></span>
<%= S_NAME %>
<% if($link){ %>
<a href="<%= $link %>">
<% } %>
<span class="postername"><%= $name %></span>
<span class="postertrip"><%= $trip %></span>
<% if($link){ %>
</a>
<% } %>
: <span class="posttime"><%= $time %></span>
<%= S_ID %><span class="id"><%= $link=~/sage/?'Heaven':make_id($thread.$ip) %></span>
<% if($file and $ext=~/^(?:jpg|gif|png|svg)$/){ %>
<a href="<%= expand_filename("gcd.pl?file=$file.$ext") %>"><%= S_DLIMAGE %>: <%= $filename %></a>
<% }elsif($file){ %>
<a href="<%= expand_filename("src/$file.$ext") %>"><%= $filename %></a>
<% } %>
</p>
<div class="postbody">
<% if($file){ %>
<div class="image">
<a href="<%= expand_filename("src/$file.$ext") %>">
<% if($ext =~ /^(?:jpg|gif|png|svg)$/){ %>
<img src="<%= expand_filename("thumb/$file.gif") %>" alt="<%= $filename %>" title="<%= $filename %>" />
<% } else { %>
<span class="nothumb"><%= S_NOTHUMB %>:<br /><%= $filename %></span>
<% } %>
</a>
</div>
<% } %>
<div class="commenttext">
<%= $comment %>
</div>
</div>
</div>
<%
}
}
sub reply_form($$){
my($thread,$postcount)=@_;
if($postcount>999){
%>
<p class="threadclosed" id="replyform"><%= S_CLOSED %></p>
<% }else{ %>
<form class="postform" method="post" action="<%= $ENV{SCRIPT_NAME} %>" id="replyform">
<p>
<input type="hidden" name="task" value="post" />
<input type="hidden" name="thread" value="<%= $thread %>" />
<span style="display:none">
<label for="name">Spam: </label><br />
<input type="text" name="name" id="name" />
<label for="link">Spam: </label>
<input type="text" name="link" id="link" /><br />
</span>
<label for="field1-<%= $thread %>"><%= S_NAME %></label>
<input type="text" name="field1" id="field1-<%= $thread %>" /><br />
<label for="field2-<%= $thread %>"><%= S_LINK %></label>
<input type="text" name="field2" id="field2-<%= $thread %>" /><br />
<label for="comment-<%= $thread %>"><%= S_COMMENT %></label>
<textarea name="comment" id="comment-<%= $thread %>" rows="6" cols="60"></textarea><br />
<label for="file-<%= $thread %>"><%= S_IMAGE %></label>
<input type="file" name="file" id="file-<%= $thread %>" />
<input type="submit" value="<%= S_REPLY %>" />
</p>
</form>
<%
}
}
sub get_threads(){
my $sth=$dbh->prepare('SELECT * FROM threads WHERE deleted=0 ORDER BY '.
'lasthit DESC;') or die S_DBERR;
$sth->execute() or die S_DBERR;
return $sth->fetchall_arrayref();
}
sub make_post($$$$;$$){
my($thread,$name,$link,$comment,$title,$file)=@_;
my($trip,$filename);
die S_HAX unless $thread=~/^[0-9]*$/;
$name=substr($name,0,128);
$link=substr($link,0,512);
$comment=substr($comment,0,8192);
$title=substr($title,0,256);
($name,$trip)=process_tripcode($name,'!',SECRET,'utf8');
$name=ANON_NAME if !$name and !$trip;
#$link=clean_string(decode_string($link,'utf8'));
$link=my_clean_string($link);
$name=gethostbyaddr inet_aton($ip),AF_INET or $ip if $link=~/fusianasan/;
$link="mailto:$link" if($link and $link!~/^$PerlHP::Utils::protocol_re:/);
#$comment=~s/^(>>[0-9\-,]+)/ $1/gm;
#$comment=do_wakabamark(undef,0,$comment);
$comment=format_post(my_clean_string($comment),$thread);
die S_NOTEXT unless $comment;
die S_SPAM if spam_check($link."\n".$comment,SPAM_FILE);
if($file){
#$filename=clean_string(decode_string($file,'utf8'));
$filename=my_clean_string($file);
my $fh=upload('file');
binmode($fh);
my $buffer;
my $size=-s $fh;
die S_TOOBIG if $size>MAX_FILE_SIZE;
my($ext,$height,$width)=analyze_image($fh);
if(!$width){
$ext='invalid';
if($filename=~/\.([^\.])$/){
$ext=$1;
}
if($ext=~/^(jpg|gif|png)$/){
$ext.='.invalid';
}
}
seek($fh,0,0);
my $sha=Digest::SHA->new(256);
read $fh,$buffer,$size;
$sha->add($buffer);
$file=$sha->hexdigest;
seek($fh,0,0);
open OUTFILE,"+>src/${file}.${ext}" or die S_NOWRITE;
binmode OUTFILE;
print OUTFILE $buffer or die S_NOWRITE;
close $fh;
close OUTFILE;
if($ext =~ /^(?:jpg|gif|png|svg)$/){
my $tn_height=100;
my $tn_width=int($width*100/$height);
if($ext eq 'svg'){
`svg2png -w $tn_width -h $tn_height src/${file}.${ext} -|convert -size ${tn_width}x${tn_height} -geometry ${tn_width}x${tn_height} - thumb/${file}.gif`;
`convert -size ${tn_width}x${tn_height} -geometry ${tn_width}x${tn_height} src/${file}.${ext} thumb/${file}.gif` if $?;
}else{
`convert -size ${tn_width}x${tn_height} -geometry ${tn_width}x${tn_height} src/${file}.${ext} thumb/${file}.gif`;
}
}
$file=$file.'.'.$ext;
}
my $sth;
if($thread==0){
#$title=clean_string(decode_string($title,'utf8'));
$title=my_clean_string($title);
die S_NOTITLE unless $title;
$sth=$dbh->prepare('INSERT INTO threads VALUES(null,?,?,?,0,0);') or die
S_DBERR;
$sth->execute($title,time,0) or die S_DBERR;
$sth=$dbh->prepare('SELECT id FROM threads WHERE id IS NULL;') or
die S_DBERR;
$sth->execute() or die S_DBERR;
($thread)=$sth->fetchrow_array();
}
$sth=$dbh->prepare('SELECT * FROM threads WHERE id=?;') or die S_DBERR;
$sth->execute($thread) or die S_DBERR;
my($thread,$title,$lasthit,$postcount,$permasaged,$deleted)=
$sth->fetchrow_array();
my $tl="$ENV{SCRIPT_NAME}/$thread";
#$comment=~s/(>>((?:[0-9\-]|,)+))/<a href="$tl\/$2" rel="nofollow">$1<\/a>$3/g;
++$postcount;
my $time=scalar(gmtime(time));
$sth=$dbh->prepare('INSERT INTO posts VALUES(?,?,?,?,?,?,?,?,?,?,0);') or
die S_DBERR;
$sth->execute($postcount,$thread,$time,$name,$trip,$link,$comment,
$ENV{REMOTE_ADDR},$file,$filename) or die S_DBERR.' '.$sth->errstr;
$lasthit=time unless $link=~/sage/ or $permasaged;
$sth=$dbh->prepare('UPDATE threads SET lasthit=?,postcount=? WHERE id=?;') or
die S_DBERR;
$sth->execute($lasthit,$postcount,$thread) or die S_DBERR;
close_db();
header('Status: 301 Go West');
header("Location: $ENV{SCRIPT_NAME} ");
}
sub open_db(){
$dbh=DBI->connect(SQL_DBI_SOURCE,SQL_USERNAME,SQL_PASSWORD,{AutoCommit=>1})
or die S_SQLCONF;
my $sth=$dbh->prepare('CREATE TABLE IF NOT EXISTS threads(id BIGINT UNSIGNED'.
' UNIQUE PRIMARY KEY AUTO_INCREMENT NOT NULL,title TEXT,lasthit INTEGER '.
'UNSIGNED NOT NULL,postcount SMALLINT UNSIGNED,permasaged BOOL,deleted BOOL'.
',lastmod TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,'.
'INDEX threadindex (id));') or die S_DBERR;
$sth->execute() or die S_DBERR;
$sth=$dbh->prepare('CREATE TABLE IF NOT EXISTS posts(num SMALLINT UNSIGNED '.
'NOT NULL,thread BIGINT UNSIGNED NOT NULL REFERENCES threads(id),time TEXT,'.
'name TEXT,trip TEXT,link TEXT,comment TEXT,ip TEXT,file TEXT,filename TEXT'.
',deleted BOOL,INDEX postindex (thread,num));') or die S_DBERR;
$sth->execute() or die S_DBERR;
}
sub close_db(){
$dbh->disconnect();
}
sub make_id($){
my($text)=@_;
return encode_base64(rc4(null_string(6),$text.SECRET),"");
}
sub expand_filename($){
my ($filename)=@_;
return $filename if($filename=~m!^/!);
return $filename if($filename=~m!^\w+:!);
my ($self_path)=$ENV{SCRIPT_NAME}=~m!^(.*/)[^/]+$!;
return $self_path.$filename;
}
sub my_clean_string($){
my($str)=@_;
$str=decode('utf8',$str) if $has_encode;
$str=~s/&/&/g;
$str=~s/</</g;
$str=~s/>/>/g;
$str=~s/"/"/g;
$str=~s/'/'/g;
$str=~s/[\x00-\x08\x0b\x0c\x0e-\x1f\x80-\x84]//g; # control chars
$str=~s/[\x{d800}-\x{dfff}]//g; # surrogate code points
$str=~s/[\x{202a}-\x{202e}]//g; # text direction
$str=~s/[\x{fdd0}-\x{fdef}\x{fffe}\x{ffff}\x{1fffe}\x{1ffff}\x{2fffe}\x{2ffff}\x{3fffe}\x{3ffff}\x{4fffe}\x{4ffff}\x{5fffe}\x{5ffff}\x{6fffe}\x{6ffff}\x{7fffe}\x{7ffff}\x{8fffe}\x{8ffff}\x{9fffe}\x{9ffff}\x{afffe}\x{affff}\x{bfffe}\x{bffff}\x{cfffe}\x{cffff}\x{dfffe}\x{dffff}\x{efffe}\x{effff}\x{ffffe}\x{fffff}]//g; # non-characters
$str=join('',map{$_<0x10fffe?$_:''}split(//,$str));
return $str;
}
sub format_post($$){
my $protocol_re=qr/(?:http|https|ftp|mailto|nntp)/;
my($text,$thread)=@_;
$text=~s/\r\n/\n/sg; # fix newlines
$text=~s/\r/\n/sg; # fix newlines
$text=~s{($protocol_re:[^\s<>"]*?)((?:\s|<|>|"|\.|\)|\]|!|\?|,|,|")*(?:[\s<>"]|$))}{<a href="$1" rel="nofollow">$1\</a>}sg; # hyperlink urls
$text=~s/>>([0-9,\-]+)/<a href="$ENV{SCRIPT_NAME}\/$thread\/$1">>>$1<\/a>/g; # >> links
$text=~s/^(>.*)$/<blockquote><p>$1<\/p><\/blockquote>/mg; # blockquotes
$text=~s/^\x{3000}(.*)$/<p lang="ja">$1<\/p>/mg; # sjis art
$text=~s/^ (.*)$/<code>$1<\/code>/mg; # code sections
$text=~s/^spoiler:(.*)$/<div class="spoiler"><input type="button" class="spoilerbutton" value="spoiler" onclick="this.parentNode.getElementsByTagName('div')[0].style.display='block';this.style.display='none'" \/><div class="spoilertext">$1<\/div><\/div>/mg; # spoilers
$text=~s/<\/p><\/blockquote>\n<blockquote><p>/\n/sg; # fixup multiline quotes
$text=~s/<\/p>\n<p lang="ja">/\n/sg; # fixup multiline sjis art
$text=~s/<\/code>\n<code>/\n/sg; # fixup multiline code sections
$text=~s/<\/div><\/div>\n<div class="spoiler"><input type="button" class="spoilerbutton" value="spoiler" onclick="this.parentNode.getElementsByTagName('div')[0].style.display='block';this.style.display='none'" \/><div class="spoilertext">/\n/sg; # fixup multiline spoilers
$text=~s/(<\/(?:blockquote|p)>)\n/$1/sg; # remove newlines after blockquotes
$text=~s/\n(<blockquote)/$1/sg; # remove newlines before blockquotes
$text=~s/\n/<br \/>/sg; # convert newlines to <br />
return $text;
}
%>