| 1 |
<?php |
| 2 |
/** |
| 3 |
* License Settings pAge |
| 4 |
*/ |
| 5 |
class qcld_openaiaddon_License_Settings_page |
| 6 |
{ |
| 7 |
|
| 8 |
function __construct() |
| 9 |
{ |
| 10 |
add_action( 'admin_init', array($this, 'register_license_key_settings') ); |
| 11 |
} |
| 12 |
|
| 13 |
function register_license_key_settings(){ |
| 14 |
register_setting( 'qcld_openaiaddon_license', 'qcld_openaiaddon_enter_license_key', array($this, 'qcld_callback_quantum_license_key') ); |
| 15 |
register_setting( 'qcld_openaiaddon_license', 'qcld_openaiaddon_enter_envato_key', array($this, 'qcld_callback_envato_license_key') ); |
| 16 |
register_setting( 'qcld_openaiaddon_license', 'qcld_openaiaddon__buy_from_where', array( 'default' => '' ) ); |
| 17 |
register_setting( 'qcld_openaiaddon_license', 'qcld_openaiaddon_site_type', array( 'default' => '' ) ); |
| 18 |
//start new-update-for-codecanyon |
| 19 |
register_setting( 'qcld_openaiaddon_license', 'qcld_openaiaddon_enter_license_or_purchase_key', array( 'default' => '' ) ); |
| 20 |
//end new-update-for-codecanyon |
| 21 |
} |
| 22 |
|
| 23 |
function qcld_callback_quantum_license_key($posted_option){ |
| 24 |
|
| 25 |
if(isset($_POST['submit'])){ |
| 26 |
$license_key = sanitize_text_field($_POST['qcld_openaiaddon_enter_license_or_purchase_key']); |
| 27 |
$buy_from = sanitize_text_field($_POST['qcld_openaiaddon__buy_from_where']); |
| 28 |
$server_type = sanitize_text_field($_POST['qcld_openaiaddon_site_type']); |
| 29 |
$plugin_name = openaiaddon_LICENSING_PLUGIN_NAME; |
| 30 |
|
| 31 |
$request = wp_remote_get( |
| 32 |
openaiaddon_LICENSING_PRODUCT_DEV_URL."wp-json/qcld-sumu-subscription-checker/v1/checkplugin/?license_key=".$license_key."&plugin_to_check=".$plugin_name |
| 33 |
); |
| 34 |
$current_domain_url = site_url() ; |
| 35 |
$current_domain = str_replace( |
| 36 |
array( 'https://', 'http://', 'www.' ), |
| 37 |
array('', '', ''), |
| 38 |
$current_domain_url |
| 39 |
); |
| 40 |
if( $buy_from == 'quantumcloud'){ |
| 41 |
if ( !is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) { |
| 42 |
|
| 43 |
$result = json_decode($request['body']); |
| 44 |
if( $result){ |
| 45 |
$requested_plugin_name = $result->plugin_name; |
| 46 |
$plugin_max_domain = $result->plugin_max_domain; |
| 47 |
if($requested_plugin_name == $plugin_name){ |
| 48 |
|
| 49 |
|
| 50 |
delete_openaiaddon_update_transient(); |
| 51 |
delete_openaiaddon_renew_transient(); |
| 52 |
|
| 53 |
delete_openaiaddon_invalid_license(); |
| 54 |
set_openaiaddon_valid_license(); |
| 55 |
$track_domain_request = wp_remote_get(openaiaddon_LICENSING_PRODUCT_DEV_URL."wp-json/qc-domain-tracker/v1/insertdomain/?license_key=".$license_key."&plugin_name=".$plugin_name."¤t_domain=".$current_domain."&plugin_max_domain=".$plugin_max_domain."&buy_from=".$buy_from.'&server_type='.$server_type); |
| 56 |
|
| 57 |
if( !is_wp_error( $track_domain_request ) || wp_remote_retrieve_response_code( $track_domain_request ) === 200 ){ |
| 58 |
|
| 59 |
}else{ |
| 60 |
|
| 61 |
} |
| 62 |
} |
| 63 |
}else{ |
| 64 |
set_openaiaddon_invalid_license(); |
| 65 |
delete_openaiaddon_valid_license(); |
| 66 |
} |
| 67 |
}else{ |
| 68 |
|
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
return $posted_option; |
| 73 |
} |
| 74 |
|
| 75 |
function qcld_callback_envato_license_key($posted_option){ |
| 76 |
if(isset($_POST['submit'])){ |
| 77 |
$purchase_code = sanitize_text_field($_POST['qcld_openaiaddon_enter_envato_key']); |
| 78 |
$buy_from = sanitize_text_field($_POST['qcld_openaiaddon_buy_from_where']); |
| 79 |
$server_type = sanitize_text_field($_POST['qcld_openaiaddon_site_type']); |
| 80 |
$plugin_name = openaiaddon_LICENSING_PLUGIN_NAME; |
| 81 |
$current_domain_url = site_url() ; |
| 82 |
$current_domain = str_replace( |
| 83 |
array( 'https://', 'http://', 'www.' ), |
| 84 |
array('', '', ''), |
| 85 |
$current_domain_url |
| 86 |
); |
| 87 |
|
| 88 |
if( $buy_from == 'codecanyon'){ |
| 89 |
if (!preg_match("/^(\w{8})-((\w{4})-){3}(\w{12})$/", $purchase_code) ){ |
| 90 |
//throw new Exception("Invalid code"); |
| 91 |
setqc_openaiaddon_invalid_license(); |
| 92 |
deleteqc_openaiaddon_valid_license(); |
| 93 |
}else{ |
| 94 |
|
| 95 |
$verify_purchase_code = wp_remote_get(wplivechat_LICENSING_PRODUCT_DEV_URL."wp-json/qc-envato/v1/checklicense/?license_key=".$purchase_code); |
| 96 |
|
| 97 |
if ( !is_wp_error( $verify_purchase_code ) || wp_remote_retrieve_response_code( $verify_purchase_code ) === 200 ) { |
| 98 |
|
| 99 |
$verify_purchase_result = json_decode($verify_purchase_code['body'], true); |
| 100 |
$item_details = $verify_purchase_result['item']; |
| 101 |
|
| 102 |
if( $item_details['id'] == wplivechat_ENVATO_PLUGIN_ID ){ |
| 103 |
$track_domain_request = wp_remote_get(wplivechat_LICENSING_PRODUCT_DEV_URL."wp-json/qc-domain-tracker/v1/insertdomain/?license_key=".$purchase_code."&plugin_name=".$plugin_name."¤t_domain=".$current_domain."&plugin_max_domain=1&buy_from=".$buy_from.'&server_type='.$server_type); |
| 104 |
|
| 105 |
deleteqc_openaiaddon_update_transient(); |
| 106 |
deleteqc_openaiaddon_renew_transient(); |
| 107 |
|
| 108 |
deleteqc_openaiaddon_invalid_license(); |
| 109 |
setqc_openaiaddon_valid_license(); |
| 110 |
}else{ |
| 111 |
setqc_openaiaddon_invalid_license(); |
| 112 |
deleteqc_openaiaddon_valid_license(); |
| 113 |
} |
| 114 |
|
| 115 |
}else{ |
| 116 |
setqc_openaiaddon_invalid_license(); |
| 117 |
deleteqc_openaiaddon_valid_license(); |
| 118 |
} |
| 119 |
|
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
return $posted_option; |
| 124 |
} |
| 125 |
} |
| 126 |
|