forked from Heyuri/kokonotsuba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkoko.php
1555 lines (1438 loc) · 72.4 KB
/
koko.php
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
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
define("PIXMICAT_VER", 'Koko BBS Release 1'); // Version information text
/*
YOU MUST GIVE CREDIT TO WWW.HEYURI.NET ON YOUR BBS IF YOU ARE PLANNING TO USE THIS SOFTWARE.
*/
if (file_exists('.lockdown') && valid() < LEV_JANITOR) {
die('Posting temporarily disabled. Come back later!');
}
@session_start();
require './config.php'; // Introduce a settings file
require ROOTPATH.'lib/pmclibrary.php'; // Ingest libraries
require ROOTPATH.'lib/lib_errorhandler.php'; // Introduce global error capture
require ROOTPATH.'lib/lib_compatible.php'; // Introduce compatible libraries
require ROOTPATH.'lib/lib_common.php'; // Introduce common function archives
/* Update the log file/output thread */
function updatelog($resno=0,$pagenum=-1,$single_page=false){
global $LIMIT_SENSOR;
$PIO = PMCLibrary::getPIOInstance();
$FileIO = PMCLibrary::getFileIOInstance();
$PTE = PMCLibrary::getPTEInstance();
$PMS = PMCLibrary::getPMSInstance();
$pagenum = intval($pagenum);
$adminMode = valid()>=LEV_JANITOR && $pagenum != -1 && !$single_page; // Front-end management mode
$resno = intval($resno); // Number digitization
$page_start = $page_end = 0; // Static page number
$inner_for_count = 1; // The number of inner loop executions
$RES_start = $RES_amount = $hiddenReply = $tree_count = 0;
$kill_sensor = $old_sensor = false; // Predictive system start flag
$arr_kill = $arr_old = array(); // Obsolete numbered array
$pte_vals = array('{$THREADFRONT}'=>'','{$THREADREAR}'=>'','{$SELF}'=>PHP_SELF,
'{$DEL_HEAD_TEXT}' => '<input type="hidden" name="mode" value="usrdel" />'._T('del_head'),
'{$DEL_IMG_ONLY_FIELD}' => '<input type="checkbox" name="onlyimgdel" id="onlyimgdel" value="on" />',
'{$DEL_IMG_ONLY_TEXT}' => _T('del_img_only'),
'{$DEL_PASS_TEXT}' => ($adminMode ? '<input type="hidden" name="func" value="delete" />' : '')._T('del_pass'),
'{$DEL_PASS_FIELD}' => '<input type="password" name="pwd" size="8" value="" />',
'{$DEL_SUBMIT_BTN}' => '<input type="submit" value="'._T('del_btn').'" />',
'{$IS_THREAD}' => !!$resno);
if($resno) $pte_vals['{$RESTO}'] = $resno;
if(!$resno){
if($pagenum==-1){ // Rebuild mode (PHP dynamic output of multiple pages)
$threads = $PIO->fetchThreadList(); // Get a full list of discussion threads
$PMS->useModuleMethods('ThreadOrder', array($resno,$pagenum,$single_page,&$threads)); // "ThreadOrder" Hook Point
$threads_count = count($threads);
$inner_for_count = $threads_count > PAGE_DEF ? PAGE_DEF : $threads_count;
$page_end = ceil($threads_count / PAGE_DEF); // The last value of the page number
}else{ // Discussion of the clue label pattern (PHP dynamic output one page)
$threads_count = $PIO->threadCount(); // Discuss the number of strings
if($pagenum < 0 || ($pagenum * PAGE_DEF) >= $threads_count) error(_T('page_not_found')); // $Pagenum is out of range
$page_start = $page_end = $pagenum; // Set a static page number
$threads = $PIO->fetchThreadList(); // Get a full list of discussion threads
$PMS->useModuleMethods('ThreadOrder', array($resno,$pagenum,$single_page,&$threads)); // "ThreadOrder" Hook Point
$threads = array_splice($threads, $pagenum * PAGE_DEF, PAGE_DEF); // Remove the list of discussion threads after the tag
$inner_for_count = count($threads); // The number of discussion strings is the number of cycles
}
}else{
if(!$PIO->isThread($resno)){ error(_T('thread_not_found')); }
$AllRes = isset($pagenum) && ($_GET['pagenum']??'')=='all'; // Whether to use ALL for output
// Calculate the response label range
$tree_count = $PIO->postCount($resno) - 1; // Number of discussion thread responses
if($tree_count && RE_PAGE_DEF){ // There is a response and RE_PAGE_DEF > 0 to do the pagination action
if($pagenum==='all'){ // show all
$pagenum = 0;
$RES_start = 1; $RES_amount = $tree_count;
}else{
if($pagenum==='RE_PAGE_MAX') $pagenum = ceil($tree_count / RE_PAGE_DEF) - 1; // Special value: Last page
if($pagenum < 0) $pagenum = 0; // negative number
if($pagenum * RE_PAGE_DEF >= $tree_count) error(_T('page_not_found'));
$RES_start = $pagenum * RE_PAGE_DEF + 1; // Begin
$RES_amount = RE_PAGE_DEF; // Take several
}
}elseif($pagenum > 0) error(_T('page_not_found')); // In the case of no response, only pagenum = 0 or negative numbers are allowed
else{ $RES_start = 1; $RES_amount = $tree_count; $pagenum = 0; } // Output All Responses
if(THREAD_PAGINATION && !$adminMode){ // Thread Pagination
$cacheETag = md5(($AllRes ? 'all' : $pagenum).'-'.$tree_count);
$cacheFile = STORAGE_PATH .'cache/'.$resno.'-'.($AllRes ? 'all' : $pagenum).'.';
$cacheGzipPrefix = extension_loaded('zlib') ? 'compress.zlib://' : ''; // Zlib compression stream
$cacheControl = 'cache';
//$cacheControl = isset($_SERVER['HTTP_CACHE_CONTROL']) ? $_SERVER['HTTP_CACHE_CONTROL'] : ''; // respect user's cache wishes? (comment this line out to force caching)
if(isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == '"'.$cacheETag.'"'){ // Same page
header('HTTP/1.1 304 Not Modified');
header('ETag: "'.$cacheETag.'"');
return;
}elseif(file_exists($cacheFile.$cacheETag) && $cacheControl != 'no-cache'){ // Send paginated html file
header('X-Cache: HIT'); // Send buffered request
header('ETag: "'.$cacheETag.'"');
header('Connection: close');
readfile($cacheGzipPrefix.$cacheFile.$cacheETag);
return;
}else{
header('X-Cache: MISS');
}
}
}
// Predict that old articles will be deleted and archives
if(PIOSensor::check('predict', $LIMIT_SENSOR)){ // Whether a forecast is required
$old_sensor = true; // tag opens
$arr_old = array_flip(PIOSensor::listee('predict', $LIMIT_SENSOR)); // Array of old articles
}
$tmp_total_size = $FileIO->getCurrentStorageSize(); // The current usage of additional image files
$tmp_STORAGE_MAX = STORAGE_MAX * (($tmp_total_size >= STORAGE_MAX) ? 1 : 0.95); // Estimated upper limit
if(STORAGE_LIMIT && STORAGE_MAX > 0 && ($tmp_total_size >= $tmp_STORAGE_MAX)){
$kill_sensor = true; // tag opens
$arr_kill = $PIO->delOldAttachments($tmp_total_size, $tmp_STORAGE_MAX); // Outdated attachment array
}
$PMS->useModuleMethods('ThreadFront', array(&$pte_vals['{$THREADFRONT}'], $resno)); // "ThreadFront" Hook Point
$PMS->useModuleMethods('ThreadRear', array(&$pte_vals['{$THREADREAR}'], $resno)); // "ThreadRear" Hook Point
// Generate static pages one page at a time
for($page = $page_start; $page <= $page_end; $page++){
$dat = ''; $pte_vals['{$THREADS}'] = '';
head($dat, $resno);
// form
$qu = '';
if (USE_QUOTESYSTEM && $resno && isset($_GET['q'])) {
$qq = explode(',', $_GET['q']);
foreach ($qq as $q) {
$q = intval($q);
if ($q<1) continue;
$qu.= '>>'.intval($q)."\r\n";
}
}
$form_dat = '';
form($form_dat, $resno, '', '', '', $qu);
$pte_vals['{$FORMDAT}'] = $form_dat;
unset($qu);
// Output the thread content
for($i = 0; $i < $inner_for_count; $i++){
// Take out the thread number
if($resno) $tID = $resno; // Single thread output (response mode)
else{
if($pagenum == -1 && ($page * PAGE_DEF + $i) >= $threads_count) break; // rebuild Exceeding the index indicates that it is all done
$tID = ($page_start==$page_end) ? $threads[$i] : $threads[$page * PAGE_DEF + $i]; // One page of content (normal mode) / multi-page content (rebuild mode)
$tree_count = $PIO->postCount($tID) - 1; // Number of discussion thread responses
$RES_start = $tree_count - RE_DEF + 1; if($RES_start < 1) $RES_start = 1; // Begin
$RES_amount = RE_DEF; // Take several
$hiddenReply = $RES_start - 1; // The number of responses that are hidden
}
// $RES_start, $RES_amount Take it to calculate the new clue structure (after the tag, part of the response is hidden)
$tree = $PIO->fetchPostList($tID); // The entire discussion is structured in a tree-like manner
$tree_cut = array_slice($tree, $RES_start, $RES_amount); array_unshift($tree_cut, $tID); // Take out a specific range of responses
$posts = $PIO->fetchPosts($tree_cut); // Get the article schema content
$pte_vals['{$THREADS}'] .= arrangeThread($PTE, $tree, $tree_cut, $posts, $hiddenReply, $resno, $arr_kill, $arr_old, $kill_sensor, $old_sensor, true, $adminMode, $inner_for_count); // Leave this function to discuss serial printing
}
$pte_vals['{$PAGENAV}'] = '';
// Page change judgment
$prev = ($resno ? $pagenum : $page) - 1;
$next = ($resno ? $pagenum : $page) + 1;
if($resno){ // Response labels
if(RE_PAGE_DEF > 0){ // The Responses tab is on
$pte_vals['{$PAGENAV}'] .= '<table border="1" id="pager"><tbody><tr><td nowrap="nowrap">';
$pte_vals['{$PAGENAV}'] .= ($prev >= 0) ? '<a rel="prev" href="'.PHP_SELF.'?res='.$resno.'&pagenum='.$prev.'">'._T('prev_page').'</a>' : _T('first_page');
$pte_vals['{$PAGENAV}'] .= "</td><td>";
if($tree_count==0) $pte_vals['{$PAGENAV}'] .= '[<b>0</b>] '; // No response
else{
for($i = 0, $len = $tree_count / RE_PAGE_DEF; $i <= $len; $i++){
if(!$AllRes && $pagenum==$i) $pte_vals['{$PAGENAV}'] .= '[<b>'.$i.'</b>] ';
else $pte_vals['{$PAGENAV}'] .= '[<a href="'.PHP_SELF.'?res='.$resno.'&pagenum='.$i.'">'.$i.'</a>] ';
}
$pte_vals['{$PAGENAV}'] .= $AllRes ? '[<b>'._T('all_pages').'</b>] ' : ($tree_count > RE_PAGE_DEF ? '[<a href="'.PHP_SELF.'?res='.$resno.'">'._T('all_pages').'</a>] ' : '');
}
$pte_vals['{$PAGENAV}'] .= '</td><td nowrap="nowrap">';
$pte_vals['{$PAGENAV}'] .= (!$AllRes && $tree_count > $next * RE_PAGE_DEF) ? '<a href="'.PHP_SELF.'?res='.$resno.'&pagenum='.$next.'">'._T('next_page').'</a>' : _T('last_page');
$pte_vals['{$PAGENAV}'] .= '</td></tr></tbody></table>';
}
}else{ // General labels
$pte_vals['{$PAGENAV}'] .= '<table border="1" id="pager"><tbody><tr>';
if($prev >= 0){
if(!$adminMode && $prev==0) $pte_vals['{$PAGENAV}'] .= '<td><form action="'.PHP_SELF2.'" method="get">';
else{
if($adminMode || (STATIC_HTML_UNTIL != -1) && ($prev > STATIC_HTML_UNTIL)) $pte_vals['{$PAGENAV}'] .= '<td><form action="'.PHP_SELF.'?pagenum='.$prev.'" method="post">';
else $pte_vals['{$PAGENAV}'] .= '<td><form action="'.$prev.PHP_EXT.'" method="get">';
}
$pte_vals['{$PAGENAV}'] .= '<div><input type="submit" value="'._T('prev_page').'" /></div></form></td>';
}else $pte_vals['{$PAGENAV}'] .= '<td nowrap="nowrap">'._T('first_page').'</td>';
$pte_vals['{$PAGENAV}'] .= '<td>';
for($i = 0, $len = $threads_count / PAGE_DEF; $i <= $len; $i++){
if($page==$i) $pte_vals['{$PAGENAV}'] .= "[<b>".$i."</b>] ";
else{
$pageNext = ($i==$next) ? ' rel="next"' : '';
if(!$adminMode && $i==0) $pte_vals['{$PAGENAV}'] .= '[<a href="'.PHP_SELF2.'?">0</a>] ';
elseif($adminMode || (STATIC_HTML_UNTIL != -1 && $i > STATIC_HTML_UNTIL)) $pte_vals['{$PAGENAV}'] .= '[<a href="'.PHP_SELF.'?pagenum='.$i.'"'.$pageNext.'>'.$i.'</a>] ';
else $pte_vals['{$PAGENAV}'] .= '[<a href="'.$i.PHP_EXT.'?"'.$pageNext.'>'.$i.'</a>] ';
}
}
$pte_vals['{$PAGENAV}'] .= '</td>';
if($threads_count > $next * PAGE_DEF){
if($adminMode || (STATIC_HTML_UNTIL != -1) && ($next > STATIC_HTML_UNTIL)) $pte_vals['{$PAGENAV}'] .= '<td><form action="'.PHP_SELF.'?pagenum='.$next.'" method="post">';
else $pte_vals['{$PAGENAV}'] .= '<td><form action="'.$next.PHP_EXT.'" method="get">';
$pte_vals['{$PAGENAV}'] .= '<div><input type="submit" value="'._T('next_page').'" /></div></form></td>';
}else $pte_vals['{$PAGENAV}'] .= '<td nowrap="nowrap">'._T('last_page').'</td>';
$pte_vals['{$PAGENAV}'] .= '</tr></tbody></table>';
}
$dat .= $PTE->ParseBlock('MAIN', $pte_vals);
foot($dat,$resno);
// Remove any preset form values (DO NOT CACHE PRIVATE DETAILS!!!)
$dat = preg_replace('/id="com" cols="48" rows="4" class="inputtext">(.*)<\/textarea>/','id="com" cols="48" rows="4" class="inputtext"></textarea>',$dat);
$dat = preg_replace('/name="email" id="email" size="28" value="(.*)" class="inputtext" \/>/','name="email" id="email" size="28" value="" class="inputtext" />',$dat);
$dat = preg_replace('/replyhl/','',$dat);
// Minify
if(MINIFY_HTML){
$dat = html_minify($dat);
}
// Archive / Output
if($single_page || ($pagenum == -1 && !$resno)){ // Static cache page generation
if(THREAD_PAGINATION){
if($oldCaches = glob(STORAGE_PATH.'cache/catalog-*')){
foreach($oldCaches as $o) unlink($o); // Clear old catalog caches
}
if($oldCaches = glob(STORAGE_PATH.'cache/api-0.*')){
foreach($oldCaches as $o) unlink($o); // Clear old API caches
}
}
if($page==0) $logfilename = PHP_SELF2;
else $logfilename = $page.PHP_EXT;
$fp = fopen($logfilename, 'w');
stream_set_write_buffer($fp, 0);
fwrite($fp, $dat);
fclose($fp);
@chmod($logfilename, 0666);
if(STATIC_HTML_UNTIL != -1 && STATIC_HTML_UNTIL==$page) break; // Page Limit
}else{ // PHP output (responsive mode/regular dynamic output)
if(THREAD_PAGINATION && !$adminMode && $resno && !isset($_GET['upseries'])){ // Thread pagination
if($oldCaches = glob(STORAGE_PATH.'cache/api-'.$resno.'.*')){
foreach($oldCaches as $o) unlink($o); // Clear old API caches
}
if($oldCaches = glob($cacheFile.'*')){
foreach($oldCaches as $o) unlink($o); // Clear old caches
}
@$fp = fopen($cacheGzipPrefix.$cacheFile.$cacheETag, 'w');
if($fp) { // Write new caches
fwrite($fp, $dat);
fclose($fp);
@chmod($cacheFile.$cacheETag, 0666);
header('ETag: "'.$cacheETag.'"');
header('Connection: close');
}
}
echo $dat;
break;
}
}
}
/* Output thread schema */
function arrangeThread($PTE, $tree, $tree_cut, $posts, $hiddenReply, $resno=0, $arr_kill, $arr_old, $kill_sensor, $old_sensor, $showquotelink=true, $adminMode=false, $threads_shown=0){
$PIO = PMCLibrary::getPIOInstance();
$FileIO = PMCLibrary::getFileIOInstance();
$PMS = PMCLibrary::getPMSInstance();
$thdat = ''; // Discuss serial output codes
$posts_count = count($posts); // Number of cycles
if(gettype($tree_cut) == 'array') $tree_cut = array_flip($tree_cut); // array_flip + isset Search Law
if(gettype($tree) == 'array') $tree_clone = array_flip($tree);
// $i = 0 (first article), $i = 1~n (response)
for($i = 0; $i < $posts_count; $i++){
$imgsrc = $img_thumb = $imgwh_bar = '';
$IMG_BAR = $REPLYBTN = $QUOTEBTN = $BACKLINKS = $POSTFORM_EXTRA = $WARN_OLD = $WARN_BEKILL = $WARN_ENDREPLY = $WARN_HIDEPOST = '';
extract($posts[$i]); // Take out the thread content setting variable
// Set the field value
if(CLEAR_SAGE) $email = preg_replace('/^sage( *)/i', '', trim($email)); // Clear the "sage" keyword from the e-mail
if(ALLOW_NONAME==2){ // Forced beheading
if($email) $now = "<a href=\"mailto:$email\">$now</a>";
}else{
if($email) $name = "<a href=\"mailto:$email\">$name</a>";
}
$com = quote_link($com);
$com = quote_unkfunc($com);
// Configure attachment display
if ($ext) {
if(!$fname) $fname = $tim;
$truncated = (strlen($fname)>40 ? substr($fname,0,40).'(…)' : $fname);
if ($fname=='SPOILERS') {
$truncated=$fname;
} else {
$truncated.=$ext;
$fname.=$ext;
}
$imageURL = $FileIO->getImageURL($tim.$ext); // image URL
$thumbName = $FileIO->resolveThumbName($tim); // thumb Name
$imgsrc = '<a href="'.$imageURL.'" target="_blank" rel="nofollow"><img src="'.STATIC_URL.'image/nothumb.gif" class="postimg" alt="'.$imgsize.'" hspace="20" vspace="3" border="0" align="left" /></a>'; // Default display style (when no preview image)
if($tw && $th){
if ($thumbName != false){ // There is a preview image
$thumbURL = $FileIO->getImageURL($thumbName); // thumb URL
// $img_thumb = '<small>'._T('img_sample').'</small>';
$imgsrc = '<a href="'.$imageURL.'" target="_blank" rel="nofollow"><img src="'.$thumbURL.'" width="'.$tw.'" height="'.$th.'" class="postimg" alt="'.$imgsize.'" title="Click to show full image" hspace="20" vspace="3" border="0" align="left" /></a>';
}
if(SHOW_IMGWH) $imgwh_bar = ', '.$imgw.'x'.$imgh; // Displays the original length and width dimensions of the attached image file
} else $imgsrc = '';
$IMG_BAR = _T('img_filename').'<a href="'.$imageURL.'" target="_blank" rel="nofollow" onmouseover="this.textContent=\''.$fname.'\';" onmouseout="this.textContent=\''.$truncated.'\'"> '.$truncated.'</a> <a href="'.$imageURL.'" download="'.$fname.'"><div class="download"></div></a> <small>('.$imgsize.$imgwh_bar.')</small> '.$img_thumb;
}
// Set the response/reference link
if(USE_QUOTESYSTEM) {
$qu = $_GET['q']??''; if ($qu) $qu.= ',';
if($resno){ // Response mode
if($showquotelink) $QUOTEBTN = '<a href="'.PHP_SELF.'?res='.$tree[0]."&q=".htmlspecialchars($qu)."".$no.'#postform" class="qu" title="Quote">'.strval($no).'</a>';
else $QUOTEBTN = '<a href="'.PHP_SELF.'?res='.$tree."&q=".htmlspecialchars($qu)."".$no.'#postform" title="Quote">'.strval($no).'</a>';
}else{
if(!$i) $REPLYBTN = '[<a href="'.PHP_SELF.'?res='.$no.'">'._T('reply_btn').'</a>]'; // First article
$QUOTEBTN = '<a href="'.PHP_SELF.'?res='.$tree[0]."&q=".htmlspecialchars($qu)."".$no.'#postform" title="Quote">'.$no.'</a>';
}
unset($qu);
if (USE_BACKLINK) {
$blref = $PIO->searchPost(array('((?:>| ^~)+)(?:No\.)?('.$no.')\b'), 'com', 'REG');
if ($blcnt=count($blref)) {
$blref = array_reverse($blref);
foreach ($blref as $ref) {
$BACKLINKS.= ' <a href="'.PHP_SELF.'?res='.($ref['resto']?$ref['resto']:$ref['no']).'#p'.$ref['no'].'" class="backlink">>>'.$ref['no'].'</a>';
}
}
}
} else {
if($resno&&!$i) $REPLYBTN = '[<a href="'.PHP_SELF.'?res='.$no.'">'._T('reply_btn').'</a>]';
$QUOTEBTN = $no;
}
if($adminMode){ // Front-end management mode
$modFunc = '';
$PMS->useModuleMethods('AdminList', array(&$modFunc, $posts[$i], $resto)); // "AdminList" Hook Point
$POSTFORM_EXTRA .= $modFunc;
}
// Set thread properties
if(STORAGE_LIMIT && $kill_sensor) if(isset($arr_kill[$no])) $WARN_BEKILL = '<span class="warning">'._T('warn_sizelimit').'</span><br />'; // Predict to delete too large files
if(!$i){ // 首篇 Only
if($old_sensor) if(isset($arr_old[$no])) $WARN_OLD = '<span class="warning">'._T('warn_oldthread').'</span><br />'; // Reminder that it is about to be deleted
$flgh = $PIO->getPostStatus($status);
if($hiddenReply) $WARN_HIDEPOST = '<span class="omittedposts">'._T('notice_omitted',$hiddenReply).'</span><br />'; // There is a hidden response
}
// Automatically link category labels
if(USE_CATEGORY){
$ary_category = explode(',', str_replace(',', ',', $category)); $ary_category = array_map('trim', $ary_category);
$ary_category_count = count($ary_category);
$ary_category2 = array();
for($p = 0; $p < $ary_category_count; $p++){
if($c = $ary_category[$p]) $ary_category2[] = '<a href="'.PHP_SELF.'?mode=category&c='.urlencode($c).'">'.$c.'</a>';
}
$category = implode(', ', $ary_category2);
}else $category = '';
$THREADNAV = '<a href="#postform">■</a>
<a href="#top">▲</a>
<a href="#bottom">▼</a>
';
// Final output
if($i){ // Response
$arrLabels = array('{$NO}'=>$no, '{$RESTO}'=>$resto, '{$SUB}'=>$sub, '{$NAME}'=>$name, '{$NOW}'=>$now, '{$CATEGORY}'=>$category, '{$QUOTEBTN}'=>$QUOTEBTN, '{$IMG_BAR}'=>$IMG_BAR, '{$IMG_SRC}'=>$imgsrc, '{$WARN_BEKILL}'=>$WARN_BEKILL, '{$NAME_TEXT}'=>_T('post_name'), '{$CATEGORY_TEXT}'=>_T('post_category'), '{$SELF}'=>PHP_SELF, '{$COM}'=>$com, '{$POSTINFO_EXTRA}'=>$POSTFORM_EXTRA, '{$THREADNAV}'=>$THREADNAV, '{$BACKLINKS}'=>$BACKLINKS, '{$IS_THREAD}'=>!!$resno);
if($resno) $arrLabels['{$RESTO}']=$resno;
$PMS->useModuleMethods('ThreadReply', array(&$arrLabels, $posts[$i], $resno)); // "ThreadReply" Hook Point
$thdat .= $PTE->ParseBlock('REPLY',$arrLabels);
}else{ // First Article
$arrLabels = array('{$NO}'=>$no, '{$RESTO}'=>$no, '{$SUB}'=>$sub, '{$NAME}'=>$name, '{$NOW}'=>$now, '{$CATEGORY}'=>$category, '{$QUOTEBTN}'=>$QUOTEBTN, '{$REPLYBTN}'=>$REPLYBTN, '{$IMG_BAR}'=>$IMG_BAR, '{$IMG_SRC}'=>$imgsrc, '{$WARN_OLD}'=>$WARN_OLD, '{$WARN_BEKILL}'=>$WARN_BEKILL, '{$WARN_ENDREPLY}'=>$WARN_ENDREPLY, '{$WARN_HIDEPOST}'=>$WARN_HIDEPOST, '{$NAME_TEXT}'=>_T('post_name'), '{$CATEGORY_TEXT}'=>_T('post_category'), '{$SELF}'=>PHP_SELF, '{$COM}'=>$com, '{$POSTINFO_EXTRA}'=>$POSTFORM_EXTRA, '{$THREADNAV}'=>$THREADNAV, '{$BACKLINKS}'=>$BACKLINKS, '{$IS_THREAD}'=>!!$resno);
if($resno) $arrLabels['{$RESTO}']=$resno;
$PMS->useModuleMethods('ThreadPost', array(&$arrLabels, $posts[$i], $resno)); // "ThreadPost" Hook Point
$thdat .= $PTE->ParseBlock('THREAD',$arrLabels);
}
}
$thdat .= $PTE->ParseBlock('THREADSEPARATE',($resno)?array('{$RESTO}'=>$resno):array());
return $thdat;
}
/* post preview */
function previewPost($tmpno) {
$PIO = PMCLibrary::getPIOInstance();
$PTE = PMCLibrary::getPTEInstance();
$PMS = PMCLibrary::getPMSInstance();
extract($PIO->fetchPosts($tmpno)[0]);
if(USE_CATEGORY){
$ary_category = explode(',', str_replace(',', ',', $category)); $ary_category = array_map('trim', $ary_category);
$ary_category_count = count($ary_category);
$ary_category2 = array();
for($p = 0; $p < $ary_category_count; $p++){
if($c = $ary_category[$p]) $ary_category2[] = '<a href="'.PHP_SELF.'?mode=category&c='.urlencode($c).'">'.$c.'</a>';
}
$category = implode(', ', $ary_category2);
}else $category = '';
$com = quote_link($com);
$com = quote_unkfunc($com);
$dat = '';
head($dat);
if (!$resto) $dat.= '[<a href="'.PHP_SELF2.'">Return</a>]';
form($dat, $resto, $_POST['name'], $_POST['email'], $_POST['sub'], $_POST['com'], $_POST['category'], true);
$dat.= '[<a href="'.$_SERVER['HTTP_REFERER'].'" onclick="event.preventDefault();history.go(-1);">Back</a>]';
if(!TEXTBOARD_ONLY && $_FILES['upfile']['error']!=UPLOAD_ERR_NO_FILE) $dat.= ' <span class="warning">Files are not previewed.</span>';
$arrLabels = array('{$NO}'=>$no, '{$RESTO}'=>$resto,
'{$SUB}'=>$sub, '{$NAME}'=>$name, '{$NOW}'=>$now, '{$CATEGORY}'=>$category, '{$COM}'=>$com,
'{$QUOTEBTN}'=>"<a href=\"#postform\">$no</a>", '{$SELF}'=>PHP_SELF,
'{$IMG_BAR}'=>'', '{$IMG_SRC}'=>'', '{$REPLYBTN}'=>'', '{$IS_PREVIEW}'=>true,
'{$NAME_TEXT}'=>_T('post_name'), '{$CATEGORY_TEXT}'=>_T('post_category'), '{$BACKLINKS}'=>'',
'{$WARN_OLD}'=>'', '{$WARN_BEKILL}'=>'', '{$WARN_ENDREPLY}'=>'', '{$WARN_HIDEPOST}'=>'', '{$POSTINFO_EXTRA}'=>'');
$dat.= $PTE->ParseBlock($resto?'REPLY':'THREAD',$arrLabels);
$dat.= $PTE->ParseBlock('THREADSEPARATE',array());
foot($dat,!!$resto);
echo $dat;
}
/* Write to log file */
function regist($preview=false){
global $BAD_STRING, $BAD_FILEMD5, $BAD_IPADDR, $LIMIT_SENSOR, $THUMB_SETTING;
$PIO = PMCLibrary::getPIOInstance();
$FileIO = PMCLibrary::getFileIOInstance();
$PMS = PMCLibrary::getPMSInstance();
$fname = $dest = $mes = ''; $up_incomplete = 0; $is_admin = false;
$delta_totalsize = 0; // The change in the total file size
if(!$_SERVER['HTTP_REFERER']
|| !$_SERVER['HTTP_USER_AGENT']
|| preg_match("/^(curl|wget)/i", $_SERVER['HTTP_USER_AGENT']) ){
error('You look like a robot.', $dest);
}
if($_SERVER['REQUEST_METHOD'] != 'POST') error(_T('regist_notpost')); // Informal POST method
$name = CleanStr($_POST['name']??'');
$email = CleanStr($_POST['email']??'');
$sub = CleanStr($_POST['sub']??'');
$com = $_POST['com']??'';
$pwd = $_POST['pwd']??'';
$category = CleanStr($_POST['category']??'');
$resto = intval($_POST['resto']??0);
$pwdc = $_COOKIE['pwdc']??'';
$ip = getREMOTE_ADDR();
//$host = gethostbyaddr($ip);
$host = $ip; //This should improve reliability by a longshot
$PMS->useModuleMethods('RegistBegin', array(&$name, &$email, &$sub, &$com, array('file'=>&$upfile, 'path'=>&$upfile_path, 'name'=>&$upfile_name, 'status'=>&$upfile_status), array('ip'=>$ip, 'host'=>$host), $resto)); // "RegistBegin" Hook Point
// Blocking: IP/Hostname/DNSBL Check Function
$baninfo = '';
if(BanIPHostDNSBLCheck($ip, $host, $baninfo)) error(_T('regist_ipfiltered', $baninfo));
// Block: Restrict the text that appears (text filter?)
foreach($BAD_STRING as $value){
if(strpos($com, $value)!==false || strpos($sub, $value)!==false || strpos($name, $value)!==false || strpos($email, $value)!==false){
error(_T('regist_wordfiltered'));
}
}
// Check if you enter Sakura Japanese kana (kana = Japanese syllabary)
foreach(array($name, $email, $sub, $com) as $anti) if(anti_sakura($anti)) error(_T('regist_sakuradetected'));
// Time
$time = $_SERVER['REQUEST_TIME'];
$tim = $time.substr($_SERVER['REQUEST_TIME_FLOAT'],2,3);
if(!TEXTBOARD_ONLY) {
$upfile = CleanStr($_FILES['upfile']['tmp_name']??'');
$upfile_path = $_POST['upfile_path']??'';
$upfile_name = $_FILES['upfile']['name']??'';
$upfile_status = $_FILES['upfile']['error']??UPLOAD_ERR_NO_FILE;
// Determine the upload status
switch($upfile_status){
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_FORM_SIZE:
error('ERROR: The file is too large.(upfile)');
break;
case UPLOAD_ERR_INI_SIZE:
error('ERROR: The file is too large.(php.ini)');
break;
case UPLOAD_ERR_PARTIAL:
error('ERROR: The uploaded file was only partially uploaded.');
break;
case UPLOAD_ERR_NO_FILE:
if(!$resto && !isset($_POST['noimg']) && !$preview) error(_T('regist_upload_noimg'));
break;
case UPLOAD_ERR_NO_TMP_DIR:
error('ERROR: Missing a temporary folder.');
break;
case UPLOAD_ERR_CANT_WRITE:
error('ERROR: Failed to write file to disk.');
break;
default:
error('ERROR: Unable to save the uploaded file.');
}
// If there is an uploaded file, process the additional image file
if($upfile && (@is_uploaded_file($upfile) || @is_file($upfile)) && !$preview){
// 1. Save the file first
$dest = STORAGE_PATH .$tim.'.tmp';
@move_uploaded_file($upfile, $dest) or @copy($upfile, $dest);
@chmod($dest, 0666);
if(!is_file($dest)) error(_T('regist_upload_filenotfound'), $dest);
// 2. Determine whether there is any interruption in the process of uploading additional image files
$upsizeTTL = $_SERVER['CONTENT_LENGTH'];
if(isset($_FILES['upfile'])){ // Only when there is transmitted data does it need to be calculated, so as to avoid white work
$upsizeHDR = 0;
// File path: IE has the full path attached, so you have to get it from the hidden form
$tmp_upfile_path = $upfile_name;
if($upfile_path) $tmp_upfile_path = get_magic_quotes_gpc() ? stripslashes($upfile_path) : $upfile_path;
list(,$boundary) = explode('=', $_SERVER['CONTENT_TYPE']);
foreach($_POST as $header => $value){ // Form fields transfer data
$upsizeHDR += strlen('--'.$boundary."\r\n")
+ strlen('Content-Disposition: form-data; name="'.$header.'"'."\r\n\r\n".(get_magic_quotes_gpc()?stripslashes($value):$value)."\r\n");
}
// The attached image file field transmits the data
$upsizeHDR += strlen('--'.$boundary."\r\n")
+ strlen('Content-Disposition: form-data; name="upfile"; filename="'.$tmp_upfile_path."\"\r\n".'Content-Type: '.$_FILES['upfile']['type']."\r\n\r\n")
+ strlen("\r\n--".$boundary."--\r\n")
+ $_FILES['upfile']['size']; // Send attachment data
// The upload byte difference exceeds HTTP_UPLOAD_DIFF: The upload of additional image files is incomplete
if(($upsizeTTL - $upsizeHDR) > HTTP_UPLOAD_DIFF){
if(KILL_INCOMPLETE_UPLOAD){
unlink($dest);
die(_T('regist_upload_killincomp')); // The prompt to the browser, if the user still sees it, will not be puzzled
}else $up_incomplete = 1;
}
}
// 3. Check whether it is an acceptable file
$size = @getimagesize($dest);
$imgsize = @filesize($dest); // File size
$imgsize = ($imgsize>=1024) ? (int)($imgsize/1024).' KB' : $imgsize.' B'; // Discrimination of KB and B
$fname = pathinfo($upfile_name, PATHINFO_FILENAME);
$ext = '.'.strtolower(pathinfo($upfile_name, PATHINFO_EXTENSION));
if (is_array($size)) {
// File extension detection from Heyuri
// Don't assume the script supports the file type just because the extension is here.
switch($size[2]){ // Determine the format of the uploaded image file
case IMAGETYPE_GIF: $ext = '.gif'; break;
case IMAGETYPE_JPEG:
case IMAGETYPE_JPEG2000: $ext = '.jpg'; break;
case IMAGETYPE_PNG: $ext = '.png'; break;
case IMAGETYPE_SWF:
case IMAGETYPE_SWC: $ext = '.swf';
if(!($size[0]&&$size[1])){
$size[0]=MAX_W;
$size[1]=MAX_H;
}
break;
case IMAGETYPE_PSD: $ext = '.psd'; break;
case IMAGETYPE_BMP: $ext = '.bmp'; break;
case IMAGETYPE_WBMP: $ext = '.wbmp'; break;
case IMAGETYPE_XBM: $ext = '.xbm'; break;
case IMAGETYPE_TIFF_II:
case IMAGETYPE_TIFF_MM:
case IMAGETYPE_IFF: $ext = '.tiff'; break;
case IMAGETYPE_JB2: $ext = '.jb2'; break;
case IMAGETYPE_JPC: $ext = '.jpc'; break;
case IMAGETYPE_JP2: $ext = '.jp2'; break;
case IMAGETYPE_JPX: $ext = '.jpx'; break;
case IMAGETYPE_ICO: $ext = '.ico'; break;
case IMAGETYPE_WEBP: $ext = '.webp'; break;
}
} else {
$size = array(0, 0, 0);
$video_exts = explode('|', strtolower(VIDEO_EXT));
if(array_search(substr($ext, 1), $video_exts)!==false) {
// Video thumbs
$tmpfile = tempnam(sys_get_temp_dir(), "thumbnail_");
rename($tmpfile, $tmpfile.".jpg");
$tmpfile .= ".jpg";
@exec("ffmpeg -y -i ".$dest." -ss 00:00:1 -vframes 1 ".$tmpfile." 2>&1");
$size = @getimagesize($tmpfile);
$imgsize = @filesize($dest); // File size
$imgsize = ($imgsize>=1024) ? (int)($imgsize/1024).' KB' : $imgsize.' B'; // Discrimination of KB and B
}
}
$allow_exts = explode('|', strtolower(ALLOW_UPLOAD_EXT)); // Accepted additional image file extension
if(array_search(substr($ext, 1), $allow_exts)===false) error(_T('regist_upload_notsupport'), $dest); // Uploaded file not allowed due to wrong file extension
// Block setting: Restrict the upload of MD5 checkcodes for additional images
$md5chksum = md5_file($dest); // File MD%
if(array_search($md5chksum, $BAD_FILEMD5)!==false) error(_T('regist_upload_blocked'), $dest); // If the MD5 checkcode of the uploaded file is in the block list, the upload is blocked
// 4. Calculate the thumbnail display size of the additional image file
$W = $imgW = $size[0];
$H = $imgH = $size[1];
$MAXW = $resto ? MAX_RW : MAX_W;
$MAXH = $resto ? MAX_RH : MAX_H;
if($W > $MAXW || $H > $MAXH){
$W2 = $MAXW / $W;
$H2 = $MAXH / $H;
$key = ($W2 < $H2) ? $W2 : $H2;
$W = ceil($W * $key);
$H = ceil($H * $key);
}
if ($ext=='.swf') $W = $H = 0; // dumb flash file thinks it's an image lol.
$mes = _T('regist_uploaded', CleanStr($upfile_name));
}
} else {
$upfile = '';
$upfile_path = '';
$upfile_name = '';
$upfile_status = 4;
}
// Check the form field contents and trim them
if(strlenUnicode($name) > INPUT_MAX) error(_T('regist_nametoolong'), $dest);
if(strlenUnicode($email) > INPUT_MAX) error(_T('regist_emailtoolong'), $dest);
if(strlenUnicode($sub) > INPUT_MAX) error(_T('regist_topictoolong'), $dest);
if(strlenUnicode($resto) > INPUT_MAX) error(_T('regist_longthreadnum'), $dest);
setrawcookie('namec', rawurlencode($name), time()+7*24*3600);
// E-mail / Title trimming
$email = str_replace("\r\n", '', $email); $sub = str_replace("\r\n", '', $sub);
// Tripcode crap
$name = str_replace('&#', '&&', $name); // otherwise HTML numeric entities will explode!
list($name, $trip, $sectrip) = str_replace('&%', '&#', explode('#',$name.'##'));
if ($trip) {
$salt = strtr(preg_replace('/[^\.-z]/', '.', substr($trip.'H.',1,2)), ':;<=>?@[\\]^_`', 'ABCDEFGabcdef');
$trip = '!'.substr(crypt($trip, $salt), -10);
}
if ($sectrip) {
if ($level=valid($sectrip)) {
// Moderator capcode
switch ($level) {
case 1: if (JCAPCODE_FMT) $name = sprintf(JCAPCODE_FMT, $name); break;
case 2: if (MCAPCODE_FMT) $name = sprintf(MCAPCODE_FMT, $name); break;
case 3: if (ACAPCODE_FMT) $name = sprintf(ACAPCODE_FMT, $name); break;
}
} else {
// User
$sha =str_rot13(base64_encode(pack("H*",sha1($sectrip.TRIPSALT))));
$sha = substr($sha,0,10);
$trip = '!!'.$sha;
}
}
if(!$name || preg_match("/^[ | |]*$/", $name)){
if(ALLOW_NONAME) $name = DEFAULT_NONAME;
else error(_T('regist_withoutname'), $dest);
}
$name = "<b>$name</b>$trip";
if (isset(CAPCODES[$trip])) {
$capcode = CAPCODES[$trip];
$name = '<font color="'.$capcode['color'].'">'.$name.'<b>'.$capcode['cap'].'</b>'.'</font>';
}
if(stristr($email, 'vipcode') && defined('VIPDEF')) {
$name .= ' <img src="'.STATIC_URL.'vip.gif" title="This user is a VIP user" style="vertical-align: middle;margin-top: -2px;" alt="VIP">';
}
$email = preg_replace('/^vipcode$/i', '', $email);
// Text trimming
if((strlenUnicode($com) > COMM_MAX) && !$is_admin) error(_T('regist_commenttoolong'), $dest);
$com = CleanStr($com, $is_admin); // The$ is_admin parameter is introduced because when the administrator starts, the administrator is allowed to set whether to use HTML according to config.
if(!$com && $upfile_status==4) error(TEXTBOARD_ONLY?'ERROR: No text entered.':_T('regist_withoutcomment'));
$com = str_replace(array("\r\n", "\r"), "\n", $com); $com = preg_replace("/\n(( | )*\n){3,}/", "\n", $com);
if(!BR_CHECK || substr_count($com,"\n") < BR_CHECK) $com = nl2br($com); // Newline characters are replaced by <br />
$com = str_replace("\n", '', $com); // If there are still \n newline characters, cancel the newline
if(AUTO_LINK) $com = auto_link($com);
if (FORTUNES && stristr($email, 'fortune')) {
if (!$preview) {
$fortunenum=array_rand(FORTUNES);
$fortcol=sprintf("%02x%02x%02x",
127+127*sin(2*M_PI*$fortunenum/count(FORTUNES)),
127+127*sin(2*M_PI*$fortunenum/count(FORTUNES)+2/3*M_PI),
127+127*sin(2*M_PI*$fortunenum/count(FORTUNES)+4/3*M_PI));
$com = "<font color=\"#$fortcol\"><b>Your fortune: ".FORTUNES[$fortunenum]."</b></font><br/><br/>$com";
} else {
$com = "<font color=\"#F00\"><b>DON'T TRY TO CHEAT THE SYSTEM!</b></font><br /><br />$com";
}
}
if (ROLL && stristr($email, 'roll')) {
if (!$preview) {
$rollnum=array_rand(ROLL);
$fortcol=sprintf("%02x%02x%02x",
127+127*sin(2*M_PI*$rollnum/count(ROLL)),
127+127*sin(2*M_PI*$rollnum/count(ROLL)+2/3*M_PI),
127+127*sin(2*M_PI*$rollnum/count(ROLL)+4/3*M_PI));
$com = "<font color='#ff0000'><b>[NUMBER: ".rand(1,10000)."]</b></font><br/><br/>$com";
$email = preg_replace('/^roll( *)/i', '');
} else {
$com = "<font color=\"#F00\"><b>DON'T TRY TO CHEAT THE SYSTEM!</b></font><br /><br />$com";
}
}
// Default content
if(!$sub || preg_match("/^[ | |]*$/", $sub)) $sub = DEFAULT_NOTITLE;
if(!$com || preg_match("/^[ | |\t]*$/", $com)) $com = DEFAULT_NOCOMMENT;
// Trimming label style
if($category && USE_CATEGORY){
$category = explode(',', $category); // Disassemble the labels into an array
$category = ','.implode(',', array_map('trim', $category)).','; // Remove the white space and merge into a single string (left and right, you can directly search in the form XX)
}else{ $category = ''; }
if($up_incomplete) $com .= '<br /><br /><span class="warning">'._T('notice_incompletefile').'</span>'; // Tips for uploading incomplete additional image files
// Password and time style
if($pwd=='') $pwd = ($pwdc=='') ? substr(rand(),0,8) : $pwdc;
$pass = $pwd ? substr(md5($pwd), 2, 8) : '*'; // Generate a password for true storage judgment (the 8 characters at the bottom right of the imageboard where it says Password ******** SUBMIT for deleting posts)
$youbi = array(_T('sun'),_T('mon'),_T('tue'),_T('wed'),_T('thu'),_T('fri'),_T('sat'));
$yd = $youbi[gmdate('w', $time+TIME_ZONE*60*60)];
$now = gmdate('Y/m/d', $time+TIME_ZONE*60*60).'('.(string)$yd.')'.gmdate('H:i', $time+TIME_ZONE*60*60);
if(DISP_ID){ // ID
if(valid() == LEV_ADMIN and DISP_ID == 2) $now .= ' ID:ADMIN'; else
if(valid() == LEV_MODERATOR and DISP_ID == 2) $now .= ' ID:MODERATOR'; else
if(stristr($email, 'sage') and DISP_ID == 2) $now .= ' ID:Heaven';
else {
switch (ID_MODE) {
case 0:
$now .= ' ID:'.substr(crypt(md5(getREMOTE_ADDR().IDSEED.($resto?$resto:($PIO->getLastPostNo("beforeCommit")+1))),'id'), -8);
break;
case 1:
$now .= ' ID:'.substr(crypt(md5(getREMOTE_ADDR().IDSEED.($resto?$resto:($PIO->getLastPostNo("beforeCommit")+1)).gmdate('Ymd', $time+TIME_ZONE*60*60)),'id'), -8);
break;
}
}
}
// Continuous submission / same additional image check
$checkcount = 50; // Check 50 by default
$pwdc = substr(md5($pwdc), 2, 8); // Cookies Password
if (valid()<LEV_MODERATOR or defined('VIPDEF')) {
if($PIO->isSuccessivePost($checkcount, $com, $time, $pass, $pwdc, $host, $upfile_name))
error(_T('regist_successivepost'), $dest); // Continuous submission check
if($dest){ if($PIO->isDuplicateAttachment($checkcount, $md5chksum)) error(_T('regist_duplicatefile'), $dest); } // Same additional image file check
}
if($resto) $ThreadExistsBefore = $PIO->isThread($resto);
// Deletion of old articles
if(PIOSensor::check('delete', $LIMIT_SENSOR)){
$delarr = PIOSensor::listee('delete', $LIMIT_SENSOR);
if(count($delarr)){
deleteCache($delarr);
$PMS->useModuleMethods('PostOnDeletion', array($delarr, 'recycle')); // "PostOnDeletion" Hook Point
$files = $PIO->removePosts($delarr);
if(count($files)) $delta_totalsize -= $FileIO->deleteImage($files); // Update delta value
}
}
// Additional image file capacity limit function is enabled: delete oversized files
if(STORAGE_LIMIT && STORAGE_MAX > 0){
$tmp_total_size = $FileIO->getCurrentStorageSize(); // Get the current size of additional images
if($tmp_total_size > STORAGE_MAX){
$files = $PIO->delOldAttachments($tmp_total_size, STORAGE_MAX, false);
$delta_totalsize -= $FileIO->deleteImage($files);
}
}
// Determine whether the article you want to respond to has just been deleted
if($resto){
if($ThreadExistsBefore){ // If the thread of the discussion you want to reply to exists
if(!$PIO->isThread($resto)){ // If the thread of the discussion you want to reply to has been deleted
// Update the data source in advance, and this new addition is not recorded
$PIO->dbCommit();
updatelog();
error(_T('regist_threaddeleted'), $dest);
}else{ // Check that the thread is set to suppress response (by the way, take out the post time of the original post)
$post = $PIO->fetchPosts($resto); // [Special] Take a single article content, but the $post of the return also relies on [$i] to switch articles!
list($chkstatus, $chktime) = array($post[0]['status'], $post[0]['tim']);
$chktime = substr($chktime, 0, -3); // Remove microseconds (the last three characters)
$flgh = $PIO->getPostStatus($chkstatus);
}
}else error(_T('thread_not_found'), $dest); // Does not exist
}
// Calculate field values
$no = $PIO->getLastPostNo('beforeCommit') + 1;
isset($ext) ? 0 : $ext = '';
isset($imgW) ? 0 : $imgW = 0;
isset($imgH) ? 0 : $imgH = 0;
isset($imgsize) ? 0 : $imgsize = '';
isset($W) ? 0 : $W = 0;
isset($H) ? 0 : $H = 0;
isset($md5chksum) ? 0 : $md5chksum = '';
$age = false;
$status = '';
if ($resto) {
if ($PIO->postCount($resto) <= MAX_RES || MAX_RES==0) {
if(!MAX_AGE_TIME || (($time - $chktime) < (MAX_AGE_TIME * 60 * 60))) $age = true; // Discussion threads are not expired
}
if (NOTICE_SAGE && stristr($email, 'sage')) {
$age = false;
if (!CLEAR_SAGE) $name.= ' <b><font color="#F00">SAGE!</font></b>';
}
}
// noko
$redirect = PHP_SELF2.'?'.$tim;
if (strstr($email, 'noko') && !strstr($email, 'nonoko')) {
$redirect = PHP_SELF.'?res='.($resto?$resto:$no);
if (!strstr($email, 'noko2')) $redirect.= "#p$no";
}
$email = preg_replace('/^(no)+ko\d*$/i', '', $email);
$PMS->useModuleMethods('RegistBeforeCommit', array(&$name, &$email, &$sub, &$com, &$category, &$age, $dest, $resto, array($W, $H, $imgW, $imgH, $tim, $ext), &$status)); // "RegistBeforeCommit" Hook Point
$PIO->addPost($no,$resto,$md5chksum,$category,$tim,$fname,$ext,$imgW,$imgH,$imgsize,$W,$H,$pass,$now,$name,$email,$sub,$com,$host,$age,$status);
if($preview) {
previewPost($no);
return;
}
logtime("Post No.$no registered", valid());
// Formal writing to storage
$PIO->dbCommit();
$lastno = $PIO->getLastPostNo('afterCommit'); // Get this new article number
$PMS->useModuleMethods('RegistAfterCommit', array($lastno, $resto, $name, $email, $sub, $com)); // "RegistAfterCommit" Hook Point
// Cookies storage: password and e-mail part, for one week
setcookie('pwdc', $pwd, time()+7*24*3600);
setcookie('emailc', $email, time()+7*24*3600);
if($dest && is_file($dest)){
$destFile = IMG_DIR.$tim.$ext; // Image file storage location
$thumbFile = THUMB_DIR.$tim.'s.'.$THUMB_SETTING['Format']; // Preview image storage location
if (defined(CDN_DIR)) {
$destFile = CDN_DIR.$destFile;
$thumbFile = CDN_DIR.$thumbFile;
}
if(USE_THUMB !== 0){ // Generate preview image
$thumbType = USE_THUMB; if(USE_THUMB==1){ $thumbType = $THUMB_SETTING['Method']; }
require(ROOTPATH.'lib/thumb/thumb.'.$thumbType.'.php');
if (isset($tmpfile)) $thObj = new ThumbWrapper($tmpfile, $imgW, $imgH);
else $thObj = new ThumbWrapper($dest, $imgW, $imgH);
$thObj->setThumbnailConfig($W, $H, $THUMB_SETTING);
$thObj->makeThumbnailtoFile($thumbFile);
@chmod($thumbFile, 0666);
unset($thObj);
}
rename($dest, $destFile);
if(file_exists($destFile)){
$FileIO->uploadImage($tim.$ext, $destFile, filesize($destFile));
$delta_totalsize += filesize($destFile);
}
if(file_exists($thumbFile)){
$FileIO->uploadImage($tim.'s.'.$THUMB_SETTING['Format'], $thumbFile, filesize($thumbFile));
$delta_totalsize += filesize($thumbFile);
}
}
// webhooks
if(defined('IRC_WH')){
$url = 'https:'.fullURL().PHP_SELF."?res=".($resto?$resto:$no)."#p$no";
$stream = stream_context_create([
'ssl' =>[
'verify_peer'=>false,
'verify_peer_name'=>false,
],
'http'=>[
'method'=>'POST',
'header'=>'content-type:application/x-www-form-urlencoded',
'content'=>'content='.htmlspecialchars_decode(($resto?'New post':'New thread')." <$url>", ENT_QUOTES),
]
]);
@file_get_contents(IRC_WH, false, $stream);
}
if(defined('DISCORD_WH')){
$url = 'https:'.fullURL().PHP_SELF."?res=".($resto?$resto:$no)."#p$no";
$stream = stream_context_create([
'http'=>[
'method'=>'POST',
'header'=>'content-type:application/x-www-form-urlencoded',
'content'=>http_build_query([
'content'=>($resto?'New post':'New thread')." <$url>",
]),
]
]);
@file_get_contents(DISCORD_WH, false, $stream);
}
// webhooks with titles
if(defined('IRC_WH_NEWS') && !$resto){
$url = 'https:'.fullURL().PHP_SELF."?res=".($resto?$resto:$no);
$stream = stream_context_create([
'ssl' =>[
'verify_peer'=>false,
'verify_peer_name'=>false,
],
'http'=>[
'method'=>'POST',
'header'=>'content-type:application/x-www-form-urlencoded',
'content'=>'content='.htmlspecialchars_decode(($resto?'New post':''." '$sub'")." <$url>", ENT_QUOTES),
]
]);
@file_get_contents(IRC_WH_NEWS, false, $stream);
}
if(defined('DISCORD_WH_NEWS') && !$resto){
$url = 'https:'.fullURL().PHP_SELF."?res=".($resto?$resto:$no);
$stream = stream_context_create([
'http'=>[
'method'=>'POST',
'header'=>'content-type:application/x-www-form-urlencoded',
'content'=>http_build_query([
'content'=>($resto?'New post':''." '$sub'")." <$url>",
]),
]
]);
@file_get_contents(DISCORD_WH_NEWS, false, $stream);
}
// delta != 0 indicates that the total file size has changed and the cache must be updated
if($delta_totalsize != 0){
$FileIO->updateStorageSize($delta_totalsize);
}
updatelog();
if(isset($_POST['up_series'])){
if($resto) $redirect = PHP_SELF.'?res='.$resto.'&upseries=1';
else $redirect = PHP_SELF.'?res='.$lastno.'&upseries=1';
}
redirect($redirect, 0);
}
/* User post deletion */
function usrdel(){
$PIO = PMCLibrary::getPIOInstance();
$FileIO = PMCLibrary::getFileIOInstance();
$PMS = PMCLibrary::getPMSInstance();
// $pwd: User input value, $pwdc: Cookie records password
$pwd = $_POST['pwd']??'';
$pwdc = $_COOKIE['pwdc']??'';
$onlyimgdel = $_POST['onlyimgdel']??'';
$delno = array();
reset($_POST);
while ($item = each($_POST)){
if ($item[1] !== 'delete') {
continue;
}
if (!is_numeric($item[0])) {
continue;
}
array_push($delno, intval($item[0]));
}
$haveperm = valid()>=LEV_JANITOR;
$PMS->useModuleMethods('Authenticate', array($pwd,'userdel',&$haveperm));
if($haveperm && isset($_POST['func'])){ // If the user has permissions (admin, mod, or janny) for front-end management capabilities
$message = '';
$PMS->useModuleMethods('AdminFunction', array('run', &$delno, $_POST['func'], &$message)); // "AdminFunction" Hook Point
if($_POST['func'] != 'delete'){
if(isset($_SERVER['HTTP_REFERER'])){
header('HTTP/1.1 302 Moved Temporarily');
header('Location: '.$_SERVER['HTTP_REFERER']);
}
exit(); // Only execute AdminFunction to terminate the deletion action
}
}
if($pwd=='' && $pwdc!='') $pwd = $pwdc;
$pwd_md5 = substr(md5($pwd),2,8);
$host = gethostbyaddr(getREMOTE_ADDR());
$search_flag = $delflag = false;
if(!count($delno)) error(_T('del_notchecked'));
$delposts = array(); // Articles that are truly eligible for deletion
$posts = $PIO->fetchPosts($delno);
foreach($posts as $post){
if($pwd_md5==$post['pwd'] || $host==$post['host'] || $haveperm){
$search_flag = true; // Found
array_push($delposts, intval($post['no']));
logtime("Delete post No.".$post['no'].($onlyimgdel?' (file only)':''), valid());
}
}
if($search_flag){
if(!$onlyimgdel) $PMS->useModuleMethods('PostOnDeletion', array($delposts, 'frontend')); // "PostOnDeletion" Hook Point
$files = $onlyimgdel ? $PIO->removeAttachments($delposts) : $PIO->removePosts($delposts);
$FileIO->updateStorageSize(-$FileIO->deleteImage($files)); // Update capacity cache
deleteCache($delposts);
$PIO->dbCommit();
}else error(_T('del_wrongpwornotfound'));
updatelog();
if(isset($_POST['func']) && $_POST['func'] == 'delete'){ // Front-end management deletes the article and returns to the management page
if(isset($_SERVER['HTTP_REFERER'])){
header('HTTP/1.1 302 Moved Temporarily');
header('Location: '.$_SERVER['HTTP_REFERER']);
}
exit();
}
}
/* Manage article(threads) mode */
function admindel(&$dat){
$PIO = PMCLibrary::getPIOInstance();
$FileIO = PMCLibrary::getFileIOInstance();
$PMS = PMCLibrary::getPMSInstance();
$pass = $_POST['pass']??''; // Admin password
$page = $_REQUEST['page']??0; // Toggle the number of pages
$onlyimgdel = $_POST['onlyimgdel']??''; // Only delete the image
$modFunc = '';
$delno = $thsno = array();
$message = ''; // Display message after deletion