Skip to content

Commit

Permalink
v2.5 released
Browse files Browse the repository at this point in the history
  • Loading branch information
Jedi knight authored and amin0_000 committed Dec 6, 2016
1 parent 0a48d4e commit 98bb263
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 19 deletions.
127 changes: 113 additions & 14 deletions software-license-manager/includes/slm-third-party-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/* * ********************************* */
/* * * WP eStore Plugin Integration ** */
/* * ********************************* */
add_filter('eStore_notification_email_body_filter', 'slm_handle_estore_email_body_filter', 10, 3);//Standard sale notification email
add_filter('eStore_squeeze_form_email_body_filter', 'slm_handle_estore_email_body_filter', 10, 3);//Squeeze form email
add_filter('eStore_notification_email_body_filter', 'slm_handle_estore_email_body_filter', 10, 3); //Standard sale notification email
add_filter('eStore_squeeze_form_email_body_filter', 'slm_handle_estore_email_body_filter', 10, 3); //Squeeze form email

function slm_handle_estore_email_body_filter($body, $payment_data, $cart_items) {
global $slm_debug_logger, $wpdb;
Expand Down Expand Up @@ -40,21 +40,34 @@ function slm_estore_check_and_generate_key($retrieved_product, $payment_data, $c

if ($retrieved_product->create_license == 1) {
$slm_debug_logger->log_debug('Need to create a license key for this product (' . $retrieved_product->id . ')');
$slm_key = slm_estore_create_license($payment_data, $cart_items);
$slm_key = slm_estore_create_license($retrieved_product, $payment_data, $cart_items);
$license_data = "\n" . __('Item Name: ', 'slm') . $retrieved_product->name . " - " . __('License Key: ', 'slm') . $slm_key;
$slm_debug_logger->log_debug('Liense data: ' . $license_data);
$license_data = apply_filters('slm_estore_item_license_data', $license_data);
}
return $license_data;
}

function slm_estore_create_license($payment_data, $cart_items) {
function slm_estore_create_license($retrieved_product, $payment_data, $cart_items) {
global $slm_debug_logger;
global $wpdb;

$product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME;

//Retrieve the default settings values.
$options = get_option('slm_plugin_options');
$lic_key_prefix = $options['lic_prefix'];
$max_domains = $options['default_max_domains'];

//Lets check any product specific configuration.
$prod_id = $retrieved_product->id;
$product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_max_allowed_domains'", OBJECT);
if ($product_meta) {
//Found product specific SLM config data.
$max_domains = $product_meta->meta_value;
} else {
//Use the default value from settings
}

$fields = array();
$fields['license_key'] = uniqid($lic_key_prefix);
$fields['lic_status'] = 'pending';
Expand All @@ -63,27 +76,27 @@ function slm_estore_create_license($payment_data, $cart_items) {
$fields['email'] = $payment_data['payer_email'];
$fields['company_name'] = $payment_data['company_name'];
$fields['txn_id'] = $payment_data['txn_id'];
$fields['date_created'] = date ("Y-m-d");//Today's date
$fields['max_allowed_domains'] = $options['default_max_domains']; //TODO - later take from estore's product configuration
$fields['date_created'] = date("Y-m-d"); //Today's date
$fields['max_allowed_domains'] = $max_domains;

$slm_debug_logger->log_debug('Inserting license data into the license manager DB table.');
$fields = array_filter($fields);//Remove any null values.
$fields = array_filter($fields); //Remove any null values.


$tbl_name = SLM_TBL_LICENSE_KEYS;
$result = $wpdb->insert($tbl_name, $fields);
if(!$result){
$slm_debug_logger->log_debug('Notice! initial database table insert failed on license key table (User Email: '.$fields['email'].'). Trying again by converting charset', true);
if (!$result) {
$slm_debug_logger->log_debug('Notice! initial database table insert failed on license key table (User Email: ' . $fields['email'] . '). Trying again by converting charset', true);
//Convert the default PayPal IPN charset to UTF-8 format
$first_name = mb_convert_encoding($fields['first_name'], "UTF-8", "windows-1252");
$fields['first_name'] = esc_sql($first_name);
$last_name = mb_convert_encoding($fields['last_name'], "UTF-8", "windows-1252");
$fields['last_name'] = esc_sql($last_name);
$company_name = mb_convert_encoding($fields['company_name'], "UTF-8", "windows-1252");
$fields['company_name'] = esc_sql($company_name);

$result = $wpdb->insert($tbl_name, $fields);
if(!$result){
if (!$result) {
$slm_debug_logger->log_debug('Error! Failed to update license key table. DB insert query failed.', false);
}
}
Expand All @@ -92,6 +105,92 @@ function slm_estore_create_license($payment_data, $cart_items) {
return $fields['license_key'];
}

/* Code to handle the eStore's product add/edit interface for SLM specific product configuration */
add_filter('eStore_addon_product_settings_filter', 'slm_estore_product_configuration_html', 10, 2); //Render the product add/edit HTML
add_action('eStore_new_product_added', 'slm_estore_new_product_added', 10, 2); //Handle the DB insert after a product add.
add_action('eStore_product_updated', 'slm_estore_product_updated', 10, 2); //Handle the DB update after a product edit.
add_action('eStore_product_deleted', 'slm_estore_product_deleted'); //Handle the DB delete after a product delete.

function slm_estore_product_configuration_html($product_config_html, $prod_id) {
global $wpdb;
$product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME;

if (empty($prod_id)) {
//New product add
$slm_max_allowed_domains = "";
} else {
//Existing product edit
$product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_max_allowed_domains'", OBJECT);
if ($product_meta) {
$slm_max_allowed_domains = $product_meta->meta_value;
} else {
$slm_max_allowed_domains = "";
}
}

$product_config_html .= '<div class="msg_head">Software License Manager Plugin (Click to Expand)</div><div class="msg_body"><table class="form-table">';

$product_config_html .= '<tr valign="top"><th scope="row">Maximum Allowed Domains</th><td>';
$product_config_html .= '<input name="slm_max_allowed_domains" type="text" id="slm_max_allowed_domains" value="' . $slm_max_allowed_domains . '" size="10" />';
$product_config_html .= '<p class="description">Number of domains/installs in which this license can be used. Leave blank if you wish to use the default value set in the license manager plugin settings.</p>';
$product_config_html .= '</td></tr>';

$product_config_html .= '</table></div>';

return $product_config_html;
}

function slm_estore_new_product_added($prod_dat_array, $prod_id) {
global $wpdb;
$product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME;

$fields = array();
$fields['prod_id'] = $prod_id;
$fields['meta_key'] = 'slm_max_allowed_domains';
$fields['meta_value'] = $prod_dat_array['slm_max_allowed_domains'];

$result = $wpdb->insert($product_meta_table_name, $fields);
if (!$result) {
//insert query failed
}
}

function slm_estore_product_updated($prod_dat_array, $prod_id) {
global $wpdb;
$product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME;

$slm_max_allowed_domains = $prod_dat_array['slm_max_allowed_domains'];
if (empty($slm_max_allowed_domains)) {
//If blank value was submitted then delete the data from the table
$result = $wpdb->delete($product_meta_table_name, array('prod_id' => $prod_id, 'meta_key' => 'slm_max_allowed_domains'));
return;
}

//Find the existing value for this field (for the given product)
$product_meta = $wpdb->get_row("SELECT * FROM $product_meta_table_name WHERE prod_id = '$prod_id' AND meta_key='slm_max_allowed_domains'", OBJECT);
if ($product_meta) {
//Found existing value so lets update it
$fields = array();
$fields['meta_key'] = 'slm_max_allowed_domains';
$fields['meta_value'] = $prod_dat_array['slm_max_allowed_domains'];
$result = $wpdb->update($product_meta_table_name, $fields, array('prod_id' => $prod_id));

} else {
//No value for this field was there so lets insert one.
$fields = array();
$fields['prod_id'] = $prod_id;
$fields['meta_key'] = 'slm_max_allowed_domains';
$fields['meta_value'] = $prod_dat_array['slm_max_allowed_domains'];
$result = $wpdb->insert($product_meta_table_name, $fields);
}
}

function slm_estore_product_deleted($prod_id) {
global $wpdb;
$product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME;
$result = $wpdb->delete($product_meta_table_name, array('prod_id' => $prod_id, 'meta_key' => 'slm_max_allowed_domains'));
}

/************************************/
/*** End of WP eStore integration ***/
/************************************/
2 changes: 1 addition & 1 deletion software-license-manager/menu/slm-add-licenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function wp_lic_mgr_add_licenses_menu() {

<tr valign="top">
<th scope="row">Maximum Allowed Domains</th>
<td><input name="max_allowed_domains" type="text" id="max_allowed_domains" value="<?php echo $max_domains; ?>" size="5" /><br/>Number of domains in which this license can be used.</td>
<td><input name="max_allowed_domains" type="text" id="max_allowed_domains" value="<?php echo $max_domains; ?>" size="5" /><br/>Number of domains/installs in which this license can be used.</td>
</tr>

<tr valign="top">
Expand Down
2 changes: 1 addition & 1 deletion software-license-manager/menu/slm-lic-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function wp_lic_mgr_general_settings() {
<tr valign="top">
<th scope="row">Maximum Allowed Domains</th>
<td><input type="text" name="default_max_domains" value="<?php echo $options['default_max_domains']; ?>" size="6" />
<br />Maximum number of domains which each license is valid for (default value).</td>
<br />Maximum number of domains/installs which each license is valid for (default value).</td>
</tr>

<tr valign="top">
Expand Down
5 changes: 4 additions & 1 deletion software-license-manager/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.tipsandtricks-hq.com/software-license-manager-plugin-fo
Tags: license key, serial key, manager, license, serial, key, selling, sell, license activation, manage license, software license, software license manager
Requires at least: 4.0
Tested up to: 4.7
Stable tag: 2.4
Stable tag: 2.5
License: GPLv2 or later

Create and manage license keys for your software applications easily
Expand Down Expand Up @@ -53,6 +53,9 @@ https://www.tipsandtricks-hq.com/software-license-manager-plugin-for-wordpress

== Changelog ==

= 2.5 =
- Updated the eStore plugin integration so a custom "Maximum Allowed Domains" value can be specified in the eStore product configuration.

= 2.4 =
- Added new action and filter hooks in the add/edit interface so an addon can extend the functionality of that interface.
- Added nonce check in the add/edit license interface.
Expand Down
4 changes: 2 additions & 2 deletions software-license-manager/slm_bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: Software License Manager
Version: 2.4
Version: 2.5
Plugin URI: https://www.tipsandtricks-hq.com/software-license-manager-plugin-for-wordpress
Author: Tips and Tricks HQ
Author URI: https://www.tipsandtricks-hq.com/
Expand All @@ -14,7 +14,7 @@

//Short name/slug "SLM" or "slm"

define('WP_LICENSE_MANAGER_VERSION', "2.4");
define('WP_LICENSE_MANAGER_VERSION', "2.5");
define('WP_LICENSE_MANAGER_DB_VERSION', '1.3');
define('WP_LICENSE_MANAGER_FOLDER', dirname(plugin_basename(__FILE__)));
define('WP_LICENSE_MANAGER_URL', plugins_url('',__FILE__));
Expand Down

0 comments on commit 98bb263

Please sign in to comment.