Issues (435)

app/Http/Controllers/MovieController.php (7 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Category;
6
use Blacklight\Movie;
7
use Illuminate\Http\Request;
8
9
class MovieController extends BasePageController
10
{
11
    /**
12
     * @throws \Exception
13
     */
14
    public function showMovies(Request $request, string $id = '')
15
    {
16
        $movie = new Movie(['Settings' => $this->settings]);
0 ignored issues
show
The call to Blacklight\Movie::__construct() has too many arguments starting with array('Settings' => $this->settings). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

16
        $movie = /** @scrutinizer ignore-call */ new Movie(['Settings' => $this->settings]);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
17
18
        $moviecats = Category::getChildren(Category::MOVIE_ROOT)->map(function ($mcat) {
19
            return ['id' => $mcat->id, 'title' => $mcat->title];
20
        });
21
22
        $category = $request->has('imdb') ? -1 : ($request->input('t', Category::MOVIE_ROOT));
23
        if ($id && $moviecats->pluck('title')->contains($id)) {
24
            $cat = Category::where(['title' => $id, 'root_categories_id' => Category::MOVIE_ROOT])->first(['id']);
25
            $category = $cat->id ?? Category::MOVIE_ROOT;
26
        }
27
28
        $catarray = $category !== -1 ? [$category] : [];
29
30
        $page = $request->input('page', 1);
31
        $offset = ($page - 1) * config('nntmux.items_per_cover_page');
32
33
        $orderby = $request->input('ob', '');
34
        $ordering = $movie->getMovieOrdering();
35
        if (! in_array($orderby, $ordering, false)) {
36
            $orderby = '';
37
        }
38
39
        $rslt = $movie->getMovieRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, -1, $this->userdata->categoryexclusions);
0 ignored issues
show
The property categoryexclusions does not seem to exist on App\Models\User.
Loading history...
40
        $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query());
41
42
        $movies = $results->map(function ($result) {
43
            $result['genre'] = makeFieldLinks($result, 'genre', 'movies');
44
            $result['actors'] = makeFieldLinks($result, 'actors', 'movies');
45
            $result['director'] = makeFieldLinks($result, 'director', 'movies');
46
            $result['languages'] = explode(', ', $result['language']);
47
48
            // Add cover image URL using helper function
49
            $result['cover'] = getReleaseCover($result);
50
51
            return $result;
52
        });
53
54
        $years = range(1903, now()->addYear()->year);
55
        rsort($years);
56
57
        $catname = $category === -1 ? 'All' : Category::find($category) ?? 'All';
58
59
        $this->viewData = array_merge($this->viewData, [
60
            'cpapi' => $this->userdata->cp_api,
61
            'cpurl' => $this->userdata->cp_url,
62
            'catlist' => $moviecats,
63
            'category' => $category,
64
            'categorytitle' => $id,
65
            'title' => stripslashes($request->input('title', '')),
66
            'actors' => stripslashes($request->input('actors', '')),
67
            'director' => stripslashes($request->input('director', '')),
68
            'ratings' => range(1, 9),
69
            'rating' => $request->input('rating', ''),
70
            'genres' => $movie->getGenres(),
71
            'genre' => $request->input('genre', ''),
72
            'years' => $years,
73
            'year' => $request->input('year', ''),
74
            'catname' => $catname,
75
            'resultsadd' => $movies,
76
            'results' => $results,
77
            'covgroup' => 'movies',
78
            'meta_title' => 'Browse Movies',
79
            'meta_keywords' => 'browse,nzb,description,details',
80
            'meta_description' => 'Browse for Movies',
81
        ]);
82
83
        // Return the appropriate view
84
        $viewName = $request->has('imdb') ? 'movies.viewmoviefull' : 'movies.index';
85
86
        return view($viewName, $this->viewData);
87
    }
88
89
    /**
90
     * Show a single movie with all its releases
91
     *
92
     * @throws \Exception
93
     */
94
    public function showMovie(Request $request, string $imdbid)
