-
Notifications
You must be signed in to change notification settings - Fork 0
/
akane.php
1659 lines (1637 loc) · 72.1 KB
/
akane.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
/*-----------------------------------------------------------------------------------
| |
| Akane v2.0 |
| |
| Description: Akane est un script d'imageboard (forum à image) écrit en PHP. |
| Il permet à des utilisateurs anonymes de partager des images |
| et du texte au travers de fils de discussion. |
| |
| Auteur: Marsyl |
| |
| Site: https://www.akane-ch.org/ |
| |
| |
-----------------------------------------------------------------------------------*/
/*-------Installation--------*/
/*
1) Créez un dossier à la racine du serveur. Mettez-y le fichier akane.php puis créez les dossiers res/ src/ et thumb/.
SERVER_ROOT/
|
+-- <nom du forum>/
|
+-- Akane.php
|
+-- res/
|
+-- src/
|
+-- thumb/
2) Créez une base de donnée ("imageboard" par défaut, sinon renommez dans les paramètres plus bas).
3) Remplissez les paramètres ci-dessous.
4) Lancez le fichier akane.php dans un navigateur.
*/
/*-------Paramètres--------*/
//Logo
define('LOGO','/img/logo.svg');
//Environnement
define('TITLE', '/e/ - Example'); //nom du forum
define('ROOT','/e/'); //racine du forum
define('RES_FOLDER', 'res/'); //dossier des pages
define('IMG_FOLDER', 'src/'); //dossier des images
define('THUMB_FOLDER', 'thumb/'); //dossier des miniatures
define('ANON_NAME', 'Sine Nomine'); //nom par défaut
define('MAX_BUMP', 50); //bump max par sujet
define('MAX_REPLIES', 200); //réponses max par sujet
define('THREADS_PER_PAGE', 5); //nombres de sujets par pages
define('MAX_PAGES', 10); //nombre maximum de pages
define('INDEX_PREVIEW', 5); //nombre de réponses à affichier par sujet dans l'index
define('PASSWORD_SALT', '$2y$10$'.'**********************'); //sel de chiffrement. 22 caractères obligatoires pour blowfish
define('CAPCODE', [
0 => '<span style="color:red;font-weight:bold;"> ## Administrateur</span>',
1 => '<span style="color:purple;font-weight:bold;"> ## Moderateur</span>'
]);
//Messages
define('COOLDOWN', 15); //temps à attendre entre deux messages
define('MSG_MAX_LENGTH', 5000); //taille maximale d'un message
define('MAX_FILESIZE',3*1024*1024); //taille du fichier en Mo
define('FILE_TYPES', [ //formats de fichiers acceptés
'jpg' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif',
]);
define('IMG_THUMB', [ //taille de la miniature de l'OP
'WIDTH' => 248,
'HEIGHT' => 248,
]);
define('IMG_THUMB_REPLY', [ //taille de la miniature des réponses
'WIDTH' => 124,
'HEIGHT' => 124,
]);
//Base de données
define('DB_USER','root');
define('DB_PASSWORD', '');
define('DB_NAME','imageboard');
define('DB_HOST','localhost');
define('DB_POST_TABLE','e_posts');
//--------Connexion--------//
/**
* @return PDO
*/
function getPDO(): PDO
{
try{
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';', DB_USER, DB_PASSWORD, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]);
}catch (PDOException $e){
print_r($e);
}
return $pdo;
}
//----------Models---------//
abstract class Model
{
protected $pdo;
protected $table;
public $id;
public $values;
public function __construct()
{
$this->pdo = getPDO();
}
/**
* @param string $column
* @param mixed $value
* @param string $order (ex : "column DESC/ASC")
* @param integer $offset
* @param integer $limit
* @return mixed
*/
public function findAll(?string $column = null, $value = null, ?string $order = null, ?int $offset = null, ?int $limit = null)
{
$sql = "SELECT * FROM {$this->table}";
if($column && isset($value)){
$sql .= " WHERE {$column} = '{$value}'";
}
if($order){
$sql .= " ORDER BY {$order}";
}
if(isset($limit)){
$sql .= " LIMIT {$offset}, {$limit}";
}
$values = $this->pdo->query($sql)->fetchAll();
return $values;
}
/**
* @param string $column
* @param mixed $value
*/
public function findOne(string $column, $value)
{
$sql = "SELECT * FROM {$this->table} WHERE {$column} = '{$value}'";
$values = $this->pdo->query($sql)->fetch();
return $values;
}
/**
* @param string $item
* @param string $column
* @param mixed $value
*/
public function find(string $item, string $column, $value)
{
$sql = "SELECT {$item} FROM {$this->table} WHERE {$column} = '{$value}'";
$values = $this->pdo->query($sql)->fetchColumn();
return $values;
}
/**
* @param integer $id
* @return mixed
*/
public function findOneByID(int $id)
{
$sql = "SELECT * FROM {$this->table} WHERE id = {$id}";
$values = $this->pdo->query($sql)->fetch();
return $values;
}
/**
* @param array $items : ['column' => 'value']
* @return void
*/
public function delete(array $items): void
{
$sql = "DELETE FROM {$this->table} WHERE ";
foreach($items as $key=>$item){
$sql .= "{$key} = '{$item}', ";
}
$sql = substr($sql, 0, -2);
$this->pdo->query($sql);
}
/**
* @param array $values
* @return void
*/
public function insert(): void
{
$sql = "INSERT INTO {$this->table} SET ";
foreach($this->values as $key=>$value){
$sql .= "{$key} = :{$key}, ";
}
$sql = substr($sql, 0, -2);
$stmt = $this->pdo->prepare($sql);
$stmt->execute($this->values);
$this->id = $this->pdo->lastInsertId();
}
/**
* @param string $column
* @param string $value
* @param string $where
* @param string $col
*/
public function update(string $column, string $value, string $where, string $col)
{
$this->pdo->query("UPDATE {$this->table} SET {$column} = '{$value}' WHERE {$where} = '{$col}'");
}
}
class Board extends Model
{
/**
* @return void
*/
public function init(): void
{
$table = DB_POST_TABLE;
if(!$this->pdo->query("SHOW TABLES LIKE '{$table}'")->fetch()){
$this->pdo->query("CREATE TABLE IF NOT EXISTS `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`rank` int(11) NULL,
`password` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `ban` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`IP` varchar(255) NOT NULL,
`reason` text DEFAULT NULL,
`expires` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `report` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`board` varchar(255) NOT NULL,
`postID` varchar(255) NOT NULL,
`reason` varchar(255) NOT NULL,
`reporterIP` varchar(255) NOT NULL,
`prio` int(11) NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `{$table}` ;
CREATE TABLE IF NOT EXISTS `{$table}` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` bigint(20) NOT NULL,
`bump` bigint(20) NOT NULL DEFAULT '0',
`locked` BOOLEAN NOT NULL DEFAULT FALSE,
`sticky` BOOLEAN NOT NULL DEFAULT FALSE,
`parent` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`tripcode` varchar(255) DEFAULT NULL,
`IP` varchar(255) NOT NULL,
`email` varchar(255) DEFAULT NULL,
`subject` varchar(255) DEFAULT NULL,
`message` text,
`upfile_name` varchar(255) DEFAULT NULL,
`md5` varchar(255) DEFAULT NULL,
`file` varchar(255) DEFAULT NULL,
`thumbnail` varchar(255) DEFAULT NULL,
`replies` text NULL DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;");
$page = new Page();
$page->head(TITLE)->title()->postForm(0)->navLinks(null, 0, 0)->navLinks(null, 0, 1)->footer()->write('', 'index', 'html');
header('Refresh: 2; URL='.ROOT);
echo('installation terminée');
exit();
}
}
}
class Post extends Model
{
protected $table = DB_POST_TABLE;
public $date;
public $bump;
public $locked;
public $sticky;
public $parent;
public $name;
public $tripcode;
public $IP;
public $email;
public $subject;
public $message;
public $upfile_name;
public $md5;
public $file;
public $thumbnail;
public $replies;
public $password;
public $quotes;
/**
* @return void
*/
public function create(): void
{
$this->values = [
'date' => $this->date,
'bump' => $this->bump,
'locked' => $this->locked,
'sticky' => $this->sticky,
'parent' => $this->parent,
'name' => $this->name,
'tripcode' => $this->tripcode,
'IP' => $this->IP,
'email' => $this->email,
'subject' => $this->subject,
'message' => $this->message,
'upfile_name' => $this->upfile_name,
'md5' => $this->md5,
'file' => $this->file,
'thumbnail' => $this->thumbnail,
'replies' => $this->replies,
'password' => $this->password
];
}
/**
* @param integer $id
* @return void
*/
public function bump(int $id): void
{
$bump = time().substr(microtime(), 2, 3);
$this->pdo->query("UPDATE {$this->table} SET bump = {$bump} WHERE id = {$id}");
}
}
class Ban extends Model
{
protected $table = "ban";
public $IP;
public $reason;
public $expires;
/**
* @return void
*/
public function create(): void
{
$this->values = [
'IP' => $this->IP,
'reason' => $this->reason,
'expires' => $this->expires
];
}
}
class User extends Model
{
protected $table = "user";
public $name;
public $rank;
public $password;
/**
* @return void
*/
public function create(): void
{
$this->values = [
'name' => $this->name,
'rank' => $this->rank,
'password' => $this->password
];
}
/**
* @return mixed
*/
public function connect()
{
if(isset($_SESSION['auth']['password'])){
$password = $_SESSION['auth']['password'];
}elseif(isset($_POST['adminpass'])){
$password = crypt($_POST['adminpass'], PASSWORD_SALT);
//var_dump($password);die();
}else{
return false;
}
if($userInfo = $this->pdo->query("SELECT * FROM {$this->table} WHERE password = '{$password}'")->fetch()){
$this->name = $userInfo['name'];
$this->rank = $userInfo['rank'];
$this->password = $userInfo['password'];
$_SESSION['auth']['name'] = $userInfo['name'];
$_SESSION['auth']['password'] = $userInfo['password'];
return $this;
}else{
return false;
}
}
}
class Report extends Model
{
protected $table = "report";
public $board;
public $postID;
public $reason;
public $reporterIP;
public $prio;
/**
* @return void
*/
public function create(): void
{
$this->values = [
'board' => $this->board,
'postID' => $this->postID,
'reason' => $this->reason,
'reporterIP' => $this->reporterIP,
'prio' => $this->prio
];
}
}
//--------Fichiers---------//
class Page
{
protected $data = '';
/**
* Écrit une page
* @return void
*/
public function write(string $path, string $filename, string $ext): Page
{
$this->data = preg_replace('/\n|\r| ( +)/', '', $this->data);
$output = fopen($path.$filename.'.'.$ext, 'w') or die('impossible de trouver le fichier');
fwrite($output, $this->data);
fclose($output);
$this->data = '';
return $this;
}
/**
* Affiche la page en direct
* @return void
*/
public function render(): Page
{
$this->data = preg_replace('/\n|\r| ( +)/', '', $this->data);
echo($this->data);
$this->data = '';
return $this;
}
/**
* @param string $title
* @return Page
*/
public function head(string $title): Page
{
$this->data .= '<!DOCTYPE html>
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="cache-control" content="max-age=0">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT">
<meta http-equiv="pragma" content="no-cache">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="imageboard, forum, culture, japonaise,japon,anime,manga,nsfw">
<link rel="shortcut icon" href="/img/favicon.ico">
<title>'.$title. '</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/" + ";SameSite=Lax";
}
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(\';\');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == \' \') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function quotePost(postId){
$("#message").val($("#message").val() + postId + "\n");
return false;
}
window.addEventListener(\'DOMContentLoaded\',(event)=>{
if(window.location.hash){
if(window.location.hash.match(/^#q[0-9]+$/i)!==null){
var postId=window.location.hash.match(/^#q[0-9]+$/i)[0].substr(2);
if(postId!=\'\'){
quotePost(\'>>\'+postId);
}
}
}
let formPos = JSON.parse(getCookie("formPos"));
if (formPos != "") {
$(\'#move\').css({"top":formPos["top"], "left":formPos["left"]});
}
$(\'.backlink, .replyLink\').mouseenter(function(){
var num=$(this).text().substr(2);
var ptop=$(this).offset().top-20;
var pleft=$(this).offset().left;
$(\'body\').append(\'<div class="floatReply">\'+$(\'#\'+num).html()+\'</div>\');
$(\'.floatReply\').css({position: \'absolute\',top:(ptop-$(\'.floatReply\').height()),left:pleft+40});
}).mouseleave(function(){
$(\'.floatReply\').remove();
});
$(\'form img\').mouseenter(function(){
var src=$(this).parent(\'a\').attr(\'href\');
$(\'html\').append(\'<div class="imgLarge" style="position:fixed;top:0;right:0;height:100vh;z-index:12;"><img style="top:0;right:0;max-height:100%;max-width:60vw;" src="\'+src+\'"></div>\');
}).mouseleave(function(){
$(\'.imgLarge\').remove();
});
});
</script>
<style>
html{height:100%;scroll-behavior: smooth;}
html,body{background:#d3d3d3;}
body{font-family:Arial;font-size:10pt;margin:8px;padding-top:170px;}
footer{font-size:8pt;}
textarea {
font-family: Arial;
font-size: 10pt;
}
.logo{background: #951818;;
width: 100vw;
height:106px;
margin-left: -8px;
margin-top: -8px;
position: fixed;
top: 0;
padding:8px}
.logo img{width:96%;max-width:600px;max-height:7em;}
.postform{text-align:left;width:100%;}
.postform ul{font-size:8pt;font-weight:normal;padding:0;margin:0;margin-left:8px;}
#move {
z-index: 9;
}
#moveheader {
cursor: move;
z-index: 10;
}
.doc{width:100%;max-width:750px;margin:auto;}
.box{background-color:#FFF;}
.boxtitle{background:#a2a2a2;color:#FFFFFF;margin:0;font-size:16pt;font-weight:bold;padding-left:8px;}
.boxcontent{padding:8px;}
.boardtype{font-weight:bold;}
.lastsubjects{width:100%;border:1px solid #cacaca;border-spacing:0;}
hr{clear:both;}
a{color:black;}
a.anchor {
display: block;
position: relative;
top: -300px;
visibility: hidden;
}
a:hover{color:red;}
button{color: white;
background: #2d2d2d;
border-radius: 4px;
border: none;}
button a{color:white;text-decoration:none;}
button a:hover{color:white;}
button:hover{cursor:pointer;box-shadow:0px 0px 1px 1px #888;}
.paginate{background:#b5b5b5;padding:8px;padding-left:16px;}
.paginate button{font-size:14pt;font-weight:bold;}
.postStatus{color:red;font-weight:bold;}
.postImg{float:left}
.counter{float:left;color:#9b9b9b;font-family:Courier;}
.reply, .floatReply{background:#ffffff;box-shadow:0px 0px 1px #a8a8a8;padding:0;padding-bottom:8px;}
.floatReply img{margin-right:12px;}
.reply:target{background-color:#bfbfbf;scroll-margin-top: 170px;}
.replyLink{color:red;text-decoration:underline;}
.replyhead{font-size:10pt;margin: 0;padding:8px;background:#ddd;}
.replybody{padding: 8px;}
.backlink{font-size:10pt;text-decoration:underline;}
.quote{color:#789922;}
form a{text-decoration:none;}
form img{margin-right:12px;}
.navlinks{clear: both;
padding: 8px;
margin-top: -3px;
background: #2d2d2d;
width: 100vw;
margin-left: -8px;
position: fixed;
top: 8em;
padding-left:16px;}
.navlinks button{font-size:14pt;font-weight:bold;margin-right:8px;}
.useractions{float:right;padding-right:36px;}
.OPImg{margin-bottom:8px;float:left;}
.catalogrow{cursor:pointer;}
.cataloglabel{background:#484848;color:white;font-weight:bold;text-align:left;}
.catalogrow:hover{background-color:#c2c2c2;}
.subject{color:#cc1105;font-size:16px;font-weight:bold;}.name{color:#0052aa;font-weight:bold;}
.tripcode{color:#228854;}
@media only screen and (max-width: 480px){
iframe{width:150px;height:84px;}
.counter{display:none;}
.boardname h{font-size:14pt;}
.logo{height:5em}
.navlinks{top:5em}
.navlinks button{font-size:8pt;margin-bottom:8px;}
.useractions{font-size:10pt;}
}
@media only screen and (min-width:800px){
#move{position:fixed;}
}
</style>
</head>
<body>
<a class="anchor" id="up"></a>';
return $this;
}
/**
* @return Page
*/
public function title(?User $user = null): Page
{
$this->data .= ($user ? '<div>[<span style="color:red;font-weight:bold;">Connecté: '.$user->name.'</span>]
[<a href="akane.php?admin&logout">Se déconnecter</a>]
[<a href="akane.php?admin&banlist">Liste des bannis</a>]
[<a href="akane.php?admin&reportlist">Signalements</a>]
[<a href="akane.php?admin&rebuildall">Tout reconstruire</a>]</div>': '').'
<div class="logo">
<img src="'.LOGO.'">
</div>
<div class="boardname"><hr style="max-width:750px">
<h1 align="center">'.TITLE.'</h1>
</div>';
return $this;
}
/**
* @param integer $parent
* @return Page
*/
public function postForm($parent): Page
{
$this->data .= '<div id="move" class="box" style="left:50vw;top:50vh;">
<div id="moveheader" class="boxtitle">
'.(!$parent ? 'Créer un nouveau sujet' : 'Répondre au sujet No.'.$parent).'
</div>
<form action="'.ROOT.'akane.php" method="post" enctype="multipart/form-data"><input type="hidden" name="parent" value="'.(!$parent ? '0' : $parent). '">
<table class="postform">
<tr><td><input type="text" placeholder="Nom (facultatif)" name="name" style="width: -moz-available;"></td></tr>
<tr><td><input type="text" placeholder="E-mail (facultatif)" name="email" style="width: -moz-available;"></td></tr>';
if(!$parent){$this->data .= '
<tr><td><input type="text" placeholder="Sujet (facultatif)" name="subject" style="width: -moz-available;"></td></tr>';
}
$this->data .= '
<tr><td><textarea id="message" placeholder="Message" name="message" max="8000" style="width: -moz-available;height:80px;"></textarea></td></tr>';
if(UPLOADS){
$this->data .= '
<tr><td><input type="file" name="upfile"></td></tr>';
}
if(VIDEO){
$this->data .= '
<tr><td><input type="text" name="video" placeholder="Lien de la vidéo" style="width: -moz-available;"></td></tr>';
}
$this->data .= '
<tr><td><input type="password" placeholder="Mot de passe (pour supprimer)" name="password" style="width: -moz-available;"></td></tr>
<tr><td><input type="submit" name="newpost" value="Envoyer"></td></tr><tr>
<th colspan="2">
<ul>
<li>'.(UPLOADS ? 'Il faut au moins une image ou du texte pour répondre.' : 'Il faut au moins un message '.(VIDEO ? 'ou une vidéo' : '').' pour répondre.').'</li>
'.(UPLOADS ? '<li>Les formats supportés sont JPG, PNG et GIF.</li><li>Taille maximale du fichier: 3Mo.</li>' : '').
(VIDEO ? '<li>Un lecteur vidéo sera généré s\'il y a un lien</li><li>Plate-formes supportées: Youtube.</li>' : '').'
</ul>
</th>
</tr>
</table>
</form>
</div>
<script>
dragElement(document.getElementById("move"));
function dragElement(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if (document.getElementById(elmnt.id + "header")) {
document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
} else {
elmnt.onmousedown = dragMouseDown;
}
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
formPos = new Object;
formPos["top"] = (elmnt.offsetTop - pos2);
formPos["left"] = (elmnt.offsetLeft - pos1);
elmnt.style.top = formPos["top"] + "px";
elmnt.style.left = formPos["left"] + "px";
setCookie(\'formPos\', JSON.stringify(formPos), 365);
}
function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
}
}
</script>';
return $this;
}
/**
* @param bool $logged
* @param integer $parent
* @param bool $position : 0 = en haut, 1 = en bas
* @return Page
*/
public function navLinks(?User $user, int $parent, bool $position): Page
{
if(!$position){
$this->data .= '<form action="'.ROOT.'akane.php" method="get">
<hr>
<div class="navlinks">
<span><button><a href="/">Accueil</a></button>' .
($parent ? '<button><a href="' .
($user ? 'akane.php?admin&page=0' : ROOT) . '">Index</a></button>' : '') . '
<button type="button"><a href="' . ROOT . 'catalogue">Catalogue</a></button>
<button type="button"><a href="#down">▼</a></button>
<button type="button"><a href="#up">▲</a></button>
<button onclick="window.location.reload();" type="button">Rafraîchir</button>
</span>
<span class="useractions">
<input type="password" placeholder="Mot de passe" name="delpassword" size="8">
<input type="submit" name="deletepost" value="Supprimer"><input type="submit" name="report" value="Signaler">
</span>
</div>';
}else{
$this->data .= '</form>';
}
return $this;
}
/**
* @param array $OP
* @param bool $logged
* @param bool $index
* @return Page
*/
public function OP(array $OP, ?User $user, bool $index): Page
{
$this->data .= '<div id="'.$OP['id'].'" style="scroll-margin-top: 170px;'.($user ? 'border: 4px solid hsl('.(hexdec(substr(md5($OP['IP']), 0, 2))).',100%,75%);' : '').'">';
if(UPLOADS && !empty($OP['file'])){
$this->data .= 'Fichier:<a href="'.ROOT.IMG_FOLDER.$OP['file'].'" target="_blank">'.(strlen($OP['upfile_name']) > 20 ? substr($OP['upfile_name'], 0, 20).'...'.substr($OP['upfile_name'], -4) : $OP['upfile_name']).'</a>
[<a target="_blank" href="https://saucenao.com/search.php?url=https://www.akane-ch.org'.ROOT.THUMB_FOLDER.$OP['thumbnail'].'">SauceNao</a>]<br>
<a href="'.ROOT.IMG_FOLDER.$OP['file'].'" target="_blank">
<img class="OPImg" src="'.ROOT.THUMB_FOLDER.$OP['thumbnail'].'" title="'.$OP['upfile_name'].'" alt="'.$OP['upfile_name'].'"></a>';
}
$this->data .= '<input type="checkbox" name="del" value="'.$OP['id'].'">'.(!empty($OP['subject']) ? '
<span class="subject">'.$OP['subject'].'</span> ' : '').'
<span class="name">'.(!empty($OP['email']) ? '<a href="mailto:'.$OP['email'].'">'.$OP['name'].'</a>' : $OP['name']).'</span>
'.(!empty($OP['tripcode']) ? '
<span class="tripcode">'.$OP['tripcode'].'</span>' : '').'
<span>'.date('d/m/y \à H:i:s', $OP['date']).'</span>
<span><a href="'.ROOT.RES_FOLDER.$OP['id'].'#'.$OP['id'].'">No.</a>
<a href="'.ROOT.RES_FOLDER.$OP['id'].'#q'.$OP['id'].'"'.(!$index ? ' onclick="javascript:quotePost(\'>>'.$OP['id'].'\')"' : null).'>'.$OP['id'].'</a>
'.($OP['locked'] ? '
[<span class="postStatus">Verrouillé</span>]' : '').
($OP['sticky'] ? '
[<span class="postStatus">Épinglé</span>]' : '').
($index ? '
<button><a href="'.($user ? 'akane.php?admin&res='.$OP['id'] : ROOT.RES_FOLDER.$OP['id']).'">Répondre</a></button>' : '').
($user ? '
['.$OP['IP'].']
[<a href="akane.php?admin&admindel='.$OP['id'].'">Supprimer</a>]
[<a href="akane.php?admin&ban='.$OP['id'].'">Bannir</a>]
'.($OP['locked'] ? '
[<a href="akane.php?admin&unlock='.$OP['id'].'">Déverrouiller</a>] ' : '
[<a href="akane.php?admin&lock='.$OP['id'].'">Verrouiller</a>] ').
(!$OP['sticky'] ? '
[<a href="akane.php?admin&stick='.$OP['id'].'">Épingler</a>]
' : '[<a href="akane.php?admin&unstick='.$OP['id'].'">Désépingler</a>]
') : '').'
'.$OP['replies'].'</span><br><p>'.
$OP['message'].'</p><br></div>';
return $this;
}
/**
* @param integer $parent
* @param bool $logged
* @param bool $index
* @param bool ?$hrTag
* @return Page
*/
public function replies(int $parent, ?User $user = null, bool $index, ?bool $hrTag = false): Page
{
$item = new Post();
$replies = $item->findAll('parent', $parent, 'id DESC');
if($index){
$replyCount = count($replies);
$hidden = $replyCount - INDEX_PREVIEW;
if($replyCount > INDEX_PREVIEW){
$this->data .= '<span style="color:grey;">'.$hidden.' réponses omises, cliquez sur \'Répondre\' pour tout voir.</span>';
}
}else{
$hidden = 0;
}
$counter = 0;
foreach(array_reverse($replies) as $reply){
$this->data .= '<table style="margin-top:6px;'.($counter < $hidden ? 'display:none;' : '').'">
<tr><td class="counter" '.($counter >= MAX_BUMP ? 'style="color:orange;" alt="Le sujet ne remontera plus"' : '').'>'.sprintf('%03d', ($counter + 1)). '</td>
<td id="'.$reply['id'].'" class="reply anchor" '.($user ? 'style="border: 4px solid hsl('.(hexdec(substr(md5($reply['IP']), 0, 2))).',100%,75%);"' : '').'>
<div class="replyhead">
<input type="checkbox" name="del" value="'.$reply['id'].'">
<span class="name">'.(!empty($reply['email']) ? '<a href="mailto:'.$reply['email'].'">'.$reply['name'].'</a>' : $reply['name']).'</span>
'.(!empty($reply['tripcode']) ? '<span class="tripcode">'.$reply['tripcode'].'</span> ' : '').'
<span>'.date('d/m/y \à H:i:s', $reply['date']).'</span>
<span><a href="'.ROOT.RES_FOLDER.$reply['parent'].'#'.$reply['id'].'">No.</a>
<a href="'.ROOT.RES_FOLDER.$reply['parent'].'#q'.$reply['id'].'" '.(!$index ? 'onclick="javascript:quotePost(\'>>'.$reply['id'].'\')"' : '').'>'.$reply['id'].'</a>'.
($user ? ' ['.$reply['IP'].']
[<a href="akane.php?admin&admindel='.$reply['id'].'">Supprimer</a>]
[<a href="akane.php?admin&ban='.$reply['id'].'">Bannir</a>]' : '').' '.$reply['replies'].'</span><br>';
if(UPLOADS && !empty($reply['file'])){
$this->data .= 'Fichier:<a href="'.ROOT.IMG_FOLDER.$reply['file'].'" target="_blank">'.(strlen($reply['upfile_name']) > 20 ? substr($reply['upfile_name'], 0, 20).'...'.substr($reply['upfile_name'], -4) : $reply['upfile_name']).'</a>
[<a target="_blank" href="https://saucenao.com/search.php?url=https://www.akane-ch.org'.ROOT.THUMB_FOLDER.$reply['thumbnail'].'">SauceNao</a>]</div>
<div class="replybody">
<a href="'.ROOT.IMG_FOLDER.$reply['file'].'" target="_blank"><img class="postImg" src="'.ROOT.THUMB_FOLDER.$reply['thumbnail'].'" title="'.$reply['upfile_name'].'" alt="'.$reply['upfile_name'].'"></a>';
}else{
$this->data .= '</div><div class="replybody">';
}
$this->data .= '<p>'.$reply['message'].'</p>
</div>
</td>
</tr>
</table>';
$counter++;
}
if($hrTag){
$this->data .= '<hr>';
}
return $this;
}
/**
* @return Page
*/
public function catalog(): Page
{
$item = new Post();
$posts = $item->findAll('parent', 0, 'sticky DESC, bump DESC');
$this->data .= '
<div class="navlinks">
<a href="/"><button>Accueil</button></a>
<a href="'.ROOT. '"><button>Index</button></a>
<a href="'.ROOT.'catalogue" data-refresh=".box"><button>Rafraîchir</button></a>
</div>
<div class="box" style="margin:auto;max-width:750px;">
<div class="boxtitle">
Catalogue
</div>
<div class="boxcontent">
<table class="lastsubjects">
<thead>
<th class="cataloglabel">No.</th>
<th class="cataloglabel">Sujet/Message</th>
<th class="cataloglabel">Auteur</th>
<th class="cataloglabel">Réponses</th>
</thead>';
foreach($posts as $post){
$numReplies = count($item->findAll('parent', $post['id']));
$this->data .= '
<tr class="catalogrow" onclick="window.open(\''.ROOT.RES_FOLDER.$post['id'].'\')">
<td>'.$post['id'].'</td>
<td style="line-break:anywhere;">'.($post['subject'] ? '<strong>'.substr($post['subject'], 0, 80).'</strong><br>' : '').substr(strip_tags($post['message']), 0, 80).'</td>
<td>'.$post['name'].'</td>
<td>'.$numReplies.'</td>
</tr>';
}
$this->data .= '</table></div></div>';
return $this;
}
/**
* @return Page
*/
public function auth(): Page
{
$this->data .= '<div align="center">
<h2>Administration</h2>
<form action="akane.php?admin" method="post">
<label>Mot de passe</label>
<input type="password" name="adminpass">
<input type="submit" name="login" value="Connexion">
</form>
</div>
</body>
</html>';
return $this;
}
/**
* @return Page
*/
public function banList(): Page
{
$item = new Ban();
$posts = $item->findAll(null , null, 'id DESC');
$this->data .= '<div class="doc">
<div class="box">
<div class="boxtitle">
Liste des bannis
</div>
<div class="boxcontent">
<table class="lastsubjects" style="width:100%;">
<thead>
<th class="cataloglabel">Identifiant No.</th>
<th class="cataloglabel">Adresse IP</th>
<th class="cataloglabel">Motif</th>
<th class="cataloglabel"Date d\'expiration</th>
<th class="cataloglabel">Action</th>
</thead>';
foreach($posts as $post){
$this->data .= '<tr class="catalogrow">
<td>'.$post['id'].'</td>
<td>'.$post['IP'].'</td>
<td>'.$post['reason'].'</td>
<td>'.date('d/m/Y à H:i:s', $post['expires']).'</td>
<td><a href="akane.php?admin&liftban='.$post['id'].'">Lever</a></td>
</tr>';
}
$this->data .= '</table>
</div>
</div>
</div>';
return $this;
}
/**
* @param int $id
* @return Page
*/
public function banForm(int $id)
{
$item = new Post();
$post = $item->findOne('id', $id);
$this->data .= '<div class="box">
<div class="boxtitle">
Registrer un ban
</div>
<div class="boxcontent">
<form action="akane.php?admin&ban" method="post">
<input type="hidden" name="IP" value="'.$post['IP'].'">
<input type="hidden" name="id" value="'.$post['id'].'">
<table class="lastsubjects" style="width:100%;">
<thead>
<th class="cataloglabel">IP</th>
<th class="cataloglabel">Post No.</th>';
if(!empty($post['thumbnail'])){
$this->data .= '<th class="cataloglabel">Image</th>';
}
$this->data .= '<th class="cataloglabel">Message</th>
<th class="cataloglabel">Raison</th>
<th class="cataloglabel">Durée</th>
<th class="cataloglabel">Public ?</th>
<th class="cataloglabel">Action</th>
</thead>
<tr>
<td>'.$post['IP'].'</td>
<td>'.$post['id'].'</td>';
if(!empty($post['thumbnail'])){
$this->data .= '<td><img src="'.ROOT.THUMB_FOLDER.$post['thumbnail'].'" height="124"></td>';
}
$this->data .= '<td>'.strip_tags($post['message']).'</td>
<td>
<select name="reason">
<option value="Contenu illégal.">Contenu illégal</option>
<option value="Message troll.">Troll</option>
<option value="Shitpost.">Shitpost</option>
<option value="Spam">Spam</option>
<option value="Signalement abusif">Signalement abusif</option>
<option value="Contenu NSFW en dehors des forums NSFW">NSFW</option>
<option value="Partage d\'infos personnelles">Infos persos</option>
<option value="Pas de pub à but lucratif.">Publicité lucrative</option>
</select>
</td>
<td>
<select name="expires">
<option value="3600">Une heure</option>
<option value="21600">Six heures</option>
<option value="86400">Un jour</option>
<option value="172800">Deux jours</option>
<option value="259200">Trois jours</option>
<option value="604800">Une semaine</option>
<option value="2592000">Un mois</option>
<option value="0">Permanant</option>
</select>
</td>
<td><input type="checkbox" name="publicban"></td>
<td><input type="submit" name="submitban" value="Bannir"></td>
</tr>
</table>
</form>
</div>