2016-01-08 16:01:21 +01:00
|
|
|
<?php
|
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;
|
|
|
|
|
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;
|
2017-07-15 22:17:24 +02: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.
|
2018-07-17 22:21:03 +02:00
|
|
|
*
|
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
|
|
|
{
|
2018-08-09 17:46:14 +02:00
|
|
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests, UserNavigation, RequestInformation;
|
2015-05-14 13:41:21 +02:00
|
|
|
|
2018-07-22 08:10:16 +02:00
|
|
|
/** @var string Format for date and time. */
|
2020-06-06 22:25:52 +02:00
|
|
|
protected string $dateTimeFormat;
|
2018-07-22 08:10:16 +02:00
|
|
|
/** @var string Format for "23 Feb, 2016". */
|
2020-06-06 22:25:52 +02:00
|
|
|
protected string $monthAndDayFormat;
|
2018-07-22 08:10:16 +02:00
|
|
|
/** @var string Format for "March 2018" */
|
2020-06-06 22:25:52 +02:00
|
|
|
protected string $monthFormat;
|
2018-07-22 08:10:16 +02:00
|
|
|
/** @var string Redirect user */
|
2020-06-06 22:25:52 +02:00
|
|
|
protected string $redirectUri = '/';
|
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.
|
2019-08-23 18:55:14 +02:00
|
|
|
*
|
2019-07-21 17:15:06 +02:00
|
|
|
* @codeCoverageIgnore
|
2015-04-28 15:26:30 +02:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2017-07-22 10:50:30 +02:00
|
|
|
// is site a demo site?
|
2020-07-06 06:49:48 +02:00
|
|
|
$isDemoSiteConfig = app('fireflyconfig')->get('is_demo_site', config('firefly.configuration.is_demo_site', false,),);
|
|
|
|
$isDemoSite = $isDemoSiteConfig ? $isDemoSiteConfig->data : false;
|
2019-12-20 05:44:33 +01:00
|
|
|
app('view')->share('IS_DEMO_SITE', $isDemoSite,);
|
2018-12-15 07:59:02 +01:00
|
|
|
app('view')->share('DEMO_USERNAME', config('firefly.demo_username'));
|
|
|
|
app('view')->share('DEMO_PASSWORD', config('firefly.demo_password'));
|
2018-07-14 16:08:34 +02:00
|
|
|
app('view')->share('FF_VERSION', config('firefly.version'));
|
2016-10-29 07:44:46 +02:00
|
|
|
|
2020-03-19 08:43:52 +01:00
|
|
|
// upload size
|
|
|
|
$maxFileSize = app('steam')->phpBytes(ini_get('upload_max_filesize'));
|
|
|
|
$maxPostSize = app('steam')->phpBytes(ini_get('post_max_size'));
|
|
|
|
$uploadSize = min($maxFileSize, $maxPostSize);
|
|
|
|
|
|
|
|
|
|
|
|
app('view')->share('uploadSize', $uploadSize);
|
|
|
|
|
2019-12-20 05:44:33 +01:00
|
|
|
// share is alpha, is beta
|
|
|
|
$isAlpha = false;
|
|
|
|
if (false !== strpos(config('firefly.version'), 'alpha')) {
|
|
|
|
$isAlpha = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$isBeta = false;
|
|
|
|
if (false !== strpos(config('firefly.version'), 'beta')) {
|
|
|
|
$isBeta = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
app('view')->share('FF_IS_ALPHA', $isAlpha);
|
|
|
|
app('view')->share('FF_IS_BETA', $isBeta);
|
|
|
|
|
2016-10-29 07:44:46 +02:00
|
|
|
$this->middleware(
|
|
|
|
function ($request, $next) {
|
2020-04-19 06:51:40 +02:00
|
|
|
$locale = app('steam')->getLocale();
|
2017-07-22 10:50:30 +02:00
|
|
|
// translations for specific strings:
|
2020-04-19 06:51:40 +02:00
|
|
|
$this->monthFormat = (string) trans('config.month', [], $locale);
|
|
|
|
$this->monthAndDayFormat = (string) trans('config.month_and_day', [], $locale);
|
|
|
|
$this->dateTimeFormat = (string) trans('config.date_time', [], $locale);
|
2016-10-29 07:44:46 +02:00
|
|
|
|
2017-07-15 21:40:42 +02:00
|
|
|
// get shown-intro-preference:
|
2017-07-15 22:17:24 +02:00
|
|
|
if (auth()->check()) {
|
2020-04-19 06:09:55 +02:00
|
|
|
$language = app('steam')->getLanguage();
|
2020-04-19 06:51:40 +02:00
|
|
|
$locale = app('steam')->getLocale();
|
2018-07-17 22:21:03 +02:00
|
|
|
$page = $this->getPageName();
|
|
|
|
$shownDemo = $this->hasSeenDemo();
|
2018-07-14 16:08:34 +02:00
|
|
|
app('view')->share('language', $language);
|
2020-04-19 06:09:55 +02:00
|
|
|
app('view')->share('locale', $locale);
|
2018-07-14 16:08:34 +02:00
|
|
|
app('view')->share('shownDemo', $shownDemo);
|
|
|
|
app('view')->share('current_route_name', $page);
|
|
|
|
app('view')->share('original_route_name', Route::currentRouteName());
|
2017-07-15 22:17:24 +02:00
|
|
|
}
|
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
|
|
|
}
|