-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpost.php
More file actions
256 lines (227 loc) · 8.67 KB
/
post.php
File metadata and controls
256 lines (227 loc) · 8.67 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
include "core.php";
head();
if ($settings['sidebar_position'] == 'Left') {
sidebar();
}
?>
<div class="col-md-8 mb-3">
<?php
$slug = $_GET['name'];
if (empty($slug)) {
echo '<meta http-equiv="refresh" content="0; url=blog">';
exit;
}
$runq = mysqli_query($connect, "SELECT * FROM `posts` WHERE active='Yes' AND slug='$slug'");
if (mysqli_num_rows($runq) == 0) {
echo '<meta http-equiv="refresh" content="0; url=blog">';
exit;
}
mysqli_query($connect, "UPDATE `posts` SET views = views + 1 WHERE active='Yes' and slug='$slug'");
$row = mysqli_fetch_assoc($runq);
$post_id = $row['id'];
$post_slug = $row['slug'];
echo '
<div class="card shadow-sm bg-light">
<div class="col-md-12">
';
if ($row['image'] != '') {
echo '
<img src="' . $row['image'] . '" width="100%" height="auto" alt="' . $row['title'] . '"/>
';
}
echo '
<div class="card-body">
<div class="mb-1">
<i class="fas fa-chevron-right"></i> <a href="category?name=' . post_categoryslug($row['category_id']) . '">' . post_category($row['category_id']) . '</a>
</div>
<h5 class="card-title fw-bold">' . $row['title'] . '</h5>
<div class="d-flex justify-content-between align-items-center">
<small>
Posted by <b><i><i class="fas fa-user"></i> ' . post_author($row['author_id']) . '</i></b>
on <b><i><i class="far fa-calendar-alt"></i> ' . date($settings['date_format'], strtotime($row['date'])) . ', ' . $row['time'] . '</i></b>
</small>
<small>
<i class="fa fa-eye"></i> ' . $row['views'] . '
</small>
<small class="float-end">
<i class="fa fa-comments"></i> <a href="#comments"><b>' . post_commentscount($row['id']) . '</b></a>
</small>
</div>
<hr />
' . html_entity_decode($row['content']) . '
<hr />
<h5><i class="fas fa-share-alt-square"></i> Share</h5>
<div id="share" style="font-size: 14px;"></div>
<hr />
<h5 class="mt-2" id="comments">
<i class="fa fa-comments"></i> Comments (' . post_commentscount($row['id']) . ')
</h5>
';
?>
<?php
$q = mysqli_query($connect, "SELECT * FROM comments WHERE post_id='$row[id]' AND approved='Yes' ORDER BY id DESC");
$count = mysqli_num_rows($q);
if ($count <= 0) {
echo '<div class="alert alert-info">There are no comments yet.</div>';
} else {
while ($comment = mysqli_fetch_array($q)) {
$aauthor = $comment['user_id'];
if ($comment['guest'] == 'Yes') {
$aavatar = 'assets/img/avatar.png';
$arole = '<span class="badge bg-secondary">Guest</span>';
} else {
$querych = mysqli_query($connect, "SELECT * FROM `users` WHERE id='$aauthor' LIMIT 1");
if (mysqli_num_rows($querych) > 0) {
$rowch = mysqli_fetch_assoc($querych);
$aavatar = $rowch['avatar'];
$aauthor = $rowch['username'];
if ($rowch['role'] == 'Admin') {
$arole = '<span class="badge bg-danger">Administrator</span>';
} elseif ($rowch['role'] == 'Editor') {
$arole = '<span class="badge bg-warning">Editor</span>';
} else {
$arole = '<span class="badge bg-info">User</span>';
}
}
}
echo '
<div class="row d-flex justify-content-center bg-white rounded border mt-3 mb-3 ms-1 me-1">
<div class="mb-2 d-flex flex-start align-items-center">
<img class="rounded-circle shadow-1-strong mt-1 me-3"
src="' . $aavatar . '" alt="' . $aauthor . '"
width="50" height="50" />
<div class="mt-1 mb-1">
<h6 class="fw-bold mt-1 mb-1">
<i class="fa fa-user"></i> ' . $aauthor . ' ' . $arole . '
</h6>
<p class="small mb-0">
<i><i class="fas fa-calendar"></i> ' . date($settings['date_format'], strtotime($comment['date'])) . ', ' . $comment['time'] . '</i>
</p>
</div>
</div>
<hr class="my-0" />
<p class="mt-1 mb-1 pb-1">
' . emoticons($comment['comment']) . '
</p>
</div>
';
}
}
?>
<h5 class="mt-4">Leave A Comment</h5>
<?php
$guest = 'No';
if ($logged == 'No' AND $settings['comments'] == 'guests') {
$cancomment = 'Yes';
} else {
$cancomment = 'No';
}
if ($logged == 'Yes') {
$cancomment = 'Yes';
}
if ($cancomment == 'Yes') {
?>
<form name="comment_form" action="post?name=<?php
echo $post_slug;
?>" method="post">
<?php
if ($logged == 'No') {
$guest = 'Yes';
?>
<label for="name"><i class="fa fa-user"></i> Name:</label>
<input type="text" name="author" value="" class="form-control" required />
<br />
<?php
}
?>
<label for="comment"><i class="fa fa-comment"></i> Comment:</label>
<textarea name="comment" id="comment" rows="5" class="form-control" maxlength="1000" oninput="countText()" required></textarea>
<label for="characters"><i>Characters left: </i></label>
<span id="characters">1000</span><br>
<br />
<?php
if ($logged == 'No') {
$guest = 'Yes';
?>
<center><div class="g-recaptcha" data-sitekey="<?php
echo $settings['gcaptcha_sitekey'];
?>"></div></center>
<?php
}
?>
<input type="submit" name="post" class="btn btn-primary col-12" value="Post" />
</form>
<?php
} else {
echo '<div class="alert alert-info">Please <strong><a href="login"><i class="fas fa-sign-in-alt"></i> Sign In</a></strong> to be able to post a comment.</div>';
}
if ($cancomment == 'Yes') {
if (isset($_POST['post'])) {
$authname_problem = 'No';
$date = date($settings['date_format']);
$time = date('H:i');
$comment = $_POST['comment'];
$captcha = '';
if ($logged == 'No') {
$author = $_POST['author'];
$bot = 'Yes';
if (isset($_POST['g-recaptcha-response'])) {
$captcha = $_POST['g-recaptcha-response'];
}
if ($captcha) {
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($settings['gcaptcha_secretkey']) . '&response=' . urlencode($captcha);
$response = file_get_contents($url);
$responseKeys = json_decode($response, true);
if ($responseKeys["success"]) {
$bot = 'No';
}
}
if (strlen($author) < 2) {
$authname_problem = 'Yes';
echo '<div class="alert alert-warning">Your name is too short.</div>';
}
} else {
$bot = 'No';
$author = $rowu['id'];
}
if (strlen($comment) < 2) {
echo '<div class="alert alert-danger">Your comment is too short.</div>';
} else {
if ($authname_problem == 'No' AND $bot == 'No') {
$runq = mysqli_query($connect, "INSERT INTO `comments` (`post_id`, `comment`, `user_id`, `date`, `time`, `guest`) VALUES ('$row[id]', '$comment', '$author', '$date', '$time', '$guest')");
echo '<div class="alert alert-success">Your comment has been successfully posted</div>';
echo '<meta http-equiv="refresh" content="0;url=post?name=' . $row['slug'] . '#comments">';
}
}
}
}
?>
</div>
</div>
</div>
</div>
<script>
$("#share").jsSocials({
showCount: false,
showLabel: true,
shares: [
{ share: "facebook", logo: "fab fa-facebook-square", label: "Share" },
{ share: "twitter", logo: "fab fa-twitter-square", label: "Tweet" },
{ share: "linkedin", logo: "fab fa-linkedin", label: "Share" },
{ share: "email", logo: "fas fa-envelope", label: "E-Mail" }
]
});
function countText() {
let text = document.comment_form.comment.value;
document.getElementById('characters').innerText = 1000 - text.length;
//document.getElementById('words').innerText = text.length == 0 ? 0 : text.split(/\s+/).length;
//document.getElementById('rows').innerText = text.length == 0 ? 0 : text.split(/\n/).length;
}
</script>
<?php
if ($settings['sidebar_position'] == 'Right') {
sidebar();
}
footer();
?>