-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
145 lines (131 loc) · 2.86 KB
/
index.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
<html>
<head>
<meta charset="utf-8">
<title>Custom Google Search</title>
<style type="text/css">
body {
font-family: arial,sans-serif;
max-width: 800px;
margin-top: 30px;
}
p {
margin: 0;
padding: 0;
}
h2 {
text-align: center;
margin-bottom: 30px;
color: #444;
}
.item {
margin: 0 30px 30px ;
// display: flex;
}
.item a {
text-decoration: none;
color: #609;
font-size: 1.2em;
}
.item a:hover {
text-decoration: underline;
}
.item a:visited {
color: #1a0dab;
}
.item .link {
color: #006621;
font-size: 0.8em;
margin-bottom: 5px;
}
.item .desc {
color: #444;
font-size: 0.9em;
}
.cont {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
display: flex;
align-items: center;
align-content: center;
justify-content: center;
overflow: auto;
}
.results input {
font-size: 1em;
}
.results {
text-align:center;
}
input {
background-color: #fff;
width: 500px;
font-size: 1.4em;
padding: 2px 10px;
height: 2em;
vertical-align: top;
border: none;
border-radius: 2px;
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.26), 0 0 0 2px rgba(0,0,0,0.08);
transition: box-shadow 200ms cubic-bezier(0.4, 0.0, 0.2, 1);
}
input.button {
margin-left: 3px;
width: initial;
cursor: pointer;
}
input.button:hover {
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.36), 0 0 0 2px rgba(0,0,0,0.20);
}
</style>
</head>
<body>
<?php
if(!isset($_GET["q"])) {
?>
<div class="cont">
<div class="search">
<form action="index.php">
<input type="text" name="q" autofocus>
<input class="button" type="submit" value="🔎">
</form>
</div>
</div>
</body>
</html>
<?php
exit;
}
$json = file_get_contents("https://www.googleapis.com/customsearch/v1?key=AIzaSyDB2ISX0WhMFSmN5jBGc&cx=001997956626253:oi9ssr7ci6e&q=" . $_GET["q"]);
$data = json_decode($json, true);
$title = $data["queries"]["request"][0]["title"];
$total = $data["queries"]["request"][0]["totalResults"];
?>
<div class="search results">
<form action="index.php">
<input type="text" name="q" autofocus>
<input class="button" type="submit" value="🔎">
</form>
</div>
<h2>
<?php echo $title ?>
</h2>
<?php
foreach ($data["items"] as $item) {
?>
<div class="item">
<p class="title">
<a target="_blank" href="<?php echo $item["link"] ?>">
<?php echo $item["title"] ?>
</a>
</p>
<p class="link"><?php echo $item["displayLink"] ?></p>
<p class="desc"><?php echo $item["snippet"] ?></p>
</div>
<?php
}
?>
</body>
</html>