PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.5.1
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.5.1
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.5.1, at app/Http/Controllers/SettingsController.php

421 lines 15.5 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\Framework\Http\Request\Request;
11 use FluentBooking\Framework\Support\Arr;
12
13 class SettingsController extends Controller
14 {
15 public function getSettingsMenu()
16 {
17 return [
18 'menu_items' => AdminMenuHandler::settingsMenuItems()
19 ];
20 }
21
22 public function getGeneralSettings()
23 {
24 $settings = Helper::getGlobalSettings();
25
26 $settings['emailingFields'] = [
27 'from_name' => [
28 'wrapper_class' => 'fc_item_half',
29 'type' => 'input-text',
30 'placeholder' => __('From Name for emails', 'fluent-booking'),
31 'label' => __('From Name', 'fluent-booking'),
32 'help' => __('Default Name that will be used to send email)', 'fluent-booking')
33 ],
34 'from_email' => [
35 'wrapper_class' => 'fc_item_half',
36 'type' => 'input-or-select',
37 'placeholder' => 'name@domain.com',
38 'data_type' => 'email',
39 'options' => Helper::getVerifiedSenders(),
40 'label' => __('From Email Address', 'fluent-booking'),
41 'help' => __('Provide Valid Email Address that will be used to send emails', 'fluent-booking'),
42 'inline_help' => __('email as per your domain/SMTP settings', 'fluent-booking')
43 ],
44 'reply_to_name' => [
45 'wrapper_class' => 'fc_item_half',
46 'type' => 'input-text',
47 'placeholder' => __('Reply to Name', 'fluent-booking'),
48 'label' => __('Reply to Name (Optional)', 'fluent-booking'),
49 'help' => __('Default Reply to Name (Optional)', 'fluent-booking')
50 ],
51 'reply_to_email' => [
52 'wrapper_class' => 'fc_item_half',
53 'type' => 'input-text',
54 'placeholder' => 'name@domain.com',
55 'data_type' => 'email',
56 'label' => __('Reply to Email (Optional)', 'fluent-booking'),
57 'help' => __('Default Reply to Email (Optional)', 'fluent-booking')
58 ],
59 'use_host_name' => [
60 'wrapper_class' => 'fc_full_width fc_mb_0',
61 'type' => 'inline-checkbox',
62 'checkbox_label' => __('Use host name as From Name for booking emails to guests', 'fluent-booking'),
63 'true_label' => 'yes',
64 'false_label' => 'no',
65 ],
66 'use_host_email_on_reply' => [
67 'wrapper_class' => 'fc_full_width fc_mb_0',
68 'type' => 'inline-checkbox',
69 'checkbox_label' => __('Use host email for reply-to value for booking emails to guests', 'fluent-booking'),
70 'true_label' => 'yes',
71 'false_label' => 'no',
72 ],
73 'attach_ics_on_confirmation' => [
74 'wrapper_class' => 'fc_full_width fc_mb_0',
75 'type' => 'inline-checkbox',
76 'checkbox_label' => __('Include ICS file attachment in booking confirmation emails', 'fluent-booking'),
77 'true_label' => 'yes',
78 'false_label' => 'no',
79 ],
80 'email_footer' => [
81 'wrapper_class' => 'fc_full_width fc_mb_0 fc_wp_editor',
82 'type' => 'wp-editor-field',
83 'label' => __('Email Footer for Booking related emails (Optional)', 'fluent-booking'),
84 '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')
85 ]
86 ];
87
88 $settings['all_countries'] = Countries::get();
89
90 return apply_filters('fluent_booking/general_settings', $settings);
91 }
92
93 public function updateGeneralSettings(Request $request)
94 {
95 $settings = [
96 'emailing' => $request->get('emailing', []),
97 'administration' => $request->get('administration', []),
98 ];
99
100 $formattedSettings = [];
101
102 foreach ($settings as $settingKey => $setting) {
103 $santizedSettings = array_map('sanitize_text_field', $setting);
104 if ($settingKey == 'emailing') {
105 $santizedSettings['email_footer'] = wp_kses_post($setting['email_footer']);
106 }
107 $formattedSettings[$settingKey] = $santizedSettings;
108 }
109 $formattedSettings['time_format'] = $request->get('timeFormat');
110
111 update_option('_fluent_booking_settings', $formattedSettings, 'no');
112
113 return [
114 'message' => __('Settings updated successfully', 'fluent-booking'),
115 'settings' => $formattedSettings
116 ];
117 }
118
119 public function updatePaymentSettings(Request $request)
120 {
121 $paymentSettings = $request->get('payments', []);
122
123 $currency = Arr::get($paymentSettings, 'currency');
124 $isActive = Arr::get($paymentSettings, 'is_active', 'no');
125
126 update_option('fluent_booking_global_payment_settings', [
127 'currency' => sanitize_text_field($currency),
128 'is_active' => ($isActive == 'yes') ? 'yes' : 'no'
129 ], 'no');
130
131 return [
132 'message' => __('Settings updated successfully', 'fluent-booking')
133 ];
134 }
135
136 public function updateThemeSettings(Request $request)
137 {
138 $themeSettings = sanitize_text_field($request->get('theme'));
139
140 $bookingOption = get_option('_fluent_booking_settings', []);
141
142 $bookingOption['theme'] = $themeSettings;
143
144 update_option('_fluent_booking_settings', $bookingOption, 'no');
145
146 return [
147 'message' => __('Settings updated successfully', 'fluent-booking')
148 ];
149 }
150
151 public function getGlobalModules(Request $request)
152 {
153 $settings = Helper::getGlobalModuleSettings();
154
155
156 if (!$settings) {
157 $settings = (object)[];
158 }
159
160 $featuresPrefs = Helper::getPrefSettins(false);
161
162 if (empty($featuresPrefs['frontend']['render_type'])) {
163 $featuresPrefs['frontend']['render_type'] = 'standalone';
164 }
165
166 $featuresPrefs['panel_url'] = Helper::getAppBaseUrl();
167
168 return [
169 'settings' => $settings,
170 'modules' => (new GlobalModules())->getAllModules(),
171 'featureModules' => $featuresPrefs
172 ];
173 }
174
175 public function updateGlobalModules(Request $request)
176 {
177 $settings = $request->get('settings', []);
178
179 $modules = (new GlobalModules())->getAllModules();
180
181 $formattedModules = [];
182
183 foreach ($settings as $settingKey => $value) {
184 if (!isset($modules[$settingKey])) {
185 continue;
186 }
187 $formattedModules[$settingKey] = $value == 'yes' ? 'yes' : 'no';
188 }
189
190 Helper::updateGlobalModuleSettings($formattedModules);
191
192 return [
193 'message' => __('Settings updated successfully', 'fluent-booking'),
194 ];
195 }
196
197 public function getPages(Request $request)
198 {
199
200 $db = App::getInstance('db');
201
202 $allPages = $db->table('posts')->where('post_type', 'page')
203 ->where('post_status', 'publish')
204 ->select(['ID', 'post_title'])
205 ->orderBy('post_title', 'ASC')
206 ->get();
207
208 $pages = [];
209 foreach ($allPages as $page) {
210 $pages[] = [
211 'id' => $page->ID,
212 'title' => $page->post_title ? $page->post_title : __('(no title)', 'fluent-boards')
213 ];
214 }
215
216 return [
217 'pages' => $pages
218 ];
219 }
220
221 public function saveAddonsSettings(Request $request)
222 {
223 if (!defined('FLUENT_BOOKING_PRO_DIR_FILE')) {
224 return $this->sendError([
225 'message' => __('This feature is only available in FluentBooking Pro', 'fluent-booking')
226 ]);
227 }
228
229 $settings = $request->get('settings', []);
230
231 $prefSettings = Helper::getPrefSettins(false);
232
233 $settings = wp_parse_args($settings, $prefSettings);
234
235 $settings = Arr::only($settings, array_keys($prefSettings));
236 $settings['frontend']['slug'] = sanitize_title($settings['frontend']['slug']);
237
238 if (empty($settings['frontend']['slug'])) {
239 $settings['frontend']['slug'] = 'projects';
240 }
241
242 if (defined('FLUENT_BOOKING_ADMIN_SLUG') && FLUENT_BOOKING_FRONT_SLUG) {
243 $settings['frontend']['slug'] = FLUENT_BOOKING_FRONT_SLUG;
244 }
245
246 do_action('fluent_booking/saving_addons', $settings, $prefSettings);
247
248 update_option('fluent_booking_modules', $settings, 'yes');
249
250 return $this->sendSuccess([
251 'message' => __('Settings are saved', 'fluent-booking'),
252 'featureModules' => $settings
253 ]);
254 }
255
256 public function installPlugin(Request $request)
257 {
258 $pluginId = $request->get('plugin_id');
259
260 $allowedPlugins = [
261 'fluent-smtp' => [
262 'name' => 'FluentSMTP',
263 'repo-slug' => 'fluent-smtp',
264 'file' => 'fluent-smtp.php',
265 ],
266 'fluent-booking' => [
267 'name' => 'FluentBooking',
268 'repo-slug' => 'fluent-booking',
269 'file' => 'fluent-booking.php',
270 ],
271 'fluentform' => [
272 'name' => 'FluentForm',
273 'repo-slug' => 'fluentform',
274 'file' => 'fluentform.php',
275 ],
276 'fluent-crm' => [
277 'name' => 'FluentCRM',
278 'repo-slug' => 'fluent-crm',
279 'file' => 'fluent-crm.php',
280 ],
281 'fluent-boards' => [
282 'name' => 'FluentBoards',
283 'repo-slug' => 'fluent-boards',
284 'file' => 'fluent-boards.php',
285 ],
286 ];
287
288 if (!isset($allowedPlugins[$pluginId])) {
289 return $this->sendError([
290 'message' => __('This action is not allowed', 'fluent-booking')
291 ]);
292 }
293
294 $this->backgroundInstaller($allowedPlugins[$pluginId], $pluginId);
295
296 return $this->sendSuccess([
297 'message' => __('Plugin is being installed in the background', 'fluent-booking')
298 ]);
299 }
300
301 private function backgroundInstaller($plugin_to_install, $plugin_id)
302 {
303 if (!empty($plugin_to_install['repo-slug'])) {
304 require_once ABSPATH . 'wp-admin/includes/file.php';
305 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
306 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
307 require_once ABSPATH . 'wp-admin/includes/plugin.php';
308
309 WP_Filesystem();
310
311 $skin = new \Automatic_Upgrader_Skin();
312 $upgrader = new \WP_Upgrader($skin);
313 $installed_plugins = array_reduce(array_keys(\get_plugins()), array($this, 'associate_plugin_file'), array());
314 $plugin_slug = $plugin_to_install['repo-slug'];
315 $plugin_file = isset($plugin_to_install['file']) ? $plugin_to_install['file'] : $plugin_slug . '.php';
316 $installed = false;
317 $activate = false;
318
319 // See if the plugin is installed already.
320 if (isset($installed_plugins[$plugin_file])) {
321 $installed = true;
322 $activate = !is_plugin_active($installed_plugins[$plugin_file]);
323 }
324
325 // Install this thing!
326 if (!$installed) {
327 // Suppress feedback.
328 ob_start();
329
330 try {
331 $plugin_information = plugins_api(
332 'plugin_information',
333 array(
334 'slug' => $plugin_slug,
335 'fields' => array(
336 'short_description' => false,
337 'sections' => false,
338 'requires' => false,
339 'rating' => false,
340 'ratings' => false,
341 'downloaded' => false,
342 'last_updated' => false,
343 'added' => false,
344 'tags' => false,
345 'homepage' => false,
346 'donate_link' => false,
347 'author_profile' => false,
348 'author' => false,
349 ),
350 )
351 );
352
353 if (is_wp_error($plugin_information)) {
354 throw new \Exception($plugin_information->get_error_message());
355 }
356
357 $package = $plugin_information->download_link;
358 $download = $upgrader->download_package($package);
359
360 if (is_wp_error($download)) {
361 throw new \Exception($download->get_error_message());
362 }
363
364 $working_dir = $upgrader->unpack_package($download, true);
365
366 if (is_wp_error($working_dir)) {
367 throw new \Exception($working_dir->get_error_message());
368 }
369
370 $result = $upgrader->install_package(
371 array(
372 'source' => $working_dir,
373 'destination' => WP_PLUGIN_DIR,
374 'clear_destination' => false,
375 'abort_if_destination_exists' => false,
376 'clear_working' => true,
377 'hook_extra' => array(
378 'type' => 'plugin',
379 'action' => 'install',
380 ),
381 )
382 );
383
384 if (is_wp_error($result)) {
385 throw new \Exception($result->get_error_message());
386 }
387
388 $activate = true;
389
390 } catch (\Exception $e) {
391 }
392
393 // Discard feedback.
394 ob_end_clean();
395 }
396
397 wp_clean_plugins_cache();
398
399 // Activate this thing.
400 if ($activate) {
401 try {
402 $result = activate_plugin($installed ? $installed_plugins[$plugin_file] : $plugin_slug . '/' . $plugin_file);
403
404 if (is_wp_error($result)) {
405 throw new \Exception($result->get_error_message());
406 }
407 } catch (\Exception $e) {
408 }
409 }
410 }
411 }
412
413 private function associate_plugin_file($plugins, $key)
414 {
415 $path = explode('/', $key);
416 $filename = end($path);
417 $plugins[$filename] = $key;
418 return $plugins;
419 }
420 }
421