-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost.php
198 lines (172 loc) · 9.07 KB
/
post.php
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php $title = "Post" ?>
<?php include "includes/components/header.php" ?>
<!-- Responsive navbar-->
<?php include "includes/components/navbar.php" ?>
<?php
if (isset($_GET["blog"])) {
$blog = getBlog($_GET["blog"]);
$author = getUserByID($blog["author"]);
} else {
header("Location: 404.php");
return;
}
?>
<!-- Page content-->
<div class="container mt-5">
<div class="row">
<div class="col-lg-8">
<!-- Post content-->
<article>
<!-- Post header-->
<header class="mb-4">
<!-- Post title-->
<h1 class="fw-bolder mb-1"><?= $blog["title"] ?></h1>
<!-- Post meta content-->
<div class="text-muted fst-italic mb-2">Posted on <?= date('F d, Y', strtotime($blog["date"])); ?> by <strong><?= $author["first_name"] . " " . $author["last_name"] ?></strong></div>
<!-- Post categories-->
<?php
$tags = explode(",", $blog["tags"]);
foreach ($tags as $key => $value) {
echo "<a class='badge bg-secondary text-decoration-none link-light' href='blogs.php?search=$value'>$value</a> ";
}
?>
</header>
<!-- Preview image figure-->
<figure class="mb-4"><img class="img-fluid rounded" width="900px" height="400px" src="images/blogs/<?= $blog["image"] ?>?123456321" alt="Blog Image" /></figure>
<!-- Post content-->
<section class="mb-5">
<hr>
<p class="fs-5 mb-4"><?= $blog["content"] ?></p>
</section>
</article>
<!-- Comments section-->
<section class="mb-5">
<div class="card bg-light">
<div class="card-body">
<!-- Comment form-->
<?php
if (isset($_SESSION["id"])) {
echo "
<form action='post.php?blog={$blog['id']}' method='POST' class='mb-4'>
<textarea name='content' class='form-control' rows='3' placeholder='Leave a comment!'></textarea>
<br>
<input id='btn' name='comment' type='submit' class='btn btn-primary' value='Post Comment'>
</form>
";
} else {
echo "
<a href='login.php'>Login</a> to post a comment!<br>
<br>
";
}
?>
<hr>
<br>
<div class="comment-area">
<?php
global $connection;
if (isset($_POST["comment"])) {
$commenter = $_SESSION["id"];
$commented_to = $_GET["blog"];
$content = $_POST["content"];
$date = date("Y-m-d");
$sql = "INSERT INTO comments(`commenter`, `commented_to`, `content`, `date`) VALUES(?,?,?,?)";
$query = $connection->prepare($sql);
$query->bind_param("iiss", $commenter, $commented_to, $content, $date);
$query->execute();
header("Location: post.php?blog=$commented_to");
}
$comments = getAllCommentsByPostID($_GET["blog"]);
while ($row = mysqli_fetch_assoc($comments)) {
$user = getUserByID($row['commenter']);
echo "
<div class='d-flex'>
<div class='flex-shrink-0'><img width='50px' class='rounded-circle' src='images/avatars/{$user['avatar']}' alt='...' /></div>
<div class='ms-3'>
<div class='fw-bold'>{$user['username']}</div>
{$row['content']}
<div>
<a class='reply' style='color: blue; cursor: pointer;'>Reply</a>
<form class='reply-form' action='post.php?blog={$blog['id']}' method='POST' style='display: none;'>
<textarea name='content' class='form-control' rows='3' placeholder='Leave a reply!'></textarea>
<input name='comment' type='submit' class='btn btn-primary' value='Post Comment'>
</form>
</div>
</div>
</div>
<hr>
";
}
?>
</div>
<!-- Comment with nested comments-->
<!-- <div class="d-flex mb-4">
<div class="flex-shrink-0"><img class="rounded-circle" src="https://dummyimage.com/50x50/ced4da/6c757d.jpg" alt="..." /></div>
<div class="ms-3">
<div class="fw-bold">Commenter Name</div>
If you're going to lead a space frontier, it has to be government; it'll never be private enterprise. Because the space frontier is dangerous, and it's expensive, and it has unquantified risks.
<div>
<a class="reply" style="color: blue; cursor: pointer;">Reply</a>
<form id='reply-form' action="post.php?blog=" <?= $blog["id"] ?> method="POST" style="display: none;">
<textarea name='content' class='form-control' rows='3' placeholder='Leave a reply!'></textarea>
<input id='btn' name='comment' type='submit' class='btn btn-primary' value='Post Comment'>
</form>
</div>
<div class="d-flex mt-4">
<div class="flex-shrink-0"><img class="rounded-circle" src="https://dummyimage.com/50x50/ced4da/6c757d.jpg" alt="..." /></div>
<div class="ms-3">
<div class="fw-bold">Commenter Name</div>
And under those conditions, you cannot establish a capital-market evaluation of that enterprise. You can't get investors.
</div>
</div>
</div>
</div> -->
</div>
</div>
</section>
</div>
<!-- Side widgets -->
<div class="col-lg-4">
<!-- Categories widget-->
<div class="card mb-4">
<div class="card-header">Posts Like This</div>
<div class="card-body">
<div class="row">
<?php
$others = getPostsLikeThese($blog["title"], $blog['id'])
?>
<div class="col-sm-6">
<ul class="list-unstyled mb-0">
<?php
$i = 1;
while ($row = mysqli_fetch_assoc($others)) {
if ($i === 3) {
break;
}
echo "<li><a href='post.php?blog={$row['id']}'>{$row['title']}</a></li>";
}
?>
</ul>
</div>
<div class="col-sm-6">
<ul class="list-unstyled mb-0">
<?php
$i = 1;
while ($row = mysqli_fetch_assoc($others)) {
if ($i === 3) {
break;
}
echo "<li><a href='post.php?blog={$row['id']}'>{$row['title']}</a></li>";
}
?>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Footer-->
<script src="js/reply.js"></script>
<?php include "includes/components/footer.php" ?>