95
    {
96
        $movie = new Movie(['Settings' => $this->settings]);
0 ignored issues
show
The call to Blacklight\Movie::__construct() has too many arguments starting with array('Settings' => $this->settings). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

96
        $movie = /** @scrutinizer ignore-call */ new Movie(['Settings' => $this->settings]);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
97
98
        // Get movie info
99
        $movieInfo = $movie->getMovieInfo($imdbid);
100
101
        if (! $movieInfo) {
0 ignored issues
show
$movieInfo is of type App\Models\MovieInfo, thus it always evaluated to true.
Loading history...
102
            return redirect()->route('Movies')->with('error', 'Movie not found');
103
        }
104
105
        // Get all releases for this movie
106
        $rslt = $movie->getMovieRange(1, [], 0, 1000, '', -1, $this->userdata->categoryexclusions);
0 ignored issues
show
The property categoryexclusions does not seem to exist on App\Models\User.
Loading history...
107
108
        // Filter to only this movie's IMDB ID
109
        $movieData = collect($rslt)->firstWhere('imdbid', $imdbid);
0 ignored issues
show
It seems like $rslt can also be of type array; however, parameter $value of collect() does only seem to accept Illuminate\Contracts\Support\Arrayable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

109
        $movieData = collect(/** @scrutinizer ignore-type */ $rslt)->firstWhere('imdbid', $imdbid);
Loading history...
110
111
        if (! $movieData) {
112
            return redirect()->route('Movies')->with('error', 'No releases found for this movie');
113
        }
114
115
        // Process movie data - ensure we handle both objects and arrays
116
        if (is_object($movieInfo)) {
117
            // If it's an Eloquent model, use toArray()
118
            if (method_exists($movieInfo, 'toArray')) {
119
                $movieArray = $movieInfo->toArray();
120
            } else {
121
                $movieArray = get_object_vars($movieInfo);
122
            }
123
        } else {
124
            $movieArray = $movieInfo;
125
        }
126
127
        // Ensure we have at least the basic fields
128
        if (empty($movieArray['title'])) {
129
            $movieArray['title'] = 'Unknown Title';
130
        }
131
        if (empty($movieArray['imdbid'])) {
132
            $movieArray['imdbid'] = $imdbid;
133
        }
134
135
        // Only process fields if they exist and are not empty
136
        if (! empty($movieArray['genre'])) {
137
            $movieArray['genre'] = makeFieldLinks($movieArray, 'genre', 'movies');
138
        }
139
        if (! empty($movieArray['actors'])) {
140
            $movieArray['actors'] = makeFieldLinks($movieArray, 'actors', 'movies');
141
        }
142
        if (! empty($movieArray['director'])) {
143
            $movieArray['director'] = makeFieldLinks($movieArray, 'director', 'movies');
144
        }
145
146
        // Add cover image URL using helper function
147
        $movieArray['cover'] = getReleaseCover($movieArray);
148
149
        // Process all releases
150
        $releaseNames = isset($movieData->grp_release_name) ? explode('#', $movieData->grp_release_name) : [];
151
        $releaseSizes = isset($movieData->grp_release_size) ? explode(',', $movieData->grp_release_size) : [];
152
        $releaseGuids = isset($movieData->grp_release_guid) ? explode(',', $movieData->grp_release_guid) : [];
153
        $releasePostDates = isset($movieData->grp_release_postdate) ? explode(',', $movieData->grp_release_postdate) : [];
154
        $releaseAddDates = isset($movieData->grp_release_adddate) ? explode(',', $movieData->grp_release_adddate) : [];
155
156
        $releases = [];
157
        foreach ($releaseNames as $index => $releaseName) {
158
            if ($releaseName && isset($releaseGuids[$index])) {
159
                $releases[] = [
160
                    'name' => $releaseName,
161
                    'guid' => $releaseGuids[$index],
162
                    'size' => $releaseSizes[$index] ?? 0,
163
                    'postdate' => $releasePostDates[$index] ?? null,
164
                    'adddate' => $releaseAddDates[$index] ?? null,
165
                ];
166
            }
167
        }
168
169
        $this->viewData = array_merge($this->viewData, [
170
            'movie' => $movieArray,
171
            'releases' => $releases,
172
            'meta_title' => ($movieArray['title'] ?? 'Movie').' - Movie Details',
173
            'meta_keywords' => 'movie,details,releases',
174
            'meta_description' => 'View all releases for '.($movieArray['title'] ?? 'this movie'),
175
        ]);
176
177
        return view('movies.viewmoviefull', $this->viewData);
178
    }
179
180
    /**
181
     * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
182
     */
183
    public function showTrailer(Request $request)
184
    {
185
        $movie = new Movie;
186
187
        if ($request->has('id') && ctype_digit($request->input('id'))) {
188
            $mov = $movie->getMovieInfo($request->input('id'));
189
190
            if (! $mov) {
0 ignored issues
show
$mov is of type App\Models\MovieInfo, thus it always evaluated to true.
Loading history...
191
                return response()->json(['message' => 'There is no trailer for this movie.'], 404);
192
            }
193
194
            $modal = $request->has('modal');
195
196
            $viewData = [
197
                'movie' => $mov,
198
            ];
199
200
            // Return different views for modal vs full page
201
            if ($modal) {
202
                return view('movies.trailer-modal', $viewData);
203
            }
204
205
            $this->viewData = array_merge($this->viewData, [
206
                'movie' => $mov,
207
                'title' => 'Info for '.$mov['title'],
208
                'meta_title' => '',
209
                'meta_keywords' => '',
210
                'meta_description' => '',
211
            ]);
212
213
            return view('movies.viewmovietrailer', $this->viewData);
214
        }
215
216
        return response()->json(['message' => 'Invalid movie ID.'], 400);
217
    }
218
}
219