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