-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfeed.php
213 lines (202 loc) · 11.3 KB
/
feed.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Feed | Instaclone</title>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<link href="css/style.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
</head>
<body>
<?php
include_once 'connect.php';
$us = $_GET['username'];
?>
<nav class="navigation">
<a href="feed.php?username=<?php echo $us?>">
<img
src="images/navLogo.png"
alt="logo"
title="logo"
class="navigation__logo"
/>
</a>
<form action="explore.php?curr=<?php echo $us?>&for=_&get=search" class="navigation__search-container" method="post">
<div class="navigation__search-container">
<i class="fa fa-search"></i>
<input type="text" name="search_for" placeholder="Search">
<input type="submit" id="search" name="search" value="Search">
</div>
</form>
<div class="navigation__icons">
<a href="explore.php" class="navigation__link">
<i class="fa fa-compass"></i>
</a>
<a href="post.php?username=<?php echo $us?>" class="navigation__link">
<img
class=" "
src= <?php echo "images/plus.svg"?>
style="width:17px; height:17px"
/>
</a>
<a href="profile.php?curr_us=<?php echo $us ?>&profile_for=<?php echo $us ?>" class="navigation__link">
<i class="fa fa-user-o"></i>
</a>
</div>
</nav>
<main class="feed">
<?php
$result = mysqli_query($conn, "SELECT
followings.following AS follower,
(
SELECT users.profile_picture
FROM users
WHERE username = followings.following
) AS following_dp,
posts.post_id AS post_id,
posts.photo AS photo,
likes,
(
SELECT 1
FROM likes
WHERE likes.post_id = posts.post_id
AND
likes.likername = followings.username
) AS is_liked,
comments,
datediff(now(), posts.time_stamp) AS time_stamp
from followings
join posts
on posts.post_id = (
SELECT posts.post_id
FROM posts
WHERE posts.username = followings.following
ORDER BY posts.time_stamp DESC
LIMIT 1
)
where followings.username = '$us'
group by followings.following; "
);
while($row = mysqli_fetch_array($result)){
$follower = $row['follower'];
$following_dp = $row['following_dp'];
$post_id = $row['post_id'];
$photo = $row['photo'];
$likes = $row['likes'];
$is_liked = $row['is_liked'];
$comments_count = $row['comments'];
$created_at = $row['time_stamp'];
?>
<section class="photo">
<header class="photo__header">
<div class="photo__header-column">
<img
class="photo__avatar"
src= <?php
if($following_dp == null)
echo "images/avatar.svg";
else
echo $following_dp;
?>
style="width:30px;height:30px"
/>
</div>
<div class="photo__header-column">
<a href = "profile.php?curr_us=<?php echo $us?>&profile_for=<?php echo $follower?>">
<?php echo $follower?>
<img height = "13" width = "13"src = "images\verified.png" />
</a>
</div>
</header>
<div class="photo__file-container">
<a href="image-detail.php?post_id=<?php echo $post_id?>&curr_us=<?php echo $us ?>"> <img class="photo__file" src=<?php echo $photo?> ></a>
</div>
<div class="photo__info">
<div class="photo__icons">
<span class="photo__icon">
<a href="like.php?is_liked=<?php echo $is_liked ?>&post_id=<?php echo $post_id ?>&username=<?php echo $us ?>">
<?php
if($is_liked == 1)
echo "<i class = \"fa heart fa-lg heart-red fa-heart\"></i>";
else
echo "<i class = \"fa fa-heart-o heart fa-lg\"></i>";
?>
</a>
<a href="image-detail.php?post_id=<?php echo $post_id?>&curr_us=<?php echo $us ?>">
<i class="fa fa-comment-o fa-lg"></i>
</a>
</div>
<span class="photo__likes"><?php echo $likes ?> likes</span>
<ul class="photo__comments">
<?php
$result2 = mysqli_query($conn, "SELECT
comments.commentername AS 'commenter_name',
comments.comment_text AS 'comment_text'
FROM comments
WHERE post_id = $post_id
ORDER BY time_stamp DESC
LIMIT 2"
);
while($row2 = mysqli_fetch_array($result2)){
$commenter_name = $row2['commenter_name'];
$comment_text = $row2['comment_text'];
?>
<li class="photo__comment">
<span class="photo__comment-author"><?php echo $commenter_name ?></span><?php echo $comment_text ?>
</li>
<?php
}
?>
<a href="image-detail.php?post_id=<?php echo $post_id?>&curr_us=<?php echo $us ?>">
<li class="photo__comment">
<span class="photo__comment-author">
<?php
if($comments_count != 0 && $comments_count != 1)
echo $comments_count-2;
else if($comments_count == 1 || $comments_count == 0)
echo "no";
else
echo $comments_count;
?>
more comments...</span>
</li>
</a>
</ul>
<span class="photo__time-ago"><?php echo $created_at ?> days</span>
<div class="photo__add-comment-container">
<form action="comment.php?post_id=<?php echo $post_id ?>&username=<?php echo $us ?>&return_to=feed" method="POST">
<textarea name = "comment" placeholder="Add a comment..." class="photo__add-comment"></textarea>
<input type = "submit" class="fa fa-ellipsis-h"></input>
</form>
</div>
</div>
</section>
<?php
}
?>
</main>
<footer class="footer">
<nav class="footer__nav">
<ul class="footer__list">
<li class="footer__list-item"><a href="#" class="footer__link">about us</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">support</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">blog</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">press</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">api</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">jobs</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">privacy</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">terms</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">directory</a></li>
<li class="footer__list-item"><a href="#" class="footer__link">language</a></li>
</ul>
</nav>
<span class="footer__copyright">© 2017 instagram</span>
</footer>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="js/app.js"></script>
</body>
</html>