Repository navigation
Expand file tree
/
Copy pathposts.php
More file actions
407 lines (357 loc) · 13.3 KB
/
Copy pathposts.php
File metadata and controls
407 lines (357 loc) · 13.3 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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<?php
session_start();
$loggedIn = isset($_SESSION['loggedIn']) ? $_SESSION['loggedIn'] : false;
//Require database connection
require "files/dbconfig.php";
$con = new DBConfig();
//Require class user to get user details
require "files/user.php";
$user = new User();
//Require classs to get post data
require "files/posts.php";
$post = new Posts();
//Including categories files
include "files/categories.php";
//Creating object for category
$categoryObj = new Categories();
//Require functions file
require "includes/functions.php";
// Include meta information
include "files/meta.php";
$category_name = isset($_GET['name']) ? $_GET['name'] : false;
//Get page number for offset
$page = isset($_GET['page']) ? $_GET['page'] : 1;
if (!filter_var($page, FILTER_VALIDATE_INT)){
$page = 1;
}
if ($category_name == false){
header('Location: index.php');
exit();
} else {
//Empty variables
$found = 0;
$title = 'Category not found';
$name = $con->conn->real_escape_string($category_name);
$sql = 'SELECT * FROM categories WHERE cname = "'.$name.'";';
$result = $con->conn->query($sql);
if ($result->num_rows > 0){
$row = $result->fetch_assoc();
$category_id = $row['cid'];
$title = $row['cname'];
$categoryExists = $categoryObj->categoryName($category_id);
if ($categoryExists != -1){
$found = 1;
}
$numberOfPosts = $categoryObj->totalPosts($category_id);
}
if ($found == 1) {
//Show category posts
$posts = $categoryObj->getPosts($category_id, $page);
//Creating pagination
$limit = 15;
$totalPages = 1;
if ($numberOfPosts > $limit){
$totalPages = ceil($numberOfPosts / $limit);
if ($page < 1 || $page > $totalPages){
$page = 1;
}
$previous = $page > 1 ? $page - 1 : '#';
if ($page < $totalPages) {
$next = $page + 1;
} else {
$next = '#';
}
}
} else {
echo '<html>
<head>
<title>404 Not Found</title>
<style>
*{
margin: 0;
padding: 0;
}
</style>
<link rel="icon" href="'.$metaInfo ['domain'].'/images/logo.png" type="image/png">
</head>
<body>';
echo '<iframe src="'.$metaInfo['domain'].'/error.php" frameBorder="0" width="100%" height="100%"></iframe>' ;
echo '</body></html>';
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en" data-theme='light'>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#333">
<meta name="keywords" content="<?php echo $metaInfo['keywords'];?>">
<meta name="description" content="<?php echo $metaInfo['description']?> ">
<meta property="og:title" content="<?php echo $title.' - '.$metaInfo['keywords']?> " />
<meta property="og:description" content="<?php echo $metaInfo['ogDescription']?> " />
<meta property="og:image" content="<?php echo $metaInfo['domain'].'/'.$metaInfo['ogImage']?> " />
<meta property="og:url" content="<?php echo $metaInfo['ogUrl']?> " />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="<?php echo $metaInfo['domain']; ?>/css/styles.css">
<link rel="stylesheet" href="<?php echo $metaInfo['domain']; ?>/css/dark.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="icon" href="<?php echo $metaInfo['domain']; ?>/images/logo.png" type="image/png">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="icon" href="<?php echo $metaInfo['domain']; ?>/images/logo.png" type="image/png">
<style>
#main-doc{
margin: 0px auto;
width: 1210px;
display: grid;
grid-template-rows: 1fr 50px;
grid-template-columns: 810px 300px;
grid-column-gap: 100px;
margin-top: 90px;
}
.left, .right{
margin-top: 40px;
}
.left{
background: var(--bg);
box-shadow: 10px 10px 20px var(--boxShadowd),
-10px -10px 20px var(--boxShadowl);
}
.posts .info{
margin: 0px;
}
@media only screen and (max-width: 600px){
#main-doc{
width: 100%;
display: block;
margin-top: 50px;
}
.left{
margin-top: 20px;
}
.right{
height: auto;
margin-bottom: 15px;
}
.right .srrba{
margin-bottom: 10px;
}
.right .top {
margin: 0 3%;
box-shadow: none !important;
}
.right .top .h4{
text-align: left;
}
}
</style>
<title><?php echo $title.' - '.$metaInfo['keywords']; ?></title>
</head>
<body>
<header>
<?php
include "includes/header.php";
?>
</header>
<main>
<div id="main-doc">
<div class="left">
<?php
if ($posts != 0){
?>
<div class="sr-banner">
<img src="<?php echo $metaInfo['domain'].'/images/'.$categoryexists; ?>.jpg" alt="banner">
<div class="sr-bcontent">
<a href="<?php echo $metaInfo['domain']; ?>/index.php">Home</a> >
<a href="#"><?php echo $categoryExists; ?></a>
</div>
</div>
<div class="srcontent">
<ul>
<?php
foreach ($posts as $row){
$title = htmlspecialchars($row['ptitle']);
$info = strip_tags(substr($row['pcontent'], 0,200));
$date = $row['pdate'];
$category = $categoryObj->categoryName($row['pcat']);
$views = $row['views'];
$comments = $post->noComments($row['pid']);
$banner = $row['pbanner'];
$usrName = $user->userName($row['uid']);
//Check if a post is available or not
if ($row['available'] != 1){
$title = $info = '<i>This post has been deleted.</i>';
$banner = 'default.png';
}
echo '
<li class="posts">
<div class="d-banner">
<img src="'.$metaInfo['domain'].'/banners/'.$banner.'" alt="banner" class="banner">
</div>
<div class="p-right">
<div class="category">'.$category.'</div>
<div class="comments">'.numberShort($comments).' <i class="fa fa-comments-o" aria-hidden="true"></i></div>
<div class="views">'.numberShort($views).'<i class="fa fa-eye" aria-hidden="true"></i></div>
<div class="post-content">
<div class="intro">
<a href="'.$metaInfo['domain'].'/view-post/'.$row['slug'].'">'.$title.'</a>
<div class="info">
<p>
'.($info).'
</p>
</div>
</div>
<div class="author"><a href="'.$metaInfo['domain'].'/view-profile/'.$user->userName($row['uid']).'">'.$usrName.'</a></div>
<div class="time-stamp">'.$date.'</div>
<a href="'.$metaInfo['domain'].'view-post/'.$row['slug'].'"><button class="read-more">Read more</button></a>
</div>
</li>
';
}
?>
</ul>
</div>
<?php
} else {
echo '
<div style="color: var(--textHM); margin: 30px;">
Currently there are no posts in this category. Check back later.
</div>
';
}
?>
</div>
<?php
if ($posts != 0){
?>
<div class="right">
<div class="top">
<h4 class="h4">Popular posts</h4>
<?php
//Getting top posts of a user
$topPosts = $categoryObj->topPosts($category_id, 4);
?>
<ul class="news">
<?php
foreach ($topPosts as $row){
echo '
<div class="srrba" data-slug="'.$row['slug'].'">
<a href="'.$metaInfo['domain'].'/view-post/'.$row['slug'].'"><img src="'.$metaInfo['domain'].'/banners/'.$row['pbanner'].'">
<div class="srrba-t">
<p>
'.htmlspecialchars($row['ptitle']).'
</p>
</div>
</a>
</div>
';
}
?>
</ul>
</div>
</div>
<?php
}
?>
</div>
</main>
<?php
if ($totalPages > 1){
echo '<div class="pagination">
<ul>
<li class="previous number" data-page="'.$previous.'">
<i class="fa fa-angle-double-left" aria-hidden="true"></i>
</li>
';
if ($totalPages > 1 && $totalPages < 6){
for ($i = 1; $i <= $totalPages; $i++){
$active = $page == $i ? 'active' : '';
echo '
<li class="number '.$active.'" data-page="'.$i.'">
'.$i.'
</li>
';
}
}
if ($totalPages > 5){
if ($page == 1 || $page == 2 || $page == 3) {
for($i = 1; $i < 4; $i++){
$active = $page == $i ? 'active' : '';
echo '
<li class="number '.$active.'" data-page="'.$i.'">
'.$i.'
</li>
';
}
echo '
<li class="cont">
...
</li>
';
for($i = $totalPages-1; $i <= $totalPages; $i++){
$active = $page == $i ? 'active' : '';
echo '
<li class="number '.$active.'" data-page="'.$i.'">
'.$i.'
</li>
';
}
} elseif ($page <= $totalPages){
echo '
<li class="number" data-page="1">
1
</li>
<li class="cont">
...
</li>
';
for($i = $totalPages-4; $i <= $totalPages; $i++){
$active = $page == $i ? 'active' : '';
echo '
<li class="number '.$active.'" data-page="'.$i.'">
'.$i.'
</li>
';
}
}
}
echo '
<li class="next number" data-page="'.$next.'">
<i class="fa fa-angle-double-right" aria-hidden="true"></i>
</li>
</div>
';
}
?>
<footer>
</body>
<?php
include "includes/footer.php";
?>
</footer>
<script
src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
crossorigin="anonymous">
</script>
<?php
//Include dark mode script
include "includes/dark_mode_script.php";
//Include navigation bar script
include "includes/nav_toggle_js.php";
//Include notifications
include 'load-notifications.php';
?>
<script>
$(document).ready(function(){
$('.number').click(function(){
window.location.assign('posts.php?name=<?php echo $name;?>&page='+$(this).data('page'));
});
$('.srrba').click(function(){
window.location.assign('<?php echo $metaInfo['domain'];?>/view-post/'+ $(this).data('slug'));
});
});
</script>
</html>