public function __construct() { define('VTPRD_PARENT_PLUGIN_NAME', 'WooCommerce'); define('VTPRD_EARLIEST_ALLOWED_PARENT_VERSION', '2.0.14'); //all due to support for hook 'woocommerce_email_order_items_table' - requires the 2nd order_info variable... define('VTPRD_TESTED_UP_TO_PARENT_VERSION', '2.1.9'); //v1.1.5 begin ==>> replaced 'http//' with 'https//' define('VTPRD_DOCUMENTATION_PATH', 'https://www.varktech.com/documentation/pricing-deals/introrule/'); //*** define('VTPRD_INSTALLATION_INSTRUCTIONS_BY_PARENT', 'https://www.varktech.com/woocommerce/pricing-deals-for-woocommerce/?active_tab=instructions'); define('VTPRD_PRO_INSTALLATION_INSTRUCTIONS_BY_PARENT', 'https://www.varktech.com/woocommerce/woocommerce-dynamic-pricing-discounts-pro/?active_tab=instructions'); define('VTPRD_PURCHASE_PRO_VERSION_BY_PARENT', 'https://www.varktech.com/woocommerce/woocommerce-dynamic-pricing-discounts-pro/'); define('VTPRD_DOWNLOAD_FREE_VERSION_BY_PARENT', 'wordpress.org/extend/plugins/pricing-deals-for-woocommerce/'); define('VTPRD_SUPPORT_URL', 'https://www.varktech.com/support/'); //v1.1.5 NEW //v1.1.5 end //html default selector locations in checkout where error message will display before. define('VTPRD_CHECKOUT_PRODUCTS_SELECTOR_BY_PARENT', '.shop_table'); // PRODUCTS TABLE on BOTH cart page and checkout page define('VTPRD_CHECKOUT_ADDRESS_SELECTOR_BY_PARENT', '#customer_details'); // address area on checkout page default = on define('VTPRD_CHECKOUT_BUTTON_ERROR_MSG_DEFAULT', __('Your email, bill-to or ship-to address are attached to other discounted order(s). This has affected the current order Lifetime discount limit, and resulted in the total Discount being reduced. Please hit the "Purchase" button a second time to complete the transaction.', 'vtprd')); global $vtprd_info, $vtprd_rule_type_framework, $wpdb; define('VTPRD_PURCHASE_LOG', $wpdb->prefix . 'vtprd_purchase_log'); define('VTPRD_PURCHASE_LOG_PRODUCT', $wpdb->prefix . 'vtprd_purchase_log_product'); define('VTPRD_PURCHASE_LOG_PRODUCT_RULE', $wpdb->prefix . 'vtprd_purchase_log_product_rule'); //option set during update rule process if (get_option('vtprd_ruleset_has_a_display_rule') == true) { $ruleset_has_a_display_rule = get_option('vtprd_ruleset_has_a_display_rule'); } else { $ruleset_has_a_display_rule = 'no'; } //v1.1.1.2 begin //option set during update rule process if (get_option('vtprd_ruleset_contains_auto_add_free_product') == true) { $ruleset_contains_auto_add_free_product = get_option('vtprd_ruleset_contains_auto_add_free_product'); } else { $ruleset_contains_auto_add_free_product = 'no'; } //v1.1.1.2 end $coupon_code_discount_deal_title = __('deals', 'vtprd'); $default_short_msg = __('Short checkout message required', 'vtprd'); $default_full_msg = __('Get 10% off Laptops Today! (sample)', 'vtprd'); $default_coupon_msg = __('Optional - Discount applied *only* with Coupon Code', 'vtprd'); //v1.1.0.8 $vtprd_info = array('parent_plugin' => 'woo', 'parent_plugin_taxonomy' => 'product_cat', 'parent_plugin_taxonomy_name' => 'Product Categories', 'parent_plugin_cpt' => 'product', 'applies_to_post_types' => 'product', 'rulecat_taxonomy' => 'vtprd_rule_category', 'rulecat_taxonomy_name' => 'Pricing Deals Rules', 'cart_discount_processing_save_unit_price' => 0, 'current_processing_request' => 'cart', 'skip_cart_processing_due_to_coupon_individual_use' => false, 'product_session_info' => '', 'ruleset_has_a_display_rule' => $ruleset_has_a_display_rule, 'ruleset_contains_auto_add_free_product' => $ruleset_contains_auto_add_free_product, 'inPop_conditions_met' => 'no', 'actionPop_conditions_met' => 'no', 'maybe_auto_add_free_product_count' => 0, 'cart_rows_at_checkout_count' => 0, 'after_checkout_cart_row_execution_count' => 0, 'product_meta_key_includeOrExclude' => '_vtprd_includeOrExclude', 'inpop_variation_checkbox_total' => 0, 'on_checkout_page' => '', 'coupon_num' => '', 'checkout_validation_in_process' => 'no', 'ajax_test_value' => '', 'coupon_code_discount_deal_title' => $coupon_code_discount_deal_title, 'cart_color_cnt' => '', 'rule_id_list' => '', 'line_cnt' => 0, 'action_cnt' => 0, 'bold_the_error_amt_on_detail_line' => 'no', 'currPageURL' => '', 'woo_cart_url' => '', 'woo_checkout_url' => '', 'woo_pay_url' => '', 'purch_hist_product_row_id' => '', 'purch_hist_product_price_total' => '', 'purch_hist_product_qty_total' => '', 'get_purchaser_info' => '', 'purch_hist_done' => '', 'purchaser_ip_address' => vtprd_get_ip_address(), 'default_short_msg' => $default_short_msg, 'default_full_msg' => $default_full_msg, 'user_is_tax_exempt' => '', 'product_catalog_price_array' => array(), 'previous_auto_add_array' => '', 'default_coupon_msg' => $default_coupon_msg, 'coupon_codes_array' => array(), 'cart_has_catalog_discounts' => false); //end vtprd_info if ($vtprd_info['purchaser_ip_address'] <= ' ') { $vtprd_info['purchaser_ip_address'] = vtprd_get_ip_address(); //v1.1.5 changed below } //load up 'user_is_tax_exempt' //v1.0.9.0 //vtprd_get_current_user_role(); //v1.0.9.0 }
/** * Calls the API and, if successfull, returns the object delivered by the API. * * @uses get_bloginfo() * @uses wp_remote_post() * @uses is_wp_error() * * @param string $_action The requested action. * @param array $_data Parameters for the API action. * @return false|object */ private function api_request($_action, $_data) { //error_log( print_r( 'BEGIN api_request, $_action= ' .$_action . ' $_data=' , true ) ); //error_log( var_export($_data, true ) ); //v1.1.6.3 begin - is Woocommerce installed if (!class_exists('WooCommerce')) { return false; } //v1.1.6.3 end global $wp_version; $data = array_merge($this->api_data, $_data); if ($data['slug'] != $this->slug) { return; } if ($this->api_url == home_url()) { return false; // Don't allow a plugin to ping itself } //v1.1.5 begin verify - saves an additional call if already invalid... //apply to PRO plugin if active or inactive!! //however, if previously invalid, do not apply //$vtprd_license_options == get_option( 'vtprd_license_options' ); /* global $vtprd_license_options; if (!$vtprd_license_options) { $vtprd_license_options = get_option( 'vtprd_license_options' ); } */ global $vtprd_license_options; //v1.1.6 $vtprd_license_options = get_option('vtprd_license_options'); //$vtprd_license_options == get_option( 'vtprd_license_options' ); //SO we START with ONLY valid and active licenses! if (isset($vtprd_license_options['status']) && $vtprd_license_options['status'] == 'valid' && $vtprd_license_options['state'] == 'active') { $carry_on = true; } else { return false; } /* //TEST for duplicative api call testing - only do this ONCE per 10 second interval: $today= time(); if (($today - $vtprd_license_options['last_successful_rego_ts']) < 10) { //error_log( print_r( 'api_request time interval exit, Exit 0002a' , true ) ); return false; } */ //v1.1.5 end /* CLIENT - All the Plugin Updater does is run the function - api_request -. By **hardcode**, all that function does is send a -'get_version' - request. HOST SOOOO the default check_license is NEVER done... get_version ==>> get_latest_version_remote which does NOT do check_license ... // data to send in our API request $api_params = array( 'edd_action' => $action, 'license' => $license, 'item_name' => urlencode( VTPRD_ITEM_NAME ), // the name of our product in VTPRD 'item_id' => urlencode( VTPRD_ITEM_ID ), // the name of our product in VTPRD 'url' => $url, 'prod_or_test' => $prod_or_test, 'test_url' => $test_url, 'email' => urlencode($email), 'ip_address' => vtprd_get_ip_address() ); vark_get_latest_version_remote */ //******************************************** //$url ALWAYS has the PROD url in it //******************************************** if ($vtprd_license_options['prod_or_test'] == 'prod') { $url = $vtprd_license_options['url']; $test_url = ''; } else { $test_url = $vtprd_license_options['url']; $url = $vtprd_license_options['prod_url_supplied_for_test_site']; } $api_params = array('edd_action' => 'get_version', 'license' => trim($vtprd_license_options['key']), 'item_name' => urlencode(VTPRD_ITEM_NAME), 'item_id' => VTPRD_ITEM_ID, 'slug' => $data['slug'], 'author' => $data['author'], 'url' => $url, 'prod_or_test' => $vtprd_license_options['prod_or_test'], 'test_url' => $test_url, 'email' => $vtprd_license_options['email'], 'ip_address' => vtprd_get_ip_address()); //v1.1.6.3 begin if (defined('VTPRD_PRO_VERSION')) { $version = VTPRD_PRO_VERSION; } else { global $vtprd_setup_options; $version = $vtprd_setup_options['current_pro_version']; } //v1.1.6.3 end //v1.1.6 begin // $request = wp_remote_post( VTPRD_STORE_URL, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); $request = wp_remote_post(VTPRD_STORE_URL, array('method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'headers' => array('user-agent' => 'Aardvark/Updater/vtprd/Free/V' . VTPRD_VERSION . '/Pro/V' . $version . ';' . $vtprd_license_options['url']), 'body' => $api_params, 'sslverify' => false)); /* from woothemes-updater/classes/class-woothemes-update-checker.php $request = wp_remote_post( ( $api == 'info' ) ? $this->api_url : $this->update_check_url, array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'headers' => array( 'user-agent' => 'WooThemesUpdater/' . $this->version ), 'body' => $args, 'sslverify' => false ) ); */ //v1.1.6 end //error_log( print_r( 'api_request after wp_remote_post, $request= ' .$_action , true ) ); //error_log( var_export($request, true ) ); //error_log( var_export($api_params, true ) ); if (!is_wp_error($request)) { $request = json_decode(wp_remote_retrieve_body($request)); } else { /* $vtprd_license_options['status'] = 'invalid'; $vtprd_license_options['state'] = 'pending'; $vtprd_license_options['last_failed_rego___ts'] = time(); $vtprd_license_options['last_failed_rego___date_time'] = date("Y-m-d H:i:s"); $vtprd_license_options['diagnostic_msg'] = 'error contacting host, please try again'; update_option('vtprd_license_options', $vtprd_license_options); */ return 'false'; } //v1.1.6 begin //used to control license checks during Admin and Cron $today = time(); update_option('vtprd_last_license_check_ts', $today); //v1.1.6 end //global $vtprd_license_options; //just in case $vtprd_license_options = get_option('vtprd_license_options'); //just in case //date time stamp if ($request->status == 'valid') { $vtprd_license_options['last_successful_rego_ts'] = $today; //v1.1.6 $vtprd_license_options['last_successful_rego_date_time'] = date("Y-m-d H:i:s"); //Can't update vtprd_license_options here, things explode!! Store for update in main plugin php file update_option('vtprd_license_checked', $vtprd_license_options); } else { $vtprd_license_options['last_failed_rego___ts'] = $today; //v1.1.6 $vtprd_license_options['last_failed_rego___date_time'] = date("Y-m-d H:i:s"); } //error_log( print_r( 'api_request*2* after wp_remote_post, $request*2*= ' .$_action , true ) ); //error_log( var_export($request, true ) ); //v1.1.5 begin if ($request->status == 'invalid') { // v1.1.6 pulled out of here, put in mainline - now picked up when 'vtprd_license_suspended' is processed /* if ($request->state == 'suspended-by-vendor') { vtprd_deactivate_pro_plugin(); vtprd_increment_license_count(); } */ $vtprd_license_options['status'] = $request->status; $vtprd_license_options['state'] = $request->state; $vtprd_license_options['strikes'] = $request->strikes; //****************************** //v1.1.6 begin refactored if (isset($request->diagnostic_msg)) { $vtprd_license_options['diagnostic_msg'] = $request->diagnostic_msg; } else { if (isset($request->verify_response)) { $vtprd_license_options['diagnostic_msg'] = $request->verify_response; } } //$vtprd_license_options['diagnostic_msg'] = $request->diagnostic_msg; $vtprd_license_options['msg'] = $request->msg; $vtprd_license_options['expires'] = $request->expires; $vtprd_license_options['last_response_from_host'] = $request; $vtprd_license_options['last_failed_rego_ts'] = time(); $vtprd_license_options['last_failed_rego_date_time'] = date("Y-m-d H:i:s"); //v1.1.6 end //****************************** //Can't update vtprd_license_options here, things explode!! Store for update in main plugin php file update_option('vtprd_license_suspended', $vtprd_license_options); return 'false'; } //update for date time stamp /* TEST TEST TEST if ( (get_option('vtprd_host_has_new_version') !== false ) //v1.1.6.3 //version update 1st time, nothing to download if ($vtprd_license_options['plugin_current_version'] <= ' ') { $vtprd_license_options['plugin_current_version'] = $request->new_version; update_option('vtprd_license_options', $vtprd_license_options); return 'false'; } //IF NO CHANGE, nothing to do. if ($vtprd_license_options['plugin_current_version'] == $request->new_version) { return 'false'; } */ //v1.1.5 end if ($request && isset($request->sections)) { $request->sections = maybe_unserialize($request->sections); } else { $request = false; } /* //error_log( print_r( 'after wp_remote_retrieve_body prod_or_test 003= ' .$vtprd_license_options['prod_or_test'] , true ) ); $vtprd_license_options2 = get_option( 'vtprd_license_options' ); //just in case //error_log( print_r( 'api_request, Exit 0005, $vtprd_license_options2 = ' , true ) ); //error_log( var_export($vtprd_license_options2, true ) ); global $vtprd_license_options; //just in case $vtprd_license_options = $vtprd_license_options2; */ return $request; }
function vtprd_license_phone_home($input, $action, $skip_admin_check = null) { //$skip_admin_check is for phone_home exec from function vtprd_maybe_recheck_license_activation() //error_log( print_r( 'Begin vtprd_license_phone_home' , true ) ); //v1.1.6.3 begin - is Woocommerce installed if (!class_exists('WooCommerce')) { return; } //v1.1.6.3 end global $vtprd_license_options; /* verify basic stuff: license supplied, email supplied if test selected, PRO is supplied if test selected, enforce the '.test. etc node requirement' IN THE ERROR msg for node requirement, explain that if TEST is 1st installation (no Prod yet), you can register the test as PROD and then Deactivate the test and re-register as PROD COUNT LICENSE NOT FOUND ==>> ONLY error NOT counted at the Server 3 STRIKES you're out... ******************************************************** * IF TEST * popup field PROD URL ==>> put into the regular URL field * grab the current URL which is the test URL in this case * put in into TEST_URL ********************************************************* */ // run a quick security check if ($skip_admin_check == 'yes') { $carry_on = true; } else { if (!check_admin_referer('vtprd_nonce', 'vtprd_nonce')) { return; // get out if we didn't click the Activate button } } // retrieve the license from the database $license = trim($input['key']); $email = $input['email']; $prod_or_test = $input['prod_or_test']; //******************************************** //$url ALWAYS has the PROD url in it, for BOTH 'prod_or_test' = PROD and DEMO //******************************************** if ($prod_or_test == 'prod' || $prod_or_test == 'demo') { $url = $input['url']; $test_url = ''; } else { $test_url = $input['url']; $url = $input['prod_url_supplied_for_test_site']; //PROD URL off of screen $url = $this->vtprd_strip_out_http($url); $input['prod_url_supplied_for_test_site'] = $url; } //********************************************************** //TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST // $url = 'www.nefarious.com'; //$test_url = 'test.staging.wpengine.anything.com'; // $ip_address = '1.2.3.4'; //********************************************************** if ($prod_or_test == 'demo') { $item_name = VTPRD_ITEM_NAME . ' Demo'; $item_id = VTPRD_ITEM_ID_DEMO; } else { $item_name = VTPRD_ITEM_NAME; $item_id = VTPRD_ITEM_ID; } /* //************************** //* Begin GET IP - somehwnat complex logic to get Host's IP address!!!!!!!!!! //************************** //get host IP, from http://stackoverflow.com/questions/5800927/how-to-identify-server-ip-address-in-php $host = gethostname(); // from http://stackoverflow.com/questions/4305604/get-ip-from-dns-without-using-gethostbyname $ip = $this->vtprd_getAddrByHost($host); //returns $host if IP not found if ($ip == $host) { //if the address did not resolve, then use gethostbyname $ip = gethostbyname($host); } */ //the definitive solution!!!!!!!!!!! //$ip = vtprd_get_ip(); ==>> now in vtprd_get_ip_address //end GET IP // data to send in our API request $api_params = array('edd_action' => $action, 'license' => $license, 'item_name' => urlencode($item_name), 'item_id' => $item_id, 'url' => urlencode($url), 'prod_or_test' => $prod_or_test, 'test_url' => urlencode($test_url), 'email' => urlencode($email), 'ip_address' => vtprd_get_ip_address()); // Call the custom API. //https://wordpress.org/support/topic/wp_remote_post-and-timeout ==>> adjust timeout for efficiency during testing /* compress was introduced in WordPress 2.6 and allows you to send the body of the request in a compressed format. This will be outside the scope of our future articles. decompress is similar to compress except that it's on our end - if compressed data is received, this will allow us to decompress the content before doing any further work or processing on it. */ $remote_data = array('timeout' => 15, 'sslverify' => false, 'body' => $api_params); //v1.1.6 begin // $response = wp_remote_post( VTPRD_STORE_URL, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); //v1.1.6.1 begin if ($prod_or_test == 'demo') { $show_demo = ';Demo'; } else { $show_demo = null; } //v1.1.6.1 end global $vtprd_setup_options; //v1.1.6.3 $response = wp_remote_post(VTPRD_STORE_URL, array('method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'headers' => array('user-agent' => 'Aardvark/Register.Check/vtprd/Free/V' . VTPRD_VERSION . '/Pro' . $show_demo . '/V' . $vtprd_setup_options['current_pro_version'] . ';' . $input['url']), 'body' => $api_params, 'sslverify' => false)); /* from woothemes-updater/classes/class-woothemes-update-checker.php $request = wp_remote_post( ( $api == 'info' ) ? $this->api_url : $this->update_check_url, array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'headers' => array( 'user-agent' => 'WooThemesUpdater/' . $this->version ), 'body' => $args, 'sslverify' => false ) ); */ //v1.1.6 end $input['params_sent_to_host'] = $api_params; $input['last_response_from_host'] = $response; // make sure the response came back okay if (is_wp_error($response)) { //no change to input, just send back $input['msg'] = "License activation function was temporarily busy, please try again!"; return $input; } // decode the license data $license_data = json_decode(wp_remote_retrieve_body($response)); //COMES BACK VALID OR INVALID if (isset($license_data->status)) { $input['status'] = $license_data->status; } if (isset($license_data->state)) { $input['state'] = $license_data->state; } if (isset($license_data->msg)) { $input['msg'] = $license_data->msg; } //v1.1.6 begin refactored if (isset($license_data->diagnostic_msg)) { $input['diagnostic_msg'] = $license_data->diagnostic_msg; } else { if (isset($license_data->verify_response)) { $input['diagnostic_msg'] = $license_data->verify_response; } } //v1.1.6 end if (isset($license_data->strikes)) { $input['strikes'] = $license_data->strikes; } $input['last_action'] = $action; if (isset($license_data->expires)) { $input['expires'] = $license_data->expires; } // ********************************************************** // STATUS: valid / invalid / unregistered (default) // STATE: active / deactivated / pending (error but not yet suspended) / suspended-by-vendor // ********************************************************** // v1.1.6 pulled out of here, put in mainline - now picked up when 'vtprd_license_suspended' is processed /* if ($license_data->state == 'suspended-by-vendor') { //deactivate PRO plugin vtprd_deactivate_pro_plugin(); //vtprd_increment_license_count(); } */ // if ($input['status'] == 'valid') { $input['last_successful_rego_ts'] = time(); $input['last_successful_rego_date_time'] = date("Y-m-d H:i:s"); } else { $input['last_failed_rego_ts'] = time(); $input['last_failed_rego_date_time'] = date("Y-m-d H:i:s"); } //in case the USEr used the old SESSIONID, move the returned LICENSE KEY back into the License field. if ($license_data->key > ' ' && $license_data->key != $input['key']) { $input['key'] = $license_data->key; } //error_log( print_r( 'PHONE Home at BOTTOM, $vtprd_license_options= ', true ) ); //error_log( var_export($vtprd_license_options, true ) ); return $input; }