| 1 |
<?php |
| 2 |
/** |
| 3 |
* The admin-specific functionality for the Add Ons page. |
| 4 |
* |
| 5 |
* @package MxChat |
| 6 |
* @subpackage MxChat/admin |
| 7 |
*/ |
| 8 |
class MxChat_Addons { |
| 9 |
/** |
| 10 |
* Store add-on configuration data |
| 11 |
* |
| 12 |
* @var array |
| 13 |
*/ |
| 14 |
private $addons_config; |
| 15 |
|
| 16 |
/** |
| 17 |
* Initialize the class and set its properties. |
| 18 |
*/ |
| 19 |
public function __construct() { |
| 20 |
$this->addons_config = array( |
| 21 |
|
| 22 |
'mxchat-theme' => array( |
| 23 |
'title' => __('MxChat Theme Customizer', 'mxchat'), |
| 24 |
'description' => __('Make your chatbot uniquely yours. Generate beautiful themes instantly using simple descriptions or customize manually with precise color controls—zero coding required. Perfect for matching your brand identity.', 'mxchat'), |
| 25 |
'key_benefits' => array( |
| 26 |
__('AI-powered theme generator', 'mxchat'), |
| 27 |
__('Live preview customizer', 'mxchat'), |
| 28 |
__('One-click theme application', 'mxchat') |
| 29 |
), |
| 30 |
'license' => 'MxChat PRO', |
| 31 |
'accent' => '#fa73e6', |
| 32 |
'url' => 'https://mxchat.ai/ai-theme-customizer/', |
| 33 |
'plugin_file' => 'mxchat-theme/mxchat-theme.php', |
| 34 |
'config_page' => 'mxchat-theme-settings' |
| 35 |
), |
| 36 |
|
| 37 |
'mxchat-admin-assistant' => array( |
| 38 |
'title' => __('MxChat Admin Assistant', 'mxchat'), |
| 39 |
'description' => __('Your AI powerhouse inside WordPress. Chat with multiple AI models, generate images, research the web, and boost productivity—all without leaving your dashboard.', 'mxchat'), |
| 40 |
'key_benefits' => array( |
| 41 |
__('ChatGPT-like admin interface', 'mxchat'), |
| 42 |
__('Generate images & research web', 'mxchat'), |
| 43 |
__('Searchable chat history', 'mxchat') |
| 44 |
), |
| 45 |
'license' => 'MxChat PRO', |
| 46 |
'accent' => '#fa73e6', |
| 47 |
'url' => 'https://mxchat.ai/ai-admin-assistant/', |
| 48 |
'plugin_file' => 'mxchat-admin-chat/mxchat-admin-chat.php', |
| 49 |
'config_page' => 'mxchat-admin-chat' |
| 50 |
), |
| 51 |
|
| 52 |
'mxchat-veo' => array( |
| 53 |
'title' => __('MxChat Video Generation', 'mxchat'), |
| 54 |
'description' => __('Generate stunning AI videos using Google Veo 2 and Veo 3 models directly from your WordPress dashboard. Create high-quality videos from text prompts with audio, multiple aspect ratios, and optimized generation speeds.', 'mxchat'), |
| 55 |
'key_benefits' => array( |
| 56 |
__('Multiple Veo models (Veo 2, 3, 3 Fast)', 'mxchat'), |
| 57 |
__('8-second videos with native audio', 'mxchat'), |
| 58 |
__('Media library integration', 'mxchat') |
| 59 |
), |
| 60 |
'license' => 'MxChat PRO', |
| 61 |
'accent' => '#ff6b35', |
| 62 |
'url' => 'https://mxchat.ai/mxchat-veo-video-generation/', |
| 63 |
'plugin_file' => 'mxchat-veo/mxchat-veo.php', |
| 64 |
'config_page' => 'mxchat-veo' |
| 65 |
), |
| 66 |
|
| 67 |
'mxchat-image-analysis' => array( |
| 68 |
'title' => __('MxChat Image Analysis', 'mxchat'), |
| 69 |
'description' => __('Enhance your chatbot with AI-powered image analysis. Users can upload images for intelligent descriptions, OCR text extraction, and get answers about visual content using OpenAI Vision and Grok APIs.', 'mxchat'), |
| 70 |
'key_benefits' => array( |
| 71 |
__('Multiple AI vision models', 'mxchat'), |
| 72 |
__('Drag & drop image uploads', 'mxchat'), |
| 73 |
__('Custom analysis prompts', 'mxchat') |
| 74 |
), |
| 75 |
'license' => 'MxChat PRO', |
| 76 |
'accent' => '#fa73e6', |
| 77 |
'url' => 'https://mxchat.ai/image-analysis/', |
| 78 |
'plugin_file' => 'mxchat-vision/mxchat-vision.php', |
| 79 |
'config_page' => 'mxchat-vision' |
| 80 |
), |
| 81 |
|
| 82 |
'mxchat-forms' => array( |
| 83 |
'title' => __('MxChat Forms', 'mxchat'), |
| 84 |
'description' => __('Convert conversations into data collection. Create smart forms that trigger during chats, collect user information, and turn casual visitors into qualified leads.', 'mxchat'), |
| 85 |
'key_benefits' => array( |
| 86 |
__('No-code form builder', 'mxchat'), |
| 87 |
__('Intent-triggered activation', 'mxchat'), |
| 88 |
__('Export lead data easily', 'mxchat') |
| 89 |
), |
| 90 |
'license' => 'MxChat PRO', |
| 91 |
'accent' => '#fa73e6', |
| 92 |
'url' => 'https://mxchat.ai/forms-action/', |
| 93 |
'plugin_file' => 'mxchat-forms/mxchat-forms.php', |
| 94 |
'config_page' => 'mxchat-forms' |
| 95 |
), |
| 96 |
|
| 97 |
'mxchat-multi-bot' => array( |
| 98 |
'title' => __('MxChat Multi-Bot Manager', 'mxchat'), |
| 99 |
'description' => __('Create unlimited specialized chatbots for every purpose. Deploy dedicated bots with separate knowledge bases, custom personalities, and page-specific assignments—perfect for support, sales, and department-specific assistance.', 'mxchat'), |
| 100 |
'key_benefits' => array( |
| 101 |
__('Unlimited specialized chatbots', 'mxchat'), |
| 102 |
__('Separate Pinecone knowledge bases', 'mxchat'), |
| 103 |
__('Page-specific bot assignments', 'mxchat') |
| 104 |
), |
| 105 |
'license' => 'MxChat PRO', |
| 106 |
'accent' => '#8b5cf6', |
| 107 |
'url' => 'https://mxchat.ai/multi-bot/', |
| 108 |
'plugin_file' => 'mxchat-multi-bot/mxchat-multi-bot.php', |
| 109 |
'config_page' => 'mxchat-multi-bot' |
| 110 |
), |
| 111 |
|
| 112 |
'mxchat-woo' => array( |
| 113 |
'title' => __('MxChat WooCommerce', 'mxchat'), |
| 114 |
'description' => __('Boost sales with AI-powered shopping assistance. Help customers find products, manage carts, and complete purchases—all through natural conversation.', 'mxchat'), |
| 115 |
'key_benefits' => array( |
| 116 |
__('Smart product recommendations', 'mxchat'), |
| 117 |
__('Cart & checkout assistance', 'mxchat'), |
| 118 |
__('Order history access', 'mxchat') |
| 119 |
), |
| 120 |
'license' => 'MxChat PRO', |
| 121 |
'accent' => '#fa73e6', |
| 122 |
'url' => 'https://mxchat.ai/woocommerce/', |
| 123 |
'plugin_file' => 'mxchat-woo/mxchat-woo.php', |
| 124 |
'config_page' => 'mxchat-woo' |
| 125 |
), |
| 126 |
|
| 127 |
'mxchat-assistant-api' => array( |
| 128 |
'title' => __('MxChat Assistant API', 'mxchat'), |
| 129 |
'description' => __('Unlock the full power of OpenAI Assistants. Bypass MxChat\'s knowledge base and connect directly to your custom OpenAI Assistant for advanced AI capabilities and specialized responses.', 'mxchat'), |
| 130 |
'key_benefits' => array( |
| 131 |
__('Custom OpenAI Assistant integration', 'mxchat'), |
| 132 |
__('Advanced AI capabilities', 'mxchat'), |
| 133 |
__('24-hour conversation persistence', 'mxchat') |
| 134 |
), |
| 135 |
'license' => 'MxChat PRO', |
| 136 |
'accent' => '#00d4aa', |
| 137 |
'url' => 'https://mxchat.ai/openai-assistants-api/', |
| 138 |
'plugin_file' => 'mxchat-assistant-api/mxchat-assistant-api.php', |
| 139 |
'config_page' => 'mxchat-assistant-api' |
| 140 |
), |
| 141 |
|
| 142 |
'mxchat-perplexity' => array( |
| 143 |
'title' => __('MxChat Perplexity', 'mxchat'), |
| 144 |
'description' => __('Give your chatbot real-time knowledge. Add powerful web search capabilities so your bot can answer questions about current events and time-sensitive information.', 'mxchat'), |
| 145 |
'key_benefits' => array( |
| 146 |
__('Real-time web search', 'mxchat'), |
| 147 |
__('Intent-triggered research', 'mxchat'), |
| 148 |
__('Up-to-date information', 'mxchat') |
| 149 |
), |
| 150 |
'license' => 'MxChat PRO', |
| 151 |
'accent' => '#fa73e6', |
| 152 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-perplexity/', |
| 153 |
'plugin_file' => 'mxchat-perplexity/mxchat-perplexity.php', |
| 154 |
'config_page' => 'mxchat-perplexity' |
| 155 |
), |
| 156 |
|
| 157 |
'mxchat-moderation' => array( |
| 158 |
'title' => __('MxChat Moderation', 'mxchat'), |
| 159 |
'description' => __('Keep your chat clean and professional. Block unwanted users, filter inappropriate content, and ensure your chatbot represents your brand properly.', 'mxchat'), |
| 160 |
'key_benefits' => array( |
| 161 |
__('IP & email-based blocking', 'mxchat'), |
| 162 |
__('Content filtering', 'mxchat'), |
| 163 |
__('Spam protection', 'mxchat') |
| 164 |
), |
| 165 |
'license' => 'MxChat PRO', |
| 166 |
'accent' => '#fa73e6', |
| 167 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-moderation/', |
| 168 |
'plugin_file' => 'mxchat-moderation/mx-chat-moderation.php', |
| 169 |
'config_page' => 'mx-chat-moderation' |
| 170 |
), |
| 171 |
|
| 172 |
'mxchat-smart-recommender' => array( |
| 173 |
'title' => __('MxChat Smart Recommender', 'mxchat'), |
| 174 |
'description' => __('Turn your chatbot into a sales machine. Build personalized recommendation flows that understand user preferences and suggest perfect products or services.', 'mxchat'), |
| 175 |
'key_benefits' => array( |
| 176 |
__('Increase conversion rates', 'mxchat'), |
| 177 |
__('Custom recommendation flows', 'mxchat'), |
| 178 |
__('No coding required', 'mxchat') |
| 179 |
), |
| 180 |
'license' => 'MxChat PRO', |
| 181 |
'accent' => '#fa73e6', |
| 182 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-smart-recommender/', |
| 183 |
'plugin_file' => 'mxchat-smart-recommender/mxchat-smart-recommender.php', |
| 184 |
'config_page' => 'mxchat-smart-recommender' |
| 185 |
), |
| 186 |
); |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Register the stylesheets for the admin area. |
| 191 |
*/ |
| 192 |
public function enqueue_styles() { |
| 193 |
$plugin_version = '2.4.6'; |
| 194 |
|
| 195 |
wp_enqueue_style( |
| 196 |
'mxchat-addons', |
| 197 |
plugin_dir_url(__FILE__) . '../css/admin-add-ons.css', |
| 198 |
array(), |
| 199 |
$plugin_version, |
| 200 |
'all' |
| 201 |
); |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* Check if an addon is installed and active |
| 206 |
* |
| 207 |
* @param string $plugin_file The plugin's main file path |
| 208 |
* @return array Status information |
| 209 |
*/ |
| 210 |
private function get_addon_status($plugin_file) { |
| 211 |
if (!function_exists('get_plugins')) { |
| 212 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 213 |
} |
| 214 |
|
| 215 |
$all_plugins = get_plugins(); |
| 216 |
$active_plugins = get_option('active_plugins', array()); |
| 217 |
|
| 218 |
// Find the addon by iterating through configs |
| 219 |
$config_page = ''; |
| 220 |
foreach ($this->addons_config as $slug => $addon) { |
| 221 |
if ($addon['plugin_file'] === $plugin_file) { |
| 222 |
$config_page = $addon['config_page']; |
| 223 |
break; |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
if (isset($all_plugins[$plugin_file])) { |
| 228 |
if (in_array($plugin_file, $active_plugins)) { |
| 229 |
return array( |
| 230 |
'status' => 'active', |
| 231 |
'action_url' => admin_url('admin.php?page=' . $config_page), |
| 232 |
'action_text' => __('Configure', 'mxchat') |
| 233 |
); |
| 234 |
} else { |
| 235 |
return array( |
| 236 |
'status' => 'inactive', |
| 237 |
'action_url' => wp_nonce_url( |
| 238 |
admin_url('plugins.php?action=activate&plugin=' . $plugin_file), |
| 239 |
'activate-plugin_' . $plugin_file |
| 240 |
), |
| 241 |
'action_text' => __('Activate', 'mxchat') |
| 242 |
); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
return array( |
| 247 |
'status' => 'not-installed', |
| 248 |
'action_url' => '', |
| 249 |
'action_text' => __('Get Extension', 'mxchat') |
| 250 |
); |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* Render the Add Ons page content. |
| 255 |
*/ |
| 256 |
public function render_page() { |
| 257 |
$this->enqueue_styles(); |
| 258 |
// Remove the sorting logic and just use the original order |
| 259 |
$sorted_addons = $this->addons_config; |
| 260 |
|
| 261 |
?> |
| 262 |
<div class="wrap mxchat-addons-wrapper"> |
| 263 |
<div class="mxchat-addons-hero"> |
| 264 |
<h1 class="mxchat-main-title"> |
| 265 |
<span class="mxchat-gradient-text">Power Up</span> Your Chatbot |
| 266 |
</h1> |
| 267 |
<p class="mxchat-hero-subtitle"> |
| 268 |
<?php esc_html_e('Extend MxChat with these powerful extensions and unlock advanced features.', 'mxchat'); ?> |
| 269 |
</p> |
| 270 |
</div> |
| 271 |
|
| 272 |
<div class="mxchat-addons-section"> |
| 273 |
<div class="mxchat-addons-grid"> |
| 274 |
<?php foreach ($sorted_addons as $slug => $addon): ?> |
| 275 |
<?php $this->render_addon_card($slug, $addon); ?> |
| 276 |
<?php endforeach; ?> |
| 277 |
</div> |
| 278 |
</div> |
| 279 |
|
| 280 |
<div class="mxchat-cta-section"> |
| 281 |
<h2><?php esc_html_e('Ready to take your chatbot to the next level?', 'mxchat'); ?></h2> |
| 282 |
<p><?php esc_html_e('Get MxChat PRO today and access all premium extensions at one low price.', 'mxchat'); ?></p> |
| 283 |
<a href="https://mxchat.ai/" class="mxchat-cta-button" target="_blank"><?php esc_html_e('Learn More', 'mxchat'); ?></a> |
| 284 |
</div> |
| 285 |
</div> |
| 286 |
<?php |
| 287 |
} |
| 288 |
|
| 289 |
/** |
| 290 |
* Render individual add-on card |
| 291 |
* |
| 292 |
* @param string $slug The addon slug |
| 293 |
* @param array $addon The addon configuration array |
| 294 |
*/ |
| 295 |
private function render_addon_card($slug, $addon) { |
| 296 |
$status_info = $this->get_addon_status($addon['plugin_file']); |
| 297 |
$button_url = $status_info['status'] === 'not-installed' ? $addon['url'] : $status_info['action_url']; |
| 298 |
$button_target = $status_info['status'] === 'not-installed' ? '_blank' : '_self'; |
| 299 |
|
| 300 |
// Check if addon is deprecated |
| 301 |
$is_deprecated = isset($addon['status']) && $addon['status'] === 'deprecated'; |
| 302 |
?> |
| 303 |
<div class="mxchat-addon-card <?php echo $is_deprecated ? 'deprecated' : ''; ?>" style="--card-accent: <?php echo esc_attr($addon['accent']); ?>"> |
| 304 |
<div class="mxchat-addon-badge"> |
| 305 |
<?php if ($is_deprecated): ?> |
| 306 |
<?php esc_html_e('Deprecated', 'mxchat'); ?> |
| 307 |
<?php else: ?> |
| 308 |
<?php echo esc_html(ucfirst($addon['license'])); ?> |
| 309 |
<?php endif; ?> |
| 310 |
</div> |
| 311 |
<div class="mxchat-addon-content"> |
| 312 |
<h3 class="mxchat-addon-title"><?php echo esc_html($addon['title']); ?></h3> |
| 313 |
<p class="mxchat-addon-description"><?php echo esc_html($addon['description']); ?></p> |
| 314 |
|
| 315 |
<?php if (!empty($addon['key_benefits'])): ?> |
| 316 |
<div class="mxchat-benefits-list"> |
| 317 |
<?php foreach ($addon['key_benefits'] as $benefit): ?> |
| 318 |
<div class="mxchat-benefit-item"> |
| 319 |
<span class="mxchat-benefit-icon">✓</span> |
| 320 |
<?php echo esc_html($benefit); ?> |
| 321 |
</div> |
| 322 |
<?php endforeach; ?> |
| 323 |
</div> |
| 324 |
<?php endif; ?> |
| 325 |
|
| 326 |
<div class="mxchat-addon-footer"> |
| 327 |
<?php if ($is_deprecated): ?> |
| 328 |
<div class="mxchat-status-indicator deprecated"> |
| 329 |
<?php esc_html_e('Now Built-in', 'mxchat'); ?> |
| 330 |
</div> |
| 331 |
<a href="<?php echo esc_url(admin_url('admin.php?page=mxchat-prompts')); ?>" |
| 332 |
class="mxchat-action-button deprecated" |
| 333 |
target="_self"> |
| 334 |
<?php esc_html_e('Go to Knowledge Tab', 'mxchat'); ?> |
| 335 |
</a> |
| 336 |
<?php else: ?> |
| 337 |
<div class="mxchat-status-indicator <?php echo esc_attr($status_info['status']); ?>"> |
| 338 |
<?php echo esc_html(ucfirst(str_replace('-', ' ', $status_info['status']))); ?> |
| 339 |
</div> |
| 340 |
<a href="<?php echo esc_url($button_url); ?>" |
| 341 |
class="mxchat-action-button" |
| 342 |
target="<?php echo esc_attr($button_target); ?>" |
| 343 |
data-action="<?php echo esc_attr($status_info['status']); ?>"> |
| 344 |
<?php echo esc_html($status_info['action_text']); ?> |
| 345 |
</a> |
| 346 |
<?php endif; ?> |
| 347 |
</div> |
| 348 |
</div> |
| 349 |
</div> |
| 350 |
<?php |
| 351 |
} |
| 352 |
|
| 353 |
} |