2015-08-30 10:31:16 -04:00
|
|
|
<?php
|
|
|
|
|
2015-09-10 14:31:09 -04:00
|
|
|
namespace BookStack\Http\Controllers;
|
2015-08-30 10:31:16 -04:00
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
2015-09-10 14:31:09 -04:00
|
|
|
use BookStack\Http\Requests;
|
|
|
|
use BookStack\Http\Controllers\Controller;
|
2015-08-30 10:31:16 -04:00
|
|
|
use Setting;
|
|
|
|
|
|
|
|
class SettingController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the settings.
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$this->checkPermission('settings-update');
|
2015-12-05 09:41:51 -05:00
|
|
|
$this->setPageTitle('Settings');
|
2015-08-30 10:31:16 -04:00
|
|
|
return view('settings/index');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified settings in storage.
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request)
|
|
|
|
{
|
2015-12-31 12:57:34 -05:00
|
|
|
$this->preventAccessForDemoUsers();
|
2015-08-30 10:31:16 -04:00
|
|
|
$this->checkPermission('settings-update');
|
2015-12-31 12:57:34 -05:00
|
|
|
|
2015-08-30 10:31:16 -04:00
|
|
|
// 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));
|
2016-03-03 13:01:14 -05:00
|
|
|
if($key == 'app-color') {
|
|
|
|
Setting::put('app-color-rgba', $this->hex2rgba($value, 0.15));
|
|
|
|
}
|
2015-08-30 10:31:16 -04:00
|
|
|
Setting::put($key, $value);
|
|
|
|
}
|
2015-12-31 12:57:34 -05:00
|
|
|
|
2015-09-05 15:25:57 -04:00
|
|
|
session()->flash('success', 'Settings Saved');
|
2015-08-30 10:31:16 -04:00
|
|
|
return redirect('/settings');
|
|
|
|
}
|
|
|
|
|
2016-03-03 13:01:14 -05:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
protected function hex2rgba($color, $opacity = false)
|
|
|
|
{
|
|
|
|
// Return false if no color provided
|
|
|
|
if(empty($color)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Trim any whitespace
|
|
|
|
$color = trim($color);
|
|
|
|
|
|
|
|
// Sanitize $color if "#" is provided
|
|
|
|
if($color[0] == '#' ) {
|
|
|
|
$color = substr($color, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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).')';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return rgb(a) color string
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2015-08-30 10:31:16 -04:00
|
|
|
}
|