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

533 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 '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-player' => [
195 'is_repo' => false,
196 'title' => __('FluentPlayer', 'fluent-community'),
197 'logo' => Helper::assetUrl('images/brands/fluent-player.svg'),
198 'is_installed' => defined('FLUENT_PLAYER_VERSION'),
199 'learn_more_url' => 'https://wordpress.org/plugins/fluent-player/',
200 'action_text' => $this->isPluginInstalled('fluent-player/fluent-player.php') ? __('Active FluentPlayer', 'fluent-community') : __('Install FluentPlayer', 'fluent-community'),
201 'description' => __('Advanced video player with support for YouTube, Vimeo, HLS and more.', 'fluent-community')
202 ],
203 'fluent-cart' => [
204 'is_repo' => true,
205 'title' => __('FluentCart', 'fluent-community'),
206 'logo' => Helper::assetUrl('images/brands/fluent-cart.svg'),
207 'is_installed' => defined('FLUENTCART_VERSION'),
208 'learn_more_url' => 'https://wordpress.org/plugins/fluent-cart/',
209 'settings_url' => defined('FLUENTCART_VERSION') ? admin_url('admin.php?page=fluent-cart#/') : '',
210 'action_text' => $this->isPluginInstalled('fluent-cart/fluent-cart.php') ? __('Active FluentCart', 'fluent-community') : __('Install Fluent Cart', 'fluent-community'),
211 'description' => __('The easiest way to sell digital and physical products in WordPress. Create, manage, and sell products with ease.', 'fluent-community')
212 ],
213 'fluent-crm' => [
214 'is_repo' => true,
215 'title' => __('FluentCRM', 'fluent-community'),
216 'logo' => Helper::assetUrl('images/brands/fluentcrm.svg'),
217 'is_installed' => defined('FLUENTCRM'),
218 'learn_more_url' => 'https://fluentcrm.com',
219 'settings_url' => defined('FLUENTCRM') ? admin_url('admin.php?page=fluentcrm-admin#/') : '',
220 'action_text' => $this->isPluginInstalled('fluent-crm/fluent-crm.php') ? __('Active FluentCRM', 'fluent-community') : __('Install FluentCRM', 'fluent-community'),
221 'description' => __('The Best Email Marketing Automation Plugin for WordPress. Capture, Segment and Automate your Marketing.', 'fluent-community')
222 ],
223 'fluentform' => [
224 'is_repo' => true,
225 'title' => __('Fluent Forms', 'fluent-community'),
226 'logo' => Helper::assetUrl('images/brands/fluentform.png'),
227 'is_installed' => defined('FLUENTFORM'),
228 'learn_more_url' => 'https://wordpress.org/plugins/fluentform/',
229 'settings_url' => defined('FLUENTFORM') ? admin_url('admin.php?page=fluent_forms') : '',
230 'action_text' => $this->isPluginInstalled('fluentform/fluentform.php') ? __('Active Fluent Forms', 'fluent-community') : __('Install Fluent Forms', 'fluent-community'),
231 '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')
232 ],
233 'fluent-smtp' => [
234 'is_repo' => true,
235 'title' => __('Fluent SMTP', 'fluent-community'),
236 'logo' => Helper::assetUrl('images/brands/fluent-smtp.svg'),
237 'is_installed' => defined('FLUENTMAIL'),
238 'learn_more_url' => 'https://wordpress.org/plugins/fluent-smtp/',
239 'settings_url' => defined('FLUENTMAIL') ? admin_url('options-general.php?page=fluent-mail#/') : '',
240 'action_text' => $this->isPluginInstalled('fluent-smtp/fluent-smtp.php') ? __('Active Fluent SMTP', 'fluent-community') : __('Install Fluent SMTP', 'fluent-community'),
241 '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')
242 ],
243 'fluent-support' => [
244 'is_repo' => true,
245 'title' => __('Fluent Support', 'fluent-community'),
246 'logo' => Helper::assetUrl('images/brands/fluent-support.svg'),
247 'is_installed' => defined('FLUENT_SUPPORT_VERSION'),
248 'learn_more_url' => 'https://wordpress.org/plugins/fluent-support/',
249 'settings_url' => defined('FLUENT_SUPPORT_VERSION') ? admin_url('admin.php?page=fluent-support#/') : '',
250 'action_text' => $this->isPluginInstalled('fluent-support/fluent-support.php') ? __('Active Fluent Support', 'fluent-community') : __('Install Fluent Support', 'fluent-community'),
251 'description' => __('WordPress Helpdesk and Customer Support Ticket Plugin. Provide awesome support and manage customer queries right from your WordPress dashboard.', 'fluent-community')
252 ]
253 ];
254
255 if (defined('FLUENT_COMMUNITY_PRO')) {
256 $addons['wp-payment-form'] = [
257 'is_repo' => true,
258 'title' => __('Paymattic', 'fluent-community'),
259 'logo' => Helper::assetUrl('images/brands/paymattic.png'),
260 'is_installed' => defined('WPPAYFORM_VERSION'),
261 'learn_more_url' => 'https://wordpress.org/plugins/wp-payment-form/',
262 'settings_url' => defined('WPPAYFORM_VERSION') ? admin_url('admin.php?page=wppayform.php#/integrations/fluent_community') : '',
263 'action_text' => $this->isPluginInstalled('wp-payment-form/wp-payment-form.php') ? __('Active Paymattic', 'fluent-community') : __('Install Paymattic', 'fluent-community'),
264 'description' => __('Paymattic – Secure, Simple Payment & Donation with Subscription Payments, Recurring Donations, Customer Management', 'fluent-community')
265 ];
266 }
267
268 return $addons;
269 }
270
271 private function isPluginInstalled($plugin)
272 {
273 return file_exists(WP_PLUGIN_DIR . '/' . $plugin);
274 }
275
276 public function installPlugin(Request $request)
277 {
278 if (!current_user_can('install_plugins')) {
279 return $this->sendError([
280 'message' => __('You do not have permission to install plugins', 'fluent-community')
281 ]);
282 }
283
284 $pluginSlug = $request->get('plugin');
285
286 $addons = $this->getAddons();
287
288 if (!isset($addons[$pluginSlug])) {
289 return $this->sendError(['message' => __('Invalid Plugin', 'fluent-community')]);
290 }
291
292 $details = $addons[$pluginSlug];
293
294 if ($details['is_repo']) {
295 $plugin = [
296 'name' => $details['title'],
297 'repo-slug' => $pluginSlug,
298 'file' => $pluginSlug . '.php',
299 ];
300 try {
301 OnboardingService::backgroundInstaller($plugin);
302 } catch (\Exception $e) {
303 return $this->sendError(['message' => $e->getMessage()]);
304 }
305 } else {
306 if ($pluginSlug == 'fluent-messaging') {
307 if (!defined('FLUENT_COMMUNITY_PRO')) {
308 return $this->sendError(['message' => __('FluentMessaging is a Pro Plugin. Please install FluentCommunity Pro first.', 'fluent-community')]);
309 }
310 do_action('fluent_community/install_messaging_plugin');
311 } else if ($pluginSlug == 'fluent-player') {
312
313 if (!defined('FLUENT_COMMUNITY_PRO')) {
314 return $this->sendError(['message' => __('FluentPlayer requires the pro version of FluentCommunity. Please install FluentCommunity Pro first.', 'fluent-community')]);
315 }
316
317 do_action('fluent_community/install_fluent_player_plugin');
318 }
319 }
320
321 return [
322 'message' => __('Plugin has been installed Successfully', 'fluent-community'),
323 'is_installed' => true
324 ];
325 }
326
327 public function getCustomizationSettings(Request $request)
328 {
329 $data = [
330 'settings' => Utility::getCustomizationSettings()
331 ];
332
333 return apply_filters('fluent_community/customization_settings_api_response', $data, $request->all());
334 }
335
336 public function updateCustomizationSettings(Request $request)
337 {
338 $settings = $request->get('settings', []);
339
340 $yesNoFields = [
341 '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'
342 ];
343
344 foreach ($settings as $key => $value) {
345 if (in_array($key, $yesNoFields)) {
346 $settings[$key] = $value == 'yes' ? 'yes' : 'no';
347 } else if ($key == 'default_theme_mode') {
348 $settings[$key] = in_array($value, ['light', 'dark', 'system'], true) ? $value : 'light';
349 } else if ($key == 'affiliate_id') {
350 $settings[$key] = (int)$value;
351 if (!$settings[$key]) {
352 $settings[$key] = '';
353 }
354 } else {
355 $settings[$key] = sanitize_text_field($value);
356 }
357 }
358
359 if (isset($settings['dark_mode']) && $settings['dark_mode'] !== 'yes') {
360 $settings['default_theme_mode'] = 'light';
361 }
362
363 Utility::updateCustomizationSettings($settings);
364
365 return [
366 'message' => __('Customization settings have been saved successfully.', 'fluent-community')
367 ];
368 }
369
370 public function getFluentPlayerSettings(Request $request)
371 {
372 return [
373 'settings' => \FluentCommunity\Modules\Integrations\FluentPlayer\Bootstrap::getSettings()
374 ];
375 }
376
377 public function updateFluentPlayerSettings(Request $request)
378 {
379 $settings = $request->get('settings', []);
380
381 $updatedSettings = \FluentCommunity\Modules\Integrations\FluentPlayer\Bootstrap::updateSettings($settings);
382
383 return [
384 'message' => __('FluentPlayer settings have been saved successfully.', 'fluent-community'),
385 'settings' => $updatedSettings
386 ];
387 }
388
389 public function getPrivacySettings(Request $request)
390 {
391 $data = [
392 'settings' => Utility::getPrivacySettings()
393 ];
394
395 return apply_filters('fluent_community/privacy_settings_api_response', $data, $request->all());
396 }
397
398 public function updatePrivacySettings(Request $request)
399 {
400 $settings = $request->get('settings', []);
401 Utility::updatePrivacySettings($settings);
402
403 return [
404 'message' => __('Privacy settings have been saved successfully.', 'fluent-community')
405 ];
406 }
407
408 public function getColorConfig(Request $request)
409 {
410 $config = Utility::getColorConfig('edit');
411 $schemas = Utility::getColorSchemas();
412
413 $data = [
414 'config' => $config,
415 'schemas' => $schemas
416 ];
417
418 return apply_filters('fluent_community/color_config_api_response', $data, $request->all());
419 }
420
421 public function getCrmTaggingConfig(Request $request)
422 {
423 $defaults = [
424 'is_enabled' => 'no',
425 'tagging_maps' => [],
426 'linked_maps' => [],
427 'create_crm_contact' => 'yes',
428 'create_user' => 'no',
429 'send_welcome_email' => 'yes',
430 'has_space_tagging' => 'no',
431 'has_space_sync' => 'no',
432 'has_course_tagging' => 'no',
433 'has_course_sync' => 'no',
434 ];
435
436 $settings = get_option('_fcom_crm_tagging', []);
437 $settings = wp_parse_args($settings, $defaults);
438
439 $spaceGroups = SpaceGroup::with(['spaces' => function ($query) {
440 $query->where('type', 'community');
441 }])
442 ->orderBy('serial', 'ASC')
443 ->get();
444
445 $formattedSpaceGroups = [];
446 foreach ($spaceGroups as $spaceGroup) {
447 if ($spaceGroup->spaces->isEmpty()) {
448 continue;
449 }
450
451 $spaces = $spaceGroup->spaces->map(function ($space) {
452 return [
453 'id' => $space->id,
454 'title' => $space->title,
455 'privacy' => $space->privacy,
456 'slug' => $space->slug,
457 'icon' => $space->getIconMark(),
458 'type' => $space->type,
459 ];
460 });
461
462 $formattedSpaceGroups[] = [
463 'id' => $spaceGroup->id,
464 'title' => $spaceGroup->title,
465 'spaces' => $spaces
466 ];
467 }
468
469 $otherSpaces = Space::whereNull('parent_id')
470 ->orderBy('title', 'ASC')
471 ->get();
472
473 if (!$otherSpaces->isEmpty()) {
474 $formattedSpaceGroups[] = [
475 'id' => 'other',
476 'title' => __('Other Spaces', 'fluent-community'),
477 'spaces' => $otherSpaces->map(function ($space) {
478 return [
479 'id' => $space->id,
480 'type' => $space->type,
481 'title' => $space->title,
482 'privacy' => $space->privacy,
483 'slug' => $space->slug,
484 'icon' => $space->getIconMark(),
485 ];
486 })
487 ];
488 }
489
490 $courses = Course::orderBy('title', 'ASC')->get();
491
492 if (!$courses->isEmpty()) {
493 $formattedSpaceGroups[] = [
494 'id' => 'courses',
495 'title' => __('All Courses', 'fluent-community'),
496 'spaces' => $courses->map(function ($course) {
497 return [
498 'id' => $course->id,
499 'title' => $course->title,
500 'privacy' => $course->privacy,
501 'slug' => $course->slug,
502 'icon' => $course->getIconMark(),
503 'type' => $course->type,
504 ];
505 })
506 ];
507 }
508
509 if (empty($settings['tagging_maps'])) {
510 $settings['tagging_maps'] = (object)[];
511 }
512
513 if (empty($settings['linked_maps'])) {
514 $settings['linked_maps'] = (object)[];
515 }
516
517 if (defined('FLUENTCRM')) {
518 $fluentCrmTags = \FluentCrm\App\Models\Tag::select(['id', 'title'])->orderBy('title', 'ASC')->get();
519 } else {
520 $fluentCrmTags = [];
521 }
522
523
524 $data = [
525 'settings' => $settings,
526 'spaceGroups' => $formattedSpaceGroups,
527 'crm_tags' => $fluentCrmTags,
528 'has_fluentcrm' => defined('FLUENTCRM')
529 ];
530 return apply_filters('fluent_community/crm_tagging_config_api_response', $data, $request->all());
531 }
532 }
533