-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
100 lines (97 loc) · 2.79 KB
/
index.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
<?php require 'lib/header.php';
if (Session::check() and isset($_SESSION['login'])) {
$db_info = new DB('blog', 'user_info');
$data = $usr->fetch($db_info, 'id', Session::get('id'));
if (is_bool($data)) {
header('Location: update_profile.php');
}
}
$post = new Post(new DB('blog', 'post'));
$date = new Date(new DateTimeZone('Asia/Dhaka'));
?>
<!-- Page Header -->
<header class="masthead" style="background-image: url('img/home-bg.jpg')">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<div class="site-heading">
<h1>Clean Blog</h1>
<span class="subheading">A Blog Theme by Hridoy</span>
</div>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<?php
$page = 1;
if (isset($_GET['page'])) {
$page = $_GET['page'];
$limit = $post->paginate($page, 5);
$page++;
} else {
$limit = $post->paginate($page, 5);
$page++;
}
$data = $post->readAll($limit);
$count = $post->count($limit);
if ($count > 0) :
foreach ($data as $posts) :
?>
<div class="post-preview" id="post">
<a href="post.php?id=<?= $posts['id'] ?>">
<h2 class="post-title">
<?php echo $posts['title']; ?>
</h2>
<h3 class="post-subtitle">
<?php echo substr($posts['content'], 0, 20); ?>
</h3>
</a>
<p class="post-meta">Posted by
<a href="#"><?php echo $posts['author']; ?></a>
on <?php echo $date->getDiff($posts['time']) . " ago"; ?></p>
</div>
<hr>
<?php endforeach;
$lim['upper'] = $limit['upper'] + 1;
$lim['lower'] = $limit['lower'];
$limDiff = $lim['upper'] - $lim['lower'];
if ($post->count($lim) == $limDiff) :
?>
<!-- Pager -->
<div class="clearfix">
<a class="btn btn-primary float-right" href="<?php echo $_SERVER['PHP_SELF'] . "?page=" . $page; ?>">Older Posts →</a>
</div>
<?php
endif;
else :
?>
<div class="post-preview">
<h3 class="post-subtitle">
Nothing to display!
</h3>
</div>
<?php endif; ?>
</div>
</div>
</div>
<hr>
<script>
$(".post-preview").hover(
function() {
$(this).append($("<span class='d-flex justify-content-end'>Edit Delete</span>"));
},
function() {
$(this).find("span:last").remove();
}
);
$("li.fade").hover(function() {
$(this).fadeOut(100);
$(this).fadeIn(500);
});
</script>
<?php include 'lib/footer.php'; ?>