-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
249 lines (176 loc) · 7.04 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
<?php
include("includes/header.php");
$message_obj = new Message($con, $userLoggedIn);
if(isset($_GET['profile_username'])) {
$username = $_GET['profile_username'];
$user_details_query = mysqli_query($con, "SELECT * FROM users WHERE username='$username'");
$user_array = mysqli_fetch_array($user_details_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['respond_request'])) {
header("Location: requests.php");
}
if(isset($_POST['post_message'])) {
if(isset($_POST['message_body'])) {
$body = mysqli_real_escape_string($con, $_POST['message_body']);
$date = date("Y-m-d H:i:s");
$message_obj->sendMessage($username, $body, $date);
}
$link = '#profileTabs a[href="#messages_div"]';
echo "<script>
$(function() {
$('" . $link ."').tab('show');
});
</script>";
}
?>
<style type="text/css">
.wrapper {
margin-left: 0px;
padding-left: 0px;
}
</style>
<div class="profile_left">
<img src="<?php echo $user_array['profile_pic']; ?>">
<div class="profile_info">
<p><?php echo "Posts: " . $user_array['num_posts']; ?></p>
<p><?php echo "Likes: " . $user_array['num_likes']; ?></p>
<p><?php echo "Friends: " . $num_friends ?></p>
</div>
<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 '<input type="submit" name="remove_friend" class="danger" value="Remove Friend"><br>';
}
else if ($logged_in_user_obj->didReceiveRequest($username)) {
echo '<input type="submit" name="respond_request" class="warning" value="Respond to Request"><br>';
}
else if ($logged_in_user_obj->didSendRequest($username)) {
echo '<input type="submit" name="" class="default" value="Request Sent"><br>';
}
else
echo '<input type="submit" name="add_friend" class="success" value="Add Friend"><br>';
}
?>
</form>
<input type="submit" class="deep_blue" data-toggle="modal" data-target="#post_form" value="Post Something">
<?php
if($userLoggedIn != $username) {
echo '<div class="profile_info_bottom">';
echo $logged_in_user_obj->getMutualFriends($username) . " Mutual friends";
echo '</div>';
}
?>
</div>
<div class="profile_main_column column">
<ul class="nav nav-tabs" role="tablist" id="profileTabs">
<li role="presentation" class="active"><a href="#newsfeed_div" aria-controls="newsfeed_div" role="tab" data-toggle="tab">Newsfeed</a></li>
<li role="presentation"><a href="#messages_div" aria-controls="messages_div" role="tab" data-toggle="tab">Messages</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="newsfeed_div">
<div class="posts_area"></div>
<img id="loading" src="assets/images/icons/loading.gif">
</div>
<div role="tabpanel" class="tab-pane fade" id="messages_div">
<?php
echo "<h4>You and <a href='" . $username ."'>" . $profile_user_obj->getFirstAndLastName() . "</a></h4><hr><br>";
echo "<div class='loaded_messages' id='scroll_messages'>";
echo $message_obj->getMessages($username);
echo "</div>";
?>
<div class="message_post">
<form action="" method="POST">
<textarea name='message_body' id='message_textarea' placeholder='Write your message ...'></textarea>
<input type='submit' name='post_message' class='info' id='message_submit' value='Send'>
</form>
</div>
<script>
var div = document.getElementById("scroll_messages");
div.scrollTop = div.scrollHeight;
</script>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="post_form" tabindex="-1" role="dialog" aria-labelledby="postModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="postModalLabel">Post something!</h4>
</div>
<div class="modal-body">
<p>This will appear on the user's profile page and also their newsfeed for your friends to see!</p>
<form class="profile_post" action="" method="POST">
<div class="form-group">
<textarea class="form-control" name="post_body"></textarea>
<input type="hidden" name="user_from" value="<?php echo $userLoggedIn; ?>">
<input type="hidden" name="user_to" value="<?php echo $username; ?>">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" name="post_button" id="submit_profile_post">Post</button>
</div>
</div>
</div>
</div>
<script>
var userLoggedIn = '<?php echo $userLoggedIn; ?>';
var profileUsername = '<?php echo $username; ?>';
$(document).ready(function() {
$('#loading').show();
//Original ajax request for loading first posts
$.ajax({
url: "includes/handlers/ajax_load_profile_posts.php",
type: "POST",
data: "page=1&userLoggedIn=" + userLoggedIn + "&profileUsername=" + profileUsername,
cache:false,
success: function(data) {
$('#loading').hide();
$('.posts_area').html(data);
}
});
$(window).scroll(function() {
var height = $('.posts_area').height(); //Div containing posts
var scroll_top = $(this).scrollTop();
var page = $('.posts_area').find('.nextPage').val();
var noMorePosts = $('.posts_area').find('.noMorePosts').val();
if ((document.body.scrollHeight == document.body.scrollTop + window.innerHeight) && noMorePosts == 'false') {
$('#loading').show();
var ajaxReq = $.ajax({
url: "includes/handlers/ajax_load_profile_posts.php",
type: "POST",
data: "page=" + page + "&userLoggedIn=" + userLoggedIn + "&profileUsername=" + profileUsername,
cache:false,
success: function(response) {
$('.posts_area').find('.nextPage').remove(); //Removes current .nextpage
$('.posts_area').find('.noMorePosts').remove(); //Removes current .nextpage
$('#loading').hide();
$('.posts_area').append(response);
}
});
} //End if
return false;
}); //End (window).scroll(function())
});
</script>
</div>
</body>
</html>