Files
newznab-tmux/app/Http/Controllers/MovieController.php
T
2025-07-01 13:59:57 +02:00

151 lines
6.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Category;
use Blacklight\Movie;
use Illuminate\Http\Request;
class MovieController extends BasePageController
{
/**
* @throws \Exception
*/
public function showMovies(Request $request, string $id = ''): void
{
$this->setPreferences();
$movie = new Movie(['Settings' => $this->settings]);
$moviecats = Category::getChildren(Category::MOVIE_ROOT)->map(function ($mcat) {
return ['id' => $mcat->id, 'title' => $mcat->title];
});
$category = $request->has('imdb') ? -1 : ($request->input('t', Category::MOVIE_ROOT));
if ($id && $moviecats->pluck('title')->contains($id)) {
$cat = Category::where(['title' => $id, 'root_categories_id' => Category::MOVIE_ROOT])->first(['id']);
$category = $cat->id ?? Category::MOVIE_ROOT;
}
$this->smarty->assign('cpapi', $this->userdata->cp_api);
$this->smarty->assign('cpurl', $this->userdata->cp_url);
$catarray = $category !== -1 ? [$category] : [];
$this->smarty->assign('catlist', $moviecats);
$this->smarty->assign('category', $category);
$this->smarty->assign('categorytitle', $id);
$page = $request->input('page', 1);
$offset = ($page - 1) * config('nntmux.items_per_cover_page');
$orderby = $request->input('ob', '');
$ordering = $movie->getMovieOrdering();
if (! in_array($orderby, $ordering, false)) {
$orderby = '';
}
$rslt = $movie->getMovieRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, -1, $this->userdata->categoryexclusions);
$results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query());
// Optimize data processing - do heavy lifting in backend
$movies = $results->map(function ($result) {
// Pre-process exploded data to avoid template overhead
$result['genre'] = makeFieldLinks($result, 'genre', 'movies');
$result['actors'] = makeFieldLinks($result, 'actors', 'movies');
$result['director'] = makeFieldLinks($result, 'director', 'movies');
$result['languages'] = explode(', ', $result['language']);
// Pre-explode release data to reduce template processing
$result['release_ids'] = explode(',', $result['grp_release_id']);
$result['release_guids'] = explode(',', $result['grp_release_guid']);
$result['release_nfoids'] = explode(',', $result['grp_release_nfoid']);
$result['release_groups'] = explode(',', $result['grp_release_grpname']);
$result['release_names'] = explode('#', $result['grp_release_name']);
$result['release_postdates'] = explode(',', $result['grp_release_postdate']);
$result['release_sizes'] = explode(',', $result['grp_release_size']);
$result['release_totalparts'] = explode(',', $result['grp_release_totalparts']);
$result['release_comments'] = explode(',', $result['grp_release_comments']);
$result['release_grabs'] = explode(',', $result['grp_release_grabs']);
$result['release_failed'] = explode(',', $result['grp_release_failed']);
$result['release_password'] = explode(',', $result['grp_release_password']);
$result['release_innerfiles'] = explode(',', $result['grp_rarinnerfilecount']);
$result['release_haspreview'] = explode(',', $result['grp_haspreview']);
// Pre-process category data
if (isset($result['category_name'])) {
$result['category_split'] = explode('>', $result['category_name']);
}
return $result;
});
$this->smarty->assign('title', stripslashes($request->input('title', '')));
$this->smarty->assign('actors', stripslashes($request->input('actors', '')));
$this->smarty->assign('director', stripslashes($request->input('director', '')));
$this->smarty->assign('ratings', range(1, 9));
$this->smarty->assign('rating', $request->input('rating', ''));
$this->smarty->assign('genres', $movie->getGenres());
$this->smarty->assign('genre', $request->input('genre', ''));
$years = range(1903, now()->addYear()->year);
rsort($years);
$this->smarty->assign('years', $years);
$this->smarty->assign('year', $request->input('year', ''));
$catname = $category === -1 ? 'All' : Category::find($category) ?? 'All';
$this->smarty->assign('catname', $catname);
$this->smarty->assign([
'resultsadd' => $movies,
'results' => $results,
'covgroup' => 'movies',
]);
$meta_title = 'Browse Movies';
$meta_keywords = 'browse,nzb,description,details';
$meta_description = 'Browse for Movies';
$content = $request->has('imdb') ? $this->smarty->fetch('viewmoviefull.tpl') : $this->smarty->fetch('movies.tpl');
$this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description'));
$this->pagerender();
}
/**
* @return \Illuminate\Http\JsonResponse|void
*/
public function showTrailer(Request $request)
{
$movie = new Movie;
if ($request->has('id') && ctype_digit($request->input('id'))) {
$mov = $movie->getMovieInfo($request->input('id'));
if (! $mov) {
return response()->json(['message' => 'There is no trailer for this movie.'], 404);
}
$this->smarty->assign('movie', $mov);
$title = 'Info for '.$mov['title'];
$meta_title = '';
$meta_keywords = '';
$meta_description = '';
$this->smarty->registerPlugin('modifier', 'ss', 'stripslashes');
$modal = false;
if ($request->has('modal')) {
$modal = true;
$this->smarty->assign('modal', true);
}
$content = $this->smarty->fetch('viewmovietrailer.tpl');
if ($modal) {
echo $content;
} else {
$this->smarty->assign(compact('content', 'title', 'meta_title', 'meta_keywords', 'meta_description'));
$this->pagerender();
}
}
}
}