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 '
' . strval($db->getReplies($post["id"])->num_rows) . 'replies ' . $post["name"] . ' ' . $post["date"] . '
'; } // Render an OP post. function op($post){ return '' . '' . $post["name"] . '' . ' ' . $post["date"] . '' . ' No. ' . $post["id"] . '' . '

' . str_replace("\r\n", "
" , $post["post"]) . '

'; } // Render a Reply post. function reply($post){ return '
' . '' . $post["name"] . '' . ' ' . $post["date"] . '' . '' . " No. " . $post["id"] . '' . '

' . str_replace("\r\n", "
" , $post["post"]) . '

' . '
'; } // render a new thread form function newThreadForm(){ return '

New Thread

Headline:
Post:
'; } // render a new reply form function newReplyForm($id){ return '

Reply

Name:
Post:
'; } } 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,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 . "
See " . strval($this->db->getReplies($thread["id"])->num_rows) . " replies.
"; 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); } } ?>