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