From 620bf33369fc83876c64a149cd9604c240e93158 Mon Sep 17 00:00:00 2001 From: Michel Velis Date: Sun, 2 Dec 2018 18:33:40 -0500 Subject: [PATCH] version 4.4 release --- .../includes/subscriptio/slm-subscriptio.php | 6 +- .../woocommerce/includes/purchase.php | 324 ++++++++++------- .../wc-software-license-manager.php | 17 +- .../includes/wpestores/slm-wpestores.php | 1 + .../admin/slm-add-licenses.php | 67 ++-- .../admin/slm-admin-init.php | 2 +- .../admin/slm-lic-settings.php | 8 +- ...ass-software-license-manager-activator.php | 5 +- ...s-software-license-manager-deactivator.php | 5 +- ...software-license-manager-slm-installer.php | 2 + .../includes/slm-api-listener.php | 50 ++- .../includes/slm-meta-boxes.php | 333 +++++++----------- .../includes/slm_plugin_core.php | 66 ++-- .../public/assets/images/slm_logo_small.svg | 16 +- .../software-license-manager.php | 6 +- 15 files changed, 480 insertions(+), 428 deletions(-) diff --git a/software-license-manager/admin/includes/subscriptio/slm-subscriptio.php b/software-license-manager/admin/includes/subscriptio/slm-subscriptio.php index 90644f9..9164850 100755 --- a/software-license-manager/admin/includes/subscriptio/slm-subscriptio.php +++ b/software-license-manager/admin/includes/subscriptio/slm-subscriptio.php @@ -19,9 +19,9 @@ function subscriptio_check_status( $schedules ) { } // Schedule an action if it's not already scheduled -if ( ! wp_next_scheduled( 'subscriptio_check_status' ) ) { - wp_schedule_event( time(), 'subcriptio_interval_check', 'subscriptio_check_status' ); -} +// if ( ! wp_next_scheduled( 'subscriptio_check_status' ) ) { +// wp_schedule_event( time(), 'subcriptio_interval_check', 'subscriptio_check_status' ); +// } // Hook into that action that'll fire every three minutes add_action( 'subscriptio_check_status', 'subcriptio_interval_check_event_func' ); diff --git a/software-license-manager/admin/includes/woocommerce/includes/purchase.php b/software-license-manager/admin/includes/woocommerce/includes/purchase.php index 8fe95b9..8e0e2ee 100755 --- a/software-license-manager/admin/includes/woocommerce/includes/purchase.php +++ b/software-license-manager/admin/includes/woocommerce/includes/purchase.php @@ -16,14 +16,36 @@ global $post, $woocommerce, $product; +if ( ! function_exists( 'write_log' ) ) { + /** + * Write in the log. + * + * @since 1.0.0 + * + * @param mixed $log The content to log. + */ + function write_log( $log ) { + if ( true === WP_DEBUG ) { + if ( is_array( $log ) || is_object( $log ) ) { + error_log( print_r( $log, true ) ); + } else { + error_log( $log ); + } + } + } +} + + add_action('woocommerce_order_status_completed', 'wc_slm_on_complete_purchase', 10); function wc_slm_on_complete_purchase($order_id) { + //write_log('loading wc_slm_on_complete_purchase'); if (WOO_SLM_API_URL != '' && WOO_SLM_API_SECRET != '') { wc_slm_create_license_keys($order_id); } } + /** * Create license key * @@ -32,131 +54,154 @@ function wc_slm_on_complete_purchase($order_id) { */ function wc_slm_create_license_keys($order_id) { - $_order = new WC_Order($order_id); - $order_id = new WC_Order( $order_id ); + // write_log('loading wc_slm_create_license_keys'); + + $order_id = new WC_Order( $order_id ); + $purchase_id_ = $order_id->get_id(); + + // write_log('purchase_id_ -- '.$purchase_id_ ); + // write_log('purchase_id_ -- '.$user_id ); - global $purchase_id; - $purchase_id_ = $order_id->id; - $user_id = $_order->get_user_id(); - $user_info = get_userdata($user_id); - $get_user_meta = get_user_meta($user_id); - $payment_meta['user_info']['first_name'] = $get_user_meta['billing_first_name'][0]; - $payment_meta['user_info']['last_name'] = $get_user_meta['billing_last_name'][0]; - $payment_meta['user_info']['email'] = $get_user_meta['billing_email'][0]; - $payment_meta['user_info']['company'] = $get_user_meta['billing_company'][0]; + global $user_id; + + $user_id = $order_id->get_user_id(); + $user_info = get_userdata($user_id); + $get_user_meta = get_user_meta($user_id); + $payment_meta['user_info']['first_name'] = $get_user_meta['billing_first_name'][0]; + $payment_meta['user_info']['last_name'] = $get_user_meta['billing_last_name'][0]; + $payment_meta['user_info']['email'] = $get_user_meta['billing_email'][0]; + $payment_meta['user_info']['company'] = $get_user_meta['billing_company'][0]; + + // write_log('user_id -- '.$user_id ); // Collect license keys $licenses = array(); - $items = $_order->get_items(); + $items = $order_id->get_items(); + + //write_log($items); foreach ($items as $item => $values) { $download_id = $product_id = $values['product_id']; $product = new WC_Product($product_id); - $variation_id = new WC_Product_Variation($product_id); - - //if ($product->is_downloadable() && $product->has_file()) { - - $download_quantity = absint($values['qty']); - for ($i = 1; $i <= $download_quantity; $i++) { - /** - * Calculate Expire date - * @since 1.0.3 - */ - $renewal_period = (int) wc_slm_get_licensing_renewal_period($product_id); - - if ($renewal_period == 0) { - $renewal_period = '0000-00-00'; - } - else { - $renewal_period = date('Y-m-d', strtotime('+' . $renewal_period . ' years')); - } - // Sites allowed get license meta from variation - $sites_allowed = wc_slm_get_sites_allowed($product_id); - $amount_of_licenses = wc_slm_get_licenses_qty($product_id); - - if (!$sites_allowed) { - $sites_allowed_error = __('License could not be created: Invalid sites allowed number.', 'wc-slm'); - $int = wc_insert_payment_note($order_id, $sites_allowed_error); - break; - } - - // Get an instance of the WC_Order object (same as before) - $order = wc_get_order( $order_id ); - // Get the order ID - $order_id = $order->get_id(); - // Get the custumer ID - $order_id = $order->get_user_id(); - $order_data = $order->get_data(); // The Order data - - // Iterating through each WC_Order_Item objects - foreach( $order-> get_items() as $item_key => $item_values ){ - - ## Using WC_Order_Item methods ## - $item_id = $item_values->get_id(); - $item_name = $item_values->get_name(); - $item_type = $item_values->get_type(); - - ## Access Order Items data properties (in an array of values) ## - $item_data = $item_values->get_data(); - $product_name = $item_data['name']; - $product_id = $item_data['product_id']; - $variation_id = $item_data['variation_id']; - $quantity = $item_data['quantity']; - $tax_class = $item_data['tax_class']; - $line_subtotal = $item_data['subtotal']; - $line_subtotal_tax = $item_data['subtotal_tax']; - $line_total = $item_data['total']; - $line_total_tax = $item_data['total_tax']; - $post_object = get_post($variation_id); - $amount_of_licenses = get_post_meta( $post_object->ID, 'amount_of_licenses', true); - $amount_of_licenses_devices = get_post_meta( $post_object->ID, 'amount_of_licenses_devices', true); - } - - // Transaction id - $transaction_id = wc_get_payment_transaction_id($product_id); - - // Build item name - $item_name = $product->get_title(); - - // Build parameters - $api_params = array(); - $api_params['slm_action'] = 'slm_create_new'; - $api_params['secret_key'] = KEY_API; - $api_params['first_name'] = (isset($payment_meta['user_info']['first_name'])) ? $payment_meta['user_info']['first_name'] : ''; - $api_params['last_name'] = (isset($payment_meta['user_info']['last_name'])) ? $payment_meta['user_info']['last_name'] : ''; - $api_params['email'] = (isset($payment_meta['user_info']['email'])) ? $payment_meta['user_info']['email'] : ''; - $api_params['company_name'] = $payment_meta['user_info']['company']; - $api_params['purchase_id_'] = $purchase_id_; - $api_params['product_ref'] = $product_id; // TODO: get product id - $api_params['txn_id'] = $purchase_id_; - $api_params['max_allowed_domains'] = $amount_of_licenses; - $api_params['max_allowed_devices'] = $amount_of_licenses_devices; - $api_params['date_created'] = date('Y-m-d'); - $api_params['date_expiry'] = $renewal_period; - - // Send query to the license manager server - $url = 'http://' . WOO_SLM_API_URL . '?' . http_build_query($api_params); - $url = str_replace(array('http://', 'https://'), '', $url); - $url = 'http://' . $url; - $response = wp_remote_get($url, array('timeout' => 20, 'sslverify' => false)); - $license_key = wc_slm_get_license_key($response); - - // Collect license keys - if ($license_key) { - $licenses[] = array( - 'item' => $item_name, - 'key' => $license_key, - 'expires' => $renewal_period, - ); - } + // $variation_id = new WC_Product_Variation($product_id); + + //if ($product->is_downloadable('yes')) { + + $download_quantity = absint($values['qty']); + for ($i = 1; $i <= $download_quantity; $i++) { + /** + * Calculate Expire date + * @since 1.0.3 + */ + $renewal_period = (int) wc_slm_get_licensing_renewal_period($product_id); + + if ($renewal_period == 0) { + $renewal_period = '0000-00-00'; + } + else { + $renewal_period = date('Y-m-d', strtotime('+' . $renewal_period . ' years')); } - } - //wc_slm_print_pretty($payment_meta); + //write_log('renewal_period -- '.$renewal_period ); - // Payment note + // Sites allowed get license meta from variation + $sites_allowed = wc_slm_get_sites_allowed($product_id); + $devices_allowed = wc_slm_get_devices_allowed($product_id); + $amount_of_licenses = wc_slm_get_licenses_qty($product_id); + + if (!$sites_allowed) { + $sites_allowed_error = __('License could not be created: Invalid sites allowed number.', 'wc-slm'); + $int = wc_insert_payment_note($purchase_id_, $sites_allowed_error); + break; + } + + // Get an instance of the WC_Order object (same as before) + $order = new WC_Order( $order_id ); + + // Get the order ID + $order_id = $order->get_id(); + + // Get the custumer ID + // $user_id = $order->get_user_id(); + $order_data = $order->get_data(); // The Order data + + // Iterating through each WC_Order_Item objects + foreach( $order-> get_items() as $item_key => $item_values ){ + + ## Using WC_Order_Item methods ## + $item_id = $item_values->get_id(); + $item_name = $item_values->get_name(); + $item_type = $item_values->get_type(); + + ## Access Order Items data properties (in an array of values) ## + $item_data = $item_values->get_data(); + $product_name = $item_data['name']; + $product_id = $item_data['product_id']; + // $variation_id = $item_data['variation_id']; + $quantity = $item_data['quantity']; + $tax_class = $item_data['tax_class']; + $line_subtotal = $item_data['subtotal']; + $line_subtotal_tax = $item_data['subtotal_tax']; + $line_total = $item_data['total']; + $line_total_tax = $item_data['total_tax']; + // $post_object = get_post($variation_id); + + $amount_of_licenses = wc_slm_get_sites_allowed($product_id);; + $_license_current_version = get_post_meta( $product_id, '_license_current_version', true ); + $amount_of_licenses_devices = wc_slm_get_devices_allowed($product_id); + $current_version = (int)get_post_meta( $product_id, '_license_current_version', true); + $license_type = get_post_meta( $product_id, '_license_type', true ); + } + + // Transaction id + $transaction_id = wc_get_payment_transaction_id($product_id); + + // Build item name + $item_name = $product->get_title(); + + // Build parameters + $api_params = array(); + $api_params['slm_action'] = 'slm_create_new'; + $api_params['secret_key'] = KEY_API; + $api_params['first_name'] = (isset($payment_meta['user_info']['first_name'])) ? $payment_meta['user_info']['first_name'] : ''; + $api_params['last_name'] = (isset($payment_meta['user_info']['last_name'])) ? $payment_meta['user_info']['last_name'] : ''; + $api_params['email'] = (isset($payment_meta['user_info']['email'])) ? $payment_meta['user_info']['email'] : ''; + $api_params['company_name'] = $payment_meta['user_info']['company']; + $api_params['purchase_id_'] = $purchase_id_; + $api_params['product_ref'] = $product_id; // TODO: get product id + $api_params['txn_id'] = $purchase_id_; + $api_params['max_allowed_domains'] = $amount_of_licenses; + $api_params['max_allowed_devices'] = $amount_of_licenses_devices; + $api_params['date_created'] = date('Y-m-d'); + $api_params['date_expiry'] = $renewal_period; + $api_params['until'] = $_license_current_version; + $api_params['subscr_id'] = $order->get_customer_id(); + $api_params['lic_type'] = $license_type; + + //write_log('license_type -- ' . $license_type ); + + // Send query to the license manager server + $url = 'http://' . WOO_SLM_API_URL . '?' . http_build_query($api_params); + $url = str_replace(array('http://', 'https://'), '', $url); + $url = 'http://' . $url; + $response = wp_remote_get($url, array('timeout' => 20, 'sslverify' => false)); + $license_key = wc_slm_get_license_key($response); + + // Collect license keys + if ($license_key) { + $licenses[] = array( + 'item' => $item_name, + 'key' => $license_key, + 'expires' => $renewal_period, + ); + } + } + // } + } + + // Payment note wc_slm_payment_note($order_id, $licenses); // Assign licenses @@ -174,7 +219,6 @@ function wc_slm_get_license_key($response) { if (is_wp_error($response)) { return false; } - // Get License data $json = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', utf8_encode(wp_remote_retrieve_body($response))); $license_data = json_decode($json); @@ -182,7 +226,6 @@ function wc_slm_get_license_key($response) { if (!isset($license_data->key)) { return false; } - // Prepare note text return $license_data->key; } @@ -193,12 +236,20 @@ function wc_slm_get_license_key($response) { * @since 1.0.0 * @return void */ -function wc_slm_payment_note($order_id, $licenses) { +function wc_slm_get_license_id($license){ + global $wpdb; + $license_id = $wpdb->get_row("SELECT ID, license_key FROM ". $wpdb->prefix . "lic_key_tbl" . " WHERE license_key = '".$license."' ORDER BY id DESC LIMIT 0,1"); + return $license_id->ID; +} + +function wc_slm_payment_note($order_id, $licenses) { if ($licenses && count($licenses) != 0) { $message = __('License Key(s) generated', 'wc-slm'); + foreach ($licenses as $license) { - $message .= '
' . $license['item'] . ': ' . $license['key']; + $license_key = $license['key']; + $message .= '
' . $license['item'] . ': ' . $license_key . ''; } } else { @@ -226,24 +277,34 @@ function wc_slm_assign_licenses($order_id, $licenses) { * @return mixed */ function wc_slm_get_sites_allowed($product_id) { - - $wc_slm_sites_allowed = absint(get_post_meta($product_id, '_wc_slm_sites_allowed', true)); - + $wc_slm_sites_allowed = absint(get_post_meta($product_id, '_domain_licenses', true)); if (empty($wc_slm_sites_allowed)) { return false; } - return $wc_slm_sites_allowed; } -function wc_slm_get_licenses_qty($product_id) { +function wc_slm_get_lic_type($product_id) { + $_license_type = absint(get_post_meta($product_id, '_license_type', true)); + if (empty($_license_type)) { + return false; + } + return $_license_type; +} - $amount_of_licenses = absint(get_post_meta($product_id, '_amount_of_licenses', true)); +function wc_slm_get_devices_allowed($product_id) { + $_devices_licenses = absint(get_post_meta($product_id, '_devices_licenses', true)); + if (empty($_devices_licenses)) { + return false; + } + return $_devices_licenses; +} +function wc_slm_get_licenses_qty($product_id) { + $amount_of_licenses = absint(get_post_meta($product_id, '_amount_of_licenses', true)); if (empty($amount_of_licenses)) { return false; } - return $amount_of_licenses; } @@ -254,14 +315,11 @@ function wc_slm_get_licenses_qty($product_id) { * @return mixed */ function wc_slm_get_licensing_renewal_period($product_id) { - - $wc_slm_sites_allowed = absint(get_post_meta($product_id, '_wc_slm_licensing_renewal_period', true)); - - if (empty($wc_slm_sites_allowed)) { + $_license_renewal_period = absint(get_post_meta($product_id, '_license_renewal_period', true)); + if (empty($_license_renewal_period)) { return 0; } - - return $wc_slm_sites_allowed; + return $_license_renewal_period; } /** @@ -271,13 +329,12 @@ function wc_slm_get_licensing_renewal_period($product_id) { * @return bool */ function wc_slm_is_licensing_enabled($download_id) { - $licensing_enabled = absint(get_post_meta($download_id, '_wc_slm_licensing_enabled', true)); - // Set defaults if ($licensing_enabled) { return true; - } else { + } + else { return false; } } @@ -289,5 +346,4 @@ function wc_insert_payment_note($order_id, $msg) { function wc_get_payment_transaction_id($order_id) { return get_post_meta($order_id, '_transaction_id', true); -} - +} \ No newline at end of file diff --git a/software-license-manager/admin/includes/woocommerce/wc-software-license-manager.php b/software-license-manager/admin/includes/woocommerce/wc-software-license-manager.php index 2210575..ea438cd 100755 --- a/software-license-manager/admin/includes/woocommerce/wc-software-license-manager.php +++ b/software-license-manager/admin/includes/woocommerce/wc-software-license-manager.php @@ -4,17 +4,6 @@ // Author: Omid Shamlu // Author URI: http://wp-master.ir -if (!function_exists('write_log')) { - function write_log ( $log ) { - if ( true === WP_DEBUG ) { - if ( is_array( $log ) || is_object( $log ) ) { - error_log( print_r( $log, true ) ); - } else { - error_log( $log ); - } - } - } -} if (!class_exists('WOO_SLM')) { class WOO_SLM { @@ -29,7 +18,7 @@ public static function instance() { } private function setup_constants() { // Plugin version - define('WOO_SLM_VER', '2.1.0'); + define('WOO_SLM_VER', '2.2.0'); // get api settinsg from options table define('WOO_SLM_API_URL', get_site_url().'/'); define('WOO_SLM_API_SECRET', SLM_Helper_Class::slm_get_option('lic_creation_secret')); @@ -39,9 +28,7 @@ private function setup_constants() { private function includes() { // log files and scripts require_once SLM_ADMIN_ADDONS . 'woocommerce/includes/helper.php'; - if (is_admin()) { - require_once SLM_ADMIN_ADDONS . 'woocommerce/includes/meta-boxes.php'; - } + // purchases and emails require_once SLM_ADMIN_ADDONS . 'woocommerce/includes/emails.php'; require_once SLM_ADMIN_ADDONS . 'woocommerce/includes/purchase.php'; diff --git a/software-license-manager/admin/includes/wpestores/slm-wpestores.php b/software-license-manager/admin/includes/wpestores/slm-wpestores.php index 70d69fa..0c25223 100755 --- a/software-license-manager/admin/includes/wpestores/slm-wpestores.php +++ b/software-license-manager/admin/includes/wpestores/slm-wpestores.php @@ -119,6 +119,7 @@ function slm_estore_create_license($retrieved_product, $payment_data, $cart_item $fields['date_expiry'] = $slm_date_of_expiry; $fields['product_ref'] = $prod_id;//WP eStore product ID $fields['subscr_id'] = isset($payment_data['subscr_id']) ? $payment_data['subscr_id'] : ''; + $fields['lic_type'] = isset($payment_data['lic_type']) ? $payment_data['lic_type'] : ''; $slm_debug_logger->log_debug('Inserting license data into the license manager DB table.'); $fields = array_filter($fields); //Remove any null values. diff --git a/software-license-manager/admin/slm-add-licenses.php b/software-license-manager/admin/slm-add-licenses.php index 19b9e75..0d142e8 100755 --- a/software-license-manager/admin/slm-add-licenses.php +++ b/software-license-manager/admin/slm-add-licenses.php @@ -21,6 +21,9 @@ function wp_lic_mgr_add_licenses_menu() { $until = ''; $product_ref = ''; $subscr_id = ''; + $lic_type = ''; + $reg_domains = ''; + $reg_devices = ''; $current_date = (date ("Y-m-d")); $slm_options = get_option('slm_plugin_options'); $current_date_plus_1year = date('Y-m-d', strtotime('+1 year')); @@ -33,26 +36,27 @@ function wp_lic_mgr_add_licenses_menu() { if (isset($_GET['edit_record'])) { $errors = ''; $id = $_GET['edit_record']; - $lk_table = SLM_TBL_LICENSE_KEYS; - $sql_prep = $wpdb->prepare("SELECT * FROM $lk_table WHERE id = %s", $id); - $record = $wpdb->get_row($sql_prep, OBJECT); - $license_key = $record->license_key; - $max_domains = $record->max_allowed_domains; - $max_devices = $record->max_allowed_devices; + $lk_table = SLM_TBL_LICENSE_KEYS; + $sql_prep = $wpdb->prepare("SELECT * FROM $lk_table WHERE id = %s", $id); + $record = $wpdb->get_row($sql_prep, OBJECT); + $license_key = $record->license_key; + $max_domains = $record->max_allowed_domains; + $max_devices = $record->max_allowed_devices; $license_status = $record->lic_status; - $first_name = $record->first_name; - $last_name = $record->last_name; - $email = $record->email; - $company_name = $record->company_name; - $txn_id = $record->txn_id; - $reset_count = $record->manual_reset_count; - $purchase_id_ = $record->purchase_id_; - $created_date = $record->date_created; - $renewed_date = $record->date_renewed; - $expiry_date = $record->date_expiry; - $product_ref = $record->product_ref; - $until = $record->until; - $subscr_id = $record->subscr_id; + $first_name = $record->first_name; + $last_name = $record->last_name; + $email = $record->email; + $company_name = $record->company_name; + $txn_id = $record->txn_id; + $reset_count = $record->manual_reset_count; + $purchase_id_ = $record->purchase_id_; + $created_date = $record->date_created; + $renewed_date = $record->date_renewed; + $expiry_date = $record->date_expiry; + $product_ref = $record->product_ref; + $until = $record->until; + $subscr_id = $record->subscr_id; + $lic_type = $record->lic_type; } if (isset($_POST['save_record'])) { @@ -82,6 +86,7 @@ function wp_lic_mgr_add_licenses_menu() { $product_ref = $_POST['product_ref']; $until = $_POST['until']; $subscr_id = $_POST['subscr_id']; + $lic_type = $_POST['lic_type']; if(empty($created_date)){ $created_date = $current_date; @@ -112,6 +117,7 @@ function wp_lic_mgr_add_licenses_menu() { $fields['product_ref'] = $product_ref; $fields['until'] = $until; $subscr_id = $_POST['subscr_id']; + $lic_type = $_POST['lic_type']; $id = isset($_POST['edit_record'])?$_POST['edit_record']:''; $lk_table = SLM_TBL_LICENSE_KEYS; @@ -179,9 +185,7 @@ function wp_lic_mgr_add_licenses_menu() {
"> @@ -214,7 +218,7 @@ function hyphenate($str) {
The unique license key. -
+
+ +
+ + + + +
type of license: subscription base or lifetime +
+
+
diff --git a/software-license-manager/admin/slm-admin-init.php b/software-license-manager/admin/slm-admin-init.php index 71f3e19..4d767d3 100755 --- a/software-license-manager/admin/slm-admin-init.php +++ b/software-license-manager/admin/slm-admin-init.php @@ -22,7 +22,7 @@ function wp_lic_mgr_add_admin_menu() { $icon_svg = SLM_ASSETS_URL . 'images/slm_logo_small.svg'; - add_menu_page("License Manager", "License Manager", SLM_MANAGEMENT_PERMISSION, SLM_MAIN_MENU_SLUG, "wp_lic_mgr_manage_licenses_menu", $icon_svg); + add_menu_page("License", "License", SLM_MANAGEMENT_PERMISSION, SLM_MAIN_MENU_SLUG, "wp_lic_mgr_manage_licenses_menu", $icon_svg); add_submenu_page(SLM_MAIN_MENU_SLUG, "All Licenses", "All Licenses", SLM_MANAGEMENT_PERMISSION, SLM_MAIN_MENU_SLUG, "wp_lic_mgr_manage_licenses_menu"); add_submenu_page(SLM_MAIN_MENU_SLUG, "New License", "New Licenses", SLM_MANAGEMENT_PERMISSION, 'wp_lic_mgr_addedit', "wp_lic_mgr_add_licenses_menu"); add_submenu_page(SLM_MAIN_MENU_SLUG, "Admin Tools", "Admin Tools", SLM_MANAGEMENT_PERMISSION, 'wp_lic_mgr_admin_fnc', "wp_lic_mgr_admin_fnc_menu"); diff --git a/software-license-manager/admin/slm-lic-settings.php b/software-license-manager/admin/slm-lic-settings.php index 92ca720..1b668c6 100755 --- a/software-license-manager/admin/slm-lic-settings.php +++ b/software-license-manager/admin/slm-lic-settings.php @@ -40,7 +40,7 @@ function wp_lic_mgr_general_settings() { 'enable_auto_key_expiry' => isset($_POST['enable_auto_key_expiry']) ? '1':'', 'enable_debug' => isset($_POST['enable_debug']) ? '1':'', 'slm_woo' => isset($_POST['slm_woo']) ? '1':'', - 'slm_subscriptio' => isset($_POST['slm_subscriptio']) ? '1':'', + // 'slm_subscriptio' => isset($_POST['slm_subscriptio']) ? '1':'', 'slm_wpestores' => isset($_POST['slm_wpestores']) ? '1':'', ); update_option('slm_plugin_options', $options); @@ -133,13 +133,13 @@ function wp_lic_mgr_general_settings() {
A fully customizable, open source eCommerce platform built for WordPress. - + WP eStores Support diff --git a/software-license-manager/includes/class-software-license-manager-activator.php b/software-license-manager/includes/class-software-license-manager-activator.php index 06a6b4d..91a97f0 100755 --- a/software-license-manager/includes/class-software-license-manager-activator.php +++ b/software-license-manager/includes/class-software-license-manager-activator.php @@ -9,7 +9,7 @@ */ class Software_License_Manager_Activator { - public function slm_db_install{ + public static function slm_db_install{ //Installer function require_once( SLM_LIB . 'class-software-license-manager-slm-installer.php'); } @@ -22,4 +22,5 @@ public static function activate() { wp_schedule_event(time(), 'daily', 'slm_daily_cron_event'); do_action('slm_activation_complete'); } -} \ No newline at end of file +} +$slm_activator = new Software_License_Manager_Activator(); \ No newline at end of file diff --git a/software-license-manager/includes/class-software-license-manager-deactivator.php b/software-license-manager/includes/class-software-license-manager-deactivator.php index ec5f4ac..7f37b70 100755 --- a/software-license-manager/includes/class-software-license-manager-deactivator.php +++ b/software-license-manager/includes/class-software-license-manager-deactivator.php @@ -9,10 +9,11 @@ */ //Deactivation handler class Software_License_Manager_Deactivator { - public static function deactivate() { //Clear the daily cron event wp_clear_scheduled_hook('slm_daily_cron_event'); do_action('slm_deactivation_complete'); } -} \ No newline at end of file +} + +$slm_deactivator = new Software_License_Manager_Deactivator(); \ No newline at end of file diff --git a/software-license-manager/includes/class-software-license-manager-slm-installer.php b/software-license-manager/includes/class-software-license-manager-slm-installer.php index 9a85f85..f9832c5 100755 --- a/software-license-manager/includes/class-software-license-manager-slm-installer.php +++ b/software-license-manager/includes/class-software-license-manager-slm-installer.php @@ -32,6 +32,7 @@ max_allowed_domains int(40) NOT NULL, max_allowed_devices int(40) NOT NULL, lic_status ENUM('pending', 'active', 'blocked', 'expired') NOT NULL DEFAULT 'pending', + lic_type ENUM('none', 'subscription', 'lifetime') NOT NULL DEFAULT 'subscription', first_name varchar(32) NOT NULL default '', last_name varchar(32) NOT NULL default '', email varchar(64) NOT NULL, @@ -82,5 +83,6 @@ 'enable_debug' => '', 'slm_woo' => '', 'slm_subscriptio' => '', + 'slm_wpestores' => '', ); add_option('slm_plugin_options', $options); \ No newline at end of file diff --git a/software-license-manager/includes/slm-api-listener.php b/software-license-manager/includes/slm-api-listener.php index 19d4b1d..6e101d1 100755 --- a/software-license-manager/includes/slm-api-listener.php +++ b/software-license-manager/includes/slm-api-listener.php @@ -45,10 +45,11 @@ function creation_api_listener() { $fields = array(); 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 + $fields['license_key'] = strip_tags($_REQUEST['license_key']); //Use the key you pass via the request } else{ - $fields['license_key'] = uniqid($lic_key_prefix);//Use random generated key + // $fields['license_key'] = uniqid($lic_key_prefix); //Use random generated key + $fields['license_key'] = strtoupper($lic_key_prefix . hyphenate(md5(uniqid(rand(4,8), true) . time() ))); } $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'])); @@ -76,6 +77,8 @@ function creation_api_listener() { $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['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'] ) ) : ''; global $wpdb; $tbl_name = SLM_TBL_LICENSE_KEYS; @@ -380,6 +383,7 @@ function check_api_listener() { 'company_name' => $retLic->company_name, 'txn_id' => $retLic->txn_id, 'subscr_id' => $retLic->subscr_id, + 'lic_type' => $retLic->lic_type, 'until' => $retLic->until, )); @@ -393,6 +397,25 @@ function check_api_listener() { } } + /** + * Update the specified License Key + * + * @action slm_update + * + * Required parameter(s): + * + * slm_action - Must have the value 'slm_update' to trigger this feature + * license_key - The key for the license to update + * + * Supported parameter(s): + * + * lic_status + * txn_id + * max_allowed_domains + * date_expiry + * product_ref + */ + function update_api_listener() { if ( ! isset( $_REQUEST['slm_action'] ) ) { @@ -437,6 +460,10 @@ function update_api_listener() { $fields['lic_status'] = isset( $_REQUEST['lic_status'] ) ? wp_unslash( strip_tags( sanitize_text_field( $_REQUEST['lic_status'] ) ) ) : 'active'; } + if ( isset( $_REQUEST['lic_type'] ) ) { + $fields['lic_type'] = isset( $_REQUEST['lic_type'] ) ? wp_unslash( strip_tags( sanitize_text_field( $_REQUEST['lic_type'] ) ) ) : 'subscription'; + } + if ( isset( $_REQUEST['txn_id'] ) ) { $fields['txn_id'] = strip_tags( sanitize_text_field( $_REQUEST['txn_id'] ) ); } @@ -449,6 +476,14 @@ function update_api_listener() { $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 { + + $fields['max_allowed_devices'] = strip_tags( $_REQUEST['max_allowed_devices'] ); + } + $fields['date_expiry'] = isset( $_REQUEST['date_expiry'] ) ? strip_tags( sanitize_text_field( $_REQUEST['date_expiry'] ) ) : ''; $fields['product_ref'] = isset( $_REQUEST['product_ref'] ) ? wp_unslash( strip_tags( sanitize_text_field( $_REQUEST['product_ref'] ) ) ) : ''; @@ -480,6 +515,17 @@ function update_api_listener() { } } + /** + * Delete the specified License Key + * + * @action slm_remove + * + * Required parameter(s): + * + * slm_action - Must have the value 'slm_remove' to trigger this feature + * license_key - The key for the license to remove + * + */ function deletion_api_listener() { diff --git a/software-license-manager/includes/slm-meta-boxes.php b/software-license-manager/includes/slm-meta-boxes.php index cbde8ef..46a507e 100644 --- a/software-license-manager/includes/slm-meta-boxes.php +++ b/software-license-manager/includes/slm-meta-boxes.php @@ -2,221 +2,156 @@ // Author: Michel Velis // Author URI: http://pilotkit.co -// Since: 3.0.0 - -// Add Variation Custom fields - -//Display Fields in admin on product edit screen -add_action( 'woocommerce_product_after_variable_attributes', 'woo_variable_fields', 10, 3 ); +// Since: 4.4.0 +// from: https://gist.github.com/JeroenSormani/6b710d079386d096f932 + +add_filter('woocommerce_product_data_tabs', 'wc_slm_add_tab' ); +add_action('woocommerce_process_product_meta_simple', 'wc_slm_save_data'); +add_action('woocommerce_product_data_panels', 'wc_slm_data_panel'); + + +/** + * Add 'Gift Card' product option + */ +function add_wc_slm_data_tab_enabled_product_option( $product_type_options ) { + $product_type_options['wc_slm_data_tab_enabled'] = array( + 'id' => '_wc_slm_data_tab_enabled', + 'wrapper_class' => 'show_if_simple show_if_variable', + 'label' => __( 'License Manager', 'woocommerce' ), + 'default' => 'no', + 'description' => __( 'Enables the license creation api.', 'woocommerce' ) + ); + return $product_type_options; +} +add_filter( 'product_type_options', 'add_wc_slm_data_tab_enabled_product_option' ); + + +/** CSS To Add Custom tab Icon */ + +function wcpp_custom_style() { + ?> + + __('Licensing', 'woocommerce' ), + 'target' => 'wc_slm_meta', + 'class' => array( 'show_if_simple', 'show_if_wc_slm_data_tab_enabled'), + ); -// Create new fields for variations -function woo_variable_fields( $loop, $variation_data, $variation ) { + return $wc_slm_data_tabs; +} - echo '
'; +function wc_slm_data_panel() { + global $post; + ?> +
- // License Field - woocommerce_wp_text_input( + +
+ 'amount_of_licenses['. $loop .']', - 'label' => __( 'Number of Licenses (domain)', 'woocommerce' ), - 'placeholder' => '1-20', - 'desc_tip' => true, - 'wrapper_class' => 'form-row form-row-first', - 'description' => __( 'Ideal for themes, plugins, and websites', 'woocommerce' ), - 'value' => get_post_meta($variation->ID, 'amount_of_licenses', true) + 'id' => '_domain_licenses', + 'label' => __( 'Domain Licenses', 'woocommerce' ), + 'placeholder' => '0', + 'desc_tip' => 'true', + 'type' => 'number', + 'description' => __( 'Enter the allowed amount of domains this license can have (websites).', 'woocommerce' ) ) - ); - - echo "
"; - - echo '
'; - - // License Field - woocommerce_wp_text_input( + ); + woocommerce_wp_text_input( array( - 'id' => 'amount_of_licenses_devices['. $loop .']', - 'label' => __( 'Number of Licenses (devices)', 'woocommerce' ), - 'placeholder' => '1-20', - 'desc_tip' => true, - 'wrapper_class' => 'form-row form-row-first', - 'description' => __( 'Ideal for software and apps.', 'woocommerce' ), - 'value' => get_post_meta($variation->ID, 'amount_of_licenses_devices', true) + 'id' => '_devices_licenses', + 'label' => __( 'Devices Licenses', 'woocommerce' ), + 'placeholder' => '0', + 'desc_tip' => 'true', + 'type' => 'number', + 'description' => __( 'Enter the allowed amount of devices this license can have (computers, mobile, etc).', 'woocommerce' ) ) - ); - - echo "
"; - -} - -/** Save new fields for variations */ -function save_variation_fields( $variation_id, $i) { - - // License Field - $text_field = stripslashes( $_POST['amount_of_licenses'][$i] ); - update_post_meta( $variation_id, 'amount_of_licenses', esc_attr( $text_field ) ); - - $text_field = stripslashes( $_POST['amount_of_licenses_devices'][$i] ); - update_post_meta( $variation_id, 'amount_of_licenses_devices', esc_attr( $text_field ) ); - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// First Register the Tab by hooking into the 'woocommerce_product_data_tabs' filter -add_filter( 'woocommerce_product_data_tabs', 'add_my_custom_product_data_tab' ); -function add_my_custom_product_data_tab( $product_data_tabs ) { - $product_data_tabs['my-custom-tab'] = array( - 'label' => __( 'License', 'woocommerce' ), - 'target' => 'my_custom_product_data', - 'class' => array( 'show_if_simple', 'show_if_variable' ), ); - return $product_data_tabs; -} - - - - - -// functions you can call to output text boxes, select boxes, etc. -add_action('woocommerce_product_data_panels', 'woocom_custom_product_data_fields'); - -function woocom_custom_product_data_fields() { - global $post; - - // Note the 'id' attribute needs to match the 'target' parameter set above - ?>
'_text_field', - 'label' => __( 'Custom Text Field', 'woocommerce' ), - 'wrapper_class' => 'show_if_simple', //show_if_simple or show_if_variable - 'placeholder' => 'Custom text field', - 'desc_tip' => 'true', - 'description' => __( 'Enter the custom value here.', 'woocommerce' ) - ) - ); - - // Number Field - woocommerce_wp_text_input( - array( - 'id' => '_number_field', - 'label' => __( 'Custom Number Field', 'woocommerce' ), - 'placeholder' => '', - 'description' => __( 'Enter the custom value here.', 'woocommerce' ), - 'type' => 'number', - 'custom_attributes' => array( - 'step' => 'any', - 'min' => '15' - ) - ) - ); - - // Checkbox - woocommerce_wp_checkbox( - array( - 'id' => '_checkbox', - 'label' => __('Custom Checkbox Field', 'woocommerce' ), - 'description' => __( 'Check me!', 'woocommerce' ) - ) - ); - - // Select - woocommerce_wp_select( - array( - 'id' => '_select', - 'label' => __( 'Custom Select Field', 'woocommerce' ), - 'options' => array( - 'one' => __( 'Custom Option 1', 'woocommerce' ), - 'two' => __( 'Custom Option 2', 'woocommerce' ), - 'three' => __( 'Custom Option 3', 'woocommerce' ) - ) - ) - ); - - // Textarea - woocommerce_wp_textarea_input( - array( - 'id' => '_textarea', - 'label' => __( 'Custom Textarea', 'woocommerce' ), - 'placeholder' => '', - 'description' => __( 'Enter the value here.', 'woocommerce' ) - ) - ); - ?>
- + woocommerce_wp_text_input( + array( + 'id' => '_license_renewal_period', + 'label' => __( 'Renewal period ', 'woocommerce' ), + 'placeholder' => '0', + 'desc_tip' => 'true', + 'description' => __( 'License renewal period(yearly) , enter 0 for lifetime.', 'woocommerce' ) + ) + ); + woocommerce_wp_select( + array( + 'id' => '_license_type', + 'label' => __( 'License Type', 'woocommerce' ), + 'placeholder' => 'Select one', + 'desc_tip' => 'true', + 'description' => __( 'type of license: subscription base or lifetime', 'woocommerce' ), + 'options' => array( + 'none' => __( 'Select one', 'woocommerce' ), + 'subscription' => __( 'subscription', 'woocommerce' ), + 'lifetime' => __( 'lifetime', 'woocommerce' ), + ) + ) + ); + woocommerce_wp_text_input( + array( + 'id' => '_license_current_version', + 'label' => __( 'Current Version', 'woocommerce' ), + 'placeholder' => '0.0.0', + 'desc_tip' => 'true', + 'description' => __( 'Enter the current version of your application, theme, or plug-in', 'woocommerce' ) + ) + ); + ?> +
activate(); } /** @@ -57,49 +75,49 @@ function activate_software_license_manager() { */ function deactivate_software_license_manager() { require_once SLM_LIB . 'class-software-license-manager-deactivator.php'; - Software_License_Manager_Deactivator::deactivate(); + $slm_deactivator->deactivate(); } register_activation_hook( __FILE__, 'activate_software_license_manager' ); register_deactivation_hook( __FILE__, 'deactivate_software_license_manager' ); //Includes -include_once( SLM_LIB .'slm-debug-logger.php'); -include_once( SLM_LIB .'slm-error-codes.php'); -include_once( SLM_LIB .'slm-utility.php'); -include_once( SLM_LIB .'slm-init-time-tasks.php'); -include_once( SLM_LIB .'slm-api-utility.php'); -include_once( SLM_LIB .'slm-api-listener.php'); +require_once( SLM_LIB .'slm-debug-logger.php'); +require_once( SLM_LIB .'slm-error-codes.php'); +require_once( SLM_LIB .'slm-utility.php'); +require_once( SLM_LIB .'slm-init-time-tasks.php'); +require_once( SLM_LIB .'slm-api-utility.php'); +require_once( SLM_LIB .'slm-api-listener.php'); // Front end-menu // TODO check for optional plugins // Third Party Support if (null !== SLM_Helper_Class::slm_get_option('slm_woo') && SLM_Helper_Class::slm_get_option('slm_woo') == 1) { - include_once( SLM_PUBLIC . 'slm-add-menu-frontend.php'); + require_once( SLM_PUBLIC . 'slm-add-menu-frontend.php'); // WordPress Plugin :: wc-software-license-manager - include_once( SLM_ADMIN . 'includes/woocommerce/wc-software-license-manager.php'); + require_once( SLM_ADMIN . 'includes/woocommerce/wc-software-license-manager.php'); - // support for meta boxes (variations only, this can be applied to single prodicts as well) - include_once( SLM_LIB . 'slm-meta-boxes.php'); + // support for meta boxes (variations only, this can be applied to single products as well) + require_once( SLM_LIB . 'slm-meta-boxes.php'); } -if (null !== SLM_Helper_Class::slm_get_option('slm_subscriptio') && SLM_Helper_Class::slm_get_option('slm_subscriptio') == 1) { - // Subscriptio PLugin Intergration - include_once( SLM_ADMIN . 'includes/subscriptio/slm-subscriptio.php'); -} +// if (null !== SLM_Helper_Class::slm_get_option('slm_subscriptio') && SLM_Helper_Class::slm_get_option('slm_subscriptio') == 1) { +// // Subscriptio PLugin Integration +// require_once( SLM_ADMIN . 'includes/subscriptio/slm-subscriptio.php'); +// } -if (null !== SLM_Helper_Class::slm_get_option('slm_wpestores') && SLM_Helper_Class::slm_get_option('slm_wpestores') == 1) { - // wpestores PLugin Intergration - include_once( SLM_ADMIN . 'includes/wpestores/slm-wpestores.php'); -} +// 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'); +// } //Include admin side only files if (is_admin()) { - include_once( SLM_ADMIN . 'slm-admin-init.php'); - include_once( SLM_ADMIN . 'includes/slm-list-table-class.php'); //Load our own WP List Table class + require_once( SLM_ADMIN . 'slm-admin-init.php'); + require_once( SLM_ADMIN . 'includes/slm-list-table-class.php'); //Load our own WP List Table class } //Action hooks @@ -125,7 +143,7 @@ function slm_plugins_loaded_handler() { //Check if db update needed if (get_option('wp_lic_mgr_db_version') != SLM_DB_VERSION) { require_once( SLM_LIB . 'class-software-license-manager-slm-installer.php'); - // TODO - Software_License_Manager_Activator::slm_db_install(); + // TODO - $slm_activator->slm_db_install(); } } } diff --git a/software-license-manager/public/assets/images/slm_logo_small.svg b/software-license-manager/public/assets/images/slm_logo_small.svg index 09ad389..8f20dac 100755 --- a/software-license-manager/public/assets/images/slm_logo_small.svg +++ b/software-license-manager/public/assets/images/slm_logo_small.svg @@ -1,15 +1,3 @@ - - - - - - - - - - - - - - + + diff --git a/software-license-manager/software-license-manager.php b/software-license-manager/software-license-manager.php index 7b78b42..6edb7aa 100755 --- a/software-license-manager/software-license-manager.php +++ b/software-license-manager/software-license-manager.php @@ -1,7 +1,7 @@