/** * Get plugin information */ public function plugin_information() { $this->check_access(); $api_product_post_id = wppl_get_api_product_post_id($this->request['api_product_id']); $plugin_version = get_post_meta($api_product_post_id, '_version', true); $transient_name = 'plugininfo_' . md5($this->request['api_product_id'] . $plugin_version); if (false === ($data = get_transient($transient_name))) { $api_product_post = get_post($api_product_post_id); $data = new stdClass(); $data->name = $api_product_post->post_title; $data->plugin = $this->request['plugin_name']; $data->slug = $this->request['api_product_id']; $data->version = $plugin_version; $data->last_updated = get_post_meta($api_product_post_id, '_last_updated', true); if ($author_uri = get_post_meta($api_product_post_id, '_author_uri', true)) { $data->author = '<a href="' . $author_uri . '">' . get_post_meta($api_product_post_id, '_author', true) . '</a>'; } else { $data->author = get_post_meta($api_product_post_id, '_author', true); } $data->requires = get_post_meta($api_product_post_id, '_requires_wp_version', true); $data->tested = get_post_meta($api_product_post_id, '_tested_wp_version', true); $data->homepage = get_post_meta($api_product_post_id, '_plugin_uri', true); $data->sections = array('description' => wpautop($api_product_post->post_content), 'changelog' => get_post_meta($api_product_post_id, '_changelog', true)); if (!function_exists('Markdown')) { include_once 'markdown.php'; } foreach ($data->sections as $key => $section) { $data->sections[$key] = str_replace(array("\r\n", "\r"), "\n", $data->sections[$key]); $data->sections[$key] = trim($data->sections[$key]); if (0 === strpos($data->sections[$key], "")) { $data->sections[$key] = substr($data->sections[$key], 3); } // Markdown transformations $data->sections[$key] = preg_replace('/^[\\s]*=[\\s]+(.+?)[\\s]+=/m', '<h4>$1</h4>', $data->sections[$key]); $data->sections[$key] = Markdown($data->sections[$key]); } set_transient($transient_name, $data, DAY_IN_SECONDS); } // Add download link which is unique to the request $data->download_link = wppl_get_package_download_url($api_product_post_id, $this->request['licence_key'], $this->request['email']); // Send response $this->send_response($data); }
/** * Activate a licence key */ public function activate() { global $wpdb; $this->check_required(array('email', 'licence_key', 'api_product_id', 'instance')); $licence = wppl_get_licence_from_key($this->request['licence_key']); $api_product_post_id = wppl_get_api_product_post_id($this->request['api_product_id']); if (!$licence) { $this->trigger_error('101', __('Activation error: The provided licence is invalid or has expired.', 'wp-plugin-licencing')); } if (!$api_product_post_id) { $this->trigger_error('102', __('Activation error: Invalid API Product ID.', 'wp-plugin-licencing')); } if (!is_email($this->request['email']) || strtolower($this->request['email']) != strtolower($licence->activation_email)) { $this->trigger_error('103', sprintf(__('Activation error: The email provided (%s) is invalid.', 'wp-plugin-licencing'), $this->request['email'])); } if (!in_array($api_product_post_id, wppl_get_licence_api_product_permissions($licence->product_id))) { $this->trigger_error('104', __('Activation error: Licence is not for this product.', 'wp-plugin-licencing')); } $active_instances = wppl_get_licence_activations($this->request['licence_key'], $this->request['api_product_id'], 1); // Check if activation limit is reached if ($licence->activation_limit && sizeof($active_instances) >= $licence->activation_limit) { // lets allow reactvation for guests, but registered users need to de-activate first if (!$licence->user_id) { foreach ($active_instances as $activation) { if ($activation->instance == $this->request['instance']) { // Reactivate the key $activation_result = $wpdb->update("{$wpdb->prefix}wp_plugin_licencing_activations", array('activation_active' => 1, 'activation_date' => current_time('mysql')), array('instance' => $this->request['instance'], 'api_product_id' => $this->request['api_product_id'], 'licence_key' => $this->request['licence_key'])); if (!$activation_result) { $this->trigger_error('106', __('Activation error: Could not reactivate licence key.', 'wp-plugin-licencing')); } else { $response = array('activated' => true); $activations_remaining = absint($licence->activation_limit - sizeof($active_instances)); $response['remaining'] = sprintf(__('%s out of %s activations remaining', 'wp-plugin-licencing'), $activations_remaining, $licence->activation_limit); $this->send_response($response); } } } } $this->trigger_error('105', __('Activation error: Licence key activation limit reached. Deactivate an install first.', 'wp-plugin-licencing')); } $instance_exists = false; $instances = wppl_get_licence_activations($this->request['licence_key'], $this->request['api_product_id']); // Check for reactivation if ($instances) { foreach ($instances as $activation) { if ($activation->instance == $this->request['instance']) { $instance_exists = true; } } } if ($instance_exists) { $activation_result = $wpdb->update("{$wpdb->prefix}wp_plugin_licencing_activations", array('activation_active' => 1, 'activation_date' => current_time('mysql')), array('instance' => $this->request['instance'], 'api_product_id' => $this->request['api_product_id'], 'licence_key' => $this->request['licence_key'])); } else { $activation_result = $wpdb->insert("{$wpdb->prefix}wp_plugin_licencing_activations", array('activation_active' => 1, 'activation_date' => current_time('mysql'), 'instance' => $this->request['instance'], 'api_product_id' => $this->request['api_product_id'], 'licence_key' => $this->request['licence_key'])); } if (!$activation_result) { $this->trigger_error('107', __('Activation error: Could not activate licence key.', 'wp-plugin-licencing')); } $activations = wppl_get_licence_activations($this->request['licence_key'], $this->request['api_product_id']); $response = array('activated' => true); if ($licence->activation_limit) { $activations_remaining = absint($licence->activation_limit - sizeof($activations)); $response['remaining'] = sprintf(__('%s out of %s activations remaining', 'wp-plugin-licencing'), $activations_remaining, $licence->activation_limit); } $this->send_response($response); }
echo '<ul class="digital-downloads">'; foreach ($api_product_permissions as $api_product_permission) { echo '<li><a class="download-button" href="' . wppl_get_package_download_url($api_product_permission, $key->licence_key, $key->activation_email) . '">' . get_the_title($api_product_permission) . ' (v' . get_post_meta($api_product_permission, '_version', true) . ')</a></li>'; } echo '</ul>'; } } ?> </td> </tr> <?php foreach ($activations as $activation) { ?> <tr> <td colspan="3"><?php echo get_the_title(wppl_get_api_product_post_id($activation->api_product_id)); ?> — <a href="<?php echo esc_attr($activation->instance); ?> " target="_blank"><?php echo esc_html($activation->instance); ?> </a> <a class="button" style="float:right" href="<?php echo wppl_get_licence_deactivation_url($activation->activation_id, $key->licence_key, $key->activation_email); ?> "><?php _e('Deactivate', 'wp-plugin-licencing'); ?> </a></td> </tr>