From 6c9369ad85f2fb3dc61234b54db7e7079cdc0c4e Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Fri, 23 Apr 2021 18:43:12 -0600 Subject: Refactoring part 1 --- viewthread.php | 60 +++++++++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'viewthread.php') diff --git a/viewthread.php b/viewthread.php index d41fb9b..ae08090 100644 --- a/viewthread.php +++ b/viewthread.php @@ -1,6 +1,6 @@ get_from_database($_GET['id'], $dbc); if ($result == 0) { http_response_code(404); - include_once 'templates/404.php'; + include('includes/templates/404.php'); die(); } } ?> - + - <?= $current->subject; ?> - cflip.net forum - + <?= $current->subject; ?> - cflip.net forum + - -

subject; ?>

- created by author->name; ?> - in category->name; ?> - 3 days ago + +

subject; ?>

+created by author->name; ?> +in category->name; ?> +3 days ago -
- get_posts($dbc); +
+get_posts($dbc); - foreach ($posts as $post) { - $post->display_content($dbc); - } - ?> -
-

Reply to this thread

-
- -
- -
+foreach ($posts as $post) { + $post->display_content($dbc); +} +?> +
+

Reply to this thread

+
+ +
+ +
signed in to reply to this thread.'; return; - } + } $post_content = filter_input(INPUT_POST, 'post_content', FILTER_SANITIZE_STRING); $user_id = filter_var($_SESSION['user_id'], FILTER_SANITIZE_NUMBER_INT); @@ -93,5 +90,4 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { insert_post($dbc, $post_content, $current->id, $user_id, $current->category->id); } } - ?> -- cgit v1.2.3 From 7c3f2e348c015ea93563d866f89ec8cea9159ea0 Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Sat, 24 Apr 2021 09:40:20 -0600 Subject: Refactoring part 2 Starting to move some functionality such as the session and database connection into singleton classes to manage them. Functions for modifying posts and threads are being put in one place as well. --- viewthread.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'viewthread.php') diff --git a/viewthread.php b/viewthread.php index ae08090..cc2d221 100644 --- a/viewthread.php +++ b/viewthread.php @@ -34,11 +34,10 @@ in category->name; ?> get_by_id($_SESSION['user_id'], $dbc); +if (Session::get()->is_signed_in()) { + $user = Session::get()->get_current_user(); - if ($user->level > 0) { + if ($user->level == USER_LEVEL_MODERATOR) { echo '

@@ -75,6 +74,8 @@ foreach ($posts as $post) { signed in to reply to this thread.'; @@ -87,7 +88,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (empty($post_content) or !$post_content) { echo 'Thread subject cannot be empty'; } else { - insert_post($dbc, $post_content, $current->id, $user_id, $current->category->id); + create_post($post_content, $current->id, $current->category->id); } } ?> -- cgit v1.2.3 From 2098bf444afadcf0363d89b4cc1dca5d2213d754 Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Sat, 24 Apr 2021 19:40:50 -0600 Subject: Remove all uses of db_inc.php This method of importing the database login every time wasn't very good. Now everything uses the new Database singleton class. --- viewthread.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'viewthread.php') diff --git a/viewthread.php b/viewthread.php index cc2d221..73a02ef 100644 --- a/viewthread.php +++ b/viewthread.php @@ -1,6 +1,5 @@ get_from_database($_GET['id'], $dbc); - if ($result == 0) { + $result = $current->get_from_database($_GET['id']); + + if (!$result) { http_response_code(404); include('includes/templates/404.php'); die(); @@ -58,10 +58,12 @@ if (Session::get()->is_signed_in()) { ?>


get_posts($dbc); +include './includes/functions_post.php'; + +$posts = $current->get_posts(); foreach ($posts as $post) { - $post->display_content($dbc); + echo get_post_content($post); } ?>
-- cgit v1.2.3 From fe3e6194d33d63f149f2a362adf325019278d61e Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Sat, 24 Apr 2021 19:50:59 -0600 Subject: Use Session class instead of $_SESSION --- viewthread.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'viewthread.php') diff --git a/viewthread.php b/viewthread.php index 73a02ef..812db0a 100644 --- a/viewthread.php +++ b/viewthread.php @@ -79,13 +79,12 @@ foreach ($posts as $post) { include_once 'includes/functions_post.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { - if (!isset($_SESSION['signed_in'])) { + if (!Session::get()->is_signed_in()) { echo 'You must be signed in to reply to this thread.'; return; } $post_content = filter_input(INPUT_POST, 'post_content', FILTER_SANITIZE_STRING); - $user_id = filter_var($_SESSION['user_id'], FILTER_SANITIZE_NUMBER_INT); if (empty($post_content) or !$post_content) { echo 'Thread subject cannot be empty'; -- cgit v1.2.3 From df9177492976ba968a556a52cc155477652089dc Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Sun, 25 Apr 2021 17:47:41 -0600 Subject: Reload page after submitting a reply to a thread --- viewthread.php | 1 + 1 file changed, 1 insertion(+) (limited to 'viewthread.php') diff --git a/viewthread.php b/viewthread.php index 812db0a..e8eda06 100644 --- a/viewthread.php +++ b/viewthread.php @@ -90,6 +90,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { echo 'Thread subject cannot be empty'; } else { create_post($post_content, $current->id, $current->category->id); + header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $current->id); } } ?> -- cgit v1.2.3