112 lines
4.9 KiB
PHP
112 lines
4.9 KiB
PHP
<?php
|
|
|
|
// forum.php :: Internal forums script for the game.
|
|
|
|
require_once '../src/lib.php';
|
|
|
|
if (!file_exists('../.installed')) redirect('install.php');
|
|
|
|
$controlrow = get_control_row();
|
|
|
|
// Login (or verify) if not logged in.
|
|
if (($userrow = checkcookies()) === false) {
|
|
if (isset($_GET['do']) && $_GET['do'] === 'verify') {
|
|
header("Location: users.php?do=verify");
|
|
exit;
|
|
}
|
|
|
|
header("Location: login.php?do=login");
|
|
exit;
|
|
}
|
|
|
|
// Close game.
|
|
if ((bool) $controlrow["gameopen"] === false) {
|
|
display("The game is currently closed for maintanence. Please check back later.", "Game Closed");
|
|
exit;
|
|
}
|
|
|
|
// Force verify if the user isn't verified yet.
|
|
if ((bool) $controlrow["verifyemail"] && (bool) $userrow["verify"] === false) {
|
|
header("Location: users.php?do=verify");
|
|
exit;
|
|
}
|
|
|
|
// Block user if he/she has been banned.
|
|
if ($userrow["authlevel"] === 2) {
|
|
exit("Your account has been blocked.");
|
|
}
|
|
|
|
$do = explode(':', $_GET['do'] ?? '');
|
|
match ($do[0]) {
|
|
'thread' => showthread($do[1], $do[2]),
|
|
'new' => newthread(),
|
|
'reply' => reply(),
|
|
'list' => donothing($do[1]),
|
|
default => donothing()
|
|
};
|
|
|
|
function donothing($start = 0)
|
|
{
|
|
$query = db()->query('SELECT * FROM forum WHERE parent=0 ORDER BY newpostdate DESC LIMIT 20 OFFSET ?;', [20 * $start]);
|
|
$page = "<table width=\"100%\"><tr><td style=\"padding:1px; background-color:black;\"><table width=\"100%\" style=\"margins:0px;\" cellspacing=\"1\" cellpadding=\"3\"><tr><th colspan=\"3\" style=\"background-color:#dddddd;\"><center><a href=\"forum.php?do=new\">New Thread</a></center></th></tr><tr><th width=\"50%\" style=\"background-color:#dddddd;\">Thread</th><th width=\"10%\" style=\"background-color:#dddddd;\">Replies</th><th style=\"background-color:#dddddd;\">Last Post</th></tr>\n";
|
|
|
|
$hasRows = false;
|
|
|
|
while ($row = $query->fetchArray(SQLITE3_ASSOC)) {
|
|
$hasRows = true;
|
|
$page .= "<tr><td style=\"background-color:#ffffff;\"><a href=\"forum.php?do=thread:".$row["id"].":0\">".$row["title"]."</a></td><td style=\"background-color:#ffffff;\">".$row["replies"]."</td><td style=\"background-color:#ffffff;\">".$row["newpostdate"]."</td></tr>\n";
|
|
}
|
|
|
|
if (!$hasRows) {
|
|
$page .= "<tr><td style=\"background-color:#ffffff;\" colspan=\"3\"><b>No threads in forum.</b></td></tr>\n";
|
|
}
|
|
|
|
$page .= "</table></td></tr></table>";
|
|
|
|
display($page, "Forum");
|
|
}
|
|
|
|
function showthread($id, $start)
|
|
{
|
|
$posts = db()->query('SELECT * FROM forum WHERE id=? OR parent=? ORDER BY id LIMIT 15 OFFSET ?;', [$id, $id, $start * 15]);
|
|
$title = db()->query('SELECT title FROM forum WHERE id=? LIMIT 1;', [$id])->fetchArray(SQLITE3_ASSOC);
|
|
|
|
$page = "<table width=\"100%\"><tr><td style=\"padding:1px; background-color:black;\"><table width=\"100%\" style=\"margins:0px;\" cellspacing=\"1\" cellpadding=\"3\"><tr><td colspan=\"2\" style=\"background-color:#dddddd;\"><b><a href=\"forum.php\">Forum</a> :: ".$title['title']."</b></td></tr>\n";
|
|
while ($row = $posts->fetchArray(SQLITE3_ASSOC)) {
|
|
$page .= "<tr><td width=\"25%\" style=\"background-color:#ffffff; vertical-align:top;\"><span class=\"small\"><b>".$row["author"]."</b><br><br>".prettyforumdate($row["postdate"])."</td><td style=\"background-color:#ffffff; vertical-align:top;\">".nl2br($row["content"])."</td></tr>\n";
|
|
}
|
|
$page .= "</table></td></tr></table><br>";
|
|
$page .= "<table width=\"100%\"><tr><td><b>Reply To This Thread:</b><br><form action=\"forum.php?do=reply\" method=\"post\"><input type=\"hidden\" name=\"parent\" value=\"$id\" /><input type=\"hidden\" name=\"title\" value=\"Re: ".$title["title"]."\" /><textarea name=\"content\" rows=\"7\" cols=\"40\"></textarea><br><input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /></form></td></tr></table>";
|
|
|
|
display($page, "Forum");
|
|
}
|
|
|
|
function reply()
|
|
{
|
|
global $userrow;
|
|
|
|
$p = $_POST['parent'] ?? 0;
|
|
$t = trim($_POST['title'] ?? '');
|
|
$c = trim($_POST['content'] ?? '');
|
|
|
|
db()->query('INSERT INTO forum (author, title, content, parent) VALUES (?, ?, ?, ?);', [$userrow['username'], $t, $c, $p]);
|
|
db()->query('UPDATE forum SET newpostdate=CURRENT_TIMESTAMP, replies=replies + 1 WHERE id=?;', [$p]);
|
|
redirect("forum.php?do=thread:$p:0");
|
|
}
|
|
|
|
function newthread()
|
|
{
|
|
global $userrow;
|
|
|
|
if (isset($_POST["submit"])) {
|
|
extract($_POST);
|
|
$t = trim($_POST['title'] ?? '');
|
|
$c = trim($_POST['content'] ?? '');
|
|
db()->query('INSERT INTO forum (author, title, content) VALUES (?, ?, ?);', [$userrow['username'], $t, $c]);
|
|
redirect('forum.php');
|
|
}
|
|
|
|
$page = "<table width=\"100%\"><tr><td><b>Make A New Post:</b><br><br/ ><form action=\"forum.php?do=new\" method=\"post\">Title:<br><input type=\"text\" name=\"title\" size=\"50\" maxlength=\"50\" /><br><br>Message:<br><textarea name=\"content\" rows=\"7\" cols=\"40\"></textarea><br><br><input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /></form></td></tr></table>";
|
|
display($page, "Forum");
|
|
}
|