| 
									
										
										
										
											2015-12-17 01:09:44 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-06 02:09:21 +08:00
										 |  |  | if (!function_exists('versioned_asset')) { | 
					
						
							| 
									
										
										
										
											2015-12-17 01:09:44 +08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Get the path to a versioned file. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-03-06 02:09:21 +08:00
										 |  |  |      * @param  string $file | 
					
						
							| 
									
										
										
										
											2015-12-17 01:09:44 +08:00
										 |  |  |      * @return string | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @throws \InvalidArgumentException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function versioned_asset($file) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         static $manifest = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (is_null($manifest)) { | 
					
						
							|  |  |  |             $manifest = json_decode(file_get_contents(public_path('build/manifest.json')), true); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($manifest[$file])) { | 
					
						
							|  |  |  |             return '/' . $manifest[$file]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (file_exists(public_path($file))) { | 
					
						
							|  |  |  |             return '/' . $file; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         throw new InvalidArgumentException("File {$file} not defined in asset manifest."); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-02-28 03:24:42 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Check if the current user has a permission. | 
					
						
							| 
									
										
										
										
											2016-05-02 04:20:50 +08:00
										 |  |  |  * If an ownable element is passed in the jointPermissions are checked against | 
					
						
							| 
									
										
										
										
											2016-02-28 03:24:42 +08:00
										 |  |  |  * that particular item. | 
					
						
							|  |  |  |  * @param $permission | 
					
						
							|  |  |  |  * @param \BookStack\Ownable $ownable | 
					
						
							|  |  |  |  * @return mixed | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function userCan($permission, \BookStack\Ownable $ownable = null) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if ($ownable === null) { | 
					
						
							|  |  |  |         return auth()->user() && auth()->user()->can($permission); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-01 04:31:21 +08:00
										 |  |  |     // Check permission on ownable item
 | 
					
						
							| 
									
										
										
										
											2016-05-02 04:20:50 +08:00
										 |  |  |     $permissionService = app('BookStack\Services\PermissionService'); | 
					
						
							|  |  |  |     return $permissionService->checkEntityUserAccess($ownable, $permission); | 
					
						
							| 
									
										
										
										
											2016-03-06 20:55:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Helper to access system settings. | 
					
						
							|  |  |  |  * @param $key | 
					
						
							|  |  |  |  * @param bool $default | 
					
						
							|  |  |  |  * @return mixed | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function setting($key, $default = false) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     $settingService = app('BookStack\Services\SettingService'); | 
					
						
							|  |  |  |     return $settingService->get($key, $default); | 
					
						
							|  |  |  | } |