forked from lucasvaltl/Pano
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
249 lines (190 loc) · 9.48 KB
/
Copy pathsearch.php
File metadata and controls
249 lines (190 loc) · 9.48 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
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
//ob_start needed to allow redirecting after login
ob_start();
//session_start() needed to use global session variabls $_SESSION etc
session_start();
include('includes/config.php');
require_once('includes/dbconnect.php');
$filename = basename(__FILE__, '.php');
if (isset($_GET['id'])) {
$profileUserName = $_GET['id'];
}
?>
<!DOCTYPE html>
<html>
<a href="javascript:" id="return-to-top"><i class="icon-chevron-up"></i></a>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<script src="https://use.fontawesome.com/ed51c90fe4.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
<link rel="stylesheet" href="css/offset.css">
<link rel="stylesheet" href="css/style.css">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<title> Pano - Search Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="theme-color" content="#ffffff">
<meta property="og:title" content="Pano" />
<meta property="og:image" content="https://apppanoblob.blob.core.windows.net/assets/ogimage.jpg" />
<meta property="og:description" content="The social network taking a wider perspective " />
</head>
<body ng-app="">
<?php
include('includes/header.php');
?>
<main>
<?php
include('includes/search-list.php');
// collect input from typesearch form and ensure correctness
$_SESSION['SearchTerm'] = mysqli_real_escape_string($conn, $_GET['search']);
if (isset($_SESSION['SearchTerm'])){
if ($_SESSION['SearchTerm'][0] == '#'){
$popularTagQuery = "SELECT TagName, COUNT(TagName) AS TagNameOccurence
FROM tags AS t
LEFT JOIN tagspostsmapping AS tpm ON tpm.TagID = t.TagID
GROUP BY TagName
ORDER BY TagNameOccurence DESC
LIMIT 5";
if ($result = mysqli_query($conn, $popularTagQuery)){
$tagNames = [];
while ($row = mysqli_fetch_array($result)){
$tagName = $row['TagName'];
$tagNames [] = $tagName;
}
}
?>
<h1 class="search-results-text">Search results for: <?=$_SESSION['SearchTerm']?></h1>
<h3 class="search-results-text">
Popular hashtags:
<?php
for ($i = 0; $i < sizeof($tagNames); $i++) {
echo '<a href="'. SITE_ROOT .'/search.php?search=%23'. substr($tagNames[$i],1) .'"> '.$tagNames[$i].' </a>';
}
?>
</h3>
<br>
<?php
include('includes/loadposts.php');
?>
<div id="feed-container" class="search-panoramas">
<!-- posts go in here -->
</div>
<br>
<br>
<button id="load-more-button" data-page="1" type="button">Load More</button>
<div id="loader">
<img class="loading" src="<?=SITE_ROOT?>/images/loading.gif" width="50" height="50" />
</div>
<?php
} else {
?>
<h1 class="search-results-text">
Search results for: <?=$_SESSION['SearchTerm']?>
</h1>
<br>
<?
//for the prepared statement
$_SESSION['SearchTerm'] = "%{$_SESSION['SearchTerm']}%";
if (!$stmt = $conn->prepare(
"SELECT * FROM user
WHERE FirstName LIKE ?
OR UserName LIKE ?
LIMIT 10")){
echo "Prepare failed: (". $conn->errno .")" . $conn->error;
}
if(!$stmt->bind_param("ss", $_SESSION['SearchTerm'], $_SESSION['SearchTerm'])){
echo "Binding parameters failed: (".$stmt->errno . ")".$stmt->error;
}
// Attempt select query execution
if ($stmt->execute()) {
$result = $stmt->get_result();
if(mysqli_num_rows($result) > 0){
$rows = [];
while($row = mysqli_fetch_array($result)){
$isFriendOfUser = false;
$friendRequestSent= false;
$friendName = $row['UserName'];
$friendUserID = $row['UserID'];
$friendProfilePictureID = $row['ProfilePictureID'];
//if the friend is yourself, skip the iteration
if ($friendName == $_SESSION['UserName']){
continue;
}
//otherwise check to see if the logged in user is friends with this user's friends
$sql2 = "SELECT * FROM friends
WHERE UserID = '$friendUserID' AND FriendID = '{$_SESSION['UserID']}'";
if ($result2 = mysqli_query($conn, $sql2)) {
$count = mysqli_num_rows($result2);
//if friends, display tick, otherwise an add friend icon will appear
if ($count == 1) {
$isFriendOfUser = true;
}
}
$sql3 = "SELECT * FROM `friendrequests` WHERE FriendID='$friendUserID' AND UserID='{$_SESSION['UserID']}'";
if ($result3 = mysqli_query($conn, $sql3)) {
$count2 = mysqli_num_rows($result3);
//if friends, display tick, otherwise an add friend icon will appear
if ($count2 == 1) {
$friendRequestSent = true;
}
}
$sql4 = "SELECT my.FriendID
FROM friends AS my
JOIN friends AS their USING (FriendID)
WHERE (my.UserID = '{$_SESSION['UserID']}' AND their.UserID = '$friendUserID')";
$mutualFriends = 0;
if ($result4 = mysqli_query($conn, $sql4)) {
$mutualFriends = mysqli_num_rows($result4);
}
//create a frienditem and allow the returnHTML function to run with the parameters
$row = array($friendUserID, $friendName, $friendName, $friendProfilePictureID, $isFriendOfUser,$friendRequestSent, $mutualFriends);
$rows[] = $row;
}//while fetching rows
// Define the custom sort function
function custom_sort($a,$b) {
return $a[6]<$b[6];
}
// Sort the multidimensional array
usort($rows, "custom_sort");
foreach ($rows as $row) {
$row = new frienditem($row[0],$row[1],$row[2],$row[3], $row[4],$row[5],$row[6]);
echo $row->returnHTML();
}//foreachloop
// Close result set
mysqli_free_result($result);
mysqli_free_result($result2);
//needed to clear the SearchTerm session variable so home feed etc can be viewed
$_SESSION['SearchTerm'] = null;
}
} else{
echo "<p>No matches found</p>";
}
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
} // search term
// close connection
mysqli_close($conn);
?>
</main>
</body>
<!-- jquery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous">
</script>
<?php
include('includes/footer.php');
include('includes/friendRequestJS.php');
include('includes/commentlikejs.php');
?>
</html>