1 | <?php |
||
2 | |||
3 | namespace App\Http\Controllers; |
||
4 | |||
5 | use App\Models\Category; |
||
6 | use App\Models\RootCategory; |
||
7 | use Blacklight\Releases; |
||
8 | use Illuminate\Http\Request; |
||
9 | |||
10 | class BrowseController extends BasePageController |
||
11 | { |
||
12 | /** |
||
13 | * @throws \Exception |
||
14 | */ |
||
15 | public function index(Request $request) |
||
16 | { |
||
17 | $this->setPreferences(); |
||
18 | $releases = new Releases; |
||
19 | |||
20 | $this->smarty->assign('category', -1); |
||
21 | |||
22 | $ordering = $releases->getBrowseOrdering(); |
||
23 | $orderBy = $request->has('ob') && ! empty($request->input('ob')) ? $request->input('ob') : ''; |
||
24 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
25 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
26 | |||
27 | $rslt = $releases->getBrowseRange($page, [-1], $offset, config('nntmux.items_per_page'), $orderBy, -1, $this->userdata->categoryexclusions, -1); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
28 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, $request->url(), $request->query()); |
||
29 | |||
30 | $this->smarty->assign('catname', 'All'); |
||
31 | |||
32 | $this->smarty->assign('lastvisit', $this->userdata->lastlogin); |
||
33 | |||
34 | $browse = []; |
||
35 | foreach ($results as $result) { |
||
36 | $browse[] = $result; |
||
37 | } |
||
38 | |||
39 | $this->smarty->assign( |
||
40 | [ |
||
41 | 'results' => $results, |
||
42 | 'resultsadd' => $browse, |
||
43 | ] |
||
44 | ); |
||
45 | |||
46 | foreach ($ordering as $orderType) { |
||
47 | $this->smarty->assign('orderby'.$orderType, url('browse/All?ob='.$orderType)); |
||
48 | } |
||
49 | |||
50 | $meta_title = 'Browse All Releases'; |
||
51 | $meta_keywords = 'browse,nzb,description,details'; |
||
52 | $meta_description = 'Browse for Nzbs'; |
||
53 | |||
54 | $content = $this->smarty->fetch('browse.tpl'); |
||
55 | $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description')); |
||
56 | $this->pagerender(); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @throws \Exception |
||
61 | */ |
||
62 | public function show(Request $request, string $parentCategory, string $id = 'All'): void |
||
63 | { |
||
64 | $this->setPreferences(); |
||
65 | $releases = new Releases; |
||
66 | |||
67 | $parentId = RootCategory::query()->where('title', $parentCategory)->value('id'); |
||
68 | |||
69 | $query = Category::query()->where('title', $id)->where('root_categories_id', $parentId); |
||
70 | if ($id !== 'All') { |
||
71 | $cat = $query->first(); |
||
72 | $category = $cat !== null ? $cat->id : -1; |
||
73 | } else { |
||
74 | $category = $parentId ?? -1; |
||
75 | } |
||
76 | |||
77 | $grp = -1; |
||
78 | |||
79 | $catarray = []; |
||
80 | $catarray[] = $category; |
||
81 | |||
82 | $this->smarty->assign('parentcat', ucfirst($parentCategory)); |
||
83 | $this->smarty->assign('category', $category); |
||
84 | |||
85 | $ordering = $releases->getBrowseOrdering(); |
||
86 | $orderBy = $request->has('ob') && ! empty($request->input('ob')) ? $request->input('ob') : ''; |
||
87 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
88 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
89 | |||
90 | $rslt = $releases->getBrowseRange($page, $catarray, $offset, config('nntmux.items_per_page'), $orderBy, -1, $this->userdata->categoryexclusions, $grp); |
||
0 ignored issues
–
show
|
|||
91 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, $request->url(), $request->query()); |
||
92 | |||
93 | $browse = []; |
||
94 | |||
95 | foreach ($results as $result) { |
||
96 | $browse[] = $result; |
||
97 | } |
||
98 | |||
99 | $this->smarty->assign('catname', $id); |
||
100 | |||
101 | $this->smarty->assign('lastvisit', $this->userdata->lastlogin); |
||
102 | |||
103 | $this->smarty->assign( |
||
104 | [ |
||
105 | 'results' => $results, |
||
106 | 'resultsadd' => $browse, |
||
107 | ] |
||
108 | ); |
||
109 | |||
110 | $covgroup = ''; |
||
111 | if ($category === -1 && $grp === -1) { |
||
112 | $this->smarty->assign('catname', 'All'); |
||
113 | } elseif ($category !== -1 && $grp === -1) { |
||
114 | $cdata = Category::find($category); |
||
115 | if ($cdata !== null) { |
||
116 | if ($cdata->root_categories_id === Category::GAME_ROOT) { |
||
0 ignored issues
–
show
|
|||
117 | $covgroup = 'console'; |
||
118 | } elseif ($cdata->root_categories_id === Category::MOVIE_ROOT) { |
||
119 | $covgroup = 'movies'; |
||
120 | } elseif ($cdata->root_categories_id === Category::XXX_ROOT) { |
||
121 | $covgroup = 'xxx'; |
||
122 | } elseif ($cdata->root_categories_id === Category::PC_ROOT) { |
||
123 | $covgroup = 'games'; |
||
124 | } elseif ($cdata->root_categories_id === Category::MUSIC_ROOT) { |
||
125 | $covgroup = 'music'; |
||
126 | } elseif ($cdata->root_categories_id === Category::BOOKS_ROOT) { |
||
127 | $covgroup = 'books'; |
||
128 | } |
||
129 | } |
||
130 | } elseif ($grp !== -1) { |
||
131 | $this->smarty->assign('catname', $grp); |
||
132 | } |
||
133 | |||
134 | if ($id === 'All' && $parentCategory === 'All') { |
||
135 | $meta_title = 'Browse '.$parentCategory.' releases'; |
||
136 | foreach ($ordering as $orderType) { |
||
137 | $this->smarty->assign('orderby'.$orderType, url('browse/'.$parentCategory.'?ob='.$orderType)); |
||
138 | } |
||
139 | } else { |
||
140 | $meta_title = 'Browse '.$parentCategory.' / '.$id.' releases'; |
||
141 | foreach ($ordering as $orderType) { |
||
142 | $this->smarty->assign('orderby'.$orderType, url('browse/'.$parentCategory.'/'.$id.'?ob='.$orderType)); |
||
143 | } |
||
144 | } |
||
145 | $meta_keywords = 'browse,nzb,description,details'; |
||
146 | $meta_description = 'Browse for Nzbs'; |
||
147 | |||
148 | $content = $this->smarty->fetch('browse.tpl'); |
||
149 | $this->smarty->assign(compact('content', 'covgroup', 'meta_title', 'meta_keywords', 'meta_description')); |
||
150 | $this->pagerender(); |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * @throws \Exception |
||
155 | */ |
||
156 | public function group(Request $request): void |
||
157 | { |
||
158 | $this->setPreferences(); |
||
159 | $releases = new Releases; |
||
160 | if ($request->has('g')) { |
||
161 | $group = $request->input('g'); |
||
162 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
163 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
164 | $rslt = $releases->getBrowseRange($page, [-1], $offset, config('nntmux.items_per_page'), '', -1, $this->userdata->categoryexclusions, $group); |
||
0 ignored issues
–
show
|
|||
165 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, $request->url(), $request->query()); |
||
166 | |||
167 | $browse = []; |
||
168 | |||
169 | foreach ($results as $result) { |
||
170 | $browse[] = $result; |
||
171 | } |
||
172 | |||
173 | $this->smarty->assign( |
||
174 | [ |
||
175 | 'results' => $results, |
||
176 | 'resultsadd' => $browse, |
||
177 | 'parentcat' => $group, |
||
178 | 'catname' => 'all', |
||
179 | ] |
||
180 | ); |
||
181 | $meta_title = 'Browse Groups'; |
||
182 | $meta_keywords = 'browse,nzb,description,details'; |
||
183 | $meta_description = 'Browse Groups'; |
||
184 | $content = $this->smarty->fetch('browse.tpl'); |
||
185 | |||
186 | $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description')); |
||
187 | |||
188 | $this->pagerender(); |
||
189 | } |
||
190 | } |
||
191 | } |
||
192 |