2016-01-08 16:01:21 +01:00
|
|
|
<?php
|
2022-12-29 19:41:57 +01:00
|
|
|
|
2016-05-20 12:27:31 +02:00
|
|
|
/**
|
|
|
|
* Controller.php
|
2020-01-31 07:32:04 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2016-05-20 12:27:31 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2016-10-05 06:52:15 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 08:40:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2016-05-20 12:27:31 +02:00
|
|
|
*/
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
2015-02-06 04:39:52 +01:00
|
|
|
|
2016-01-08 16:01:21 +01:00
|
|
|
namespace FireflyIII\Http\Controllers;
|
|
|
|
|
2024-12-25 07:10:02 +01:00
|
|
|
use FireflyIII\Models\TransactionCurrency;
|
2024-12-28 07:35:20 +01:00
|
|
|
use FireflyIII\Support\Facades\Amount;
|
2024-12-22 16:41:55 +01:00
|
|
|
use FireflyIII\Support\Facades\Steam;
|
2018-08-09 17:46:14 +02:00
|
|
|
use FireflyIII\Support\Http\Controllers\RequestInformation;
|
2018-08-09 16:07:33 +02:00
|
|
|
use FireflyIII\Support\Http\Controllers\UserNavigation;
|
2016-01-08 16:01:21 +01:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
2015-06-13 10:02:36 +02:00
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
2015-02-06 04:39:52 +01:00
|
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
2015-02-11 07:35:10 +01:00
|
|
|
use Illuminate\Routing\Controller as BaseController;
|
2024-12-22 16:41:55 +01:00
|
|
|
use Illuminate\Support\Facades\View;
|
2024-12-22 08:43:12 +01:00
|
|
|
use Route;
|
2015-02-06 04:39:52 +01:00
|
|
|
|
2015-02-11 07:35:10 +01:00
|
|
|
/**
|
2017-11-15 12:25:49 +01:00
|
|
|
* Class Controller.
|
2023-12-22 20:12:38 +01:00
|
|
|
*
|
2025-01-03 18:16:27 +01:00
|
|
|
* @SuppressWarnings("PHPMD.CouplingBetweenObjects")
|
2025-01-03 19:07:29 +01:00
|
|
|
* @SuppressWarnings("PHPMD.NumberOfChildren")
|
2015-02-11 07:35:10 +01:00
|
|
|
*/
|
2020-07-31 15:12:26 +02:00
|
|
|
abstract class Controller extends BaseController
|
2015-02-11 07:35:10 +01:00
|
|
|
{
|
2022-10-30 14:24:19 +01:00
|
|
|
use AuthorizesRequests;
|
|
|
|
use DispatchesJobs;
|
|
|
|
use RequestInformation;
|
|
|
|
use UserNavigation;
|
2023-11-04 14:18:49 +01:00
|
|
|
use ValidatesRequests;
|
2015-05-14 13:41:21 +02:00
|
|
|
|
2024-11-26 18:04:32 +01:00
|
|
|
// fails on PHP < 8.4
|
|
|
|
public protected(set) string $name;
|
|
|
|
|
2020-06-06 22:25:52 +02:00
|
|
|
protected string $dateTimeFormat;
|
|
|
|
protected string $monthAndDayFormat;
|
2024-12-24 19:03:47 +01:00
|
|
|
protected bool $convertToNative = false;
|
2024-12-25 08:14:07 +01:00
|
|
|
protected ?TransactionCurrency $defaultCurrency;
|
2020-06-06 22:25:52 +02:00
|
|
|
protected string $monthFormat;
|
2022-04-12 18:19:30 +02:00
|
|
|
protected string $redirectUrl = '/';
|
2016-01-09 07:48:45 +01:00
|
|
|
|
2015-04-28 15:26:30 +02:00
|
|
|
/**
|
2016-01-08 16:01:21 +01:00
|
|
|
* Controller constructor.
|
2015-04-28 15:26:30 +02:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2017-07-22 10:50:30 +02:00
|
|
|
// is site a demo site?
|
2021-05-24 08:50:17 +02:00
|
|
|
$isDemoSiteConfig = app('fireflyconfig')->get('is_demo_site', config('firefly.configuration.is_demo_site', false));
|
2024-12-22 08:43:12 +01:00
|
|
|
$isDemoSite = (bool) $isDemoSiteConfig->data;
|
2024-12-22 16:41:55 +01:00
|
|
|
View::share('IS_DEMO_SITE', $isDemoSite);
|
|
|
|
View::share('DEMO_USERNAME', config('firefly.demo_username'));
|
|
|
|
View::share('DEMO_PASSWORD', config('firefly.demo_password'));
|
|
|
|
View::share('FF_VERSION', config('firefly.version'));
|
2016-10-29 07:44:46 +02:00
|
|
|
|
2020-11-29 11:36:29 +01:00
|
|
|
// is webhooks enabled?
|
2024-12-22 16:41:55 +01:00
|
|
|
View::share('featuringWebhooks', true === config('firefly.feature_flags.webhooks') && true === config('firefly.allow_webhooks'));
|
2020-11-29 11:36:29 +01:00
|
|
|
|
2020-11-07 17:19:23 +01:00
|
|
|
// share custom auth guard info.
|
2024-12-22 08:43:12 +01:00
|
|
|
$authGuard = config('firefly.authentication_guard');
|
|
|
|
$logoutUrl = config('firefly.custom_logout_url');
|
2020-11-07 17:19:23 +01:00
|
|
|
|
2024-03-05 19:38:45 +01:00
|
|
|
// overrule v2 layout back to v1.
|
2024-04-08 07:45:58 +02:00
|
|
|
if ('true' === request()->get('force_default_layout') && 'v2' === config('view.layout')) {
|
2024-12-22 16:41:55 +01:00
|
|
|
View::getFinder()->setPaths([realpath(base_path('resources/views'))]); // @phpstan-ignore-line
|
2024-03-05 19:38:45 +01:00
|
|
|
}
|
|
|
|
|
2024-12-22 16:41:55 +01:00
|
|
|
View::share('authGuard', $authGuard);
|
|
|
|
View::share('logoutUrl', $logoutUrl);
|
2020-11-07 17:19:23 +01:00
|
|
|
|
2020-03-19 08:43:52 +01:00
|
|
|
// upload size
|
2024-12-22 16:41:55 +01:00
|
|
|
$maxFileSize = Steam::phpBytes((string) ini_get('upload_max_filesize'));
|
|
|
|
$maxPostSize = Steam::phpBytes((string) ini_get('post_max_size'));
|
2024-12-22 08:43:12 +01:00
|
|
|
$uploadSize = min($maxFileSize, $maxPostSize);
|
2024-12-22 16:41:55 +01:00
|
|
|
View::share('uploadSize', $uploadSize);
|
2020-03-19 08:43:52 +01:00
|
|
|
|
2019-12-20 05:44:33 +01:00
|
|
|
// share is alpha, is beta
|
2024-12-22 08:43:12 +01:00
|
|
|
$isAlpha = false;
|
2021-05-24 08:50:17 +02:00
|
|
|
if (str_contains(config('firefly.version'), 'alpha')) {
|
2019-12-20 05:44:33 +01:00
|
|
|
$isAlpha = true;
|
|
|
|
}
|
|
|
|
|
2024-12-22 08:43:12 +01:00
|
|
|
$isBeta = false;
|
2021-05-24 08:50:17 +02:00
|
|
|
if (str_contains(config('firefly.version'), 'beta')) {
|
2019-12-20 05:44:33 +01:00
|
|
|
$isBeta = true;
|
|
|
|
}
|
|
|
|
|
2024-12-22 16:41:55 +01:00
|
|
|
View::share('FF_IS_ALPHA', $isAlpha);
|
|
|
|
View::share('FF_IS_BETA', $isBeta);
|
2019-12-20 05:44:33 +01:00
|
|
|
|
2016-10-29 07:44:46 +02:00
|
|
|
$this->middleware(
|
2021-09-25 16:25:03 +02:00
|
|
|
function ($request, $next): mixed {
|
2024-12-22 16:41:55 +01:00
|
|
|
$locale = Steam::getLocale();
|
2017-07-22 10:50:30 +02:00
|
|
|
// translations for specific strings:
|
2024-12-22 08:43:12 +01:00
|
|
|
$this->monthFormat = (string) trans('config.month_js', [], $locale);
|
|
|
|
$this->monthAndDayFormat = (string) trans('config.month_and_day_js', [], $locale);
|
|
|
|
$this->dateTimeFormat = (string) trans('config.date_time_js', [], $locale);
|
2023-04-08 06:55:38 +02:00
|
|
|
$darkMode = 'browser';
|
2024-12-25 08:14:07 +01:00
|
|
|
$this->defaultCurrency =null;
|
2017-07-15 21:40:42 +02:00
|
|
|
// get shown-intro-preference:
|
2017-07-15 22:17:24 +02:00
|
|
|
if (auth()->check()) {
|
2025-01-19 19:07:19 +01:00
|
|
|
$this->defaultCurrency = Amount::getNativeCurrency();
|
2024-12-22 16:41:55 +01:00
|
|
|
$language = Steam::getLanguage();
|
|
|
|
$locale = Steam::getLocale();
|
2023-04-08 06:55:38 +02:00
|
|
|
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
|
2024-12-28 07:35:20 +01:00
|
|
|
$this->convertToNative =Amount::convertToNative();
|
2018-07-17 22:21:03 +02:00
|
|
|
$page = $this->getPageName();
|
|
|
|
$shownDemo = $this->hasSeenDemo();
|
2024-12-22 16:41:55 +01:00
|
|
|
View::share('language', $language);
|
|
|
|
View::share('locale', $locale);
|
2024-12-24 19:03:47 +01:00
|
|
|
View::share('convertToNative', $this->convertToNative);
|
2024-12-22 16:41:55 +01:00
|
|
|
View::share('shownDemo', $shownDemo);
|
|
|
|
View::share('current_route_name', $page);
|
|
|
|
View::share('original_route_name', Route::currentRouteName());
|
2017-07-15 22:17:24 +02:00
|
|
|
}
|
2024-12-22 16:41:55 +01:00
|
|
|
View::share('darkMode', $darkMode);
|
2017-07-15 21:40:42 +02:00
|
|
|
|
2016-10-29 07:44:46 +02:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
2015-04-28 15:26:30 +02:00
|
|
|
}
|
2015-02-06 04:39:52 +01:00
|
|
|
}
|