Skip to content

Commit

Permalink
added: support for item reference (now you can tag a license under pl…
Browse files Browse the repository at this point in the history
…ugins, themes, code, etc), for previous version, a default tag will be set, it is recommended to update the items in your store/or licenses and change the item-reference to match your scenario.

fixed: fix a bug where db options would get reset after applying a new update.

Signed-off-by: Michel Velis <michel@epikly.com>
  • Loading branch information
michelve committed Apr 28, 2020
1 parent 1f672fc commit a2cc6ec
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 36 deletions.
53 changes: 42 additions & 11 deletions admin/slm-add-licenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function slm_add_licenses_menu()
$reg_devices = '';
$class_hide = '';
$date_activated = '';
$lic_item_ref = '';
$current_date = (date("Y-m-d"));
$current_date_plus_1year = date('Y-m-d', strtotime('+1 year'));

Expand Down Expand Up @@ -64,6 +65,7 @@ function slm_add_licenses_menu()
$subscr_id = $record->subscr_id;
$lic_type = $record->lic_type;
$expiry_date = $record->date_expiry;
$lic_item_ref = $record->item_reference;
}
if (isset($_POST['save_record'])) {

Expand Down Expand Up @@ -97,6 +99,7 @@ function slm_add_licenses_menu()
$current_ver = $_POST['current_ver'];
$subscr_id = $_POST['subscr_id'];
$lic_type = $_POST['lic_type'];
$lic_item_ref = trim($_POST['item_reference']);


if ($_POST['lic_type'] == 'lifetime'){
Expand Down Expand Up @@ -138,6 +141,7 @@ function slm_add_licenses_menu()
$fields['current_ver'] = $current_ver;
$fields['subscr_id'] = $subscr_id;
$fields['lic_type'] = $lic_type;
$fields['item_reference'] = $lic_item_ref;


$id = isset($_POST['edit_record']) ? $_POST['edit_record'] : '';
Expand Down Expand Up @@ -343,7 +347,7 @@ function slm_add_licenses_menu()
</div>

<div class="form-group col-md-6">
<label for="email">License type</label>
<label for="lic_type">License type</label>
<select name="lic_type" class="form-control">
<option value="subscription" <?php if ($lic_type == 'subscription') {
echo 'selected="selected"';
Expand All @@ -352,15 +356,14 @@ function slm_add_licenses_menu()
echo 'selected="selected"';
} ?>> <?php _e('Life-time');?></option>
</select>

<small class="form-text text-muted"><?php _e('type of license: subscription base or lifetime');?></small>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div>


<div class="tab-pane fade show" id="userinfo" role="tabpanel" aria-labelledby="userinfo-tab">
<div class="col-full">

Expand Down Expand Up @@ -589,7 +592,7 @@ function slm_add_licenses_menu()
<small class="form-text text-muted">The unique transaction ID associated with this license key</small>
</div>

<div class="form-group col-md-6">
<div class="form-group col-md-6">
<label for="purchase_id_">Purchase Order ID #</label>
<input name="purchase_id_" class="form-control" type="text" id="purchase_id_" value="<?php echo $purchase_id_; ?>" size="8" />
<?php
Expand All @@ -602,18 +605,46 @@ function slm_add_licenses_menu()
</div>
</div>
<div class="clear"></div>

<div class="form-group">
<label for="until">Supported Until</label>
<input name="until" type="text" class="form-control" id="until" value="<?php echo $until; ?>" />
<small class="form-text text-muted">Until what version this product is supported</small>
</div>
<div class="form-group">
<div class="row">
<div class="form-group col-md-6">
<label for="until">Supported Until</label>
<input name="until" type="text" class="form-control" id="until" value="<?php echo $until; ?>" />
<small class="form-text text-muted">Until what version this product is supported</small>
</div>
<div class="form-group col-md-6">
<label for="current_ver">Current Version</label>
<input name="current_ver" type="text" class="form-control" id="current_ver" value="<?php echo $current_ver; ?>" />
<small class="form-text text-muted">What is the current version of this product</small>
</div>
<div class="clear"></div>
</div>

<?php
if ($slm_options['slm_multiple_items']==1) :
global $wpdb;
$post_meta_tbl = $wpdb->prefix . 'postmeta';
$item_ref_meta = '_license_item_reference';
$sql_prep = $wpdb->prepare("SELECT DISTINCT(meta_value) FROM $post_meta_tbl WHERE meta_key = %s", $item_ref_meta);
$values_item_refs = $wpdb->get_results($sql_prep, OBJECT);
?>
<div class="row">
<div class="form-group col-md-12">
<label for="item_reference">Item reference</label>
<select name="item_reference" class="form-control">
<?php
foreach ($values_item_refs as $item_reference) {
$sel_val = esc_attr(trim($item_reference->meta_value));
$is_selected = $lic_item_ref==$sel_val ? ' selected="selected"' : '';
echo '<option value="'. $sel_val .'"'.$is_selected.'>'.$sel_val .'</option>';
}
?>
</select>
<small class="form-text text-muted"><?php _e('Item reference of your software');?></small>
</div>
</div>
<?php endif; ?>

<div class="clear"></div>

</div>
<div class="clear"></div>
Expand Down
14 changes: 12 additions & 2 deletions admin/slm-lic-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function slm_general_settings(){
'slm_conflictmode' => isset($_POST['slm_conflictmode']) ? '1' : '',
'slm_wpestores' => isset($_POST['slm_wpestores']) ? '1' : '',
'slm_dl_manager' => isset($_POST['slm_dl_manager']) ? '1' : '',
'slm_multiple_items' => isset($_POST['slm_multiple_items']) ? '1' : '',
'expiration_reminder_text' => sanitize_text_field($_POST['expiration_reminder_text'])
);
update_option('slm_plugin_options', $options);
Expand Down Expand Up @@ -160,7 +161,7 @@ function slm_general_settings(){
<th scope="row"><?php _e('General settings', 'softwarelicensemanager'); ?></th>
<td>
<input name="slm_stats" type="checkbox" <?php if ($options['slm_stats'] != '') echo ' checked="checked"'; ?> value="1" />
<?php _e('Disable stats in licenses overview page.', 'softwarelicensemanager'); ?></td>
<?php _e('Enable stats in licenses overview page.', 'softwarelicensemanager'); ?></td>
</tr>

<tr>
Expand All @@ -170,6 +171,15 @@ function slm_general_settings(){
<?php _e('Disable stats in licenses overview page.', 'softwarelicensemanager'); ?></td>
</tr>

<tr>
<th scope="row"><?php _e('Multiple items validation', 'softwarelicensemanager'); ?></th>
<td>
<input name="slm_multiple_items" type="checkbox" <?php if ($options['slm_multiple_items'] != '') echo ' checked="checked"'; ?> value="1" />
<?php _e('Enable verification of Item reference.', 'softwarelicensemanager'); ?>
<p class="description"><?php _e("When enabled, there will be another field in Licenced product - Item reference. This field should correspond to the API parameter item_reference of your software.", 'softwarelicensemanager'); ?></p>
</td>
</tr>

<tr>
<th scope="row"></th>
<td>
Expand All @@ -195,7 +205,7 @@ function slm_general_settings(){
<th scope="row"></th>
<td>
<input name="slm_woo_downloads" type="checkbox" <?php if ($options['slm_woo_downloads'] != '') echo ' checked="checked"'; ?> value="1" />
<?php _e('Disable woocommerce download page. Proccess downloads though license order info page.', 'softwarelicensemanager'); ?></td>
<?php _e('Disable woocommerce download page. Process downloads though license order info page.', 'softwarelicensemanager'); ?></td>
</tr>
<tr valign="top">
<th scope="row"> <?php _e('Download Manager Support', 'softwarelicensemanager'); ?></th>
Expand Down
3 changes: 2 additions & 1 deletion admin/slm-list-licenses-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ function prepare_items()
}

$columns = $this->get_columns();
$hidden = array();
// $hidden = array();
$hidden = get_hidden_columns( $screen );
$sortable = $this->get_sortable_columns();

$this->_column_headers = array($columns, $hidden, $sortable);
Expand Down
29 changes: 29 additions & 0 deletions includes/class-slm-installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
$lic_log_tbl = SLM_TBL_LIC_LOG;
$lic_emails_table = SLM_TBL_EMAILS;

//***Database version check */
$used_db_version = get_option( 'slm_db_version', SLM_DB_VERSION);

$charset_collate = '';
if (!empty($wpdb->charset)){
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
Expand All @@ -38,6 +41,7 @@
first_name varchar(32) NOT NULL default '',
last_name varchar(32) NOT NULL default '',
email varchar(64) NOT NULL,
item_reference varchar(255) NOT NULL,
company_name varchar(100) NOT NULL default '',
txn_id varchar(64) NOT NULL default '',
manual_reset_count varchar(128) NOT NULL default '',
Expand All @@ -56,7 +60,24 @@
)" . $charset_collate . ";";
dbDelta($lk_tbl_sql);

// // thanks to @MechComp
if (version_compare($used_db_version, '4.1.3', '<=')) {
$lk_tbl_sql = "ALTER TABLE " . $lic_key_table . " ADD item_reference varchar(255) NOT NULL;";
dbDelta($lk_tbl_sql);
}

// set default value for reference item when they are empty
if (version_compare($used_db_version, '4.1.3', '<=')) {
// get empty values
$item_result = $wpdb->get_results("SELECT id FROM `$lic_key_table` WHERE `item_reference` LIKE '' ORDER BY id");

foreach ($item_result as $reference_item) {
$item_id = $reference_item->id;
// update and set default value
$update_reference = "UPDATE $lic_key_table SET item_reference='default' WHERE id='".$item_id."';";
dbDelta($update_reference);
}
}

$ld_tbl_sql = "CREATE TABLE " .$lic_domain_table. " (
id INT NOT NULL AUTO_INCREMENT ,
Expand Down Expand Up @@ -117,10 +138,18 @@
'slm_woo_downloads' => '',
'slm_stats' => '1',
'slm_adminbar' => '1',
'slm_multiple_items' => '',
'slm_conflictmode' => '1',
'enable_auto_key_expiration' => '1',
'slm_dl_manager' => '',
'expiration_reminder_text' => 'Your account has reverted to Basic with limited functionality. Renew today to keep using it on all of your devices and enjoy the valuable features. It’s a smart investment');

//Bugfix - Prevention of overwriting existing settings
// thanks to @MechComp
$old_options = get_option('slm_plugin_options');
if($old_options != false){
$options = array_merge($options,$old_options);
}

update_option('slm_plugin_options', $options);
update_option("slm_db_version", SLM_DB_VERSION);
18 changes: 16 additions & 2 deletions includes/slm-api-listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function creation_api_listener() {
//current_ver
$fields['subscr_id'] = isset( $_REQUEST['subscr_id'] ) ? wp_unslash( strip_tags( $_REQUEST['subscr_id'] ) ) : '';
$fields['lic_type'] = isset( $_REQUEST['lic_type'] ) ? wp_unslash( strip_tags( $_REQUEST['lic_type'] ) ) : '';
$fields['item_reference'] = isset( $_REQUEST['item_reference'] ) ? wp_unslash( strip_tags( $_REQUEST['item_reference'] ) ) : '';

global $wpdb;
$tbl_name = SLM_TBL_LICENSE_KEYS;
Expand Down Expand Up @@ -119,6 +120,7 @@ function activation_api_listener() {
if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_activate') {
//Handle the license activation API query
global $slm_debug_logger;
$options = get_option('slm_plugin_options');

SLM_API_Utility::verify_secret_key(); //Verify the secret key first.
$slm_debug_logger->log_debug("API - license activation (slm_activate) request received.");
Expand Down Expand Up @@ -153,8 +155,17 @@ function activation_api_listener() {

$key = $fields['lic_key'];

$sql_prep1 = $wpdb->prepare("SELECT * FROM $tbl_name WHERE license_key = %s", $key);
$retLic = $wpdb->get_row($sql_prep1, OBJECT);
// $sql_prep1 = $wpdb->prepare("SELECT * FROM $tbl_name WHERE license_key = %s", $key);
// $retLic = $wpdb->get_row($sql_prep1, OBJECT);

//Enable item_reference verification during activation
if ($options['slm_multiple_items']==1){
$sql_prep1 = $wpdb->prepare("SELECT * FROM $tbl_name WHERE license_key = %s AND item_reference = %s", $key, $item_reference);
$retLic = $wpdb->get_row($sql_prep1, OBJECT);
}else{
$sql_prep1 = $wpdb->prepare("SELECT * FROM $tbl_name WHERE license_key = %s", $key);
$retLic = $wpdb->get_row($sql_prep1, OBJECT);
}

$sql_prep2 = $wpdb->prepare("SELECT * FROM $reg_table WHERE lic_key = %s", $key);
$reg_domains = $wpdb->get_results($sql_prep2, OBJECT);
Expand Down Expand Up @@ -427,6 +438,7 @@ function update_api_listener(){
$fields['txn_id'] = strip_tags(sanitize_text_field($_REQUEST['txn_id']));
$fields['lic_type'] = isset($_REQUEST['lic_type']) ? wp_unslash(strip_tags(sanitize_text_field($_REQUEST['lic_type']))) : 'subscription';
$fields['lic_status'] = isset($_REQUEST['lic_status']) ? wp_unslash(strip_tags(sanitize_text_field($_REQUEST['lic_status']))) : 'active';
$fields['item_reference'] = isset( $_REQUEST['item_reference'] ) ? wp_unslash( strip_tags( $_REQUEST['item_reference'] ) ) : '';


global $wpdb;
Expand Down Expand Up @@ -510,6 +522,7 @@ function check_api_listener() {
'lic_type' => $retLic->lic_type,
'max_allowed_domains' => $retLic->max_allowed_domains,
'max_allowed_devices' => $retLic->max_allowed_devices,
'item_reference' => $retLic->item_reference,
'registered_domains' => $reg_domains,
'registered_devices' => $reg_devices,
'date_created' => $retLic->date_created,
Expand Down Expand Up @@ -585,6 +598,7 @@ function check_api_info() {
'license_key' => $retLic->license_key,
'lic_type' => $retLic->lic_type,
'max_allowed_domains' => $retLic->max_allowed_domains,
'item_reference' => $retLic->item_reference,
'max_allowed_devices' => $retLic->max_allowed_devices,
'date_created' => $retLic->date_created,
'date_renewed' => $retLic->date_renewed,
Expand Down
8 changes: 4 additions & 4 deletions software-license-manager.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: Software License Manager
Version: 5.4.1
Version: 5.4.2
Plugin URI: https://github.com/michelve/software-license-manager/
Author: Michel Velis
Author URI: https://www.epikly.com/
Expand All @@ -19,9 +19,9 @@
global $wpdb, $slm_debug_logger;

//Short name/slug "SLM" or "slm"
define('SLM_VERSION', '5.4.1');
define('SLM_DB_VERSION', '4.1.4');
define('SLM_REWRITE_VERSION', '2.3.3');
define('SLM_VERSION', '5.4.2');
define('SLM_DB_VERSION', '4.1.7');
define('SLM_REWRITE_VERSION', '2.3.5');
define('SLM_FOLDER', dirname(plugin_basename(__FILE__)));
define('SLM_URL', plugins_url('' ,__FILE__));
define('SLM_ASSETS_URL', SLM_URL . '/public/assets/');
Expand Down
Loading

0 comments on commit a2cc6ec

Please sign in to comment.