|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\BasePageController; |
|
6
|
|
|
use App\Models\Category; |
|
7
|
|
|
use App\Models\Release; |
|
8
|
|
|
use App\Models\Settings; |
|
9
|
|
|
use App\Models\User; |
|
10
|
|
|
use Blacklight\SABnzbd; |
|
11
|
|
|
use Blacklight\utility\Utility; |
|
12
|
|
|
use Illuminate\Http\Request; |
|
13
|
|
|
use Spatie\Permission\Models\Role; |
|
14
|
|
|
|
|
15
|
|
|
class AdminSiteController extends BasePageController |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param \Illuminate\Http\Request $request |
|
19
|
|
|
* |
|
20
|
|
|
* @throws \Exception |
|
21
|
|
|
*/ |
|
22
|
|
|
public function edit(Request $request) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->setAdminPrefs(); |
|
25
|
|
|
|
|
26
|
|
|
$meta_title = $title = 'Site Edit'; |
|
27
|
|
|
|
|
28
|
|
|
// set the current action |
|
29
|
|
|
$action = $request->input('action') ?? 'view'; |
|
30
|
|
|
|
|
31
|
|
|
switch ($action) { |
|
32
|
|
|
case 'submit': |
|
33
|
|
|
if ($request->missing('book_reqids')) { |
|
34
|
|
|
$request->merge(['book_reqids' => []]); |
|
35
|
|
|
} |
|
36
|
|
|
$error = ''; |
|
37
|
|
|
$ret = Settings::settingsUpdate($request->all()); |
|
|
|
|
|
|
38
|
|
|
if (\is_int($ret)) { |
|
|
|
|
|
|
39
|
|
|
if ($ret === Settings::ERR_BADUNRARPATH) { |
|
40
|
|
|
$error = 'The unrar path does not point to a valid binary'; |
|
41
|
|
|
} elseif ($ret === Settings::ERR_BADFFMPEGPATH) { |
|
42
|
|
|
$error = 'The ffmpeg path does not point to a valid binary'; |
|
43
|
|
|
} elseif ($ret === Settings::ERR_BADMEDIAINFOPATH) { |
|
44
|
|
|
$error = 'The mediainfo path does not point to a valid binary'; |
|
45
|
|
|
} elseif ($ret === Settings::ERR_BADNZBPATH) { |
|
46
|
|
|
$error = 'The nzb path does not point to a valid directory'; |
|
47
|
|
|
} elseif ($ret === Settings::ERR_DEEPNOUNRAR) { |
|
48
|
|
|
$error = 'Deep password check requires a valid path to unrar binary'; |
|
49
|
|
|
} elseif ($ret === Settings::ERR_BADTMPUNRARPATH) { |
|
50
|
|
|
$error = 'The temp unrar path is not a valid directory'; |
|
51
|
|
|
} elseif ($ret === Settings::ERR_BADLAMEPATH) { |
|
52
|
|
|
$error = 'The lame path is not a valid directory'; |
|
53
|
|
|
} elseif ($ret === Settings::ERR_SABCOMPLETEPATH) { |
|
54
|
|
|
$error = 'The sab complete path is not a valid directory'; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if ($error === '') { |
|
|
|
|
|
|
59
|
|
|
$site = $ret; |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
return redirect('admin/site-edit'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$this->smarty->assign('error', $error); |
|
65
|
|
|
$site = (object) $request->all(); |
|
66
|
|
|
$this->smarty->assign('site', $site); |
|
67
|
|
|
|
|
68
|
|
|
break; |
|
69
|
|
|
case 'view': |
|
70
|
|
|
default: |
|
71
|
|
|
$site = $this->settings; |
|
72
|
|
|
$this->smarty->assign('site', $site); |
|
|
|
|
|
|
73
|
|
|
$this->smarty->assign('settings', Settings::toTree()); |
|
74
|
|
|
break; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$this->smarty->assign('yesno_ids', [1, 0]); |
|
78
|
|
|
$this->smarty->assign('yesno_names', ['Yes', 'No']); |
|
79
|
|
|
|
|
80
|
|
|
$this->smarty->assign('passwd_ids', [1, 0]); |
|
81
|
|
|
$this->smarty->assign('passwd_names', ['Deep (requires unrar)', 'None']); |
|
82
|
|
|
|
|
83
|
|
|
/*0 = English, 2 = Danish, 3 = French, 1 = German*/ |
|
84
|
|
|
$this->smarty->assign('langlist_ids', [0, 2, 3, 1]); |
|
85
|
|
|
$this->smarty->assign('langlist_names', ['English', 'Danish', 'French', 'German']); |
|
86
|
|
|
|
|
87
|
|
|
$this->smarty->assign( |
|
88
|
|
|
'imdblang_ids', |
|
89
|
|
|
[ |
|
90
|
|
|
'en', 'da', 'nl', 'fi', 'fr', 'de', 'it', 'tlh', 'no', 'po', 'ru', 'es', |
|
91
|
|
|
'sv', |
|
92
|
|
|
] |
|
93
|
|
|
); |
|
94
|
|
|
$this->smarty->assign( |
|
95
|
|
|
'imdblang_names', |
|
96
|
|
|
[ |
|
97
|
|
|
'English', 'Danish', 'Dutch', 'Finnish', 'French', 'German', 'Italian', |
|
98
|
|
|
'Klingon', 'Norwegian', 'Polish', 'Russian', 'Spanish', 'Swedish', |
|
99
|
|
|
] |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
$this->smarty->assign('sabintegrationtype_ids', [SABnzbd::INTEGRATION_TYPE_USER, SABnzbd::INTEGRATION_TYPE_NONE]); |
|
103
|
|
|
$this->smarty->assign('sabintegrationtype_names', ['User', 'None (Off)']); |
|
104
|
|
|
|
|
105
|
|
|
$this->smarty->assign('newgroupscan_names', ['Days', 'Posts']); |
|
106
|
|
|
|
|
107
|
|
|
$this->smarty->assign('registerstatus_ids', [Settings::REGISTER_STATUS_OPEN, Settings::REGISTER_STATUS_INVITE, Settings::REGISTER_STATUS_CLOSED]); |
|
108
|
|
|
$this->smarty->assign('registerstatus_names', ['Open', 'Invite', 'Closed']); |
|
109
|
|
|
|
|
110
|
|
|
$this->smarty->assign('passworded_ids', [0, 1]); |
|
111
|
|
|
$this->smarty->assign('passworded_names', [ |
|
112
|
|
|
'Hide passworded', |
|
113
|
|
|
'Show everything', |
|
114
|
|
|
]); |
|
115
|
|
|
|
|
116
|
|
|
$this->smarty->assign('lookuplanguage_iso', ['en', 'de', 'es', 'fr', 'it', 'nl', 'pt', 'sv']); |
|
117
|
|
|
$this->smarty->assign('lookuplanguage_names', ['English', 'Deutsch', 'Español', 'Français', 'Italiano', 'Nederlands', 'Português', 'Svenska']); |
|
118
|
|
|
|
|
119
|
|
|
$this->smarty->assign('imdb_urls', [0, 1]); |
|
120
|
|
|
$this->smarty->assign('imdburl_names', ['imdb.com', 'akas.imdb.com']); |
|
121
|
|
|
|
|
122
|
|
|
$this->smarty->assign('lookupbooks_ids', [0, 1, 2]); |
|
123
|
|
|
$this->smarty->assign('lookupbooks_names', ['Disabled', 'Lookup All Books', 'Lookup Renamed Books']); |
|
124
|
|
|
|
|
125
|
|
|
$this->smarty->assign('lookupgames_ids', [0, 1, 2]); |
|
126
|
|
|
$this->smarty->assign('lookupgames_names', ['Disabled', 'Lookup All Consoles', 'Lookup Renamed Consoles']); |
|
127
|
|
|
|
|
128
|
|
|
$this->smarty->assign('lookupmusic_ids', [0, 1, 2]); |
|
129
|
|
|
$this->smarty->assign('lookupmusic_names', ['Disabled', 'Lookup All Music', 'Lookup Renamed Music']); |
|
130
|
|
|
|
|
131
|
|
|
$this->smarty->assign('lookupmovies_ids', [0, 1, 2]); |
|
132
|
|
|
$this->smarty->assign('lookupmovies_names', ['Disabled', 'Lookup All Movies', 'Lookup Renamed Movies']); |
|
133
|
|
|
|
|
134
|
|
|
$this->smarty->assign('lookuptv_ids', [0, 1, 2]); |
|
135
|
|
|
$this->smarty->assign('lookuptv_names', ['Disabled', 'Lookup All TV', 'Lookup Renamed TV']); |
|
136
|
|
|
|
|
137
|
|
|
$this->smarty->assign('lookup_reqids_ids', [0, 1, 2]); |
|
138
|
|
|
$this->smarty->assign('lookup_reqids_names', ['Disabled', 'Lookup Request IDs', 'Lookup Request IDs Threaded']); |
|
139
|
|
|
|
|
140
|
|
|
$this->smarty->assign('coversPath', NN_COVERS); |
|
141
|
|
|
|
|
142
|
|
|
// return a list of audiobooks, mags, ebooks, technical and foreign books |
|
143
|
|
|
$result = Category::query()->whereIn('id', [Category::MUSIC_AUDIOBOOK, Category::BOOKS_MAGAZINES, Category::BOOKS_TECHNICAL, Category::BOOKS_FOREIGN])->get(['id', 'title']); |
|
144
|
|
|
|
|
145
|
|
|
// setup the display lists for these categories, this could have been static, but then if names changed they would be wrong |
|
146
|
|
|
$book_reqids_ids = []; |
|
147
|
|
|
$book_reqids_names = []; |
|
148
|
|
|
foreach ($result as $bookcategory) { |
|
149
|
|
|
$book_reqids_ids[] = $bookcategory['id']; |
|
150
|
|
|
$book_reqids_names[] = $bookcategory['title']; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
// convert from a string array to an int array as we want to use int |
|
154
|
|
|
$book_reqids_ids = array_map(function ($value) { |
|
155
|
|
|
return (int) $value; |
|
156
|
|
|
}, $book_reqids_ids); |
|
157
|
|
|
$this->smarty->assign('book_reqids_ids', $book_reqids_ids); |
|
158
|
|
|
$this->smarty->assign('book_reqids_names', $book_reqids_names); |
|
159
|
|
|
|
|
160
|
|
|
// convert from a list to an array as we need to use an array, but teh Settings table only saves strings |
|
161
|
|
|
$books_selected = explode(',', Settings::settingValue('..book_reqids')); |
|
162
|
|
|
|
|
163
|
|
|
// convert from a string array to an int array |
|
164
|
|
|
$books_selected = array_map(function ($value) { |
|
165
|
|
|
return (int) $value; |
|
166
|
|
|
}, $books_selected); |
|
167
|
|
|
$this->smarty->assign('book_reqids_selected', $books_selected); |
|
168
|
|
|
|
|
169
|
|
|
$this->smarty->assign('themelist', Utility::getThemesList()); |
|
170
|
|
|
|
|
171
|
|
|
if (strpos(env('NNTP_SERVER'), 'astra') === false) { |
|
172
|
|
|
$this->smarty->assign('compress_headers_warning', 'compress_headers_warning'); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
$content = $this->smarty->fetch('site-edit.tpl'); |
|
|
|
|
|
|
176
|
|
|
|
|
177
|
|
|
$this->smarty->assign(compact('title', 'meta_title', 'content')); |
|
178
|
|
|
|
|
179
|
|
|
$this->adminrender(); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @throws \Exception |
|
184
|
|
|
*/ |
|
185
|
|
|
public function stats() |
|
186
|
|
|
{ |
|
187
|
|
|
$this->setAdminPrefs(); |
|
188
|
|
|
|
|
189
|
|
|
$meta_title = $title = 'Site Stats'; |
|
190
|
|
|
|
|
191
|
|
|
$topgrabs = User::getTopGrabbers(); |
|
192
|
|
|
$this->smarty->assign('topgrabs', $topgrabs); |
|
193
|
|
|
|
|
194
|
|
|
$topdownloads = Release::getTopDownloads(); |
|
195
|
|
|
$this->smarty->assign('topdownloads', $topdownloads); |
|
196
|
|
|
|
|
197
|
|
|
$topcomments = Release::getTopComments(); |
|
198
|
|
|
$this->smarty->assign('topcomments', $topcomments); |
|
199
|
|
|
|
|
200
|
|
|
$recent = Category::getRecentlyAdded(); |
|
201
|
|
|
$this->smarty->assign('recent', $recent); |
|
202
|
|
|
|
|
203
|
|
|
$usersbymonth = User::getUsersByMonth(); |
|
204
|
|
|
$this->smarty->assign('usersbymonth', $usersbymonth); |
|
205
|
|
|
|
|
206
|
|
|
$usersbyrole = Role::query()->select(['name'])->withCount('users')->groupBy('name')->having('users_count', '>', 0)->orderBy('users_count', 'desc')->get(); |
|
207
|
|
|
$this->smarty->assign('usersbyrole', $usersbyrole); |
|
208
|
|
|
$this->smarty->assign('totusers', 0); |
|
209
|
|
|
$this->smarty->assign('totrusers', 0); |
|
210
|
|
|
|
|
211
|
|
|
$content = $this->smarty->fetch('site-stats.tpl'); |
|
212
|
|
|
|
|
213
|
|
|
$this->smarty->assign(compact('title', 'meta_title', 'content')); |
|
214
|
|
|
|
|
215
|
|
|
$this->adminrender(); |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.