PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.7.7
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.7.7
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.7.7, at app/Http/Controllers/SettingController.php

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