| 
									
										
										
										
											2016-09-03 19:08:58 +08:00
										 |  |  | <?php namespace BookStack\Providers; | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-25 19:30:50 +08:00
										 |  |  | use Blade; | 
					
						
							|  |  |  | use BookStack\Entities\Book; | 
					
						
							|  |  |  | use BookStack\Entities\Bookshelf; | 
					
						
							| 
									
										
										
										
											2019-04-08 01:28:11 +08:00
										 |  |  | use BookStack\Entities\BreadcrumbsViewComposer; | 
					
						
							| 
									
										
										
										
											2018-09-25 19:30:50 +08:00
										 |  |  | use BookStack\Entities\Chapter; | 
					
						
							|  |  |  | use BookStack\Entities\Page; | 
					
						
							|  |  |  | use BookStack\Settings\Setting; | 
					
						
							| 
									
										
										
										
											2018-09-25 23:58:03 +08:00
										 |  |  | use BookStack\Settings\SettingService; | 
					
						
							| 
									
										
										
										
											2018-09-25 19:30:50 +08:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\Relation; | 
					
						
							| 
									
										
										
										
											2019-04-08 01:28:11 +08:00
										 |  |  | use Illuminate\Support\Facades\View; | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  | use Illuminate\Support\ServiceProvider; | 
					
						
							| 
									
										
										
										
											2018-09-25 19:30:50 +08:00
										 |  |  | use Schema; | 
					
						
							| 
									
										
										
										
											2019-08-04 21:26:39 +08:00
										 |  |  | use URL; | 
					
						
							| 
									
										
										
										
											2016-12-31 22:38:04 +08:00
										 |  |  | use Validator; | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class AppServiceProvider extends ServiceProvider | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Bootstrap any application services. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function boot() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-08-04 21:26:39 +08:00
										 |  |  |         // Set root URL
 | 
					
						
							| 
									
										
										
										
											2019-09-01 19:07:51 +08:00
										 |  |  |         $appUrl = config('app.url'); | 
					
						
							|  |  |  |         if ($appUrl) { | 
					
						
							|  |  |  |             $isHttps = (strpos($appUrl, 'https://') === 0); | 
					
						
							|  |  |  |             URL::forceRootUrl($appUrl); | 
					
						
							|  |  |  |             URL::forceScheme($isHttps ? 'https' : 'http'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-08-04 21:26:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-22 03:43:15 +08:00
										 |  |  |         // Custom validation methods
 | 
					
						
							|  |  |  |         Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) { | 
					
						
							| 
									
										
										
										
											2020-04-05 23:15:05 +08:00
										 |  |  |             $validImageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'webp']; | 
					
						
							| 
									
										
										
										
											2019-03-22 03:43:15 +08:00
										 |  |  |             return in_array(strtolower($value->getClientOriginalExtension()), $validImageExtensions); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 03:07:18 +08:00
										 |  |  |         Validator::extend('no_double_extension', function ($attribute, $value, $parameters, $validator) { | 
					
						
							|  |  |  |             $uploadName = $value->getClientOriginalName(); | 
					
						
							|  |  |  |             return substr_count($uploadName, '.') < 2; | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-25 19:30:50 +08:00
										 |  |  |         // Custom blade view directives
 | 
					
						
							|  |  |  |         Blade::directive('icon', function ($expression) { | 
					
						
							| 
									
										
										
										
											2017-02-04 19:01:49 +08:00
										 |  |  |             return "<?php echo icon($expression); ?>"; | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2017-07-03 00:20:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-16 01:29:51 +08:00
										 |  |  |         Blade::directive('exposeTranslations', function ($expression) { | 
					
						
							| 
									
										
										
										
											2019-07-06 21:52:25 +08:00
										 |  |  |             return "<?php \$__env->startPush('translations'); ?>" . | 
					
						
							|  |  |  |                 "<?php foreach({$expression} as \$key): ?>" . | 
					
						
							|  |  |  |                 '<meta name="translation" key="<?php echo e($key); ?>" value="<?php echo e(trans($key)); ?>">' . "\n" . | 
					
						
							|  |  |  |                 "<?php endforeach; ?>" . | 
					
						
							|  |  |  |                 '<?php $__env->stopPush(); ?>'; | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 00:20:05 +08:00
										 |  |  |         // Allow longer string lengths after upgrade to utf8mb4
 | 
					
						
							| 
									
										
										
										
											2018-09-25 19:30:50 +08:00
										 |  |  |         Schema::defaultStringLength(191); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Set morph-map due to namespace changes
 | 
					
						
							|  |  |  |         Relation::morphMap([ | 
					
						
							|  |  |  |             'BookStack\\Bookshelf' => Bookshelf::class, | 
					
						
							|  |  |  |             'BookStack\\Book' => Book::class, | 
					
						
							|  |  |  |             'BookStack\\Chapter' => Chapter::class, | 
					
						
							|  |  |  |             'BookStack\\Page' => Page::class, | 
					
						
							|  |  |  |         ]); | 
					
						
							| 
									
										
										
										
											2019-04-08 01:28:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // View Composers
 | 
					
						
							|  |  |  |         View::composer('partials.breadcrumbs', BreadcrumbsViewComposer::class); | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Register any application services. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function register() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-01-29 00:58:52 +08:00
										 |  |  |         $this->app->singleton(SettingService::class, function ($app) { | 
					
						
							| 
									
										
										
										
											2017-02-06 02:57:57 +08:00
										 |  |  |             return new SettingService($app->make(Setting::class), $app->make('Illuminate\Contracts\Cache\Repository')); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | } |