forked from getbookshelf/bookshelf-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
55 lines (48 loc) · 1.77 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
<?php
require_once __DIR__ . '/inc/base.php';
insertHeader();
$query = $_GET['query'];
$filter = $_GET['filter'];
$lib_man = new \Bookshelf\Core\LibraryManager();
$db_con = new \Bookshelf\DataIo\DatabaseConnection();
$config = new \Bookshelf\Core\Configuration(true, $db_con);
$base_url = $config->getBaseUrl();
if(!empty($query)) {
echo '<h1>Results for "' . $db_con->purify($query) . '"</h1>';
$books = $lib_man->search($query);
foreach($books as $book) {
echo '<a href="book.php?id=' . $lib_man->getBook('uuid', $book->uuid, true) . '"><img class="book" src="' . $book->metadata->cover_image . '"></a>';
}
}
elseif(!empty($filter)) {
if($filter == 'author') {
echo '<h1>Filtering by author</h1>';
}
elseif($filter == 'lang') {
echo '<h1>Filtering by language</h1>';
}
elseif($filter == 'categories') {
echo 'Filtering by category is currently not implemented. Please check back soon.';
insertFooter();
exit;
}
$renames = array('desc' => 'description', 'isbn' => 'identifier', 'lang' => 'language');
$values = $lib_man->dumpDistinctLibraryData(str_replace(array_keys($renames), $renames, $filter));
if(empty($values)) {
echo 'No books found.';
exit();
}
foreach($values as $value) {
echo '<h2>' . $value . '</h2>';
$books = $lib_man->search($filter . ': ' . $value);
foreach($books as $book) {
echo '<a href="book.php?id=' . $lib_man->getBook('uuid', $book->uuid, true) . '"><img class="book" src="' . $book->metadata->cover_image . '"></a>';
}
}
}
else {
\Bookshelf\Utility\ErrorHandler::throwError('No query specified.', \Bookshelf\Utility\ErrorLevel::ERROR);
header('Location: index.php');
exit();
}
insertFooter();