diff --git a/README.md b/README.md index fb9550a..9ed9d34 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Welcome to software license manager 👋 -![Version](https://img.shields.io/badge/version-5.5.7-blue.svg?cacheSeconds=2592000) +![Version](https://img.shields.io/badge/version-5.5.8-blue.svg?cacheSeconds=2592000) [![Documentation](https://img.shields.io/badge/documentation-yes-brightgreen.svg)](https://documenter.getpostman.com/view/307939/6tjU1FL?version=latest) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/michelve/software-license-manager/blob/master/LICENSE.md) diff --git a/admin/includes/wpestores/slm-wpestores.php b/admin/includes/wpestores/slm-wpestores.php index f06bca5..5bbb3dd 100755 --- a/admin/includes/wpestores/slm-wpestores.php +++ b/admin/includes/wpestores/slm-wpestores.php @@ -6,16 +6,17 @@ 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) { +function slm_handle_estore_email_body_filter($body, $payment_data, $cart_items) +{ global $slm_debug_logger, $wpdb; $slm_debug_logger->log_debug("WP eStore integration - checking if a license key needs to be created for this transaction."); $products_table_name = $wpdb->prefix . "wp_eStore_tbl"; $slm_data = ""; //Check if this is a recurring payment. - if ( function_exists('is_paypal_recurring_payment') ) { + if (function_exists('is_paypal_recurring_payment')) { $recurring_payment = is_paypal_recurring_payment($payment_data); - if( $recurring_payment ){ + if ($recurring_payment) { $slm_debug_logger->log_debug("This is a recurring payment. No need to create a new license key."); do_action('slm_estore_recurring_payment_received', $payment_data, $cart_items); return $body; @@ -26,7 +27,7 @@ function slm_handle_estore_email_body_filter($body, $payment_data, $cart_items) $prod_id = $current_cart_item['item_number']; $item_name = $current_cart_item['item_name']; $quantity = $current_cart_item['quantity']; - if(empty($quantity)){ + if (empty($quantity)) { $quantity = 1; } $slm_debug_logger->log_debug('License Manager - Item Number: ' . $prod_id . ', Quantity: ' . $quantity . ', Item Name: ' . $item_name); @@ -52,7 +53,8 @@ function slm_handle_estore_email_body_filter($body, $payment_data, $cart_items) return $body; } -function slm_estore_check_and_create_key_for_qty($retrieved_product, $payment_data, $cart_items, $item_name, $quantity){ +function slm_estore_check_and_create_key_for_qty($retrieved_product, $payment_data, $cart_items, $item_name, $quantity) +{ $prod_key_data = ""; for ($i = 0; $i < $quantity; $i++) { $prod_key_data .= slm_estore_check_and_generate_key($retrieved_product, $payment_data, $cart_items, $item_name); @@ -60,7 +62,8 @@ function slm_estore_check_and_create_key_for_qty($retrieved_product, $payment_da return $prod_key_data; } -function slm_estore_check_and_generate_key($retrieved_product, $payment_data, $cart_items, $item_name) { +function slm_estore_check_and_generate_key($retrieved_product, $payment_data, $cart_items, $item_name) +{ global $slm_debug_logger; $license_data = ''; @@ -74,7 +77,8 @@ function slm_estore_check_and_generate_key($retrieved_product, $payment_data, $c return $license_data; } -function slm_estore_create_license($retrieved_product, $payment_data, $cart_items, $item_name) { +function slm_estore_create_license($retrieved_product, $payment_data, $cart_items, $item_name) +{ global $slm_debug_logger; global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; @@ -98,10 +102,10 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item if ($product_meta) { //Found product specific SLM config data. $num_days_before_expiry = $product_meta->meta_value; - $slm_date_of_expiry = date('Y-m-d', strtotime('+'.$num_days_before_expiry.' days')); + $slm_date_of_expiry = wp_date('Y-m-d', strtotime('+' . $num_days_before_expiry . ' days')); } else { //Use the default value (1 year from today). - $current_date_plus_1year = date('Y-m-d', strtotime('+1 year')); + $current_date_plus_1year = wp_date('Y-m-d', strtotime('+1 year')); $slm_date_of_expiry = $current_date_plus_1year; } @@ -115,9 +119,9 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item $fields['company_name'] = $payment_data['company_name']; $fields['txn_id'] = $payment_data['txn_id']; $fields['max_allowed_domains'] = $max_domains; - $fields['date_created'] = date("Y-m-d"); //Today's date + $fields['date_created'] = wp_date("Y-m-d"); //Today's date $fields['date_expiry'] = $slm_date_of_expiry; - $fields['product_ref'] = $prod_id;//WP eStore product ID + $fields['product_ref'] = $prod_id; //WP eStore product ID $fields['subscr_id'] = isset($payment_data['subscr_id']) ? $payment_data['subscr_id'] : ''; $slm_debug_logger->log_debug('Inserting license data into the license manager DB table.'); @@ -155,7 +159,8 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item 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) { +function slm_estore_product_configuration_html($product_config_html, $prod_id) +{ global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; @@ -181,7 +186,6 @@ function slm_estore_product_configuration_html($product_config_html, $prod_id) { } else { $slm_date_of_expiry = ""; } - } $product_config_html .= '
Software License Manager Plugin (Click to Expand)
'; @@ -201,7 +205,8 @@ function slm_estore_product_configuration_html($product_config_html, $prod_id) { return $product_config_html; } -function slm_estore_new_product_added($prod_dat_array, $prod_id) { +function slm_estore_new_product_added($prod_dat_array, $prod_id) +{ global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; @@ -224,10 +229,10 @@ function slm_estore_new_product_added($prod_dat_array, $prod_id) { if (!$result) { //insert query failed } - } -function slm_estore_product_updated($prod_dat_array, $prod_id) { +function slm_estore_product_updated($prod_dat_array, $prod_id) +{ global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; @@ -240,7 +245,6 @@ function slm_estore_product_updated($prod_dat_array, $prod_id) { $meta_value = $prod_dat_array['slm_max_allowed_domains']; $update_db_qry = "UPDATE $product_meta_table_name SET meta_value='$meta_value' WHERE prod_id='$prod_id' AND meta_key='$meta_key_name'"; $results = $wpdb->query($update_db_qry); - } else { //No value for this field was there so lets insert one. $fields = array(); @@ -259,7 +263,6 @@ function slm_estore_product_updated($prod_dat_array, $prod_id) { $meta_value = $prod_dat_array['slm_date_of_expiry']; $update_db_qry = "UPDATE $product_meta_table_name SET meta_value='$meta_value' WHERE prod_id='$prod_id' AND meta_key='$meta_key_name'"; $results = $wpdb->query($update_db_qry); - } else { //No value for this field was there so lets insert one. $fields = array(); @@ -268,10 +271,10 @@ function slm_estore_product_updated($prod_dat_array, $prod_id) { $fields['meta_value'] = $prod_dat_array['slm_date_of_expiry']; $result = $wpdb->insert($product_meta_table_name, $fields); } - } -function slm_estore_product_deleted($prod_id) { +function slm_estore_product_deleted($prod_id) +{ global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; @@ -281,4 +284,4 @@ function slm_estore_product_deleted($prod_id) { /************************************/ /*** End of WP eStore integration ***/ -/************************************/ \ No newline at end of file +/************************************/ diff --git a/admin/slm-add-licenses.php b/admin/slm-add-licenses.php index 2e7b350..94f5c7a 100755 --- a/admin/slm-add-licenses.php +++ b/admin/slm-add-licenses.php @@ -32,8 +32,10 @@ function slm_add_licenses_menu() $lic_item_ref = ''; $slm_billing_length = ''; $slm_billing_interval = ''; - $current_date = (date("Y-m-d")); - $current_date_plus_1year = date('Y-m-d', strtotime('+1 year')); + //$current_date = (date("Y-m-d")); + $current_date = wp_date("Y-m-d"); + $current_time = wp_date("H:i:s"); + $current_date_plus_1year = wp_date('Y-m-d', strtotime('+1 year')); echo '
'; // echo '

Add/Edit Licenses

'; diff --git a/includes/slm-api-listener.php b/includes/slm-api-listener.php index 2e2aa9c..a6fe257 100755 --- a/includes/slm-api-listener.php +++ b/includes/slm-api-listener.php @@ -12,8 +12,10 @@ * 7) slm_info */ -class SLM_API_Listener { - function __construct() { +class SLM_API_Listener +{ + function __construct() + { if (isset($_REQUEST['slm_action']) && isset($_REQUEST['secret_key'])) { //Trigger an action hook @@ -28,7 +30,8 @@ function __construct() { } } - function creation_api_listener() { + function creation_api_listener() + { if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_create_new') { //Handle the licene creation API query global $slm_debug_logger, $wpdb; @@ -46,68 +49,61 @@ function creation_api_listener() { $fields = array(); - if (isset($_REQUEST['license_key']) && !empty($_REQUEST['license_key'])){ + if (isset($_REQUEST['license_key']) && !empty($_REQUEST['license_key'])) { $fields['license_key'] = strip_tags($_REQUEST['license_key']); //Use the key you pass via the request - } - else{ + } else { $fields['license_key'] = slm_get_license($lic_key_prefix); } - $fields['lic_status'] = isset( $_REQUEST['lic_status'] ) ? wp_unslash( strip_tags( $_REQUEST['lic_status'] ) ) : 'pending'; + $fields['lic_status'] = isset($_REQUEST['lic_status']) ? wp_unslash(strip_tags($_REQUEST['lic_status'])) : 'pending'; $fields['first_name'] = wp_unslash(strip_tags($_REQUEST['first_name'])); $fields['last_name'] = wp_unslash(strip_tags($_REQUEST['last_name'])); $fields['purchase_id_'] = wp_unslash(strip_tags($_REQUEST['purchase_id_'])); $fields['email'] = strip_tags($_REQUEST['email']); - $fields['company_name'] = isset( $_REQUEST['company_name'] ) ? wp_unslash( strip_tags( $_REQUEST['company_name'] ) ) : ''; + $fields['company_name'] = isset($_REQUEST['company_name']) ? wp_unslash(strip_tags($_REQUEST['company_name'])) : ''; $fields['txn_id'] = strip_tags($_REQUEST['txn_id']); if (empty($_REQUEST['max_allowed_domains'])) { $fields['max_allowed_domains'] = $options['default_max_domains']; - } - else { + } else { $fields['max_allowed_domains'] = strip_tags($_REQUEST['max_allowed_domains']); } if (empty($_REQUEST['max_allowed_devices'])) { $fields['max_allowed_devices'] = $options['default_max_devices']; - } - else { + } else { $fields['max_allowed_devices'] = strip_tags($_REQUEST['max_allowed_devices']); } - $fields['date_created'] = isset($_REQUEST['date_created'])?strip_tags($_REQUEST['date_created']):date("Y-m-d"); - $fields['date_expiry'] = isset($_REQUEST['date_expiry'])?strip_tags($_REQUEST['date_expiry']):''; - $fields['product_ref'] = isset( $_REQUEST['product_ref'] ) ? wp_unslash( strip_tags( $_REQUEST['product_ref'] ) ) : ''; - $fields['until'] = isset( $_REQUEST['until'] ) ? wp_unslash( strip_tags( $_REQUEST['until'] ) ) : ''; - $fields[ 'current_ver'] = isset($_REQUEST[ 'current_ver']) ? wp_unslash(strip_tags($_REQUEST[ 'current_ver'])) : ''; + $fields['date_created'] = isset($_REQUEST['date_created']) ? strip_tags($_REQUEST['date_created']) : wp_date("Y-m-d"); + $fields['date_expiry'] = isset($_REQUEST['date_expiry']) ? strip_tags($_REQUEST['date_expiry']) : ''; + $fields['product_ref'] = isset($_REQUEST['product_ref']) ? wp_unslash(strip_tags($_REQUEST['product_ref'])) : ''; + $fields['until'] = isset($_REQUEST['until']) ? wp_unslash(strip_tags($_REQUEST['until'])) : ''; + $fields['current_ver'] = isset($_REQUEST['current_ver']) ? wp_unslash(strip_tags($_REQUEST['current_ver'])) : ''; //current_ver - $fields['subscr_id'] = isset( $_REQUEST['subscr_id'] ) ? wp_unslash( strip_tags( $_REQUEST['subscr_id'] ) ) : ''; - $fields['item_reference'] = isset( $_REQUEST['item_reference'] ) ? wp_unslash( strip_tags( $_REQUEST['item_reference'] ) ) : ''; + $fields['subscr_id'] = isset($_REQUEST['subscr_id']) ? wp_unslash(strip_tags($_REQUEST['subscr_id'])) : ''; + $fields['item_reference'] = isset($_REQUEST['item_reference']) ? wp_unslash(strip_tags($_REQUEST['item_reference'])) : ''; - $fields['lic_type'] = isset( $_REQUEST['lic_type'] ) ? wp_unslash( strip_tags( $_REQUEST['lic_type'] ) ) : ''; + $fields['lic_type'] = isset($_REQUEST['lic_type']) ? wp_unslash(strip_tags($_REQUEST['lic_type'])) : ''; - $fields['slm_billing_length'] = isset( $_REQUEST['slm_billing_length'] ) ? wp_unslash( strip_tags( $_REQUEST['slm_billing_length'] ) ) : ''; - $fields['slm_billing_interval'] = isset( $_REQUEST['slm_billing_interval'] ) ? wp_unslash( strip_tags( $_REQUEST['slm_billing_interval'] ) ) : ''; + $fields['slm_billing_length'] = isset($_REQUEST['slm_billing_length']) ? wp_unslash(strip_tags($_REQUEST['slm_billing_length'])) : ''; + $fields['slm_billing_interval'] = isset($_REQUEST['slm_billing_interval']) ? wp_unslash(strip_tags($_REQUEST['slm_billing_interval'])) : ''; - if($_REQUEST['lic_type'] == 'subscription' && !isset( $_REQUEST['slm_billing_length'] )){ + if ($_REQUEST['lic_type'] == 'subscription' && !isset($_REQUEST['slm_billing_length'])) { //error inserting - $error_args = ( - array( - 'result' => 'error', - 'message' => 'License creation failed. Specify license length "slm_billing_length".', - 'error_code' => SLM_Error_Codes::CREATE_FAILED - ) - ); + $error_args = (array( + 'result' => 'error', + 'message' => 'License creation failed. Specify license length "slm_billing_length".', + 'error_code' => SLM_Error_Codes::CREATE_FAILED + )); SLM_API_Utility::output_api_response($error_args); } - if($_REQUEST['lic_type'] == 'subscription' && !isset( $_REQUEST['slm_billing_interval'] )){ + if ($_REQUEST['lic_type'] == 'subscription' && !isset($_REQUEST['slm_billing_interval'])) { //error inserting - $error_args = ( - array( - 'result' => 'error', - 'message' => 'License creation failed. Specify license length "slm_billing_interval".', - 'error_code' => SLM_Error_Codes::CREATE_FAILED - ) - ); + $error_args = (array( + 'result' => 'error', + 'message' => 'License creation failed. Specify license length "slm_billing_interval".', + 'error_code' => SLM_Error_Codes::CREATE_FAILED + )); SLM_API_Utility::output_api_response($error_args); } @@ -115,34 +111,30 @@ function creation_api_listener() { $result = $wpdb->insert($tbl_name, $fields); if ($result === false) { //error inserting - $args = ( - array( - 'result' => 'error', - 'message' => 'License creation failed', - 'error_code' => SLM_Error_Codes::CREATE_FAILED - ) - ); + $args = (array( + 'result' => 'error', + 'message' => 'License creation failed', + 'error_code' => SLM_Error_Codes::CREATE_FAILED + )); SLM_API_Utility::output_api_response($args); - } - else { - $args = ( - array( - 'result' => 'success', - 'message' => 'License successfully created', - 'key' => $fields['license_key'], - 'code' => SLM_Error_Codes::LICENSE_CREATED - ) - ); + } else { + $args = (array( + 'result' => 'success', + 'message' => 'License successfully created', + 'key' => $fields['license_key'], + 'code' => SLM_Error_Codes::LICENSE_CREATED + )); // log data global $wpdb; - SLM_Utility::create_log( $fields['license_key'], 'slm_create_new'); + SLM_Utility::create_log($fields['license_key'], 'slm_create_new'); SLM_API_Utility::output_api_response($args); } } } - function activation_api_listener() { + function activation_api_listener() + { $registered_devices = $item_reference = $registered_domain = ''; if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_activate') { @@ -184,10 +176,10 @@ function activation_api_listener() { $key = $fields['lic_key']; //Enable item_reference verification during activation - if ($options['slm_multiple_items']==1){ + 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{ + } else { $sql_prep1 = $wpdb->prepare("SELECT * FROM $tbl_name WHERE license_key = %s", $key); $retLic = $wpdb->get_row($sql_prep1, OBJECT); } @@ -202,8 +194,7 @@ function activation_api_listener() { if ($retLic->lic_status == 'blocked') { $args = (array('result' => 'error', 'message' => 'Your license key is blocked', 'error_code' => SLM_Error_Codes::LICENSE_BLOCKED)); SLM_API_Utility::output_api_response($args); - } - elseif ($retLic->lic_status == 'expired') { + } elseif ($retLic->lic_status == 'expired') { $args = (array('result' => 'error', 'message' => 'Your license key has expired', 'error_code' => SLM_Error_Codes::LICENSE_EXPIRED)); SLM_API_Utility::output_api_response($args); } @@ -215,7 +206,6 @@ function activation_api_listener() { $args = (array('result' => 'success', 'message' => 'Registered domain has been updated')); SLM_API_Utility::output_api_response($args); - } if ($fields['registered_domain'] == $reg_domain->registered_domain) { $args = (array( @@ -235,8 +225,8 @@ function activation_api_listener() { $wpdb->insert($reg_table, $fields); $slm_debug_logger->log_debug("Updating license key status to active for domain."); - $current_date = date('Y/m/d'); - $data = array('lic_status' => 'active', 'date_activated' => ''.$current_date.''); + $current_date = wp_date('Y/m/d'); + $data = array('lic_status' => 'active', 'date_activated' => '' . $current_date . ''); $where = array('id' => $retLic->id); $updated = $wpdb->update($tbl_name, $data, $where); @@ -246,26 +236,22 @@ function activation_api_listener() { // send activation email $subject = 'Your license key was activated'; - $message = ' Your license key: '.$key.' was activated successfully on '.date("F j, Y, g:i a").'.'; + $message = ' Your license key: ' . $key . ' was activated successfully on ' . wp_date("F j, Y, g:i a") . '.'; SLM_Utility::slm_send_mail($lic_email, $subject, $message, 'success'); - $args = ( - array( - 'result' => 'success', - 'icon_url' => SLM_Utility::slm_get_icon_url('1x', 'verified.png'), - 'message' => 'License key activated.', - 'registered_domain' => $_REQUEST['registered_domain'], - 'code' => SLM_Error_Codes::LICENSE_VALID, - 'item_reference' => $item_reference - ) - ); + $args = (array( + 'result' => 'success', + 'icon_url' => SLM_Utility::slm_get_icon_url('1x', 'verified.png'), + 'message' => 'License key activated.', + 'registered_domain' => $_REQUEST['registered_domain'], + 'code' => SLM_Error_Codes::LICENSE_VALID, + 'item_reference' => $item_reference + )); SLM_Utility::create_log($fields['lic_key'], 'Updating license key status to active for domain.' . $fields['registered_domain']); SLM_API_Utility::output_api_response($args); - } - - else { + } else { $args = (array('result' => 'error', 'message' => 'Reached maximum allowable domains', 'error_code' => SLM_Error_Codes::REACHED_MAX_DOMAINS)); SLM_Utility::create_log($fields['lic_key'], 'Reached maximum allowable domains'); SLM_API_Utility::output_api_response($args); @@ -280,12 +266,12 @@ function activation_api_listener() { $wpdb->update($reg_table_devices, array( 'registered_devices' => $fields['registered_devices'] ), array( - 'registered_devices' => trim(strip_tags($_REQUEST['migrate_from']) - ))); + 'registered_devices' => trim(strip_tags($_REQUEST['migrate_from'])) + )); $devices_args = (array( 'result' => 'success', - 'message' => 'Registered device has been updated') - ); + 'message' => 'Registered device has been updated' + )); SLM_API_Utility::output_api_response($devices_args); } if ($fields['registered_devices'] == $reg_devices->registered_devices) { @@ -294,8 +280,8 @@ function activation_api_listener() { 'icon_url' => SLM_Utility::slm_get_icon_url('1x', 'f-remove.png'), 'message' => 'License key already in use on ' . $reg_devices->registered_devices, 'error_code' => SLM_Error_Codes::LICENSE_IN_USE, - 'device' => $reg_devices->registered_devices) - ); + 'device' => $reg_devices->registered_devices + )); SLM_Utility::create_log($fields['lic_key'], 'License key already in use on ' . $reg_devices->registered_devices); SLM_API_Utility::output_api_response($devices_args); } @@ -305,7 +291,7 @@ function activation_api_listener() { $wpdb->insert($reg_table_devices, $fields); $slm_debug_logger->log_debug("Updating license key status to active for device."); - $current_date = date('Y/m/d'); + $current_date = wp_date('Y/m/d'); $data = array( 'lic_status' => 'active', 'date_activated' => '' . $current_date . '' @@ -318,42 +304,41 @@ function activation_api_listener() { 'registered_device' => $_REQUEST['registered_devices'], 'code' => SLM_Error_Codes::LICENSE_ACTIVATED, 'icon_url' => SLM_Utility::slm_get_icon_url('1x', 'verified.png'), - 'message' => 'Updating license key status to active for device.', )); + 'message' => 'Updating license key status to active for device.', + )); SLM_Utility::create_log($fields['lic_key'], 'Updating license key status to active for device.'); SLM_API_Utility::output_api_response($args); // send activation email $subject = 'Your license key was activated'; - $message = ' Your license key: '.$key.' was activated successfully on '.date("F j, Y, g:i a").'.'; + $message = ' Your license key: ' . $key . ' was activated successfully on ' . wp_date("F j, Y, g:i a") . '.'; SLM_Utility::slm_send_mail($lic_email, $subject, $message, 'success'); - - } - else { + } else { $args = (array( 'result' => 'error', 'icon_url' => SLM_Utility::slm_get_icon_url('1x', 'f-remove.png'), 'message' => 'Reached maximum allowable devices for this license. Please upgarde.', - 'error_code' => SLM_Error_Codes::REACHED_MAX_DEVICES) - ); + 'error_code' => SLM_Error_Codes::REACHED_MAX_DEVICES + )); SLM_Utility::create_log($fields['lic_key'], 'Reached maximum allowable devices'); SLM_API_Utility::output_api_response($args); } } - } - else { + } else { $args = (array( 'result' => 'error', 'message' => 'Invalid license key, key was not found.', - 'error_code' => SLM_Error_Codes::LICENSE_INVALID) - ); + 'error_code' => SLM_Error_Codes::LICENSE_INVALID + )); SLM_API_Utility::output_api_response($args); } } } - function deactivation_api_listener() { + function deactivation_api_listener() + { if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_deactivate') { //Handle the license deactivation API query global $slm_debug_logger; @@ -377,30 +362,28 @@ function deactivation_api_listener() { if (empty($_REQUEST['registered_domain'])) { $args = (array('result' => 'error', 'message' => 'Registered domain information is missing', 'error_code' => SLM_Error_Codes::DOMAIN_MISSING)); SLM_API_Utility::output_api_response($args); - } - else { + } else { $registered_dom_table = SLM_TBL_LIC_DOMAIN; $sql_prep = $wpdb->prepare("DELETE FROM $registered_dom_table WHERE lic_key=%s AND registered_domain=%s", $license_key, $registered_domain); $delete = $wpdb->query($sql_prep); if ($delete === false) { $slm_debug_logger->log_debug("Error - failed to delete the registered domain from the database."); - } - else if ($delete == 0) { + } else if ($delete == 0) { $args = (array( 'result' => 'error', 'message' => 'The license key on this domain is already inactive', 'error_code' => SLM_Error_Codes::DOMAIN_ALREADY_INACTIVE, - 'registered_domain' => $registered_domain->registered_domain) - ); + 'registered_domain' => $registered_domain->registered_domain + )); SLM_Utility::create_log($license_key, 'domain license deactivation request failed'); SLM_API_Utility::output_api_response($args); - } - else { + } else { $args = (array( 'result' => 'success', 'error_code' => SLM_Error_Codes::KEY_DEACTIVATE_DOMAIN_SUCCESS, - 'message' => 'The license key has been deactivated for this domain')); + 'message' => 'The license key has been deactivated for this domain' + )); SLM_Utility::create_log($license_key, 'domain license deactivation request sucess'); SLM_API_Utility::output_api_response($args); } @@ -413,21 +396,18 @@ function deactivation_api_listener() { if (empty($_REQUEST['registered_devices'])) { $args_ = (array('result' => 'error', 'message' => 'Registered device information is missing', 'error_code' => SLM_Error_Codes::DOMAIN_MISSING)); SLM_API_Utility::output_api_response($args_); - } - else { + } else { $registered_device_table = SLM_TBL_LIC_DEVICES; $sql_prep2 = $wpdb->prepare("DELETE FROM $registered_device_table WHERE lic_key=%s AND registered_devices=%s", $license_key, $registered_devices); $delete2 = $wpdb->query($sql_prep2); if ($delete2 === false) { $slm_debug_logger->log_debug("Error - failed to delete the registered device from the database."); - } - else if ($delete2 == 0) { + } else if ($delete2 == 0) { $args_ = (array('result' => 'error', 'message' => 'The license key on this device is already inactive', 'error_code' => SLM_Error_Codes::DOMAIN_ALREADY_INACTIVE)); SLM_Utility::create_log($license_key, 'device license deactivation request failed'); SLM_API_Utility::output_api_response($args_); - } - else { + } else { $args_ = (array( 'result' => 'success', 'error_code' => SLM_Error_Codes::KEY_DEACTIVATE_SUCCESS, @@ -441,7 +421,8 @@ function deactivation_api_listener() { } } - function update_api_listener(){ + function update_api_listener() + { if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_update') { //Handle the license activation API query @@ -464,7 +445,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'] ) ) : ''; + $fields['item_reference'] = isset($_REQUEST['item_reference']) ? wp_unslash(strip_tags($_REQUEST['item_reference'])) : ''; global $wpdb; @@ -502,7 +483,8 @@ function update_api_listener(){ } } - function check_api_listener() { + function check_api_listener() + { if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_check') { //Handle the license check API query global $slm_debug_logger; @@ -534,7 +516,7 @@ function check_api_listener() { if ($retLic) { //A license key exists - $args = apply_filters( 'slm_check_response_args', array( + $args = apply_filters('slm_check_response_args', array( 'result' => 'success', 'code' => SLM_Error_Codes::LICENSE_EXIST, 'message' => 'License key details retrieved.', @@ -563,22 +545,20 @@ function check_api_listener() { //Output the license details SLM_Utility::create_log($key, 'check: valid license key'); SLM_API_Utility::output_api_response($args); - } - else { - $args = ( - array( - 'result' => 'error', - 'message' => 'Invalid license key', - 'error_code' => SLM_Error_Codes::LICENSE_INVALID - ) - ); + } else { + $args = (array( + 'result' => 'error', + 'message' => 'Invalid license key', + 'error_code' => SLM_Error_Codes::LICENSE_INVALID + )); SLM_Utility::create_log($key, 'check: invalid license key'); SLM_API_Utility::output_api_response($args); } } } - function check_api_info() { + function check_api_info() + { if (isset($_REQUEST['slm_action']) && trim($_REQUEST['slm_action']) == 'slm_info') { //Handle the license check API query global $slm_debug_logger; @@ -610,7 +590,7 @@ function check_api_info() { if ($retLic) { //A license key exists - $args = apply_filters( 'slm_info_response_args', array( + $args = apply_filters('slm_info_response_args', array( 'result' => 'success', 'message' => 'License key details retrieved.', 'code' => SLM_Error_Codes::LICENSE_EXIST, @@ -638,18 +618,15 @@ function check_api_info() { //Output the license details SLM_Utility::create_log($key, 'check: valid license key'); SLM_API_Utility::output_api_response($args); - } - else { - $args = ( - array( - 'result' => 'error', - 'message' => 'Invalid license key', - 'error_code' => SLM_Error_Codes::LICENSE_INVALID - ) - ); + } else { + $args = (array( + 'result' => 'error', + 'message' => 'Invalid license key', + 'error_code' => SLM_Error_Codes::LICENSE_INVALID + )); SLM_Utility::create_log($key, 'check: invalid license key'); SLM_API_Utility::output_api_response($args); } } } -} \ No newline at end of file +} diff --git a/includes/slm-debug-logger.php b/includes/slm-debug-logger.php index 195206d..5aa0866 100755 --- a/includes/slm-debug-logger.php +++ b/includes/slm-debug-logger.php @@ -11,12 +11,13 @@ * SLM_Debug_Logger::log_debug_st("Some debug message"); */ -class SLM_Debug_Logger{ +class SLM_Debug_Logger +{ var $log_folder_path; var $default_log_file = 'log.txt'; var $default_log_file_cron = 'log-cron-job.txt'; var $debug_enabled = false; - var $debug_status = array('SUCCESS','STATUS','NOTICE','WARNING','FAILURE','CRITICAL'); + var $debug_status = array('SUCCESS', 'STATUS', 'NOTICE', 'WARNING', 'FAILURE', 'CRITICAL'); var $section_break_marker = "\n----------------------------------------------------------\n\n"; var $log_reset_marker = "-------- Log File Reset --------\n"; @@ -25,23 +26,22 @@ function __construct() $this->log_folder_path = SLM_PATH . '/logs'; //Check config and if debug is enabled then set the enabled flag to true $options = get_option('slm_plugin_options'); - if(!empty($options['enable_debug'])){//Debugging is enabled + if (!empty($options['enable_debug'])) { //Debugging is enabled $this->debug_enabled = true; } } function get_debug_timestamp() { - return '['.date('m/d/Y g:i A').'] - '; + return '[' . wp_date('m/d/Y g:i A') . '] - '; } function get_debug_status($level) { $size = count($this->debug_status); - if($level >= $size){ + if ($level >= $size) { return 'UNKNOWN'; - } - else{ + } else { return $this->debug_status[$level]; } } @@ -54,43 +54,43 @@ function get_section_break($section_break) return ""; } - function reset_log_file($file_name='') + function reset_log_file($file_name = '') { - if(empty($file_name)){ + if (empty($file_name)) { $file_name = $this->default_log_file; } - $debug_log_file = $this->log_folder_path.'/'.$file_name; - $content = $this->get_debug_timestamp().$this->log_reset_marker; - $fp=fopen($debug_log_file,'w'); + $debug_log_file = $this->log_folder_path . '/' . $file_name; + $content = $this->get_debug_timestamp() . $this->log_reset_marker; + $fp = fopen($debug_log_file, 'w'); fwrite($fp, $content); fclose($fp); } - function append_to_file($content,$file_name) + function append_to_file($content, $file_name) { - if(empty($file_name))$file_name = $this->default_log_file; - $debug_log_file = $this->log_folder_path.'/'.$file_name; - $fp=fopen($debug_log_file,'a'); + if (empty($file_name)) $file_name = $this->default_log_file; + $debug_log_file = $this->log_folder_path . '/' . $file_name; + $fp = fopen($debug_log_file, 'a'); fwrite($fp, $content); fclose($fp); } - function log_debug($message,$level=0,$section_break=false,$file_name='') + function log_debug($message, $level = 0, $section_break = false, $file_name = '') { if (!$this->debug_enabled) return; - $content = $this->get_debug_timestamp();//Timestamp - $content .= $this->get_debug_status($level);//Debug status + $content = $this->get_debug_timestamp(); //Timestamp + $content .= $this->get_debug_status($level); //Debug status $content .= ' : '; $content .= $message . "\n"; $content .= $this->get_section_break($section_break); $this->append_to_file($content, $file_name); } - function log_debug_cron($message,$level=0,$section_break=false) + function log_debug_cron($message, $level = 0, $section_break = false) { if (!$this->debug_enabled) return; - $content = $this->get_debug_timestamp();//Timestamp - $content .= $this->get_debug_status($level);//Debug status + $content = $this->get_debug_timestamp(); //Timestamp + $content .= $this->get_debug_status($level); //Debug status $content .= ' : '; $content .= $message . "\n"; $content .= $this->get_section_break($section_break); @@ -98,17 +98,16 @@ function log_debug_cron($message,$level=0,$section_break=false) $this->append_to_file($content, $this->default_log_file_cron); } - static function log_debug_st($message,$level=0,$section_break=false,$file_name='') + static function log_debug_st($message, $level = 0, $section_break = false, $file_name = '') { $options = get_option('slm_plugin_options'); - if(empty($options['enable_debug'])){//Debugging is disabled - return; + if (empty($options['enable_debug'])) { //Debugging is disabled + return; } - $content = '['.date('m/d/Y g:i A').'] - STATUS : '. $message . "\n"; + $content = '[' . wp_date('m/d/Y g:i A') . '] - STATUS : ' . $message . "\n"; $debug_log_file = SLM_PUBLIC . '/logs/log.txt'; - $fp=fopen($debug_log_file,'a'); + $fp = fopen($debug_log_file, 'a'); fwrite($fp, $content); fclose($fp); } - -} \ No newline at end of file +} diff --git a/includes/slm-plugin-core.php b/includes/slm-plugin-core.php index 5628346..7680f47 100755 --- a/includes/slm-plugin-core.php +++ b/includes/slm-plugin-core.php @@ -1,4 +1,5 @@ deactivate(); } -function slm_get_license($lic_key_prefix = ''){ - - return strtoupper($lic_key_prefix . hyphenate(md5(uniqid(rand(4, 10), true) . date( 'Y-m-d H:i:s') . time()))); - - +function slm_get_license($lic_key_prefix = '') +{ + return strtoupper($lic_key_prefix . hyphenate(md5(uniqid(rand(4, 10), true) . date('Y-m-d H:i:s') . time()))); } register_activation_hook(__FILE__, 'activate_software_license_manager'); @@ -106,11 +109,11 @@ function slm_get_license($lic_key_prefix = ''){ /** * Check if WooCommerce is activated */ - if( is_plugin_active( 'woocommerce/woocommerce.php' ) ) { - require_once( SLM_WOO . 'includes/wc_licenses_class.php'); - require_once( SLM_WOO . 'includes/wc-slm.php'); + if (is_plugin_active('woocommerce/woocommerce.php')) { + require_once(SLM_WOO . 'includes/wc_licenses_class.php'); + require_once(SLM_WOO . 'includes/wc-slm.php'); // support for meta boxes - require_once( SLM_WOO . 'includes/slm-meta-boxes.php'); + require_once(SLM_WOO . 'includes/slm-meta-boxes.php'); } // build woocommerce tabs SLM_Utility::slm_woo_build_tab(); @@ -119,7 +122,7 @@ function slm_get_license($lic_key_prefix = ''){ if (null !== SLM_Helper_Class::slm_get_option('slm_wpestores') && SLM_Helper_Class::slm_get_option('slm_wpestores') == 1) { // wpestores PLugin Integration - require_once( SLM_ADMIN . 'includes/wpestores/slm-wpestores.php'); + require_once(SLM_ADMIN . 'includes/wpestores/slm-wpestores.php'); } //Include admin side only files @@ -139,18 +142,20 @@ function slm_get_license($lic_key_prefix = ''){ $slm_debug_logger = new SLM_Debug_Logger(); //Do init time tasks -function slm_init_handler() { +function slm_init_handler() +{ $init_task = new SLM_Init_Time_Tasks(); $api_listener = new SLM_API_Listener(); } //Do plugins loaded time tasks -function slm_plugins_loaded_handler() { +function slm_plugins_loaded_handler() +{ //Runs when plugins_loaded action gets fired if (is_admin()) { //Check if db update needed if (get_option('slm_db_version') != SLM_DB_VERSION) { - require_once( SLM_LIB . 'class-slm-installer.php'); + require_once(SLM_LIB . 'class-slm-installer.php'); // TODO - $slm_activator->slm_db_install(); } } @@ -171,7 +176,8 @@ public static function get_object() } private function __construct() - { } + { + } } // initialize plugin @@ -181,51 +187,55 @@ private function __construct() //TODO - need to move this to an ajax handler file -function slm_del_reg_dom() { +function slm_del_reg_dom() +{ global $wpdb; $reg_table = SLM_TBL_LIC_DOMAIN; $id = strip_tags($_GET['id']); - $ret = $wpdb->query($wpdb->prepare( "DELETE FROM {$reg_table} WHERE id=%d", $id ) ); + $ret = $wpdb->query($wpdb->prepare("DELETE FROM {$reg_table} WHERE id=%d", $id)); echo ($ret) ? 'success' : 'failed'; exit(0); } -function slm_del_reg_devices() { +function slm_del_reg_devices() +{ global $wpdb; $reg_table = SLM_TBL_LIC_DEVICES; $id = strip_tags($_GET['id']); - $ret = $wpdb->query($wpdb->prepare( "DELETE FROM {$reg_table} WHERE id=%d", $id ) ); + $ret = $wpdb->query($wpdb->prepare("DELETE FROM {$reg_table} WHERE id=%d", $id)); echo ($ret) ? 'success' : 'failed'; exit(0); } //TODO - need to move this to an ajax handler file -function slm_remove_activation() { +function slm_remove_activation() +{ global $wpdb; $table = ''; $id = strip_tags($_GET['id']); $lic_type = strip_tags($_GET['lic_type']); - if($lic_type == 'Devices'){ + if ($lic_type == 'Devices') { $table = SLM_TBL_LIC_DEVICES; - } - else { + } else { $table = SLM_TBL_LIC_DOMAIN; } - $ret = $wpdb->query($wpdb->prepare( "DELETE FROM {$table} WHERE id=%d", $id ) ); + $ret = $wpdb->query($wpdb->prepare("DELETE FROM {$table} WHERE id=%d", $id)); echo ($ret) ? 'success' : 'failed'; exit(0); } -function wc_print_pretty($args) { +function wc_print_pretty($args) +{ echo '
';
     print_r($args);
     echo '
'; } -function wc_log($msg) { +function wc_log($msg) +{ $log = ABSPATH . DIRECTORY_SEPARATOR . 'slm_log.txt'; file_put_contents($log, $msg . ' ', FILE_APPEND); -} \ No newline at end of file +} diff --git a/includes/slm-utility.php b/includes/slm-utility.php index 60402b0..c2d2a63 100755 --- a/includes/slm-utility.php +++ b/includes/slm-utility.php @@ -16,7 +16,8 @@ function action_wp_mail_failed($wp_error) add_action('wp_mail_failed', 'action_wp_mail_failed', 10, 1); -class SLM_Helper_Class { +class SLM_Helper_Class +{ public static function slm_get_option($option) { @@ -115,20 +116,22 @@ static function insert_license_data_internal($fields) } } -class SLM_Utility { +class SLM_Utility +{ - static function check_for_expired_lic($lic_key=''){ + static function check_for_expired_lic($lic_key = '') + { global $wpdb, $first_name, $body, $date_expiry, $license_key, $expiration_reminder_text; $headers = array('Content-Type: text/html; charset=UTF-8'); $response = ''; $sql_query = $wpdb->get_results("SELECT * FROM " . SLM_TBL_LICENSE_KEYS . " WHERE date_expiry < NOW() AND NOT date_expiry='00000000' ORDER BY date_expiry ASC;", ARRAY_A); $subject = get_bloginfo('name') . ' - Your license has expired'; - $expiration_reminder_text = SLM_Helper_Class::slm_get_option( 'expiration_reminder_text'); + $expiration_reminder_text = SLM_Helper_Class::slm_get_option('expiration_reminder_text'); //SLM_Helper_Class::write_log('Found: ' . $expiration_reminder_text); - if (count( $sql_query) > 0) { + if (count($sql_query) > 0) { foreach ($sql_query as $expired_licenses) { @@ -143,11 +146,11 @@ static function check_for_expired_lic($lic_key=''){ $date_expiry = $expired_licenses['date_expiry']; - if(SLM_Helper_Class::slm_get_option('enable_auto_key_expiration') == 1 ){ + if (SLM_Helper_Class::slm_get_option('enable_auto_key_expiration') == 1) { global $wpdb; $data = array('lic_status' => 'expired'); $where = array('id' => $id); - $updated = $wpdb->update(SLM_TBL_LICENSE_KEYS , $data, $where); + $updated = $wpdb->update(SLM_TBL_LICENSE_KEYS, $data, $where); self::create_log($license_key, 'set to expired'); @@ -160,8 +163,7 @@ static function check_for_expired_lic($lic_key=''){ $response = 'Reminder message was sent to: ' . $license_key; //SLM_Helper_Class::write_log($response); } - } - else { + } else { SLM_Helper_Class::write_log('array is empty'); $response = 'array is empty'; } @@ -179,41 +181,40 @@ static function slm_check_sent_emails($license_key, $email, $subject, $body, $he if ($license["lic_key"] != $license_key) { // TODO: use mail class from include wp_mail($email, $subject, $body, $headers); - self::create_email_log($license_key, $email, 'success', 'yes', date("Y/m/d")); + self::create_email_log($license_key, $email, 'success', 'yes', wp_date("Y/m/d")); return '200'; //reminder was never sent before, first time (record does not exist) - } - else { + } else { //reminder was sent before return '400'; } } - } - else { + } else { // array or results are empty (lic key was not found) // TODO: use mail class from include wp_mail($email, $subject, $body, $headers); - self::create_email_log($license_key, $email, 'success', 'yes', date("Y/m/d")); + self::create_email_log($license_key, $email, 'success', 'yes', wp_date("Y/m/d")); return '300'; } } - static function do_auto_key_expiry() { + static function do_auto_key_expiry() + { global $wpdb; - $current_date = (date ("Y-m-d")); + $current_date = wp_date("Y-m-d"); $tbl_name = SLM_TBL_LICENSE_KEYS; - $sql_prep = $wpdb->prepare("SELECT * FROM $tbl_name WHERE lic_status !=%s", 'expired');//Load the non-expired keys + $sql_prep = $wpdb->prepare("SELECT * FROM $tbl_name WHERE lic_status !=%s", 'expired'); //Load the non-expired keys $licenses = $wpdb->get_results($sql_prep, OBJECT); - if(!$licenses){ + if (!$licenses) { SLM_Debug_Logger::log_debug_st("do_auto_key_expiry() - no license keys found."); return false; } - foreach($licenses as $license){ + foreach ($licenses as $license) { $key = $license->license_key; $expiry_date = $license->date_expiry; - if ($expiry_date == '0000-00-00' || $expiry_date == '00000000' || $expiry_date == ''){ - SLM_Debug_Logger::log_debug_st("This key (".$key.") doesn't have a valid expiration date set. The expiration of this key will not be checked."); + if ($expiry_date == '0000-00-00' || $expiry_date == '00000000' || $expiry_date == '') { + SLM_Debug_Logger::log_debug_st("This key (" . $key . ") doesn't have a valid expiration date set. The expiration of this key will not be checked."); continue; } @@ -222,24 +223,25 @@ static function do_auto_key_expiry() { if ($today_dt > $expire_dt) { //This key has reached the expiry. So expire this key. - SLM_Debug_Logger::log_debug_st("This key (".$key.") has expired. Expiry date: ".$expiry_date.". Setting license key status to expired."); + SLM_Debug_Logger::log_debug_st("This key (" . $key . ") has expired. Expiry date: " . $expiry_date . ". Setting license key status to expired."); $data = array('lic_status' => 'expired'); $where = array('id' => $license->id); $updated = $wpdb->update($tbl_name, $data, $where); - do_action('slm_license_key_expired',$license->id); - self::check_for_expired_lic( $key); + do_action('slm_license_key_expired', $license->id); + self::check_for_expired_lic($key); } - } } - static function get_user_info($by, $value) { - $user = get_user_by( $by, $value); - return $user; + static function get_user_info($by, $value) + { + $user = get_user_by($by, $value); + return $user; } - static function get_days_remaining( $date1 ){ + static function get_days_remaining($date1) + { $future = strtotime($date1); $now = time(); @@ -251,7 +253,8 @@ static function get_days_remaining( $date1 ){ /* * Deletes a license key from the licenses table */ - static function delete_license_key_by_row_id($key_row_id) { + static function delete_license_key_by_row_id($key_row_id) + { global $wpdb; $license_table = SLM_TBL_LICENSE_KEYS; @@ -259,11 +262,11 @@ static function delete_license_key_by_row_id($key_row_id) { SLM_Utility::delete_registered_domains_of_key($key_row_id); //Now, delete the key from the licenses table. - $wpdb->delete( $license_table, array( 'id' => $key_row_id ) ); - + $wpdb->delete($license_table, array('id' => $key_row_id)); } - static function slm_get_lic_email($license) { + static function slm_get_lic_email($license) + { // DOC: https://www.smashingmagazine.com/2011/09/interacting-with-the-wordpress-database/ global $wpdb; $lic_key_table = SLM_TBL_LICENSE_KEYS; @@ -271,42 +274,45 @@ static function slm_get_lic_email($license) { return $email; } - static function slm_send_mail($to, $subject, $message, $bgcolor) { + static function slm_send_mail($to, $subject, $message, $bgcolor) + { // send activation email - $headers[] = 'From: '.get_bloginfo('name').' <'.get_bloginfo('admin_email').'>'; + $headers[] = 'From: ' . get_bloginfo('name') . ' <' . get_bloginfo('admin_email') . '>'; $headers[] = 'Content-Type: text/html; charset=UTF-8'; $body = self::slm_email_template($message, $bgcolor); wp_mail($to, $subject, $body, $headers); } - static function slm_email_template($message, $bgcolor = ''){ - if ($bgcolor == 'success'){ + static function slm_email_template($message, $bgcolor = '') + { + if ($bgcolor == 'success') { $color = '#eceff0'; } - if (empty($bgcolor)){ + if (empty($bgcolor)) { $color = '#eceff0'; } - if ($bgcolor == 'error'){ + if ($bgcolor == 'error') { $color = '#e23b2f'; } - $template = ' Epikly



License key was activated successfully !

'.$message.'

Regards,

'.get_bloginfo( 'name' ).'
'.get_bloginfo( 'admin_email' ).'

'; + $template = ' Epikly



License key was activated successfully !

' . $message . '

Regards,

' . get_bloginfo('name') . '
' . get_bloginfo('admin_email') . '

'; return $template; - } - static function count_licenses($status){ + static function count_licenses($status) + { global $wpdb; $license_table = SLM_TBL_LICENSE_KEYS; $get_lic_status = $wpdb->get_var("SELECT COUNT(*) FROM $license_table WHERE lic_status = '" . $status . "'"); return $get_lic_status; } - static function slm_get_icon_url($size, $filename){ - return SLM_ASSETS_URL . 'icons/' . $size . '/' .$filename; + static function slm_get_icon_url($size, $filename) + { + return SLM_ASSETS_URL . 'icons/' . $size . '/' . $filename; } static function count_logrequest() @@ -333,29 +339,32 @@ static function getstats_licenses($date_created, $interval) return $query; } - static function get_total_licenses(){ + static function get_total_licenses() + { global $wpdb; $license_table = SLM_TBL_LICENSE_KEYS; $license_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $license_table . ""); return $license_count; } - static function get_lic_expiringsoon(){ + static function get_lic_expiringsoon() + { global $wpdb; $license_table = SLM_TBL_LICENSE_KEYS; $license_count = $wpdb->get_var("SELECT COUNT(*) FROM $license_table WHERE date_expiry BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 1 MONTH ) AND DATE_SUB( CURDATE( ) ,INTERVAL 0 MONTH );"); return $license_count; } - static function block_license_key_by_row_id($key_row_id){ + static function block_license_key_by_row_id($key_row_id) + { global $wpdb; $license_table = SLM_TBL_LICENSE_KEYS; //Now, delete the key from the licenses table. - $wpdb->update( $license_table, array('lic_status' => 'blocked'), array('id' => $key_row_id)); - + $wpdb->update($license_table, array('lic_status' => 'blocked'), array('id' => $key_row_id)); } - static function expire_license_key_by_row_id($key_row_id){ + static function expire_license_key_by_row_id($key_row_id) + { global $wpdb; $license_table = SLM_TBL_LICENSE_KEYS; @@ -367,7 +376,7 @@ static function active_license_key_by_row_id($key_row_id) { global $wpdb; $license_table = SLM_TBL_LICENSE_KEYS; - $current_date = date('Y/m/d'); + $current_date = wp_date('Y/m/d'); // 'lic_status' => ''. $current_date.'' $wpdb->update($license_table, array('lic_status' => 'active'), array('id' => $key_row_id)); @@ -377,7 +386,8 @@ static function active_license_key_by_row_id($key_row_id) /* * Deletes any registered domains info from the domain table for the given key's row id. */ - static function delete_registered_domains_of_key($key_row_id) { + static function delete_registered_domains_of_key($key_row_id) + { global $slm_debug_logger; global $wpdb; $reg_table = SLM_TBL_LIC_DOMAIN; @@ -385,17 +395,19 @@ static function delete_registered_domains_of_key($key_row_id) { $reg_domains = $wpdb->get_results($sql_prep, OBJECT); foreach ($reg_domains as $domain) { $row_to_delete = $domain->id; - $wpdb->delete( $reg_table, array( 'id' => $row_to_delete ) ); - $slm_debug_logger->log_debug("Registered domain with row id (".$row_to_delete.") deleted."); + $wpdb->delete($reg_table, array('id' => $row_to_delete)); + $slm_debug_logger->log_debug("Registered domain with row id (" . $row_to_delete . ") deleted."); } } - static function create_secret_keys() { + static function create_secret_keys() + { $key = strtoupper(implode('-', str_split(substr(strtolower(md5(microtime() . rand(1000, 9999))), 0, 32), 8))); return hash('sha256', $key); } - static function create_log($license_key, $action){ + static function create_log($license_key, $action) + { global $wpdb; $slm_log_table = SLM_TBL_LIC_LOG; $origin = ''; @@ -411,12 +423,11 @@ static function create_log($license_key, $action){ $log_data = array( 'license_key' => $license_key, 'slm_action' => $action, - 'time' => date("Y/m/d"), + 'time' => wp_date("Y/m/d"), 'source' => $origin ); - $wpdb->insert( $slm_log_table, $log_data ); - + $wpdb->insert($slm_log_table, $log_data); } static function create_email_log($lic_key, $sent_to, $status, $sent, $date_sent) @@ -433,10 +444,11 @@ static function create_email_log($lic_key, $sent_to, $status, $sent, $date_sent) ); $wpdb->insert($slm_email_table, $log_data); - SLM_Helper_Class::write_log('email log created for '. $lic_key); + SLM_Helper_Class::write_log('email log created for ' . $lic_key); } - static function slm_wp_dashboards_stats($amount){ + static function slm_wp_dashboards_stats($amount) + { global $wpdb; $slm_log_table = SLM_TBL_LICENSE_KEYS; @@ -445,14 +457,15 @@ static function slm_wp_dashboards_stats($amount){ foreach ($result as $license) { echo ' - '. $license->first_name . ' ' .$license->last_name .'
+ ' . $license->first_name . ' ' . $license->last_name . '
' . $license->license_key . ' '; } } - static function slm_get_licinfo ($api_action, $license_key){ - $api_url = get_site_url() . '/?secret_key=' . SLM_Helper_Class::slm_get_option('lic_verification_secret') . '&slm_action='.$api_action.'&license_key='.$license_key; + static function slm_get_licinfo($api_action, $license_key) + { + $api_url = get_site_url() . '/?secret_key=' . SLM_Helper_Class::slm_get_option('lic_verification_secret') . '&slm_action=' . $api_action . '&license_key=' . $license_key; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $api_url, @@ -470,7 +483,8 @@ static function slm_get_licinfo ($api_action, $license_key){ return $json; } - static function get_subscriber_licenses(){ + static function get_subscriber_licenses() + { global $wpdb; $email = $_GET['email']; $manage_subscriber = $_GET['manage_subscriber']; @@ -492,21 +506,22 @@ static function get_subscriber_licenses(){ } } - static function get_lic_activity($license_key){ + static function get_lic_activity($license_key) + { global $wpdb; $slm_log_table = SLM_TBL_LIC_LOG; echo '
'; - $activity = $wpdb->get_results( "SELECT * FROM " . $slm_log_table . " WHERE license_key='" . $license_key."';"); + $activity = $wpdb->get_results("SELECT * FROM " . $slm_log_table . " WHERE license_key='" . $license_key . "';"); foreach ($activity as $log) { echo ' ' . - '' . - ' + '' . + ''; } echo ' @@ -515,8 +530,9 @@ static function get_lic_activity($license_key){ '; } - static function get_license_activation($license_key, $tablename, $item_name, $allow_removal = true) { - ?> + static function get_license_activation($license_key, $tablename, $item_name, $allow_removal = true) + { +?>
-
- registered_devices .'" aria-label="' .$activation->registered_devices .'" aria-describedby="' .$activation->registered_devices .'" value="' .$activation->registered_devices .'" readonly>'; +
+ registered_devices . '" aria-label="' . $activation->registered_devices . '" aria-describedby="' . $activation->registered_devices . '" value="' . $activation->registered_devices . '" readonly>'; + } else { + echo ''; } - else { - echo ''; - } - ?> - -
- + ?> + +
+ +
+
- -
@@ -555,20 +570,22 @@ static function get_license_activation($license_key, $tablename, $item_name, $al Not registered yet
'; ?>
- is_type( 'slm_license' ) ) { + if ($product->is_type('slm_license')) { $tabs['shipping'] = array( - 'title' => __( 'License information', 'softwarelicensemanager' ), + 'title' => __('License information', 'softwarelicensemanager'), 'priority' => 50, 'callback' => 'slm_woo_tab_lic_info' ); @@ -576,14 +593,15 @@ function slm_woo_product_tab( $tabs ) { return $tabs; } - function slm_woo_tab_lic_info() { + function slm_woo_tab_lic_info() + { global $product; - // The new tab content - echo '

License information

'; - echo 'License type: ' . get_post_meta($product->get_id(), '_license_type', true ) . '
'; - echo 'Domains allowed: ' . get_post_meta($product->get_id(), '_domain_licenses', true ) . '
'; - echo 'Devices allowed: ' . get_post_meta($product->get_id(), '_devices_licenses', true ) . '
'; - echo 'Renews every ' . get_post_meta($product->get_id(), '_license_renewal_period', true ) . ' ' . get_post_meta($product->get_id(), '_license_renewal_period_term', true ) . '
'; + // The new tab content + echo '

License information

'; + echo 'License type: ' . get_post_meta($product->get_id(), '_license_type', true) . '
'; + echo 'Domains allowed: ' . get_post_meta($product->get_id(), '_domain_licenses', true) . '
'; + echo 'Devices allowed: ' . get_post_meta($product->get_id(), '_devices_licenses', true) . '
'; + echo 'Renews every ' . get_post_meta($product->get_id(), '_license_renewal_period', true) . ' ' . get_post_meta($product->get_id(), '_license_renewal_period_term', true) . '
'; } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 319f3d2..c324cc6 100644 --- a/package.json +++ b/package.json @@ -1,45 +1,45 @@ { - "name": "software-license-manager", - "version": "5.5.6", - "description": "Software license management solution for your web applications (WordPress plugins, Themes, Applications, PHP based membership script etc.). Supports WooCommerce.", - "scripts": { - "changelog": "auto-changelog -p && git add CHANGELOG.md" - }, - "auto-changelog": { - "output": "CHANGELOG.md", - "template": "keepachangelog", - "issueUrl": "https://github.com/michelve/software-license-manager/issues/{id}", - "unreleased": true, - "commitLimit": false, - "includeBranch": [ - "release-v2", - "release-v3" - ] - }, - "repository": { - "type": "git", - "url": "git+https://michelve@github.com/michelve/software-license-manager.git" - }, - "keywords": [ - "software", - "license", - "license", - "license", - "manager", - "wordpress", - "license", - "manager", - "slm", - "woocommerce", - "lcienses" - ], - "author": "Michel Velis and Tips and Tricks HQ", - "license": "MIT", - "bugs": { - "url": "https://github.com/michelve/software-license-manager/issues" - }, - "homepage": "https://github.com/michelve/software-license-manager#readme", - "devDependencies": { - "auto-changelog": "^1.14.1" - } + "name": "software-license-manager", + "version": "5.5.8", + "description": "Software license management solution for your web applications (WordPress plugins, Themes, Applications, PHP based membership script etc.). Supports WooCommerce.", + "scripts": { + "changelog": "auto-changelog -p && git add CHANGELOG.md" + }, + "auto-changelog": { + "output": "CHANGELOG.md", + "template": "keepachangelog", + "issueUrl": "https://github.com/michelve/software-license-manager/issues/{id}", + "unreleased": true, + "commitLimit": false, + "includeBranch": [ + "release-v2", + "release-v3" + ] + }, + "repository": { + "type": "git", + "url": "git+https://michelve@github.com/michelve/software-license-manager.git" + }, + "keywords": [ + "software", + "license", + "license", + "license", + "manager", + "wordpress", + "license", + "manager", + "slm", + "woocommerce", + "lcienses" + ], + "author": "Michel Velis and Tips and Tricks HQ", + "license": "MIT", + "bugs": { + "url": "https://github.com/michelve/software-license-manager/issues" + }, + "homepage": "https://github.com/michelve/software-license-manager#readme", + "devDependencies": { + "auto-changelog": "^1.14.1" + } } diff --git a/readme.txt b/readme.txt index c14d376..243e24b 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: http://paypal.me/mvelis Tags: license, software license Requires at least: 4.1 Tested up to: 5.7 -Stable tag: 5.5.7 +Stable tag: 5.5.8 Requires PHP: 5.2.4 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html diff --git a/software-license-manager.php b/software-license-manager.php index 0bc4c17..2d74605 100755 --- a/software-license-manager.php +++ b/software-license-manager.php @@ -1,7 +1,7 @@ Tips and Tricks HQ Text Domain: softwarelicensemanager Domain Path: /i18n/languages/ -WC tested up to: 4.2.1 +WC tested up to: 4.3.0 */ // If this file is called directly, abort. @@ -19,9 +19,9 @@ global $wpdb, $slm_debug_logger; //Short name/slug "SLM" or "slm" -define('SLM_VERSION', '5.5.7'); -define('SLM_DB_VERSION', '4.2.9'); -define('SLM_REWRITE_VERSION', '2.4.0'); +define('SLM_VERSION', '5.5.8'); +define('SLM_DB_VERSION', '4.3.0'); +define('SLM_REWRITE_VERSION', '2.4.1'); define('SLM_FOLDER', dirname(plugin_basename(__FILE__))); define('SLM_URL', plugins_url('', __FILE__)); define('SLM_ASSETS_URL', SLM_URL . '/public/assets/');
ID Request
' . $log->id . ' ' . $log->slm_action . '' . - '

Source: ' . $log->source . - '

Time: ' . $log->time . '

' . $log->id . ' ' . $log->slm_action . '' . + '

Source: ' . $log->source . + '

Time: ' . $log->time . '