get('/forum/thread/:x/:x', 'Forum\showthread'); $r->form('/forum/new', 'Forum\newthread'); $r->post('/forum/reply', 'Forum\reply'); $r->get('/forum/list/:x', 'Forum\donothing'); $r->get('/forum', 'Forum\donothing'); return $r; } function donothing($start = 0) { $query = db()->query('SELECT * FROM forum WHERE parent=0 ORDER BY newpostdate DESC LIMIT 20 OFFSET ?;', [20 * $start]); $page = "
\n"; $hasRows = false; while ($row = $query->fetchArray(SQLITE3_ASSOC)) { $hasRows = true; $page .= "\n"; } if (!$hasRows) { $page .= "\n"; } $page .= "
New Thread
ThreadRepliesLast Post
".$row["title"]."".$row["replies"]."".$row["newpostdate"]."
No threads in forum.
"; 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 = "
\n"; while ($row = $posts->fetchArray(SQLITE3_ASSOC)) { $page .= "\n"; } $page .= "
Forum :: ".$title['title']."
".$row["author"]."

".prettyforumdate($row["postdate"])."
".nl2br($row["content"])."

"; $page .= "
Reply To This Thread:

"; display($page, "Forum"); } function reply() { global $userrow; $form = validate($_POST, [ 'title' => [], 'content' => [] ]); if (!$form['valid']) { exit(ul_from_validate_errors($form['errors'])); } $form = $form['data']; db()->query('INSERT INTO forum (author, title, content, parent) VALUES (?, ?, ?, ?);', [ $userrow['username'], $form['title'], $form['content'], $form['parent'] ]); db()->query('UPDATE forum SET newpostdate=CURRENT_TIMESTAMP, replies=replies + 1 WHERE id=?;', [$form['parent']]); redirect("/forum/thread/{$form['parent']}/0"); } function newthread() { global $userrow; if (isset($_POST["submit"])) { $form = validate($_POST, [ 'title' => ['length:2-30'], 'content' => [] ]); if (!$form['valid']) { exit(ul_from_validate_errors($form['errors'])); } $form = $form['data']; db()->query('INSERT INTO forum (author, title, content) VALUES (?, ?, ?);', [ $userrow['username'], $form['title'], $form['content'] ]); redirect('/forum'); } $page = "
Make A New Post:

Title:


Message:


"; display($page, "Forum"); }