-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscover.php
More file actions
209 lines (186 loc) · 12 KB
/
discover.php
File metadata and controls
209 lines (186 loc) · 12 KB
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
<!DOCTYPE html>
<?php
require("php/common.php");
require("php/checkLogin.php");
?>
<html>
<head>
<title>Discovery | Breadbin</title>
<link href="css/common.css" rel="stylesheet" type="text/css">
<link href="css/navbar.css" rel="stylesheet" type="text/css">
<link href="css/discover.css" rel="stylesheet" type="text/css">
<link href="css/vendor/lazyYT.css" rel="stylesheet" type="text/css">
<link href="css/vendor/normalize.css" rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Roboto:400' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="icon" type="image/png" href="img/favicon.png" />
<script src="js/vendor/jquery-1.11.2.min.js"></script>
<script src="js/vendor/jquery.cookie.js"></script>
<script src="js/vendor/jquery.unveil.js"></script>
<script src="js/vendor/jquery.wookmark.js"></script>
<script src="js/vendor/jquery.hoverIntent.js"></script>
<script src="js/postFunctions.js"></script>
<script src="js/tileFunctions.js"></script>
<script type="text/javascript" src="js/vendor/lazyYT.js"></script>
<script>
$( document ).ready(function() {
$('.js-lazyYT').lazyYT();
});
$(window).load(function() {
$('#mainLoader').hide();
$("#content").css("opacity", "1");
$('#content').css("pointer-events", "auto");
});
</script>
</head>
<body>
<noscript>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=error.php">
</noscript>
<?php require('php/template/navbar.php'); ?>
<div id="categories" style="background-color:#fff">
<ul class="cats">
<li class="cats">
<a <?php echo empty($_GET) ? 'class="active"' : 'class="catLink"' ?> href="discover.php">All</a>
</li>
<li class="cats">
<a <?php echo $_GET['f'] == 1 ? 'class="active"' : 'class="catLink"' ?> href="discover.php?f=1">Staff Recommendations</a>
</li>
<li class="cats">
<a <?php echo $_GET['f'] == 2 ? 'class="active"' : 'class="catLink"' ?> href="discover.php?f=2">Top Posts</a>
</li>
<li class="cats">
<a <?php echo $_GET['f'] == 3 ? 'class="active"' : 'class="catLink"' ?> href="discover.php?f=3">Just Pictures</a>
</li>
<li class="cats">
<a <?php echo $_GET['f'] == 4 ? 'class="active"' : 'class="catLink"' ?> href="discover.php?f=4">Just Text</a>
</li>
<li class="cats">
<a <?php echo $_GET['f'] == 5 ? 'class="active"' : 'class="catLink"' ?> href="discover.php?f=5">People</a>
</li>
</ul>
</div>
<div id="content">
<div id="main">
<?php
/* userid <> :id AND */
$query = "SELECT * FROM posts WHERE userid != :id AND userid NOT IN (SELECT user_no FROM following WHERE follower_id = :id) ORDER BY RAND()";
if (!empty($_GET)) { //All
if ($_GET['f'] == 1) { //Staff Recommended
$query = "SELECT * FROM posts WHERE userid != :id AND favourite = 1 AND userid NOT IN (SELECT user_no FROM following WHERE follower_id = :id) ORDER BY RAND()";
} else if ($_GET['f'] == 2) { //Top Posts
$query = "SELECT posts.*, COUNT(post_toasts.userid) AS toasts, COUNT(post_burns.userid) AS burns, (COUNT(post_toasts.userid) - COUNT(post_burns.userid)) AS total FROM posts LEFT JOIN post_toasts ON post_toasts.postid = posts.id LEFT JOIN post_burns ON post_burns.postid = posts.id WHERE posts.userid != :id GROUP BY posts.id HAVING (total) > 0 ORDER BY total";
/*AND posts.userid NOT IN (SELECT user_no FROM following WHERE follower_id = :id)*/
} else if ($_GET['f'] == 3) { //Just Pictures
$query = "SELECT * FROM posts WHERE userid != :id AND type = 'image' AND userid NOT IN (SELECT user_no FROM following WHERE follower_id = :id) ORDER BY RAND()";
} else if ($_GET['f'] == 4) {
$query = "SELECT * FROM posts WHERE userid != :id AND type = 'text' AND userid NOT IN (SELECT user_no FROM following WHERE follower_id = :id) ORDER BY RAND()";
} else if ($_GET['f'] == 5) {
$query = "SELECT * FROM posts WHERE userid = :id ORDER BY RAND()";
}
}
$query_params = array(':id' => $_SESSION['user']['id']);
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
$posts = $stmt->fetchAll();
if (!$posts) {
echo '<center>Nothing to discover.</center>';
} else {
echo '<ul id="tiles">';
$postNumber=0;
foreach ($posts as $row) {
$postNumber++;
$query = "SELECT username FROM users WHERE id = :id";
$query_params = array(':id' => $row['userid']);
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
$test = $stmt->fetch();
$query = "SELECT * FROM post_burns WHERE postid = :postId AND userid= :userId";
$query_params = array(':postId' => $row['id'], ':userId' => $_SESSION['user']['id']);
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
$ifBurnt = $stmt->rowCount();
$query = "SELECT * FROM post_toasts WHERE postid = :postId AND userid = :userId";
$query_params = array(':postId' => $row['id'], ':userId' => $_SESSION['user']['id']);
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
$ifToasted = $stmt->rowCount();
if ($row['type'] == "image") {
$withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $row['image']);
$imageLocation = $withoutExt . '-profile.jpg';
echo '<li class="'.$postNumber.'">';
echo '<div class="banner">';
echo '<a href="showPost.php?id=' . $row['id'] . '"><img class="tiles" src="/' . $imageLocation . '"></a>';
echo '</div>';
echo '<div id="bottomImgTools">';
echo '<div class="postUsername">';
echo '<div class="imageAvatar" style="display: inline; margin-right: 5px;">';
echo '<a href="profile.php?id=' . $row['userid'] . '">';
echo file_exists($isRoot . 'img/avatars/' . $row['userid'] . '/avatar.jpg') ? '<img src="/img/avatars/' . $row['userid'] . '/avatar.jpg" height="25px" width="25px" style="border-radius: 5%; border: 1px solid rgba(54, 54, 54, 0.25);">' : '<img src="/img/defaultAvatar.png" height="25px" width="25px" style="border-radius: 5%; border: 1px solid rgba(54, 54, 54, 0.25);">';
echo '</div>';
echo '<div class="profileName" style="display: inline; position: absolute; top: 6px;">';
echo '' . $test['username'] .'</a>';
echo '</div>';
echo '</div>';
echo '<div class="postLikeToast" id="post-' . $row['id'] . '">';
echo $ifToasted ? '<div class="unToastDisc" style="display: inline;"><i class="fa fa-arrow-circle-up"></i></div> ' : '<div class="toastDisc" style="display: inline;"><i class="fa fa-arrow-circle-up"></i></div> ';
echo $ifBurnt ? '<div class="unBurnDisc" style="display: inline;"><i class="fa fa-arrow-circle-down"></i></div>' : '<div class="burnDisc" style="display: inline;"><i class="fa fa-arrow-circle-down"></i></div>';
echo '</div>';
echo '</div>';
echo '</li>';
} else if ($row['type'] == "text") {
echo '<li class="'.$postNumber.'"><div class="box" style="background:'.$lighterColour.'"><p class="textPost">' . $row['text'] . '</p>';
echo '<div id="bottomImgTools">';
echo '<div class="postUsername">';
echo '<div class="imageAvatar" style="display: inline; margin-right: 5px;">';
echo '<a href="profile.php?id=' . $row['userid'] . '">';
echo file_exists($isRoot . 'img/avatars/' . $row['userid'] . '/avatar.jpg') ? '<img src="/img/avatars/' . $row['userid'] . '/avatar.jpg" height="25px" width="25px" style="border-radius: 5%; border: 1px solid rgba(54, 54, 54, 0.25);">' : '<img src="/img/defaultAvatar.png" height="25px" width="25px" style="border-radius: 5%; border: 1px solid rgba(54, 54, 54, 0.25);">';
echo '</div>';
echo '<div class="profileName" style="display: inline; position: absolute; top: 6px;">';
echo '' . $test['username'] .'</a>';
echo '</div>';
echo '</div>';
echo '<div class="postLikeToast" id="post-' . $row['id'] . '">';
echo $ifToasted ? '<div class="unToastDisc" style="display: inline;"><i class="fa fa-arrow-circle-up"></i></div> ' : '<div class="toastDisc" style="display: inline;"><i class="fa fa-arrow-circle-up"></i></div> ';
echo $ifBurnt ? '<div class="unBurnDisc" style="display: inline;"><i class="fa fa-arrow-circle-down"></i></div>' : '<div class="burnDisc" style="display: inline;"><i class="fa fa-arrow-circle-down"></i></div>';
echo '</div>';
echo '</div>';
echo '</li>';
} else if ($row['type'] == 'imagetext') {
$withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $row['image']);
$imageLocation = $withoutExt . '-profile.jpg';
echo '<li class="'.$postNumber.'">';
echo '<div class="banner">';
echo '<a href="showPost.php?p=' . $row['id'] . '"><img class="blurImage" src="/' . $imageLocation . '"></a>';
echo '</div>';
echo '<div id="bottomImgTools">';
echo '<div class="postUsername">';
echo '<div class="imageAvatar" style="display: inline; margin-right: 5px;">';
echo '<a href="profile.php?id=' . $row['userid'] . '">';
echo file_exists($isRoot . 'img/avatars/' . $row['userid'] . '/avatar.jpg') ? '<img src="/img/avatars/' . $row['userid'] . '/avatar.jpg" height="25px" width="25px" style="border-radius: 5%; border: 1px solid rgba(54, 54, 54, 0.25);">' : '<img src="/img/defaultAvatar.png" height="25px" width="25px" style="border-radius: 5%; border: 1px solid rgba(54, 54, 54, 0.25);">';
echo '</div>';
echo '<div class="profileName" style="display: inline; position: absolute; top: 6px;">';
echo '' . $test['username'] .'</a>';
echo '</div>';
echo '</div>';
echo '<div class="postLikeToast" id="post-' . $row['id'] . '">';
echo $ifToasted ? '<div class="unToastDisc" style="display: inline;"><i class="fa fa-arrow-circle-up"></i></div> ' : '<div class="toastDisc" style="display: inline;"><i class="fa fa-arrow-circle-up"></i></div> ';
echo $ifBurnt ? '<div class="unBurnDisc" style="display: inline;"><i class="fa fa-arrow-circle-down"></i></div>' : '<div class="burnDisc" style="display: inline;"><i class="fa fa-arrow-circle-down"></i></div>';
echo '</div>';
echo '</div>';
echo '</li>';
} else if ($row['type'] == "video") {
echo '<li class="'.$postNumber.'">';
echo '<div class="banner">';
echo '<div class="js-lazyYT" data-youtube-id="'.$row['text'].'" data-width="300px" data-height="194px"></div>';
echo '</div>';
echo '</li>';
}
}
}
?>
</ul>
</div>
</div>
</body>
</html>