| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentCart\App\App; |
| 6 |
use FluentCart\App\Services\PluginInstaller\BackgroundInstaller; |
| 7 |
use FluentCart\App\Vite; |
| 8 |
use FluentCart\Framework\Http\Request\Request; |
| 9 |
|
| 10 |
class AddonsController extends Controller |
| 11 |
{ |
| 12 |
|
| 13 |
public function getAddons(Request $request) |
| 14 |
{ |
| 15 |
$addons = [ |
| 16 |
'fluent-crm' => [ |
| 17 |
'installable' => 'fluent-crm', |
| 18 |
'enabled' => defined('FLUENTCRM'), |
| 19 |
'title' => __('FluentCRM', 'fluent-cart'), |
| 20 |
'logo' => Vite::getAssetUrl('images/integrations/fluentcrm.svg'), |
| 21 |
'categories' => [ |
| 22 |
'crm', |
| 23 |
'core', |
| 24 |
'marketing', |
| 25 |
], |
| 26 |
'description' => __('The most powerful and user-friendly email marketing automation plugin for WordPress. Send newsletters, marketing emails, customer onboard emails, Automations with FluentCart + FluentCRM integration.', 'fluent-cart' ), |
| 27 |
], |
| 28 |
'fluent-smtp' => [ |
| 29 |
'installable' => 'fluent-smtp', |
| 30 |
'logo' => Vite::getAssetUrl('images/integrations/fluent-smtp.svg'), |
| 31 |
'enabled' => defined('FLUENTMAIL_PLUGIN_FILE'), |
| 32 |
'title' => __('FluentSMTP', 'fluent-cart'), |
| 33 |
'categories' => [ |
| 34 |
'core', |
| 35 |
'marketing', |
| 36 |
], |
| 37 |
'description' => __('A free and open-source WordPress SMTP plugin to send emails via multiple SMTP providers. Ensure email deliverability for your WooCommerce and FluentCart emails with FluentSMTP.', 'fluent-cart'), |
| 38 |
], |
| 39 |
'fluent-community' => [ |
| 40 |
'installable' => 'fluent-community', |
| 41 |
'logo' => Vite::getAssetUrl('images/integrations/fluent-community.svg'), |
| 42 |
'enabled' => defined('FLUENT_COMMUNITY_PLUGIN_VERSION'), |
| 43 |
'title' => __('FluentCommunity', 'fluent-cart'), |
| 44 |
'categories' => [ |
| 45 |
'core', |
| 46 |
'community', |
| 47 |
'lms' |
| 48 |
], |
| 49 |
'description' => __('Build a community, membership site, or online forum with FluentCart + FluentCommunity integration. Engage your customers and users right from your WordPress dashboard.', 'fluent-cart'), |
| 50 |
], |
| 51 |
'fluent-security' => [ |
| 52 |
'installable' => 'fluent-security', |
| 53 |
'logo' => Vite::getAssetUrl('images/integrations/fluent-auth.svg'), |
| 54 |
'enabled' => defined('FLUENT_AUTH_VERSION'), |
| 55 |
'title' => __('FluentAuth', 'fluent-cart'), |
| 56 |
'categories' => [ |
| 57 |
'core' |
| 58 |
], |
| 59 |
'description' => __('Customize WordPress emails, customized login & signup forms with enhanced security and social logins. Enhance your site security with FluentCart + FluentSecurity integration.', 'fluent-cart'), |
| 60 |
], |
| 61 |
'fluentform' => [ |
| 62 |
'installable' => 'fluentform', |
| 63 |
'logo' => Vite::getAssetUrl('images/integrations/fluent-form.svg'), |
| 64 |
'enabled' => defined('FLUENTFORM'), |
| 65 |
'title' => __('Fluent Forms', 'fluent-cart'), |
| 66 |
'categories' => [ |
| 67 |
'core', |
| 68 |
'marketing' |
| 69 |
], |
| 70 |
'description' => __('Create advanced forms and surveys with an easy-to-use drag & drop form builder.', 'fluent-cart'), |
| 71 |
], |
| 72 |
'fluent-support' => [ |
| 73 |
'installable' => 'fluent-support', |
| 74 |
'logo' => Vite::getAssetUrl('images/integrations/fluent-support.svg'), |
| 75 |
'enabled' => defined('FLUENT_SUPPORT_VERSION'), |
| 76 |
'title' => __('FluentSupport', 'fluent-cart'), |
| 77 |
'categories' => [ |
| 78 |
'core', |
| 79 |
'marketing' |
| 80 |
], |
| 81 |
'description' => __('A powerful helpdesk and customer support plugin for WordPress. Manage customer support tickets directly from your WordPress dashboard with FluentCart + FluentSupport integration.', 'fluent-cart'), |
| 82 |
] |
| 83 |
]; |
| 84 |
|
| 85 |
$addons = array_merge($addons, $this->getPremiumIntegrations()); |
| 86 |
|
| 87 |
$addons = apply_filters('fluent_cart/integration/addons', $addons); |
| 88 |
|
| 89 |
return [ |
| 90 |
'addons' => $addons |
| 91 |
]; |
| 92 |
} |
| 93 |
|
| 94 |
public function getPremiumIntegrations() { |
| 95 |
return [ |
| 96 |
'webhook' => [ |
| 97 |
'title' => __('Webhook', 'fluent-cart'), |
| 98 |
'description' => __('Send data anywhere via webhook', 'fluent-cart'), |
| 99 |
'logo' => Vite::getAssetUrl('images/integrations/webhook.svg'), |
| 100 |
'enabled' => App::isProActive() ? true : false, |
| 101 |
'is_pro' => true, |
| 102 |
'is_pro_active' => App::isProActive(), |
| 103 |
'categories' => ['core'], |
| 104 |
], |
| 105 |
'wp_user' => [ |
| 106 |
'title' => __('WP User Create/Update', 'fluent-cart'), |
| 107 |
'description' => __('Create / Update WP User with Custom Roles on order events', 'fluent-cart'), |
| 108 |
'logo' => Vite::getAssetUrl('images/integrations/wp_user.svg'), |
| 109 |
'enabled' => App::isProActive() ? true : false, |
| 110 |
'is_pro_active' => App::isProActive(), |
| 111 |
'is_pro' => true, |
| 112 |
'categories' => ['core'], |
| 113 |
], |
| 114 |
]; |
| 115 |
} |
| 116 |
|
| 117 |
public function installAndActivate(Request $request) |
| 118 |
{ |
| 119 |
$addon = $request->getSafe('addon', 'sanitize_text_field'); |
| 120 |
|
| 121 |
$listedPlugins = apply_filters('fluent_cart/installable_repo_plugins', [ |
| 122 |
'fluent-crm', |
| 123 |
'fluent-smtp', |
| 124 |
'fluent-community', |
| 125 |
'fluent-security', |
| 126 |
'fluentform', |
| 127 |
'fluent-support', |
| 128 |
'fluent-player' |
| 129 |
]); |
| 130 |
|
| 131 |
if (!$addon || !in_array($addon, $listedPlugins)) { |
| 132 |
return $this->sendError([ |
| 133 |
'message' => __('This addon cannot be installed at this time', 'fluent-cart') |
| 134 |
]); |
| 135 |
} |
| 136 |
|
| 137 |
// integrations/manage is a FluentCart permission and does not imply the |
| 138 |
// WordPress capability to put executable code on the site: a Manager is not |
| 139 |
// necessarily an administrator. |
| 140 |
// |
| 141 |
// installPlugin() always ends by activating the plugin — freshly downloaded |
| 142 |
// or already on disk — so activate_plugins is required either way, and an |
| 143 |
// absent addon needs install_plugins on top for the download itself. The two |
| 144 |
// are separate capabilities a custom role can hold independently. |
| 145 |
if (!function_exists('get_plugins')) { |
| 146 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 147 |
} |
| 148 |
|
| 149 |
$isInstalled = array_key_exists($addon . '/' . $addon . '.php', get_plugins()); |
| 150 |
|
| 151 |
if (!current_user_can('activate_plugins')) { |
| 152 |
return $this->sendError([ |
| 153 |
'message' => __('You do not have permission to activate plugins.', 'fluent-cart') |
| 154 |
], 403); |
| 155 |
} |
| 156 |
|
| 157 |
if (!$isInstalled && !current_user_can('install_plugins')) { |
| 158 |
return $this->sendError([ |
| 159 |
'message' => __('You do not have permission to install plugins.', 'fluent-cart') |
| 160 |
], 403); |
| 161 |
} |
| 162 |
|
| 163 |
$result = (new BackgroundInstaller())->installPlugin($addon); |
| 164 |
|
| 165 |
if (is_wp_error($result)) { |
| 166 |
return $this->sendError([ |
| 167 |
'message' => $result->get_error_message() |
| 168 |
]); |
| 169 |
} |
| 170 |
|
| 171 |
return $this->sendSuccess([ |
| 172 |
'message' => __('Addon installation started successfully.', 'fluent-cart'), |
| 173 |
'redirect' => admin_url('admin.php?page=fluent-cart#/integrations') |
| 174 |
]); |
| 175 |
} |
| 176 |
|
| 177 |
} |
| 178 |
|