PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.10.02
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.10.02
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
fluent-booking / app / Http / Controllers / SettingsController.php

SettingsController.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.10.02, at app/Http/Controllers/SettingsController.php

317 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App\Http\Controllers;
4
5 use FluentBooking\App\App;
6 use FluentBooking\App\Services\GlobalModules\GlobalModules;
7 use FluentBooking\App\Hooks\Handlers\AdminMenuHandler;
8 use FluentBooking\App\Services\Helper;
9 use FluentBooking\App\Services\Libs\Countries;
10 use FluentBooking\App\Services\OnboardingService;
11 use FluentBooking\Framework\Http\Request\Request;
12 use FluentBooking\Framework\Support\Arr;
13
14 class SettingsController extends Controller
15 {
16 public function getSettingsMenu()
17 {
18 return [
19 'menu_items' => AdminMenuHandler::settingsMenuItems()
20 ];
21 }
22
23 public function getGeneralSettings()
24 {
25 $settings = Helper::getGlobalSettings();
26
27 $settings['emailingFields'] = [
28 'from_name' => [
29 'wrapper_class' => 'fc_item_half',
30 'type' => 'input-text',
31 'placeholder' => __('From Name for emails', 'fluent-booking'),
32 'label' => __('From Name', 'fluent-booking'),
33 'help' => __('Default Name that will be used to send email)', 'fluent-booking')
34 ],
35 'from_email' => [
36 'wrapper_class' => 'fc_item_half',
37 'type' => 'input-or-select',
38 'placeholder' => 'name@domain.com',
39 'data_type' => 'email',
40 'options' => Helper::getVerifiedSenders(),
41 'label' => __('From Email Address', 'fluent-booking'),
42 'help' => __('Provide Valid Email Address that will be used to send emails', 'fluent-booking'),
43 'inline_help' => __('email as per your domain/SMTP settings', 'fluent-booking')
44 ],
45 'reply_to_name' => [
46 'wrapper_class' => 'fc_item_half',
47 'type' => 'input-text',
48 'placeholder' => __('Reply to Name', 'fluent-booking'),
49 'label' => __('Reply to Name (Optional)', 'fluent-booking'),
50 'help' => __('Default Reply to Name (Optional)', 'fluent-booking')
51 ],
52 'reply_to_email' => [
53 'wrapper_class' => 'fc_item_half',
54 'type' => 'input-text',
55 'placeholder' => 'name@domain.com',
56 'data_type' => 'email',
57 'label' => __('Reply to Email (Optional)', 'fluent-booking'),
58 'help' => __('Default Reply to Email (Optional)', 'fluent-booking')
59 ],
60 'use_host_name' => [
61 'wrapper_class' => 'fc_full_width fc_mb_0',
62 'type' => 'inline-checkbox',
63 'checkbox_label' => __('Use host name as From Name for booking emails to guests', 'fluent-booking'),
64 'true_label' => 'yes',
65 'false_label' => 'no',
66 ],
67 'use_host_email_on_reply' => [
68 'wrapper_class' => 'fc_full_width fc_mb_0',
69 'type' => 'inline-checkbox',
70 'checkbox_label' => __('Use host email for reply-to value for booking emails to guests', 'fluent-booking'),
71 'true_label' => 'yes',
72 'false_label' => 'no',
73 ],
74 'attach_ics_on_confirmation' => [
75 'wrapper_class' => 'fc_full_width fc_mb_0',
76 'type' => 'inline-checkbox',
77 'checkbox_label' => __('Include ICS file attachment in booking confirmation emails', 'fluent-booking'),
78 'true_label' => 'yes',
79 'false_label' => 'no',
80 ],
81 'email_footer' => [
82 'wrapper_class' => 'fc_full_width fc_mb_0 fc_wp_editor',
83 'type' => 'wp-editor-field',
84 'label' => __('Email Footer for Booking related emails (Optional)', 'fluent-booking'),
85 'inline_help' => __('You may include your business name, address etc here, for example: <br />You have received this email because signed up for an event or made a booking on our website.', 'fluent-booking')
86 ]
87 ];
88
89 $settings['all_countries'] = Countries::get();
90
91 return apply_filters('fluent_booking/general_settings', $settings);
92 }
93
94 public function updateGeneralSettings(Request $request)
95 {
96 $settings = [
97 'emailing' => $request->get('emailing', []),
98 'administration' => $request->get('administration', []),
99 ];
100
101 $formattedSettings = [];
102
103 foreach ($settings as $settingKey => $setting) {
104 $santizedSettings = array_map('sanitize_text_field', $setting);
105 if ($settingKey == 'emailing') {
106 $santizedSettings['email_footer'] = wp_kses_post($setting['email_footer']);
107 }
108 $formattedSettings[$settingKey] = $santizedSettings;
109 }
110 $formattedSettings['time_format'] = $request->get('timeFormat');
111
112 update_option('_fluent_booking_settings', $formattedSettings, 'no');
113
114 return [
115 'message' => __('Settings updated successfully', 'fluent-booking'),
116 'settings' => $formattedSettings
117 ];
118 }
119
120 public function updatePaymentSettings(Request $request)
121 {
122 $paymentSettings = $request->get('payments', []);
123
124 $currency = Arr::get($paymentSettings, 'currency', 'USD');
125 $isActive = Arr::get($paymentSettings, 'is_active', 'no');
126 $numberFormat = Arr::get($paymentSettings, 'number_format', 'comma_separated');
127 $currencyPosition = Arr::get($paymentSettings, 'currency_position', 'left');
128
129 update_option('fluent_booking_global_payment_settings', [
130 'currency' => sanitize_text_field($currency),
131 'is_active' => $isActive == 'yes' ? 'yes' : 'no',
132 'number_format' => $numberFormat == 'comma_separated' ? 'comma_separated' : 'dot_separated',
133 'currency_position' => sanitize_text_field($currencyPosition)
134 ], 'no');
135
136 return [
137 'message' => __('Settings updated successfully', 'fluent-booking')
138 ];
139 }
140
141 public function updateThemeSettings(Request $request)
142 {
143 $themeSettings = sanitize_text_field($request->get('theme'));
144
145 $bookingOption = get_option('_fluent_booking_settings', []);
146
147 $bookingOption['theme'] = $themeSettings;
148
149 update_option('_fluent_booking_settings', $bookingOption, 'no');
150
151 return [
152 'message' => __('Settings updated successfully', 'fluent-booking')
153 ];
154 }
155
156 public function getGlobalModules(Request $request)
157 {
158 $settings = Helper::getGlobalModuleSettings();
159
160
161 if (!$settings) {
162 $settings = (object)[];
163 }
164
165 $featuresPrefs = Helper::getPrefSettings(false);
166
167 if (empty($featuresPrefs['frontend']['render_type'])) {
168 $featuresPrefs['frontend']['render_type'] = 'standalone';
169 }
170
171 $featuresPrefs['panel_url'] = Helper::getAppBaseUrl();
172
173 return [
174 'settings' => $settings,
175 'modules' => (new GlobalModules())->getAllModules(),
176 'featureModules' => $featuresPrefs
177 ];
178 }
179
180 public function updateGlobalModules(Request $request)
181 {
182 $settings = $request->get('settings', []);
183
184 $modules = (new GlobalModules())->getAllModules();
185
186 $formattedModules = [];
187
188 foreach ($settings as $settingKey => $value) {
189 if (!isset($modules[$settingKey])) {
190 continue;
191 }
192 $formattedModules[$settingKey] = $value == 'yes' ? 'yes' : 'no';
193 }
194
195 Helper::updateGlobalModuleSettings($formattedModules);
196
197 return [
198 'message' => __('Settings updated successfully', 'fluent-booking'),
199 ];
200 }
201
202 public function getPages(Request $request)
203 {
204 $db = App::getInstance('db');
205
206 $allPages = $db->table('posts')->where('post_type', 'page')
207 ->where('post_status', 'publish')
208 ->select(['ID', 'post_title', 'post_name'])
209 ->orderBy('post_title', 'ASC')
210 ->get();
211
212 $pages = [];
213 foreach ($allPages as $page) {
214 $pages[] = [
215 'id' => $page->ID,
216 'name' => $page->post_name,
217 'title' => $page->post_title ? $page->post_title : __('(no title)', 'fluent-booking')
218 ];
219 }
220
221 return [
222 'pages' => $pages
223 ];
224 }
225
226 public function saveAddonsSettings(Request $request)
227 {
228 if (!defined('FLUENT_BOOKING_PRO_DIR_FILE')) {
229 return $this->sendError([
230 'message' => __('This feature is only available in FluentBooking Pro', 'fluent-booking')
231 ]);
232 }
233
234 $settings = $request->get('settings', []);
235
236 $prefSettings = Helper::getPrefSettings(false);
237
238 $settings = wp_parse_args($settings, $prefSettings);
239
240 $settings = Arr::only($settings, array_keys($prefSettings));
241 $settings['frontend']['slug'] = sanitize_title($settings['frontend']['slug']);
242
243 if (empty($settings['frontend']['slug'])) {
244 $settings['frontend']['slug'] = 'projects';
245 }
246
247 if (defined('FLUENT_BOOKING_ADMIN_SLUG') && FLUENT_BOOKING_FRONT_SLUG) {
248 $settings['frontend']['slug'] = FLUENT_BOOKING_FRONT_SLUG;
249 }
250
251 do_action('fluent_booking/saving_addons', $settings, $prefSettings);
252
253 update_option('fluent_booking_modules', $settings, 'yes');
254
255 return $this->sendSuccess([
256 'message' => __('Settings are saved', 'fluent-booking'),
257 'featureModules' => $settings
258 ]);
259 }
260
261 public function installPlugin(Request $request)
262 {
263 if (!current_user_can('install_plugins')) {
264 return $this->sendError([
265 'message' => __('You do not have permission to install plugins', 'fluent-booking')
266 ]);
267 }
268
269 $pluginId = $request->get('plugin_id');
270
271 $allowedPlugins = [
272 'fluent-smtp' => [
273 'name' => 'FluentSMTP',
274 'repo-slug' => 'fluent-smtp',
275 'file' => 'fluent-smtp.php',
276 ],
277 'fluent-booking' => [
278 'name' => 'FluentBooking',
279 'repo-slug' => 'fluent-booking',
280 'file' => 'fluent-booking.php',
281 ],
282 'fluentform' => [
283 'name' => 'FluentForm',
284 'repo-slug' => 'fluentform',
285 'file' => 'fluentform.php',
286 ],
287 'fluent-crm' => [
288 'name' => 'FluentCRM',
289 'repo-slug' => 'fluent-crm',
290 'file' => 'fluent-crm.php',
291 ],
292 'fluent-boards' => [
293 'name' => 'FluentBoards',
294 'repo-slug' => 'fluent-boards',
295 'file' => 'fluent-boards.php',
296 ],
297 'fluent-cart' => [
298 'name' => 'FluentCart',
299 'repo-slug' => 'fluent-cart',
300 'file' => 'fluent-cart.php',
301 ]
302 ];
303
304 if (!isset($allowedPlugins[$pluginId])) {
305 return $this->sendError([
306 'message' => __('This action is not allowed', 'fluent-booking')
307 ]);
308 }
309
310 OnboardingService::backgroundInstaller($allowedPlugins[$pluginId]);
311
312 return $this->sendSuccess([
313 'message' => __('Plugin has been installed Successfully', 'fluent-booking')
314 ]);
315 }
316 }
317