1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\Category; |
6
|
|
|
use App\Models\Settings; |
7
|
|
|
use App\Models\UserSerie; |
8
|
|
|
use App\Models\Video; |
9
|
|
|
use Blacklight\Releases; |
10
|
|
|
use Illuminate\Http\Request; |
11
|
|
|
|
12
|
|
|
class MyShowsController extends BasePageController |
13
|
|
|
{ |
14
|
|
|
public function show(Request $request) |
15
|
|
|
{ |
16
|
|
|
$this->setPreferences(); |
17
|
|
|
$action = $request->input('action') ?? ''; |
18
|
|
|
$videoId = $request->input('id') ?? ''; |
19
|
|
|
|
20
|
|
|
if ($request->has('from')) { |
21
|
|
|
$this->smarty->assign('from', url($request->input('from'))); |
22
|
|
|
} else { |
23
|
|
|
$this->smarty->assign('from', url('/myshows')); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
switch ($action) { |
27
|
|
|
case 'delete': |
28
|
|
|
$show = UserSerie::getShow($this->userdata->id, $videoId); |
29
|
|
|
if (! $show) { |
30
|
|
|
return redirect()->back(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
UserSerie::delShow($this->userdata->id, $videoId); |
34
|
|
|
if ($request->has('from')) { |
35
|
|
|
header('Location:'.url($request->input('from'))); |
|
|
|
|
36
|
|
|
} else { |
37
|
|
|
return redirect()->to('myshows'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
break; |
41
|
|
|
case 'add': |
42
|
|
|
case 'doadd': |
43
|
|
|
$show = UserSerie::getShow($this->userdata->id, $videoId); |
44
|
|
|
if ($show) { |
45
|
|
|
return redirect()->to('myshows'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$show = Video::getByVideoID($videoId); |
49
|
|
|
if (! $show) { |
50
|
|
|
return redirect()->to('myshows'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($action === 'doadd') { |
54
|
|
|
$category = ($request->has('category') && \is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : []; |
55
|
|
|
UserSerie::addShow($this->userdata->id, $videoId, $category); |
56
|
|
|
if ($request->has('from')) { |
57
|
|
|
return redirect()->to($request->input('from')); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return redirect()->to('myshows'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$tmpcats = Category::getChildren(Category::TV_ROOT); |
64
|
|
|
$categories = []; |
65
|
|
|
foreach ($tmpcats as $c) { |
66
|
|
|
// If TV WEB-DL categorization is disabled, don't include it as an option |
67
|
|
|
if ((int) $c['id'] === Category::TV_WEBDL && (int) Settings::settingValue('catwebdl') === 0) { |
68
|
|
|
continue; |
69
|
|
|
} |
70
|
|
|
$categories[$c['id']] = $c['title']; |
71
|
|
|
} |
72
|
|
|
$this->smarty->assign('type', 'add'); |
73
|
|
|
$this->smarty->assign('cat_ids', array_keys($categories)); |
74
|
|
|
$this->smarty->assign('cat_names', $categories); |
75
|
|
|
$this->smarty->assign('cat_selected', []); |
76
|
|
|
$this->smarty->assign('video', $videoId); |
77
|
|
|
$this->smarty->assign('show', $show); |
78
|
|
|
$content = $this->smarty->fetch('myshows-add.tpl'); |
79
|
|
|
$this->smarty->assign([ |
80
|
|
|
'content' => $content, |
81
|
|
|
]); |
82
|
|
|
$this->pagerender(); |
83
|
|
|
break; |
84
|
|
|
case 'edit': |
85
|
|
|
case 'doedit': |
86
|
|
|
$show = UserSerie::getShow($this->userdata->id, $videoId); |
87
|
|
|
|
88
|
|
|
if (! $show) { |
89
|
|
|
return redirect()->to('myshows'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ($action === 'doedit') { |
93
|
|
|
$category = ($request->has('category') && \is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : []; |
94
|
|
|
UserSerie::updateShow($this->userdata->id, $videoId, $category); |
95
|
|
|
if ($request->has('from')) { |
96
|
|
|
return redirect()->to($request->input('from')); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return redirect()->to('myshows'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$tmpcats = Category::getChildren(Category::TV_ROOT); |
103
|
|
|
$categories = []; |
104
|
|
|
foreach ($tmpcats as $c) { |
105
|
|
|
$categories[$c['id']] = $c['title']; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$this->smarty->assign('type', 'edit'); |
109
|
|
|
$this->smarty->assign('cat_ids', array_keys($categories)); |
110
|
|
|
$this->smarty->assign('cat_names', $categories); |
111
|
|
|
$this->smarty->assign('cat_selected', explode('|', $show['categories'])); |
112
|
|
|
$this->smarty->assign('video', $videoId); |
113
|
|
|
$this->smarty->assign('show', $show); |
114
|
|
|
$content = $this->smarty->fetch('myshows-add.tpl'); |
115
|
|
|
$this->smarty->assign([ |
116
|
|
|
'content' => $content, |
117
|
|
|
]); |
118
|
|
|
$this->pagerender(); |
119
|
|
|
break; |
120
|
|
|
default: |
121
|
|
|
|
122
|
|
|
$title = 'My Shows'; |
123
|
|
|
$meta_title = 'My Shows'; |
124
|
|
|
$meta_keywords = 'search,add,to,cart,nzb,description,details'; |
125
|
|
|
$meta_description = 'Manage Your Shows'; |
126
|
|
|
|
127
|
|
|
$tmpcats = Category::getChildren(Category::TV_ROOT); |
128
|
|
|
$categories = []; |
129
|
|
|
foreach ($tmpcats as $c) { |
130
|
|
|
$categories[$c['id']] = $c['title']; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$shows = UserSerie::getShows($this->userdata->id); |
134
|
|
|
$results = []; |
135
|
|
|
$catArr = []; |
136
|
|
|
if ($shows !== null) { |
137
|
|
|
foreach ($shows as $showk => $show) { |
138
|
|
|
$showcats = explode('|', $show['categories']); |
139
|
|
|
if (\is_array($showcats) && ! empty($showcats)) { |
140
|
|
|
foreach ($showcats as $scat) { |
141
|
|
|
if (! empty($scat)) { |
142
|
|
|
$catArr[] = $categories[$scat]; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
$show['categoryNames'] = implode(', ', $catArr); |
146
|
|
|
} else { |
147
|
|
|
$show['categoryNames'] = ''; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
$results[$showk] = $show; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
$this->smarty->assign('shows', $results); |
154
|
|
|
|
155
|
|
|
$content = $this->smarty->fetch('myshows.tpl'); |
156
|
|
|
$this->smarty->assign(compact('content', 'title', 'meta_title', 'meta_keywords', 'meta_description')); |
157
|
|
|
$this->pagerender(); |
158
|
|
|
break; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @throws \Exception |
164
|
|
|
*/ |
165
|
|
|
public function browse(Request $request): void |
166
|
|
|
{ |
167
|
|
|
$this->setPreferences(); |
168
|
|
|
$title = 'Browse My Shows'; |
169
|
|
|
$meta_title = 'My Shows'; |
170
|
|
|
$meta_keywords = 'search,add,to,cart,nzb,description,details'; |
171
|
|
|
$meta_description = 'Browse Your Shows'; |
172
|
|
|
|
173
|
|
|
$shows = UserSerie::getShows($this->userdata->id); |
174
|
|
|
|
175
|
|
|
$releases = new Releases; |
176
|
|
|
|
177
|
|
|
$page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
178
|
|
|
$offset = ($page - 1) * config('nntmux.items_per_page'); |
179
|
|
|
$ordering = $releases->getBrowseOrdering(); |
180
|
|
|
$orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : ''; |
181
|
|
|
$browseCount = $shows->count(); |
182
|
|
|
|
183
|
|
|
$rslt = $releases->getShowsRange($shows ?? [], $offset, config('nntmux.items_per_page'), $orderby, -1, $this->userdata->categoryexclusions); |
|
|
|
|
184
|
|
|
$results = $this->paginate($rslt ?? [], $browseCount, config('nntmux.items_per_page'), $page, $request->url(), $request->query()); |
185
|
|
|
|
186
|
|
|
$this->smarty->assign('covgroup', ''); |
187
|
|
|
|
188
|
|
|
foreach ($ordering as $ordertype) { |
189
|
|
|
$this->smarty->assign('orderby'.$ordertype, url('/myshows/browse?ob='.$ordertype.'&offset=0')); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
$this->smarty->assign('lastvisit', $this->userdata->lastlogin); |
193
|
|
|
|
194
|
|
|
$this->smarty->assign(['results' => $results, 'resultsadd' => $rslt]); |
195
|
|
|
|
196
|
|
|
$this->smarty->assign('shows', true); |
197
|
|
|
|
198
|
|
|
$content = $this->smarty->fetch('browse.tpl'); |
199
|
|
|
$this->smarty->assign([ |
200
|
|
|
'content' => $content, |
201
|
|
|
'title' => $title, |
202
|
|
|
'meta_title' => $meta_title, |
203
|
|
|
'meta_keywords' => $meta_keywords, |
204
|
|
|
'meta_description' => $meta_description, |
205
|
|
|
]); |
206
|
|
|
$this->pagerender(); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|