mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 09:18:54 +00:00
116 lines
4.0 KiB
PHP
116 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Blacklight\Books;
|
|
use App\Models\Category;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
class BooksController extends BasePageController
|
|
{
|
|
/**
|
|
* @param \Illuminate\Http\Request $request
|
|
*
|
|
* @param string $id
|
|
*
|
|
* @throws \Exception
|
|
*/
|
|
public function index(Request $request, $id = '')
|
|
{
|
|
$this->setPrefs();
|
|
$book = new Books(['Settings' => $this->settings]);
|
|
|
|
$boocats = Category::getChildren(Category::BOOKS_ROOT);
|
|
|
|
$btmp = [];
|
|
foreach ($boocats as $bcat) {
|
|
$btmp[] =
|
|
[
|
|
'id' => $bcat->id,
|
|
'title' => $bcat->title,
|
|
];
|
|
}
|
|
$category = Category::BOOKS_ROOT;
|
|
if ($id && \in_array($id, array_pluck($btmp, 'title'), false)) {
|
|
$cat = Category::query()
|
|
->where('title', $id)
|
|
->where('parentid', '=', Category::BOOKS_ROOT)
|
|
->first(['id']);
|
|
$category = $cat !== null ? $cat['id'] : Category::BOOKS_ROOT;
|
|
}
|
|
|
|
$catarray = [];
|
|
$catarray[] = $category;
|
|
|
|
$this->smarty->assign('catlist', $btmp);
|
|
$this->smarty->assign('category', $category);
|
|
$this->smarty->assign('categorytitle', $id);
|
|
|
|
$ordering = $book->getBookOrdering();
|
|
$orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : '';
|
|
|
|
$books = [];
|
|
$page = $request->has('page') ? $request->input('page') : 1;
|
|
$offset = ($page - 1) * config('nntmux.items_per_cover_page');
|
|
$rslt = $book->getBookRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, $this->userdata['categoryexclusions']);
|
|
$results = new LengthAwarePaginator($rslt, $rslt['_totalcount'], config('nntmux.items_per_cover_page'), $page, ['path' => $request->url()]);
|
|
$maxwords = 50;
|
|
foreach ($results as $result) {
|
|
if (! empty($result->overview)) {
|
|
$words = explode(' ', $result->overview);
|
|
if (\count($words) > $maxwords) {
|
|
$newwords = \array_slice($words, 0, $maxwords);
|
|
$result->overview = implode(' ', $newwords).'...';
|
|
}
|
|
}
|
|
$books[] = $result;
|
|
}
|
|
|
|
$author = ($request->has('author') && ! empty($request->input('author'))) ? stripslashes($request->input('author')) : '';
|
|
$this->smarty->assign('author', $author);
|
|
|
|
$title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : '';
|
|
$this->smarty->assign('title', $title);
|
|
|
|
$browseby_link = '&title='.$title.'&author='.$author;
|
|
|
|
if ((int) $category === -1) {
|
|
$this->smarty->assign('catname', 'All');
|
|
} else {
|
|
$cdata = Category::find($category);
|
|
if ($cdata !== null) {
|
|
$this->smarty->assign('catname', $cdata->parentid !== null ? $cdata->parent->title.' > '.$cdata->title : $cdata->title);
|
|
} else {
|
|
$this->show404();
|
|
}
|
|
}
|
|
|
|
foreach ($ordering as $ordertype) {
|
|
$this->smarty->assign('orderby'.$ordertype, WWW_TOP.'/books?t='.$category.$browseby_link.'&ob='.$ordertype.'&offset=0');
|
|
}
|
|
|
|
$this->smarty->assign(
|
|
[
|
|
'resultsadd'=> $books,
|
|
'results' => $results,
|
|
]
|
|
);
|
|
|
|
$meta_title = 'Browse Books';
|
|
$meta_keywords = 'browse,nzb,books,description,details';
|
|
$meta_description = 'Browse for Books';
|
|
$content = $this->smarty->fetch('books.tpl');
|
|
$this->smarty->assign(
|
|
[
|
|
'content' => $content,
|
|
'meta_title' => $meta_title,
|
|
'meta_keywords' => $meta_keywords,
|
|
'meta_description' => $meta_description,
|
|
]
|
|
);
|
|
|
|
$this->pagerender();
|
|
}
|
|
}
|