class-dashboard-controller.php
2 years ago
class-notice-controller.php
2 years ago
class-settings-controller.php
2 years ago
class-troubleshooting-controller.php
2 years ago
class-dashboard-controller.php
389 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Admin\Controllers; |
| 4 | |
| 5 | defined('ABSPATH') || exit(); |
| 6 | |
| 7 | use SuperbAddons\Admin\Pages\DashboardPage; |
| 8 | use SuperbAddons\Admin\Pages\ElementorDashboardPage; |
| 9 | use SuperbAddons\Admin\Pages\GutenbergDashboardPage; |
| 10 | use SuperbAddons\Admin\Pages\SettingsPage; |
| 11 | use SuperbAddons\Admin\Pages\SupportPage; |
| 12 | use SuperbAddons\Components\Admin\FeedbackModal; |
| 13 | use SuperbAddons\Config\Capabilities; |
| 14 | use SuperbAddons\Data\Controllers\RestController; |
| 15 | |
| 16 | use SuperbAddons\Components\Admin\Navigation; |
| 17 | use SuperbAddons\Data\Controllers\KeyController; |
| 18 | use SuperbAddons\Elementor\Controllers\ElementorController; |
| 19 | use SuperbAddons\Gutenberg\Controllers\GutenbergController; |
| 20 | |
| 21 | class DashboardController |
| 22 | { |
| 23 | const MENU_SLUG = 'superbaddons'; |
| 24 | const DASHBOARD = 'dashboard'; |
| 25 | const ELEMENTOR_DASHBOARD = 'superbaddons-element-dashboard'; |
| 26 | const GUTENBERG_DASHBOARD = 'superbaddons-gutenberg-dashboard'; |
| 27 | const SETTINGS = 'superbaddons-settings'; |
| 28 | const SUPPORT = 'superbaddons-support'; |
| 29 | |
| 30 | const PREMIUM_CLASS = 'superbaddons-get-premium'; |
| 31 | |
| 32 | private $hooks; |
| 33 | |
| 34 | public function __construct() |
| 35 | { |
| 36 | new SettingsController(); |
| 37 | new TroubleshootingController(); |
| 38 | $this->hooks = array(); |
| 39 | add_action("admin_menu", array($this, 'SuperbAddonsAdminMenu')); |
| 40 | add_filter('plugin_action_links_' . SUPERBADDONS_BASE, array($this, 'PluginActions')); |
| 41 | add_action('admin_enqueue_scripts', array($this, 'AdminMenuEnqueues'), 1000); |
| 42 | if (!KeyController::HasValidPremiumKey()) { |
| 43 | add_action("admin_head", array($this, 'AdminMenuHighlightScripts')); |
| 44 | } |
| 45 | $this->HandleNotices(); |
| 46 | } |
| 47 | |
| 48 | |
| 49 | public function PluginActions($actions) |
| 50 | { |
| 51 | $added_actions = array( |
| 52 | "<a href='" . esc_url(admin_url("admin.php?page=" . self::MENU_SLUG)) . "'>" . esc_html__('Dashboard', "superb-blocks") . "</a>", |
| 53 | "<a href='" . esc_url(admin_url("admin.php?page=" . self::SETTINGS)) . "'>" . esc_html__('Settings', "superb-blocks") . "</a>", |
| 54 | "<a href='" . esc_url(admin_url("admin.php?page=" . self::SUPPORT)) . "'>" . esc_html__('Support', "superb-blocks") . "</a>" |
| 55 | ); |
| 56 | $actions = array_merge($added_actions, $actions); |
| 57 | if (!KeyController::HasValidPremiumKey()) { |
| 58 | $actions[] = "<a href='" . esc_url("https://superbthemes.com/superb-addons/") . "' class='" . self::PREMIUM_CLASS . "' target='_blank'>" . esc_html__('Get Premium', "superb-blocks") . "</a>"; |
| 59 | } |
| 60 | return $actions; |
| 61 | } |
| 62 | |
| 63 | public function SuperbAddonsAdminMenu() |
| 64 | { |
| 65 | add_menu_page(esc_html__('Superb Addons', "superb-blocks"), esc_html__('Superb Addons', "superb-blocks") . $this->GetAdminMenuNotification(), Capabilities::CONTRIBUTOR, self::MENU_SLUG, array($this, 'SuperbDashboard'), SUPERBADDONS_ASSETS_PATH . '/img/icon-superb-dashboard-menu.png', '58.6'); |
| 66 | $this->hooks[self::DASHBOARD] = add_submenu_page(self::MENU_SLUG, esc_html__('Superb Addons - Dashboard', "superb-blocks"), esc_html__('Dashboard', "superb-blocks"), Capabilities::CONTRIBUTOR, self::MENU_SLUG); |
| 67 | $this->hooks[self::GUTENBERG_DASHBOARD] = add_submenu_page(self::MENU_SLUG, esc_html__('Superb Addons - Gutenberg', "superb-blocks"), esc_html__('Gutenberg Addons', "superb-blocks"), Capabilities::CONTRIBUTOR, self::GUTENBERG_DASHBOARD, array($this, 'GutenbergDashboard')); |
| 68 | $this->hooks[self::ELEMENTOR_DASHBOARD] = add_submenu_page(self::MENU_SLUG, esc_html__('Superb Addons - Elementor', "superb-blocks"), esc_html__('Elementor Addons', "superb-blocks"), Capabilities::CONTRIBUTOR, self::ELEMENTOR_DASHBOARD, array($this, 'ElementorDashboard')); |
| 69 | $this->hooks[self::SETTINGS] = add_submenu_page(self::MENU_SLUG, esc_html__('Superb Addons - Settings', "superb-blocks"), esc_html__('Settings', "superb-blocks") . $this->GetAdminMenuNotification(), Capabilities::ADMIN, self::SETTINGS, array($this, 'Settings')); |
| 70 | $this->hooks[self::SUPPORT] = add_submenu_page(self::MENU_SLUG, esc_html__('Superb Addons - Get Help', "superb-blocks"), esc_html__('Get Help', "superb-blocks"), Capabilities::CONTRIBUTOR, self::SUPPORT, array($this, 'Support')); |
| 71 | } |
| 72 | |
| 73 | private function GetAdminMenuNotification() |
| 74 | { |
| 75 | $HasRegisteredKey = KeyController::HasRegisteredKey(); |
| 76 | if ($HasRegisteredKey) { |
| 77 | $KeyStatus = KeyController::GetKeyStatus(); |
| 78 | if (!$KeyStatus['active'] || $KeyStatus['expired'] || !$KeyStatus['verified'] || $KeyStatus['exceeded']) { |
| 79 | return sprintf('<span class="update-plugins count-1"><span class="plugin-count" aria-hidden="true">1</span><span class="screen-reader-text">%s</span></span>', esc_html__("Issue Detected", "superb-blocks")); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | public function AdminMenuHighlightScripts() |
| 87 | { |
| 88 | ?> |
| 89 | <style> |
| 90 | tbody#the-list .<?= self::PREMIUM_CLASS ?> { |
| 91 | color: #4312E2; |
| 92 | font-weight: 900; |
| 93 | } |
| 94 | </style> |
| 95 | <?php |
| 96 | } |
| 97 | |
| 98 | public function HandleNotices() |
| 99 | { |
| 100 | $options = array("notices" => array()); |
| 101 | if (!KeyController::HasValidPremiumKey()) { |
| 102 | $options["notices"][] = array( |
| 103 | 'unique_id' => 'addons_delayed', |
| 104 | 'content' => "addons-notice.php", |
| 105 | 'delay' => '+6 days' |
| 106 | ); |
| 107 | } |
| 108 | AdminNoticeController::init($options); |
| 109 | } |
| 110 | |
| 111 | public function AdminMenuEnqueues($page_hook) |
| 112 | { |
| 113 | if ($page_hook === 'plugins.php') { |
| 114 | wp_enqueue_style( |
| 115 | 'superb-addons-elements', |
| 116 | SUPERBADDONS_ASSETS_PATH . '/css/framework.min.css', |
| 117 | array(), |
| 118 | SUPERBADDONS_VERSION |
| 119 | ); |
| 120 | wp_enqueue_style( |
| 121 | 'superb-addons-font-manrope', |
| 122 | SUPERBADDONS_ASSETS_PATH . '/fonts/manrope/manrope.css', |
| 123 | array(), |
| 124 | SUPERBADDONS_VERSION |
| 125 | ); |
| 126 | wp_enqueue_style( |
| 127 | 'superb-addons-admin-modal', |
| 128 | SUPERBADDONS_ASSETS_PATH . '/css/admin-modal.min.css', |
| 129 | array(), |
| 130 | SUPERBADDONS_VERSION |
| 131 | ); |
| 132 | |
| 133 | wp_enqueue_script('superb-addons-feedback', SUPERBADDONS_ASSETS_PATH . '/js/admin/deactivate-feedback.js', array('jquery'), SUPERBADDONS_VERSION, true); |
| 134 | wp_localize_script('superb-addons-feedback', 'superbaddonssettings_g', array( |
| 135 | "plugin" => plugin_basename(SUPERBADDONS_BASE), |
| 136 | "rest" => array( |
| 137 | "base" => \get_rest_url(), |
| 138 | "namespace" => RestController::NAMESPACE, |
| 139 | "nonce" => wp_create_nonce("wp_rest"), |
| 140 | "routes" => array( |
| 141 | "settings" => SettingsController::SETTINGS_ROUTE, |
| 142 | ) |
| 143 | ) |
| 144 | )); |
| 145 | add_action('admin_footer', function () { |
| 146 | new FeedbackModal(); |
| 147 | }); |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | if (!in_array($page_hook, array_values($this->hooks))) { |
| 152 | return; |
| 153 | } |
| 154 | wp_enqueue_style( |
| 155 | 'superb-addons-admin-dashboard', |
| 156 | SUPERBADDONS_ASSETS_PATH . '/css/admin-dashboard.min.css', |
| 157 | array(), |
| 158 | SUPERBADDONS_VERSION |
| 159 | ); |
| 160 | wp_enqueue_style( |
| 161 | 'superb-addons-elements', |
| 162 | SUPERBADDONS_ASSETS_PATH . '/css/framework.min.css', |
| 163 | array(), |
| 164 | SUPERBADDONS_VERSION |
| 165 | ); |
| 166 | wp_enqueue_style( |
| 167 | 'superb-addons-font-manrope', |
| 168 | SUPERBADDONS_ASSETS_PATH . '/fonts/manrope/manrope.css', |
| 169 | array(), |
| 170 | SUPERBADDONS_VERSION |
| 171 | ); |
| 172 | |
| 173 | if ($page_hook === $this->hooks[self::SUPPORT]) { |
| 174 | wp_enqueue_script('superb-addons-troubleshooting', SUPERBADDONS_ASSETS_PATH . '/js/admin/troubleshooting.js', array('jquery', 'wp-i18n'), SUPERBADDONS_VERSION, true); |
| 175 | wp_localize_script('superb-addons-troubleshooting', 'superbaddonstroubleshooting_g', array( |
| 176 | "rest" => array( |
| 177 | "base" => \get_rest_url(), |
| 178 | "namespace" => RestController::NAMESPACE, |
| 179 | "nonce" => wp_create_nonce("wp_rest"), |
| 180 | "routes" => array( |
| 181 | "troubleshooting" => TroubleshootingController::TROUBLESHOOTING_ROUTE, |
| 182 | "tutorial" => TroubleshootingController::TUTORIAL_ROUTE, |
| 183 | ) |
| 184 | ), |
| 185 | "steps" => array( |
| 186 | "wordpressversion" => array( |
| 187 | "title" => esc_html__("WordPress Version", "superb-blocks"), |
| 188 | "text" => esc_html__("Checking Compatibility", "superb-blocks"), |
| 189 | "errorText" => esc_html__("Incompatible. Please update WordPress.", "superb-blocks"), |
| 190 | "successText" => esc_html__("Compatible", "superb-blocks"), |
| 191 | ), |
| 192 | "elementorversion" => array( |
| 193 | "title" => esc_html__("Elementor Version", "superb-blocks"), |
| 194 | "text" => esc_html__("Checking Compatibility", "superb-blocks"), |
| 195 | "errorText" => esc_html__("Incompatible. Please install or update Elementor.", "superb-blocks"), |
| 196 | "successText" => esc_html__("Compatible", "superb-blocks"), |
| 197 | ), |
| 198 | "connection" => array( |
| 199 | "title" => esc_html__("Connection Status", "superb-blocks"), |
| 200 | "text" => esc_html__("Checking Connection", "superb-blocks"), |
| 201 | "errorText" => esc_html__("No Connection", "superb-blocks"), |
| 202 | "successText" => esc_html__("Connected", "superb-blocks"), |
| 203 | ), |
| 204 | "domainshift" => array( |
| 205 | "title" => esc_html__("Connection Update", "superb-blocks"), |
| 206 | "text" => esc_html__("Trying New Connection", "superb-blocks"), |
| 207 | "errorText" => esc_html__("Connection Blocked", "superb-blocks"), |
| 208 | "successText" => esc_html__("Connected", "superb-blocks"), |
| 209 | ), |
| 210 | "service" => array( |
| 211 | "title" => esc_html__("Service Status", "superb-blocks"), |
| 212 | "text" => esc_html__("Checking Service", "superb-blocks"), |
| 213 | "errorText" => esc_html__("Service Unavailable", "superb-blocks"), |
| 214 | "successText" => esc_html__("Service Online", "superb-blocks"), |
| 215 | ), |
| 216 | "keycheck" => array( |
| 217 | "title" => esc_html__("License Key Status", "superb-blocks"), |
| 218 | "text" => esc_html__("Checking License Key", "superb-blocks"), |
| 219 | "errorText" => esc_html__("Invalid License Key", "superb-blocks"), |
| 220 | "successText" => esc_html__("Valid License Key", "superb-blocks"), |
| 221 | ), |
| 222 | "keyverify" => array( |
| 223 | "title" => esc_html__("License Key Verification", "superb-blocks"), |
| 224 | "text" => esc_html__("Re-verifying License Key", "superb-blocks"), |
| 225 | "errorText" => esc_html__("License could not be verified", "superb-blocks"), |
| 226 | "successText" => esc_html__("License Key Verified", "superb-blocks"), |
| 227 | ), |
| 228 | "cacheclear" => array( |
| 229 | "title" => esc_html__("Cache Status", "superb-blocks"), |
| 230 | "text" => esc_html__("Clearing Cache", "superb-blocks"), |
| 231 | "errorText" => esc_html__("Cache could not be cleared", "superb-blocks"), |
| 232 | "successText" => esc_html__("Cache Cleared", "superb-blocks"), |
| 233 | ) |
| 234 | ) |
| 235 | )); |
| 236 | add_action("admin_footer", array($this, 'TroubleshootingTemplates')); |
| 237 | wp_enqueue_style( |
| 238 | 'superb-addons-admin-modal', |
| 239 | SUPERBADDONS_ASSETS_PATH . '/css/admin-modal.min.css', |
| 240 | array(), |
| 241 | SUPERBADDONS_VERSION |
| 242 | ); |
| 243 | wp_enqueue_style( |
| 244 | 'superbaddons-js-snackbar', |
| 245 | SUPERBADDONS_ASSETS_PATH . '/lib/js-snackbar.min.css', |
| 246 | array(), |
| 247 | SUPERBADDONS_VERSION |
| 248 | ); |
| 249 | } elseif ($page_hook === $this->hooks[self::SETTINGS]) { |
| 250 | wp_enqueue_style( |
| 251 | 'superb-addons-admin-modal', |
| 252 | SUPERBADDONS_ASSETS_PATH . '/css/admin-modal.min.css', |
| 253 | array(), |
| 254 | SUPERBADDONS_VERSION |
| 255 | ); |
| 256 | |
| 257 | wp_enqueue_script('superb-addons-settings', SUPERBADDONS_ASSETS_PATH . '/js/admin/settings.js', array('jquery'), SUPERBADDONS_VERSION, true); |
| 258 | wp_localize_script('superb-addons-settings', 'superbaddonssettings_g', array( |
| 259 | "save_message" => esc_html__("Settings saved successfully.", "superb-blocks"), |
| 260 | "modal" => array( |
| 261 | "cache" => array( |
| 262 | "title" => esc_html__("Clear Cache", "superb-blocks"), |
| 263 | "content" => esc_html__("All element- data and images will need to be loaded again if the cache is removed. This should only be done if you are experiencing issues or planning to delete the plugin. Are you sure you want to clear the cache?", "superb-blocks"), |
| 264 | "success" => esc_html__("Cache cleared successfully.", "superb-blocks") |
| 265 | ), |
| 266 | "view_logs" => array( |
| 267 | "title" => esc_html__("Error Log", "superb-blocks"), |
| 268 | "no_logs" => esc_html__("No errors have been logged.", "superb-blocks"), |
| 269 | "icon_unshared" => esc_url(SUPERBADDONS_ASSETS_PATH . "/img/cloud-slash.svg"), |
| 270 | "unshared_title" => esc_html__("Error Log Not Shared", "superb-blocks"), |
| 271 | "icon_shared" => esc_url(SUPERBADDONS_ASSETS_PATH . "/img/cloud-check.svg"), |
| 272 | "shared_title" => esc_html__("Error Log Shared", "superb-blocks"), |
| 273 | ), |
| 274 | "clear_logs" => array( |
| 275 | "title" => esc_html__("Clear Logs", "superb-blocks"), |
| 276 | "content" => esc_html__("Error Logs are used for debugging purposes and help improve the plugin when shared with our support team and developers. Are you sure you want to clear the error logs?", "superb-blocks"), |
| 277 | "success" => esc_html__("Error logs cleared successfully.", "superb-blocks") |
| 278 | ), |
| 279 | "remove_key" => array( |
| 280 | "title" => esc_html__("Remove License Key", "superb-blocks"), |
| 281 | "content" => esc_html__("Are you sure you want to remove your license key from this website?", "superb-blocks"), |
| 282 | ) |
| 283 | ), |
| 284 | "rest" => array( |
| 285 | "base" => \get_rest_url(), |
| 286 | "namespace" => RestController::NAMESPACE, |
| 287 | "nonce" => wp_create_nonce("wp_rest"), |
| 288 | "routes" => array( |
| 289 | "settings" => SettingsController::SETTINGS_ROUTE, |
| 290 | ) |
| 291 | ) |
| 292 | )); |
| 293 | wp_enqueue_style( |
| 294 | 'superbaddons-js-snackbar', |
| 295 | SUPERBADDONS_ASSETS_PATH . '/lib/js-snackbar.min.css', |
| 296 | array(), |
| 297 | SUPERBADDONS_VERSION |
| 298 | ); |
| 299 | } elseif ($page_hook === $this->hooks[self::ELEMENTOR_DASHBOARD] || $page_hook === $this->hooks[self::GUTENBERG_DASHBOARD]) { |
| 300 | $library_loader_file = $page_hook === $this->hooks[self::ELEMENTOR_DASHBOARD] ? 'elementor' : 'gutenberg'; |
| 301 | $menu_items = $page_hook === $this->hooks[self::ELEMENTOR_DASHBOARD] ? ElementorController::GetElementorLibraryMenuItems() : GutenbergController::GetGutenbergLibraryMenuItems(); |
| 302 | |
| 303 | |
| 304 | wp_enqueue_script('superb-addons-select2', SUPERBADDONS_ASSETS_PATH . '/lib/select2.min.js', array('jquery'), SUPERBADDONS_VERSION, true); |
| 305 | wp_enqueue_script('superb-addons-library-dashboard', SUPERBADDONS_ASSETS_PATH . '/js/admin/' . $library_loader_file . '.js', array('jquery'), SUPERBADDONS_VERSION, true); |
| 306 | wp_localize_script('superb-addons-library-dashboard', 'superblayoutlibrary_g', array( |
| 307 | "style_placeholder" => esc_html__('All themes', "superb-blocks"), |
| 308 | "category_placeholder" => esc_html__('All categories', "superb-blocks"), |
| 309 | "snacks" => array( |
| 310 | "list_error" => esc_html__('Something went wrong while attempting to list elements. Please try again or contact support if the problem persists.', "superb-blocks") |
| 311 | ), |
| 312 | "menu_items" => $menu_items, |
| 313 | "rest" => array( |
| 314 | "base" => \get_rest_url(), |
| 315 | "namespace" => RestController::NAMESPACE, |
| 316 | "nonce" => wp_create_nonce("wp_rest"), |
| 317 | "routes" => array( |
| 318 | "settings" => SettingsController::SETTINGS_ROUTE, |
| 319 | ) |
| 320 | ) |
| 321 | )); |
| 322 | |
| 323 | wp_enqueue_style( |
| 324 | 'superb-elementor-editor-layout-library', |
| 325 | SUPERBADDONS_ASSETS_PATH . '/css/layout-library-editor.min.css', |
| 326 | array(), |
| 327 | SUPERBADDONS_VERSION |
| 328 | ); |
| 329 | wp_enqueue_style( |
| 330 | 'superbaddons-select2', |
| 331 | SUPERBADDONS_ASSETS_PATH . '/lib/select2.min.css', |
| 332 | array(), |
| 333 | SUPERBADDONS_VERSION |
| 334 | ); |
| 335 | wp_enqueue_style( |
| 336 | 'superbaddons-js-snackbar', |
| 337 | SUPERBADDONS_ASSETS_PATH . '/lib/js-snackbar.min.css', |
| 338 | array(), |
| 339 | SUPERBADDONS_VERSION |
| 340 | ); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | public function TroubleshootingTemplates() |
| 345 | { |
| 346 | ob_start(); |
| 347 | include(SUPERBADDONS_PLUGIN_DIR . 'src/admin/templates/troubleshooting-step.php'); |
| 348 | $template = ob_get_clean(); |
| 349 | echo '<script type="text/template" id="tmpl-superb-addons-troubleshooting-step">' . $template . '</script>'; |
| 350 | } |
| 351 | |
| 352 | public function SuperbDashboard() |
| 353 | { |
| 354 | $this->DashboardPageSetup(DashboardPage::class); |
| 355 | } |
| 356 | |
| 357 | public function ElementorDashboard() |
| 358 | { |
| 359 | $this->DashboardPageSetup(ElementorDashboardPage::class); |
| 360 | } |
| 361 | |
| 362 | public function GutenbergDashboard() |
| 363 | { |
| 364 | $this->DashboardPageSetup(GutenbergDashboardPage::class); |
| 365 | } |
| 366 | |
| 367 | public function Support() |
| 368 | { |
| 369 | $this->DashboardPageSetup(SupportPage::class); |
| 370 | } |
| 371 | |
| 372 | public function Settings() |
| 373 | { |
| 374 | $this->DashboardPageSetup(SettingsPage::class); |
| 375 | } |
| 376 | |
| 377 | private function DashboardPageSetup($page_class) |
| 378 | { |
| 379 | ?> |
| 380 | <div class="superbaddons-wrap"> |
| 381 | <?php new Navigation(); ?> |
| 382 | <div class="superbaddons-wrap-inner"> |
| 383 | <?php new $page_class(); ?> |
| 384 | </div> |
| 385 | </div> |
| 386 | <?php |
| 387 | } |
| 388 | } |
| 389 |