-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
146 lines (80 loc) · 3.21 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
<?php
# Replit development code
$replit_support = filter_var(@file_get_contents("./replit.txt"), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
function p(string $url_input) {
if ($GLOBALS['replit_support']) {
return 'https://apis.scratchconnect.eu.org/free-proxy/get?url=' . $url_input;
} else {
return $url_input;
}
}
# Page setup
if (str_contains($_SERVER['REQUEST_URI'], "+")) {
$uri_search_fixed = implode(" ", explode("+", $_SERVER['REQUEST_URI']));
header("Location: {$uri_search_fixed}");
die();
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Simpleviewer - Searching for <?= @$_GET['q'] ?></title>
<link rel="stylesheet" href="/style.css">
<meta charset="UTF-8">
<meta name="description" content="View Scratch without JavaScript or a modern browser">
<meta name="keywords" content="Scratch, MIT, Legacy, Compatibility, Accessibility">
<meta name="author" content="Voxalice">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body bgcolor="#222"><font color="white" face="sans-serif">
<?php
# Read 'page' as query parameter
if (@round(@$_GET["page"]) > 0) {
$page = @round(@$_GET["page"]);
} else {
$page = 1;
}
$page_offset = $page - 1;
$page_offset = $page_offset * 16;
# Get search results
$search_query = urlencode($_GET['q']); # >:(
$search = @file_get_contents(p("https://api.scratch.mit.edu/search/projects?limit=16&offset={$page_offset}&language=en&mode=popular&q={$search_query}"));
$search_json = json_decode($search, true);
$search_query_echo = str_replace('+', ' ', $search_query);
echo "<h1>Search: {$search_query_echo}</h1>";
# Check if search results were returned
if (str_contains($search, "comments_allowed")) {
foreach($search_json as $key => $value) {
# Echo search results
echo "<div class='result'><a href='/projects/{$value['id']}'><img src='{$value['images']['100x80']}' width='100' height='80'><br><br><b>\"{$value['title']}\"</b></a>, by <a href='/users/{$value['author']['username']}'>{$value['author']['username']}</a> (Project #{$value['id']})</div><br>";
}
# Add page buttons
$page_previous = $page - 1;
$page_next = $page + 1;
# Construct previous page link
$query = $_GET;
// replace parameter(s)
$query['page'] = $page_previous;
// rebuild url
$query_result_previous = "/search.php?" . http_build_query($query);
# Construct next page link
$query = $_GET;
// replace parameter(s)
$query['page'] = $page_next;
// rebuild url
$query_result_next = "/search.php?" . http_build_query($query);
# Echo page buttons / links
if ($page > 1) {
echo "<a href='{$query_result_previous}'>< Previous page</a> | ";
}
echo "<a href='{$query_result_next}'>Next page ></a><br><br>";
} else {
echo "<p>No results :(</p><br>";
}
?>
<form action="/search.php">
<label for="simpleviewer-search"><b>Search for another project:</b></label> <input type="search" id="simpleviewer-search" name="q" value="<?= $_GET['q'] ?>"> <input type="submit" value="Submit">
</form>
<?php include "footer.php"; ?>
</font></body>
</html>