| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCommunity\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentCommunity\App\Functions\Utility; |
| 6 |
use FluentCommunity\App\Models\BaseSpace; |
| 7 |
use FluentCommunity\App\Services\AuthenticationService; |
| 8 |
use FluentCommunity\App\Services\CustomSanitizer; |
| 9 |
use FluentCommunity\App\Services\FeedsHelper; |
| 10 |
use FluentCommunity\App\Services\ProfileHelper; |
| 11 |
use FluentCommunity\Modules\Auth\AuthHelper; |
| 12 |
use FluentCommunity\Modules\PushNotification\PushNotificationModule; |
| 13 |
use FluentCommunity\App\Services\Helper; |
| 14 |
use FluentCommunity\App\Services\OnboardingService; |
| 15 |
use FluentCommunity\Framework\Http\Request\Request; |
| 16 |
use FluentCommunity\Framework\Support\Arr; |
| 17 |
|
| 18 |
class AdminController extends Controller |
| 19 |
{ |
| 20 |
public function getGeneralSettings(Request $request) |
| 21 |
{ |
| 22 |
$settings = Helper::generalSettings(false); |
| 23 |
|
| 24 |
$userRoles = wp_roles()->roles; |
| 25 |
|
| 26 |
$formatedRoles = []; |
| 27 |
foreach ($userRoles as $role => $roleData) { |
| 28 |
$formatedRoles[$role] = $roleData['name']; |
| 29 |
} |
| 30 |
|
| 31 |
unset($formatedRoles['administrator']); |
| 32 |
|
| 33 |
$data = [ |
| 34 |
'settings' => $settings, |
| 35 |
'user_roles' => $formatedRoles, |
| 36 |
'users_can_register' => !!get_option('users_can_register'), |
| 37 |
'user_registration_enable_url' => admin_url('options-general.php') |
| 38 |
]; |
| 39 |
return apply_filters('fluent_community/general_settings_api_response', $data, $request->all()); |
| 40 |
} |
| 41 |
|
| 42 |
public function saveGeneralSettings(Request $request) |
| 43 |
{ |
| 44 |
$inputs = $request->get('settings', []); |
| 45 |
$settings = Helper::generalSettings(false); |
| 46 |
$storedSettings = $settings; |
| 47 |
$inputs = Arr::only($inputs, array_keys($settings)); |
| 48 |
|
| 49 |
$settings['logo'] = Arr::get($inputs, 'logo', ''); |
| 50 |
$settings['white_logo'] = Arr::get($inputs, 'white_logo', ''); |
| 51 |
$settings['featured_image'] = Arr::get($inputs, 'featured_image', ''); |
| 52 |
|
| 53 |
if (!empty($settings['logo'])) { |
| 54 |
$settings['logo'] = sanitize_url($settings['logo']); |
| 55 |
} |
| 56 |
|
| 57 |
if (!empty($settings['white_logo'])) { |
| 58 |
$settings['white_logo'] = sanitize_url($settings['white_logo']); |
| 59 |
} |
| 60 |
|
| 61 |
if (!empty($settings['featured_image'])) { |
| 62 |
$settings['featured_image'] = sanitize_url($settings['featured_image']); |
| 63 |
} |
| 64 |
|
| 65 |
if (!empty($settings['site_title'])) { |
| 66 |
$settings['site_title'] = sanitize_text_field(Arr::get($inputs, 'site_title', '')); |
| 67 |
} |
| 68 |
|
| 69 |
$settings['disable_global_posts'] = sanitize_text_field(Arr::get($inputs, 'disable_global_posts', 'no')); |
| 70 |
$settings['access'] = Arr::get($inputs, 'access', []); |
| 71 |
$settings['auth_content'] = wp_kses_post(Arr::get($inputs, 'auth_content', '')); |
| 72 |
$settings['auth_redirect'] = sanitize_url(Arr::get($inputs, 'auth_redirect', '')); |
| 73 |
$settings['restricted_role_content'] = wp_kses_post(Arr::get($inputs, 'restricted_role_content', '')); |
| 74 |
$settings['logo_permalink'] = sanitize_url(Arr::get($inputs, 'logo_permalink', '')); |
| 75 |
$settings['logo_permalink_type'] = sanitize_text_field(Arr::get($inputs, 'logo_permalink_type', 'default')); |
| 76 |
$settings['auth_url'] = sanitize_url(Arr::get($inputs, 'auth_url', '')); |
| 77 |
$media = Helper::getMediaFromUrl($settings['logo']); |
| 78 |
$whiteMedia = Helper::getMediaFromUrl($settings['white_logo']); |
| 79 |
$featuredMedia = Helper::getMediaFromUrl($settings['featured_image']); |
| 80 |
$settings['cutsom_auth_url'] = sanitize_url(Arr::get($inputs, 'cutsom_auth_url', '')); |
| 81 |
$settings['auth_form_type'] = sanitize_text_field(Arr::get($inputs, 'auth_form_type', '')); |
| 82 |
$settings['explicit_registration'] = sanitize_text_field(Arr::get($inputs, 'explicit_registration', 'no')); |
| 83 |
|
| 84 |
$isCustomSignupPage = $settings['auth_form_type'] === 'default' && Arr::get($inputs, 'use_custom_signup_page', 'no') == 'yes'; |
| 85 |
if (!$isCustomSignupPage) { |
| 86 |
$settings['custom_signup_url'] = ''; |
| 87 |
$settings['use_custom_signup_page'] = 'no'; |
| 88 |
} else { |
| 89 |
$settings['use_custom_signup_page'] = 'yes'; |
| 90 |
|
| 91 |
$url = Arr::get($inputs, 'custom_signup_url', ''); |
| 92 |
|
| 93 |
if (!$url || !filter_var($url, FILTER_VALIDATE_URL)) { |
| 94 |
return $this->sendError([ |
| 95 |
'message' => __('Please provide a valid signup URL', 'fluent-community') |
| 96 |
]); |
| 97 |
} |
| 98 |
$settings['custom_signup_url'] = $url; |
| 99 |
} |
| 100 |
|
| 101 |
if ($media) { |
| 102 |
$settings['logo'] = $media->public_url; |
| 103 |
$media->update([ |
| 104 |
'is_active' => true, |
| 105 |
'user_id' => get_current_user_id(), |
| 106 |
'object_source' => 'general' |
| 107 |
]); |
| 108 |
} |
| 109 |
|
| 110 |
if ($whiteMedia) { |
| 111 |
$settings['white_logo'] = $whiteMedia->public_url; |
| 112 |
$whiteMedia->update([ |
| 113 |
'is_active' => true, |
| 114 |
'user_id' => get_current_user_id(), |
| 115 |
'object_source' => 'general' |
| 116 |
]); |
| 117 |
} |
| 118 |
|
| 119 |
if ($featuredMedia) { |
| 120 |
$settings['featured_image'] = $featuredMedia->public_url; |
| 121 |
$featuredMedia->update([ |
| 122 |
'is_active' => true, |
| 123 |
'user_id' => get_current_user_id(), |
| 124 |
'object_source' => 'general' |
| 125 |
]); |
| 126 |
} |
| 127 |
|
| 128 |
$slugChanged = false; |
| 129 |
$newSlug = sanitize_title($inputs['slug'] ?? ''); |
| 130 |
if ($newSlug && $settings['slug'] != $newSlug && !defined('FLUENT_COMMUNITY_PORTAL_SLUG')) { |
| 131 |
$settings['slug'] = $newSlug; |
| 132 |
$slugChanged = true; |
| 133 |
} |
| 134 |
|
| 135 |
if (!Helper::isSuperAdmin()) { |
| 136 |
foreach (['auth_url', 'cutsom_auth_url', 'auth_form_type', 'auth_redirect', 'custom_signup_url', 'use_custom_signup_page', 'explicit_registration'] as $restrictedKey) { |
| 137 |
if ($settings[$restrictedKey] != Arr::get($storedSettings, $restrictedKey, '')) { |
| 138 |
return $this->sendError([ |
| 139 |
'message' => __('You do not have permission to change the authentication and login settings', 'fluent-community') |
| 140 |
]); |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
update_option('fluent_community_settings', $settings); |
| 146 |
|
| 147 |
$redirectUrl = ''; |
| 148 |
|
| 149 |
if ($slugChanged) { |
| 150 |
// flush rewrite rules |
| 151 |
flush_rewrite_rules(true); |
| 152 |
Helper::generalSettings(false); |
| 153 |
$redirectUrl = Helper::baseUrl('admin/settings/general'); |
| 154 |
} |
| 155 |
|
| 156 |
return [ |
| 157 |
'message' => __('Settings have been saved successfully.', 'fluent-community'), |
| 158 |
'redirect_url' => $redirectUrl |
| 159 |
]; |
| 160 |
} |
| 161 |
|
| 162 |
public function getEmailSettings(Request $request) |
| 163 |
{ |
| 164 |
$emailSettings = Utility::getEmailNotificationSettings(); |
| 165 |
$globalSettings = Helper::generalSettings(false); |
| 166 |
if (empty($emailSettings['logo'])) { |
| 167 |
$emailSettings['global_logo'] = $globalSettings['logo']; |
| 168 |
} |
| 169 |
|
| 170 |
$data = [ |
| 171 |
'email_settings' => $emailSettings |
| 172 |
]; |
| 173 |
return apply_filters('fluent_community/email_settings_api_response', $data, $request->all()); |
| 174 |
} |
| 175 |
|
| 176 |
public function saveEmailSettings(Request $request) |
| 177 |
{ |
| 178 |
$prevSettings = Utility::getEmailNotificationSettings(); |
| 179 |
$newSettings = $request->get('email_settings', []); |
| 180 |
|
| 181 |
$logo = Arr::get($newSettings, 'logo', ''); |
| 182 |
|
| 183 |
if ($logo) { |
| 184 |
$logoMedia = Helper::getMediaFromUrl($logo); |
| 185 |
if ($logoMedia) { |
| 186 |
$newSettings['logo'] = $logoMedia->public_url; |
| 187 |
$logoMedia->update([ |
| 188 |
'is_active' => true, |
| 189 |
'user_id' => get_current_user_id(), |
| 190 |
'object_source' => 'general' |
| 191 |
]); |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
$newSettings = wp_parse_args($newSettings, $prevSettings); |
| 196 |
$newSettings = CustomSanitizer::santizeEmailSettings($newSettings); |
| 197 |
|
| 198 |
Utility::updateOption('global_email_settings', $newSettings); |
| 199 |
|
| 200 |
/* |
| 201 |
* We are unscheduling all digest schedules if the settings has been changed or disabled |
| 202 |
*/ |
| 203 |
$isScheduleChanged = ($newSettings['digest_mail_day'] != $prevSettings['digest_mail_day']) || ($newSettings['daily_digest_time'] != $prevSettings['daily_digest_time']); |
| 204 |
if ($isScheduleChanged) { |
| 205 |
if (as_next_scheduled_action('fluent_community_send_daily_digest_init')) { |
| 206 |
as_unschedule_all_actions('fluent_community_send_daily_digest_init', [], 'fluent-community'); |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
return [ |
| 211 |
'email_settings' => $newSettings, |
| 212 |
'message' => __('Email notification settings have been updated', 'fluent-community') |
| 213 |
]; |
| 214 |
} |
| 215 |
|
| 216 |
public function getPushSettings(Request $request) |
| 217 |
{ |
| 218 |
$data = [ |
| 219 |
'push_settings' => Utility::getPushNotificationSettings(), |
| 220 |
'push_available' => PushNotificationModule::isFluentNotifyActive(), |
| 221 |
'push_setup' => [ |
| 222 |
'state' => PushNotificationModule::getSetupState(), |
| 223 |
'settings_url' => PushNotificationModule::getSettingsUrl(), |
| 224 |
'can_install' => current_user_can('install_plugins'), |
| 225 |
'can_activate' => current_user_can('activate_plugins'), |
| 226 |
'has_installer' => (bool)has_action('fluent_community/install_fluent_notify_plugin'), |
| 227 |
'learn_more_url' => 'https://fluentnotify.com' |
| 228 |
] |
| 229 |
]; |
| 230 |
|
| 231 |
return apply_filters('fluent_community/push_settings_api_response', $data, $request->all()); |
| 232 |
} |
| 233 |
|
| 234 |
public function savePushSettings(Request $request) |
| 235 |
{ |
| 236 |
$prevSettings = Utility::getPushNotificationSettings(); |
| 237 |
|
| 238 |
$settings = Arr::only((array)$request->get('settings', []), array_keys($prevSettings)); |
| 239 |
$settings = wp_parse_args($settings, $prevSettings); |
| 240 |
|
| 241 |
foreach ($settings as $key => $value) { |
| 242 |
if ($key === 'prompt_placements') { |
| 243 |
$settings[$key] = array_values(array_intersect( |
| 244 |
array_map('sanitize_text_field', (array)$value), |
| 245 |
PushNotificationModule::PROMPT_PLACEMENTS |
| 246 |
)); |
| 247 |
} else { |
| 248 |
$settings[$key] = $value === 'yes' ? 'yes' : 'no'; |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
Utility::updateOption('global_push_settings', $settings); |
| 253 |
|
| 254 |
return [ |
| 255 |
'push_settings' => $settings, |
| 256 |
'message' => __('Push notification settings have been updated', 'fluent-community') |
| 257 |
]; |
| 258 |
} |
| 259 |
|
| 260 |
public function getStorageSettings(Request $request) |
| 261 |
{ |
| 262 |
if (!defined('FLUENT_COMMUNITY_PRO')) { |
| 263 |
$config = [ |
| 264 |
'driver' => 'local' |
| 265 |
]; |
| 266 |
} else { |
| 267 |
$config = \FluentCommunityPro\App\Modules\CloudStorage\StorageHelper::getConfig('view'); |
| 268 |
} |
| 269 |
|
| 270 |
return apply_filters('fluent_community/storage_settings_response', [ |
| 271 |
'config' => $config |
| 272 |
], $request->all()); |
| 273 |
} |
| 274 |
|
| 275 |
public function updateStorageSettings(Request $request) |
| 276 |
{ |
| 277 |
if (!defined('FLUENT_COMMUNITY_PRO')) { |
| 278 |
return $this->sendError([ |
| 279 |
'message' => __('Sorry, you cannot update this config. Please activate pro', 'fluent-community') |
| 280 |
]); |
| 281 |
} |
| 282 |
|
| 283 |
if (defined('FLUENT_COMMUNITY_CLOUD_STORAGE') && FLUENT_COMMUNITY_CLOUD_STORAGE) { |
| 284 |
return $this->sendError([ |
| 285 |
'message' => __('You cannot update the storage settings as it is defined in the config file', 'fluent-community') |
| 286 |
]); |
| 287 |
} |
| 288 |
|
| 289 |
$config = (array)$request->get('config', []); |
| 290 |
|
| 291 |
$driver = Arr::get($config, 'driver', 'local'); |
| 292 |
|
| 293 |
$validation = [ |
| 294 |
'driver' => 'required' |
| 295 |
]; |
| 296 |
|
| 297 |
$isRemote = in_array($driver, ['amazon_s3', 'bunny_cdn', 'cloudflare_r2']); |
| 298 |
|
| 299 |
if ($driver == 'cloudflare_r2') { |
| 300 |
$validation = [ |
| 301 |
'driver' => 'required', |
| 302 |
'access_key' => 'required', |
| 303 |
'secret_key' => 'required', |
| 304 |
'public_url' => 'required|url', |
| 305 |
'endpoint_url' => 'required|url', |
| 306 |
]; |
| 307 |
} else if ($driver == 'amazon_s3') { |
| 308 |
$validation = [ |
| 309 |
'driver' => 'required', |
| 310 |
'access_key' => 'required', |
| 311 |
'secret_key' => 'required', |
| 312 |
'bucket' => 'required' |
| 313 |
]; |
| 314 |
} else if ($driver == 'bunny_cdn') { |
| 315 |
$validation = [ |
| 316 |
'driver' => 'required', |
| 317 |
'access_key' => 'required', |
| 318 |
's3_endpoint' => 'required', |
| 319 |
'bucket' => 'required', |
| 320 |
'public_url' => 'required|url' |
| 321 |
]; |
| 322 |
} |
| 323 |
|
| 324 |
$this->validate($config, $validation); |
| 325 |
|
| 326 |
if ($isRemote) { |
| 327 |
$previousConfig = \FluentCommunityPro\App\Modules\CloudStorage\StorageHelper::getConfig(); |
| 328 |
if ($config['access_key'] == 'FCOM_ENCRYPTED_DATA_KEY') { |
| 329 |
$config['access_key'] = Arr::get($previousConfig, 'access_key'); |
| 330 |
} |
| 331 |
|
| 332 |
if ($config['secret_key'] == 'FCOM_ENCRYPTED_DATA_KEY') { |
| 333 |
$config['secret_key'] = Arr::get($previousConfig, 'secret_key'); |
| 334 |
} |
| 335 |
|
| 336 |
$driver = (new \FluentCommunityPro\App\Modules\CloudStorage\CloudStorageModule)->getConnectionDriver($config); |
| 337 |
|
| 338 |
if (!$driver) { |
| 339 |
return $this->sendError([ |
| 340 |
'message' => __('Could not connect to the remote storage service. Please check your credentials', 'fluent-community') |
| 341 |
]); |
| 342 |
} |
| 343 |
|
| 344 |
$test = $driver->testConnection(); |
| 345 |
if (!$test || is_wp_error($test)) { |
| 346 |
$errorMessage = is_wp_error($test) ? $test->get_error_message() : 'Unknown Error'; |
| 347 |
return $this->sendError([ |
| 348 |
'message' => __('Could not connect to the remote storage service. Error: ', 'fluent-community') . $errorMessage |
| 349 |
]); |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
$config = Arr::only($config, [ |
| 354 |
'driver', |
| 355 |
'access_key', |
| 356 |
'secret_key', |
| 357 |
'bucket', |
| 358 |
'public_url', |
| 359 |
'endpoint_url', |
| 360 |
'account_id', |
| 361 |
'sub_folder', |
| 362 |
's3_endpoint' |
| 363 |
]); |
| 364 |
|
| 365 |
if ($config['driver'] == 'local') { |
| 366 |
$config = [ |
| 367 |
'driver' => 'local' |
| 368 |
]; |
| 369 |
|
| 370 |
$featureConfig = Utility::getFeaturesConfig(); |
| 371 |
$featureConfig['cloud_storage'] = 'no'; |
| 372 |
Utility::updateOption('fluent_community_features', $featureConfig); |
| 373 |
} else { |
| 374 |
$featureConfig = Utility::getFeaturesConfig(); |
| 375 |
$featureConfig['cloud_storage'] = 'yes'; |
| 376 |
Utility::updateOption('fluent_community_features', $featureConfig); |
| 377 |
} |
| 378 |
|
| 379 |
$config = array_filter($config); |
| 380 |
\FluentCommunityPro\App\Modules\CloudStorage\StorageHelper::updateConfig($config); |
| 381 |
|
| 382 |
return [ |
| 383 |
'message' => __('Storage settings have been updated successfully', 'fluent-community') |
| 384 |
]; |
| 385 |
} |
| 386 |
|
| 387 |
public function getWelcomeBannerSettings(Request $request) |
| 388 |
{ |
| 389 |
$settings = apply_filters('fluent_community/get_welcome_banner_settings', Helper::getWelcomeBannerSettings(), $request->all()); |
| 390 |
|
| 391 |
return [ |
| 392 |
'settings' => $settings |
| 393 |
]; |
| 394 |
} |
| 395 |
|
| 396 |
public function updateWelcomeBannerSettings(Request $request) |
| 397 |
{ |
| 398 |
$settings = $request->get('settings', []); |
| 399 |
|
| 400 |
$settings = CustomSanitizer::sanitizeWelcomeBannerSettings($settings); |
| 401 |
|
| 402 |
if (Arr::get($settings, 'login.enabled') == 'yes') { |
| 403 |
$settings['login']['description_rendered'] = wp_kses_post(FeedsHelper::mdToHtml(Arr::get($settings, 'login.description'))); |
| 404 |
} |
| 405 |
|
| 406 |
if (Arr::get($settings, 'logout.enabled') == 'yes') { |
| 407 |
$settings['logout']['description_rendered'] = wp_kses_post(FeedsHelper::mdToHtml(Arr::get($settings, 'logout.description'))); |
| 408 |
if (Arr::get($settings, 'logout.buttonLabel') && Arr::get($settings, 'logout.useCustomUrl') != 'yes') { |
| 409 |
$settings['logout']['buttonLink'] = Helper::getAuthUrl(); |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
$settings = apply_filters('fluent_community/update_welcome_banner_settings', $settings); |
| 414 |
|
| 415 |
Utility::updateOption('welcome_banner_settings', $settings); |
| 416 |
|
| 417 |
Utility::setCache('welcome_banner_settings', $settings, WEEK_IN_SECONDS); |
| 418 |
|
| 419 |
return [ |
| 420 |
'message' => __('Welcome banner settings have been updated successfully', 'fluent-community'), |
| 421 |
'settings' => $settings |
| 422 |
]; |
| 423 |
} |
| 424 |
|
| 425 |
public function getAuthSettings() |
| 426 |
{ |
| 427 |
$settings = AuthenticationService::getAuthSettings(); |
| 428 |
|
| 429 |
$settings['login']['form']['fields'] = AuthHelper::getLoginFormFields(); |
| 430 |
$settings['signup']['form']['fields'] = AuthHelper::getFormFields(); |
| 431 |
|
| 432 |
$settings = apply_filters('fluent_community/get_auth_settings', $settings); |
| 433 |
|
| 434 |
return [ |
| 435 |
'settings' => $settings |
| 436 |
]; |
| 437 |
} |
| 438 |
|
| 439 |
public function getOnBoardingSettings() |
| 440 |
{ |
| 441 |
$settings = Helper::generalSettings(); |
| 442 |
|
| 443 |
$currentUser = get_user_by('ID', get_current_user_id()); |
| 444 |
|
| 445 |
$settings['has_fluentcrm'] = defined('FLUENTCRM') ? 'yes' : 'no'; |
| 446 |
$settings['has_fluentsmtp'] = defined('FLUENTMAIL_PLUGIN_FILE') ? 'yes' : 'no'; |
| 447 |
$settings['has_fluentcart'] = defined('FLUENTCART_VERSION') ? 'yes' : 'no'; |
| 448 |
$settings['template'] = ''; |
| 449 |
$settings['install_fluentcrm'] = 'yes'; |
| 450 |
$settings['install_fluentsmtp'] = 'yes'; |
| 451 |
$settings['install_fluentcart'] = 'yes'; |
| 452 |
$settings['subscribe_to_newsletter'] = 'yes'; |
| 453 |
$settings['share_data'] = 'no'; |
| 454 |
if ($currentUser) { |
| 455 |
$settings['user_full_name'] = $currentUser->first_name ? $currentUser->first_name . ' ' . $currentUser->last_name : $currentUser->display_name; |
| 456 |
$settings['user_email_address'] = $currentUser->user_email; |
| 457 |
} else { |
| 458 |
$settings['user_full_name'] = ''; |
| 459 |
$settings['user_email_address'] = ''; |
| 460 |
} |
| 461 |
|
| 462 |
$data = [ |
| 463 |
'settings' => $settings |
| 464 |
]; |
| 465 |
return apply_filters('fluent_community/onboarding_settings_api_response', $data, $this->request->all()); |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
public function saveOnBoardingSettings(Request $request) |
| 470 |
{ |
| 471 |
$inputs = $request->get('settings', []); |
| 472 |
$settings = Helper::generalSettings(); |
| 473 |
|
| 474 |
if (Arr::get($inputs, 'site_title')) { |
| 475 |
$settings['site_title'] = sanitize_text_field(Arr::get($inputs, 'site_title')); |
| 476 |
} |
| 477 |
|
| 478 |
$logo = Arr::get($inputs, 'logo'); |
| 479 |
|
| 480 |
if ($logo) { |
| 481 |
$media = Helper::getMediaFromUrl($logo); |
| 482 |
if ($media) { |
| 483 |
$settings['logo'] = $media->public_url; |
| 484 |
$media->update([ |
| 485 |
'is_active' => true, |
| 486 |
'user_id' => get_current_user_id(), |
| 487 |
'object_source' => 'onboarding' |
| 488 |
]); |
| 489 |
} |
| 490 |
} |
| 491 |
|
| 492 |
if (Arr::get($inputs, 'slug') && empty($settings['is_slug_defined'])) { |
| 493 |
$settings['slug'] = sanitize_title(Arr::get($inputs, 'slug')); |
| 494 |
} |
| 495 |
update_option('fluent_community_settings', $settings, true); |
| 496 |
|
| 497 |
// Email Subscription Settings |
| 498 |
$subscriptionSettings = array_filter([ |
| 499 |
'user_id' => get_current_user_id(), |
| 500 |
'subscribe_to_newsletter' => sanitize_text_field(Arr::get($inputs, 'subscribe_to_newsletter', 'no')), |
| 501 |
'share_data' => sanitize_text_field(Arr::get($inputs, 'share_data', 'no')), |
| 502 |
'user_full_name' => sanitize_text_field(Arr::get($inputs, 'user_full_name', '')), |
| 503 |
'user_email_address' => sanitize_email(Arr::get($inputs, 'user_email_address', '')) |
| 504 |
]); |
| 505 |
|
| 506 |
Utility::updateOption('onboarding_sub_settings', $subscriptionSettings); |
| 507 |
OnboardingService::maybeCreateSpaceTemplates(Arr::get($inputs, 'template')); |
| 508 |
|
| 509 |
$installableAddons = array_keys(array_filter([ |
| 510 |
'fluent-crm' => Arr::get($inputs, 'install_fluentcrm', 'no') == 'yes', |
| 511 |
'fluent-smtp' => Arr::get($inputs, 'install_fluentsmtp', 'no') == 'yes', |
| 512 |
'fluent-cart' => Arr::get($inputs, 'install_fluentcart', 'no') == 'yes', |
| 513 |
])); |
| 514 |
|
| 515 |
// Install Plugins which are checked |
| 516 |
OnboardingService::installAddons($installableAddons); |
| 517 |
|
| 518 |
// Maybe Optin User to Newsletter |
| 519 |
OnboardingService::maybeOptinUserToNewsletter($subscriptionSettings); |
| 520 |
|
| 521 |
// flash the permalinks |
| 522 |
flush_rewrite_rules(true); |
| 523 |
|
| 524 |
return [ |
| 525 |
'message' => __('Onboarding settings have been updated.', 'fluent-community') |
| 526 |
]; |
| 527 |
} |
| 528 |
|
| 529 |
public function changePortalSlug(Request $request) |
| 530 |
{ |
| 531 |
$newSlug = sanitize_title($request->get('new_slug', '')); |
| 532 |
|
| 533 |
if (!$newSlug) { |
| 534 |
return $this->sendError([ |
| 535 |
'message' => __('Slug cannot be empty', 'fluent-community') |
| 536 |
]); |
| 537 |
} |
| 538 |
|
| 539 |
if (defined('FLUENT_COMMUNITY_PORTAL_SLUG')) { |
| 540 |
return $this->sendError([ |
| 541 |
'message' => __('You cannot change the slug as it is defined in the config file', 'fluent-community') |
| 542 |
]); |
| 543 |
} |
| 544 |
|
| 545 |
$settings = Helper::generalSettings(); |
| 546 |
|
| 547 |
if ($settings['slug'] != $newSlug) { |
| 548 |
$settings['slug'] = $newSlug; |
| 549 |
|
| 550 |
update_option('fluent_community_settings', $settings); |
| 551 |
flush_rewrite_rules(true); |
| 552 |
|
| 553 |
$slug = $settings['slug']; |
| 554 |
add_rewrite_rule('^' . $slug . '/?$', 'index.php?fcom_route=portal_home', 'top'); // For /hooks |
| 555 |
add_rewrite_rule('^' . $slug . '/(.+)/?', 'index.php?fcom_route=$matches[1]', 'top'); |
| 556 |
// flush rewrite rules |
| 557 |
flush_rewrite_rules(true); |
| 558 |
|
| 559 |
delete_option('rewrite_rules'); |
| 560 |
} |
| 561 |
|
| 562 |
return [ |
| 563 |
'message' => __('Slug has been changed successfully', 'fluent-community') |
| 564 |
]; |
| 565 |
} |
| 566 |
|
| 567 |
public function getProfileLinkProviders(Request $request) |
| 568 |
{ |
| 569 |
$data = [ |
| 570 |
'providers' => ProfileHelper::socialLinkProviders() |
| 571 |
]; |
| 572 |
return apply_filters('fluent_community/profile_link_providers_api_response', $data, $request->all()); |
| 573 |
} |
| 574 |
|
| 575 |
public function updateProfileLinkProviders(Request $request) |
| 576 |
{ |
| 577 |
$providerKeys = array_keys(ProfileHelper::socialLinkProviders()); |
| 578 |
$config = $request->get('configs', []); |
| 579 |
|
| 580 |
$config = array_filter($config, function ($value) use ($providerKeys) { |
| 581 |
return in_array($value, $providerKeys); |
| 582 |
}); |
| 583 |
|
| 584 |
do_action('fluent_community/update_profile_link_providers', $config); |
| 585 |
|
| 586 |
return [ |
| 587 |
'message' => __('Profile link providers have been updated successfully', 'fluent-community'), |
| 588 |
]; |
| 589 |
} |
| 590 |
|
| 591 |
public function getAllSpaceCourses(Request $request) |
| 592 |
{ |
| 593 |
$data = [ |
| 594 |
'all_spaces' => BaseSpace::query()->withoutGlobalScopes() |
| 595 |
->whereIn('type', ['community', 'course']) |
| 596 |
->orderBy('serial', 'ASC')->get() |
| 597 |
]; |
| 598 |
return apply_filters('fluent_community/all_space_courses_api_response', $data, $request->all()); |
| 599 |
} |
| 600 |
|
| 601 |
} |
| 602 |
|