forked from mithu2649/closy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.php
98 lines (81 loc) · 4.23 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
<?php
include('./classes/DB.php');
include('./classes/Login.php');
include('./classes/Post.php');
include('./classes/Image.php');
$username="";
//set within the queries later, if problems occur
$isFollowing = False;
$isVerified = False;
if(!Login::isLoggedIn()){
header('location:login.php', 'please login');
}
if(isset($_GET['username'])){
if(DB::query('SELECT username FROM users WHERE username=:username', array(':username'=>$_GET['username']))){
$username = DB::query('SELECT username FROM users WHERE username=:username', array(':username'=>$_GET['username']))[0]['username'];
$isVerified = DB::query('SELECT verified FROM users WHERE username=:username', array(':username'=>$_GET['username']))[0]['verified'];
$user_id = DB::query('SELECT id FROM users WHERE username=:username', array(':username'=>$_GET['username']))[0]['id'];
$follower_id = Login::isLoggedIn(); //user logged in as
if($user_id != $follower_id){
if(isset($_POST['follow'])){
if (!DB::query('SELECT follower_id FROM followers WHERE user_id=:user_id AND follower_id=:follower_id', array(':user_id'=>$user_id, ':follower_id'=>$follower_id))) {
if($follower_id == 5){
DB::query('UPDATE users SET verified=1 WHERE id=:user_id', array(':user_id'=>$user_id));
}
DB::query('INSERT INTO followers VALUES (\'\', :user_id, :follower_id)', array(':user_id'=>$user_id, ':follower_id'=>$follower_id));
}else {
echo 'Already following!';
}
$isFollowing = True;
}
if(isset($_POST['unfollow'])){
if (DB::query('SELECT follower_id FROM followers WHERE user_id=:user_id AND follower_id=:follower_id', array(':user_id'=>$user_id, ':follower_id'=>$follower_id))) {
if($follower_id == 5){
DB::query('UPDATE users SET verified=0 WHERE id=:user_id', array(':user_id'=>$user_id));
}
DB::query('DELETE FROM followers WHERE user_id=:user_id AND follower_id=:follower_id', array(':user_id'=>$user_id, ':follower_id'=>$follower_id));
}
$isFollowing = False;
}
if (DB::query('SELECT follower_id FROM followers WHERE user_id=:user_id AND follower_id=:follower_id', array(':user_id'=>$user_id, ':follower_id'=>$follower_id))){
//following...
$isFollowing = True;
}
}
if(isset($_POST['post'])){
if($_FILES['postimg']['size'] == 0){
Post::createPost($_POST['postbody'], Login::isLoggedIn(), $user_id);
}else{
$post_id = Post::createImagePost($_POST['postbody'], Login::isLoggedIn(), $user_id);
Image::uploadImage('postimg', 'UPDATE posts SET post_img=:postimg WHERE id=:post_id', array(':post_id'=>$post_id));
}
}
if(isset($_GET['postid'])){
Post::likePost($_GET['postid'], $follower_id);
}
$posts = Post::displayPosts($user_id, $username, $follower_id);
}else{
die('user_not_found');
}
}
?>
<h1><?php echo $username;?>'s Profile - <?php if($isVerified){echo 'verified';} ?></h1>
<form action="profile.php?username=<?php echo $username; ?>" method="post">
<?php
if($user_id != $follower_id){
if($isFollowing){
echo '<input type="submit" value="unfollow" name="unfollow">';
}else{
echo '<input type="submit" value="follow" name="follow">';
}
}
?>
</form>
<form action="profile.php?username=<?php echo $username; ?>" method="post" enctype="multipart/form-data">
<textarea name="postbody" id="post_body" cols="30" rows="10"></textarea>
<br>Upload an Image:
<input type="file" name="postimg"><br><br>
<input type="submit" name="post" value="Post"></form>
<div class="posts">
<?php echo $posts;?>
</div>