| 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 |
'mxchat-pinecone' => array( |
| 22 |
'title' => __('Pinecone DB Manager', 'mxchat'), |
| 23 |
'description' => __('Seamlessly manage your vectorized content in Pinecone\'s vector database directly from your WordPress dashboard. This integration provides an efficient alternative to the default WordPress database storage.', 'mxchat'), |
| 24 |
'license' => 'free', |
| 25 |
'accent' => '#fa73e6', |
| 26 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-pinecone/', |
| 27 |
'plugin_file' => 'mxchat-pinecone/pinecone-manager.php', |
| 28 |
'config_page' => 'mxchat-pinecone' |
| 29 |
), |
| 30 |
|
| 31 |
'mxchat-theme' => array( |
| 32 |
'title' => __('MxChat Theme Customizer', 'mxchat'), |
| 33 |
'description' => __('MxChat Theme Customizer is a powerful add-on for MxChat Pro that makes it effortless to personalize your chatbot’s appearance. With an intuitive color picker, you can instantly adjust background colors, and interface elements—all with real-time previews. No coding required, just simple, live customization to match your brand’s look.', 'mxchat'), |
| 34 |
'license' => 'MxChat PRO', |
| 35 |
'accent' => '#fa73e6', |
| 36 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-theme/', |
| 37 |
'plugin_file' => 'mxchat-theme/mxchat-theme.php', |
| 38 |
'config_page' => 'mxchat-theme-settings' |
| 39 |
), |
| 40 |
'mxchat-moderation' => array( |
| 41 |
'title' => __('MxChat Moderation', 'mxchat'), |
| 42 |
'description' => __('MxChat Moderation is the ultimate add-on for MxChat, giving you full control over who interacts with your chatbot. Effortlessly block spammers, trolls, or unwanted users using IP and email-based bans—keeping your chat clean, safe, and enjoyable. Say goodbye to disruptive users and hello to a smoother, more secure chatbot experience!', 'mxchat'), |
| 43 |
'license' => 'MxChat PRO', |
| 44 |
'accent' => '#fa73e6', |
| 45 |
'url' => 'https://quickdeploywp.com/plugin/mxchat-moderation/', |
| 46 |
'plugin_file' => 'mxchat-moderation/mx-chat-moderation.php', |
| 47 |
'config_page' => 'mx-chat-moderation' |
| 48 |
), |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Register the stylesheets for the admin area. |
| 54 |
*/ |
| 55 |
public function enqueue_styles() { |
| 56 |
$plugin_version = '2.0.2'; |
| 57 |
|
| 58 |
wp_enqueue_style( |
| 59 |
'mxchat-addons', |
| 60 |
plugin_dir_url(__FILE__) . '../css/admin-add-ons.css', |
| 61 |
array(), |
| 62 |
$plugin_version, |
| 63 |
'all' |
| 64 |
); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Check if an addon is installed and active |
| 69 |
* |
| 70 |
* @param string $plugin_file The plugin's main file path |
| 71 |
* @return array Status information |
| 72 |
*/ |
| 73 |
private function get_addon_status($plugin_file) { |
| 74 |
if (!function_exists('get_plugins')) { |
| 75 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 76 |
} |
| 77 |
|
| 78 |
$all_plugins = get_plugins(); |
| 79 |
$active_plugins = get_option('active_plugins', array()); |
| 80 |
|
| 81 |
// Find the addon by iterating through configs |
| 82 |
$config_page = ''; |
| 83 |
foreach ($this->addons_config as $slug => $addon) { |
| 84 |
if ($addon['plugin_file'] === $plugin_file) { |
| 85 |
$config_page = $addon['config_page']; |
| 86 |
break; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
if (isset($all_plugins[$plugin_file])) { |
| 91 |
if (in_array($plugin_file, $active_plugins)) { |
| 92 |
return array( |
| 93 |
'status' => 'active', |
| 94 |
'action_url' => admin_url('admin.php?page=' . $config_page), |
| 95 |
'action_text' => __('Configure', 'mxchat') |
| 96 |
); |
| 97 |
} else { |
| 98 |
return array( |
| 99 |
'status' => 'inactive', |
| 100 |
'action_url' => wp_nonce_url( |
| 101 |
admin_url('plugins.php?action=activate&plugin=' . $plugin_file), |
| 102 |
'activate-plugin_' . $plugin_file |
| 103 |
), |
| 104 |
'action_text' => __('Activate', 'mxchat') |
| 105 |
); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
return array( |
| 110 |
'status' => 'not-installed', |
| 111 |
'action_url' => '', |
| 112 |
'action_text' => __('Get Extension', 'mxchat') |
| 113 |
); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Render the Add Ons page content. |
| 118 |
*/ |
| 119 |
public function render_page() { |
| 120 |
$this->enqueue_styles(); |
| 121 |
?> |
| 122 |
<div class="wrap mxchat-addons-wrapper"> |
| 123 |
<div class="mxchat-addons-hero"> |
| 124 |
<h1 class="mxchat-main-title"> |
| 125 |
<span class="mxchat-gradient-text">Power Up</span> Your Chatbot |
| 126 |
</h1> |
| 127 |
<p class="mxchat-hero-subtitle"> |
| 128 |
<?php esc_html_e('Enhance your chatbot with premium & free extensions available through QuickDeployWP, an official distribution platform made by MxChat.', 'mxchat'); ?> |
| 129 |
</p> |
| 130 |
</div> |
| 131 |
<div class="mxchat-addons-grid"> |
| 132 |
<?php |
| 133 |
foreach ($this->addons_config as $slug => $addon) { |
| 134 |
$this->render_addon_card($slug, $addon); |
| 135 |
} |
| 136 |
?> |
| 137 |
</div> |
| 138 |
</div> |
| 139 |
<?php |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Render individual add-on card |
| 144 |
* |
| 145 |
* @param string $slug The addon slug |
| 146 |
* @param array $addon The addon configuration array |
| 147 |
*/ |
| 148 |
private function render_addon_card($slug, $addon) { |
| 149 |
$status_info = $this->get_addon_status($addon['plugin_file']); |
| 150 |
$button_url = $status_info['status'] === 'not-installed' ? $addon['url'] : $status_info['action_url']; |
| 151 |
$button_target = $status_info['status'] === 'not-installed' ? '_blank' : '_self'; |
| 152 |
?> |
| 153 |
<div class="mxchat-addon-card" style="--card-accent: <?php echo esc_attr($addon['accent']); ?>"> |
| 154 |
<div class="mxchat-addon-badge"><?php echo esc_html(ucfirst($addon['license'])); ?></div> |
| 155 |
<div class="mxchat-addon-content"> |
| 156 |
<h3 class="mxchat-addon-title"><?php echo esc_html($addon['title']); ?></h3> |
| 157 |
<p class="mxchat-addon-description"><?php echo esc_html($addon['description']); ?></p> |
| 158 |
<div class="mxchat-addon-footer"> |
| 159 |
<div class="mxchat-status-indicator <?php echo esc_attr($status_info['status']); ?>"> |
| 160 |
<?php echo esc_html(ucfirst(str_replace('-', ' ', $status_info['status']))); ?> |
| 161 |
</div> |
| 162 |
<a href="<?php echo esc_url($button_url); ?>" |
| 163 |
class="mxchat-action-button" |
| 164 |
target="<?php echo esc_attr($button_target); ?>" |
| 165 |
data-action="<?php echo esc_attr($status_info['status']); ?>"> |
| 166 |
<?php echo esc_html($status_info['action_text']); ?> |
| 167 |
</a> |
| 168 |
</div> |
| 169 |
</div> |
| 170 |
</div> |
| 171 |
<?php |
| 172 |
} |
| 173 |
} |
| 174 |
|