|
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
|
|
|
* @param \Illuminate\Http\Request $request |
|
14
|
|
|
* |
|
15
|
|
|
* @param string $id |
|
16
|
|
|
* |
|
17
|
|
|
* @throws \Exception |
|
18
|
|
|
*/ |
|
19
|
|
|
public function index(Request $request, $id = '') |
|
20
|
|
|
{ |
|
21
|
|
|
$this->setPrefs(); |
|
22
|
|
|
$book = new Books(['Settings' => $this->settings]); |
|
23
|
|
|
|
|
24
|
|
|
$boocats = Category::getChildren(Category::BOOKS_ROOT); |
|
25
|
|
|
|
|
26
|
|
|
$btmp = []; |
|
27
|
|
|
foreach ($boocats as $bcat) { |
|
28
|
|
|
$btmp[] = |
|
29
|
|
|
[ |
|
30
|
|
|
'id' => $bcat->id, |
|
31
|
|
|
'title' => $bcat->title, |
|
32
|
|
|
]; |
|
33
|
|
|
} |
|
34
|
|
|
$category = $request->has('t') ? $request->input('t') : Category::BOOKS_ROOT; |
|
35
|
|
|
if ($id && \in_array($id, Arr::pluck($btmp, 'title'), false)) { |
|
36
|
|
|
$cat = Category::query() |
|
37
|
|
|
->where('title', $id) |
|
38
|
|
|
->where('root_categories_id', '=', Category::BOOKS_ROOT) |
|
39
|
|
|
->first(['id']); |
|
40
|
|
|
$category = $cat !== null ? $cat['id'] : Category::BOOKS_ROOT; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$catarray = []; |
|
44
|
|
|
$catarray[] = $category; |
|
45
|
|
|
|
|
46
|
|
|
$this->smarty->assign('catlist', $btmp); |
|
|
|
|
|
|
47
|
|
|
$this->smarty->assign('category', $category); |
|
48
|
|
|
$this->smarty->assign('categorytitle', $id); |
|
49
|
|
|
|
|
50
|
|
|
$ordering = $book->getBookOrdering(); |
|
51
|
|
|
$orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : ''; |
|
52
|
|
|
|
|
53
|
|
|
$books = []; |
|
54
|
|
|
$page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
|
55
|
|
|
$offset = ($page - 1) * config('nntmux.items_per_cover_page'); |
|
56
|
|
|
$rslt = $book->getBookRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, $this->userdata->categoryexclusions); |
|
|
|
|
|
|
57
|
|
|
$results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query()); |
|
58
|
|
|
$maxwords = 50; |
|
59
|
|
|
foreach ($results as $result) { |
|
60
|
|
|
if (! empty($result->overview)) { |
|
61
|
|
|
$words = explode(' ', $result->overview); |
|
62
|
|
|
if (\count($words) > $maxwords) { |
|
63
|
|
|
$newwords = \array_slice($words, 0, $maxwords); |
|
64
|
|
|
$result->overview = implode(' ', $newwords).'...'; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
$books[] = $result; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$author = ($request->has('author') && ! empty($request->input('author'))) ? stripslashes($request->input('author')) : ''; |
|
71
|
|
|
$this->smarty->assign('author', $author); |
|
72
|
|
|
|
|
73
|
|
|
$title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : ''; |
|
74
|
|
|
$this->smarty->assign('title', $title); |
|
75
|
|
|
|
|
76
|
|
|
$browseby_link = '&title='.$title.'&author='.$author; |
|
77
|
|
|
|
|
78
|
|
|
if ((int) $category === -1) { |
|
79
|
|
|
$this->smarty->assign('catname', 'All'); |
|
80
|
|
|
} else { |
|
81
|
|
|
$cdata = Category::find($category); |
|
82
|
|
|
if ($cdata !== null) { |
|
83
|
|
|
$this->smarty->assign('catname', $cdata); |
|
84
|
|
|
} else { |
|
85
|
|
|
$this->smarty->assign('catname', 'All'); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
foreach ($ordering as $ordertype) { |
|
90
|
|
|
$this->smarty->assign('orderby'.$ordertype, url('/books?t='.$category.$browseby_link.'&ob='.$ordertype.'&offset=0')); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$this->smarty->assign( |
|
94
|
|
|
[ |
|
95
|
|
|
'resultsadd'=> $books, |
|
96
|
|
|
'results' => $results, |
|
97
|
|
|
'covgroup' => 'books', |
|
98
|
|
|
] |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
$meta_title = 'Browse Books'; |
|
102
|
|
|
$meta_keywords = 'browse,nzb,books,description,details'; |
|
103
|
|
|
$meta_description = 'Browse for Books'; |
|
104
|
|
|
$content = $this->smarty->fetch('books.tpl'); |
|
|
|
|
|
|
105
|
|
|
$this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description')); |
|
106
|
|
|
|
|
107
|
|
|
$this->pagerender(); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.