Beispiel #1
0
 /**
  * Get activated activations by license
  *
  * @param \Never5\LicenseWP\License\License $license
  * @param \Never5\LicenseWP\ApiProduct\ApiProduct $api_product
  * @param bool $only_active
  *
  * @return array
  */
 public function get_activations($license, $api_product = null, $only_active = true)
 {
     global $wpdb;
     // dat SQL
     $sql = "SELECT `activation_id` FROM {$wpdb->lwp_activations} WHERE `license_key`=%s";
     // add API product ID if !== null
     if (null !== $api_product) {
         $sql .= $wpdb->prepare(" AND `api_product_id`=%s ", $api_product->get_slug());
     }
     // add if only_active is true
     if ($only_active) {
         $sql .= " AND activation_active = 1";
     }
     $sql .= ";";
     // get activation rows
     $rows = $wpdb->get_results($wpdb->prepare($sql, $license->get_key()));
     // array that stores the api products
     $activations = array();
     // check and loop
     if (is_array($rows) && count($rows) > 0) {
         foreach ($rows as $row) {
             // create ApiProduct objects and store them in array
             $activations[] = license_wp()->service('activation_factory')->make($row->activation_id);
         }
     }
     // return array
     return $activations;
 }
Beispiel #2
0
 /**
  * @param string $content
  * @param License $license
  *
  * @return string
  */
 private function replace_expiration_vars($content, $license)
 {
     // get user
     $user = get_user_by('id', $license->get_user_id());
     // get first name
     $fname = 'there';
     if (!empty($user) && !empty($user->first_name)) {
         $fname = $user->first_name;
     }
     // get WooCommerce product object
     $wc_product = new \WC_Product($license->get_product_id());
     // get parent product if the product has one
     if (0 != $wc_product->get_parent()) {
         $wc_product = new \WC_Product($wc_product->get_parent());
     }
     $content = str_ireplace(':fname:', $fname, $content);
     $content = str_ireplace(':product:', $wc_product->get_title(), $content);
     $content = str_ireplace(':license-key:', $license->get_key(), $content);
     $content = str_ireplace(':license-expiration-date:', $license->get_date_expires() ? $license->get_date_expires()->format('M d Y') : '', $content);
     $content = str_ireplace(':renewal-link:', $license->get_renewal_url(), $content);
     return $content;
 }
Beispiel #3
0
 /**
  * Deactivates an instance of a license
  *
  * @param \Never5\LicenseWP\License\License $license
  * @param \Never5\LicenseWP\ApiProduct\ApiProduct $api_product
  * @param array $request
  *
  * @throws ApiException
  */
 private function deactivate($license, $api_product, $request)
 {
     // get activations
     $activations = $license->get_activations($api_product);
     // check & loop
     if (count($activations) > 0) {
         /** @var \Never5\LicenseWP\Activation\Activation $activation */
         foreach ($activations as $activation) {
             // check if given instance equals activation instance
             if ($activation->format_instance($request['instance']) === $activation->get_instance()) {
                 // set activation to not active
                 $activation->set_activation_active(0);
                 // set activation date to now
                 $activation->set_activation_date(new \DateTime());
                 // persist activation
                 $activation = license_wp()->service('activation_repository')->persist($activation);
                 // check if deactivation was successful
                 if ($activation->is_active()) {
                     throw new ApiException(__('Deactivation error: Could not deactivate license key. Please contact support.', 'license-wp'), 108);
                 }
                 // response
                 $response = apply_filters('license_wp_api_activation_response', array('success' => true));
                 // send JSON the WP way
                 wp_send_json($response);
                 exit;
             }
         }
     }
     throw new ApiException(__('Deactivation error: instance not found.', 'license-wp'), 109);
 }
Beispiel #4
0
 /**
  * Returns URL to deactivate activation
  *
  * @param \Never5\LicenseWP\License\License $license
  *
  * @return string
  */
 public function get_deactivate_url($license)
 {
     return esc_url(add_query_arg(array('deactivate_license' => $this->get_id(), 'license_key' => $license->get_key(), 'activation_email' => $license->get_activation_email())));
 }
Beispiel #5
0
 /**
  * Get API product download URL
  *
  * @param \Never5\LicenseWP\License\License $license
  *
  * @return string
  */
 public function get_download_url($license)
 {
     return add_query_arg(array('download_api_product' => $this->get_id(), 'license_key' => $license->get_key(), 'activation_email' => $license->get_activation_email()), home_url('/'));
 }