| @@ -5,9 +5,11 @@ | ||
| 5 | 5 | use FluentBooking\App\App; |
| 6 | 6 | use FluentBooking\App\Services\GlobalModules\GlobalModules; |
| 7 | 7 | use FluentBooking\App\Hooks\Handlers\AdminMenuHandler; |
| 8 | 8 | use FluentBooking\App\Services\Helper; |
| 9 | +use FluentBooking\App\Services\CurrenciesHelper; | |
| 9 | 10 | use FluentBooking\App\Services\Libs\Countries; |
| 11 | +use FluentBooking\App\Services\OnboardingService; | |
| 10 | 12 | use FluentBooking\Framework\Http\Request\Request; |
| 11 | 13 | use FluentBooking\Framework\Support\Arr; |
| 12 | 14 | |
| 13 | 15 | class SettingsController extends Controller |
| @@ -80,9 +82,9 @@ | ||
| 80 | 82 | 'email_footer' => [ |
| 81 | 83 | 'wrapper_class' => 'fc_full_width fc_mb_0 fc_wp_editor', |
| 82 | 84 | 'type' => 'wp-editor-field', |
| 83 | 85 | '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') | |
| 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') | |
| 85 | 87 | ] |
| 86 | 88 | ]; |
| 87 | 89 | |
| 88 | 90 | $settings['all_countries'] = Countries::get(); |
| @@ -119,16 +121,22 @@ | ||
| 119 | 121 | public function updatePaymentSettings(Request $request) |
| 120 | 122 | { |
| 121 | 123 | $paymentSettings = $request->get('payments', []); |
| 122 | 124 | |
| 123 | - $currency = Arr::get($paymentSettings, 'currency'); | |
| 125 | + $currency = Arr::get($paymentSettings, 'currency', 'USD'); | |
| 124 | 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'); | |
| 125 | 129 | |
| 126 | 130 | update_option('fluent_booking_global_payment_settings', [ |
| 127 | - 'currency' => sanitize_text_field($currency), | |
| 128 | - 'is_active' => ($isActive == 'yes') ? 'yes' : 'no' | |
| 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) | |
| 129 | 135 | ], 'no'); |
| 130 | 136 | |
| 137 | + CurrenciesHelper::getGlobalCurrencySettings(true); | |
| 138 | + | |
| 131 | 139 | return [ |
| 132 | 140 | 'message' => __('Settings updated successfully', 'fluent-booking') |
| 133 | 141 | ]; |
| 134 | 142 | } |
| @@ -156,9 +164,9 @@ | ||
| 156 | 164 | if (!$settings) { |
| 157 | 165 | $settings = (object)[]; |
| 158 | 166 | } |
| 159 | 167 | |
| 160 | - $featuresPrefs = Helper::getPrefSettins(false); | |
| 168 | + $featuresPrefs = Helper::getPrefSettings(false); | |
| 161 | 169 | |
| 162 | 170 | if (empty($featuresPrefs['frontend']['render_type'])) { |
| 163 | 171 | $featuresPrefs['frontend']['render_type'] = 'standalone'; |
| 164 | 172 | } |
| @@ -195,9 +203,8 @@ | ||
| 195 | 203 | } |
| 196 | 204 | |
| 197 | 205 | public function getPages(Request $request) |
| 198 | 206 | { |
| 199 | - | |
| 200 | 207 | $db = App::getInstance('db'); |
| 201 | 208 | |
| 202 | 209 | $allPages = $db->table('posts')->where('post_type', 'page') |
| 203 | 210 | ->where('post_status', 'publish') |
| @@ -209,9 +216,9 @@ | ||
| 209 | 216 | foreach ($allPages as $page) { |
| 210 | 217 | $pages[] = [ |
| 211 | 218 | 'id' => $page->ID, |
| 212 | 219 | 'name' => $page->post_name, |
| 213 | - 'title' => $page->post_title ? $page->post_title : __('(no title)', 'fluent-boards') | |
| 220 | + 'title' => $page->post_title ? $page->post_title : __('(no title)', 'fluent-booking') | |
| 214 | 221 | ]; |
| 215 | 222 | } |
| 216 | 223 | |
| 217 | 224 | return [ |
| @@ -228,9 +235,9 @@ | ||
| 228 | 235 | } |
| 229 | 236 | |
| 230 | 237 | $settings = $request->get('settings', []); |
| 231 | 238 | |
| 232 | - $prefSettings = Helper::getPrefSettins(false); | |
| 239 | + $prefSettings = Helper::getPrefSettings(false); | |
| 233 | 240 | |
| 234 | 241 | $settings = wp_parse_args($settings, $prefSettings); |
| 235 | 242 | |
| 236 | 243 | $settings = Arr::only($settings, array_keys($prefSettings)); |
| @@ -255,8 +262,14 @@ | ||
| 255 | 262 | } |
| 256 | 263 | |
| 257 | 264 | public function installPlugin(Request $request) |
| 258 | 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 | + | |
| 259 | 272 | $pluginId = $request->get('plugin_id'); |
| 260 | 273 | |
| 261 | 274 | $allowedPlugins = [ |
| 262 | 275 | 'fluent-smtp' => [ |
| @@ -283,8 +296,13 @@ | ||
| 283 | 296 | 'name' => 'FluentBoards', |
| 284 | 297 | 'repo-slug' => 'fluent-boards', |
| 285 | 298 | 'file' => 'fluent-boards.php', |
| 286 | 299 | ], |
| 300 | + 'fluent-cart' => [ | |
| 301 | + 'name' => 'FluentCart', | |
| 302 | + 'repo-slug' => 'fluent-cart', | |
| 303 | + 'file' => 'fluent-cart.php', | |
| 304 | + ] | |
| 287 | 305 | ]; |
| 288 | 306 | |
| 289 | 307 | if (!isset($allowedPlugins[$pluginId])) { |
| 290 | 308 | return $this->sendError([ |
| @@ -291,131 +309,11 @@ | ||
| 291 | 309 | 'message' => __('This action is not allowed', 'fluent-booking') |
| 292 | 310 | ]); |
| 293 | 311 | } |
| 294 | 312 | |
| 295 | - $this->backgroundInstaller($allowedPlugins[$pluginId], $pluginId); | |
| 313 | + OnboardingService::backgroundInstaller($allowedPlugins[$pluginId]); | |
| 296 | 314 | |
| 297 | 315 | return $this->sendSuccess([ |
| 298 | - 'message' => __('Plugin is being installed in the background', 'fluent-booking') | |
| 316 | + 'message' => __('Plugin has been installed Successfully', 'fluent-booking') | |
| 299 | 317 | ]); |
| 300 | - } | |
| 301 | - | |
| 302 | - private function backgroundInstaller($plugin_to_install, $plugin_id) | |
| 303 | - { | |
| 304 | - if (!empty($plugin_to_install['repo-slug'])) { | |
| 305 | - require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 306 | - require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; | |
| 307 | - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 308 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 309 | - | |
| 310 | - WP_Filesystem(); | |
| 311 | - | |
| 312 | - $skin = new \Automatic_Upgrader_Skin(); | |
| 313 | - $upgrader = new \WP_Upgrader($skin); | |
| 314 | - $installed_plugins = array_reduce(array_keys(\get_plugins()), array($this, 'associate_plugin_file'), array()); | |
| 315 | - $plugin_slug = $plugin_to_install['repo-slug']; | |
| 316 | - $plugin_file = isset($plugin_to_install['file']) ? $plugin_to_install['file'] : $plugin_slug . '.php'; | |
| 317 | - $installed = false; | |
| 318 | - $activate = false; | |
| 319 | - | |
| 320 | - // See if the plugin is installed already. | |
| 321 | - if (isset($installed_plugins[$plugin_file])) { | |
| 322 | - $installed = true; | |
| 323 | - $activate = !is_plugin_active($installed_plugins[$plugin_file]); | |
| 324 | - } | |
| 325 | - | |
| 326 | - // Install this thing! | |
| 327 | - if (!$installed) { | |
| 328 | - // Suppress feedback. | |
| 329 | - ob_start(); | |
| 330 | - | |
| 331 | - try { | |
| 332 | - $plugin_information = plugins_api( | |
| 333 | - 'plugin_information', | |
| 334 | - array( | |
| 335 | - 'slug' => $plugin_slug, | |
| 336 | - 'fields' => array( | |
| 337 | - 'short_description' => false, | |
| 338 | - 'sections' => false, | |
| 339 | - 'requires' => false, | |
| 340 | - 'rating' => false, | |
| 341 | - 'ratings' => false, | |
| 342 | - 'downloaded' => false, | |
| 343 | - 'last_updated' => false, | |
| 344 | - 'added' => false, | |
| 345 | - 'tags' => false, | |
| 346 | - 'homepage' => false, | |
| 347 | - 'donate_link' => false, | |
| 348 | - 'author_profile' => false, | |
| 349 | - 'author' => false, | |
| 350 | - ), | |
| 351 | - ) | |
| 352 | - ); | |
| 353 | - | |
| 354 | - if (is_wp_error($plugin_information)) { | |
| 355 | - throw new \Exception($plugin_information->get_error_message()); | |
| 356 | - } | |
| 357 | - | |
| 358 | - $package = $plugin_information->download_link; | |
| 359 | - $download = $upgrader->download_package($package); | |
| 360 | - | |
| 361 | - if (is_wp_error($download)) { | |
| 362 | - throw new \Exception($download->get_error_message()); | |
| 363 | - } | |
| 364 | - | |
| 365 | - $working_dir = $upgrader->unpack_package($download, true); | |
| 366 | - | |
| 367 | - if (is_wp_error($working_dir)) { | |
| 368 | - throw new \Exception($working_dir->get_error_message()); | |
| 369 | - } | |
| 370 | - | |
| 371 | - $result = $upgrader->install_package( | |
| 372 | - array( | |
| 373 | - 'source' => $working_dir, | |
| 374 | - 'destination' => WP_PLUGIN_DIR, | |
| 375 | - 'clear_destination' => false, | |
| 376 | - 'abort_if_destination_exists' => false, | |
| 377 | - 'clear_working' => true, | |
| 378 | - 'hook_extra' => array( | |
| 379 | - 'type' => 'plugin', | |
| 380 | - 'action' => 'install', | |
| 381 | - ), | |
| 382 | - ) | |
| 383 | - ); | |
| 384 | - | |
| 385 | - if (is_wp_error($result)) { | |
| 386 | - throw new \Exception($result->get_error_message()); | |
| 387 | - } | |
| 388 | - | |
| 389 | - $activate = true; | |
| 390 | - | |
| 391 | - } catch (\Exception $e) { | |
| 392 | - } | |
| 393 | - | |
| 394 | - // Discard feedback. | |
| 395 | - ob_end_clean(); | |
| 396 | - } | |
| 397 | - | |
| 398 | - wp_clean_plugins_cache(); | |
| 399 | - | |
| 400 | - // Activate this thing. | |
| 401 | - if ($activate) { | |
| 402 | - try { | |
| 403 | - $result = activate_plugin($installed ? $installed_plugins[$plugin_file] : $plugin_slug . '/' . $plugin_file); | |
| 404 | - | |
| 405 | - if (is_wp_error($result)) { | |
| 406 | - throw new \Exception($result->get_error_message()); | |
| 407 | - } | |
| 408 | - } catch (\Exception $e) { | |
| 409 | - } | |
| 410 | - } | |
| 411 | - } | |
| 412 | - } | |
| 413 | - | |
| 414 | - private function associate_plugin_file($plugins, $key) | |
| 415 | - { | |
| 416 | - $path = explode('/', $key); | |
| 417 | - $filename = end($path); | |
| 418 | - $plugins[$filename] = $key; | |
| 419 | - return $plugins; | |
| 420 | 318 | } |
| 421 | 319 | } |