CategoriesController.php
8 years ago
ExportController.php
3 weeks ago
GoogleCategoriesController.php
3 weeks ago
SchedulingConnectionController.php
8 years ago
SchedulingLicenseController.php
3 weeks ago
SchedulingLicenseController.php
108 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\App\Controller; |
| 4 | |
| 5 | use PMXE_Plugin; |
| 6 | use Wpae\App\Service\License\LicenseActivator; |
| 7 | use Wpae\Http\JsonResponse; |
| 8 | use Wpae\Scheduling\LicensingManager; |
| 9 | |
| 10 | class SchedulingLicenseController |
| 11 | { |
| 12 | /** @var LicensingManager */ |
| 13 | private $licensingManager; |
| 14 | |
| 15 | /** @var LicenseActivator */ |
| 16 | private $licensingActivator; |
| 17 | |
| 18 | private $slug = 'wp-all-export-pro'; |
| 19 | |
| 20 | public function __construct() |
| 21 | { |
| 22 | $this->licensingManager = new LicensingManager(); |
| 23 | $this->licensingActivator = new LicenseActivator(); |
| 24 | } |
| 25 | |
| 26 | public function getSchedulingLicense() |
| 27 | { |
| 28 | $options = \PMXE_Plugin::getInstance()->getOption(); |
| 29 | |
| 30 | if (empty($options['scheduling_license'])) { |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | return new JsonResponse( |
| 35 | array( |
| 36 | 'license' => $this->licensingManager->checkLicense($options['scheduling_license'], \PMXE_Plugin::getSchedulingName()) |
| 37 | ) |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | public function saveSchedulingLicenseAction() |
| 42 | { |
| 43 | // phpcs:ignore WordPress.Security.NonceVerification.Missing -- AJAX nonce verified by check_ajax_referer in wpae_api dispatcher (wpae_api.php) plus current_user_can capability check |
| 44 | $license = isset( $_POST['license'] ) ? sanitize_text_field( wp_unslash( $_POST['license'] ) ) : ''; |
| 45 | |
| 46 | $licenseCheckResponse = $this->licensingManager->checkLicense($license, \PMXE_Plugin::getSchedulingName()); |
| 47 | if(!empty($licenseCheckResponse['success'])) { |
| 48 | PMXE_Plugin::getInstance()->updateOption(array('scheduling_license' => $license)); |
| 49 | $post['license_status'] = $this->check_scheduling_license(); |
| 50 | $response = $this->activate_scheduling_licenses(); |
| 51 | |
| 52 | if (class_exists('PMXI_Plugin')) { |
| 53 | if (method_exists('PMXI_Plugin', 'getSchedulingName')) { |
| 54 | |
| 55 | if (!empty($license)) { |
| 56 | $schedulingLicenseData = array(); |
| 57 | $schedulingLicenseData['scheduling_license_status'] = $post['license_status']; |
| 58 | $schedulingLicenseData['scheduling_license'] = $license; |
| 59 | |
| 60 | \PMXI_Plugin::getInstance()->updateOption($schedulingLicenseData); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return new JsonResponse($licenseCheckResponse); |
| 66 | } else { |
| 67 | return new JsonResponse($licenseCheckResponse); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * |
| 73 | * Activate licenses for main plugin and all premium addons |
| 74 | * |
| 75 | */ |
| 76 | protected function activate_scheduling_licenses() |
| 77 | { |
| 78 | global $wpdb; |
| 79 | |
| 80 | delete_transient(PMXE_Plugin::$cache_key); |
| 81 | |
| 82 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- forces removal of cached license-check transient rows on options table to bypass any stale object-cache hit before re-activation |
| 83 | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_' . PMXE_Plugin::$cache_key) ); |
| 84 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- forces removal of cached license-check transient timeout row on options table to bypass any stale object-cache hit before re-activation |
| 85 | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_timeout_' . PMXE_Plugin::$cache_key) ); |
| 86 | |
| 87 | delete_site_transient('update_plugins'); |
| 88 | |
| 89 | // retrieve the license from the database |
| 90 | return $this->licensingActivator->activateLicense(PMXE_Plugin::getSchedulingName(),\Wpae\App\Service\License\LicenseActivator::CONTEXT_SCHEDULING); |
| 91 | } |
| 92 | |
| 93 | public function check_scheduling_license() |
| 94 | { |
| 95 | $options = PMXE_Plugin::getInstance()->getOption(); |
| 96 | |
| 97 | global $wpdb; |
| 98 | |
| 99 | delete_transient(PMXE_Plugin::$cache_key); |
| 100 | |
| 101 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- forces removal of cached license-check transient rows on options table to bypass any stale object-cache hit before re-checking |
| 102 | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_' . PMXE_Plugin::$cache_key) ); |
| 103 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- forces removal of cached license-check transient timeout row on options table to bypass any stale object-cache hit before re-checking |
| 104 | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_timeout_' . PMXE_Plugin::$cache_key) ); |
| 105 | |
| 106 | return $this->licensingActivator->checkLicense(PMXE_Plugin::getSchedulingName(), $options, LicenseActivator::CONTEXT_SCHEDULING); |
| 107 | } |
| 108 | } |