-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
411 lines (372 loc) · 21.4 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
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
408
409
410
411
<?php
session_start();
if( !isset($_SESSION['username']) ) {
header("Location: login.php");
exit;
}
include 'dbconnect.php';
$username = $_SESSION['username'];
$name = $_SESSION["name"];
$profilename = $_REQUEST["user"];
if(!$dbcon){
die('Error Connecting to database');
}
$rowi = "";
$profiledata = mysqli_query($dbcon,"SELECT users.Name,users.Username,users.Email,users.Bio,users.Website,pictures.Profile,pictures.Cover FROM `users`, `pictures` WHERE users.Username = '$profilename' AND pictures.Username = '$profilename'");
$data = mysqli_fetch_array($profiledata);
$pname = $data['Name'];
$pusername = $data['Username'];
$pprofilepic = $data['Profile'];
$pcoverpic = $data['Cover'];
$pbio = $data['Bio'];
$pweb = $data['Website'];
$followdata = mysqli_query($dbcon,"SELECT COUNT(follower) as Following FROM followers WHERE Username = '$username' AND Follower = '$pusername'");
$following = mysqli_fetch_array($followdata);
$fcheck = $following["Following"];
$posts = "SELECT (SELECT likes.Liked FROM likes WHERE likes.postId=posts.id AND likes.Username='$username') as Liked,(SELECT COUNT(comments.Comment) FROM comments WHERE comments.PostId = posts.Id) as CommentCount,(SELECT COUNT(likes.Liked) FROM likes WHERE likes.Liked = 1 AND posts.Id = likes.postId) as LikeCount, posts.* FROM `posts` WHERE posts.Username = '$profilename' ORDER BY Id DESC";
$allposts=$dbcon->query($posts);
$pcount = mysqli_num_rows($allposts);
$friends = "SELECT followers.Follower, pictures.Profile, users.Name, users.Username FROM `followers`,pictures,users WHERE followers.Username = '$profilename' AND followers.Username <> followers.Follower AND pictures.Username = followers.Follower AND followers.Follower = users.Username LIMIT 5";
$friendlist = $dbcon->query($friends);
$counter = mysqli_num_rows($friendlist);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="theme-color" content="#243447">
<title>
<?php echo $pname; ?>
</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css">
<link rel="stylesheet" href="css/animate.css">
<link rel="stylesheet" href="css/bot.css">
<link rel="stylesheet" href="css/styles.css">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<nav class="navbar navbar-expand-md bg-custom-2 fixed-top navbar-dark navbar-fixed">
<!-- Brand -->
<div class="container">
<a class="navbar-brand" href="home.php">The Hub</a>
<!-- Toggler/collapsibe Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Navbar links -->
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<form action="search.php?" method="get" name="searchForm">
<div class="input-group">
<input type="text" name="query" id="" class="form-control search-1" placeholder="Search">
<span class="input-group-btn">
<button type="submit" class="btn btn-custom search-2" id="" name="search">
<i class="fas fa-search"></i>
</button>
</span>
</div>
</form>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="home.php">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Interests</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="interests.php">Add Interests</a>
<a class="dropdown-item" href="findusers.php">Find Users</a>
<a class="dropdown-item" href="discover.php">Discover</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<?php
echo $name;
?>
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="profile.php?user=<?php echo $username; ?>">Profile</a>
<a class="dropdown-item" href="settings.php">Settings</a>
<a class="dropdown-item" href="signout.php">Sign Out</a>
</div>
</li>
</ul>
</div>
</div>
</nav>
<article id="cover">
<div class="container wow animated fadeIn">
<div id="profile-head" class="">
<img src=<?php if($pprofilepic!='' ) { echo "'$pprofilepic'"; } else{ echo "'img/profile_pic/default.png'"; } ?> width="200px" class="img-responsive img-rounded" id="profile-pic" />
</div>
<div id="profile-details">
<h2>
<?php echo $pname; ?>
</h2>
<h5>@
<?php echo $pusername; ?>
</h5>
<p class="col-md-6 offset-md-3 col-xs-12 col-sm-12">
<?php
if(isset($pbio)){
echo $pbio;
}
?>
</p>
<?php
if(isset($pweb)){
echo '<a href="'.$pweb.'" target="_blank">'.$pweb.'</a>';
}
?>
<?php
if($fcheck!=1){
$colors = '
<button id="follow-btn" class="btn btn-outline-primary" name="follow">
<span style="font-size:1.1em;">Follow </span> <i style="font-size:0.8em;" class="fas fa-1x fa-plus-circle"></i>
</button>';
}
else if($fcheck==1){
$colors = '
<button id="unfollow-btn" class="btn btn-primary" name="follow">
<span style="font-size:1.1em;">Following </span> <i style="font-size:0.8em;" class="fas fa-1x fa-check-circle"></i>
</button>';
}
if($username == $pusername){
$followbtn = "";
}
else{
$followbtn = '
<div class="mars-top-30">
'.$colors.'
</div>';
}
echo $followbtn;
?>
<script>
if (document.getElementById('follow-btn') != null) {
let follow = document.getElementById('follow-btn');
follow.addEventListener("click", function() {
let u = "<?php echo $username; ?>";
let p = "<?php echo $pusername; ?>";
fetch(`follow.php?username=${u}&follow=${p}&b=1`, {
method: 'GET'
});
follow.className = "btn btn-primary";
follow.innerHTML = '<span style="font-size:1.1em;">Following </span> <i style="font-size:0.8em;" class="fas fa-1x fa-check-circle"></i>';
setTimeout(() => {
location.reload(true);
}, 1000);
});
}
if (document.getElementById('unfollow-btn') != null) {
let unfollow = document.getElementById('unfollow-btn');
unfollow.addEventListener("click", function() {
let u = "<?php echo $username; ?>";
let p = "<?php echo $pusername; ?>";
fetch(`follow.php?username=${u}&follow=${p}&b=0`, {
method: 'GET'
});
unfollow.className = "btn btn-outline-primary";
unfollow.innerHTML = '<span style="font-size:1.1em;">Follow </span> <i style="font-size:0.8em;" class="fas fa-1x fa-plus-circle"></i>';
setTimeout(() => {
location.reload(true);
}, 1000);
});
}
</script>
</div>
<div class="row" style="margin-top:50px; margin-bottom:50px;">
<div class="col-md-4 d-none d-md-block">
<div class="row">
<div class="col-7">
<h5 class="text-left">Follows</h5>
</div>
<div class="col-5 linked text-right">
<a href="#" style="color:blue">See All</a>
</div>
</div>
<div id="other-user" class="container wow animated fadeIn">
<div id="friends-err" class="text-center">
<h5 class="text-muted">No Users Found.</h5>
</div>
<?php
while($row1=$friendlist->fetch_assoc()){
$url1 = $row1['Profile'];
if($url1!=''){
$url1 = $row1['Profile'];
}
else{
$url1 = "img/profile_pic/default.png";
}
echo
'<a href="profile.php?user='.$row1["Username"].'"><div class="row text-left mars-btm-20" id="other-lines">
<div class="col-3">
<img src="'.$url1.'" class="rounded" alt="">
</div>
<div class="col-9">
<h6 style="margin-bottom:0px; font-size:1.1em;">'.$row1["Name"].'</h6>
<p style="font-size:0.8em;">@'.$row1["Username"].'</p>
</div>
</div></a>';
}
?>
</div>
</div>
<script>
let c = "<?php echo $counter; ?>";
if (c != 0) {
document.getElementById('friends-err').style.display = "none";
}
</script>
<div class="col-12 col-md-8 wow animated fadeIn" style="margin-top:25px;">
<?php
$a =0;
while($row=$allposts->fetch_assoc()){
if($pprofilepic!="") {$picurl=$pprofilepic;}
else {$picurl = 'img/profile_pic/default.png';}
$unix_timestamp = $row["Time"];
$a++;
$datetime = new DateTime("@$unix_timestamp");
$datetime->setTimezone(new DateTimeZone('Asia/Kolkata'));
if($username == $row["Username"]){
$option = '<span class="dropdown">
<a href="#" data-toggle="dropdown"><i style="color: #737373;" class="fas fa-ellipsis-v"></i></a>
<div class="dropdown-menu">
<a class="dropdown-item" href="editPost.php?postId='.$row["Id"].'">Edit</a>
<a class="dropdown-item" href="deletePost.php?postId='.$row["Id"].'">Delete</a>
</div>
</span>';
}
else{
$option = '';
}
echo'
<div id="post-box" >
<div class="row" id="pro-info">
<div class="col-2 col-md-2 col-lg-1 ">
<a id="links" href="profile.php?user='.$row["Username"].'" > <img src="'.$picurl.'" class=" rounded-circle " width="50px" id="post-circle" /></a>
</div>
<div class="col-8 col-md-9 col-lg-10" id="pro-name" style="text-align:left">
<a id="links" href="profile.php?user='.$row["Username"].'"> <h5 style="margin-bottom:0;">'.$row["Name"].'</h5></a>
<p style="font-size:0.75em;">'.$datetime->format('d M Y').' at '.$datetime->format('H:i').' hrs</p>
</div>
<div class="text-right" style="" id="drop-circles">
'.$option.'
</div>
</div>
<div class="row">
<div class="col-11 offset-lg-1 col-md-10 offset-md-2">
<p class="text-left text-md-left" id="postdata'.$a.'"></p>
</div>
</div>
<script>
pd = `'.$row["Post"].'`
var repl = pd.replace(/#(\w+)/g, `<a id="hashtag" href="hashtag.php?hashtag=$1">#$1</a>`);
var res = repl.replace(/@(\w+)/g, `<a id="hashtag" href="profile.php?user=$1">@$1</a>`);
document.getElementById("postdata'.$a.'").innerHTML = res;
</script>
<div class="row text-center ">
<div class="col-6 comm-box" >
<input type="checkbox" onclick="like('.$a.','.$row["Id"].','.$row["Liked"].');" id="like'.$a.'">
<label for="like'.$a.'" class="label-color">
<i class="fas fa-heart" ></i> Like (<span id="count'.$a.'">'.$row["LikeCount"].'</span>)
</label>
</div>
<div class="col-6 comm-box"><a href="comments.php?postId='.$row["Id"].'">
<div><i class="fas fa-comment"></i> Comment ('.$row["CommentCount"].')
</div></a>
</div>
</div>
</div>
<script>
function like(i,id,likes){
let user = "'.$row["Username"].'";
var liked = document.getElementById(`like${i}`).checked;
if(liked==true){
let t = document.getElementById("count"+i).innerText;
let l = parseInt(t)+1;
document.getElementById("count"+i).innerText = l ;
fetch(`like.php?postId=${id}&username=${user}&liked=1`,{method:"GET"});
}
else{
let t = document.getElementById("count"+i).innerText;
let l = parseInt(t)-1;
document.getElementById("count"+i).innerText = l ;
fetch(`like.php?postId=${id}&username=${user}&liked=2`,{method:"GET"});
}
}
</script>
<script>
if('.$row["Liked"].' == 1)
document.getElementById("like'.$a.'").setAttribute("checked","checked");
</script>
';
}
?>
<div id="error-err" class="text-center" style="margin-top:48px">
<h5 class="text-muted">No Posts Found.</h5>
</div>
<script>
let pc = "<?php echo $pcount; ?>";
if (pc != 0) {
document.getElementById('error-err').style.display = "none";
}
</script>
</div>
</div>
</div>
<div id="chat-open">
<div class="col-12" id="main-box">
<header class="header">
<h5 class="text-left">Hub Bot (AI Chatbot)</h5>
<h6 id="status"><span><i class="fas fa-circle" style="color:grey"></i></span> Checking...</h6>
<span class="closer">
<span class="voice-box" title="Listen to the HubBot"><input type="checkbox" onclick="voice();" id="voice" name="voice">
<label for="voice" class="label-color-voice">
<i class="fas fa-volume-up"></i>
</label>
</span>
</span>
</header>
<div id="chat-container">
<ul id="conversation">
</ul>
<div id="bottom"></div>
</div>
<section class="row" id="input">
<div class="col-9 col-md-10" style="padding-right: 0">
<input type="text" id="chat-input" placeholder="Enter your message" class="form-control">
</div>
<div class="col-3 col-md-2" style="padding-left: 5px">
<button id="btn" class="btn btn-primary btn-block" onclick="send()"><i class="fas fa-paper-plane"></i></button>
</div>
</section>
</div>
</div>
<div id="fab" class="shadow" onclick="openchat()"><i class="fas fa-1x fa-envelope"></i></div>
<div id="fab-close" class="shadow" onclick="closechat()"><i class="fas fa-1x fa-envelope-open"></i></div>
</article>
<?php
if($pcoverpic!=""){
echo
"<script>
document.getElementById('cover').style.background = 'url($pcoverpic)';
</script>";
}
?>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.4/js/all.js"></script>
<script src="js/wow.js"></script>
<script>
new WOW().init();
</script>
<script src="js/bot.js"></script>
</body>
</html>