| @@ -2,21 +2,33 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace FluentCommunity\App\Http\Controllers; |
| 4 | 4 | |
| 5 | 5 | use FluentCommunity\App\Functions\Utility; |
| 6 | +use FluentCommunity\App\Models\Space; | |
| 7 | +use FluentCommunity\App\Models\SpaceGroup; | |
| 6 | 8 | use FluentCommunity\App\Services\Helper; |
| 9 | +use FluentCommunity\App\Services\OnboardingService; | |
| 7 | 10 | use FluentCommunity\Framework\Http\Request\Request; |
| 8 | 11 | use FluentCommunity\Framework\Support\Arr; |
| 9 | 12 | use FluentCommunity\Framework\Support\Sanitizer; |
| 13 | +use FluentCommunity\Modules\Course\Model\Course; | |
| 10 | 14 | |
| 11 | 15 | class SettingController extends Controller |
| 12 | 16 | { |
| 13 | 17 | public function getFeatures() |
| 14 | 18 | { |
| 15 | - return [ | |
| 16 | - 'features' => Utility::getFeaturesConfig(), | |
| 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, | |
| 17 | 27 | 'addOns' => $this->getAddons() |
| 18 | 28 | ]; |
| 29 | + | |
| 30 | + return apply_filters('fluent_community/features_api_response', $data, $this->request->all()); | |
| 19 | 31 | } |
| 20 | 32 | |
| 21 | 33 | public function setFeatures(Request $request) |
| 22 | 34 | { |
| @@ -26,17 +38,29 @@ | ||
| 26 | 38 | |
| 27 | 39 | $data = $request->get('features', []); |
| 28 | 40 | |
| 29 | 41 | $data = Sanitizer::sanitize($data, [ |
| 30 | - 'leader_board_module' => 'sanitize_text_field', | |
| 31 | - 'course_module' => 'sanitize_text_field', | |
| 32 | - 'giphy_module' => 'sanitize_text_field', | |
| 33 | - 'giphy_api_key' => 'sanitize_text_field', | |
| 34 | - 'cloud_storage' => 'sanitize_text_field', | |
| 35 | - 'emoji_module' => 'sanitize_text_field', | |
| 36 | - 'user_badge' => 'sanitize_text_field', | |
| 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', | |
| 37 | 53 | ]); |
| 38 | 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 | + | |
| 39 | 63 | Utility::updateOption('fluent_community_features', $data); |
| 40 | 64 | |
| 41 | 65 | return [ |
| 42 | 66 | 'message' => __('Features saved successfully.', 'fluent-community') |
| @@ -55,32 +79,35 @@ | ||
| 55 | 79 | $formattedGroups[$indexName] = []; |
| 56 | 80 | } |
| 57 | 81 | } |
| 58 | 82 | |
| 83 | + $afterCommunityLinkGroups = Arr::get($formattedGroups, 'afterCommunityLinkGroups', []); | |
| 84 | + $formattedAfterCommunityGroups = []; | |
| 59 | 85 | |
| 60 | - if (empty($formattedGroups['afterCommunityLinkGroups']) || !is_array($formattedGroups['afterCommunityLinkGroups'])) { | |
| 61 | - $formattedGroups['afterCommunityLinkGroups'] = [ | |
| 62 | - [ | |
| 63 | - 'title' => __('Links', 'fluent-community'), | |
| 64 | - 'slug' => 'custom_footer_links', | |
| 65 | - 'items' => [] | |
| 66 | - ] | |
| 67 | - ]; | |
| 68 | - } else { | |
| 69 | - foreach ($formattedGroups['afterCommunityLinkGroups'] as &$group) { | |
| 70 | - if (is_array($group) && !empty($group['items'])) { | |
| 71 | - $group['items'] = array_values($group['items']); | |
| 72 | - } else { | |
| 73 | - $group = [ | |
| 74 | - 'items' => [] | |
| 75 | - ]; | |
| 76 | - } | |
| 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 | + ]; | |
| 77 | 101 | } |
| 78 | 102 | } |
| 79 | 103 | |
| 80 | - return [ | |
| 104 | + $formattedGroups['afterCommunityLinkGroups'] = $formattedAfterCommunityGroups; | |
| 105 | + | |
| 106 | + $data = [ | |
| 81 | 107 | 'menuSettings' => $formattedGroups |
| 82 | 108 | ]; |
| 109 | + return apply_filters('fluent_community/menu_settings_api_response', $data, $request->all()); | |
| 83 | 110 | } |
| 84 | 111 | |
| 85 | 112 | public function saveMenuSettings(Request $request) |
| 86 | 113 | { |
| @@ -98,15 +125,13 @@ | ||
| 98 | 125 | $menuSettings['beforeCommunityMenuItems'] = $this->formatMenuGroup($beforeCommunityMenuItems, $previousSettings['beforeCommunityMenuItems']); |
| 99 | 126 | |
| 100 | 127 | $formattedAfterCommunityGroups = []; |
| 101 | 128 | foreach ($afterCommunityLinkGroups as $afterCommunityLinkGroup) { |
| 102 | - if (empty($afterCommunityLinkGroup['items']) || empty($afterCommunityLinkGroup['title'])) { | |
| 103 | - continue; | |
| 104 | - } | |
| 129 | + if (empty($afterCommunityLinkGroup['title'])) continue; | |
| 105 | 130 | |
| 106 | 131 | $formattedAfterCommunityGroups[] = [ |
| 107 | 132 | 'title' => sanitize_text_field($afterCommunityLinkGroup['title']), |
| 108 | - 'slug' => $afterCommunityLinkGroup['slug'] ?: 'custom_footer_group_' . time(), | |
| 133 | + 'slug' => !empty($afterCommunityLinkGroup['slug']) ? $afterCommunityLinkGroup['slug'] : 'custom_footer_group_' . time(), | |
| 109 | 134 | 'items' => $this->formatMenuGroup($afterCommunityLinkGroup['items'], []) |
| 110 | 135 | ]; |
| 111 | 136 | } |
| 112 | 137 | |
| @@ -154,9 +179,9 @@ | ||
| 154 | 179 | } |
| 155 | 180 | |
| 156 | 181 | public function getAddons() |
| 157 | 182 | { |
| 158 | - return [ | |
| 183 | + $addons = [ | |
| 159 | 184 | 'fluent-messaging' => [ |
| 160 | 185 | 'is_repo' => false, |
| 161 | 186 | 'title' => __('FluentCommunity Chat', 'fluent-community'), |
| 162 | 187 | 'logo' => Helper::assetUrl('images/brands/fluent-messages.svg'), |
| @@ -165,8 +190,36 @@ | ||
| 165 | 190 | 'settings_url' => Helper::baseUrl('chat'), |
| 166 | 191 | 'action_text' => $this->isPluginInstalled('fluent-messaging/fluent-messaging.php') ? __('Active FluentCommunity Chat', 'fluent-community') : __('Install FluentCommunity Chat', 'fluent-community'), |
| 167 | 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') |
| 168 | 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 | + ], | |
| 169 | 222 | 'fluent-crm' => [ |
| 170 | 223 | 'is_repo' => true, |
| 171 | 224 | 'title' => __('FluentCRM', 'fluent-community'), |
| 172 | 225 | 'logo' => Helper::assetUrl('images/brands/fluentcrm.svg'), |
| @@ -171,9 +224,9 @@ | ||
| 171 | 224 | 'title' => __('FluentCRM', 'fluent-community'), |
| 172 | 225 | 'logo' => Helper::assetUrl('images/brands/fluentcrm.svg'), |
| 173 | 226 | 'is_installed' => defined('FLUENTCRM'), |
| 174 | 227 | 'learn_more_url' => 'https://fluentcrm.com', |
| 175 | - 'settings_url' => admin_url('admin.php?page=fluentcrm-admin#/'), | |
| 228 | + 'settings_url' => defined('FLUENTCRM') ? admin_url('admin.php?page=fluentcrm-admin#/') : '', | |
| 176 | 229 | 'action_text' => $this->isPluginInstalled('fluent-crm/fluent-crm.php') ? __('Active FluentCRM', 'fluent-community') : __('Install FluentCRM', 'fluent-community'), |
| 177 | 230 | 'description' => __('The Best Email Marketing Automation Plugin for WordPress. Capture, Segment and Automate your Marketing.', 'fluent-community') |
| 178 | 231 | ], |
| 179 | 232 | 'fluentform' => [ |
| @@ -181,10 +234,10 @@ | ||
| 181 | 234 | 'title' => __('Fluent Forms', 'fluent-community'), |
| 182 | 235 | 'logo' => Helper::assetUrl('images/brands/fluentform.png'), |
| 183 | 236 | 'is_installed' => defined('FLUENTFORM'), |
| 184 | 237 | 'learn_more_url' => 'https://wordpress.org/plugins/fluentform/', |
| 185 | - 'settings_url' => admin_url('admin.php?page=fluent_forms'), | |
| 186 | - 'action_text' => $this->isPluginInstalled('fluent-form/fluent-form.php') ? __('Active Fluent Forms', 'fluent-community') : __('Install Fluent Forms', 'fluent-community'), | |
| 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'), | |
| 187 | 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') |
| 188 | 241 | ], |
| 189 | 242 | 'fluent-smtp' => [ |
| 190 | 243 | 'is_repo' => true, |
| @@ -191,9 +244,9 @@ | ||
| 191 | 244 | 'title' => __('Fluent SMTP', 'fluent-community'), |
| 192 | 245 | 'logo' => Helper::assetUrl('images/brands/fluent-smtp.svg'), |
| 193 | 246 | 'is_installed' => defined('FLUENTMAIL'), |
| 194 | 247 | 'learn_more_url' => 'https://wordpress.org/plugins/fluent-smtp/', |
| 195 | - 'settings_url' => admin_url('options-general.php?page=fluent-mail#/'), | |
| 248 | + 'settings_url' => defined('FLUENTMAIL') ? admin_url('options-general.php?page=fluent-mail#/') : '', | |
| 196 | 249 | 'action_text' => $this->isPluginInstalled('fluent-smtp/fluent-smtp.php') ? __('Active Fluent SMTP', 'fluent-community') : __('Install Fluent SMTP', 'fluent-community'), |
| 197 | 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') |
| 198 | 251 | ], |
| 199 | 252 | 'fluent-support' => [ |
| @@ -200,14 +253,29 @@ | ||
| 200 | 253 | 'is_repo' => true, |
| 201 | 254 | 'title' => __('Fluent Support', 'fluent-community'), |
| 202 | 255 | 'logo' => Helper::assetUrl('images/brands/fluent-support.svg'), |
| 203 | 256 | 'is_installed' => defined('FLUENT_SUPPORT_VERSION'), |
| 204 | - 'learn_more_url' => 'https://wordpress.org/plugins/fluent-connect/', | |
| 205 | - 'settings_url' => admin_url('admin.php?page=fluent-support#/'), | |
| 257 | + 'learn_more_url' => 'https://wordpress.org/plugins/fluent-support/', | |
| 258 | + 'settings_url' => defined('FLUENT_SUPPORT_VERSION') ? admin_url('admin.php?page=fluent-support#/') : '', | |
| 206 | 259 | 'action_text' => $this->isPluginInstalled('fluent-support/fluent-support.php') ? __('Active Fluent Support', 'fluent-community') : __('Install Fluent Support', 'fluent-community'), |
| 207 | 260 | 'description' => __('WordPress Helpdesk and Customer Support Ticket Plugin. Provide awesome support and manage customer queries right from your WordPress dashboard.', 'fluent-community') |
| 208 | 261 | ] |
| 209 | 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; | |
| 210 | 278 | } |
| 211 | 279 | |
| 212 | 280 | private function isPluginInstalled($plugin) |
| 213 | 281 | { |
| @@ -215,175 +283,104 @@ | ||
| 215 | 283 | } |
| 216 | 284 | |
| 217 | 285 | public function installPlugin(Request $request) |
| 218 | 286 | { |
| 219 | - if (!current_user_can('install_plugins')) { | |
| 220 | - return $this->sendError([ | |
| 221 | - 'message' => 'You do not have permission to install plugins' | |
| 222 | - ]); | |
| 223 | - } | |
| 224 | - | |
| 225 | 287 | $pluginSlug = $request->get('plugin'); |
| 226 | 288 | |
| 227 | 289 | $addons = $this->getAddons(); |
| 228 | 290 | |
| 229 | 291 | if (!isset($addons[$pluginSlug])) { |
| 230 | - return $this->sendError('Invalid Plugin'); | |
| 292 | + return $this->sendError(['message' => __('Invalid Plugin', 'fluent-community')]); | |
| 231 | 293 | } |
| 232 | 294 | |
| 233 | 295 | $details = $addons[$pluginSlug]; |
| 234 | 296 | |
| 235 | - if ($details['is_repo']) { | |
| 236 | - $plugin = [ | |
| 237 | - 'name' => $details['title'], | |
| 238 | - 'repo-slug' => $pluginSlug, | |
| 239 | - 'file' => $pluginSlug . '.php', | |
| 240 | - ]; | |
| 297 | + $pluginFile = $pluginSlug . '/' . $pluginSlug . '.php'; | |
| 241 | 298 | |
| 242 | - $this->backgroundInstaller($plugin, $pluginSlug); | |
| 243 | - } else { | |
| 244 | - if ($pluginSlug == 'fluent-messaging') { | |
| 245 | - | |
| 246 | - if (!defined('FLUENT_COMMUNITY_PRO')) { | |
| 247 | - return $this->sendError('Fluent Messaging is a Pro Plugin. Please install Fluent Space Pro first.'); | |
| 248 | - } | |
| 249 | - | |
| 250 | - do_action('fleunt_community/install_messaging_plugin'); | |
| 299 | + // Already on disk but deactivated: that is an activation, so it answers to | |
| 300 | + // activate_plugins and needs no download. | |
| 301 | + if (!$details['is_repo'] && $this->isPluginInstalled($pluginFile)) { | |
| 302 | + if (!current_user_can('activate_plugins')) { | |
| 303 | + return $this->sendError(['message' => __('You do not have permission to activate plugins', 'fluent-community')]); | |
| 251 | 304 | } |
| 252 | - } | |
| 253 | 305 | |
| 254 | - return [ | |
| 255 | - 'message' => __('Plugin has been installed Successfully', 'fluent-community'), | |
| 256 | - 'is_installed' => true | |
| 257 | - ]; | |
| 258 | - } | |
| 259 | - | |
| 260 | - private function backgroundInstaller($plugin_to_install, $plugin_id) | |
| 261 | - { | |
| 262 | - if (!empty($plugin_to_install['repo-slug'])) { | |
| 263 | - require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 264 | - require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; | |
| 265 | - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | |
| 266 | 306 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 267 | 307 | |
| 268 | - WP_Filesystem(); | |
| 308 | + if (!is_plugin_active($pluginFile)) { | |
| 309 | + $activated = activate_plugin($pluginFile); | |
| 269 | 310 | |
| 270 | - $skin = new \Automatic_Upgrader_Skin(); | |
| 271 | - $upgrader = new \WP_Upgrader($skin); | |
| 272 | - $installed_plugins = array_reduce(array_keys(\get_plugins()), array($this, 'associate_plugin_file'), | |
| 273 | - array()); | |
| 274 | - $plugin_slug = $plugin_to_install['repo-slug']; | |
| 275 | - $plugin_file = isset($plugin_to_install['file']) ? $plugin_to_install['file'] : $plugin_slug . '.php'; | |
| 276 | - $installed = false; | |
| 277 | - $activate = false; | |
| 278 | - | |
| 279 | - // See if the plugin is installed already. | |
| 280 | - if (isset($installed_plugins[$plugin_file])) { | |
| 281 | - $installed = true; | |
| 282 | - $activate = !is_plugin_active($installed_plugins[$plugin_file]); | |
| 311 | + if (is_wp_error($activated)) { | |
| 312 | + return $this->sendError(['message' => wp_kses_post($activated->get_error_message())]); | |
| 313 | + } | |
| 283 | 314 | } |
| 284 | 315 | |
| 285 | - // Install this thing! | |
| 286 | - if (!$installed) { | |
| 287 | - // Suppress feedback. | |
| 288 | - ob_start(); | |
| 316 | + return [ | |
| 317 | + 'message' => __('Plugin has been activated Successfully', 'fluent-community'), | |
| 318 | + 'is_installed' => true | |
| 319 | + ]; | |
| 320 | + } | |
| 289 | 321 | |
| 290 | - try { | |
| 291 | - $plugin_information = plugins_api( | |
| 292 | - 'plugin_information', | |
| 293 | - array( | |
| 294 | - 'slug' => $plugin_slug, | |
| 295 | - 'fields' => array( | |
| 296 | - 'short_description' => false, | |
| 297 | - 'sections' => false, | |
| 298 | - 'requires' => false, | |
| 299 | - 'rating' => false, | |
| 300 | - 'ratings' => false, | |
| 301 | - 'downloaded' => false, | |
| 302 | - 'last_updated' => false, | |
| 303 | - 'added' => false, | |
| 304 | - 'tags' => false, | |
| 305 | - 'homepage' => false, | |
| 306 | - 'donate_link' => false, | |
| 307 | - 'author_profile' => false, | |
| 308 | - 'author' => false, | |
| 309 | - ), | |
| 310 | - ) | |
| 311 | - ); | |
| 322 | + if (!current_user_can('install_plugins')) { | |
| 323 | + return $this->sendError([ | |
| 324 | + 'message' => __('You do not have permission to install plugins', 'fluent-community') | |
| 325 | + ]); | |
| 326 | + } | |
| 312 | 327 | |
| 313 | - if (is_wp_error($plugin_information)) { | |
| 314 | - throw new \Exception($plugin_information->get_error_message()); | |
| 315 | - } | |
| 328 | + if ($details['is_repo']) { | |
| 329 | + $plugin = [ | |
| 330 | + 'name' => $details['title'], | |
| 331 | + 'repo-slug' => $pluginSlug, | |
| 332 | + 'file' => $pluginSlug . '.php', | |
| 333 | + ]; | |
| 334 | + try { | |
| 335 | + OnboardingService::backgroundInstaller($plugin); | |
| 336 | + } catch (\Exception $e) { | |
| 337 | + return $this->sendError(['message' => $e->getMessage()]); | |
| 338 | + } | |
| 339 | + } else { | |
| 340 | + $installHook = ''; | |
| 316 | 341 | |
| 317 | - $package = $plugin_information->download_link; | |
| 318 | - $download = $upgrader->download_package($package); | |
| 342 | + if ($pluginSlug == 'fluent-messaging') { | |
| 343 | + if (!defined('FLUENT_COMMUNITY_PRO')) { | |
| 344 | + return $this->sendError(['message' => __('FluentMessaging is a Pro Plugin. Please install FluentCommunity Pro first.', 'fluent-community')]); | |
| 345 | + } | |
| 346 | + $installHook = 'fluent_community/install_messaging_plugin'; | |
| 347 | + } else if ($pluginSlug == 'fluent-player') { | |
| 319 | 348 | |
| 320 | - if (is_wp_error($download)) { | |
| 321 | - throw new \Exception($download->get_error_message()); | |
| 322 | - } | |
| 323 | - | |
| 324 | - $working_dir = $upgrader->unpack_package($download, true); | |
| 325 | - | |
| 326 | - if (is_wp_error($working_dir)) { | |
| 327 | - throw new \Exception($working_dir->get_error_message()); | |
| 328 | - } | |
| 329 | - | |
| 330 | - $result = $upgrader->install_package( | |
| 331 | - array( | |
| 332 | - 'source' => $working_dir, | |
| 333 | - 'destination' => WP_PLUGIN_DIR, | |
| 334 | - 'clear_destination' => false, | |
| 335 | - 'abort_if_destination_exists' => false, | |
| 336 | - 'clear_working' => true, | |
| 337 | - 'hook_extra' => array( | |
| 338 | - 'type' => 'plugin', | |
| 339 | - 'action' => 'install', | |
| 340 | - ), | |
| 341 | - ) | |
| 342 | - ); | |
| 343 | - | |
| 344 | - if (is_wp_error($result)) { | |
| 345 | - throw new \Exception($result->get_error_message()); | |
| 346 | - } | |
| 347 | - | |
| 348 | - $activate = true; | |
| 349 | - } catch (\Exception $e) { | |
| 349 | + if (!defined('FLUENT_COMMUNITY_PRO')) { | |
| 350 | + return $this->sendError(['message' => __('FluentPlayer requires the pro version of FluentCommunity. Please install FluentCommunity Pro first.', 'fluent-community')]); | |
| 350 | 351 | } |
| 351 | 352 | |
| 352 | - // Discard feedback. | |
| 353 | - ob_end_clean(); | |
| 353 | + $installHook = 'fluent_community/install_fluent_player_plugin'; | |
| 354 | + } else if ($pluginSlug == 'fluent-notify') { | |
| 355 | + $installHook = 'fluent_community/install_fluent_notify_plugin'; | |
| 354 | 356 | } |
| 355 | 357 | |
| 356 | - wp_clean_plugins_cache(); | |
| 358 | + if (!$installHook || !has_action($installHook)) { | |
| 359 | + return $this->sendError(['message' => __('This plugin can not be installed from here. Please install it manually.', 'fluent-community')]); | |
| 360 | + } | |
| 357 | 361 | |
| 358 | - // Activate this thing. | |
| 359 | - if ($activate) { | |
| 360 | - try { | |
| 361 | - $result = activate_plugin($installed ? $installed_plugins[$plugin_file] : $plugin_slug . '/' . $plugin_file); | |
| 362 | - | |
| 363 | - if (is_wp_error($result)) { | |
| 364 | - throw new \Exception($result->get_error_message()); | |
| 365 | - } | |
| 366 | - } catch (\Exception $e) { | |
| 367 | - } | |
| 362 | + try { | |
| 363 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- every assigned value is a literal fluent_community/ prefixed hook, guarded above | |
| 364 | + do_action($installHook); | |
| 365 | + } catch (\Exception $e) { | |
| 366 | + return $this->sendError(['message' => $e->getMessage()]); | |
| 368 | 367 | } |
| 369 | 368 | } |
| 370 | - } | |
| 371 | 369 | |
| 372 | - private function associate_plugin_file($plugins, $key) | |
| 373 | - { | |
| 374 | - $path = explode('/', $key); | |
| 375 | - $filename = end($path); | |
| 376 | - $plugins[$filename] = $key; | |
| 377 | - return $plugins; | |
| 370 | + return [ | |
| 371 | + 'message' => __('Plugin has been installed Successfully', 'fluent-community'), | |
| 372 | + 'is_installed' => true | |
| 373 | + ]; | |
| 378 | 374 | } |
| 379 | 375 | |
| 380 | - | |
| 381 | 376 | public function getCustomizationSettings(Request $request) |
| 382 | 377 | { |
| 383 | - return [ | |
| 378 | + $data = [ | |
| 384 | 379 | 'settings' => Utility::getCustomizationSettings() |
| 385 | 380 | ]; |
| 381 | + | |
| 382 | + return apply_filters('fluent_community/customization_settings_api_response', $data, $request->all()); | |
| 386 | 383 | } |
| 387 | 384 | |
| 388 | 385 | public function updateCustomizationSettings(Request $request) |
| 389 | 386 | { |
| @@ -389,14 +386,16 @@ | ||
| 389 | 386 | { |
| 390 | 387 | $settings = $request->get('settings', []); |
| 391 | 388 | |
| 392 | 389 | $yesNoFields = [ |
| 393 | - 'dark_mode', 'fixed_page_header', 'show_powered_by', 'feed_link_on_sidebar', 'fixed_sidebar', 'icon_on_header_menu' | |
| 390 | + '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' | |
| 394 | 391 | ]; |
| 395 | 392 | |
| 396 | 393 | foreach ($settings as $key => $value) { |
| 397 | 394 | if (in_array($key, $yesNoFields)) { |
| 398 | 395 | $settings[$key] = $value == 'yes' ? 'yes' : 'no'; |
| 396 | + } else if ($key == 'default_theme_mode') { | |
| 397 | + $settings[$key] = in_array($value, ['light', 'dark', 'system'], true) ? $value : 'light'; | |
| 399 | 398 | } else if ($key == 'affiliate_id') { |
| 400 | 399 | $settings[$key] = (int)$value; |
| 401 | 400 | if (!$settings[$key]) { |
| 402 | 401 | $settings[$key] = ''; |
| @@ -405,8 +404,12 @@ | ||
| 405 | 404 | $settings[$key] = sanitize_text_field($value); |
| 406 | 405 | } |
| 407 | 406 | } |
| 408 | 407 | |
| 408 | + if (isset($settings['dark_mode']) && $settings['dark_mode'] !== 'yes') { | |
| 409 | + $settings['default_theme_mode'] = 'light'; | |
| 410 | + } | |
| 411 | + | |
| 409 | 412 | Utility::updateCustomizationSettings($settings); |
| 410 | 413 | |
| 411 | 414 | return [ |
| 412 | 415 | 'message' => __('Customization settings have been saved successfully.', 'fluent-community') |
| @@ -412,13 +415,34 @@ | ||
| 412 | 415 | 'message' => __('Customization settings have been saved successfully.', 'fluent-community') |
| 413 | 416 | ]; |
| 414 | 417 | } |
| 415 | 418 | |
| 419 | + public function getFluentPlayerSettings(Request $request) | |
| 420 | + { | |
| 421 | + return [ | |
| 422 | + 'settings' => \FluentCommunity\Modules\Integrations\FluentPlayer\Bootstrap::getSettings() | |
| 423 | + ]; | |
| 424 | + } | |
| 425 | + | |
| 426 | + public function updateFluentPlayerSettings(Request $request) | |
| 427 | + { | |
| 428 | + $settings = $request->get('settings', []); | |
| 429 | + | |
| 430 | + $updatedSettings = \FluentCommunity\Modules\Integrations\FluentPlayer\Bootstrap::updateSettings($settings); | |
| 431 | + | |
| 432 | + return [ | |
| 433 | + 'message' => __('FluentPlayer settings have been saved successfully.', 'fluent-community'), | |
| 434 | + 'settings' => $updatedSettings | |
| 435 | + ]; | |
| 436 | + } | |
| 437 | + | |
| 416 | 438 | public function getPrivacySettings(Request $request) |
| 417 | 439 | { |
| 418 | - return [ | |
| 440 | + $data = [ | |
| 419 | 441 | 'settings' => Utility::getPrivacySettings() |
| 420 | 442 | ]; |
| 443 | + | |
| 444 | + return apply_filters('fluent_community/privacy_settings_api_response', $data, $request->all()); | |
| 421 | 445 | } |
| 422 | 446 | |
| 423 | 447 | public function updatePrivacySettings(Request $request) |
| 424 | 448 | { |
| @@ -429,5 +453,129 @@ | ||
| 429 | 453 | 'message' => __('Privacy settings have been saved successfully.', 'fluent-community') |
| 430 | 454 | ]; |
| 431 | 455 | } |
| 432 | 456 | |
| 457 | + public function getColorConfig(Request $request) | |
| 458 | + { | |
| 459 | + $config = Utility::getColorConfig('edit'); | |
| 460 | + $schemas = Utility::getColorSchemas(); | |
| 461 | + | |
| 462 | + $data = [ | |
| 463 | + 'config' => $config, | |
| 464 | + 'schemas' => $schemas | |
| 465 | + ]; | |
| 466 | + | |
| 467 | + return apply_filters('fluent_community/color_config_api_response', $data, $request->all()); | |
| 468 | + } | |
| 469 | + | |
| 470 | + public function getCrmTaggingConfig(Request $request) | |
| 471 | + { | |
| 472 | + $defaults = [ | |
| 473 | + 'is_enabled' => 'no', | |
| 474 | + 'tagging_maps' => [], | |
| 475 | + 'linked_maps' => [], | |
| 476 | + 'create_crm_contact' => 'yes', | |
| 477 | + 'create_user' => 'no', | |
| 478 | + 'send_welcome_email' => 'yes', | |
| 479 | + 'has_space_tagging' => 'no', | |
| 480 | + 'has_space_sync' => 'no', | |
| 481 | + 'has_course_tagging' => 'no', | |
| 482 | + 'has_course_sync' => 'no', | |
| 483 | + ]; | |
| 484 | + | |
| 485 | + $settings = get_option('_fcom_crm_tagging', []); | |
| 486 | + $settings = wp_parse_args($settings, $defaults); | |
| 487 | + | |
| 488 | + $spaceGroups = SpaceGroup::with(['spaces' => function ($query) { | |
| 489 | + $query->where('type', 'community'); | |
| 490 | + }]) | |
| 491 | + ->orderBy('serial', 'ASC') | |
| 492 | + ->get(); | |
| 493 | + | |
| 494 | + $formattedSpaceGroups = []; | |
| 495 | + foreach ($spaceGroups as $spaceGroup) { | |
| 496 | + if ($spaceGroup->spaces->isEmpty()) { | |
| 497 | + continue; | |
| 498 | + } | |
| 499 | + | |
| 500 | + $spaces = $spaceGroup->spaces->map(function ($space) { | |
| 501 | + return [ | |
| 502 | + 'id' => $space->id, | |
| 503 | + 'title' => $space->title, | |
| 504 | + 'privacy' => $space->privacy, | |
| 505 | + 'slug' => $space->slug, | |
| 506 | + 'icon' => $space->getIconMark(), | |
| 507 | + 'type' => $space->type, | |
| 508 | + ]; | |
| 509 | + }); | |
| 510 | + | |
| 511 | + $formattedSpaceGroups[] = [ | |
| 512 | + 'id' => $spaceGroup->id, | |
| 513 | + 'title' => $spaceGroup->title, | |
| 514 | + 'spaces' => $spaces | |
| 515 | + ]; | |
| 516 | + } | |
| 517 | + | |
| 518 | + $otherSpaces = Space::whereNull('parent_id') | |
| 519 | + ->orderBy('title', 'ASC') | |
| 520 | + ->get(); | |
| 521 | + | |
| 522 | + if (!$otherSpaces->isEmpty()) { | |
| 523 | + $formattedSpaceGroups[] = [ | |
| 524 | + 'id' => 'other', | |
| 525 | + 'title' => __('Other Spaces', 'fluent-community'), | |
| 526 | + 'spaces' => $otherSpaces->map(function ($space) { | |
| 527 | + return [ | |
| 528 | + 'id' => $space->id, | |
| 529 | + 'type' => $space->type, | |
| 530 | + 'title' => $space->title, | |
| 531 | + 'privacy' => $space->privacy, | |
| 532 | + 'slug' => $space->slug, | |
| 533 | + 'icon' => $space->getIconMark(), | |
| 534 | + ]; | |
| 535 | + }) | |
| 536 | + ]; | |
| 537 | + } | |
| 538 | + | |
| 539 | + $courses = Course::orderBy('title', 'ASC')->get(); | |
| 540 | + | |
| 541 | + if (!$courses->isEmpty()) { | |
| 542 | + $formattedSpaceGroups[] = [ | |
| 543 | + 'id' => 'courses', | |
| 544 | + 'title' => __('All Courses', 'fluent-community'), | |
| 545 | + 'spaces' => $courses->map(function ($course) { | |
| 546 | + return [ | |
| 547 | + 'id' => $course->id, | |
| 548 | + 'title' => $course->title, | |
| 549 | + 'privacy' => $course->privacy, | |
| 550 | + 'slug' => $course->slug, | |
| 551 | + 'icon' => $course->getIconMark(), | |
| 552 | + 'type' => $course->type, | |
| 553 | + ]; | |
| 554 | + }) | |
| 555 | + ]; | |
| 556 | + } | |
| 557 | + | |
| 558 | + if (empty($settings['tagging_maps'])) { | |
| 559 | + $settings['tagging_maps'] = (object)[]; | |
| 560 | + } | |
| 561 | + | |
| 562 | + if (empty($settings['linked_maps'])) { | |
| 563 | + $settings['linked_maps'] = (object)[]; | |
| 564 | + } | |
| 565 | + | |
| 566 | + if (defined('FLUENTCRM')) { | |
| 567 | + $fluentCrmTags = \FluentCrm\App\Models\Tag::select(['id', 'title'])->orderBy('title', 'ASC')->get(); | |
| 568 | + } else { | |
| 569 | + $fluentCrmTags = []; | |
| 570 | + } | |
| 571 | + | |
| 572 | + | |
| 573 | + $data = [ | |
| 574 | + 'settings' => $settings, | |
| 575 | + 'spaceGroups' => $formattedSpaceGroups, | |
| 576 | + 'crm_tags' => $fluentCrmTags, | |
| 577 | + 'has_fluentcrm' => defined('FLUENTCRM') | |
| 578 | + ]; | |
| 579 | + return apply_filters('fluent_community/crm_tagging_config_api_response', $data, $request->all()); | |
| 580 | + } | |
| 433 | 581 | } |