summaryrefslogtreecommitdiff
path: root/viewthread.php
diff options
context:
space:
mode:
Diffstat (limited to 'viewthread.php')
-rw-r--r--viewthread.php79
1 files changed, 39 insertions, 40 deletions
diff --git a/viewthread.php b/viewthread.php
index d41fb9b..e8eda06 100644
--- a/viewthread.php
+++ b/viewthread.php
@@ -1,6 +1,5 @@
<?php
-include_once 'includes/db_inc.php';
-include_once 'model/Thread.php';
+include_once 'includes/model/Thread.php';
session_start();
@@ -8,37 +7,37 @@ $current = new Thread();
if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
http_response_code(404);
- include_once 'templates/404.php';
+ include('includes/templates/404.php');
die();
} else {
- $result = $current->get_from_database($_GET['id'], $dbc);
- if ($result == 0) {
+ $result = $current->get_from_database($_GET['id']);
+
+ if (!$result) {
http_response_code(404);
- include_once 'templates/404.php';
+ include('includes/templates/404.php');
die();
}
}
?>
<!DOCTYPE html>
-<html>
+<html lang="en">
<head>
- <title><?= $current->subject; ?> - cflip.net forum</title>
- <link rel="stylesheet" href="styles/style.css">
+ <title><?= $current->subject; ?> - cflip.net forum</title>
+ <link rel="stylesheet" href="styles/style.css">
</head>
<body>
- <?php include_once 'templates/header.php';?>
- <h1><?= $current->subject; ?></h1>
- created by <b><?= $current->author->name; ?></b>
- in <b><?= $current->category->name; ?></b>
- <abbr title="<?= date('M d, Y g:ia', strtotime($current->date_created));?>">3 days ago</abbr>
+<?php include('includes/templates/header.php'); ?>
+<h1><?= $current->subject; ?></h1>
+created by <b><?= $current->author->name; ?></b>
+in <b><?= $current->category->name; ?></b>
+<abbr title="<?= date('M d, Y g:ia', strtotime($current->date_created)); ?>">3 days ago</abbr>
<?php
-include_once 'model/User.php';
+include_once('includes/model/User.php');
-if (isset($_SESSION['signed_in'])) {
- $user = new User();
- $user->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 '
<form action="moderate.php" method="post">
<p>
@@ -57,41 +56,41 @@ if (isset($_SESSION['signed_in'])) {
}
}
?>
- <hr>
- <?php
- $posts = $current->get_posts($dbc);
+<hr>
+<?php
+include './includes/functions_post.php';
- foreach ($posts as $post) {
- $post->display_content($dbc);
- }
- ?>
- <hr>
- <h2>Reply to this thread</h2>
- <form method="post">
- <textarea name="post_content" rows="10" cols="50"></textarea>
- <br>
- <input type="submit" name="submit">
- </form>
+$posts = $current->get_posts();
+
+foreach ($posts as $post) {
+ echo get_post_content($post);
+}
+?>
+<hr>
+<h2>Reply to this thread</h2>
+<form method="post">
+ <textarea name="post_content" rows="10" cols="50"></textarea>
+ <br>
+ <input type="submit" name="submit">
+</form>
</body>
</html>
<?php
-include_once 'includes/db_inc.php';
-include_once 'includes/functions_insert.php';
+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 <a href="signin.php">signed in</a> 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';
} else {
- insert_post($dbc, $post_content, $current->id, $user_id, $current->category->id);
+ create_post($post_content, $current->id, $current->category->id);
+ header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $current->id);
}
}
-
?>