This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
267 lines (261 loc) · 13.7 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
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
<?php
require_once 'init.php';
?>
<?php include 'header.php' ?>
<?php if (!$currentUser) : ?>
<div class="jumbotron">
<section class="hero-section spad">
<div class="container-fluid">
<div class="row">
<div class="col-xl-10 offset-xl-1">
<div class="row">
<div class="col-lg-7">
<div class="hero-info">
<h5><strong>Yolo</strong> - Mạng xã hội dành cho sinh viên</h5>
<div>
<p>Miễn phí mà. Tham gia đi chờ chi...</p>
<p>
<a href="./register.php" class="btn btn-light" role="button">Đăng ký</a>
<a href="./login.php" class="btn btn-light" role="button">Đăng nhập</a>
</p>
</div>
</div>
</div>
<div class="col-lg-5">
<figure class="hero-image">
<img src="./assets/images/gif1.gif" alt="" class="img-fluid" alt="Responsive image">
</figure>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<?php else : ?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<?php
$newFeeds = array();
if(isset($_GET['page'])) {
$newFeeds = findAllPosts($currentUser['id'], $_GET['page']);
$page = (int)$_GET['page'] + 1;
}
else {
$newFeeds = findAllPosts($currentUser['id'], 1);
$page = 2;
}
$success = true;
if (isset($_POST['content'])) {
$content = $_POST['content'];
$data = null;
if (isset($_FILES['postImage'])) {
$fileTemp = $_FILES['postImage']['tmp_name'];
if (!empty($fileTemp)) {
$data = file_get_contents($fileTemp);
}
}
$role = $_POST['role'];
$len = strlen($content);
if ($len == 0 || $len > 1024) {
$success = false;
} else {
createPost($currentUser['id'], $content, $data, $role);
header('Location: index.php');
exit();
}
}
?>
<?php
if (isset($_POST['contentCMT'])) {
$cmt = $_POST['contentCMT'];
$cmtId = $_POST['postIdCmt'];
$len = strlen($cmt);
if ($len == 0 || $len > 1024) {
$success = false;
} else {
addComment($cmtId, $currentUser['id'], $cmt);
header('Location: index.php');
exit();
}
}
?>
<div class="inner">
<?php if (!$success) : ?>
<div class="alert alert-danger" role="alert">
Nội dung không được rỗng và dài quá 1024 ký tự!
</div>
<?php endif; ?>
<div class="row">
<div class="col-md-12">
<form method="POST" enctype="multipart/form-data">
<div class="form-group">
<textarea class="form-control" style="border-top-left-radius:0; border-top-right-radius: 0;"
id="content" name="content" rows="3"
placeholder="<?php echo $currentUser['displayName'] ?> ơi, bạn đang nghĩ gì vậy?"></textarea>
</div>
<div class="d-flex align-items-center">
<div class="upload-btn-wrapper mr-2">
<button class="btn"><i class="fas fa-image"><strong> Ảnh/Video</strong></i></button>
<input type="file" id="postImage" name="postImage" />
</div>
<div class="form-group m-0">
<div style="max-width: 200px; margin: 4px 0;" class="select-privacy">
<select class="form-control" id="role" name="role">
<option value="1">Công khai</option>
<option value="2">Bạn bè</option>
<option value="3">Chỉ mình tôi</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-success ml-auto">Cập nhật trạng thái</button>
</div>
</form>
</div>
</div>
<?php foreach ($newFeeds as $post) : ?>
<?php
$userPost = findUserById($post['userId']);
$comments = commentWithPostId($post['id']);
?>
<div class="row">
<div class="col-12 mt-3">
<div class="card">
<div class="card-body p-3">
<div class="d-flex">
<div class="img-square-wrapper mr-2">
<a href="#">
<img class="rounded-circle" style="width:50px;height:50px;"
src="<?php echo empty($userPost['avatarImage']) ? './assets/images/default-avatar.jpg' : 'view-image.php?userId=' . $userPost['id'] ?>"
alt="<?php echo $userPost['displayName'] ?>">
</a>
</div>
<div>
<a href="./profile.php?id=<?php echo $userPost['id']; ?>" class="text-success">
<h5 class="card-title mb-1"><?php echo $post['displayName']; ?> <img
src='https://i.imgur.com/l63JR5Q.png' title=' Verified profile ' width='20' />
</h5>
</a>
<small class="text-muted">
<i class="custom-time"><?php echo $post['createdAt']; ?></i> ·
<?php if ($userPost['id'] != $currentUser['id']) : ?>
<i title="<?php if ($post['role'] == 1) echo 'Công khai';
elseif ($post['role'] == 2) echo 'Đã chia sẻ với: Bạn bè của ' . $post['displayName'];
else echo 'Chỉ mình tôi'; ?>"
class="fas fa-<?php if ($post['role'] == 1) echo 'globe-americas';
elseif ($post['role'] == 2) echo 'user-friends';
else echo 'lock'; ?>"></i>
<?php else : ?>
<div class="btn-group" id="select-policy">
<button class="fas fa-<?php if ($post['role'] == 1) echo 'globe-americas';
elseif ($post['role'] == 2) echo 'user-friends';
else echo 'lock'; ?>" data-toggle="dropdown"
id="current-policy-<?php echo $post['id']; ?>"></button>
<ul class="dropdown-menu">
<a style="pointer-events:none;" class="dropdown-item">Ai sẽ thấy bài viết
này?</a>
<li data-postId="<?php echo $post['id']; ?>" data-roleId="1"><a
class="dropdown-item" href="#"><i class="fas fa-globe-americas"></i>
<strong> Công khai</strong></a></li>
<li data-postId="<?php echo $post['id']; ?>" data-roleId="2"><a
class="dropdown-item" href="#"><i
class="fas fa-user-friends"></i> <strong> Bạn bè</strong></a>
</li>
<li data-postId="<?php echo $post['id']; ?>" data-roleId="3"><a
class="dropdown-item" href="#"><i class="fas fa-lock"></i> <strong>
Chỉ mình tôi</strong></a></li>
</ul>
</div>
<?php endif; ?>
</small>
</div>
</div>
<p class="card-text mt-3"><?php echo $post['content']; ?></p>
<?php $numOfComment = count($comments);
$numOfComment = $numOfComment > 0 ? $numOfComment . ' bình luận' : ''; ?>
<?php if ($post['image'] != NULL) : ?>
<figure>
<img src="view-image.php?postId=<?php echo $post['id'] ?>" alt="<?php echo $post['id'] ?>"
class="img-fluid w-100">
</figure>
<?php endif; ?>
<div class="react-info d-flex justify-content-between">
<div class="like-count">
<span>
<i class="fa fa-thumbs-up"></i>
<?php echo countLike($post['id']); ?> lượt thích
</span>
</div>
<div class="comment-count" data-commentcount="<?php echo count($comments); ?>">
<span><?php echo $numOfComment ?></span>
</div>
</div>
</div>
<div class="card-footer bg-transparent">
<div class="d-flex react-group">
<div class="hover-secondary w-100 text-center">
<p data-currentuserid="<?php echo $currentUser['id']; ?>"
data-postid="<?php echo $post['id']; ?>" class="btn-like px-3 py-2">
<?php if (!wasLike($currentUser['id'], $post['id'])): ?>
<i class="fa fa-thumbs-o-up"></i> Thích
<?php else: ?>
<i class="fa fa-thumbs-up"></i> Bỏ thích
<?php endif; ?>
</p>
</div>
<div class="hover-secondary w-100 text-center">
<p class="btn-comment px-3 py-2"><i class="fa fa-comment"></i> Bình luận</p>
</div>
</div>
<!-- SHOW COMMENT POST -->
<div class="comments mb-4">
<?php foreach ($comments as $row) : ?>
<?php $userComment = findUserById($row['userId']); ?>
<div class="comment d-flex align-items-center mb-3">
<a href="./profile.php?id=<?php echo $row['userId']; ?>">
<img class="rounded-circle" style="width:40px;height:40px;"
src="<?php echo empty($userComment['avatarImage']) ? './assets/images/default-avatar.jpg' : 'view-image.php?userId=' . $userComment['id'] ?>"
alt="<?php echo $userComment['displayName'] ?>">
</a>
<p class="rounded p-2 mb-0 ml-2" style="background-color: #eee;">
<a href="./profile.php?id=<?php echo $row['userId']; ?>"
class="text-success font-weight-bold"><?php echo $userComment['displayName'] ?></a>
<span><?php echo $row['content']; ?></span>
</p>
</div>
<?php endforeach; ?>
</div>
<!-- ADD COMMENT-->
<form method="POST" class="comment-form">
<div class="content-input">
<div class="row">
<div class="input-group mb-2">
<input type="hidden" value="<?php echo $post['id'] ?>" name="postIdCmt" />
<input type="text" name="contentCMT" class="form-control"
placeholder="Nhập bình luận ở đây..." required />
<div class="input-group-append">
<button style="width: 80px;" class="btn btn-success" type="submit">
<i class="fa fa-paper-plane"></i>
</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php if (count($newFeeds) != 0): ?>
<div class="load-more text-center pt-5">
<form method="GET">
<input type="hidden" value="<?php echo $page; ?>" name="page" />
<button type="submit" class="btn btn-outline-success">Tải thêm trạng thái</button>
</form>
</div>
<?php endif; ?>
</div>
<script src="./assets/js/change-privacy.js"></script>
<?php endif; ?>
<?php include 'footer.php' ?>