Dan Brown

Added settings helper and formatted code in some files

...@@ -123,7 +123,7 @@ abstract class Entity extends Ownable ...@@ -123,7 +123,7 @@ abstract class Entity extends Ownable
123 123
124 // Ensure at least one exact term matches if in search 124 // Ensure at least one exact term matches if in search
125 if (count($exactTerms) > 0) { 125 if (count($exactTerms) > 0) {
126 - $search = $search->where(function($query) use ($exactTerms, $fieldsToSearch) { 126 + $search = $search->where(function ($query) use ($exactTerms, $fieldsToSearch) {
127 foreach ($exactTerms as $exactTerm) { 127 foreach ($exactTerms as $exactTerm) {
128 foreach ($fieldsToSearch as $field) { 128 foreach ($fieldsToSearch as $field) {
129 $query->orWhere($field, 'like', $exactTerm); 129 $query->orWhere($field, 'like', $exactTerm);
......
...@@ -71,7 +71,7 @@ class AuthController extends Controller ...@@ -71,7 +71,7 @@ class AuthController extends Controller
71 71
72 protected function checkRegistrationAllowed() 72 protected function checkRegistrationAllowed()
73 { 73 {
74 - if (!\Setting::get('registration-enabled')) { 74 + if (!setting('registration-enabled')) {
75 throw new UserRegistrationException('Registrations are currently disabled.', '/login'); 75 throw new UserRegistrationException('Registrations are currently disabled.', '/login');
76 } 76 }
77 } 77 }
...@@ -170,8 +170,8 @@ class AuthController extends Controller ...@@ -170,8 +170,8 @@ class AuthController extends Controller
170 */ 170 */
171 protected function registerUser(array $userData, $socialAccount = false) 171 protected function registerUser(array $userData, $socialAccount = false)
172 { 172 {
173 - if (\Setting::get('registration-restrict')) { 173 + if (setting('registration-restrict')) {
174 - $restrictedEmailDomains = explode(',', str_replace(' ', '', \Setting::get('registration-restrict'))); 174 + $restrictedEmailDomains = explode(',', str_replace(' ', '', setting('registration-restrict')));
175 $userEmailDomain = $domain = substr(strrchr($userData['email'], "@"), 1); 175 $userEmailDomain = $domain = substr(strrchr($userData['email'], "@"), 1);
176 if (!in_array($userEmailDomain, $restrictedEmailDomains)) { 176 if (!in_array($userEmailDomain, $restrictedEmailDomains)) {
177 throw new UserRegistrationException('That email domain does not have access to this application', '/register'); 177 throw new UserRegistrationException('That email domain does not have access to this application', '/register');
...@@ -183,7 +183,7 @@ class AuthController extends Controller ...@@ -183,7 +183,7 @@ class AuthController extends Controller
183 $newUser->socialAccounts()->save($socialAccount); 183 $newUser->socialAccounts()->save($socialAccount);
184 } 184 }
185 185
186 - if (\Setting::get('registration-confirmation') || \Setting::get('registration-restrict')) { 186 + if (setting('registration-confirmation') || setting('registration-restrict')) {
187 $newUser->email_confirmed = false; 187 $newUser->email_confirmed = false;
188 $newUser->save(); 188 $newUser->save();
189 $this->emailConfirmationService->sendConfirmation($newUser); 189 $this->emailConfirmationService->sendConfirmation($newUser);
......
...@@ -39,7 +39,7 @@ class Authenticate ...@@ -39,7 +39,7 @@ class Authenticate
39 return redirect()->guest('/register/confirm/awaiting'); 39 return redirect()->guest('/register/confirm/awaiting');
40 } 40 }
41 41
42 - if ($this->auth->guest() && !Setting::get('app-public')) { 42 + if ($this->auth->guest() && !setting('app-public')) {
43 if ($request->ajax()) { 43 if ($request->ajax()) {
44 return response('Unauthorized.', 401); 44 return response('Unauthorized.', 401);
45 } else { 45 } else {
......
...@@ -124,7 +124,7 @@ class PermissionsRepo ...@@ -124,7 +124,7 @@ class PermissionsRepo
124 // Prevent deleting admin role or default registration role. 124 // Prevent deleting admin role or default registration role.
125 if ($role->name === 'admin') { 125 if ($role->name === 'admin') {
126 throw new PermissionsException('The admin role cannot be deleted'); 126 throw new PermissionsException('The admin role cannot be deleted');
127 - } else if ($role->id == Setting::get('registration-role')) { 127 + } else if ($role->id == setting('registration-role')) {
128 throw new PermissionsException('This role cannot be deleted while set as the default registration role.'); 128 throw new PermissionsException('This role cannot be deleted while set as the default registration role.');
129 } 129 }
130 130
......
...@@ -77,7 +77,7 @@ class UserRepo ...@@ -77,7 +77,7 @@ class UserRepo
77 */ 77 */
78 public function attachDefaultRole($user) 78 public function attachDefaultRole($user)
79 { 79 {
80 - $roleId = Setting::get('registration-role'); 80 + $roleId = setting('registration-role');
81 if ($roleId === false) $roleId = $this->role->first()->id; 81 if ($roleId === false) $roleId = $this->role->first()->id;
82 $user->attachRoleId($roleId); 82 $user->attachRoleId($roleId);
83 } 83 }
......
...@@ -45,7 +45,7 @@ class EmailConfirmationService ...@@ -45,7 +45,7 @@ class EmailConfirmationService
45 'token' => $token, 45 'token' => $token,
46 ]); 46 ]);
47 $this->mailer->send('emails/email-confirmation', ['token' => $token], function (Message $message) use ($user) { 47 $this->mailer->send('emails/email-confirmation', ['token' => $token], function (Message $message) use ($user) {
48 - $appName = \Setting::get('app-name', 'BookStack'); 48 + $appName = setting('app-name', 'BookStack');
49 $message->to($user->email, $user->name)->subject('Confirm your email on ' . $appName . '.'); 49 $message->to($user->email, $user->name)->subject('Confirm your email on ' . $appName . '.');
50 }); 50 });
51 } 51 }
......
...@@ -79,7 +79,7 @@ class ImageService ...@@ -79,7 +79,7 @@ class ImageService
79 private function saveNew($imageName, $imageData, $type) 79 private function saveNew($imageName, $imageData, $type)
80 { 80 {
81 $storage = $this->getStorage(); 81 $storage = $this->getStorage();
82 - $secureUploads = Setting::get('app-secure-images'); 82 + $secureUploads = setting('app-secure-images');
83 $imageName = str_replace(' ', '-', $imageName); 83 $imageName = str_replace(' ', '-', $imageName);
84 84
85 if ($secureUploads) $imageName = str_random(16) . '-' . $imageName; 85 if ($secureUploads) $imageName = str_random(16) . '-' . $imageName;
......
...@@ -135,7 +135,7 @@ class SocialAuthService ...@@ -135,7 +135,7 @@ class SocialAuthService
135 135
136 // Otherwise let the user know this social account is not used by anyone. 136 // Otherwise let the user know this social account is not used by anyone.
137 $message = 'This ' . $socialDriver . ' account is not linked to any users. Please attach it in your profile settings'; 137 $message = 'This ' . $socialDriver . ' account is not linked to any users. Please attach it in your profile settings';
138 - if (\Setting::get('registration-enabled')) { 138 + if (setting('registration-enabled')) {
139 $message .= ' or, If you do not yet have an account, You can register an account using the ' . $socialDriver . ' option'; 139 $message .= ' or, If you do not yet have an account, You can register an account using the ' . $socialDriver . ' option';
140 } 140 }
141 throw new SocialSignInException($message . '.', '/login'); 141 throw new SocialSignInException($message . '.', '/login');
......
...@@ -59,3 +59,15 @@ function userCan($permission, \BookStack\Ownable $ownable = null) ...@@ -59,3 +59,15 @@ function userCan($permission, \BookStack\Ownable $ownable = null)
59 $hasAccess = $restrictionService->checkIfEntityRestricted($ownable, $action); 59 $hasAccess = $restrictionService->checkIfEntityRestricted($ownable, $action);
60 return $hasAccess && $hasPermission; 60 return $hasAccess && $hasPermission;
61 } 61 }
62 +
63 +/**
64 + * Helper to access system settings.
65 + * @param $key
66 + * @param bool $default
67 + * @return mixed
68 + */
69 +function setting($key, $default = false)
70 +{
71 + $settingService = app('BookStack\Services\SettingService');
72 + return $settingService->get($key, $default);
73 +}
......
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 - <title>{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ Setting::get('app-name', 'BookStack') }}</title> 4 + <title>{{ isset($pageTitle) ? $pageTitle . ' | ' : '' }}{{ setting('app-name', 'BookStack') }}</title>
5 5
6 <!-- Meta --> 6 <!-- Meta -->
7 <meta name="viewport" content="width=device-width"> 7 <meta name="viewport" content="width=device-width">
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
29 <div class="row"> 29 <div class="row">
30 <div class="col-lg-4 col-sm-4" ng-non-bindable> 30 <div class="col-lg-4 col-sm-4" ng-non-bindable>
31 <a href="/" class="logo"> 31 <a href="/" class="logo">
32 - @if(Setting::get('app-logo', '') !== 'none') 32 + @if(setting('app-logo', '') !== 'none')
33 - <img class="logo-image" src="{{ Setting::get('app-logo', '') === '' ? '/logo.png' : Setting::get('app-logo', '') }}" alt="Logo"> 33 + <img class="logo-image" src="{{ setting('app-logo', '') === '' ? '/logo.png' : setting('app-logo', '') }}" alt="Logo">
34 @endif 34 @endif
35 - <span class="logo-text">{{ Setting::get('app-name', 'BookStack') }}</span> 35 + <span class="logo-text">{{ setting('app-name', 'BookStack') }}</span>
36 </a> 36 </a>
37 </div> 37 </div>
38 <div class="col-lg-4 col-sm-3 text-center"> 38 <div class="col-lg-4 col-sm-3 text-center">
......