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