diff --git a/public/css/dk.css b/public/css/dk.css index 3d101fb..f0a02c7 100644 --- a/public/css/dk.css +++ b/public/css/dk.css @@ -13,6 +13,7 @@ html { body { background-image: url('/img/backgrounds/classic.jpg'); + scrollbar-gutter: stable both-edges; &.skin-1 { background-image: url('/img/backgrounds/snowstorm.jpg'); diff --git a/src/actions/forum.php b/src/actions/forum.php index a587229..c175c86 100644 --- a/src/actions/forum.php +++ b/src/actions/forum.php @@ -19,22 +19,44 @@ function register_routes(Router $r): Router function donothing($start = 0) { $query = db()->query('SELECT * FROM forum WHERE parent=0 ORDER BY newpostdate DESC LIMIT 20 OFFSET ?;', [20 * $start]); - $page = "
\n"; + $page = << + +
New Thread
ThreadRepliesLast Post
+ + + + + + + + + + HTML; $hasRows = false; while ($row = $query->fetchArray(SQLITE3_ASSOC)) { $hasRows = true; - $page .= "\n"; + $page .= << + + + + + HTML; } if (!$hasRows) { - $page .= "\n"; + $page .= ''; } - $page .= "
+
New Thread
+
ThreadRepliesLast Post
".$row["title"]."".$row["replies"]."".$row["newpostdate"]."
{$row['title']}{$row['replies']}{$row['newpostdate']}
No threads in forum.
No threads in forum.
"; + $page .= '
'; - return display($page, "Forum"); + page_title('Forum'); + return is_htmx() ? $page : display($page); } function showthread($id, $start) @@ -42,28 +64,25 @@ 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"; + $page = "
Forum :: ".$title['title']."
\n"; while ($row = $posts->fetchArray(SQLITE3_ASSOC)) { $page .= "\n"; } $page .= "
Forum :: ".$title['title']."
".$row["author"]."

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

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

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

"; - return display($page, "Forum"); + page_title('Forum: '.$title['title']); + return is_htmx() ? $page : display($page); } function reply() { - global $userrow; - $form = validate($_POST, [ 'title' => [], 'content' => [] ]); - if (!$form['valid']) { - exit(ul_from_validate_errors($form['errors'])); - } + if (!$form['valid']) exit(ul_from_validate_errors($form['errors'])); $form = $form['data']; @@ -71,7 +90,7 @@ function reply() user()->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"); + return showthread($form['parent'], 0); } function newthread() @@ -82,17 +101,16 @@ function newthread() 'content' => [] ]); - if (!$form['valid']) { - exit(ul_from_validate_errors($form['errors'])); - } + if (!$form['valid']) exit(ul_from_validate_errors($form['errors'])); $form = $form['data']; db()->query('INSERT INTO forum (author, title, content) VALUES (?, ?, ?);', [ user()->username, $form['title'], $form['content'] ]); - redirect('/forum'); + redirect('/forum/thread/'.db()->lastInsertRowID().'/0'); } - $page = "
Make A New Post:

Title:


Message:


"; - return display($page, "Forum"); + $page = "
Make A New Post:

Title:


Message:


"; + page_title('Form: New Thread'); + return is_htmx() ? $page : display($page); } diff --git a/src/lib.php b/src/lib.php index fa96bc7..ad5bca4 100644 --- a/src/lib.php +++ b/src/lib.php @@ -104,7 +104,7 @@ function display_admin($content, $title) /** * Finalize page and output to browser. */ -function display($content, $title, bool $topnav = true, bool $leftnav = true, bool $rightnav = true): string +function display($content, $title = '', bool $topnav = true, bool $leftnav = true, bool $rightnav = true): string { global $controlrow; diff --git a/src/models/model.php b/src/models/model.php index 664246d..1e1dd13 100644 --- a/src/models/model.php +++ b/src/models/model.php @@ -20,7 +20,7 @@ class Model public function __set(string $key, mixed $value): void { if (array_key_exists($key, $this->original_data)) { - $this->changes[$key] = $value; + if ($value !== $this->original_data[$key]) $this->changes[$key] = $value; } else { throw new InvalidArgumentException("Attempted to write to $key, which doesn't exist in the data for this model."); }