3DSTownSquare/3ds/forums/~
2022-05-27 01:04:28 +00:00

32 lines
1.5 KiB
Text

<style>
body, html {
width: 320px;
}
</style>
<meta name="viewport" content="width=320">
<?php
session_start();
if(isset($_SESSION["ts_user"]) && $_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["topic"]) && isset($_POST["title"]) && isset($_POST["cont"])){
if($_POST["title"] != "" && $_POST["cont"] != "" && strlen($_POST["title"]) <= 32 && strlen($_POST["cont"]) <= 5000){
if(file_exists("data/topic/".$_POST["topic"].".json") && json_decode(file_get_contents("../acc/data/".$_SESSION["ts_user"].".json"),true)["banned"] <= 0 && (!isset($_COOKIE["as"])){
// CoolDown cookie, disguised as something else :trl:
setCookie("as", "aHR0cHM6Ly9zdGFja292ZXJmbG93LmNvbS9xdWVzdGlvbnMvMzk4MjA4MjYvaG93LWNhbi1pLW1ha2UtYS1jb29sZG93bi1pbi1waHA=",time()+30000);
$jsonF = file_get_contents("data/topic/".$_POST["topic"].".json");
$jsonD = json_decode($jsonF, true);
$posts = $jsonD["posts"];
$newPost = array("title"=>$_POST["title"],"from"=>$_SESSION["ts_user"],"cont"=>$_POST["cont"],"time"=>time(),"com"=>array());
array_push($jsonD["posts"], $newPost);
$newj = json_encode($jsonD);
file_put_contents("data/topic/".$_POST["topic"].".json", $newj);
$id = count($jsonD["posts"]) - 1;
echo "Your post has been submitted<a href='view.php?topic=0&post=".$id."'>here</a>.";
}
}else{
echo "forums.error.unknown";
}
} else {
echo "Something went wrong.<br />";
echo "Debug info: ".var_dump($_SERVER["REQUEST_METHOD"]);
}