NNTmux /
newznab-tmux
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Http\Controllers; |
||
| 4 | |||
| 5 | use App\Models\Category; |
||
| 6 | use App\Models\Settings; |
||
| 7 | use App\Models\User; |
||
| 8 | use Illuminate\Http\Request; |
||
| 9 | use Illuminate\Pagination\LengthAwarePaginator; |
||
| 10 | use Illuminate\Support\Facades\Auth; |
||
| 11 | use Illuminate\View\View; |
||
| 12 | |||
| 13 | class BasePageController extends Controller |
||
| 14 | { |
||
| 15 | public Settings $settings; |
||
| 16 | |||
| 17 | public string $title = ''; |
||
| 18 | |||
| 19 | public string $content = ''; |
||
| 20 | |||
| 21 | public string $meta_keywords = ''; |
||
| 22 | |||
| 23 | public string $meta_title = ''; |
||
| 24 | |||
| 25 | public string $meta_description = ''; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Current page the user is browsing. ie browse. |
||
| 29 | */ |
||
| 30 | public string $page = ''; |
||
| 31 | |||
| 32 | public User $userdata; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * User's theme. |
||
| 36 | */ |
||
| 37 | protected string $theme = 'Gentele'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * View data array for Blade templates |
||
| 41 | */ |
||
| 42 | protected array $viewData = []; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * BasePageController constructor. |
||
| 46 | * |
||
| 47 | * @throws \Exception |
||
| 48 | */ |
||
| 49 | public function __construct() |
||
| 50 | { |
||
| 51 | $this->middleware(['auth', 'web', '2fa'])->except('api', 'contact', 'showContactForm', 'callback', 'getNzb', 'terms', 'privacyPolicy', 'capabilities', 'movie', 'apiSearch', 'tv', 'details', 'failed', 'showRssDesc', 'fullFeedRss', 'categoryFeedRss', 'cartRss', 'myMoviesRss', 'myShowsRss', 'release', 'reset', 'showLinkRequestForm'); |
||
| 52 | |||
| 53 | // Buffer settings/DB connection. |
||
| 54 | $this->settings = new Settings; |
||
| 55 | |||
| 56 | // Initialize view data |
||
| 57 | $this->viewData = [ |
||
| 58 | 'serverroot' => url('/'), |
||
| 59 | 'site' => $this->settings, |
||
| 60 | ]; |
||
| 61 | |||
| 62 | // Initialize userdata property for controllers that need it |
||
| 63 | $this->middleware(function ($request, $next) { |
||
| 64 | if (Auth::check()) { |
||
| 65 | $this->userdata = User::find(Auth::id()); |
||
| 66 | $this->userdata->categoryexclusions = User::getCategoryExclusionById(Auth::id()); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 67 | } |
||
| 68 | |||
| 69 | return $next($request); |
||
| 70 | }); |
||
| 71 | } |
||
| 72 | |||
| 73 | public function paginate($query, $totalCount, $items, $page, $path, $reqQuery): LengthAwarePaginator |
||
| 74 | { |
||
| 75 | return new LengthAwarePaginator($query, $totalCount, $items, $page, ['path' => $path, 'query' => $reqQuery]); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Check if request is POST. |
||
| 80 | */ |
||
| 81 | public function isPostBack(Request $request): bool |
||
| 82 | { |
||
| 83 | return $request->isMethod('POST'); |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Show 404 page. |
||
| 88 | * |
||
| 89 | * @param null $message |
||
|
0 ignored issues
–
show
|
|||
| 90 | */ |
||
| 91 | public function show404($message = null): View |
||
| 92 | { |
||
| 93 | if ($message !== null) { |
||
|
0 ignored issues
–
show
|
|||
| 94 | return view('errors.404')->with('Message', $message); |
||
| 95 | } |
||
| 96 | |||
| 97 | return view('errors.404'); |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Set admin preferences. |
||
| 102 | */ |
||
| 103 | public function setAdminPrefs(): void |
||
| 104 | { |
||
| 105 | $this->viewData['catClass'] = Category::class; |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Output the page using Blade views. |
||
| 110 | */ |
||
| 111 | public function pagerender(): View |
||
| 112 | { |
||
| 113 | return view('layouts.main', $this->viewData); |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Output a page using the admin template. |
||
| 118 | * |
||
| 119 | * @throws \Exception |
||
| 120 | */ |
||
| 121 | public function adminrender(): View |
||
| 122 | { |
||
| 123 | return view('layouts.admin', $this->viewData); |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @throws \Exception |
||
| 128 | */ |
||
| 129 | public function adminBasePage(): View |
||
| 130 | { |
||
| 131 | $this->setAdminPrefs(); |
||
| 132 | $this->viewData = array_merge($this->viewData, [ |
||
| 133 | 'meta_title' => 'Admin Home', |
||
| 134 | 'meta_description' => 'Admin home page', |
||
| 135 | ]); |
||
| 136 | |||
| 137 | return $this->adminrender(); |
||
| 138 | } |
||
| 139 | } |
||
| 140 |