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 | $releases = new Releases; |
||
18 | |||
19 | $ordering = $releases->getBrowseOrdering(); |
||
20 | $orderBy = $request->has('ob') && ! empty($request->input('ob')) ? $request->input('ob') : ''; |
||
21 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
22 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
23 | |||
24 | $rslt = $releases->getBrowseRange($page, [-1], $offset, config('nntmux.items_per_page'), $orderBy, -1, $this->userdata->categoryexclusions, -1); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
25 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, $request->url(), $request->query()); |
||
26 | |||
27 | // Build order by URLs |
||
28 | $orderByUrls = []; |
||
29 | foreach ($ordering as $orderType) { |
||
30 | $orderByUrls['orderby'.$orderType] = url('browse/All?ob='.$orderType); |
||
31 | } |
||
32 | |||
33 | $this->viewData = array_merge($this->viewData, [ |
||
34 | 'category' => -1, |
||
35 | 'catname' => 'All', |
||
36 | 'results' => $results, |
||
37 | 'lastvisit' => $this->userdata->lastlogin, |
||
38 | 'meta_title' => 'Browse All Releases', |
||
39 | 'meta_keywords' => 'browse,nzb,description,details', |
||
40 | 'meta_description' => 'Browse for Nzbs', |
||
41 | ], $orderByUrls); |
||
42 | |||
43 | return view('browse.index', $this->viewData); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @throws \Exception |
||
48 | */ |
||
49 | public function show(Request $request, string $parentCategory, string $id = 'All') |
||
50 | { |
||
51 | $releases = new Releases; |
||
52 | |||
53 | $parentId = RootCategory::query()->where('title', $parentCategory)->value('id'); |
||
54 | |||
55 | $query = Category::query()->where('title', $id)->where('root_categories_id', $parentId); |
||
56 | if ($id !== 'All') { |
||
57 | $cat = $query->first(); |
||
58 | $category = $cat !== null ? $cat->id : -1; |
||
59 | } else { |
||
60 | $category = $parentId ?? -1; |
||
61 | } |
||
62 | |||
63 | $grp = -1; |
||
64 | |||
65 | $catarray = []; |
||
66 | $catarray[] = $category; |
||
67 | |||
68 | $ordering = $releases->getBrowseOrdering(); |
||
69 | $orderBy = $request->has('ob') && ! empty($request->input('ob')) ? $request->input('ob') : ''; |
||
70 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
71 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
72 | |||
73 | $rslt = $releases->getBrowseRange($page, $catarray, $offset, config('nntmux.items_per_page'), $orderBy, -1, $this->userdata->categoryexclusions, $grp); |
||
0 ignored issues
–
show
|
|||
74 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, $request->url(), $request->query()); |
||
75 | |||
76 | $covgroup = ''; |
||
77 | if ($category === -1 && $grp === -1) { |
||
78 | $catname = 'All'; |
||
79 | } elseif ($category !== -1 && $grp === -1) { |
||
80 | $catname = $id; |
||
81 | $cdata = Category::find($category); |
||
82 | if ($cdata !== null) { |
||
83 | if ($cdata->root_categories_id === Category::GAME_ROOT) { |
||
84 | $covgroup = 'console'; |
||
85 | } elseif ($cdata->root_categories_id === Category::MOVIE_ROOT) { |
||
86 | $covgroup = 'movies'; |
||
87 | } elseif ($cdata->root_categories_id === Category::XXX_ROOT) { |
||
88 | $covgroup = 'xxx'; |
||
89 | } elseif ($cdata->root_categories_id === Category::PC_ROOT) { |
||
90 | $covgroup = 'games'; |
||
91 | } elseif ($cdata->root_categories_id === Category::MUSIC_ROOT) { |
||
92 | $covgroup = 'music'; |
||
93 | } elseif ($cdata->root_categories_id === Category::BOOKS_ROOT) { |
||
94 | $covgroup = 'books'; |
||
95 | } |
||
96 | } |
||
97 | } else { |
||
98 | $catname = $grp; |
||
99 | } |
||
100 | |||
101 | // Build order by URLs |
||
102 | $orderByUrls = []; |
||
103 | if ($id === 'All' && $parentCategory === 'All') { |
||
104 | $meta_title = 'Browse '.$parentCategory.' releases'; |
||
105 | foreach ($ordering as $orderType) { |
||
106 | $orderByUrls['orderby'.$orderType] = url('browse/'.$parentCategory.'?ob='.$orderType); |
||
107 | } |
||
108 | } else { |
||
109 | $meta_title = 'Browse '.$parentCategory.' / '.$id.' releases'; |
||
110 | foreach ($ordering as $orderType) { |
||
111 | $orderByUrls['orderby'.$orderType] = url('browse/'.$parentCategory.'/'.$id.'?ob='.$orderType); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | $this->viewData = array_merge($this->viewData, [ |
||
116 | 'parentcat' => ucfirst($parentCategory), |
||
117 | 'category' => $category, |
||
118 | 'catname' => $catname, |
||
119 | 'results' => $results, |
||
120 | 'lastvisit' => $this->userdata->lastlogin, |
||
121 | 'covgroup' => $covgroup, |
||
122 | 'meta_title' => $meta_title, |
||
123 | 'meta_keywords' => 'browse,nzb,description,details', |
||
124 | 'meta_description' => 'Browse for Nzbs', |
||
125 | ], $orderByUrls); |
||
126 | |||
127 | return view('browse.index', $this->viewData); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @throws \Exception |
||
132 | */ |
||
133 | public function group(Request $request) |
||
134 | { |
||
135 | $releases = new Releases; |
||
136 | if ($request->has('g')) { |
||
137 | $group = $request->input('g'); |
||
138 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
139 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
140 | $rslt = $releases->getBrowseRange($page, [-1], $offset, config('nntmux.items_per_page'), '', -1, $this->userdata->categoryexclusions, $group); |
||
0 ignored issues
–
show
|
|||
141 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, $request->url(), $request->query()); |
||
142 | |||
143 | $this->viewData = array_merge($this->viewData, [ |
||
144 | 'results' => $results, |
||
145 | 'parentcat' => $group, |
||
146 | 'catname' => 'all', |
||
147 | 'lastvisit' => $this->userdata->lastlogin, |
||
148 | 'meta_title' => 'Browse Groups', |
||
149 | 'meta_keywords' => 'browse,nzb,description,details', |
||
150 | 'meta_description' => 'Browse Groups', |
||
151 | ]); |
||
152 | |||
153 | return view('browse.index', $this->viewData); |
||
154 | } |
||
155 | |||
156 | return redirect()->back()->with('error', 'Group parameter is required'); |
||
157 | } |
||
158 | } |
||
159 |