2021-06-26 11:23:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http\Controllers;
|
2015-08-30 10:31:16 -04:00
|
|
|
|
2020-11-18 18:38:44 -05:00
|
|
|
use BookStack\Actions\ActivityType;
|
2019-02-16 09:17:35 -05:00
|
|
|
use BookStack\Auth\User;
|
2019-05-04 10:48:15 -04:00
|
|
|
use BookStack\Uploads\ImageRepo;
|
2015-08-30 10:31:16 -04:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class SettingController extends Controller
|
|
|
|
{
|
2022-03-28 06:09:55 -04:00
|
|
|
protected ImageRepo $imageRepo;
|
2019-05-04 10:48:15 -04:00
|
|
|
|
2022-03-28 06:16:20 -04:00
|
|
|
protected array $settingCategories = ['features', 'customization', 'registration'];
|
|
|
|
|
2019-05-04 10:48:15 -04:00
|
|
|
public function __construct(ImageRepo $imageRepo)
|
|
|
|
{
|
|
|
|
$this->imageRepo = $imageRepo;
|
|
|
|
}
|
|
|
|
|
2015-08-30 10:31:16 -04:00
|
|
|
/**
|
2022-03-30 14:15:24 -04:00
|
|
|
* Handle requests to the settings index path
|
2015-08-30 10:31:16 -04:00
|
|
|
*/
|
2022-03-30 14:15:24 -04:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return redirect('/settings/features');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the settings for the given category.
|
|
|
|
*/
|
|
|
|
public function category(string $category)
|
2015-08-30 10:31:16 -04:00
|
|
|
{
|
2022-03-28 06:16:20 -04:00
|
|
|
$this->ensureCategoryExists($category);
|
2016-02-27 14:24:42 -05:00
|
|
|
$this->checkPermission('settings-manage');
|
2018-05-27 14:40:07 -04:00
|
|
|
$this->setPageTitle(trans('settings.settings'));
|
2016-05-03 16:10:05 -04:00
|
|
|
|
|
|
|
// Get application version
|
2016-10-30 13:44:00 -04:00
|
|
|
$version = trim(file_get_contents(base_path('version')));
|
2016-05-03 16:10:05 -04:00
|
|
|
|
2022-03-28 06:09:55 -04:00
|
|
|
return view('settings.' . $category, [
|
|
|
|
'category' => $category,
|
2021-06-26 11:23:15 -04:00
|
|
|
'version' => $version,
|
|
|
|
'guestUser' => User::getDefault(),
|
2019-02-16 09:17:35 -05:00
|
|
|
]);
|
2015-08-30 10:31:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified settings in storage.
|
|
|
|
*/
|
2022-03-28 06:09:55 -04:00
|
|
|
public function update(Request $request, string $category)
|
2015-08-30 10:31:16 -04:00
|
|
|
{
|
2022-03-28 06:16:20 -04:00
|
|
|
$this->ensureCategoryExists($category);
|
2019-09-19 10:12:10 -04:00
|
|
|
$this->preventAccessInDemoMode();
|
2016-02-27 14:24:42 -05:00
|
|
|
$this->checkPermission('settings-manage');
|
2019-05-04 10:48:15 -04:00
|
|
|
$this->validate($request, [
|
2021-11-04 20:26:55 -04:00
|
|
|
'app_logo' => array_merge(['nullable'], $this->getImageValidationRules()),
|
2019-05-04 10:48:15 -04:00
|
|
|
]);
|
2015-12-31 12:57:34 -05:00
|
|
|
|
2015-08-30 10:31:16 -04:00
|
|
|
// Cycles through posted settings and update them
|
2016-03-06 05:52:10 -05:00
|
|
|
foreach ($request->all() as $name => $value) {
|
2020-11-18 18:38:44 -05:00
|
|
|
$key = str_replace('setting-', '', trim($name));
|
2018-01-28 11:58:52 -05:00
|
|
|
if (strpos($name, 'setting-') !== 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-05-04 10:48:15 -04:00
|
|
|
setting()->put($key, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update logo image if set
|
2022-03-28 06:09:55 -04:00
|
|
|
if ($category === 'customization' && $request->hasFile('app_logo')) {
|
2019-05-04 10:48:15 -04:00
|
|
|
$logoFile = $request->file('app_logo');
|
|
|
|
$this->imageRepo->destroyByType('system');
|
|
|
|
$image = $this->imageRepo->saveNew($logoFile, 'system', 0, null, 86);
|
|
|
|
setting()->put('app-logo', $image->url);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear logo image if requested
|
2022-03-28 06:31:06 -04:00
|
|
|
if ($category === 'customization' && $request->get('app_logo_reset', null)) {
|
2019-05-04 10:48:15 -04:00
|
|
|
$this->imageRepo->destroyByType('system');
|
|
|
|
setting()->remove('app-logo');
|
2015-08-30 10:31:16 -04:00
|
|
|
}
|
2015-12-31 12:57:34 -05:00
|
|
|
|
2022-03-28 06:09:55 -04:00
|
|
|
$this->logActivity(ActivityType::SETTINGS_UPDATE, $category);
|
2019-10-05 07:55:01 -04:00
|
|
|
$this->showSuccessNotification(trans('settings.settings_save_success'));
|
2021-06-26 11:23:15 -04:00
|
|
|
|
2022-03-28 06:09:55 -04:00
|
|
|
return redirect("/settings/${category}");
|
2015-08-30 10:31:16 -04:00
|
|
|
}
|
2022-03-28 06:16:20 -04:00
|
|
|
|
|
|
|
protected function ensureCategoryExists(string $category): void
|
|
|
|
{
|
|
|
|
if (!in_array($category, $this->settingCategories)) {
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
}
|
2015-08-30 10:31:16 -04:00
|
|
|
}
|