3 namespace BookStack\Http\Controllers;
5 use Illuminate\Http\Request;
7 use BookStack\Http\Requests;
8 use BookStack\Http\Controllers\Controller;
11 class SettingController extends Controller
14 * Display a listing of the settings.
18 public function index()
20 $this->checkPermission('settings-update');
21 $this->setPageTitle('Settings');
22 return view('settings/index');
27 * Update the specified settings in storage.
29 * @param Request $request
32 public function update(Request $request)
34 $this->preventAccessForDemoUsers();
35 $this->checkPermission('settings-update');
37 // Cycles through posted settings and update them
38 foreach($request->all() as $name => $value) {
39 if(strpos($name, 'setting-') !== 0) continue;
40 $key = str_replace('setting-', '', trim($name));
41 if($key == 'app-color') {
42 Setting::put('app-color-rgba', $this->hex2rgba($value, 0.15));
44 Setting::put($key, $value);
47 session()->flash('success', 'Settings Saved');
48 return redirect('/settings');
52 * Adapted from http://mekshq.com/how-to-convert-hexadecimal-color-code-to-rgb-or-rgba-using-php/
53 * Converts a hex color code in to an RGBA string.
55 * @param string $color
56 * @param float|boolean $opacity
57 * @return boolean|string
59 protected function hex2rgba($color, $opacity = false)
61 // Return false if no color provided
65 // Trim any whitespace
66 $color = trim($color);
68 // Sanitize $color if "#" is provided
69 if($color[0] == '#' ) {
70 $color = substr($color, 1);
73 // Check if color has 6 or 3 characters and get values
74 if(strlen($color) == 6) {
75 $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
76 } elseif( strlen( $color ) == 3 ) {
77 $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
82 // Convert hexadec to rgb
83 $rgb = array_map('hexdec', $hex);
85 // Check if opacity is set(rgba or rgb)
89 $output = 'rgba('.implode(",",$rgb).','.$opacity.')';
91 $output = 'rgb('.implode(",",$rgb).')';
94 // Return rgb(a) color string