PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.9.1
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.9.1
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / app / Http / Controllers / SettingController.php

SettingController.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.9.1, at app/Http/Controllers/SettingController.php

548 lines 23.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Http\Controllers;
4
5 use FluentCommunity\App\Functions\Utility;
6 use FluentCommunity\App\Models\Space;
7 use FluentCommunity\App\Models\SpaceGroup;
8 use FluentCommunity\App\Services\Helper;
9 use FluentCommunity\App\Services\OnboardingService;
10 use FluentCommunity\Framework\Http\Request\Request;
11 use FluentCommunity\Framework\Support\Arr;
12 use FluentCommunity\Framework\Support\Sanitizer;
13 use FluentCommunity\Modules\Course\Model\Course;
14
15 class SettingController extends Controller
16 {
17 public function getFeatures()
18 {
19 $features = Utility::getFeaturesConfig();
20
21 if (!empty($features['giphy_api_key'])) {
22 $features['giphy_api_key'] = 'FCOM_ENCRYPTED_DATA_KEY';
23 }
24
25 $data = [
26 'features' => $features,
27 'addOns' => $this->getAddons()
28 ];
29
30 return apply_filters('fluent_community/features_api_response', $data, $this->request->all());
31 }
32
33 public function setFeatures(Request $request)
34 {
35 $request->validate([
36 'features.giphy_api_key' => 'required_if:features.giphy_module,yes|string',
37 ]);
38
39 $data = $request->get('features', []);
40
41 $data = Sanitizer::sanitize($data, [
42 'leader_board_module' => 'sanitize_text_field',
43 'course_module' => 'sanitize_text_field',
44 'giphy_module' => 'sanitize_text_field',
45 'giphy_api_key' => 'sanitize_text_field',
46 'cloud_storage' => 'sanitize_text_field',
47 'emoji_module' => 'sanitize_text_field',
48 'user_badge' => 'sanitize_text_field',
49 'has_crm_sync' => 'sanitize_text_field',
50 'followers_module' => 'sanitize_text_field',
51 'custom_profile_fields' => 'sanitize_text_field',
52 'pwa_module' => 'sanitize_text_field',
53 ]);
54
55 $prevConfig = Utility::getFeaturesConfig();
56
57 if (Arr::get($data, 'giphy_api_key') === 'FCOM_ENCRYPTED_DATA_KEY') {
58 $data['giphy_api_key'] = Arr::get($prevConfig, 'giphy_api_key', '');
59 }
60
61 $data = wp_parse_args($data, $prevConfig);
62
63 Utility::updateOption('fluent_community_features', $data);
64
65 return [
66 'message' => __('Features saved successfully.', 'fluent-community')
67 ];
68 }
69
70 public function getMenuSettings(Request $request)
71 {
72 $menuGroups = Helper::getMenuItemsGroup('edit');
73 $formattedGroups = [];
74
75 foreach ($menuGroups as $indexName => $menuGroup) {
76 if (is_array($menuGroup)) {
77 $formattedGroups[$indexName] = array_values($menuGroup);
78 } else {
79 $formattedGroups[$indexName] = [];
80 }
81 }
82
83 $afterCommunityLinkGroups = Arr::get($formattedGroups, 'afterCommunityLinkGroups', []);
84 $formattedAfterCommunityGroups = [];
85
86 if (is_array($afterCommunityLinkGroups)) {
87 foreach ($afterCommunityLinkGroups as $group) {
88 if (!is_array($group)) continue;
89
90 $title = Arr::get($group, 'title', '');
91 if (empty($title)) continue;
92
93 $items = Arr::get($group, 'items', []);
94 $items = is_array($items) ? array_values($items) : [];
95
96 $formattedAfterCommunityGroups[] = [
97 'title' => $title,
98 'slug' => Arr::get($group, 'slug', ''),
99 'items' => $items,
100 ];
101 }
102 }
103
104 $formattedGroups['afterCommunityLinkGroups'] = $formattedAfterCommunityGroups;
105
106 $data = [
107 'menuSettings' => $formattedGroups
108 ];
109 return apply_filters('fluent_community/menu_settings_api_response', $data, $request->all());
110 }
111
112 public function saveMenuSettings(Request $request)
113 {
114 $menuSettings = $request->get('menuSettings', []);
115
116 $mainMenuItems = $menuSettings['mainMenuItems'] ?? [];
117 $profileDropdownItems = $menuSettings['profileDropdownItems'] ?? [];
118 $beforeCommunityMenuItems = $menuSettings['beforeCommunityMenuItems'] ?? [];
119 $afterCommunityLinkGroups = $menuSettings['afterCommunityLinkGroups'] ?? [];
120
121 $previousSettings = Helper::getMenuItemsGroup('edit');
122
123 $menuSettings['mainMenuItems'] = $this->formatMenuGroup($mainMenuItems, $previousSettings['mainMenuItems']);
124 $menuSettings['profileDropdownItems'] = $this->formatMenuGroup($profileDropdownItems, $previousSettings['profileDropdownItems']);
125 $menuSettings['beforeCommunityMenuItems'] = $this->formatMenuGroup($beforeCommunityMenuItems, $previousSettings['beforeCommunityMenuItems']);
126
127 $formattedAfterCommunityGroups = [];
128 foreach ($afterCommunityLinkGroups as $afterCommunityLinkGroup) {
129 if (empty($afterCommunityLinkGroup['title'])) continue;
130
131 $formattedAfterCommunityGroups[] = [
132 'title' => sanitize_text_field($afterCommunityLinkGroup['title']),
133 'slug' => !empty($afterCommunityLinkGroup['slug']) ? $afterCommunityLinkGroup['slug'] : 'custom_footer_group_' . time(),
134 'items' => $this->formatMenuGroup($afterCommunityLinkGroup['items'], [])
135 ];
136 }
137
138 $menuSettings['afterCommunityLinkGroups'] = $formattedAfterCommunityGroups;
139 $menuSettings = Arr::only($menuSettings, ['mainMenuItems', 'profileDropdownItems', 'beforeCommunityMenuItems', 'afterCommunityLinkGroups']);
140
141 Utility::updateOption('fluent_community_menu_groups', $menuSettings);
142
143 return [
144 'message' => __('Menu settings saved successfully.', 'fluent-community')
145 ];
146 }
147
148 private function formatMenuGroup($mainMenuItems, $savedMenuItems)
149 {
150 $formattedMainMenuItems = [];
151 foreach ($mainMenuItems as $item) {
152 $slug = (string)Arr::get($item, 'slug');
153 if (!Arr::get($item, 'title') || !Arr::get($item, 'permalink')) {
154 continue;
155 }
156
157 if (!$slug) {
158 $slug = 'custom_' . sanitize_title(Arr::get($item, 'title')) . time();
159 $item['slug'] = $slug;
160 $item['is_custom'] = 'yes';
161 }
162
163 $defaultItem = Arr::get($savedMenuItems, $slug, []);
164 if ($defaultItem) {
165 $preservedKeys = ['is_system', 'is_locked', 'is_unavailable', 'slug'];
166 foreach ($preservedKeys as $key) {
167 if (isset($defaultItem[$key])) {
168 $item[$key] = Arr::get($defaultItem, $key);
169 }
170 }
171 }
172
173 $item = \FluentCommunity\App\Services\CustomSanitizer::sanitizeMenuLink($item);
174
175 $formattedMainMenuItems[$slug] = $item;
176 }
177
178 return $formattedMainMenuItems;
179 }
180
181 public function getAddons()
182 {
183 $addons = [
184 'fluent-messaging' => [
185 'is_repo' => false,
186 'title' => __('FluentCommunity Chat', 'fluent-community'),
187 'logo' => Helper::assetUrl('images/brands/fluent-messages.svg'),
188 'is_installed' => defined('FLUENT_MESSAGING_CHAT_VERSION'),
189 'learn_more_url' => 'https://fluentcommunity.co',
190 'settings_url' => Helper::baseUrl('chat'),
191 'action_text' => $this->isPluginInstalled('fluent-messaging/fluent-messaging.php') ? __('Active FluentCommunity Chat', 'fluent-community') : __('Install FluentCommunity Chat', 'fluent-community'),
192 'description' => __('FluentCommunity Chat is a real-time chat plugin for WordPress. It allows you to create a chat room for your community members.', 'fluent-community')
193 ],
194 'fluent-notify' => [
195 'is_repo' => false,
196 'title' => __('FluentNotify', 'fluent-community'),
197 'logo' => Helper::assetUrl('images/brands/fluent-notify.svg'),
198 'is_installed' => defined('FLUENT_NOTIFY_PLUGIN_VERSION'),
199 'learn_more_url' => 'https://fluentnotify.com',
200 'action_text' => $this->isPluginInstalled('fluent-notify/fluent-notify.php') ? __('Active FluentNotify', 'fluent-community') : __('Install FluentNotify', 'fluent-community'),
201 'description' => __('Send browser push notifications to your community members for comments, replies and mentions.', 'fluent-community')
202 ],
203 'fluent-player' => [
204 'is_repo' => false,
205 'title' => __('FluentPlayer', 'fluent-community'),
206 'logo' => Helper::assetUrl('images/brands/fluent-player.svg'),
207 'is_installed' => defined('FLUENT_PLAYER_VERSION'),
208 'learn_more_url' => 'https://wordpress.org/plugins/fluent-player/',
209 'action_text' => $this->isPluginInstalled('fluent-player/fluent-player.php') ? __('Active FluentPlayer', 'fluent-community') : __('Install FluentPlayer', 'fluent-community'),
210 'description' => __('Advanced video player with support for YouTube, Vimeo, HLS and more.', 'fluent-community')
211 ],
212 'fluent-cart' => [
213 'is_repo' => true,
214 'title' => __('FluentCart', 'fluent-community'),
215 'logo' => Helper::assetUrl('images/brands/fluent-cart.svg'),
216 'is_installed' => defined('FLUENTCART_VERSION'),
217 'learn_more_url' => 'https://wordpress.org/plugins/fluent-cart/',
218 'settings_url' => defined('FLUENTCART_VERSION') ? admin_url('admin.php?page=fluent-cart#/') : '',
219 'action_text' => $this->isPluginInstalled('fluent-cart/fluent-cart.php') ? __('Active FluentCart', 'fluent-community') : __('Install Fluent Cart', 'fluent-community'),
220 'description' => __('The easiest way to sell digital and physical products in WordPress. Create, manage, and sell products with ease.', 'fluent-community')
221 ],
222 'fluent-crm' => [
223 'is_repo' => true,
224 'title' => __('FluentCRM', 'fluent-community'),
225 'logo' => Helper::assetUrl('images/brands/fluentcrm.svg'),
226 'is_installed' => defined('FLUENTCRM'),
227 'learn_more_url' => 'https://fluentcrm.com',
228 'settings_url' => defined('FLUENTCRM') ? admin_url('admin.php?page=fluentcrm-admin#/') : '',
229 'action_text' => $this->isPluginInstalled('fluent-crm/fluent-crm.php') ? __('Active FluentCRM', 'fluent-community') : __('Install FluentCRM', 'fluent-community'),
230 'description' => __('The Best Email Marketing Automation Plugin for WordPress. Capture, Segment and Automate your Marketing.', 'fluent-community')
231 ],
232 'fluentform' => [
233 'is_repo' => true,
234 'title' => __('Fluent Forms', 'fluent-community'),
235 'logo' => Helper::assetUrl('images/brands/fluentform.png'),
236 'is_installed' => defined('FLUENTFORM'),
237 'learn_more_url' => 'https://wordpress.org/plugins/fluentform/',
238 'settings_url' => defined('FLUENTFORM') ? admin_url('admin.php?page=fluent_forms') : '',
239 'action_text' => $this->isPluginInstalled('fluentform/fluentform.php') ? __('Active Fluent Forms', 'fluent-community') : __('Install Fluent Forms', 'fluent-community'),
240 'description' => __('Collect leads and build any type of forms, accept payments, connect with your CRM with the Fastest Contact Form Builder Plugin for WordPress', 'fluent-community')
241 ],
242 'fluent-smtp' => [
243 'is_repo' => true,
244 'title' => __('Fluent SMTP', 'fluent-community'),
245 'logo' => Helper::assetUrl('images/brands/fluent-smtp.svg'),
246 'is_installed' => defined('FLUENTMAIL'),
247 'learn_more_url' => 'https://wordpress.org/plugins/fluent-smtp/',
248 'settings_url' => defined('FLUENTMAIL') ? admin_url('options-general.php?page=fluent-mail#/') : '',
249 'action_text' => $this->isPluginInstalled('fluent-smtp/fluent-smtp.php') ? __('Active Fluent SMTP', 'fluent-community') : __('Install Fluent SMTP', 'fluent-community'),
250 'description' => __('Fluent SMTP is the ultimate SMTP and SES plugin for WordPress. Connect with any SMTP service, including SendGrid, Mailgun, SES, Sendinblue, PepiPost, Google, Microsoft, and more.', 'fluent-community')
251 ],
252 'fluent-support' => [
253 'is_repo' => true,
254 'title' => __('Fluent Support', 'fluent-community'),
255 'logo' => Helper::assetUrl('images/brands/fluent-support.svg'),
256 'is_installed' => defined('FLUENT_SUPPORT_VERSION'),
257 'learn_more_url' => 'https://wordpress.org/plugins/fluent-support/',
258 'settings_url' => defined('FLUENT_SUPPORT_VERSION') ? admin_url('admin.php?page=fluent-support#/') : '',
259 'action_text' => $this->isPluginInstalled('fluent-support/fluent-support.php') ? __('Active Fluent Support', 'fluent-community') : __('Install Fluent Support', 'fluent-community'),
260 'description' => __('WordPress Helpdesk and Customer Support Ticket Plugin. Provide awesome support and manage customer queries right from your WordPress dashboard.', 'fluent-community')
261 ]
262 ];
263
264 if (defined('FLUENT_COMMUNITY_PRO')) {
265 $addons['wp-payment-form'] = [
266 'is_repo' => true,
267 'title' => __('Paymattic', 'fluent-community'),
268 'logo' => Helper::assetUrl('images/brands/paymattic.png'),
269 'is_installed' => defined('WPPAYFORM_VERSION'),
270 'learn_more_url' => 'https://wordpress.org/plugins/wp-payment-form/',
271 'settings_url' => defined('WPPAYFORM_VERSION') ? admin_url('admin.php?page=wppayform.php#/integrations/fluent_community') : '',
272 'action_text' => $this->isPluginInstalled('wp-payment-form/wp-payment-form.php') ? __('Active Paymattic', 'fluent-community') : __('Install Paymattic', 'fluent-community'),
273 'description' => __('Paymattic – Secure, Simple Payment & Donation with Subscription Payments, Recurring Donations, Customer Management', 'fluent-community')
274 ];
275 }
276
277 return $addons;
278 }
279
280 private function isPluginInstalled($plugin)
281 {
282 return file_exists(WP_PLUGIN_DIR . '/' . $plugin);
283 }
284
285 public function installPlugin(Request $request)
286 {
287 if (!current_user_can('install_plugins')) {
288 return $this->sendError([
289 'message' => __('You do not have permission to install plugins', 'fluent-community')
290 ]);
291 }
292
293 $pluginSlug = $request->get('plugin');
294
295 $addons = $this->getAddons();
296
297 if (!isset($addons[$pluginSlug])) {
298 return $this->sendError(['message' => __('Invalid Plugin', 'fluent-community')]);
299 }
300
301 $details = $addons[$pluginSlug];
302
303 if ($details['is_repo']) {
304 $plugin = [
305 'name' => $details['title'],
306 'repo-slug' => $pluginSlug,
307 'file' => $pluginSlug . '.php',
308 ];
309 try {
310 OnboardingService::backgroundInstaller($plugin);
311 } catch (\Exception $e) {
312 return $this->sendError(['message' => $e->getMessage()]);
313 }
314 } else {
315 if ($pluginSlug == 'fluent-messaging') {
316 if (!defined('FLUENT_COMMUNITY_PRO')) {
317 return $this->sendError(['message' => __('FluentMessaging is a Pro Plugin. Please install FluentCommunity Pro first.', 'fluent-community')]);
318 }
319 do_action('fluent_community/install_messaging_plugin');
320 } else if ($pluginSlug == 'fluent-player') {
321
322 if (!defined('FLUENT_COMMUNITY_PRO')) {
323 return $this->sendError(['message' => __('FluentPlayer requires the pro version of FluentCommunity. Please install FluentCommunity Pro first.', 'fluent-community')]);
324 }
325
326 do_action('fluent_community/install_fluent_player_plugin');
327 } else if ($pluginSlug == 'fluent-notify') {
328 try {
329 do_action('fluent_community/install_fluent_notify_plugin');
330 } catch (\Exception $e) {
331 return $this->sendError(['message' => $e->getMessage()]);
332 }
333 }
334 }
335
336 return [
337 'message' => __('Plugin has been installed Successfully', 'fluent-community'),
338 'is_installed' => true
339 ];
340 }
341
342 public function getCustomizationSettings(Request $request)
343 {
344 $data = [
345 'settings' => Utility::getCustomizationSettings()
346 ];
347
348 return apply_filters('fluent_community/customization_settings_api_response', $data, $request->all());
349 }
350
351 public function updateCustomizationSettings(Request $request)
352 {
353 $settings = $request->get('settings', []);
354
355 $yesNoFields = [
356 'dark_mode', 'fixed_page_header', 'show_powered_by', 'show_post_modal', 'feed_link_on_sidebar', 'fixed_sidebar', 'icon_on_header_menu', 'disable_feed_layout', 'collapse_sidebar_groups', 'hide_header_on_scroll', 'enable_sidebar_toggle'
357 ];
358
359 foreach ($settings as $key => $value) {
360 if (in_array($key, $yesNoFields)) {
361 $settings[$key] = $value == 'yes' ? 'yes' : 'no';
362 } else if ($key == 'default_theme_mode') {
363 $settings[$key] = in_array($value, ['light', 'dark', 'system'], true) ? $value : 'light';
364 } else if ($key == 'affiliate_id') {
365 $settings[$key] = (int)$value;
366 if (!$settings[$key]) {
367 $settings[$key] = '';
368 }
369 } else {
370 $settings[$key] = sanitize_text_field($value);
371 }
372 }
373
374 if (isset($settings['dark_mode']) && $settings['dark_mode'] !== 'yes') {
375 $settings['default_theme_mode'] = 'light';
376 }
377
378 Utility::updateCustomizationSettings($settings);
379
380 return [
381 'message' => __('Customization settings have been saved successfully.', 'fluent-community')
382 ];
383 }
384
385 public function getFluentPlayerSettings(Request $request)
386 {
387 return [
388 'settings' => \FluentCommunity\Modules\Integrations\FluentPlayer\Bootstrap::getSettings()
389 ];
390 }
391
392 public function updateFluentPlayerSettings(Request $request)
393 {
394 $settings = $request->get('settings', []);
395
396 $updatedSettings = \FluentCommunity\Modules\Integrations\FluentPlayer\Bootstrap::updateSettings($settings);
397
398 return [
399 'message' => __('FluentPlayer settings have been saved successfully.', 'fluent-community'),
400 'settings' => $updatedSettings
401 ];
402 }
403
404 public function getPrivacySettings(Request $request)
405 {
406 $data = [
407 'settings' => Utility::getPrivacySettings()
408 ];
409
410 return apply_filters('fluent_community/privacy_settings_api_response', $data, $request->all());
411 }
412
413 public function updatePrivacySettings(Request $request)
414 {
415 $settings = $request->get('settings', []);
416 Utility::updatePrivacySettings($settings);
417
418 return [
419 'message' => __('Privacy settings have been saved successfully.', 'fluent-community')
420 ];
421 }
422
423 public function getColorConfig(Request $request)
424 {
425 $config = Utility::getColorConfig('edit');
426 $schemas = Utility::getColorSchemas();
427
428 $data = [
429 'config' => $config,
430 'schemas' => $schemas
431 ];
432
433 return apply_filters('fluent_community/color_config_api_response', $data, $request->all());
434 }
435
436 public function getCrmTaggingConfig(Request $request)
437 {
438 $defaults = [
439 'is_enabled' => 'no',
440 'tagging_maps' => [],
441 'linked_maps' => [],
442 'create_crm_contact' => 'yes',
443 'create_user' => 'no',
444 'send_welcome_email' => 'yes',
445 'has_space_tagging' => 'no',
446 'has_space_sync' => 'no',
447 'has_course_tagging' => 'no',
448 'has_course_sync' => 'no',
449 ];
450
451 $settings = get_option('_fcom_crm_tagging', []);
452 $settings = wp_parse_args($settings, $defaults);
453
454 $spaceGroups = SpaceGroup::with(['spaces' => function ($query) {
455 $query->where('type', 'community');
456 }])
457 ->orderBy('serial', 'ASC')
458 ->get();
459
460 $formattedSpaceGroups = [];
461 foreach ($spaceGroups as $spaceGroup) {
462 if ($spaceGroup->spaces->isEmpty()) {
463 continue;
464 }
465
466 $spaces = $spaceGroup->spaces->map(function ($space) {
467 return [
468 'id' => $space->id,
469 'title' => $space->title,
470 'privacy' => $space->privacy,
471 'slug' => $space->slug,
472 'icon' => $space->getIconMark(),
473 'type' => $space->type,
474 ];
475 });
476
477 $formattedSpaceGroups[] = [
478 'id' => $spaceGroup->id,
479 'title' => $spaceGroup->title,
480 'spaces' => $spaces
481 ];
482 }
483
484 $otherSpaces = Space::whereNull('parent_id')
485 ->orderBy('title', 'ASC')
486 ->get();
487
488 if (!$otherSpaces->isEmpty()) {
489 $formattedSpaceGroups[] = [
490 'id' => 'other',
491 'title' => __('Other Spaces', 'fluent-community'),
492 'spaces' => $otherSpaces->map(function ($space) {
493 return [
494 'id' => $space->id,
495 'type' => $space->type,
496 'title' => $space->title,
497 'privacy' => $space->privacy,
498 'slug' => $space->slug,
499 'icon' => $space->getIconMark(),
500 ];
501 })
502 ];
503 }
504
505 $courses = Course::orderBy('title', 'ASC')->get();
506
507 if (!$courses->isEmpty()) {
508 $formattedSpaceGroups[] = [
509 'id' => 'courses',
510 'title' => __('All Courses', 'fluent-community'),
511 'spaces' => $courses->map(function ($course) {
512 return [
513 'id' => $course->id,
514 'title' => $course->title,
515 'privacy' => $course->privacy,
516 'slug' => $course->slug,
517 'icon' => $course->getIconMark(),
518 'type' => $course->type,
519 ];
520 })
521 ];
522 }
523
524 if (empty($settings['tagging_maps'])) {
525 $settings['tagging_maps'] = (object)[];
526 }
527
528 if (empty($settings['linked_maps'])) {
529 $settings['linked_maps'] = (object)[];
530 }
531
532 if (defined('FLUENTCRM')) {
533 $fluentCrmTags = \FluentCrm\App\Models\Tag::select(['id', 'title'])->orderBy('title', 'ASC')->get();
534 } else {
535 $fluentCrmTags = [];
536 }
537
538
539 $data = [
540 'settings' => $settings,
541 'spaceGroups' => $formattedSpaceGroups,
542 'crm_tags' => $fluentCrmTags,
543 'has_fluentcrm' => defined('FLUENTCRM')
544 ];
545 return apply_filters('fluent_community/crm_tagging_config_api_response', $data, $request->all());
546 }
547 }
548