Also updated the setting system with a more sane approach to handling default values. (Now done via the setting-defaults config file)
$page->fill($input);
$page->html = $this->formatHtml($input['html']);
$page->text = strip_tags($page->html);
$page->fill($input);
$page->html = $this->formatHtml($input['html']);
$page->text = strip_tags($page->html);
+ if (setting('app-editor') !== 'markdown') $page->markdown = '';
$page->updated_by = $userId;
$page->save();
$page->updated_by = $userId;
$page->save();
public function saveRevision(Page $page)
{
$revision = $this->pageRevision->fill($page->toArray());
public function saveRevision(Page $page)
{
$revision = $this->pageRevision->fill($page->toArray());
+ if (setting('app-editor') !== 'markdown') $revision->markdown = '';
$revision->page_id = $page->id;
$revision->slug = $page->slug;
$revision->book_slug = $page->book->slug;
$revision->page_id = $page->id;
$revision->slug = $page->slug;
$revision->book_slug = $page->book->slug;
+ if (setting('app-editor') !== 'markdown') $draft->markdown = '';
+
$draft->save();
return $draft;
}
$draft->save();
return $draft;
}
/**
* Gets a setting value from the cache or database.
/**
* Gets a setting value from the cache or database.
+ * Looks at the system defaults if not cached or in database.
* @param $key
* @param $default
* @return mixed
*/
protected function getValueFromStore($key, $default)
{
* @param $key
* @param $default
* @return mixed
*/
protected function getValueFromStore($key, $default)
{
+ // Check for an overriding value
$overrideValue = $this->getOverrideValue($key);
if ($overrideValue !== null) return $overrideValue;
$overrideValue = $this->getOverrideValue($key);
if ($overrideValue !== null) return $overrideValue;
$cacheKey = $this->cachePrefix . $key;
if ($this->cache->has($cacheKey)) {
return $this->cache->get($cacheKey);
}
$cacheKey = $this->cachePrefix . $key;
if ($this->cache->has($cacheKey)) {
return $this->cache->get($cacheKey);
}
$settingObject = $this->getSettingObjectByKey($key);
$settingObject = $this->getSettingObjectByKey($key);
if ($settingObject !== null) {
$value = $settingObject->value;
$this->cache->forever($cacheKey, $value);
return $value;
}
if ($settingObject !== null) {
$value = $settingObject->value;
$this->cache->forever($cacheKey, $value);
return $value;
}
+ // Check the defaults set in the app config.
+ $configPrefix = 'setting-defaults.' . $key;
+ if (config()->has($configPrefix)) {
+ $value = config($configPrefix);
+ $this->cache->forever($cacheKey, $value);
+ return $value;
+ }
+
--- /dev/null
+<?php
+
+/**
+ * The defaults for the system settings that are saved in the database.
+ */
+return [
+
+ 'app-editor' => 'wysiwyg'
+
+];
\ No newline at end of file
public function up()
{
Schema::table('pages', function (Blueprint $table) {
public function up()
{
Schema::table('pages', function (Blueprint $table) {
- $table->longText('markdown');
+ $table->longText('markdown')->default('');
});
Schema::table('page_revisions', function (Blueprint $table) {
});
Schema::table('page_revisions', function (Blueprint $table) {
- $table->longText('markdown');
+ $table->longText('markdown')->default('');
+ if (!isMarkdown) {
+ $scope.editorChange = function() {};
+ }
+
/**
* Start the AutoSave loop, Checks for content change
* before performing the costly AJAX request.
/**
* Start the AutoSave loop, Checks for content change
* before performing the costly AJAX request.
if (isMarkdown) data.markdown = $scope.editContent;
if (isMarkdown) data.markdown = $scope.editContent;
- console.log(data.markdown);
-
$http.put('/ajax/page/' + pageId + '/save-draft', data).then((responseData) => {
$scope.draftText = responseData.data.message;
if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true;
$http.put('/ajax/page/' + pageId + '/save-draft', data).then((responseData) => {
$scope.draftText = responseData.data.message;
if (!$scope.isNewPageDraft) $scope.isUpdateDraft = true;
-<div class="page-editor flex-fill flex" ng-controller="PageEditController" editor-type="{{ config('app.editor') }}" page-id="{{ $model->id or 0 }}" page-new-draft="{{ $model->draft or 0 }}" page-update-draft="{{ $model->isDraft or 0 }}">
+<div class="page-editor flex-fill flex" ng-controller="PageEditController" editor-type="{{ setting('app-editor') }}" page-id="{{ $model->id or 0 }}" page-new-draft="{{ $model->draft or 0 }}" page-update-draft="{{ $model->isDraft or 0 }}">
{{ csrf_field() }}
<div class="faded-small toolbar">
{{ csrf_field() }}
<div class="faded-small toolbar">
</div>
</div>
<div class="edit-area flex-fill flex">
</div>
</div>
<div class="edit-area flex-fill flex">
- @if(config('app.editor') === 'html')
+ @if(setting('app-editor') === 'wysiwyg')
<textarea id="html-editor" tinymce="editorOptions" mce-change="editorChange" mce-model="editContent" name="html" rows="5"
@if($errors->has('html')) class="neg" @endif>@if(isset($model) || old('html')){{htmlspecialchars( old('html') ? old('html') : $model->html)}}@endif</textarea>
@if($errors->has('html'))
<textarea id="html-editor" tinymce="editorOptions" mce-change="editorChange" mce-model="editContent" name="html" rows="5"
@if($errors->has('html')) class="neg" @endif>@if(isset($model) || old('html')){{htmlspecialchars( old('html') ? old('html') : $model->html)}}@endif</textarea>
@if($errors->has('html'))
- @if(config('app.editor') === 'markdown')
+ @if(setting('app-editor') === 'markdown')
<div id="markdown-editor" markdown-editor class="flex-fill flex">
<div class="markdown-editor-wrap">
<div id="markdown-editor" markdown-editor class="flex-fill flex">
<div class="markdown-editor-wrap">
<div class="col-md-6">
<div class="form-group">
<label for="setting-app-name">Application name</label>
<div class="col-md-6">
<div class="form-group">
<label for="setting-app-name">Application name</label>
- <input type="text" value="{{ Setting::get('app-name', 'BookStack') }}" name="setting-app-name" id="setting-app-name">
+ <input type="text" value="{{ setting('app-name', 'BookStack') }}" name="setting-app-name" id="setting-app-name">
</div>
<div class="form-group">
<label>Allow public viewing?</label>
</div>
<div class="form-group">
<label>Allow public viewing?</label>
- <toggle-switch name="setting-app-public" value="{{ Setting::get('app-public') }}"></toggle-switch>
+ <toggle-switch name="setting-app-public" value="{{ setting('app-public') }}"></toggle-switch>
</div>
<div class="form-group">
<label>Enable higher security image uploads?</label>
<p class="small">For performance reasons, all images are public by default, This option adds a random, hard-to-guess characters in front of image names. Ensure directory indexes are not enabled to prevent easy access.</p>
</div>
<div class="form-group">
<label>Enable higher security image uploads?</label>
<p class="small">For performance reasons, all images are public by default, This option adds a random, hard-to-guess characters in front of image names. Ensure directory indexes are not enabled to prevent easy access.</p>
- <toggle-switch name="setting-app-secure-images" value="{{ Setting::get('app-secure-images') }}"></toggle-switch>
+ <toggle-switch name="setting-app-secure-images" value="{{ setting('app-secure-images') }}"></toggle-switch>
+ </div>
+ <div class="form-group">
+ <label for="setting-app-editor">Page Editor</label>
+ <p class="small">Select which editor will be used by all users to edit pages.</p>
+ <select name="setting-app-editor" id="setting-app-editor">
+ <option @if(setting('app-editor') === 'wysiwyg') selected @endif value="wysiwyg">WYSIWYG</option>
+ <option @if(setting('app-editor') === 'markdown') selected @endif value="markdown">Markdown</option>
+ </select>
</div>
</div>
<div class="col-md-6">
<div class="form-group" id="logo-control">
<label for="setting-app-logo">Application Logo</label>
<p class="small">This image should be 43px in height. <br>Large images will be scaled down.</p>
</div>
</div>
<div class="col-md-6">
<div class="form-group" id="logo-control">
<label for="setting-app-logo">Application Logo</label>
<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>
+ <image-picker resize-height="43" show-remove="true" resize-width="200" current-image="{{ setting('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. <br> Leave empty to reset to the default color.</p>
</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. <br> Leave empty to reset to the default color.</p>
- <input type="text" value="{{ Setting::get('app-color', '') }}" name="setting-app-color" id="setting-app-color" placeholder="#0288D1">
- <input type="hidden" value="{{ Setting::get('app-color-light', '') }}" name="setting-app-color-light" id="setting-app-color-light" placeholder="rgba(21, 101, 192, 0.15)">
+ <input type="text" value="{{ setting('app-color', '') }}" name="setting-app-color" id="setting-app-color" placeholder="#0288D1">
+ <input type="hidden" value="{{ setting('app-color-light', '') }}" name="setting-app-color-light" id="setting-app-color-light" placeholder="rgba(21, 101, 192, 0.15)">
<div class="col-md-6">
<div class="form-group">
<label for="setting-registration-enabled">Allow registration?</label>
<div class="col-md-6">
<div class="form-group">
<label for="setting-registration-enabled">Allow registration?</label>
- <toggle-switch name="setting-registration-enabled" value="{{ Setting::get('registration-enabled') }}"></toggle-switch>
+ <toggle-switch name="setting-registration-enabled" value="{{ setting('registration-enabled') }}"></toggle-switch>
</div>
<div class="form-group">
<label for="setting-registration-role">Default user role after registration</label>
<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}}"
</div>
<div class="form-group">
<label for="setting-registration-role">Default user role after registration</label>
<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::first()->id) == $role->id) selected @endif
+ @if(setting('registration-role', \BookStack\Role::first()->id) == $role->id) selected @endif
>
{{ $role->display_name }}
</option>
>
{{ $role->display_name }}
</option>
<div class="form-group">
<label for="setting-registration-confirmation">Require email confirmation?</label>
<p class="small">If domain restriction is used then email confirmation will be required and the below value will be ignored.</p>
<div class="form-group">
<label for="setting-registration-confirmation">Require email confirmation?</label>
<p class="small">If domain restriction is used then email confirmation will be required and the below value will be ignored.</p>
- <toggle-switch name="setting-registration-confirmation" value="{{ Setting::get('registration-confirmation') }}"></toggle-switch>
+ <toggle-switch name="setting-registration-confirmation" value="{{ setting('registration-confirmation') }}"></toggle-switch>
</div>
</div>
<div class="col-md-6">
</div>
</div>
<div class="col-md-6">
<label for="setting-registration-restrict">Restrict registration to domain</label>
<p class="small">Enter a comma separated list of email domains you would like to restrict registration to. Users will be sent an email to confirm their address before being allowed to interact with the application.
<br> Note that users will be able to change their email addresses after successful registration.</p>
<label for="setting-registration-restrict">Restrict registration to domain</label>
<p class="small">Enter a comma separated list of email domains you would like to restrict registration to. Users will be sent an email to confirm their address before being allowed to interact with the application.
<br> Note that users will be able to change their email addresses after successful registration.</p>
- <input type="text" id="setting-registration-restrict" name="setting-registration-restrict" placeholder="No restriction set" value="{{ Setting::get('registration-restrict', '') }}">
+ <input type="text" id="setting-registration-restrict" name="setting-registration-restrict" placeholder="No restriction set" value="{{ setting('registration-restrict', '') }}">