ver 1.4.0
This commit is contained in:
296
includes/class-License.php
Normal file
296
includes/class-License.php
Normal file
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
class CHECKER_LICENSE extends SHEET_DATA_CHECKER_PRO {
|
||||
|
||||
/**
|
||||
* A reference to a contact's name of this class.
|
||||
*/
|
||||
private $license = true;
|
||||
|
||||
/**
|
||||
* Returns an instance of this class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
|
||||
return self::$instance;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the plugin by setting filters and administration functions.
|
||||
*/
|
||||
|
||||
public function __construct() {
|
||||
|
||||
add_action('plugins_loaded', [$this, 'check_license'], 1);
|
||||
add_action('admin_init', [$this, 'register_routine'], 1);
|
||||
add_action('sheetcheckerpro/license/check', [$this, 'check_license_routine'], 1);
|
||||
add_action('admin_notices', [$this, 'display_license_message'], 1);
|
||||
add_action('admin_menu', [$this, 'admin_menu_license']);
|
||||
add_action('admin_init', [$this, 'check_form'], 1 );
|
||||
|
||||
// if(false !== $this->the_lis()){
|
||||
// require 'class-Checker.php';
|
||||
// new UPDATE_CHECKER();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
public function set_license(bool $data){
|
||||
$this->license = $data;
|
||||
}
|
||||
|
||||
public function get_status(){
|
||||
return $this->license;
|
||||
}
|
||||
|
||||
public function the_lis() {
|
||||
|
||||
return true;
|
||||
|
||||
global $sheet_checker_pro;
|
||||
|
||||
$check = get_option('_sheetcheckerpro_license_check');
|
||||
|
||||
if(false !== $check && is_array($check)){
|
||||
return boolval($check['valid']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function check_license() {
|
||||
|
||||
global $sheet_checker_pro;
|
||||
|
||||
$check = get_option('_sheetcheckerpro_license_check');
|
||||
|
||||
if(false === $check) :
|
||||
$this->set_license(false);
|
||||
$license_valid = false;
|
||||
$license_detail = [
|
||||
'valid' => false,
|
||||
'messages' => [
|
||||
__('Activate License for getting started with <b>Onesender Broadcaster</b>!', SHEET_CHECKER_PRO_DOMAIN)
|
||||
]
|
||||
];
|
||||
else :
|
||||
$check = wp_parse_args($check, [
|
||||
'valid' => true,
|
||||
'detail' => [],
|
||||
'messages' => []
|
||||
]);
|
||||
|
||||
$license_valid = $check['valid'];
|
||||
$license_detail = $check;
|
||||
$this->set_license(true);
|
||||
endif;
|
||||
|
||||
$sheet_checker_pro['license'] = [
|
||||
'valid' => $license_valid,
|
||||
'detail' => $license_detail
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
public function check_license_routine() {
|
||||
$post_data = [
|
||||
'host' => $_SERVER['HTTP_HOST']
|
||||
];
|
||||
|
||||
$request_url = add_query_arg($post_data, SHEET_CHECKER_PRO_MEMBER.'/sejoli-validate-license/');
|
||||
$response = wp_remote_get($request_url);
|
||||
$json_result = json_decode(wp_remote_retrieve_body($response), true);
|
||||
$response_code = (int) wp_remote_retrieve_response_code($response);
|
||||
|
||||
if(200 === $response_code && isset($json_result['valid'])) :
|
||||
|
||||
if(true === boolval($json_result['valid'])) :
|
||||
|
||||
else:
|
||||
|
||||
delete_option('_sheetcheckerpro_license_check');
|
||||
|
||||
endif;
|
||||
|
||||
else :
|
||||
|
||||
array(
|
||||
'code' => $response_code,
|
||||
'message' => $response['response']['message']
|
||||
);
|
||||
|
||||
endif;
|
||||
|
||||
}
|
||||
|
||||
public function register_routine() {
|
||||
|
||||
if(false === wp_next_scheduled('sheetcheckerpro/license/check')) :
|
||||
wp_schedule_event(time(),'twicedaily','sheetcheckerpro/license/check');
|
||||
endif;
|
||||
|
||||
}
|
||||
|
||||
public function display_license_message() {
|
||||
|
||||
if(false === $this->the_lis()) :
|
||||
|
||||
global $sheet_checker_pro;
|
||||
|
||||
$license_form_link = add_query_arg([
|
||||
'post_type' => 'checker',
|
||||
'page' => 'sheetcheckerpro-license'
|
||||
], admin_url('edit.php'));
|
||||
return;
|
||||
?>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<div class="wrap">
|
||||
<div class="alert alert-dark d-flex align-items-center gap-2 alert-dismissible fade show" role="alert">
|
||||
<i class="fa-regular fa-circle-check"></i>
|
||||
<div>
|
||||
<p class="mb-0"><?php echo implode('<br />', $sheet_checker_pro['license']['detail']['messages']); ?></p>
|
||||
<p class="mb-0">
|
||||
<a href='<?php echo $license_form_link; ?>' class='button button-primary'>
|
||||
<?php _e('Activate Here', SHEET_CHECKER_PRO_DOMAIN); ?>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
endif;
|
||||
|
||||
if(isset($_GET['error']) && 'sheetcheckerpro-license-not-valid' === $_GET['error']) :
|
||||
?>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<div class="wrap">
|
||||
<div class="alert alert-danger d-flex align-items-center gap-2" role="alert">
|
||||
<i class="fa-regular fa-circle-exclamation"></i>
|
||||
<div>
|
||||
<p class="mb-0">Ups! Your license is not detected, have been used or expired. Please input another license code or get a new one. <a class="sheetcheckerpro-checkout-btn btn btn-primary" href="https://member.dwindi.com/product/onesender-broadcaster/">Get a license code</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
endif;
|
||||
|
||||
if(isset($_GET['success']) && 'sheetcheckerpro-license-valid' === $_GET['success']) :
|
||||
?>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<div class="wrap">
|
||||
<div class="alert alert-success d-flex align-items-center gap-2 alert-dismissible fade show" role="alert">
|
||||
<i class="fa-regular fa-circle-check"></i>
|
||||
<div>
|
||||
<p class="mb-0"><?php _e('Thank you! <b>Data Sheet Checker Pro</b> can be used now.'); ?></p>
|
||||
</div>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
endif;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function admin_menu_license() {
|
||||
$is_admin = current_user_can('manage_options');
|
||||
if ( $is_admin ) {
|
||||
if(false === $this->the_lis()) :
|
||||
add_submenu_page(
|
||||
'edit.php?post_type=checker',
|
||||
'License',
|
||||
'License',
|
||||
'manage_options',
|
||||
'sheetcheckerpro-license',
|
||||
[$this, 'display_license_page'],
|
||||
12
|
||||
);
|
||||
endif;
|
||||
}
|
||||
}
|
||||
|
||||
public function display_license_page() {
|
||||
require SHEET_CHECKER_PRO_PATH . 'templates/license.php';
|
||||
}
|
||||
|
||||
public function check_form() {
|
||||
|
||||
if(isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'sheetcheckerpro-input-license') && isset($_POST['data'])) :
|
||||
|
||||
$post_data = wp_parse_args($_POST['data'],[
|
||||
'user_email' => NULL,
|
||||
'user_pass' => NULL,
|
||||
'license' => NULL
|
||||
]);
|
||||
|
||||
$post_data['string'] = $_SERVER['HTTP_HOST'];
|
||||
$request_url = SHEET_CHECKER_PRO_MEMBER.'/sejoli-license/';
|
||||
$response = wp_remote_post($request_url, array(
|
||||
'timeout' => 120,
|
||||
'body' => $post_data
|
||||
));
|
||||
|
||||
if(is_wp_error($response)) :
|
||||
|
||||
wp_die(
|
||||
__( 'Something is happened because of your hosting. <br />Please contact your hosting provider and attach this message below:', SHEET_CHECKER_PRO_DOMAIN) . '<br /> <br />' .
|
||||
implode('<br />', $response->get_error_messages()),
|
||||
__( 'Cannot access license server', SHEET_CHECKER_PRO_DOMAIN)
|
||||
);
|
||||
|
||||
exit;
|
||||
else :
|
||||
$json_result = json_decode(wp_remote_retrieve_body($response), true);
|
||||
$response_code = intval(wp_remote_retrieve_response_code($response));
|
||||
|
||||
if(200 === $response_code) :
|
||||
|
||||
if(isset($json_result['valid']) && true === boolval($json_result['valid'])) :
|
||||
|
||||
update_option('_sheetcheckerpro_license_check', $json_result);
|
||||
|
||||
$theme_option_url = add_query_arg([
|
||||
'post_type' => 'checker',
|
||||
'success' => 'sheetcheckerpro-license-valid'
|
||||
], admin_url('edit.php'));
|
||||
|
||||
wp_redirect($theme_option_url);
|
||||
|
||||
|
||||
else :
|
||||
|
||||
$args = array();
|
||||
$args['post_type'] = 'checker';
|
||||
$args['error'] = 'sheetcheckerpro-license-not-valid';
|
||||
$args['messages'] = array_map('urlencode', array_map('strip_tags', $json_result['messages']));
|
||||
|
||||
wp_redirect(add_query_arg($args, admin_url('edit.php')));
|
||||
|
||||
endif;
|
||||
|
||||
// beside response code
|
||||
else :
|
||||
$args = array();
|
||||
$args['post_type'] = 'checker';
|
||||
$args['page'] = 'sheetcheckerpro-license';
|
||||
$args['error'] = 'sheetcheckerpro-license-not-valid';
|
||||
$args['messages'][] = sprintf( __('Error response code : %s. Cannot connect to license server', SHEET_CHECKER_PRO_DOMAIN), $response_code );
|
||||
|
||||
wp_redirect(add_query_arg($args, admin_url('admin.php')));
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
exit;
|
||||
|
||||
endif;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user