Issues (435)

app/Http/Controllers/RssController.php (13 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Controllers\Api\RSS;
6
use App\Models\Category;
7
use App\Models\User;
8
use App\Models\UserDownload;
9
use App\Models\UserRequest;
10
use Illuminate\Http\JsonResponse;
11
use Illuminate\Http\Request;
12
use Illuminate\Support\Arr;
13
use Illuminate\Support\Carbon;
14
15
class RssController extends BasePageController
16
{
17
    /**
18
     * @return JsonResponse|void
19
     *
20
     * @throws \Throwable
21
     */
22
    public function myMoviesRss(Request $request)
23
    {
24
        $rss = new RSS(['Settings' => $this->settings]);
0 ignored issues
show
The call to App\Http\Controllers\Api\RSS::__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

24
        $rss = /** @scrutinizer ignore-call */ new RSS(['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...
25
        $offset = 0;
26
27
        $user = $this->userCheck($request);
28
29
        if (is_object($user)) {
30
            return $user;
31
        }
32
33
        $outputXML = (! ($request->has('o') && $request->input('o') === 'json'));
34
35
        $userNum = ($request->has('num') && is_numeric($request->input('num')) ? abs($request->input('num')) : 0);
36
37
        $relData = $rss->getMyMoviesRss($userNum, $user['user_id'], User::getCategoryExclusionById($user['user_id']));
0 ignored issues
show
It seems like $userNum can also be of type double; however, parameter $limit of App\Http\Controllers\Api\RSS::getMyMoviesRss() does only seem to accept integer, 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

37
        $relData = $rss->getMyMoviesRss(/** @scrutinizer ignore-type */ $userNum, $user['user_id'], User::getCategoryExclusionById($user['user_id']));
Loading history...
38
39
        $rss->output($relData, $user['params'], $outputXML, $offset, 'rss');
40
    }
41
42
    /**
43
     * @return JsonResponse|void
44
     *
45
     * @throws \Throwable
46
     */
47
    public function myShowsRss(Request $request)
48
    {
49
        $rss = new RSS;
50
        $offset = 0;
51
        $user = $this->userCheck($request);
52
        if (is_object($user)) {
53
            return $user;
54
        }
55
        $userAirDate = $request->has('airdate') && is_numeric($request->input('airdate')) ? abs($request->input('airdate')) : -1;
56
        $userNum = ($request->has('num') && is_numeric($request->input('num')) ? abs($request->input('num')) : 0);
57
        $relData = $rss->getShowsRss($userNum, $user['user_id'], User::getCategoryExclusionById($user['user_id']), $userAirDate);
0 ignored issues
show
It seems like $userNum can also be of type double; however, parameter $limit of App\Http\Controllers\Api\RSS::getShowsRss() does only seem to accept integer, 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

57
        $relData = $rss->getShowsRss(/** @scrutinizer ignore-type */ $userNum, $user['user_id'], User::getCategoryExclusionById($user['user_id']), $userAirDate);
Loading history...
It seems like $userAirDate can also be of type double; however, parameter $airDate of App\Http\Controllers\Api\RSS::getShowsRss() does only seem to accept integer, 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

57
        $relData = $rss->getShowsRss($userNum, $user['user_id'], User::getCategoryExclusionById($user['user_id']), /** @scrutinizer ignore-type */ $userAirDate);
Loading history...
58
        $outputXML = (! ($request->has('o') && $request->input('o') === 'json'));
59
60
        $rss->output($relData, $user['params'], $outputXML, $offset, 'rss');
61
    }
62
63
    /**
64
     * @return JsonResponse|void
65
     *
66
     * @throws \Throwable
67
     */
68
    public function fullFeedRss(Request $request)
69
    {
70
        $rss = new RSS;
71
        $offset = 0;
72
        $user = $this->userCheck($request);
73
        if (is_object($user)) {
74
            return $user;
75
        }
76
        $userAirDate = $request->has('airdate') && is_numeric($request->input('airdate')) ? abs($request->input('airdate')) : -1;
77
        $userNum = ($request->has('num') && is_numeric($request->input('num')) ? abs($request->input('num')) : 0);
78
        $userLimit = $request->has('limit') && is_numeric($request->input('limit')) ? $request->input('limit') : 100;
79
        $userShow = $userAnidb = -1;
80
        if ($request->has('show')) {
81
            $userShow = ((int) $request->input('show') === 0 ? -1 : $request->input('show') + 0);
82
        } elseif ($request->has('anidb')) {
83
            $userAnidb = ((int) $request->input('anidb') === 0 ? -1 : $request->input('anidb') + 0);
84
        }
85
        $outputXML = (! ($request->has('o') && $request->input('o') === 'json'));
86
        $relData = $rss->getRss(Arr::wrap(0), $userShow, $userAnidb, $user['user_id'], $userAirDate, $userLimit, $userNum);
0 ignored issues
show
It seems like $userNum can also be of type double; however, parameter $offset of App\Http\Controllers\Api\RSS::getRss() does only seem to accept integer, 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

86
        $relData = $rss->getRss(Arr::wrap(0), $userShow, $userAnidb, $user['user_id'], $userAirDate, $userLimit, /** @scrutinizer ignore-type */ $userNum);
Loading history...
It seems like $userAirDate can also be of type double; however, parameter $airDate of App\Http\Controllers\Api\RSS::getRss() does only seem to accept integer, 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

86
        $relData = $rss->getRss(Arr::wrap(0), $userShow, $userAnidb, $user['user_id'], /** @scrutinizer ignore-type */ $userAirDate, $userLimit, $userNum);
Loading history...
87
        $rss->output($relData, $user['params'], $outputXML, $offset, 'rss');
88
    }
89
90
    /**
91
     * @throws \Exception
92
     */
93
    public function showRssDesc()
94
    {
95
        $rss = new RSS;
96
97
        $firstShow = $rss->getFirstInstance('videos_id', 'releases', 'id');
98
        $firstAni = $rss->getFirstInstance('anidbid', 'releases', 'id');
99
100
        $show = ($firstShow !== null) ? $firstShow->videos_id : 1;
101
        $anidb = ($firstAni !== null) ? $firstAni->anidbid : 1;
102
103
        $catExclusions = $this->userdata->categoryexclusions ?? [];
0 ignored issues
show
The property categoryexclusions does not seem to exist on App\Models\User.
Loading history...
104
105
        $this->viewData = array_merge($this->viewData, [
106
            'show' => $show,
107
            'anidb' => $anidb,
108
            'categorylist' => Category::getCategories(true, $catExclusions),
109
            'parentcategorylist' => Category::getForMenu($catExclusions),
110
            'title' => 'Rss Info',
111
            'meta_title' => 'Rss Nzb Info',
112
            'meta_keywords' => 'view,nzb,description,details,rss,atom',
113
            'meta_description' => 'View information about NNTmux RSS Feeds.',
114
        ]);
115
116
        return view('rss.rssdesc', $this->viewData);
117
    }
118
119
    /**
120
     * @throws \Throwable
121
     */
122
    public function cartRss(Request $request)
123
    {
124
        $rss = new RSS;
125
        $offset = 0;
126
        $user = $this->userCheck($request);
127
        if (is_object($user)) {
128
            return $user;
129
        }
130
        $outputXML = (! ($request->has('o') && $request->input('o') === 'json'));
131
        $userAirDate = $request->has('airdate') && is_numeric($request->input('airdate')) ? abs($request->input('airdate')) : -1;
132
        $userNum = ($request->has('num') && is_numeric($request->input('num')) ? abs($request->input('num')) : 0);
133
        $userLimit = $request->has('limit') && is_numeric($request->input('limit')) ? $request->input('limit') : 100;
134
        $userShow = $userAnidb = -1;
135
        if ($request->has('show')) {
136
            $userShow = ((int) $request->input('show') === 0 ? -1 : $request->input('show') + 0);
137
        } elseif ($request->has('anidb')) {
138
            $userAnidb = ((int) $request->input('anidb') === 0 ? -1 : $request->input('anidb') + 0);
139
        }
140
141
        $relData = $rss->getRss([-2], $userShow, $userAnidb, $user['user_id'], $userAirDate, $userLimit, $userNum);
0 ignored issues
show
It seems like $userAirDate can also be of type double; however, parameter $airDate of App\Http\Controllers\Api\RSS::getRss() does only seem to accept integer, 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

141
        $relData = $rss->getRss([-2], $userShow, $userAnidb, $user['user_id'], /** @scrutinizer ignore-type */ $userAirDate, $userLimit, $userNum);
Loading history...
It seems like $userNum can also be of type double; however, parameter $offset of App\Http\Controllers\Api\RSS::getRss() does only seem to accept integer, 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

141
        $relData = $rss->getRss([-2], $userShow, $userAnidb, $user['user_id'], $userAirDate, $userLimit, /** @scrutinizer ignore-type */ $userNum);
Loading history...
142
        $rss->output($relData, $user['params'], $outputXML, $offset, 'rss');
143
    }
144
145
    /**
146
     * @throws \Throwable
147
     */
148
    public function categoryFeedRss(Request $request)
149
    {
150
        $rss = new RSS;
151
        $offset = 0;
152
        if ($request->missing('id')) {
153
            return response()->json(['error' => 'Category ID is missing'], '403');
154
        }
155
156
        $user = $this->userCheck($request);
157
        if (is_object($user)) {
158
            return $user;
159
        }
160
        $categoryId = explode(',', $request->input('id'));
161
        $userAirDate = $request->has('airdate') && is_numeric($request->input('airdate')) ? abs($request->input('airdate')) : -1;
162
        $userNum = ($request->has('num') && is_numeric($request->input('num')) ? abs($request->input('num')) : 0);
163
        $userLimit = $request->has('limit') && is_numeric($request->input('limit')) ? $request->input('limit') : 100;
164
        $userShow = $userAnidb = -1;
165
        if ($request->has('show')) {
166
            $userShow = ((int) $request->input('show') === 0 ? -1 : $request->input('show') + 0);
167
        } elseif ($request->has('anidb')) {
168
            $userAnidb = ((int) $request->input('anidb') === 0 ? -1 : $request->input('anidb') + 0);
169
        }
170
        $outputXML = (! ($request->has('o') && $request->input('o') === 'json'));
171
        $relData = $rss->getRss($categoryId, $userShow, $userAnidb, $user['user_id'], $userAirDate, $userLimit, $userNum);
0 ignored issues
show
It seems like $userNum can also be of type double; however, parameter $offset of App\Http\Controllers\Api\RSS::getRss() does only seem to accept integer, 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

171
        $relData = $rss->getRss($categoryId, $userShow, $userAnidb, $user['user_id'], $userAirDate, $userLimit, /** @scrutinizer ignore-type */ $userNum);
Loading history...
It seems like $userAirDate can also be of type double; however, parameter $airDate of App\Http\Controllers\Api\RSS::getRss() does only seem to accept integer, 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

171
        $relData = $rss->getRss($categoryId, $userShow, $userAnidb, $user['user_id'], /** @scrutinizer ignore-type */ $userAirDate, $userLimit, $userNum);
Loading history...
172
        $rss->output($relData, $user['params'], $outputXML, $offset, 'rss');
173
    }
174
175
    /**
176
     * @throws \Throwable
177
     */
178
    private function userCheck(Request $request): JsonResponse|array
179
    {
180
        if ($request->missing('api_token')) {
181
            return response()->json(['error' => 'API key is required for viewing the RSS!'], 403);
182
        }
183
184
        $res = User::getByRssToken($request->input('api_token'));
185
186
        if ($res === null) {
187
            return response()->json(['error' => 'Invalid RSS token'], 403);
188
        }
189
190
        $uid = $res['id'];
191
        $rssToken = $res['api_token'];
192
        $maxRequests = $res->role->apirequests;
0 ignored issues
show
The property apirequests does not seem to exist on Spatie\Permission\Models\Role.
Loading history...
193
        $maxDownloads = $res->role->downloadrequests;
0 ignored issues
show
The property downloadrequests does not seem to exist on Spatie\Permission\Models\Role.
Loading history...
194
        $usedRequests = UserRequest::getApiRequests($uid);
195
        $time = UserRequest::whereUsersId($uid)->min('timestamp');
196
        $apiOldestTime = $time !== null ? Carbon::createFromTimeString($time)->toRfc2822String() : '';
197
        $grabTime = UserDownload::whereUsersId($uid)->min('timestamp');
198
        $oldestGrabTime = $grabTime !== null ? Carbon::createFromTimeString($grabTime)->toRfc2822String() : '';
199
200
        if ($res->hasRole('Disabled')) {
201
            return response()->json(['error' => 'Your account is disabled'], 403);
202
        }
203
204
        if ($usedRequests > $maxRequests) {
205
            return response()->json(['error' => 'You have reached your daily limit for API requests!'], 403);
206
        } else {
207
            UserRequest::addApiRequest($rssToken, $request->getRequestUri());
208
        }
209
        $params =
210
            [
211
                'dl' => $request->has('dl') && $request->input('dl') === '1' ? '1' : '0',
212
                'del' => $request->has('del') && $request->input('del') === '1' ? '1' : '0',
213
                'extended' => 1,
214
                'uid' => $uid,
215
                'token' => $rssToken,
216
                'apilimit' => $maxRequests,
217
                'requests' => $usedRequests,
218
                'downloadlimit' => $maxDownloads,
219
                'grabs' => UserDownload::getDownloadRequests($uid),
220
                'oldestapi' => $apiOldestTime,
221
                'oldestgrab' => $oldestGrabTime,
222
            ];
223
224
        return ['user' => $res, 'user_id' => $uid, 'rss_token' => $rssToken, 'max_requests' => $maxRequests, 'params' => $params];
225
    }
226
}
227