X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/ac80723058ab4c86e6bf024e0c75b60ab6c59624..refs/pull/422/head:/app/helpers.php diff --git a/app/helpers.php b/app/helpers.php index b5be0fd11..153f1e49f 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -37,6 +37,15 @@ function user() return auth()->user() ?: \BookStack\User::getDefault(); } +/** + * Check if current user is a signed in user. + * @return bool + */ +function signedInUser() +{ + return auth()->user() && !auth()->user()->isDefault(); +} + /** * Check if the current user has a permission. * If an ownable element is passed in the jointPermissions are checked against @@ -60,11 +69,12 @@ function userCan($permission, Ownable $ownable = null) * Helper to access system settings. * @param $key * @param bool $default - * @return mixed + * @return bool|string|\BookStack\Services\SettingService */ -function setting($key, $default = false) +function setting($key = null, $default = false) { - $settingService = app(\BookStack\Services\SettingService::class); + $settingService = resolve(\BookStack\Services\SettingService::class); + if (is_null($key)) return $settingService; return $settingService->get($key, $default); } @@ -116,6 +126,16 @@ function redirect($to = null, $status = 302, $headers = [], $secure = null) return app('redirect')->to($to, $status, $headers, $secure); } +function icon($name, $attrs = []) { + $iconPath = resource_path('assets/icons/' . $name . '.svg'); + $attrString = ' '; + foreach ($attrs as $attrName => $attr) { + $attrString .= $attrName . '="' . $attr . '" '; + } + $fileContents = file_get_contents($iconPath); + return str_replace('