CategoriesController.php
8 years ago
ExportController.php
4 years ago
GoogleCategoriesController.php
8 years ago
SchedulingConnectionController.php
8 years ago
SchedulingLicenseController.php
7 years ago
SchedulingLicenseController.php
89 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 | $license = $_POST['license']; |
| 44 | |
| 45 | if($this->licensingManager->checkLicense($license, \PMXE_Plugin::getSchedulingName())){ |
| 46 | PMXE_Plugin::getInstance()->updateOption(array('scheduling_license' => $license)); |
| 47 | $post['license_status'] = $this->check_scheduling_license(); |
| 48 | $response = $this->activate_scheduling_licenses(); |
| 49 | |
| 50 | return new JsonResponse(array('success' => true)); |
| 51 | } else { |
| 52 | return new JsonResponse(array('success'=> false)); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | * |
| 58 | * Activate licenses for main plugin and all premium addons |
| 59 | * |
| 60 | */ |
| 61 | protected function activate_scheduling_licenses() |
| 62 | { |
| 63 | global $wpdb; |
| 64 | |
| 65 | delete_transient(PMXE_Plugin::$cache_key); |
| 66 | |
| 67 | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_' . PMXE_Plugin::$cache_key) ); |
| 68 | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_timeout_' . PMXE_Plugin::$cache_key) ); |
| 69 | |
| 70 | delete_site_transient('update_plugins'); |
| 71 | |
| 72 | // retrieve the license from the database |
| 73 | return $this->licensingActivator->activateLicense(PMXE_Plugin::getSchedulingName(),\Wpae\App\Service\License\LicenseActivator::CONTEXT_SCHEDULING); |
| 74 | } |
| 75 | |
| 76 | public function check_scheduling_license() |
| 77 | { |
| 78 | $options = PMXE_Plugin::getInstance()->getOption(); |
| 79 | |
| 80 | global $wpdb; |
| 81 | |
| 82 | delete_transient(PMXE_Plugin::$cache_key); |
| 83 | |
| 84 | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_' . PMXE_Plugin::$cache_key) ); |
| 85 | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name = %s", $this->slug . '_timeout_' . PMXE_Plugin::$cache_key) ); |
| 86 | |
| 87 | return $this->licensingActivator->checkLicense(PMXE_Plugin::getSchedulingName(), $options, LicenseActivator::CONTEXT_SCHEDULING); |
| 88 | } |
| 89 | } |