|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Routing\Controllers\HasMiddleware; |
|
6
|
|
|
use Illuminate\Routing\Controllers\Middleware; |
|
7
|
|
|
use App\Events\UserLoggedIn; |
|
8
|
|
|
use App\Models\Category; |
|
9
|
|
|
use App\Models\Settings; |
|
10
|
|
|
use App\Models\User; |
|
11
|
|
|
use Blacklight\Contents; |
|
|
|
|
|
|
12
|
|
|
use Illuminate\Http\Request; |
|
13
|
|
|
use Illuminate\Pagination\LengthAwarePaginator; |
|
14
|
|
|
use Illuminate\Support\Arr; |
|
15
|
|
|
use Illuminate\Support\Facades\Auth; |
|
16
|
|
|
use Illuminate\View\View; |
|
17
|
|
|
|
|
18
|
|
|
class BasePageController extends Controller implements HasMiddleware |
|
19
|
|
|
{ |
|
20
|
|
|
public Settings $settings; |
|
21
|
|
|
|
|
22
|
|
|
public string $title = ''; |
|
23
|
|
|
|
|
24
|
|
|
public string $content = ''; |
|
25
|
|
|
|
|
26
|
|
|
public string $meta_keywords = ''; |
|
27
|
|
|
|
|
28
|
|
|
public string $meta_title = ''; |
|
29
|
|
|
|
|
30
|
|
|
public string $meta_description = ''; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Current page the user is browsing. ie browse. |
|
34
|
|
|
*/ |
|
35
|
|
|
public string $page = ''; |
|
36
|
|
|
|
|
37
|
|
|
public string $page_template = ''; |
|
38
|
|
|
|
|
39
|
|
|
public User $userdata; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* User's theme. |
|
43
|
|
|
*/ |
|
44
|
|
|
protected string $theme = 'Gentele'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var \Illuminate\Foundation\Application|mixed |
|
48
|
|
|
*/ |
|
49
|
|
|
public mixed $smarty; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* BasePageController constructor. |
|
53
|
|
|
* |
|
54
|
|
|
* @throws \Exception |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct() |
|
57
|
|
|
{ |
|
58
|
|
|
|
|
59
|
|
|
// Buffer settings/DB connection. |
|
60
|
|
|
$this->settings = new Settings; |
|
61
|
|
|
$this->smarty = app('smarty.view'); |
|
62
|
|
|
|
|
63
|
|
|
foreach (Arr::get(config('ytake-laravel-smarty'), 'plugins_paths', []) as $plugins) { |
|
64
|
|
|
$this->smarty->addPluginsDir($plugins); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$this->smarty->assign('serverroot', url('/')); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public static function middleware(): array |
|
71
|
|
|
{ |
|
72
|
|
|
return [ |
|
73
|
|
|
new Middleware(['auth', 'web', '2fa'], except: ['api', 'contact', 'showContactForm', 'callback', 'getNzb', 'terms', 'capabilities', 'movie', 'apiSearch', 'tv', 'details', 'failed', 'showRssDesc', 'fullFeedRss', 'categoryFeedRss', 'cartRss', 'myMoviesRss', 'myShowsRss', 'release', 'reset', 'showLinkRequestForm']), |
|
74
|
|
|
]; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function paginate($query, $totalCount, $items, $page, $path, $reqQuery): LengthAwarePaginator |
|
78
|
|
|
{ |
|
79
|
|
|
return new LengthAwarePaginator($query, $totalCount, $items, $page, ['path' => $path, 'query' => $reqQuery]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @throws \Exception |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function setPreferences(): void |
|
86
|
|
|
{ |
|
87
|
|
|
if (Auth::check()) { |
|
88
|
|
|
$this->userdata = User::find(Auth::id()); |
|
89
|
|
|
$this->setUserPreferences(); |
|
90
|
|
|
} else { |
|
91
|
|
|
// Tell Smarty which directories to use for templates |
|
92
|
|
|
$this->smarty->setTemplateDir([ |
|
93
|
|
|
'user' => config('ytake-laravel-smarty.template_path').'/Gentele', |
|
94
|
|
|
'shared' => config('ytake-laravel-smarty.template_path').'/shared', |
|
95
|
|
|
'default' => config('ytake-laravel-smarty.template_path').'/Gentele', |
|
96
|
|
|
]); |
|
97
|
|
|
|
|
98
|
|
|
$this->smarty->assign( |
|
99
|
|
|
[ |
|
100
|
|
|
'isadmin' => false, |
|
101
|
|
|
'ismod' => false, |
|
102
|
|
|
'loggedin' => false, |
|
103
|
|
|
] |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$this->smarty->assign( |
|
108
|
|
|
[ |
|
109
|
|
|
'theme' => 'Gentele', |
|
110
|
|
|
'site' => $this->settings, |
|
111
|
|
|
] |
|
112
|
|
|
); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function isPostBack(Request $request): bool |
|
116
|
|
|
{ |
|
117
|
|
|
return $request->isMethod('POST'); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Show 404 page. |
|
122
|
|
|
* |
|
123
|
|
|
* @param null $message |
|
|
|
|
|
|
124
|
|
|
*/ |
|
125
|
|
|
public function show404($message = null): View |
|
126
|
|
|
{ |
|
127
|
|
|
if ($message !== null) { |
|
|
|
|
|
|
128
|
|
|
return view('errors.404')->with('Message', $message); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return view('errors.404'); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function render(): void |
|
135
|
|
|
{ |
|
136
|
|
|
$this->smarty->display($this->page_template); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @throws \Exception |
|
141
|
|
|
*/ |
|
142
|
|
|
protected function setUserPreferences(): void |
|
143
|
|
|
{ |
|
144
|
|
|
$this->userdata->categoryexclusions = User::getCategoryExclusionById(Auth::id()); |
|
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
// Update last login every 15 mins. |
|
147
|
|
|
if (now()->subHours(3) > $this->userdata->lastlogin) { |
|
148
|
|
|
event(new UserLoggedIn($this->userdata)); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
$this->smarty->assign('userdata', $this->userdata); |
|
152
|
|
|
$this->smarty->assign('loggedin', 'true'); |
|
153
|
|
|
|
|
154
|
|
|
if ($this->userdata->hasRole('Admin')) { |
|
155
|
|
|
$this->smarty->assign('isadmin', 'true'); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
if ($this->userdata->hasRole('Moderator')) { |
|
159
|
|
|
$this->smarty->assign('ismod', 'true'); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
// Tell Smarty which directories to use for templates |
|
163
|
|
|
$this->smarty->setTemplateDir([ |
|
164
|
|
|
'user' => config('ytake-laravel-smarty.template_path').'/Gentele', |
|
165
|
|
|
'shared' => config('ytake-laravel-smarty.template_path').'/shared', |
|
166
|
|
|
'default' => config('ytake-laravel-smarty.template_path').'/Gentele', |
|
167
|
|
|
]); |
|
168
|
|
|
|
|
169
|
|
|
$role = $this->userdata->roles_id ?? User::ROLE_USER; |
|
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
$content = new Contents; |
|
|
|
|
|
|
172
|
|
|
$parentcatlist = Category::getForMenu($this->userdata->categoryexclusions); |
|
173
|
|
|
|
|
174
|
|
|
$this->smarty->assign('parentcatlist', $parentcatlist); |
|
175
|
|
|
$this->smarty->assign('catClass', Category::class); |
|
176
|
|
|
|
|
177
|
|
|
if (\request()->has('t')) { |
|
178
|
|
|
$this->smarty->assign('header_menu_cat', \request()->input('t')); |
|
179
|
|
|
} else { |
|
180
|
|
|
$this->smarty->assign('header_menu_cat', ''); |
|
181
|
|
|
} |
|
182
|
|
|
$header_menu = $this->smarty->fetch('headermenu.tpl'); |
|
183
|
|
|
$this->smarty->assign('header_menu', $header_menu); |
|
184
|
|
|
$notification = $this->smarty->fetch('notification.tpl'); |
|
185
|
|
|
$this->smarty->assign('notification', $notification); |
|
186
|
|
|
$sidebar = $this->smarty->fetch('sidebar.tpl'); |
|
187
|
|
|
$this->smarty->assign('sidebar', $sidebar); |
|
188
|
|
|
$footer = $this->smarty->fetch('footer.tpl'); |
|
189
|
|
|
$this->smarty->assign('footer', $footer); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Set admin preferences. |
|
194
|
|
|
*/ |
|
195
|
|
|
public function setAdminPrefs(): void |
|
196
|
|
|
{ |
|
197
|
|
|
// Tell Smarty which directories to use for templates |
|
198
|
|
|
$this->smarty->setTemplateDir( |
|
199
|
|
|
[ |
|
200
|
|
|
'admin' => config('ytake-laravel-smarty.template_path').'/admin', |
|
201
|
|
|
'shared' => config('ytake-laravel-smarty.template_path').'/shared', |
|
202
|
|
|
'default' => config('ytake-laravel-smarty.template_path').'/admin', |
|
203
|
|
|
] |
|
204
|
|
|
); |
|
205
|
|
|
|
|
206
|
|
|
$this->smarty->assign('catClass', Category::class); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Output the page. |
|
211
|
|
|
*/ |
|
212
|
|
|
public function pagerender(): void |
|
213
|
|
|
{ |
|
214
|
|
|
$this->page_template = 'basepage.tpl'; |
|
215
|
|
|
|
|
216
|
|
|
$this->render(); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Output a page using the admin template. |
|
221
|
|
|
* |
|
222
|
|
|
* @throws \Exception |
|
223
|
|
|
*/ |
|
224
|
|
|
public function adminrender(): void |
|
225
|
|
|
{ |
|
226
|
|
|
$admin_menu = $this->smarty->fetch('adminmenu.tpl'); |
|
227
|
|
|
$this->smarty->assign('admin_menu', $admin_menu); |
|
228
|
|
|
|
|
229
|
|
|
$this->page_template = 'baseadminpage.tpl'; |
|
230
|
|
|
|
|
231
|
|
|
$this->render(); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* @throws \Exception |
|
236
|
|
|
*/ |
|
237
|
|
|
public function adminBasePage(): void |
|
238
|
|
|
{ |
|
239
|
|
|
$this->setAdminPrefs(); |
|
240
|
|
|
$this->smarty->assign([ |
|
241
|
|
|
'meta_title' => 'Admin Home', |
|
242
|
|
|
'meta_description' => 'Admin home page', |
|
243
|
|
|
]); |
|
244
|
|
|
$this->adminrender(); |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths