summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcflip <36554078+cflip@users.noreply.github.com>2021-03-21 10:54:47 -0600
committercflip <36554078+cflip@users.noreply.github.com>2021-03-21 10:54:47 -0600
commit2805ef7311eeb028cd48bffe04a705676c4682be (patch)
tree59c00c77d5bd59ea89967f18d5bcd6d1b5ad6e01
parentf83530a122119d7f69812493f9c2f4987ccb2065 (diff)
big changes pt1
-rw-r--r--.htaccess5
-rw-r--r--TODO17
-rw-r--r--all-posts.php28
-rw-r--r--category.php91
-rw-r--r--create_thread.php29
-rw-r--r--footer.php4
-rw-r--r--header.php28
-rw-r--r--includes/.htaccess0
-rw-r--r--includes/db_inc.php2
-rw-r--r--includes/functions_display.php14
-rw-r--r--index.php93
-rw-r--r--model/Category.php36
-rw-r--r--model/Thread.php35
-rw-r--r--register.php37
-rw-r--r--signin.php16
-rw-r--r--templates/header.php14
-rw-r--r--thread.php97
-rw-r--r--user.php70
18 files changed, 355 insertions, 261 deletions
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 @@
+<?php session_start()?>
+<!DOCTYPE html>
+<html>
+<head>
+ <title>All posts - cflip.net forum</title>
+</head>
+<body style="width: 720px;margin: auto;">
+ <?php include_once 'templates/header.php'; ?>
+ <h2>All Posts</h2>
+ <?php
+ include_once 'includes/db_inc.php';
+ include_once 'includes/functions_display.php';
+
+ $sql = "SELECT post_id, post_content, post_date, post_author, user_id, user_name FROM posts LEFT JOIN users ON post_author = user_id";;
+ $result = mysqli_query($dbc, $sql);
+
+ if (!$result) {
+ die('Error trying to display posts: ' . mysqli_error($dbc));
+ }
+
+ if (mysqli_num_rows($result) == 0) {
+ echo 'This forum has no posts';
+ } else {
+ display_posts($dbc, 1, $result);
+ }
+ ?>
+</body>
+</html> \ 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 @@
<?php
-
include_once 'includes/db_inc.php';
-include_once 'header.php';
-include_once 'includes/functions_display.php';
+include_once 'model/Category.php';
-if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
- echo '<section>Unknown category.</section>';
-} else {
- echo '<section>';
+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);
+}
+?>
+<!DOCTYPE html>
+<html>
+<head>
+ <title><?php echo $current->name; ?> - cflip.net forum</title>
+</head>
+<body style="width: 720px;margin: auto;">
+<?php include_once 'templates/header.php';?>
+ <h1><?php echo $current->name; ?></h1>
+ <p><?php echo $current->description; ?></p>
+ <?php echo $current->thread_count . ' threads, ' . $current->post_count . ' posts'; ?>
+ <h2>Threads</h2>
+ <table width="100%">
+ <tr>
+ <th>Thread Name</th>
+ <th>Latest Post</th>
+ </tr>
+ <?php
+ include_once 'includes/db_inc.php';
- // Display category name and description
- if (mysqli_num_rows($result) == 0) {
- echo 'This category does not exist';
- } else {
- while ($row = mysqli_fetch_assoc($result)) {
- echo '<h1>' . $row['cat_name'] . '</h1>';
- 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 '</section>';
-
- $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 '<table><tr><th class="left">Thread</th><th class="right">Latest Post</th></tr>';
- display_threads($dbc, $result);
- mysqli_free_result($result);
- echo '</table>';
-}
+ $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 '<tr>';
+ echo '<td><b><a href="../thread/' . $row['thread_id'] . '">' . $row['thread_subject'] . '</a></b><br>';
+ echo '<small>by ' . $row['user_name'] . ' on ' . date('M d, Y', strtotime($row['thread_date_created'])) . '</small></td>';
+ echo '<td>' . date('M d, Y', strtotime($row['thread_date_lastpost'])) . '</td>';
+ echo '</tr>';
+ }
+ }
+ ?>
+ </table>
+</body>
+</html> \ 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 @@
+<?php session_start()?>
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Create a thread - cflip.net forum</title>
+</head>
+<body>
+<h2>Create a new thread</h2>
<?php
-
-include_once 'header.php';
-
-echo '<section><h2>Create a new thread</h2>';
-
if (!isset($_SESSION['signed_in'])) {
die('You must be <a href="signin.php">signed in</a> 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') {
}
?>
-
-</section>
-
-<?php include_once 'footer.php';?>
+</body>
+</html> \ 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 @@
-<footer>Copyright © 2021 cflip.net</footer>
-</div>
-</body>
-</html> \ No newline at end of file
diff --git a/header.php b/header.php
deleted file mode 100644
index c0ccd5c..0000000
--- a/header.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-session_start();
-?>
-
-<!DOCTYPE html>
-<html>
-<head>
- <title>cflip.net forum</title>
- <link rel="stylesheet" href="styles/style.css">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
-</head>
-<body>
-<div id="wrapper">
- <h1 id="title">cflip.net forum<sup style="font-size: small;">beta</sup></h1>
- <nav>
- <a class="nav_button" href="index.php">Home</a>
- <a class="nav_button" href="create_thread.php">Create a thread</a>
-
- <div id="user">
- <?php
- if (isset($_SESSION['signed_in'])) {
- echo 'Signed in as <b><a href="user.php?id='. $_SESSION['user_id'] .'">' . $_SESSION['user_name'] . '</a></b> <a class="nav_button" href="includes/signout_inc.php">Log out</a>';
- } else {
- echo '<a class="nav_button" href="signin.php">Sign in</a> or <a class="nav_button" href="register.php">Register an account</a>';
- }
- ?>
- </div>
- </nav>
diff --git a/includes/.htaccess b/includes/.htaccess
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/includes/.htaccess
diff --git a/includes/db_inc.php b/includes/db_inc.php
index 2d157af..7d743fc 100644
--- a/includes/db_inc.php
+++ b/includes/db_inc.php
@@ -2,7 +2,7 @@
$db_server = 'localhost';
$db_user = 'root';
-$db_pass = '';
+$db_pass = 'admin';
$db_database = 'forum2';
$dbc = mysqli_connect($db_server, $db_user, $db_pass, $db_database);
diff --git a/includes/functions_display.php b/includes/functions_display.php
index 479648f..bf9ed64 100644
--- a/includes/functions_display.php
+++ b/includes/functions_display.php
@@ -86,14 +86,9 @@ function add_quote($dbc, $thread_id, $matches) {
}
}
-function display_posts($dbc, $sql_result) {
- echo '<table>';
- $post_index = 1;
- $thread_id = $_GET['id'];
-
+function display_posts($dbc, $thread_id, $sql_result) {
while ($row = mysqli_fetch_assoc($sql_result)) {
- echo '<tr><th></th><th>' . $post_index . '</th></tr>';
- echo '<tr class="post" id=' . $post_index . '><td>Posted by <a href="user.php?id='. $row['user_id'] .'">' . $row['user_name'] . '</a><br><small>' . date('m/d/Y g:ia', strtotime($row['post_date'])) . '</small></td>';
+ echo '#' . $row['post_id'] . ' Posted by <a href="user.php?id='. $row['user_id'] .'">' . $row['user_name'] . '</a> on ' . date('m/d/Y g:ia', strtotime($row['post_date'])) . '<br>';
$post_content = $row['post_content'];
@@ -110,9 +105,6 @@ function display_posts($dbc, $sql_result) {
// Replace other URLs with links.
$post_content = preg_replace('@\b(http(s)?://)([^\s]*?(?:\.[a-z\d?=/_-]+)+)(?![^<]*?(?:</\w+>|/?>))@i', '<a href="http$2://$3">$0</a>', $post_content);
- echo '<td class="post-content">' . $post_content . '</td></tr>';
-
- $post_index++;
+ echo $post_content;
}
- echo '</table>';
} \ No newline at end of file
diff --git a/index.php b/index.php
index ec81d0a..900918b 100644
--- a/index.php
+++ b/index.php
@@ -1,5 +1,11 @@
-<?php include_once 'header.php';?>
-<section>
+<?php session_start()?>
+<!DOCTYPE html>
+<html>
+<head>
+ <title>cflip.net forum</title>
+</head>
+<body style="width: 720px;margin: auto;">
+ <?php include_once 'templates/header.php'; ?>
<h2>Welcome to the cflip.net forum!</h2>
<p>
This is the beta test of the forum website, so there are lots of features missing. Since there are no moderation features built into the website,
@@ -8,44 +14,55 @@
<p>
If you notice a problem or have an idea for a feature that is missing, <a href="http://51.195.90.7/forum/thread.php?id=40">reply to this thread!</a>
</p>
-</section>
-<table>
+ <h2>Categories</h2>
+ <table>
<tr>
- <th class="left">Category</th>
- <th class="right">Latest Thread</th>
+ <th>Category</th>
+ <th>Threads</th>
+ <th>Posts</th>
+ <th>Latest Thread</th>
</tr>
-<?php
- include_once 'includes/db_inc.php';
- include_once 'includes/functions_display.php';
+ <?php
+ include_once 'includes/db_inc.php';
- $sql = "SELECT cat_id, cat_name, cat_description FROM categories";
- $result = mysqli_query($dbc, $sql);
+ $sql = "SELECT * FROM categories";
+ $result = mysqli_query($dbc, $sql);
+
+ if (!$result) {
+ die('Error trying to display posts: ' . mysqli_error($dbc));
+ }
- if (!$result) {
- die('Failure trying to display categories: ' . mysqli_error($dbc));
- }
-
- display_categories($dbc, $result);
-?>
-</table>
-<table>
- <tr>
- <th class="left">Latest Threads <a href="all.php">View All</a></th>
- <th class="right">Latest Post</th>
+ if (mysqli_num_rows($result) == 0) {
+ echo 'No categories found!';
+ } else {
+ while ($row = mysqli_fetch_assoc($result)) {
+ echo ' <tr>
+ <td>
+ <b><a href="category/' . $row['cat_id'] . '">' . $row['cat_name'] . '</a></b>
+ <br>
+ ' . $row['cat_description'] . '
+ </td>
+ <td>' . $row['cat_thread_count'] . '</td>
+ <td>' . $row['cat_post_count'] . '</td>
+ <td><b>my supercool thread</b><br><small>by <b>cflip</b>, 3 days ago</small></td>
</tr>
-<?php
- include_once 'includes/db_inc.php';
- include_once 'includes/functions_display.php';
-
- $sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name, cat_id, cat_name FROM threads JOIN users ON thread_author = user_id JOIN categories ON thread_cat = cat_id ORDER BY thread_id DESC LIMIT 5";
- $result = mysqli_query($dbc, $sql);
-
- if (!$result) {
- die('Error trying to display threads: ' . mysqli_error($dbc));
- }
-
- display_threads($dbc, $result, true);
- mysqli_free_result($result);
-?>
-</table>
-<?php include_once 'footer.php';?> \ No newline at end of file
+';
+ }
+ }
+ ?>
+ </table>
+ <h2>More from the forum</h2>
+ <table width="100%">
+ <tr>
+ <th>Recent Posts</th>
+ <th>Recent Threads</th>
+ <th>Popular Threads</th>
+ </tr>
+ <tr>
+ <td>test<br>test<br>test<br>test<br></td>
+ <td>test<br>test<br>test<br>test<br></td>
+ <td>test<br>test<br>test<br>test<br></td>
+ </tr>
+ </table>
+</body>
+</html> \ No newline at end of file
diff --git a/model/Category.php b/model/Category.php
new file mode 100644
index 0000000..d98b08b
--- /dev/null
+++ b/model/Category.php
@@ -0,0 +1,36 @@
+<?php
+
+class Category {
+ public $id = 0;
+ public $name = 'Unknown';
+ public $description = 'This category does not exist';
+ public $thread_count = 0;
+ public $post_count = 0;
+
+ function get_from_database($id, $dbc) {
+ $sql = "SELECT cat_name, cat_description, cat_thread_count, cat_post_count FROM categories WHERE cat_id = " . mysqli_real_escape_string($dbc, $id);
+ $result = mysqli_query($dbc, $sql);
+
+ if (!$result) {
+ echo 'Failed to get category: ' . mysqli_error($dbc);
+ }
+
+ if (mysqli_num_rows($result) == 0) {
+ echo 'Category does not exist!';
+ } else {
+ while ($row = mysqli_fetch_assoc($result)) {
+ $this->id = $id;
+ $this->name = $row['cat_name'];
+ $this->description = $row['cat_description'];
+ $this->thread_count = $row['cat_thread_count'];
+ $this->post_count = $row['cat_post_count'];
+ }
+ }
+
+ mysqli_free_result($result);
+ }
+
+ function get_threads() {
+
+ }
+} \ No newline at end of file
diff --git a/model/Thread.php b/model/Thread.php
new file mode 100644
index 0000000..78d2614
--- /dev/null
+++ b/model/Thread.php
@@ -0,0 +1,35 @@
+<?php
+
+include_once 'Category.php';
+
+class Thread {
+ public $id = 0;
+ public $subject = 'Unknown thread';
+ public $date_created = 0;
+ public $date_lastpost = 0;
+ public $category;
+ public $author;
+
+ function get_from_database($id, $dbc) {
+ $sql = "SELECT thread_subject, thread_date_created, thread_date_lastpost, thread_category FROM threads WHERE thread_id = " . mysqli_real_escape_string($dbc, $id);
+ $result = mysqli_query($dbc, $sql);
+
+ if (!$result) {
+ die('Error trying to display thread page: ' . mysqli_error($dbc));
+ }
+
+ if (mysqli_num_rows($result) == 0) {
+
+ } else {
+ while ($row = mysqli_fetch_assoc($result)) {
+ $this->id = $id;
+ $this->subject = $row['thread_subject'];
+ $this->date_created = $row['thread_date_created'];
+ $this->date_lastpost = $row['thread_date_lastpost'];
+
+ $this->category = new Category();
+ $this->category->get_from_database($row['thread_category'], $dbc);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/register.php b/register.php
index efa4486..c17c1dd 100644
--- a/register.php
+++ b/register.php
@@ -1,17 +1,20 @@
-<?php include_once 'header.php';?>
-
-<section>
- <h2>Register an account</h2>
- <form action="register.php" method="post">
- <label for="user_name">Username: </label><br>
- <input type="text" name="user_name"><br>
- <label for="user_pass">Password: </label><br>
- <input type="password" name="user_pass"><br>
- <label for="user_pass_check">Re-enter password: </label><br>
- <input type="password" name="user_pass_check"><br>
- <input type="submit" name="submit">
- </form>
- <br>
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Register an account - cflip.net forum</title>
+</head>
+<body>
+<h2>Register an account</h2>
+<form action="register.php" method="post">
+ <label for="user_name">Username: </label><br>
+ <input type="text" name="user_name"><br>
+ <label for="user_pass">Password: </label><br>
+ <input type="password" name="user_pass"><br>
+ <label for="user_pass_check">Re-enter password: </label><br>
+ <input type="password" name="user_pass_check"><br>
+ <input type="submit" name="submit">
+</form>
+<br>
<?php
include_once 'includes/db_inc.php';
@@ -101,7 +104,5 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
}
}
?>
-
-</section>
-
-<?php include_once 'footer.php';?>
+</body>
+</html> \ No newline at end of file
diff --git a/signin.php b/signin.php
index 4355afe..ba8f147 100644
--- a/signin.php
+++ b/signin.php
@@ -1,6 +1,10 @@
-<?php include_once 'header.php';?>
-
-<section>
+<?php session_start()?>
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Sign in - cflip.net forum</title>
+</head>
+<body>
<h2>Sign in</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<label for="user_name">Username: </label><br>
@@ -70,7 +74,5 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
}
}
?>
-
-</section>
-
-<?php include_once 'footer.php';?> \ No newline at end of file
+</body>
+</html> \ No newline at end of file
diff --git a/templates/header.php b/templates/header.php
new file mode 100644
index 0000000..526f63b
--- /dev/null
+++ b/templates/header.php
@@ -0,0 +1,14 @@
+<h1>cflip.net forum<sup style="font-size: small;">beta</sup></h1>
+[<a href="/forum/">Home</a>]
+[<a href="/forum/all.php">All Threads</a>]
+[<a href="/forum/all-posts.php">All Posts</a>]
+[<a href="/forum/create_thread.php">Create a thread</a>]
+<span style="float:right;">
+ <?php
+ if (isset($_SESSION['signed_in'])) {
+ echo '[<a href="/forum/user/'. $_SESSION['user_name'] .'">' . $_SESSION['user_name'] . '\'s Profile</a>] [<a href="includes/signout_inc.php">Log out</a>]';
+ } else {
+ echo '<a class="nav_button" href="signin.php">Sign in</a> or <a class="nav_button" href="register.php">Register an account</a>';
+ }
+ ?>
+</span> \ No newline at end of file
diff --git a/thread.php b/thread.php
index 97ab6b9..9c43217 100644
--- a/thread.php
+++ b/thread.php
@@ -1,68 +1,43 @@
-<?php include_once 'header.php'; ?>
-
<?php
include_once 'includes/db_inc.php';
-include_once 'includes/functions_display.php';
-
-if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
- echo '<section>Unknown category.</section>';
-} else {
- $sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name FROM threads LEFT JOIN users ON thread_author = user_id WHERE thread_id = " . mysqli_real_escape_string($dbc, $_GET['id']);
- $result = mysqli_query($dbc, $sql);
-
- if (!$result) {
- die('Error trying to display thread page: ' . mysqli_error($dbc));
- }
-
- if (mysqli_num_rows($result) == 0) {
- echo 'This thread does not exist';
- } else {
- while ($row = mysqli_fetch_assoc($result)) {
- echo '<section><h1>' . $row['thread_subject'] . '</h1>';
- echo 'Created by <a href="user.php?id='. $row['user_id'] .'">' . $row['user_name'] . '</a> on ' . date('M d, Y', strtotime($row['thread_date'])) . '</section>';
- $thread_id = $row['thread_id'];
- }
- }
-
- echo '</section>';
+include_once 'model/Thread.php';
- mysqli_free_result($result);
+session_start();
- $sql = "SELECT post_id, post_content, post_date, post_author, user_id, user_name FROM posts LEFT JOIN users ON post_author = user_id WHERE post_thread = " . mysqli_real_escape_string($dbc, $_GET['id']);
- $result = mysqli_query($dbc, $sql);
+$current = new Thread();
- if (!$result) {
- die('Error trying to display posts: ' . mysqli_error($dbc));
- }
-
- if (mysqli_num_rows($result) == 0) {
- echo '<section>This thread has no posts</section>';
- } else {
- display_posts($dbc, $result);
- }
-
- mysqli_free_result($result);
-
- if (isset($_SESSION['signed_in'])) {
- echo '
- <section>
- <form action="includes/reply_inc.php?reply_to=' . $thread_id .'" method="post">
- <h2>Reply to this thread</h2>
- <i>Quote a post with ># and the number above the post (example: >#7)</i>
- <textarea name="reply_content"></textarea>
- <br>
- <input type="submit" name="submit">
- </form>
- </section>
- ';
- } else {
- echo '
- <section>
- <a href="signin.php">Sign in</a> to reply to this thread</a>
- </section>
- ';
- }
+if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
+} else {
+ $current->get_from_database($_GET['id'], $dbc);
}
-
-include_once 'footer.php';
?>
+<!DOCTYPE html>
+<html>
+<head>
+ <title><?php echo $current->subject; ?> - cflip.net forum</title>
+</head>
+<body>
+ <?php include_once 'templates/header.php';?>
+ <h1><?php echo $current->subject; ?></h1>
+ created by <b><?php echo '$current->user->name'; ?></b>
+ in <b><?php echo $current->category->name; ?></b>
+ <abbr title="<?php echo date('M d, Y g:ia', strtotime($current->date_created));?>">3 days ago</abbr>
+ <hr>
+ <?php
+ include_once 'includes/functions_display.php';
+
+ $sql = "SELECT post_id, post_content, post_date, post_author, user_id, user_name FROM posts LEFT JOIN users ON post_author = user_id WHERE post_thread = " . mysqli_real_escape_string($dbc, $_GET['id']);
+ $result = mysqli_query($dbc, $sql);
+
+ if (!$result) {
+ die('Error trying to display posts: ' . mysqli_error($dbc));
+ }
+
+ if (mysqli_num_rows($result) == 0) {
+ echo '<section>This thread has no posts</section>';
+ } else {
+ display_posts($dbc, $_GET['id'], $result);
+ }
+ ?>
+</body>
+</html> \ No newline at end of file
diff --git a/user.php b/user.php
index 62b9144..a5e1d16 100644
--- a/user.php
+++ b/user.php
@@ -1,56 +1,38 @@
<?php
-include_once 'header.php';
include_once 'includes/db_inc.php';
-include_once 'includes/functions_display.php';
-?>
-<?php
-function nobody_is_here() {
- echo 'Nobody\'s here! <a href=index.php>Go home.</a>';
-}
-
-if (!isset($_GET['id'])) {
- nobody_is_here();
-} else {
- // If this is the user's own page, show the 'options' bar
- echo '<section>';
+session_start();
- $sql = 'SELECT user_id, user_name, user_date FROM users WHERE user_id=?';
- $stmt = mysqli_stmt_init($dbc);
+$user_name = "Unknown";
+$user_date = 0;
- if (!mysqli_stmt_prepare($stmt, $sql)) {
- die('Could not create thread due to internal error: ' . mysqli_error($dbc));
- }
- mysqli_stmt_bind_param($stmt, 'i', $_GET['id']);
- mysqli_stmt_execute($stmt);
- $res = mysqli_stmt_get_result($stmt);
- $user = mysqli_fetch_assoc($res);
-
- if (!$user) {
- nobody_is_here();
- } else {
- echo '<div><h1>'. $user['user_name'] .'</h1></div>';
- echo 'Member since '. date('M d, Y', strtotime($user['user_date']));
- }
-
- if (isset($_SESSION['user_id']) && $_SESSION['user_id'] == $_GET['id']) {
- echo '<br><p><a href=change_passw.php>Change Password</a></p>';
- }
-
- echo '</section>';
-
- $sql = "SELECT thread_id, thread_subject, thread_date, user_id, user_name, cat_id, cat_name FROM threads JOIN users ON thread_author = user_id JOIN categories ON thread_cat = cat_id WHERE thread_author = " . $user['user_id'] . " ORDER BY thread_id DESC";
+if (!isset($_GET['name'])) {
+} else {
+ $sql = "SELECT user_date FROM users WHERE user_name = '" . $_GET['name'] . "'";
$result = mysqli_query($dbc, $sql);
if (!$result) {
- die('Error trying to display threads: ' . mysqli_error($dbc));
+ die('Error trying to display user page: ' . mysqli_error($dbc));
}
- echo '<table><tr><th class="left">' . $user['user_name'] . '\'s Threads</th><th class="right">Latest Post</th></tr>';
- display_threads($dbc, $result, true);
- mysqli_free_result($result);
- echo '</table>';
+ if (mysqli_num_rows($result) == 0) {
+ $user_name = "Unknown";
+ } else {
+ while ($row = mysqli_fetch_assoc($result)) {
+ $user_name = $_GET['name'];
+ $user_date = $row['user_date'];
+ }
+ }
}
?>
-
-<?php include_once 'footer.php'; ?>
+<!DOCTYPE html>
+<html>
+<head>
+ <title><?php echo $user_name; ?>'s Profile - cflip.net forum</title>
+</head>
+<body style="width: 720px;margin: auto;">
+ <?php include_once "templates/header.php" ?>
+ <h1><?php echo $user_name; ?></h1>
+ member since <?php echo $user_date; ?>
+</body>
+</html> \ No newline at end of file