示例#1
0
 /**
  * @author Vova Feldman (@svovaf)
  * @since  1.0.5
  *
  * @param bool $background
  */
 protected function _activate_license($background = false)
 {
     $this->_logger->entrance();
     $license_id = fs_request_get('license_id');
     if (FS_Plugin_License::is_valid_id($license_id) && $license_id == $this->_site->license_id) {
         // License is already activated.
         return;
     }
     $premium_license = FS_Plugin_License::is_valid_id($license_id) ? $this->_get_license_by_id($license_id) : $this->_get_available_premium_license();
     if (!is_object($premium_license)) {
         return;
     }
     /**
      * If the premium license is already associated with the install, just
      * update the license reference (activation is not required).
      *
      * @since 1.1.9
      */
     if ($premium_license->id == $this->_site->license_id) {
         // License is already activated.
         $this->_update_site_license($premium_license);
         $this->_enrich_site_plan(false);
         $this->_store_account();
         return;
     }
     if ($this->_site->user_id != $premium_license->user_id) {
         $api_request_params = array('license_key' => $premium_license->secret_key);
     } else {
         $api_request_params = array();
     }
     $api = $this->get_api_site_scope();
     $license = $api->call("/licenses/{$premium_license->id}.json", 'put', $api_request_params);
     if ($this->is_api_error($license)) {
         if (!$background) {
             $this->_admin_notices->add(sprintf('%s %s', __fs('license-activation-failed-message', $this->_slug), is_object($license) && isset($license->error) ? $license->error->message : sprintf('%s<br><code>%s</code>', __fs('server-error-message', $this->_slug), var_export($license, true))), __fs('hmm', $this->_slug) . '...', 'error');
         }
         return;
     }
     $premium_license = new FS_Plugin_License($license);
     // Updated site plan.
     $site = $this->get_api_site_scope()->get('/', true);
     if (!$this->is_api_error($site)) {
         $this->_site = new FS_Site($site);
     }
     $this->_update_site_license($premium_license);
     $this->_enrich_site_plan(false);
     $this->_store_account();
     if (!$background) {
         $this->_admin_notices->add_sticky(__fs('license-activated-message', $this->_slug) . $this->get_complete_upgrade_instructions(), 'license_activated', __fs('yee-haw', $this->_slug) . '!');
     }
     $this->_admin_notices->remove_sticky(array('trial_promotion', 'license_expired'));
 }
 /**
  * @author Vova Feldman (@svovaf)
  * @since  1.0.5
  *
  * @param bool $background
  */
 protected function _activate_license($background = false)
 {
     $this->_logger->entrance();
     $license_id = fs_request_get('license_id');
     if (FS_Plugin_License::is_valid_id($license_id) && $license_id == $this->_site->license_id) {
         // License is already activated.
         return;
     }
     $premium_license = FS_Plugin_License::is_valid_id($license_id) ? $this->_get_license_by_id($license_id) : $this->_get_available_premium_license();
     if (!is_object($premium_license)) {
         return;
     }
     $api = $this->get_api_site_scope();
     $license = $api->call("/licenses/{$premium_license->id}.json", 'put');
     if ($this->is_api_error($license)) {
         if (!$background) {
             $this->_admin_notices->add(__fs('license-activation-failed-message', $this->_slug) . '<br> ' . __fs('server-error-message', $this->_slug) . ' ' . var_export($license, true), __fs('hmm', $this->_slug) . '...', 'error');
         }
         return;
     }
     $premium_license = new FS_Plugin_License($license);
     // Updated site plan.
     $site = $this->get_api_site_scope()->get('/', true);
     if (!$this->is_api_error($site)) {
         $this->_site = new FS_Site($site);
     }
     $this->_update_site_license($premium_license);
     $this->_enrich_site_plan(false);
     $this->_store_account();
     if (!$background) {
         $this->_admin_notices->add_sticky(__fs('license-activated-message', $this->_slug) . ($this->is_premium() ? '' : ' ' . $this->_get_latest_download_link(sprintf(__fs('download-latest-x-version', $this->_slug), $this->_site->plan->title))), 'license_activated', __fs('yee-haw', $this->_slug) . '!');
     }
     $this->_admin_notices->remove_sticky(array('trial_promotion', 'license_expired'));
 }