big change to the board system, instead of using folders with differnt board configs, we will be using a simple board.php file that handles all the boards.

This commit is contained in:
hayden 2019-07-21 23:30:56 -05:00
parent 78b82c6785
commit b1a8d2b6ce
5 changed files with 76 additions and 104 deletions

71
board.php Normal file
View File

@ -0,0 +1,71 @@
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
require_once($path . '/core/header.php');
require_once($path . '/core/footer.php');
require_once($path . '/core/database.php');
if (!isset($_GET['code'])) {
header('location: /404.php');
}
$board_code = strtolower($_GET['code']);
$board_page = (int)$_GET['page'] ?? 1;
if ($board_page == 0) $board_page = 1;
$conn = get_database_conn();
$board_sql = "SELECT id, title FROM board WHERE code = ? LIMIT 1";
$stmt = mysqli_prepare($conn, $board_sql);
mysqli_stmt_bind_param($stmt, 's', $board_code);
if (!mysqli_stmt_execute($stmt)) {
header('location: /404.php');
}
mysqli_stmt_store_result($stmt);
if (mysqli_stmt_num_rows($stmt) != 1) {
header('location: /404.php');
}
mysqli_stmt_bind_result($stmt, $board_id, $board_title);
mysqli_stmt_fetch($stmt);
display_header("~chan - /$board_code/");
?>
<div style="
margin: auto;
width: 40%;
padding-top: 50px;
">
<h1><?php echo "/$board_code/ - $board_title"; ?></h1>
<!-- TODO: Add spash text -->
<?php if (isset($_SESSION['username'])): ?>
<hr>
<form action="/post.php" method="post" class="input-form">
<table>
<tr>
<td><b>title:</b></td>
<td>
<input name="title" type="text" required>
</td>
</tr>
<tr>
<td><b>message:</b></td>
<td>
<textarea name="message" cols="64" rows="8" wrap="soft" tabindex="4" maxlength="1024"></textarea>
</td>
</tr>
<tr>
<td><b>file:</b></td>
<td>
<input name="upload" type="file" required>
</td>
</tr>
<input type="hidden" name="board_id" value="<?php echo $board_id; ?>">
<input type="hidden" name="type" value="new_thread">
</table>
<br>
<button type="submit">post</button>
</form>
<?php endif; ?>
<hr>
<b>(<a href="#">archive</a>) (<a href="#">catalog</a>)</b>
<hr>
</div>

View File

@ -1,71 +0,0 @@
<?php
// this function is the main control over displaying boards.
function display_board(array $settings) {
// default settings
$defaults = array(
'title' => 'default',
'code' => 'd',
'splash' => array(
'splash 1',
'splash 2',
'splash 3'
)
);
$settings = array_merge($defaults, $settings);
// load in the required files
$path = $_SERVER['DOCUMENT_ROOT'];
require_once($path . '/core/header.php');
require_once($path . '/core/footer.php');
require_once($path . '/core/database.php');
display_header('~chan - /' . $settings['code'] . '/');
session_start();
?>
<div style="
margin: auto;
width: 40%;
padding-top: 50px;
">
<h1><?php echo '/' . $settings['code'] . '/ - ' . $settings['title']; ?></h1>
<p><?php echo $settings['splash'][array_rand($settings['splash'])]; ?></p>
<?php if (isset($_SESSION['username'])): ?>
<hr>
<form action="/post.php" method="post" class="input-form">
<table>
<tr>
<td><b>title:</b></td>
<td>
<input name="title" type="text" required>
</td>
</tr>
<tr>
<td><b>message:</b></td>
<td>
<textarea name="message" cols="30" rows="6" wrap="soft" tabindex="4" maxlength="30:"></textarea>
</td>
</tr>
<tr>
<td><b>file:</b></td>
<td>
<input name="upload" type="file" required>
</td>
</tr>
<input type="hidden" name="board_code" value="<?php echo $settings['code']; ?>">
<input type="hidden" name="type" value="new_thread">
</table>
<br>
<button type="submit">post</button>
</form>
<?php endif; ?>
<hr>
<b>(<a href="#">archive</a>) (<a href="#">catalog</a>)</b>
<hr>
</div>
<?php
}
?>

View File

@ -24,13 +24,13 @@ function display_header($title = "~chan") {
<div class="box">
<span>
<b>boards:</b> (
<a href="/boards/b/">b</a>
<a href="board.php?code=b">b</a>
/
<a href="/boards/g/">g</a>
<a href="board.php?code=g">g</a>
/
<a href="/boards/m/">m</a>
<a href="board.php?code=mc">mc</a>
/
<a href="/boards/v/">v</a>
<a href="board.php?code=v">v</a>
)
</span>
<span>
@ -46,7 +46,7 @@ function display_header($title = "~chan") {
// i just decided to echo everything out here since the <?php ?\> syntax was ugly
echo "<a href=\"/profile.php\">profile</a>";
echo " / ";
echo "<a href=\"logout.php\">log out</a>";
echo "<a href=\"/logout.php\">log out</a>";
echo " )";
} else {
echo "<a href=\"/register.php\">register</a>";

View File

@ -1,18 +0,0 @@
<?php
$USER_TABLE_SQL = "
CREATE TABLE user ( id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(32) NOT NULL,
password VARCHAR(64) NOT NULL,
admin BOOL NOT NULL,
registered DATE NOT NULL,
last_login DATE,
);";
$THREAD_TABLE_SQL = "
CREATE TABLE thread ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
user_id INT NOT NULL,
board VARCHAR(20) NOT NULL,
posted DATETIME NOT NULL
);";
?>

View File

@ -7,16 +7,6 @@ session_start();
// Unset all of the session variables.
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
// Finally, destroy the session.
session_destroy();