-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
133 lines (110 loc) · 4.83 KB
/
search.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
<?php header('Cache-Control: no-cache'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="styles/search.css" rel="stylesheet">
<link href="styles/topnav.css" rel="stylesheet">
<link href="styles/footer.css" rel="stylesheet">
<title>bonesear.ch</title>
</head>
<body>
<header>
<?php include("include/topnav.html"); ?>
</header>
<main>
<div class="search-bar">
<h1>bonesear<span class="tld">.ch</span></h1>
<span class="version">Public Beta 3.2</span>
<form action="./search.php" method="get">
<input type="text" id="query" name="query" placeholder="Search here" value="<?php if(isset($_GET['query'])) echo $_GET['query']; ?>">
<input type="submit" id="submit" value="Search">
</form>
</div>
<?php
function GetSearchResults($terms){
$url = 'http://localhost:5000/search?terms=' . $terms;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($response === false) return null;
if($httpCode !== 200) return null;
return $response;
}
function PrintResultsToScreen($json){
if($json == null){
echo '<h2 class="no-result">No results found</h2>';
return;
}
if(count($json) == 0){
echo '<h2 class="no-result">No results found</h2>';
return;
}
//print out grid container
echo '<div class="grid-container">';
foreach($json as $j){
$title = $j->title;
$metadesc = $j->metadesc;
$url = $j->domain . '/' . $j->path;
$protocol = '';
$category = $j->category;
$date = $j->date;
if($j->https){
$protocol="https://";
} else {
$protocol="http://";
}
echo '
<div class="left-nav-left-column">
<div class="upvote"><a href="#">▲</a></div>
<div class="downvote"><a href="#">▼</a></div>
</div>
<div class="left-nav-right-column">
<div class="score">100</div>
</div>';
echo '<div class="search-result">';
echo '<a href="' . $protocol . $url .'"><div>';
echo '<span class="search-result-title">' . $title . "</span>";
echo '<br>';
echo '<p class="search-result-website">' . $url . "</p>";
echo '</div></a>';
echo '<p class="search-result-meta">' . $metadesc . '</p>';
echo '</div>';
echo '<div class="right-nav">';
echo '<div class="category">' . $category . '</div>';
if($date !== null){
echo '<div class="date">' . $date . '</div>';
}
echo '</div>';
}
//print out ending div for the grid container
echo '</div>';
}
if(isset($_GET["query"])){
try{
$json = GetSearchResults(rawurlencode($_GET["query"]));
$json = json_decode($json);
PrintResultsToScreen($json);
} catch(Exception $e){
//echo '<h2 class="no-result">No results found</h2>';
}
}
?>
<?php
/* EXAMPLE SEARCH RESULT
<div class="search-result">
<a href="#"><div>
<span class="search-result-title">This is an example result.</span>
<br>
<p class="search-result-website">www.example.com/verylongurl/verylongurl/verylongurl/verylongurl/verylongurl/verylongurl/verylongurl/verylongurl/</p>
</div></a>
<p class="search-result-meta">Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur blanditiis incidunt culpa nesciunt libero reiciendis ipsa repellendus possimus beatae. Voluptate soluta alias reiciendis quos quasi pariatur veritatis dolor hic provident?</p>
</div>*/
?>
</main>
<?php include("include/footer.html") ?>
</body>
</html>