summaryrefslogtreecommitdiff
path: root/viewthread.php
blob: d0a387e7e7895e92e8745f4ce7d44b3276f17990 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
include_once './includes/model/User.php';
include_once './includes/model/Thread.php';
include_once './includes/model/Post.php';

session_start();

if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
	http_response_code(404);
	include('includes/templates/404.php');
	die();
} 

$current = new Thread($_GET['id']);
if (!$current->has_value()) {
	http_response_code(404);
	include('includes/templates/404.php');
	die();
}
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<title><?= $current->subject; ?> - cflip.net forum</title>
<?php include_once 'includes/templates/head.php'; ?>
		<meta property="og:site_name" content="cflip.net forum">
		<meta property="og:title" content="<?= $current->subject; ?>">
		<meta property="og:url" content="https://forum.cflip.net/viewthread.php?id=<?= $current->id; ?>">
		<meta property="og:type" content="article">
	</head>
	<body>
<?php include_once 'includes/templates/header.php'; ?>
		<h1><?= $current->subject; ?></h1>
		created by <b><?= $current->get_author()->name; ?></b>
		in <b><?= $current->get_parent_category()->name; ?></b>, <?= date('M d, Y g:ia', strtotime($current->date_created)); ?>
<?php if (Session::get()->is_signed_in() and Session::get()->get_current_user()->level == USER_LEVEL_MODERATOR): ?>
		<a href="moderate.php?type=thread&id=<?= $current->id; ?>">Moderator Options</a>
<?php endif ?>
		<hr>
<?php 
foreach ($current->get_posts() as $post) {
	echo $post->get_content();
} 
?>
		<hr>
		<h2>Reply to this thread</h2>
<?php
include_once 'includes/error.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	if (!Session::get()->is_signed_in()) {
		trigger_error('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);

	if (empty($post_content) or !$post_content) {
		trigger_error('Reply cannot be empty');
	} else {
		Post::create($post_content, $current->id, $current->category_id);
		header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $current->id);
	}
}
?>
		<form method="post">
			<textarea name="post_content" rows="10" cols="50"></textarea>
			<br>
			<input type="submit" name="submit">
		</form>
	</body>
</html>