]> BookStack Code Mirror - bookstack/commitdiff
Merge branch 'master' into nwalke-update_site_color
authorDan Brown <redacted>
Sun, 6 Mar 2016 09:08:20 +0000 (09:08 +0000)
committerDan Brown <redacted>
Sun, 6 Mar 2016 09:08:20 +0000 (09:08 +0000)
1  2 
app/Http/Controllers/SettingController.php
resources/views/base.blade.php
resources/views/settings/index.blade.php

index 47f59efbbb48cc3224bc74e00af0597effa87a78,c43e6e399df24ec369bb792f777adc663b64b58c..dfda2b6cf211f367755e9914225115a053c45522
@@@ -17,7 -17,7 +17,7 @@@ class SettingController extends Control
       */
      public function index()
      {
-         $this->checkPermission('settings-update');
+         $this->checkPermission('settings-manage');
          $this->setPageTitle('Settings');
          return view('settings/index');
      }
      public function update(Request $request)
      {
          $this->preventAccessForDemoUsers();
-         $this->checkPermission('settings-update');
+         $this->checkPermission('settings-manage');
  
          // 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);
          }
  
          return redirect('/settings');
      }
  
 +    /**
 +     * 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;
 +    }
 +
  }
index 830976657c63905692f306a7aff0d3d08a10f17a,e3cac3621b113e4e818e866dde739d8fecd2cec8..59bbe6fbbe19965d2ee8b57cd4fd58c1d926dbc6
      <script src="/libs/jquery/jquery.min.js?version=2.1.4"></script>
  
      @yield('head')
 +    @if(Setting::get('app-color'))
 +        <style>
 +            header{
 +                background-color: #{{ Setting::get('app-color') }};
 +            }
 +            .faded-small{
 +                background-color: {{ Setting::get('app-color-rgba') }};
 +            }
 +            .button-base, .button, input[type="button"], input[type="submit"] {
 +                background-color: #{{ Setting::get('app-color') }};
 +            }
 +            .button-base:hover, .button:hover, input[type="button"]:hover, input[type="submit"]:hover {
 +                background-color: #{{ Setting::get('app-color') }};
 +            }
 +            p.primary:hover, p .primary:hover, span.primary:hover, .text-primary:hover {
 +                color: #{{ Setting::get('app-color') }};
 +            }
 +        </style>
 +    @endif
  </head>
  <body class="@yield('body-class')" ng-app="bookStack">
  
@@@ -62,7 -43,7 +62,7 @@@
                      <div class="float right">
                          <div class="links text-center">
                              <a href="/books"><i class="zmdi zmdi-book"></i>Books</a>
-                             @if(isset($currentUser) && $currentUser->can('settings-update'))
+                             @if(isset($currentUser) && $currentUser->can('settings-manage'))
                                  <a href="/settings"><i class="zmdi zmdi-settings"></i>Settings</a>
                              @endif
                              @if(!isset($signedIn) || !$signedIn)
index 6b01583aec479daad5a9bf70bd8162f5487cc65e,4274378e62bf1a07f730473eefe4a4ea72e87884..c0e4558830db3f6ae7b00bf5b0d5fdc4c09cbdcf
                      <p class="small">This image should be 43px in height. <br>Large images will be scaled down.</p>
                      <image-picker resize-height="43" show-remove="true" resize-width="200" current-image="{{ Setting::get('app-logo', '') }}" default-image="/logo.png" name="setting-app-logo" image-class="logo-image"></image-picker>
                  </div>
 +                <div class="form-group" id="color-control">
 +                    <label for="setting-app-color">Application Primary Color</label>
 +                    <p class="small">This should be a hex value.</p>
 +                    <input class="jscolor" type="text" value="{{ Setting::get('app-color', '') }}" name="setting-app-color" id="setting-app-color" placeholder="0288D1">
 +                </div>
              </div>
          </div>
  
@@@ -59,7 -54,7 +59,7 @@@
                      <select id="setting-registration-role" name="setting-registration-role" @if($errors->has('setting-registration-role')) class="neg" @endif>
                          @foreach(\BookStack\Role::all() as $role)
                              <option value="{{$role->id}}"
-                                     @if(\Setting::get('registration-role', \BookStack\Role::getDefault()->id) == $role->id) selected @endif
+                                     @if(\Setting::get('registration-role', \BookStack\Role::first()->id) == $role->id) selected @endif
                                      >
                                  {{ $role->display_name }}
                              </option>
@@@ -94,7 -89,3 +94,7 @@@
  @include('partials/image-manager', ['imageType' => 'system'])
  
  @stop
 +
 +@section('scripts')
 +    <script src="/libs/jscolor/jscolor.min.js?version=2.0.4"></script>
 +@stop