-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsearch.php
157 lines (135 loc) · 4.87 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
include("config.php");
include("classes/SiteResultsProvider.php");
include("classes/ImageResultsProvider.php");
if(isset($_GET['term']))
$term = $_GET['term'];
else
exit("You must enter a search term!");
$type = isset($_GET["type"]) ? $_GET["type"] : "sites";
$page = isset($_GET["page"]) ? $_GET["page"] : 1;
?>
<!DOCTYPE html>
<html>
<head>
<title><?php if(isset($term) && $term != '') echo($term . ' | '); ?>Doogle Search</title>
<link rel="icon" type="image/x-icon" href="assets/images/favicon/favicon.ico">
<link rel="shortcut icon" type="image/png" href="assets/images/favicon/favicon-32x32.png">
<link rel="apple-touch-icon" href="assets/images/favicon/apple-touch-icon.png">
<link rel="android-chrome-icon" type="image/png" href="assets/images/favicon/android-chrome-512x512.png">
<meta name="description" content="Search the web for sites and images.">
<meta name="keywords" content="Search engine, doogle, websites">
<meta name="author" content="Zepher Ashe">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.3.5/jquery.fancybox.min.css" /> -->
<link rel="stylesheet" type="text/css" href="assets/css/fancybox/3.3.5/jquery.fancybox.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
<script src="assets/js/jquery-3.3.1.min.js"></script>
<!-- <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> -->
</head>
<body>
<div class="wrapper">
<div class="header">
<div class="headerContent">
<div class="logoContainer">
<a href="index.php">
<img src="assets/images/doogleLogo.png">
</a>
</div>
<div class="searchContainer">
<form action="search.php" method="GET">
<div class="searchBarContainer">
<input type="hidden" name="type" value="<?php echo $type; ?>">
<input class="searchBox" type="text" name="term" value="<?php echo $term; ?>" autocomplete="off">
<button class="searchButton">
<img src="assets/images/icons/search.png">
</button>
</div>
</form>
</div>
</div>
<div class="tabsContainer">
<ul class="tabList">
<li class="<?php echo $type == 'sites' ? 'active' : '' ?>">
<a href='<?php echo "search.php?term=$term&type=sites"; ?>'>
Sites
</a>
</li>
<li class="<?php echo $type == 'images' ? 'active' : '' ?>">
<a href='<?php echo "search.php?term=$term&type=images"; ?>'>
Images
</a>
</li>
</ul>
</div>
</div>
<div class="mainResultsSection">
<?php
if($type == "sites")
{
$resultsProvider = new SiteResultsProvider($con);
$pageSize = 20;
}
else if($type == "images")
{
$resultsProvider = new ImageResultsProvider($con);
$pageSize = 30;
}
$numResults = $resultsProvider->getNumResults($term);
echo "<p class='resultsCount'>$numResults results found</p>";
echo $resultsProvider->getResultsHtml($page, $pageSize, $term);
?>
</div>
<div class="paginationContainer">
<div class="pageButtons">
<div class="pageNumberContainer">
<img src="assets/images/pageStart.png">
</div>
<?php
$pagesToShow = 10;
$numPages = ceil($numResults / $pageSize);
$pagesLeft = min($pagesToShow, $numPages);
$currentPage = $page - floor($pagesToShow / 2);
if($currentPage < 1)
$currentPage = 1;
if($currentPage + $pagesLeft > $numPages + 1)
$currentPage = $numPages + 1 - $pagesLeft;
while($pagesLeft != 0 && $currentPage <= $numPages)
{
if($currentPage == $page)
{
echo "<div class='pageNumberContainer'>
<img src='assets/images/pageSelected.png'>
<span class='pageNumber'>$currentPage</span>
</div>";
}
else
{
echo "<div class='pageNumberContainer'>
<a href='search.php?term=$term&type=$type&page=$currentPage'>
<img src='assets/images/page.png'>
<span class='pageNumber'>$currentPage</span>
</a>
</div>";
}
$currentPage++;
$pagesLeft--;
}
?>
<div class="pageNumberContainer">
<div id="pageEndContainer">
<img src="assets/images/pageEnd.png">
</div>
</div>
</div>
</div>
</div>
<script src="assets/js/fancybox/3.3.5/jquery.fancybox.min.js"></script>
<script src="assets/js/masonry/4.2.2/masonry.pkgd.min.js"></script>
<script type="text/javascript" src="assets/js/script.js"></script>
<!--
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.3.5/jquery.fancybox.min.js"></script>
<script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>
-->
</body>
</html>