X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/0774ecc89c23d067296abac0298c2e02120917df..refs/pull/2272/head:/app/Http/Controllers/SettingController.php diff --git a/app/Http/Controllers/SettingController.php b/app/Http/Controllers/SettingController.php index dfda2b6cf..50d91d388 100644 --- a/app/Http/Controllers/SettingController.php +++ b/app/Http/Controllers/SettingController.php @@ -1,98 +1,75 @@ -checkPermission('settings-manage'); - $this->setPageTitle('Settings'); - return view('settings/index'); + $this->imageRepo = $imageRepo; + parent::__construct(); } - /** - * Update the specified settings in storage. - * - * @param Request $request - * @return Response + * Display a listing of the settings. */ - public function update(Request $request) + public function index() { - $this->preventAccessForDemoUsers(); $this->checkPermission('settings-manage'); + $this->setPageTitle(trans('settings.settings')); - // Cycles through posted settings and update them - foreach($request->all() as $name => $value) { - if(strpos($name, 'setting-') !== 0) continue; - $key = str_replace('setting-', '', trim($name)); - if($key == 'app-color') { - Setting::put('app-color-rgba', $this->hex2rgba($value, 0.15)); - } - Setting::put($key, $value); - } + // Get application version + $version = trim(file_get_contents(base_path('version'))); - session()->flash('success', 'Settings Saved'); - return redirect('/settings'); + return view('settings.index', [ + 'version' => $version, + 'guestUser' => User::getDefault() + ]); } /** - * Adapted from http://mekshq.com/how-to-convert-hexadecimal-color-code-to-rgb-or-rgba-using-php/ - * Converts a hex color code in to an RGBA string. - * - * @param string $color - * @param float|boolean $opacity - * @return boolean|string + * Update the specified settings in storage. */ - protected function hex2rgba($color, $opacity = false) + public function update(Request $request) { - // Return false if no color provided - if(empty($color)) { - return false; - } - // Trim any whitespace - $color = trim($color); + $this->preventAccessInDemoMode(); + $this->checkPermission('settings-manage'); + $this->validate($request, [ + 'app_logo' => 'nullable|' . $this->getImageValidationRules(), + ]); - // Sanitize $color if "#" is provided - if($color[0] == '#' ) { - $color = substr($color, 1); + // Cycles through posted settings and update them + foreach ($request->all() as $name => $value) { + if (strpos($name, 'setting-') !== 0) { + continue; + } + $key = str_replace('setting-', '', trim($name)); + setting()->put($key, $value); } - // Check if color has 6 or 3 characters and get values - if(strlen($color) == 6) { - $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); - } elseif( strlen( $color ) == 3 ) { - $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); - } else { - return false; + // Update logo image if set + if ($request->hasFile('app_logo')) { + $logoFile = $request->file('app_logo'); + $this->imageRepo->destroyByType('system'); + $image = $this->imageRepo->saveNew($logoFile, 'system', 0, null, 86); + setting()->put('app-logo', $image->url); } - // Convert hexadec to rgb - $rgb = array_map('hexdec', $hex); - - // Check if opacity is set(rgba or rgb) - if($opacity) { - if(abs($opacity) > 1) - $opacity = 1.0; - $output = 'rgba('.implode(",",$rgb).','.$opacity.')'; - } else { - $output = 'rgb('.implode(",",$rgb).')'; + // Clear logo image if requested + if ($request->get('app_logo_reset', null)) { + $this->imageRepo->destroyByType('system'); + setting()->remove('app-logo'); } - // Return rgb(a) color string - return $output; + $this->showSuccessNotification(trans('settings.settings_save_success')); + $redirectLocation = '/settings#' . $request->get('section', ''); + return redirect(rtrim($redirectLocation, '#')); } - }