Add files via upload

This commit is contained in:
Getindor 2020-09-10 00:34:24 -04:00 committed by GitHub
parent 2cdeb13f3d
commit 8bda8c887d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 650 additions and 0 deletions

139
board.php Normal file
View File

@ -0,0 +1,139 @@
<?php
class db{
public $config;
public $db;
function __construct($db){
$this->config = $db;
}
function connect(){
$this->db = new mysqli($this->config["server"], $this->config["user"], $this->config["pass"], $this->config["database"]);
}
function addPost($post){
return $this->db->query("INSERT INTO posts
(id, name, date, reply, board, post, info, style, fortune, roll, admin)
VALUES (" . $post["id"] . ", '" . $post["name"] . "', '" . $post["date"]
. "', " . $post["reply"] . ", '" . $post["board"] . "', '" . $post["post"]
. " ', '" . $post["info"] . "', '" . $post["style"] . "', '" . $post["fortune"]
. "', '" . $post["roll"] . "', '" . $post["admin"] . "');") or die($this->db->error);
}
// get a single post
function getPost($id){
$query = $this->db->query("SELECT * from posts WHERE id = " . $id) or die($this->db->error);
return $query->fetch_assoc();
}
// get a single post
function getPosts(){
$query = $this->db->query("SELECT * from posts") or die($this->db->error);
return $query;
}
function getThreads(){
$query = $this->db->query("SELECT * from posts WHERE reply = 0 ORDER BY id DESC") or die($this->db->error);
return $query;
}
function getReplies($id){
$query = $this->db->query("SELECT * from posts WHERE reply = " . $id) or die($this->db->error);
return $query;
}
function getReplyCount($id){
$query = $this->db->query("SELECT COUNT(*) FROM posts WHERE reply = " . $id) or die($this->db->error);
return $query;
}
function getLatestReplies($id){
$query = $this->db->query("SELECT * from posts WHERE reply = " . $id . " ORDER BY id DESC LIMIT 5") or die($this->db->error);
return $query;
}
}
class render{
// Render a thread for catalog.
function catalog($db, $post){
return '<a href="threads/' . $post["id"] . '.html"><div class="catalogThread">
<span class="catalogReplies"><span class="catalogRepliesCount">' . strval($db->getReplies($post["id"])->num_rows) . '</span><span class="catalogRepliesText">replies</span></span>
<span class="catalogContent"><span class="catalogThreadTitle">' . $post["name"] . '</span>
<span class="catalogThreadDate">' . $post["date"] . '</span></span>
</div></a>';
}
// Render an OP post.
function op($post){
return '' .
'<span class="postHeadline">' . $post["name"] . '</span>' .
'<span class="postDate"> ' . $post["date"] . '</span>' .
'<span class="postName"> No. ' . $post["id"] . '</span>' .
'<p>' . str_replace("\r\n", "<br>" , $post["post"]) . '</p></div>';
}
// Render a Reply post.
function reply($post){
return '<div class="reply">' .
'<span class="postName">' . $post["name"] . '</span>' .
'<span class="postDate"> ' . $post["date"] . '</span>' .
'<span class="postNum">' . "<a href='#" . $post["id"] . "'> No. " . $post["id"] . '</a></span>' .
'<p>' . str_replace("\r\n", "<br>" , $post["post"]) . '</p>' .
'</div>';
}
// render a new thread form
function newThreadForm(){
return '<div id="thread"><form action="createthread.php" method="post" id="newthread"><table><tr><h1>New Thread</h1><td id="postTable">Headline:</td><td> <input type="text" name="name" value=""><input type="submit" value="Post"></td><input type="text" name="reply" value="0" style="display:none;"><input type="text" name="board" value="lounge" style="display:none;"></tr><tr><td id="postTable">Post:</td><td><textarea name="post"></textarea></td></tr></table></form></div>';
}
// render a new reply form
function newReplyForm($id){
return '<div id="thread"><form action="createthread.php" method="post" id="newthread"><table><tr><h1>Reply</h1><td id="postTable">Name:</td><td> <input type="text" name="name" value=""><input type="submit" value="Post"></td><input type="text" name="reply" value="' . $id . '" style="display:none;"><input type="text" name="board" value="lounge" style="display:none;"></tr><tr><td id="postTable">Post:</td><td><textarea name="post"></textarea></td></tr></table></form></div>';
}
}
class buildHTML{
public $db;
public $posts;
function __construct($db){
$this->db = $db; //give it the class, not the config
}
function insertHTML($file, $content){
return str_replace("<!--[[CONTENT]]-->", $content,file_get_contents($file));
}
function threads(){
$result = "";
for($i=0; $i < count($this->threads);$i++){
$result = $result . render::op($this->threads, $i);
$repliesArray = $this->db->getLatestReplies($this->posts[$i]["id"]);
for($x=0; $x < count($repliesArray);$x++){
$result = $result . render::reply($repliesArray, $x);
}
}
return buildHTML::insertHTML("html/threads.html", $result);
}
function thread($id){
$result = "";
$result = $result . render::op($this->db->getPost($id));
$replies = $this->db->getReplies($id);
while($reply = $replies->fetch_assoc()){
$result = $result . render::reply($reply);
}
$result = $result . render::newReplyForm($id);
return buildHTML::insertHTML("html/threads.html", $result);
}
function frontpage(){
$result = "";
$threads = $this->db->getThreads();
while($thread = $threads->fetch_assoc()){
$result = $result . render::op($thread);
$replies = $this->db->getLatestReplies($thread["id"]);
$result = $result . "<div id='more'><a href='thread.php?q=" . $thread["id"] . "'>See " . strval($this->db->getReplies($thread["id"])->num_rows) . " replies.</a></div>";
while($reply = $replies->fetch_assoc()){
$result = $result . render::reply($reply);
}
$result = $result . render::newReplyForm($thread["id"]);
}
return buildHTML::insertHTML("html/threads.html", $result);
}
function catalog(){
$threads = $this->db->getThreads();
$result = "";
while($thread = $threads->fetch_assoc()){
$result = $result . render::catalog($this->db, $thread);
}
return buildHTML::insertHTML("html/threads.html", $result);
}
}
?>

9
catalog.php Normal file
View File

@ -0,0 +1,9 @@
<?php
include "board.php";
include "config.php";
$db = new db($config);
$db->connect();
$html = new buildHTML($db);
echo $html->catalog();
?>

9
config.php Normal file
View File

@ -0,0 +1,9 @@
<?php
$config = [
"server" => "changeme",
"database" => "changeme",
"table" => "changeme",
"user" => "changeme",
"pass" => "changeme"
];
?>

39
createthread.html Normal file
View File

@ -0,0 +1,39 @@
<html>
<head>
<title>GetgleBBS</title>
<link rel="stylesheet" href="threads.css">
</head>
<body>
<div id="page">
<div id="header">
<span class="logo">monkey cage</span><br>
<a href="index.php">frontpage,</a>
<a href="catalog.php">catalog,</a>
<a href="createthread.html">create thread</a>
</div>
<div id="threads">
<div id="thread">
<form action="createthread.php" method="post" id="newthread">
<table>
<tr>
<h1>New Thread</h1>
<td id="postTable">Headline:</td>
<td> <input type="text" name="name" value=""><input type="submit" value="Post"></td>
<input type="text" name="reply" value="0" style="display:none;">
<input type="text" name="board" value="lounge" style="display:none;">
</tr>
<tr>
<td id="postTable">Post:</td>
<td><textarea name="post"></textarea></td>
</tr>
</table>
</form>
</div>
</div>
</div>
<div id="footer">
powered by getglebbs3
</div>
</body>
</html>

80
createthread.php Normal file
View File

@ -0,0 +1,80 @@
<style>
body{
color:#f00;
background:#000;
}
</style>
<body>
<?php
include "config.php";
include "board.php";
$postAllowed = true;
$postName = $_POST["name"];
$postText = $_POST["post"];
$postReply = $_POST["reply"];
$postBoard = $_POST["board"];
$postAdmin = NULL; // admin post?
if(isset($postAdmin)){
if($postAdmin != $bbspass){
$postAllowed = false;
echo "ERROR: INCORRECT ADMIN PASSWORD.";
}
}
if(!isset($postName) or $postName == ""){
if($postReply == 0){
$postAllowed = false;
echo "ERROR: Please enter a title for your thread.";
} else {
$postName = indianName();
}
}
if(!(isset($postText)) or $postText == ""){
$postAllowed = false;
echo "ERROR: You didn't enter a post.";
}
if(!(isset($postReply)) or $postReply == ""){
$postAllowed = false;
echo "You know what you did, idiot.";
}
if(!(isset($postBoard)) or $postBoard == ""){
$postAllowed = false;
echo "Board not specified";
}
if(strlen($postText) > 4096){
$postAllowed = false;
echo "Your post is too long. Maximum post size is 4,096 chars.";
}
if(strlen($postName) > 256){
$postAllowed = false;
echo "Your post name is too long. Maximum name size is 256 chars.";
}
// Finally, lets get to the posting.
if($postAllowed == true){
$bbspass = "changeme";
$db = new db($config);
$db->connect();
$newPost = array(
"id" => $db->getPosts()->num_rows+1,
"name" => htmlspecialchars($postName),
"date" => date("Y/m/d g:i:s"),
"reply" => intval($postReply),
"board" => $postBoard,
"post" => htmlspecialchars($postText),
"info" => crypt($_SERVER['REMOTE_ADDR'], $bbspass), // used for IP banning people without storing their ip as plaintext
"style" => "normal",
"fortune" => "none",
"roll" => "none",
"admin" => "none"
);
$new = $newPost;
echo $db->addPost($new);
header("Location: index.php");
} else {
echo "not allowed";
}
?>
</body>

21
html/catalog.html Normal file
View File

@ -0,0 +1,21 @@
<html>
<head>
<title>GetgleBBS 2.0</title>
<link rel="stylesheet" href="threads.css">
</head>
<body>
<div id="header">
<span class="logo">GetgleBBS - /all/</span><br>
<a href="1.html">frontpage,</a>
<a href="catalog.html">catalog,</a>
<a href="1.html#newthread">create thread</a>
</div>
<div id="catalog">
<!--[[CONTENT]]-->
</div>
<div id="footer">
powered by getglebbs 2.0
</div>
</body>
</html>

13
html/form.html Normal file
View File

@ -0,0 +1,13 @@
<form action="createthread.php" method="post">
<table>
<tr>
<td id="postTable">Name:</td><td> <input type="text" name="name" value=""><input type="submit" value="Post"></td>
<input type="text" name="reply" value="<-[REPLY]->" style="display:none;">
<input type="text" name="board" value="<-[BOARD]->" style="display:none;">
</tr>
<tr>
<td id="postTable">Post:</td><td><textarea name="post"></textarea></td>
</tr>
</table>
</form>

21
html/thread.html Normal file
View File

@ -0,0 +1,21 @@
<html>
<head>
<title>GetgleBBS</title>
<link rel="stylesheet" href="../../thread.css">
</head>
<body>
<div id="page">
<div id="header">
<span class="logo">GetgleBBS - /all/</span><br>
<a href="../1.html">frontpage,</a>
<a href="../catalog.html">catalog,</a>
<a href="../1.html#newthread">create thread</a>
</div>
<!--[[CONTENT]]-->
<a href="1.html">return to frontpage</a>
</div>
<div id="footer">
powered by getglebbs3
</div>
</body>
</html>

23
html/threads.html Normal file
View File

@ -0,0 +1,23 @@
<html>
<head>
<title>GetgleBBS</title>
<link rel="stylesheet" href="threads.css">
</head>
<body>
<div id="page">
<div id="header">
<span class="logo">monkey cage</span><br>
<a href="index.php">frontpage,</a>
<a href="catalog.php">catalog,</a>
<a href="createthread.html">create thread</a>
</div>
<div id="threads">
<!--[[CONTENT]]-->
</div>
</div>
<div id="footer">
powered by getglebbs3
</div>
</body>
</html>

10
index.php Normal file
View File

@ -0,0 +1,10 @@
<?php
include "board.php";
include "config.php";
$db = new db($config);
$db->connect();
$html = new buildHTML($db);
echo $html->frontpage();
//print_r($db->getPost(11));
?>

143
thread.css Normal file
View File

@ -0,0 +1,143 @@
.infoBox{
background:#ea8;
border:1px solid #800;
padding:0 5px;
}
body{
padding:10px;
color:#031;
font-family: "Lucida Console", Monaco, monospace;
font-size: 10pt;
text-align:center;
background: #fff url("fade.png") top center repeat-x;
margin:auto;
}
#page{
background:#fff;
width:95%;
padding:10px;
display:inline-block;
text-align:left;
padding-bottom:500px;
}
#header{
text-align:center;
}
#more{
text-align:center;
width:100%;
}
#threads{
margin:20px;
}
#thread{
width:100%;
display:inner-block;
padding:10px;
border:1px solid #000;
text-align:left;
margin:20px;
}
header{
padding:10px;
border:1px solid #000;
}
.postHeadline{
color:#096;
font-weight: 700;
font-size:24px;
}
.postName{
color: #117743;
font-weight: 700;
}
#catalogTable{
text-align:center;
}
.reply{
margin:8px;
padding:15px;
border-top: 1px solid #ccc;
overflow-wrap: break-word;
}
#postBox{
margin:8px;
background:#f0e0d6;
border: 1px solid #d9bfb7
}
#postTable{
background-color: #0fa;
color: #031;
font-weight: 700;
border: 1px solid #800;
padding: 0 5px;
font-size: 10pt;
}
textarea{
width:320px;
height:100;
}
#powered{
margin:8px;
padding:5px;
font-size:8px;
font-weight:800;
}
.logo{
font-size:24px;
}
#boards{
}
a{
color:#096;
}
.pageLinkActive{
color:#f00;
}
#pageList{
overflow-wrap:break-word;
margin:auto;
text-align:center;
margin:5px;
}
#catalog{
width:90%;
}
.catalogContent{
display:inline-block;
padding:25px;
height:100%;
}
.catalogThread{
display:inline-block;
text-align:left;
padding:10px;
margin:10px;
width:100%;
height:24px;
height: 60px;
border: 1px solid #000;
}
.catalogReplies{
display:inline-block;
text-align:center;
float:left;
padding:10px;
}
.catalogRepliesCount{
font-size:24px;
}
.catalogRepliesText{
display:block;
}
.catalogThreadTitle{
}
.catalogThreadDate{
text-align:right;
}

