| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-18 00:56:55 +08:00
										 |  |  | namespace BookStack\Settings; | 
					
						
							| 
									
										
										
										
											2015-08-30 22:31:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-18 00:56:55 +08:00
										 |  |  | use BookStack\Activity\ActivityType; | 
					
						
							| 
									
										
										
										
											2023-05-19 03:53:39 +08:00
										 |  |  | use BookStack\Http\Controller; | 
					
						
							| 
									
										
										
										
											2023-05-18 00:56:55 +08:00
										 |  |  | use BookStack\Users\Models\User; | 
					
						
							| 
									
										
										
										
											2015-08-30 22:31:16 +08:00
										 |  |  | use Illuminate\Http\Request; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SettingController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-03-28 18:16:20 +08:00
										 |  |  |     protected array $settingCategories = ['features', 'customization', 'registration']; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-30 22:31:16 +08:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2022-04-25 01:22:40 +08:00
										 |  |  |      * Handle requests to the settings index path. | 
					
						
							| 
									
										
										
										
											2015-08-30 22:31:16 +08:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-03-31 02:15:24 +08:00
										 |  |  |     public function index() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return redirect('/settings/features'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Display the settings for the given category. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function category(string $category) | 
					
						
							| 
									
										
										
										
											2015-08-30 22:31:16 +08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-03-28 18:16:20 +08:00
										 |  |  |         $this->ensureCategoryExists($category); | 
					
						
							| 
									
										
										
										
											2016-02-28 03:24:42 +08:00
										 |  |  |         $this->checkPermission('settings-manage'); | 
					
						
							| 
									
										
										
										
											2018-05-28 02:40:07 +08:00
										 |  |  |         $this->setPageTitle(trans('settings.settings')); | 
					
						
							| 
									
										
										
										
											2016-05-04 04:10:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Get application version
 | 
					
						
							| 
									
										
										
										
											2016-10-31 01:44:00 +08:00
										 |  |  |         $version = trim(file_get_contents(base_path('version'))); | 
					
						
							| 
									
										
										
										
											2016-05-04 04:10:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 18:09:55 +08:00
										 |  |  |         return view('settings.' . $category, [ | 
					
						
							|  |  |  |             'category'  => $category, | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  |             'version'   => $version, | 
					
						
							| 
									
										
										
										
											2023-09-16 20:18:35 +08:00
										 |  |  |             'guestUser' => User::getGuest(), | 
					
						
							| 
									
										
										
										
											2019-02-16 22:17:35 +08:00
										 |  |  |         ]); | 
					
						
							| 
									
										
										
										
											2015-08-30 22:31:16 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Update the specified settings in storage. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-01-25 19:03:19 +08:00
										 |  |  |     public function update(Request $request, AppSettingsStore $store, string $category) | 
					
						
							| 
									
										
										
										
											2015-08-30 22:31:16 +08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-03-28 18:16:20 +08:00
										 |  |  |         $this->ensureCategoryExists($category); | 
					
						
							| 
									
										
										
										
											2019-09-19 22:12:10 +08:00
										 |  |  |         $this->preventAccessInDemoMode(); | 
					
						
							| 
									
										
										
										
											2016-02-28 03:24:42 +08:00
										 |  |  |         $this->checkPermission('settings-manage'); | 
					
						
							| 
									
										
										
										
											2019-05-04 22:48:15 +08:00
										 |  |  |         $this->validate($request, [ | 
					
						
							| 
									
										
										
										
											2023-01-25 19:03:19 +08:00
										 |  |  |             'app_logo' => ['nullable', ...$this->getImageValidationRules()], | 
					
						
							|  |  |  |             'app_icon' => ['nullable', ...$this->getImageValidationRules()], | 
					
						
							| 
									
										
										
										
											2019-05-04 22:48:15 +08:00
										 |  |  |         ]); | 
					
						
							| 
									
										
										
										
											2016-01-01 01:57:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-25 19:03:19 +08:00
										 |  |  |         $store->storeFromUpdateRequest($request, $category); | 
					
						
							| 
									
										
										
										
											2022-03-28 18:09:55 +08:00
										 |  |  |         $this->logActivity(ActivityType::SETTINGS_UPDATE, $category); | 
					
						
							| 
									
										
										
										
											2021-06-26 23:23:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-05 16:33:25 +08:00
										 |  |  |         return redirect("/settings/{$category}"); | 
					
						
							| 
									
										
										
										
											2015-08-30 22:31:16 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-03-28 18:16:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     protected function ensureCategoryExists(string $category): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (!in_array($category, $this->settingCategories)) { | 
					
						
							|  |  |  |             abort(404); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-08-30 22:31:16 +08:00
										 |  |  | } |