prepare("SELECT bookid FROM epube_favorites WHERE owner = ?"); $fav_sth->execute([$owner]); $fav_ids = []; while ($line = $fav_sth->fetch()) { array_push($fav_ids, $line["bookid"]); } $ids_qpart = "books.id IN (" . implode(",", $fav_ids) . ")"; } $limit = 60; $offset = (int) ($_REQUEST["offset"] ?? 0); $order_by = $query ? "author_sort, series_name, series_index, title, books.id" : "books.id DESC"; $sth = $db->prepare("SELECT books.*, s.name AS series_name, (SELECT id FROM data WHERE book = books.id AND format = 'EPUB' LIMIT 1) AS epub_id FROM books LEFT JOIN books_series_link AS bsl ON (bsl.book = books.id) LEFT JOIN series AS s ON (bsl.series = s.id) WHERE ((:query = '') OR ( LOWER(books.author_sort) LIKE LOWER(:query) OR LOWER(books.title) LIKE LOWER(:query) OR LOWER(series_name) LIKE LOWER(:query) )) AND $ids_qpart ORDER BY $order_by LIMIT :limit OFFSET :offset"); $sth->execute([':limit' => $limit, ':offset' => $offset, ':query' => '%' . $query . '%']); print "
"; $rows = 0; while ($line = $sth->fetch()) { ++$rows; if ($line['has_cover']) { $cover_filename = Config::get(Config::BOOKS_DIR) . "/" . $line["path"] . "/" . "cover.jpg"; if (file_exists($cover_filename)) $cover_mtime = filemtime($cover_filename); else $cover_mtime = 0; $cover_link = "backend.php?" . http_build_query(["op" => "cover", "id" => $line["id"], "ts" => $cover_mtime]); } else { $cover_link = ""; } $author_link = "?" . http_build_query(["query" => $line["author_sort"]]); $in_progress = false; $is_read = false; if ($line["epub_id"]) { $read_link = "read.html?" . http_build_query(["id" => $line["epub_id"], "rt" => $mode, "b" => $line["id"], "ts" => time()]); $lastread_sth = $ldb->prepare("SELECT lastread, total_pages FROM epube_books, epube_pagination WHERE epube_pagination.bookid = epube_books.bookid AND epube_books.bookid = ? AND owner = ?"); $lastread_sth->execute([$line['epub_id'], $owner]); if ($lastread_line = $lastread_sth->fetch()) { $lastread = $lastread_line["lastread"]; $total_pages = $lastread_line["total_pages"]; $is_read = $total_pages - $lastread < 5; $in_progress = $lastread > 1; } } else { $read_link = ""; } $cover_class = $is_read ? "read" : ""; $title_class = $in_progress ? "in_progress" : ""; if ($line["series_name"]) { $series_link = "?" . http_build_query(["query" => $line["series_name"]]); $series_full = $line["series_name"] . " [" . $line["series_index"] . "]"; } else { $series_link = ""; $series_full = ""; } $data_sth = $db->prepare("SELECT * FROM data WHERE book = ? LIMIT 3"); $data_sth->execute([$line['id']]); ?>
">
$mode, "query" => $query, "offset" => $offset - $limit]); $next_link = http_build_query(["mode" => $mode, "query" => $query, "offset" => $offset + $limit]); ?>