10
thread.php Normal file
View File

@ -0,0 +1,10 @@
<?php
include "board.php";
include "config.php";
$db = new db($config);
$db->connect();
$html = new buildHTML($db);
echo $html->thread($_GET["q"]);
//print_r($db->getPost(11));
?>

133
threads.css Normal file
View File

@ -0,0 +1,133 @@
.infoBox{
background:#ea8;
border:1px solid #800;
padding:0 5px;
}
body{
color:#031;
font-family: "Lucida Console", Monaco, monospace;
font-size: 10pt;
background: #fff url("fade.png") top center repeat-x;
}
#page{
background:#fff;
width:100%;
margin:0;
padding:0;
}
#more{
text-align:center;
width:100%;
}
#threads{
}
#thread{
display:inner-block;
padding:10px;
border:1px solid #000;
text-align:left;
margin:20px;
}
header{
padding:10px;
border:1px solid #000;
}
.postHeadline{
color:#096;
font-weight: 700;
font-size:24px;
}
.postName{
color: #117743;
font-weight: 700;
}
#catalogTable{
text-align:center;
}
.reply{
margin:8px;
padding:15px;
border-top: 1px solid #ccc;
overflow-wrap: break-word;
}
#postBox{
margin:8px;
background:#f0e0d6;
border: 1px solid #d9bfb7
}
#postTable{
background-color: #0fa;
color: #031;
font-weight: 700;
border: 1px solid #800;
padding: 0 5px;
font-size: 10pt;
}
textarea{
width:320px;
height:100;
}
#powered{
margin:0 auto;
padding:5px;
font-size:8px;
font-weight:800;
text-align:center;
}
.logo{
font-size:24px;
}
#boards{
}
a{
color:#096;
}
.pageLinkActive{
color:#f00;
}
#pageList{
overflow-wrap:break-word;
margin:auto;
text-align:center;
margin:5px;
}
#catalog{
width:90%;
}
.catalogContent{
display:inline-block;
padding:25px;
height:100%;
}
.catalogThread{
display:inline-block;
text-align:left;
padding:10px;
margin:10px;
width:100%;
height:24px;
height: 60px;
border: 1px solid #ccc;
}
.catalogReplies{
display:inline-block;
text-align:center;
float:left;
padding:10px;
}
.catalogRepliesCount{
font-size:24px;
}
.catalogRepliesText{
display:block;
}
.catalogThreadTitle{
}
.catalogThreadDate{
text-align:right;
}