From 2805ef7311eeb028cd48bffe04a705676c4682be Mon Sep 17 00:00:00 2001
From: cflip <36554078+cflip@users.noreply.github.com>
Date: Sun, 21 Mar 2021 10:54:47 -0600
Subject: big changes pt1
---
.htaccess | 5 +++
TODO | 17 ++++++++
all-posts.php | 28 ++++++++++++
category.php | 91 +++++++++++++++++++++++----------------
create_thread.php | 29 +++++++------
footer.php | 4 --
header.php | 28 ------------
includes/.htaccess | 0
includes/db_inc.php | 2 +-
includes/functions_display.php | 14 ++----
index.php | 93 +++++++++++++++++++++++-----------------
model/Category.php | 36 ++++++++++++++++
model/Thread.php | 35 +++++++++++++++
register.php | 37 ++++++++--------
signin.php | 16 ++++---
templates/header.php | 14 ++++++
thread.php | 97 ++++++++++++++++--------------------------
user.php | 70 +++++++++++-------------------
18 files changed, 355 insertions(+), 261 deletions(-)
create mode 100644 .htaccess
create mode 100644 TODO
create mode 100644 all-posts.php
delete mode 100644 footer.php
delete mode 100644 header.php
create mode 100644 includes/.htaccess
create mode 100644 model/Category.php
create mode 100644 model/Thread.php
create mode 100644 templates/header.php
diff --git a/.htaccess b/.htaccess
new file mode 100644
index 0000000..7e61aa0
--- /dev/null
+++ b/.htaccess
@@ -0,0 +1,5 @@
+RewriteEngine on
+
+RewriteRule ^category/([0-9]+)$ /forum/category.php?id=$1
+RewriteRule ^thread/([0-9]+)$ /forum/thread.php?id=$1
+RewriteRule ^user/([a-zA-Z0-9_]*)$ /forum/user.php?name=$1
\ No newline at end of file
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..65994ae
--- /dev/null
+++ b/TODO
@@ -0,0 +1,17 @@
+IMPROVE EXISTING CODE
+[ ] Object-oriented code
+[ ] Clean up table printing code
+[ ] Fix thread create page
+[ ] Clean up links
+[ ] Create 404 pages
+
+CREATE NEW PAGES
+[ ] Come up with designs for each page
+[ ] Create search page (all posts, threads, users + search)
+[ ] User profile picture + description
+[ ] Scrolling banners for each category
+
+CLEAN UP PAGES
+[ ] Create .htaccess for all pages/directories
+ - block off all .php files
+[ ] Create CSS style
\ No newline at end of file
diff --git a/all-posts.php b/all-posts.php
new file mode 100644
index 0000000..fabeb3c
--- /dev/null
+++ b/all-posts.php
@@ -0,0 +1,28 @@
+
+
+
+
+ All posts - cflip.net forum
+
+
+
+ All Posts
+
+
+
\ No newline at end of file
diff --git a/category.php b/category.php
index 4280767..e559f22 100644
--- a/category.php
+++ b/category.php
@@ -1,46 +1,65 @@
Unknown category.';
-} else {
- echo '';
+session_start();
- $sql = "SELECT cat_name, cat_description FROM categories WHERE cat_id = " . mysqli_real_escape_string($dbc, $_GET['id']);
- $result = mysqli_query($dbc, $sql);
+$current = new Category();
- if (!$result) {
- die('Error trying to display category: ' . mysqli_error($dbc));
- }
+if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
+} else {
+ $current->get_from_database($_GET['id'], $dbc);
+}
+?>
+
+
+
+ name; ?> - cflip.net forum
+
+
+
+ name; ?>
+ description; ?>
+ thread_count . ' threads, ' . $current->post_count . ' posts'; ?>
+ Threads
+
+
+ Thread Name |
+ Latest Post |
+
+ ' . $row['cat_name'] . '';
- echo $row['cat_description'];
+ $threads = current->get_threads();
+ for each thread {
+ $thread->get_latest_post();
}
- }
- mysqli_free_result($result);
+ $sql = "
+ SELECT thread_id, thread_subject, thread_date_created, thread_date_lastpost, thread_category, thread_author, user_id, user_name
+ FROM threads
+ LEFT JOIN users
+ ON thread_author = user_id
+ WHERE thread_category = " . $_GET['id'];
- echo '';
-
- $sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name FROM threads JOIN users ON thread_author = user_id WHERE thread_cat = " . mysqli_real_escape_string($dbc, $_GET['id']) . " ORDER BY thread_id DESC";
- $result = mysqli_query($dbc, $sql);
-
- if (!$result) {
- die('Error trying to display threads: ' . mysqli_error($dbc));
- }
-
- echo 'Thread | Latest Post |
';
- display_threads($dbc, $result);
- mysqli_free_result($result);
- echo '
';
-}
+ $result = mysqli_query($dbc, $sql);
+
+ if (!$result) {
+ die('Error trying to display posts: ' . mysqli_error($dbc));
+ }
-include 'footer.php';
\ No newline at end of file
+ if (mysqli_num_rows($result) == 0) {
+ echo 'No categories found!';
+ } else {
+ while ($row = mysqli_fetch_assoc($result)) {
+ echo '';
+ echo '' . $row['thread_subject'] . ' ';
+ echo 'by ' . $row['user_name'] . ' on ' . date('M d, Y', strtotime($row['thread_date_created'])) . ' | ';
+ echo '' . date('M d, Y', strtotime($row['thread_date_lastpost'])) . ' | ';
+ echo '
';
+ }
+ }
+ ?>
+
+
+
\ No newline at end of file
diff --git a/create_thread.php b/create_thread.php
index 51bfe10..ae3168b 100644
--- a/create_thread.php
+++ b/create_thread.php
@@ -1,9 +1,12 @@
+
+
+
+
+ Create a thread - cflip.net forum
+
+
+Create a new thread
Create a new thread
';
-
if (!isset($_SESSION['signed_in'])) {
die('You must be signed in to create a thread.');
}
@@ -44,7 +47,8 @@ if (!isset($_SESSION['signed_in'])) {
include_once 'includes/db_inc.php';
function create_thread($dbc, $thread_subject, $thread_cat, $thread_author) {
- $sql = "INSERT INTO threads(thread_subject, thread_date, thread_cat, thread_author) VALUES(?, NOW(), ?, ?);";
+ $sql = "INSERT INTO threads(thread_subject, thread_date_created, thread_date_lastpost, thread_category, thread_author) VALUES(?, CONVERT_TZ(NOW(),'SYSTEM','+00:00'), CONVERT_TZ(NOW(),'SYSTEM','+00:00'), ?, ?);
+ UPDATE categories SET cat_thread_count = cat_thread_count + 1 WHERE cat_id = " . $thread_cat . ';';
$stmt = mysqli_stmt_init($dbc);
if (!mysqli_stmt_prepare($stmt, $sql)) {
@@ -56,8 +60,9 @@ function create_thread($dbc, $thread_subject, $thread_cat, $thread_author) {
mysqli_stmt_close($stmt);
}
-function create_post($dbc, $post_content, $post_thread, $post_author) {
- $sql = "INSERT INTO posts(post_content, post_date, post_thread, post_author) VALUES(?, NOW(), ?, ?);";
+function create_post($dbc, $post_content, $post_thread, $post_category, $post_author) {
+ $sql = "INSERT INTO posts(post_content, post_date, post_thread, post_author) VALUES(?, CONVERT_TZ(NOW(),'SYSTEM','+00:00'), ?, ?);
+ UPDATE categories SET cat_post_count = cat_post_count + 1 WHERE cat_id = " . $post_category;
$stmt = mysqli_stmt_init($dbc);
if (!mysqli_stmt_prepare($stmt, $sql)) {
@@ -90,7 +95,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
} else {
create_thread($dbc, $thread_subject, $thread_cat, $user_id);
$thread_id = mysqli_insert_id($dbc);
- $post_result = create_post($dbc, $post_content, $thread_id, $user_id);
+ $post_result = create_post($dbc, $post_content, $thread_id, $thread_cat, $user_id);
if (!$post_result) {
echo 'An error occurred creating your post: ' . mysqli_error($dbc);
} else {
@@ -100,7 +105,5 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
}
?>
-
-
-
-
+
+
\ No newline at end of file
diff --git a/footer.php b/footer.php
deleted file mode 100644
index e786876..0000000
--- a/footer.php
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-