forked from Respheal/archivebinge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowse.php
317 lines (288 loc) · 13.2 KB
/
browse.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php require_once("includes/header.inc.php");
require_once("includes/meta.inc.php");
require_once("includes/css.inc.php");
$conn = dbConnect();
if($_GET['page']){
$page = mysqli_real_escape_string($conn, filter_var($_GET['page'],FILTER_SANITIZE_STRING));
$page = (int)$page;
}else{$page = 1;}
$query = "SELECT SQL_CALC_FOUND_ROWS distinct comics.comic_id, comic_name, comic_image, comic_summary, comic_status from comics";
if($_GET['sort']){
if ($_GET['sort'] == "abc"){$query = $query." order by comic_name asc"; $sort="abc";}
elseif ($_GET['sort'] == "zyx"){$query = $query." order by comic_name desc"; $sort="zyx";}
elseif ($_GET['sort'] == "123"){$query = $query." order by last_update desc"; $sort="123";}
elseif ($_GET['sort'] == "321"){$query = $query." order by last_update asc"; $sort="321";}
elseif ($_GET['sort'] == "newest"){$query = $query." order by comic_id desc"; $sort="newest";}
elseif ($_GET['sort'] == "oldest"){$query = $query." order by comic_id asc"; $sort="oldest";}
elseif ($_GET['sort'] == "popular"){$query = $query." inner join user_subs on comics.comic_id = user_subs.comic_id order by (SELECT count(comic_id) as total FROM user_subs where comic_id=comics.comic_id) desc"; $sort="popular";}
}else{$query = $query." order by last_update desc";}
$query = $query." limit ?,30";
$pagemax = $page*30;
$pagemin = $pagemax-30;
//Get tag list: $comic_tags[tag_name]
$sql = "SELECT tag_name from tags ORDER BY tag_name ASC";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$alltags[] = $row["tag_name"];
}
//Get warning list: $comic_warnings[warning_name, warning_category]
$sql = "SELECT warning_name from warnings";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$allwarnings[] = $row["warning_name"];
}
$stmt = $conn->prepare($query);
$stmt->bind_param('i', $pagemin);
//find comics that match criteria
if($stmt->execute()){
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$comics[] = array(
"id"=>$row["comic_id"],
"name"=>$row["comic_name"],
"image"=>$row["comic_image"],
"summary"=>str_replace('\r\n',' ',$row["comic_summary"]),
"status"=>$row["comic_status"]);
}
$stmt = $conn->prepare("SELECT FOUND_ROWS();");
$stmt->execute();
$stmt->bind_result($count);
$stmt->store_result();
$stmt->fetch();
//grab the tags for those comics
$stmt = $conn->prepare("select tag_name from tags inner join comic_tags on tags.tag_id = comic_tags.tag_id where comic_id=? limit 10");
$stmt->bind_param('i', $comic_id);
$i = 0;
foreach($comics as $comic){
$comic_id = $comic["id"];
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$comics[$i]["tags"][] = $row["tag_name"];
}
}
$i++;
}
$pagecount = ceil($count/30);
}else {
$error = "0 results";
}
}else {
$error = "0 results";
}
$stmt->close();
$conn->close();
?>
<script>
function disableEmptyInputs(form) {
var controls = form.elements;
for (var i=0, iLen=controls.length; i<iLen; i++) {
controls[i].disabled = controls[i].value == '';
}
}
</script>
</head>
<body>
<?php require_once 'includes/menu.inc.php';?>
<div class="container panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-9">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<a data-toggle="collapse" data-parent="#accordion" href="#pagelist" class="collapsed link-unstyled">
<div class="panel-heading">
<h4 class="panel-title">Advanced Search Options <span class="caret"></span></h4>
</div><!--panel heading-->
</a>
<div id="pagelist" class="panel-collapse collapse">
<div class="panel-body">
<p>All fields optional.</p>
<form onsubmit="disableEmptyInputs(this)" method="get" action="/search">
<div class="form-group">
<label for="name">Comic Name</label>
<input type="text" class="form-control" name="name">
</div>
<div class="form-group">
<label for="creator">Creator</label>
<input type="text" class="form-control" name="creator">
</div>
<div class="form-group">
<label for="status">Status</label>
<select class="form-control" name="status">
<option></option>
<option value="Ongoing">Ongoing</option>
<option value="On Hiatus">Hiatus</option>
<option value="Completed">Completed</option>
<option value="Cancelled">Cancelled</option>
</select>
</div>
<div class="form-group">
<label for="yestags">Include Tags</label>
<select class="multipleSelectTags form-control" multiple name="yestags[]">
<?php foreach ($alltags as $tag) {
echo '<option value="'.$tag.'">'.$tag.'</option>
';}?>
</select>
</div>
<div class="form-group">
<label for="notags">Exclude Tags</label>
<select class="multipleSelectTags form-control" multiple name="notags[]">
<?php foreach ($alltags as $tag) {
echo '<option value="'.$tag.'">'.$tag.'</option>
';}?>
</select>
</div>
<div class="form-group">
<label for="warnings">Exclude Warnings</label>
<select class="multipleSelectWarnings form-control" multiple name="warnings[]">
<?php foreach ($allwarnings as $warning) {
echo '<option value="'.$warning.'">'.$warning.'</option>
';}?>
</select>
<p class="help-block">Not all comics will have content labeled appropriately. Proceed with caution.</p>
</div>
<div class="form-group">
<label for="pagecount">Pages</label>
<div class="input-group">
<div class="input-group-addon">
<select name="pagesmods">
<option></option>
<option>></option>
<option><</option>
<option>=</option>
</select>
</div>
<input class="form-control" type="number" min="0" placeholder="Number of pages" name="pagecount">
</div>
</div>
<input type="hidden" name="advanced" value="True" />
<button type="submit" class="btn btn-default">Search</button>
</form>
</div><!--list body-->
</div><!--pagelist-->
</div><!--accordion-->
</div><!--accordion group-->
<h1>Search Results
<div class="dropdown" style="display:inline-block">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Sort <span class="caret"></span></button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="/search/all?sort=123">Last Update</a></li>
<li><a href="/search/all?sort=321">Last Update (Reverse)</a></li>
<li><a href="/search/all?sort=abc">Alphabetical</a></li>
<li><a href="/search/all?sort=zyx">Alphabetical (Reverse)</a></li>
<li><a href="/search/all?sort=newest">Newest</a></li>
<li><a href="/search/all?sort=oldest">Oldest</a></li>
<li><a href="/search/all?sort=popular">Popularity (Subscriptions)</a></li>
</ul>
</div></h1>
<?php
if(!$error){
$first = $pagemin+1;
echo '<div class="list-group">';
foreach($comics as $comic){
echo '<a href="/comic/'.$comic["id"].'" class="list-group-item list-group-item-action">';
if($comic["image"]){
echo '<style>.comic'.$comic["id"].':before {background-image: url("/assets/usr_imgs/banners/'.$comic["image"].'");}</style>';
echo '<div class="list-group-item-heading comic-bar comic'.$comic["id"].'"><h3>'.$comic["name"].'</h3></div>';
}
else{
echo '<style>.comic'.$comic["id"].'{background: inherit;}</style>';
echo '<div class="list-group-item-heading comic-bar comic'.$comic["id"].'"><h3 class="white-text">'.$comic["name"].'</h3></div>';
}
if (strlen($comic["summary"]) > 250){echo '<p class="list-group-item-text">'.truncate($comic["summary"]).'</p>';}else{echo '<p class="list-group-item-text">'.$comic["summary"].'</p>';}
echo '<div class="row"><div class="panel-body">';
if($comic["tags"] && count($comic["tags"]) > 0){
$tags = implode(", ", $comic["tags"]);
if(strlen($tags)>74){echo '<div class="col-md-9"><label>Tags: </label> '.truncate($tags,75).'</div>';}else{echo '<div class="col-md-9"><label>Tags: </label> '.$tags.'</div>';}
}
echo '<div class="col-md-3"><label>Status: </label> '.$comic["status"].'</div>';
echo '</dl>';
echo '</div></div>';
echo '</a>
';
}
echo '</div>';
}else{
echo '<div class="alert alert-info">
<strong>'.$error.'</strong>
</div>';
}
if ($pagecount > 1){
?>
<ul class="pagination">
<?php for ($i = 1; $i <= $pagecount; $i++) {
?><li<? if ($page == $i){echo ' class="active"';} ?>><a href="/search/all?page=<?php echo $i; if ($sort){echo '&sort='.$sort;}?>"><?php echo $i; ?></a></li><?php
}?>
</ul>
<?php } ?>
</div>
<div class="hidden-xs hidden-sm col-md-3 text-center">
<div class="panel panel-default">
<div class="panel-body">
<?php include_once 'includes/pw/skyscraper.inc.php'; ?>
</div>
</div>
</div>
</div><!--row-->
</div><!--panel body-->
</div> <!-- /container -->
<?php require_once 'includes/footer.inc.php';?>
<script>
$(document).ready(function() {
$.Fastselect.defaults = {
elementClass: 'fstElement',
singleModeClass: 'fstSingleMode',
noneSelectedClass: 'fstNoneSelected',
multipleModeClass: 'fstMultipleMode',
queryInputClass: 'fstQueryInput',
queryInputExpandedClass: 'fstQueryInputExpanded',
fakeInputClass: 'fstFakeInput',
controlsClass: 'fstControls',
toggleButtonClass: 'fstToggleBtn',
activeClass: 'fstActive',
itemSelectedClass: 'fstSelected',
choiceItemClass: 'fstChoiceItem',
choiceRemoveClass: 'fstChoiceRemove',
userOptionClass: 'fstUserOption',
resultsContClass: 'fstResults',
resultsOpenedClass: 'fstResultsOpened',
resultsFlippedClass: 'fstResultsFilpped',
groupClass: 'fstGroup',
itemClass: 'fstResultItem',
groupTitleClass: 'fstGroupTitle',
loadingClass: 'fstLoading',
noResultsClass: 'fstNoResults',
focusedItemClass: 'fstFocused',
matcher: null,
url: null,
loadOnce: false,
apiParam: 'query',
initialValue: null,
clearQueryOnSelect: true,
minQueryLength: 1,
focusFirstItem: false,
flipOnBottom: true,
typeTimeout: 150,
userOptionAllowed: false,
valueDelimiter: ',',
maxItems: null,
parseData: null,
onItemSelect: null,
onItemCreate: null,
onMaxItemsReached: null,
placeholder: 'Select',
searchPlaceholder: 'Search options',
noResultsText: 'No results',
userOptionPrefix: 'Add '
}
$('.multipleSelectTags').fastselect();
$('.multipleSelectWarnings').fastselect();
});
</script>
</body>
</html>