mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 17:28:55 +00:00
87c6e5d64f
[ci skip] [skip ci]
213 lines
8.5 KiB
PHP
213 lines
8.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Blacklight\Movie;
|
|
use App\Models\Category;
|
|
use App\Models\Settings;
|
|
use Blacklight\Releases;
|
|
use App\Models\UserMovie;
|
|
use Illuminate\Http\Request;
|
|
|
|
class MyMoviesController extends BasePageController
|
|
{
|
|
/**
|
|
* @param \Illuminate\Http\Request $request
|
|
*
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
* @throws \Exception
|
|
*/
|
|
public function show(Request $request)
|
|
{
|
|
$this->setPrefs();
|
|
$mv = new Movie(['Settings' => $this->settings]);
|
|
|
|
$action = $request->input('id') ?? '';
|
|
$imdbid = $request->input('imdb') ?? '';
|
|
|
|
if ($request->has('from')) {
|
|
$this->smarty->assign('from', WWW_TOP.$request->input('from'));
|
|
} else {
|
|
$this->smarty->assign('from', WWW_TOP.'/mymovies');
|
|
}
|
|
|
|
switch ($action) {
|
|
case 'delete':
|
|
$movie = UserMovie::getMovie($this->userdata->id, $imdbid);
|
|
if (! $movie) {
|
|
return redirect('/mymovies');
|
|
}
|
|
UserMovie::delMovie($this->userdata->id, $imdbid);
|
|
if ($request->has('from')) {
|
|
header('Location:'.WWW_TOP.$request->input('from'));
|
|
} else {
|
|
return redirect('/mymovies');
|
|
}
|
|
|
|
break;
|
|
case 'add':
|
|
case 'doadd':
|
|
$movie = UserMovie::getMovie($this->userdata->id, $imdbid);
|
|
if ($movie) {
|
|
return redirect('/mymovies');
|
|
}
|
|
|
|
$movie = $mv->getMovieInfo($imdbid);
|
|
if (! $movie) {
|
|
return redirect('/mymovies');
|
|
}
|
|
|
|
if ($action === 'doadd') {
|
|
$category = ($request->has('category') && \is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : [];
|
|
UserMovie::addMovie($this->userdata->id, str_pad($imdbid, 7, '0', STR_PAD_LEFT), $category);
|
|
if ($request->has('from')) {
|
|
return redirect($request->input('from'));
|
|
}
|
|
|
|
return redirect('/mymovies');
|
|
}
|
|
|
|
$tmpcats = Category::getChildren(Category::MOVIE_ROOT);
|
|
$categories = [];
|
|
foreach ($tmpcats as $c) {
|
|
// If MOVIE WEB-DL categorization is disabled, don't include it as an option
|
|
if ((int) $c['id'] === Category::MOVIE_WEBDL && (int) Settings::settingValue('indexer.categorise.catwebdl') === 0) {
|
|
continue;
|
|
}
|
|
$categories[$c['id']] = $c['title'];
|
|
}
|
|
$this->smarty->assign('type', 'add');
|
|
$this->smarty->assign('cat_ids', array_keys($categories));
|
|
$this->smarty->assign('cat_names', $categories);
|
|
$this->smarty->assign('cat_selected', []);
|
|
$this->smarty->assign('imdbid', $imdbid);
|
|
$this->smarty->assign('movie', $movie);
|
|
$content = $this->smarty->fetch('mymovies-add.tpl');
|
|
$this->smarty->assign('content', $content);
|
|
$this->pagerender();
|
|
break;
|
|
case 'edit':
|
|
case 'doedit':
|
|
$movie = UserMovie::getMovie($this->userdata->id, $imdbid);
|
|
|
|
if (! $movie) {
|
|
return redirect('/mymovies');
|
|
}
|
|
|
|
if ($action === 'doedit') {
|
|
$category = ($request->has('category') && \is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : [];
|
|
UserMovie::updateMovie($this->userdata->id, $imdbid, $category);
|
|
if ($request->has('from')) {
|
|
return redirect($request->input('from'));
|
|
}
|
|
|
|
return redirect('mymovies');
|
|
}
|
|
|
|
$tmpcats = Category::getChildren(Category::MOVIE_ROOT);
|
|
$categories = [];
|
|
foreach ($tmpcats as $c) {
|
|
$categories[$c['id']] = $c['title'];
|
|
}
|
|
|
|
$this->smarty->assign('type', 'edit');
|
|
$this->smarty->assign('cat_ids', array_keys($categories));
|
|
$this->smarty->assign('cat_names', $categories);
|
|
$this->smarty->assign('cat_selected', explode('|', $movie['categories']));
|
|
$this->smarty->assign('imdbid', $imdbid);
|
|
$this->smarty->assign('movie', $movie);
|
|
$content = $this->smarty->fetch('mymovies-add.tpl');
|
|
$this->smarty->assign('content', $content);
|
|
$this->pagerender();
|
|
break;
|
|
case 'browse':
|
|
|
|
$title = 'Browse My Movies';
|
|
$meta_title = 'My Movies';
|
|
$meta_keywords = 'search,add,to,cart,nzb,description,details';
|
|
$meta_description = 'Browse Your Movies';
|
|
|
|
$page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1;
|
|
|
|
$offset = ($page - 1) * config('nntmux.items_per_cover_page');
|
|
|
|
$movies = UserMovie::getMovies($this->userdata->id);
|
|
$categories = $movie = [];
|
|
foreach ($movies as $moviek => $movie) {
|
|
$showcats = explode('|', $movie['categories']);
|
|
if (\is_array($showcats) && \count($showcats) > 0) {
|
|
$catarr = [];
|
|
foreach ($showcats as $scat) {
|
|
if (! empty($scat)) {
|
|
$catarr[] = $categories[$scat];
|
|
}
|
|
}
|
|
$movie['categoryNames'] = implode(', ', $catarr);
|
|
} else {
|
|
$movie['categoryNames'] = '';
|
|
}
|
|
}
|
|
|
|
$ordering = (new Releases(['Settings' => $this->settings]))->getBrowseOrdering();
|
|
|
|
$page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1;
|
|
|
|
$results = $mv->getMovieRange($page, $movie['categoryNames'], $offset, config('nntmux.items_per_cover_page'), $ordering, -1, $this->userdata['categoryexclusions']);
|
|
|
|
$this->smarty->assign('covgroup', '');
|
|
|
|
foreach ($ordering as $ordertype) {
|
|
$this->smarty->assign('orderby'.$ordertype, WWW_TOP.'/mymovies/browse?ob='.$ordertype.'&offset=0');
|
|
}
|
|
|
|
$this->smarty->assign('lastvisit', $this->userdata['lastlogin']);
|
|
|
|
$this->smarty->assign('results', $results);
|
|
|
|
$this->smarty->assign('movies', true);
|
|
|
|
$content = $this->smarty->fetch('browse.tpl');
|
|
$this->smarty->assign(compact('content', 'title', 'meta_title', 'meta_keywords', 'meta_description'));
|
|
$this->pagerender();
|
|
break;
|
|
default:
|
|
|
|
$title = 'My Movies';
|
|
$meta_title = 'My Movies';
|
|
$meta_keywords = 'search,add,to,cart,nzb,description,details';
|
|
$meta_description = 'Manage Your Movies';
|
|
|
|
$tmpcats = Category::getChildren(Category::MOVIE_ROOT);
|
|
$categories = [];
|
|
foreach ($tmpcats as $c) {
|
|
$categories[$c['id']] = $c['title'];
|
|
}
|
|
|
|
$movies = UserMovie::getMovies($this->userdata->id);
|
|
$results = [];
|
|
foreach ($movies as $moviek => $movie) {
|
|
$showcats = explode('|', $movie['categories']);
|
|
if (\is_array($showcats) && \count($showcats) > 0) {
|
|
$catarr = [];
|
|
foreach ($showcats as $scat) {
|
|
if (! empty($scat)) {
|
|
$catarr[] = $categories[$scat];
|
|
}
|
|
}
|
|
$movie['categoryNames'] = implode(', ', $catarr);
|
|
} else {
|
|
$movie['categoryNames'] = '';
|
|
}
|
|
|
|
$results[$moviek] = $movie;
|
|
}
|
|
$this->smarty->assign('movies', $results);
|
|
|
|
$content = $this->smarty->fetch('mymovies.tpl');
|
|
$this->smarty->assign(compact('content', 'title', 'meta_title', 'meta_keywords', 'meta_description'));
|
|
$this->pagerender();
|
|
break;
|
|
}
|
|
}
|
|
}
|