-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
231 lines (206 loc) · 11.3 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
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
<?php include('layouts/navbar-templet.php'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icons" href="https://t4.ftcdn.net/jpg/04/92/55/37/360_F_492553733_M1ewmNvrx917YggK3b6IQjiqKzbCpufW.jpg">
<title>Blogger</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link href="styles.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<style>
.post-image {
width: 100%;
height: auto;
border-radius: 10px;
margin-bottom: 15px;
max-height: 300px;
object-fit: cover;
}
.card {
margin-bottom: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
}
.card-body {
padding: 15px;
display: flex;
flex-direction: column;
flex-grow: 1;
}
.card-footer {
background-color: #f8f9fa;
border-top: 1px solid #dee2e6;
display: flex;
justify-content: space-between;
align-items: center;
}
.btn-sm {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
}
.button-container a {
margin-left: 10px;
}
#particles-js {
cursor: default !important;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
}
.zoom {
width: 100%;
height: 300px;
object-fit: cover;
}
.profile-image {
width: 50px;
height: 50px;
object-fit: cover;
border-radius: 50%;
margin-right: 10px;
}
.profile-container {
display: flex;
align-items: center;
margin-bottom: 10px;
}
/* cursor */
.cursor{
cursor: pointer;
}
</style>
</head>
<body>
<!-- Particles container -->
<div id="particles-js"></div>
<div class="container">
<!-- Add your navigation bar here if needed -->
</div>
<div class="content">
<div id="alert" onclick="valida()"></div>
<!-- <div class="text-center">
<h1 class="text-center">Wii Lose</h1>
</div> -->
<div class="container main">
<div class="row">
<!-- Sidebar -->
<div class="col-md-3">
<div class="card">
<div class="card-header">
Categories
</div>
<div class="card-body">
<ul class="list-group">
<?php
include 'allkoneksi/koneksi.php';
$sql = "SELECT DISTINCT Tags FROM posts";
$result = $koneksi->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo '<li class="list-group-item"><a href="category.php?Tags=' . $row['Tags']. '">#' . htmlspecialchars($row['Tags']) . '</a></li>';
}
}
?>
</ul>
</div>
</div>
</div>
<!-- Main Content -->
<div class="col-md-9">
<hr>
<div class="row">
<?php
// Koneksi ke database
include 'allkoneksi/koneksi.php';
// Buat koneksi ke database
$koneksi = new mysqli($host, $username, $password, $database);
// Periksa koneksi
if ($koneksi->connect_error) {
die("Koneksi gagal: " . $koneksi->connect_error);
}
// Memeriksa apakah ada pengguna yang login
$current_user = isset($_SESSION['username']) ? $_SESSION['username'] : '';
$sql = "SELECT posts.*, users.profile_image_path FROM posts
JOIN users ON posts.uploaded_by = users.username
ORDER BY upload_date DESC LIMIT 9999";
$result = $koneksi->query($sql);
// Cek apakah ada postingan
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
?>
<div class="card mb-5">
<div class="w-100">
<div class="position-relative">
<img src="blogs/uploads/<?php echo htmlspecialchars($row['image']); ?>" class="card-img-top post-image mt-4 img-fluid" style="border-radius: 10px;" alt="<?php echo htmlspecialchars($row['title']); ?>">
<div class="card-body">
<div class="profile-container cursor " >
<?php if (!empty($row['profile_image_path'])) : ?>
<img onclick="window.location = './profile/profile-pengguna.php?id=<?= htmlspecialchars($row['user_id']); ?>'" src="profile/<?php echo htmlspecialchars($row['profile_image_path']); ?>" alt="avatar" class="profile-image">
<?php else : ?>
<img onclick="window.location = './profile/profile-pengguna.php?id=<?php echo htmlspecialchars($row['user_id']); ?>'" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSGst2EJfEU4M83w0oCJ0mpZ1O_n8jpiuvjOO4IvOFgRA&s" alt="avatar" class="profile-image">
<?php endif; ?>
<span><?php echo htmlspecialchars($row['uploaded_by']); ?></span>
</div>
<h5 class="card-title">Judul: <?php echo htmlspecialchars($row['title']); ?></h5>
<p class="card-text">Deskripsi: <?php echo htmlspecialchars($row['content']); ?></p>
<p><strong>Tags:</strong> <?php echo htmlspecialchars($row['Tags']); ?></p>
</div>
<div class="overlay position-absolute top-0 end-0 m-2">
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-gear-wide"></i>
</button>
<ul class="dropdown-menu">
<?php if ($current_user == $row['uploaded_by']) { ?>
<li><a class="dropdown-item" href="edit_post.php?id=<?php echo htmlspecialchars($row['id']); ?>">Edit <i class="bi bi-pencil-square"></i></a></li>
<li><a class="dropdown-item" href="delete_post.php?id=<?php echo htmlspecialchars($row['id']); ?>" onclick="return confirm('Apakah Anda yakin ingin menghapus postingan ini?');">Delete <i class="bi bi-trash"></i></a></li>
<?php } ?>
<li><a href="in/download.php?gambar=<?php echo htmlspecialchars($row['image']); ?>" class="dropdown-item">Simpan Foto <i class="bi bi-download"></i></a></li>
<li><a href="Private/report.html" class="dropdown-item">Report <i class="bi bi-exclamation-triangle"></i></a></li>
</ul>
</div>
</div>
<div class="card-footer">
<div>
Diposting pada <?php echo htmlspecialchars($row['upload_date']); ?>
</div>
<div class="button-container">
<a href="blogs/komen.php?post_id=<?php echo htmlspecialchars($row['id']); ?>" class="btn btn-primary"><i class="bi bi-chat-left"></i></a>
<a href="layouts/like.php?action=like&post_id=<?php echo htmlspecialchars($row['id']); ?>&type=like" class="btn btn-primary"><i class="bi bi-hand-thumbs-up"></i> <span id="likeCount<?php echo $row['id']; ?>"><?php echo htmlspecialchars($row['likes']); ?></span></a>
<a href="layouts/dislike.php?action=dislike&post_id=<?php echo htmlspecialchars($row['id']); ?>&type=dislike" class="btn btn-danger"><i class="bi bi-hand-thumbs-down"></i> <span id="dislikeCount<?php echo $row['id'] ?>"><?php echo htmlspecialchars($row['dislikes']); ?></span></a>
</div>
</div>
</div>
</div>
</div>
<?php
}
} else {
?>
<p class="alert alert-dark mr-3 text-center underline-danger">Tidak ada gambar</p>
<a href="blogs/upload.php" class="alert alert-dark me-1">Klik di sini untuk post</a>
<?php
}
// Tutup koneksi
$koneksi->close();
?>
</div>
</div>
</div>
</div>
</div>
<script>
particlesJS.load('particles-js', 'particles-config.json', function() {
console.log('particles.js loaded - callback');
});
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7pL+0pEd5eY1z4+cBB+z8V+W9CKMpYW4" crossorigin="anonymous"></script>
</body>
</html>