1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\Category; |
6
|
|
|
use Blacklight\Books; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Illuminate\Support\Arr; |
9
|
|
|
|
10
|
|
|
class BooksController extends BasePageController |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @throws \Exception |
14
|
|
|
*/ |
15
|
|
|
public function index(Request $request, string $id = ''): void |
16
|
|
|
{ |
17
|
|
|
$this->setPreferences(); |
18
|
|
|
$book = new Books(['Settings' => $this->settings]); |
|
|
|
|
19
|
|
|
|
20
|
|
|
$boocats = Category::getChildren(Category::BOOKS_ROOT); |
21
|
|
|
|
22
|
|
|
$btmp = []; |
23
|
|
|
foreach ($boocats as $bcat) { |
24
|
|
|
$btmp[] = |
25
|
|
|
[ |
26
|
|
|
'id' => $bcat->id, |
27
|
|
|
'title' => $bcat->title, |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
$category = $request->has('t') ? $request->input('t') : Category::BOOKS_ROOT; |
31
|
|
|
if ($id && \in_array($id, Arr::pluck($btmp, 'title'), false)) { |
32
|
|
|
$cat = Category::query() |
33
|
|
|
->where('title', $id) |
34
|
|
|
->where('root_categories_id', '=', Category::BOOKS_ROOT) |
35
|
|
|
->first(['id']); |
36
|
|
|
$category = $cat !== null ? $cat['id'] : Category::BOOKS_ROOT; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$catarray = []; |
40
|
|
|
$catarray[] = $category; |
41
|
|
|
|
42
|
|
|
$this->smarty->assign('catlist', $btmp); |
43
|
|
|
$this->smarty->assign('category', $category); |
44
|
|
|
$this->smarty->assign('categorytitle', $id); |
45
|
|
|
|
46
|
|
|
$ordering = $book->getBookOrdering(); |
47
|
|
|
$orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : ''; |
48
|
|
|
|
49
|
|
|
$books = []; |
50
|
|
|
$page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
51
|
|
|
$offset = ($page - 1) * config('nntmux.items_per_cover_page'); |
52
|
|
|
$rslt = $book->getBookRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, $this->userdata->categoryexclusions); |
|
|
|
|
53
|
|
|
$results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query()); |
54
|
|
|
$maxwords = 50; |
55
|
|
|
foreach ($results as $result) { |
56
|
|
|
if (! empty($result->overview)) { |
57
|
|
|
$words = explode(' ', $result->overview); |
58
|
|
|
if (\count($words) > $maxwords) { |
59
|
|
|
$newwords = \array_slice($words, 0, $maxwords); |
60
|
|
|
$result->overview = implode(' ', $newwords).'...'; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
$books[] = $result; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$author = ($request->has('author') && ! empty($request->input('author'))) ? stripslashes($request->input('author')) : ''; |
67
|
|
|
$this->smarty->assign('author', $author); |
68
|
|
|
|
69
|
|
|
$title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : ''; |
70
|
|
|
$this->smarty->assign('title', $title); |
71
|
|
|
|
72
|
|
|
$browseby_link = '&title='.$title.'&author='.$author; |
73
|
|
|
|
74
|
|
|
if ((int) $category === -1) { |
75
|
|
|
$this->smarty->assign('catname', 'All'); |
76
|
|
|
} else { |
77
|
|
|
$cdata = Category::find($category); |
78
|
|
|
if ($cdata !== null) { |
79
|
|
|
$this->smarty->assign('catname', $cdata); |
80
|
|
|
} else { |
81
|
|
|
$this->smarty->assign('catname', 'All'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
foreach ($ordering as $ordertype) { |
86
|
|
|
$this->smarty->assign('orderby'.$ordertype, url('/books?t='.$category.$browseby_link.'&ob='.$ordertype.'&offset=0')); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$this->smarty->assign( |
90
|
|
|
[ |
91
|
|
|
'resultsadd' => $books, |
92
|
|
|
'results' => $results, |
93
|
|
|
'covgroup' => 'books', |
94
|
|
|
] |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$meta_title = 'Browse Books'; |
98
|
|
|
$meta_keywords = 'browse,nzb,books,description,details'; |
99
|
|
|
$meta_description = 'Browse for Books'; |
100
|
|
|
$content = $this->smarty->fetch('books.tpl'); |
101
|
|
|
$this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description')); |
102
|
|
|
|
103
|
|
|
$this->pagerender(); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.