This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
search.php
229 lines (214 loc) · 9.58 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
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
<!DOCTYPE html>
<?php require_once("./settings/config.php"); $PAGE_TITLE = 'Anime'; ?>
<?php require_once("./settings/header_footer.php") ?>
<?php
$yearFil = filter_input(INPUT_GET, 'year', FILTER_SANITIZE_STRING);
if (!isset($yearFil))
$yearFil = '';
$statusFil = filter_input(INPUT_GET, 'status', FILTER_SANITIZE_STRING);
if (!isset($statusFil))
$statusFil = '';
$genreFil = filter_input(INPUT_GET, 'genre', FILTER_SANITIZE_STRING);
if (!isset($genreFil))
$genreFil = '';
$sortBy = filter_input(INPUT_GET, 'sortBy', FILTER_SANITIZE_STRING);
if (!isset($sortBy) || trim($sortBy) === '')
$sortBy = 'text_title';
$sortRawValue = $sortBy;
$sortByValue = '';
switch ($sortBy) {
case 'text_title': $sortByValue = 'ASC'; break;
default:
$sortByValue = "= '$sortBy' DESC";
$sortBy = 'translation';
break;
}
$sqlCounter = 0;
$statusSQL = '';
$genreSQL = '';
$yearSQL = '';
function addICS($n) {
return trim('\'%'.$n.'%\'');
}
if ($statusFil !== '') {
$sqlCounter++;
$MSSS = join(" OR `status` LIKE ", array_map('addICS', explode(',', $statusFil)));
$statusSQL = ($sqlCounter === 1 ? "WHERE" : ($sqlCounter > 1 ? "AND" : "")) . " `status` LIKE ".$MSSS;
}
if ($genreFil !== '') {
$sqlCounter++;
$MSSQ = join(" OR `tags` LIKE ", array_map('addICS', explode(',', $genreFil)));
$genreSQL = ($sqlCounter === 1 ? "WHERE" : ($sqlCounter > 1 ? "AND" : "")) . " `tags` LIKE ".$MSSQ;
}
if ($yearFil !== '') {
$sqlCounter++;
$MSSY = join(" OR `released` LIKE ", array_map('addICS', explode(',', $yearFil)));
$yearSQL = ($sqlCounter === 1 ? "WHERE" : ($sqlCounter > 1 ? "AND" : "")) . " `released` LIKE ".$MSSY;
}
$sql = "SELECT * FROM ao_index ".$statusSQL.' '.$genreSQL.' '.$yearSQL." ORDER BY `$sortBy` $sortByValue";
$q1 = $PDOConn->prepare($sql);
$q1->execute();
$filters = $PDOConn->prepare("SELECT * FROM ao_index");
$filters->execute();
$anime_list = [];
while ($f1 = $q1->fetch(PDO::FETCH_ASSOC)) {
$anime_list[] = $f1;
$local_tags = explode(',', $f1['tags']);
$releasedAt = trim(explode(',', $f1['released'])[1]);
}
unset($f1);
$page = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
if (!isset($page)) {
$page = 1;
}
if ($page <= 0) {
$page = 1;
}
$itemsPerPage = 15;
$numberOfPages = ceil(count($anime_list) / $itemsPerPage);
if ($page > $numberOfPages) {
$page = $numberOfPages;
}
$anime_list = array_slice($anime_list, ($page - 1) * $itemsPerPage, $itemsPerPage);
$pageURL = "$site_link/search.php?sortBy=$sortRawValue&genre=$genreFil&status=$statusFil&year=$yearFil&page=";
$tags = [];
$statuses = [];
$years = [];
while ($f1 = $filters->fetch(PDO::FETCH_ASSOC)) {
$local_tags = explode(',', $f1['tags']);
$releasedAt = trim(explode(',', $f1['released'])[1]);
foreach ($local_tags as $tag) {
$tags[trim($tag)] = true;
}
$statuses[$f1['status']] = true;
$years[$releasedAt] = true;
}
ksort($years);
?>
<html>
<head>
<title>Search Results | <?=$site_title?></title>
<meta property="og:title" content="Search Results | <?=$site_title?>" />
<meta property="og:type" content="profile:Anime World" />
<meta property="og:url" content="<?=$site_link?>" />
<meta name="keywords" content="anime, animeworld, watch anime, latest anime, anime online, animeworld online, anime world, anime world online, animeworldonline" />
<?=$head_tags?>
</head>
<body>
<?php echo $header; ?>
<div class="anime-filters">
<select name="sortBy">
<option <?=($sortRawValue === 'text_title' ? 'selected' : '')?> value="title">Sort By</option>
<option <?=($sortRawValue === 'dubbed' ? 'selected' : '')?> value="dubbed">Dubbed</option>
<option <?=($sortRawValue === 'subbed' ? 'selected' : '')?> value="subbed">Subbed</option>
<option <?=($sortRawValue === 'raw' ? 'selected' : '')?> value="raw">Raw</option>
<option <?=($sortRawValue === 'release' ? 'selected' : '')?> value="release">Release</option>
</select>
<select name="genre" multiple>
<option value="">Genre</option>
<?php
$genresList = explode(',', $genreFil);
foreach ($tags as $tag => $v) {
$sel = (in_array($tag, $genresList) ? 'selected' : '');
echo '<option '.$sel.' value="'.$tag.'">'.$tag.'</option>';
}
?>
</select>
<select name="status" multiple>
<option value="">Status</option>
<?php
$statusesList = explode(',', $statusFil);
foreach ($statuses as $status => $v) {
$sel = (in_array($status, $statusesList) ? 'selected' : '');
echo "<option $sel value='$status'>$status</option>";
}
?>
</select>
<select name="year" multiple>
<option value="">Year</option>
<?php
$yearsList = explode(',', $yearFil);
foreach ($years as $year => $v) {
$sel = (in_array($year, $yearsList) ? 'selected' : '');
echo "<option $sel value='$year'>$year</option>";
}
?>
</select>
<script>
$(function ($) {
let siteUrl = '<?=$site_link?>/search.php';
let selects = $('.anime-filters').find('select');
selects.each((e, item) => {
let select = $(item);
select.on('change', () => {
let paramsUrl = siteUrl + '?';
let parArr = [];
selects.each((e2, item2) => {
parArr.push($(item2).attr('name') + '=' + $(item2).val());
});
paramsUrl += parArr.join('&');
window.location.href = paramsUrl;
});
});
});
</script>
</div>
<?php
echo "<div class='movies-list filters'><div class='movies-list-content'>";
$amount = 0;
foreach($anime_list as $a1)
{
$amount = 1;
$tags = $a1['tags'];
$title = $a1["title"];
$icon = $a1["icon"];
$text_title = $a1["text_title"];
$eps = $a1["episodes"];
$translation = $a1["translation"];
$rel = $a1["released"];
if($translation == "raw") $translation = "Raw";
elseif($translation == "dubbed") $translation = "Dubbed";
elseif($translation == "subbed") $translation = "Subbed";
else $translation = "Unknown";
$rand = uniqid();
$tags = explode(', ', $tags);
$TAGS_COUNT = 0;
$Tags = '';
foreach ($tags as $tag)
{
if($TAGS_COUNT === 2) break;
switch ($TAGS_COUNT)
{
case 0: $Tags = $tag; break;
case 1: $Tags .= ', '.$tag; break;
}
$TAGS_COUNT++;
}
?>
<div class="movie-box-new">
<div id="mv-<?=$rand?>" class="movie-cover-new" style='background-image: url("<?=$icon?>")'>
<div class="movie-cover-overlay"></div>
<div class="movie-ep-count"><?=$eps?></div>
</div>
<div id="mv-nm-<?=$rand?>" class="movie-name-new"><span><?=$text_title?></span></div>
<div class="movie-episodes-no"><?=$rel?></div>
<div class="movie-trans" style="<?=($translation === 'Dubbed' ? 'background: #03A9F4':'')?>"><?=$translation?></div>
<script>$("#mv-<?=$rand?>").on('mousedown', function(e) { if(e.which === 2 || e.which === 1) { e.preventDefault(); openWindow("<?=$site_link.'/anime/'.$title?>", e.which); } });</script>
<script>$("#mv-nm-<?=$rand?>").on('mousedown', function(e) { if(e.which === 2 || e.which === 1) { e.preventDefault(); openWindow("<?=$site_link.'/anime/'.$title?>", e.which); } });</script>
</div>
<?php
}
echo '</div></div>';
?>
<div class="pagination">
<?php
for ($i = 1;$i <= $numberOfPages;$i++) {
$activePage = $page == $i ? " class='active'" : "";
echo "<a href='$pageURL$i' $activePage>$i</a>";
}
?>
</div>
<?php echo $footer;?>
<?php require_once("./settings/searchbar.php"); ?>
</body>
</html>