-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
287 lines (240 loc) · 14.8 KB
/
profile.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!-- Profile.php^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -->
<?php include_once 'header.php';
// include_once 'classes/User.php';
// include_once 'classes/Post.php';
if(isset($_GET['profile_username'])){
$username = $_GET['profile_username'];
$user_detail_query = mysqli_query($con,"select * from users where username='$username'");
$user_array = mysqli_fetch_array($user_detail_query);
}
$num_friends = (substr_count($user_array['friend_array'],","))-1;
if(isset($_POST['remove_friend'])){
$user = new User($con, $userLoggedIn);
$user->removeFriend($username);
}
if(isset($_POST['add_friend'])){
$user = new User($con, $userLoggedIn);
$user->sendRequest($username);
}
if(isset($_POST['accept_request'])){
header("Location: request.php");
}
if(isset($_POST['send_msg'])){
header("Location: messages.php?u=$username");
}
?>
<style>
.wreper_left{
margin-left: 100px;
margin-top: 30px;
width: 20%;
}
.wreper_right{
margin-left: 350px;
margin-top: -40px;
}
.left_info_wreper{
margin-left: 50px;
line-height: 25px;
display: flex;
}
</style>
<div class="profile_top">
<img class="cover" src='<?php echo $user_array['cover_pic']; ?>'>
<img class="profile" src='<?php echo $user_array['profile_pic']; ?>'>
<?php $FirstAndLastName = $user_array['first_name']." ". $user_array['last_name'];
echo "<span class='FastAndLastName'>".$FirstAndLastName."</span>";
$username = $user_array['username'];
echo "<span class='username'>@$username</span>";
?>
<div class="btns" style="display: flex; margin: -15px 500px;">
<form action="#" method="POST">
<button class="message" name="send_msg"><i class="fas fa-comment-alt"></i> Message</button>
</form>
<form action="<?php echo $username; ?>" method="POST">
<?php
$profile_user_obj = new User($con, $username);
if($profile_user_obj->isClosed()){
header("Location: user_closed.php");
}
$logged_in_user_obj = new User($con, $userLoggedIn);
if($userLoggedIn != $username){
if($logged_in_user_obj->isFriend($username)){
echo '<span class="addFriend" style="background: #ff5c5c; margin-left: 575px;"><i class="fas fa-user-minus"></i> <input type="submit" style="border: none; background: transparent; color: white; font-size: 14px;" name="remove_friend" value="Remove friend"></span>';
}
else if ($logged_in_user_obj->didReceiveRequest($username)) {
echo '<span class="addFriend" style="background: #73d640; margin-left: 575px;"> <input type="submit" style="border: none; background: transparent; color: white; font-size: 14px;" name="accept_request" value="Accept Request"></span>';
}
else if ($logged_in_user_obj->didSendRequest($username)) {
echo '<span class="addFriend" style="background: #73d640; margin-left: 575px;"> <input type="submit" style="border: none; background: transparent; color: white; font-size: 14px;" value="Request Sent"></span>';
}
else {
echo '<span style="margin-left: 575px;" class="addFriend" ><i class="fas fa-user-plus"></i> <input type="submit" style="border: none; background: transparent; color: white; font-size: 14px;" name="add_friend" value="Add friend"></span>';
}
}
?>
</form>
</div>
</div>
<div class="main-coluam">
<?php
$username = $user_array['username'];
$ret_str = "";
$data_query = mysqli_query($con, "SELECT * FROM posts ORDER BY id DESC");
while($row = mysqli_fetch_array($data_query)) {
$id = $row['id'];
$body = $row['body'];
$added_by = $row['added_by'];
$date_time = $row['date_added'];
$imagePath = $row['image'];
if($username == $added_by){
// show post/display post
$user_details_query = mysqli_query($con, "SELECT first_name, last_name, profile_pic FROM users WHERE username='$added_by'");
$user_row = mysqli_fetch_array($user_details_query);
$first_name = $user_row['first_name'];
$last_name = $user_row['last_name'];
$profile_pic = $user_row['profile_pic'];
?>
<script>
function toggle<?php echo $id; ?>(){
var element = document.getElementById("toggleComment<?php echo $id; ?>");
if(element.style.display == "block")
element.style.display = "none";
else
element.style.display = "block";
}
</script>
<?php
// count comments
$comment_check = mysqli_query($con,"select * from comments where post_id='$id'");
$comment_check_num = mysqli_num_rows($comment_check);
$date_time_now = date("Y-m-d H:i:s");
$start_date = new DateTime($date_time); //time of post
$end_date = new DateTime($date_time_now); //curent time
$interval = $start_date->diff($end_date); //difrent between dates
if($interval->y >= 1){
if($interval == 1)
$time_message = $interval->y . " year ago";
else
$time_message = $interval->y . " years ago";
}
else if($interval->m >= 1){
if($interval->d == 0){
$days = " ago";
}
else if($interval->d == 1){
$days = $interval->d . " day ago";
}
else{
$days = $interval->d . " days ago";
}
if($interval->m == 1){
$time_message = $interval->m . " month" .
$days;
}
else{
$time_message = $interval ->m . " months".
$days;
}
}
else if($interval->d >= 1){
if($interval->d == 1){
$time_message = "Yesterday";
}
else{
$time_message = $interval->d . " days ago";
}
}
else if($interval->h >= 1){
if($interval->h == 1){
$time_message = $interval->h . " hour ago";
}
else{
$time_message = $interval->h . " hours ago";
}
}
else if($interval->i >= 1){
if($interval->i == 1){
$time_message = $interval->i . " minute ago";
}
else{
$time_message = $interval->i . " minutes ago";
}
}
else{
if($interval->s < 30){
$time_message = "Just Now";
}
else{
$time_message = $interval->s . " seconds ago";
}
}
$ret_str .= "
<div class='status_post'>
<div class='post_profile_pic'>
<img src='$profile_pic' width='50' style='border-radius: 50%;'>
</div>
<div class='posted_by' style='color:#ACACAC;'>
<a href='$added_by'> $first_name $last_name </a> <br>
<div class='time'> $time_message </div>
</div> <br> <br>
<div class='post_body' id='post_body'>
<span style='margin-left: 34px;'> $body </span> <br> <br> <img src='$imagePath'> <br>
</div>
</div>
<div calss='post_feature'>
<span class='comment' style='color: #3875c5; font-size: 12px; float: right; margin-right: 40px; margin-top:-10px;' onClick='javascript:toggle$id()'><i class='fas fa-comment fa-2x'></i>($comment_check_num)</span>
<iframe src='like.php?post_id=$id'style='
border: 0px;
height: 25px;
width: 120px;
margin-left: 35px;
' scrolling='no'></iframe>
</div>
<div class='post_comment' id='toggleComment$id' style='display:none;'>
<iframe src='comment_frame.php?post_id=$id' id='comment_iframe' frameborder='0' style='display: flex; width: 100%; border-radius: 5px;'></iframe>
</div>
<hr style='margin-bottom: 28px;'> ";
}//end if
}//end of loop
echo $ret_str;
?>
</div>
<div class="profile_left">
<div class="left_wreper">
<div class="wreper_top">
<center><h2> <?php echo $FirstAndLastName ?> </h2></center>
<center><span> @<?php echo $username ?> </span></center>
</div>
<hr>
<div class="wreper_left">
<div class="post"> <b> Posts </b> </div> <br>
<div class="num_post" style="margin-left: 15px;"> <?php echo $user_array['num_posts'] ?> </div>
</div>
<hr style="transform: rotate(90deg); margin-top: -19px; width: 75px;">
<div class="wreper_right">
<div class="post"> <b> Friends </b> </div> <br>
<div class="num_friend" style="margin-left: 15px;"> <?php echo $num_friends ?> </div>
</div>
</div>
</div>
<!-- <div class="left_info">
<div class="left_info_wreper">
<div class="lable"> Bio <br>
e-Mail <br>
Ph. no. <br>
country <br>
city <br>
</div>
<div class="op" style="margin-left: 60px;">
<?php echo $user_array['bio'] ?> <br>
<?php echo $user_array['email'] ?> <br>
<?php echo $user_array['phone'] ?> <br>
<?php echo $user_array['country'] ?> <br>
<?php echo $user_array['city'] ?> <br>
</div>
</div>
</div> -->
</div>
</body>
</html>