-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
131 lines (123 loc) · 6.16 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
<?php
include_once('classes/DB.php');
include_once('classes/Login.php');
include_once('classes/Post.php');
include_once('assets/templates/header.php');
include_once('assets/templates/navbar.php');
$showTimeline = FALSE;
if (Login::isLoggedin()) {
$loggedinUserID = Login::isLoggedin();
$showTimeline = TRUE;
} else {
header('location:login.php');
die;
}
if($showTimeline) {
echo "<div class='container timeline'>";
/*
== get posts from people you follow
== what if i get your own posts also in timeline page? i don't know if it make sense!
*/
$select_posts_query = DB::query("SELECT posts.*, users.Username
FROM posts, users, followers
WHERE posts.User_ID = followers.User_ID
AND followers.User_ID != '{$loggedinUserID}'
AND users.UserID = posts.User_ID
AND followers.FollowerID = '{$loggedinUserID}'
ORDER BY PostTime DESC");
$QUERY_STRING_username = "";
echo "<div class='posts'>";
Post::displayPosts($select_posts_query, $QUERY_STRING_username, $loggedinUserID);
echo "</div>";
?>
<script type="text/javascript">
$(function () {
"use strict";
var like = $("span.likes");
$(like).click(function () {
var num = $(this).find('span.num');
$.ajax({
url : "api/?likes&postid="+$(this).data('id'),
data: "",
type: "POST",
success: function (r) {
var res = JSON.parse(r);
num.text(res.Likes).parent().removeClass('youIn youOut').addClass(res.userStatus).end().prev().addClass('icon-pop');
setTimeout(function () {
num.prev().removeClass('icon-pop');
}, 300);
},
error: function (r) {
console.log(r);
}
});
});
//comments
$('span.comments').one('click', function () {
var commentsDiv = $(this).parent().next('div.comments'),
spanComments = $(this),
num = $(this).find('span.num');
$.ajax({
url : "api/?comments&postid="+spanComments.data('id'),
type: "GET",
data: "",
success: function (r) {
commentsDiv.fadeIn().append('<h5>Comments:</h5>');
if (r != 'No Comments Yet.') {
var comments = JSON.parse(r);
num.text(comments.length);
$.each(comments, function (i) {
commentsDiv.fadeIn().append('<p><small><strong>'+comments[i].Username+'</strong> Says:</small> '+comments[i].CommentBody+'</p>');
});
} else {
commentsDiv.append('<small>'+r+'</small>');
}
commentsDiv.append("<div class='form-group'><textarea class='form-control' name='commentbody' placeholder='type a comment ...'></textarea></div><div class='form-group'><input class='btn btn-sn' type='submit' value='Comment' name='addcomment' /></div>");
$('body').on('click', 'input[name=addcomment]', function () {
$.ajax({
url : "api/?comments&addcomment&postid="+spanComments.data('id'),
type: 'POST',
data: {
commentbody : $(this).parent().prev().find('textarea').val()
},
success: function (r) {
// Start Show Comments
$.ajax({
url : "api/?comments&postid="+spanComments.data('id'),
type: "GET",
data: "",
success: function (r) {
commentsDiv.fadeIn().html('<h5>Comments:</h5>');
if (r != 'No Comments Yet.') {
var comments = JSON.parse(r);
num.text(comments.length);
$.each(comments, function (i) {
commentsDiv.fadeIn().append('<p><small><strong>'+comments[i].Username+'</strong> Says:</small> '+comments[i].CommentBody+'</p>');
});
} else {
commentsDiv.append('<small>'+r+'</small>');
}
commentsDiv.append("<div class='form-group'><textarea class='form-control' name='commentbody' placeholder='type a comment ...'></textarea></div><div class='form-group'><input class='btn btn-sn' type='submit' value='Comment' name='addcomment' /></div>");
},
error: function (r) {
console.log(r);
}
}); // End Show Comments
},
error: function (r) {
console.log(r);
}
});
});
},
error: function (r) {
console.log(r);
}
});
});
});
</script>
<?php
echo "</div>";
}
include_once('assets/templates/footer.php');