Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class IELMS_options_interface
- {
- var $licence;
- function __construct()
- {
- $this->licence = new IELMS_licence();
- if (isset($_GET['page']) && ($_GET['page'] == 'main-lms-data' ) )
- {
- add_action( 'init', array($this, 'options_update'), 1 );
- }
- add_action( 'admin_menu', array($this, 'admin_menu') );
- if(!$this->licence->licence_key_verify())
- {
- add_action('admin_notices', array($this, 'admin_no_key_notices'));
- }
- }
- function __destruct()
- {
- }
- function admin_menu()
- {
- if(!$this->licence->licence_key_verify())
- {
- add_menu_page(
- 'Export LMS Data', //Page Title
- 'Import-Export LMS Data', //Menu Title
- 'manage_options', //Capability
- 'main-lms-data', //Menu slug
- array($this,'licence_form'),
- 'dashicons-admin-tools' //Callback to print html
- );
- $hookID = add_submenu_page(
- 'main-lms-data',
- 'Export LMS Data', //page title
- 'License Manager', //menu title
- 'manage_options', //capability,
- 'main-lms-data',//menu slug
- array($this,'licence_form'),
- );
- }
- else
- {
- add_menu_page(
- 'Export LMS Data', //Page Title
- 'Import-Export LMS Data', //Menu Title
- 'manage_options', //Capability
- 'main-lms-data', //Menu slug
- array($this,'licence_deactivate_form'),
- 'dashicons-admin-tools' //Callback to print html
- );
- $hookID = add_submenu_page(
- 'main-lms-data',
- 'Export LMS Data', //page title
- 'License Manager', //menu title
- 'manage_options', //capability,
- 'main-lms-data',//menu slug
- array($this,'licence_deactivate_form'),
- );
- }
- add_action('load-' . $hookID , array($this, 'load_dependencies'));
- add_action('load-' . $hookID , array($this, 'admin_notices'));
- add_action('admin_print_styles-' . $hookID , array($this, 'admin_print_styles'));
- add_action('admin_print_scripts-' . $hookID , array($this, 'admin_print_scripts'));
- }
- function options_interface()
- {
- if(!$this->licence->licence_key_verify() && !is_multisite())
- {
- $this->licence_form();
- return;
- }
- if(!$this->licence->licence_key_verify() && is_multisite())
- {
- $this->licence_multisite_require_nottice();
- return;
- }
- }
- function options_update()
- {
- if (isset($_POST['slt_licence_form_submit']))
- {
- $this->licence_form_submit();
- return;
- }
- }
- function load_dependencies()
- {
- }
- function admin_notices()
- {
- global $slt_form_submit_messages;
- if($slt_form_submit_messages == '')
- return;
- $messages = $slt_form_submit_messages;
- if(count($messages) > 0)
- {
- echo "<div id='notice' class='updated fade'><p>". implode("</p><p>", $messages ) ."</p></div>";
- }
- }
- function admin_print_styles()
- {
- wp_register_style( 'import-export-lms-data_admin', IELMS_URL . '/includes/licensing/css/admin.css' );
- wp_enqueue_style( 'import-export-lms-data_admin' );
- }
- function admin_print_scripts()
- {
- }
- function admin_no_key_notices()
- {
- if ( !current_user_can('manage_options'))
- return;
- $screen = get_current_screen();
- if(isset($screen->id) && $screen->id == 'toplevel_page_main-lms-data')
- return;
- ?><div class="updated fade"><p><?php _e( "Import-Export LMS Data is inactive, please enter your", 'import-export-lms-data' ) ?> <a href="admin.php?page=main-lms-data"><?php _e( "Licence Key", 'import-export-lms-data' ) ?></a></p></div><?php
- }
- function licence_form_submit()
- {
- global $slt_form_submit_messages;
- //check for de-activation
- if (isset($_POST['slt_licence_form_submit']) && isset($_POST['slt_licence_deactivate']) && wp_verify_nonce($_POST['slt_license_nonce'],'slt_license'))
- {
- global $slt_form_submit_messages;
- $license_data = IELMS_licence::get_licence_data();
- $license_key = $license_data['key'];
- //build the request query
- $args = array(
- 'woo_sl_action' => 'deactivate',
- 'licence_key' => $license_key,
- 'product_unique_id' => IELMS_PRODUCT_ID,
- 'domain' => IELMS_INSTANCE
- );
- $request_uri = IELMS_APP_API_URL . '?' . http_build_query( $args , '', '&');
- $data = wp_remote_get( $request_uri );
- if(is_wp_error( $data ) || $data['response']['code'] != 200)
- {
- $slt_form_submit_messages[] .= __('There was a problem connecting to ', 'import-export-lms-data') . IELMS_APP_API_URL;
- return;
- }
- $response_block = json_decode($data['body']);
- //retrieve the last message within the $response_block
- $response_block = $response_block[count($response_block) - 1];
- $response = $response_block->message;
- if(isset($response_block->status))
- {
- if($response_block->status == 'success' && $response_block->status_code == 's201')
- {
- //the license is active and the software is active
- $slt_form_submit_messages[] = $response_block->message;
- $license_data = IELMS_licence::get_licence_data();
- //save the license
- $license_data['key'] = '';
- $license_data['last_check'] = time();
- IELMS_licence::update_licence_data( $license_data );
- }
- else //if message code is e104 force de-activation
- if ($response_block->status_code == 'e002' || $response_block->status_code == 'e104')
- {
- $license_data = IELMS_licence::get_licence_data();
- //save the license
- $license_data['key'] = '';
- $license_data['last_check'] = time();
- IELMS_licence::update_licence_data( $license_data );
- }
- else
- {
- $slt_form_submit_messages[] = __('There was a problem deactivating the licence: ', 'import-export-lms-data') . $response_block->message;
- return;
- }
- }
- else
- {
- $slt_form_submit_messages[] = __('There was a problem with the data block received from ' . IELMS_APP_API_URL, 'import-export-lms-data');
- return;
- }
- //redirect
- $current_url = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
- wp_redirect($current_url);
- die();
- }
- if (isset($_POST['slt_licence_form_submit']) && wp_verify_nonce($_POST['slt_license_nonce'],'slt_license'))
- {
- $license_key = isset($_POST['license_key'])? sanitize_key(trim($_POST['license_key'])) : '';
- if($license_key == '')
- {
- $slt_form_submit_messages[] = __("Licence Key can't be empty", 'import-export-lms-data');
- return;
- }
- //build the request query
- $args = array(
- 'woo_sl_action' => 'activate',
- 'licence_key' => $license_key,
- 'product_unique_id' => IELMS_PRODUCT_ID,
- 'domain' => IELMS_INSTANCE
- );
- $request_uri = IELMS_APP_API_URL . '?' . http_build_query( $args , '', '&');
- $data = wp_remote_get( $request_uri );
- if(is_wp_error( $data ) || $data['response']['code'] != 200)
- {
- $slt_form_submit_messages[] .= __('There was a problem connecting to ', 'import-export-lms-data') . IELMS_APP_API_URL;
- return;
- }
- $response_block = json_decode($data['body']);
- if ( ! is_array ( $response_block ) )
- {
- $slt_form_submit_messages[] = __('There was a problem with the data block received from ' . IELMS_APP_API_URL, 'import-export-lms-data');
- return;
- }
- //retrieve the last message within the $response_block
- $response_block = $response_block[count($response_block) - 1];
- $response = $response_block->message;
- if(isset($response_block->status))
- {
- if( $response_block->status == 'success' && ( $response_block->status_code == 's100' || $response_block->status_code == 's101' ) )
- {
- //the license is active and the software is active
- $slt_form_submit_messages[] = $response_block->message;
- $license_data = IELMS_licence::get_licence_data();
- //save the license
- $license_data['key'] = $license_key;
- $license_data['last_check'] = time();
- IELMS_licence::update_licence_data( $license_data );
- }
- else
- {
- $slt_form_submit_messages[] = __('There was a problem activating the licence: ', 'import-export-lms-data') . $response_block->message;
- return;
- }
- }
- else
- {
- $slt_form_submit_messages[] = __('There was a problem with the data block received from ' . IELMS_APP_API_URL, 'import-export-lms-data');
- return;
- }
- //redirect
- $current_url = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
- wp_redirect($current_url);
- die();
- }
- }
- function licence_form()
- {
- ?>
- <div class="wrap">
- <div id="icon-settings" class="icon32"></div>
- <div id="form_data">
- <h3><?php _e( "Licence", 'import-export-lms-data' ) ?></h3>
- <form name="form" method="post">
- <?php wp_nonce_field('slt_license','slt_license_nonce'); ?>
- <input type="hidden" name="slt_licence_form_submit" value="true" />
- <div class="start-container licence-key">
- <div class="text">
- <h2><?php _e( "License Key", 'import-export-lms-data' ) ?></h2>
- <div class="option">
- <div class="controls">
- <p><input type="text" value="" name="license_key" class="text-input"></p>
- </div>
- <div class="explain"><?php _e( "Enter the Licence Key you received when purchased this product. If you lost the key, you can always retrieve it from", 'import-export-lms-data' ) ?> <a href="https://terradigita.com/my-account/" target="_blank"><?php _e( "My Account", 'import-export-lms-data' ) ?></a></div>
- </div>
- <p class="submit">
- <input type="submit" name="Submit" class="button-primary" value="<?php _e('Save', 'import-export-lms-data') ?>">
- </p>
- </div>
- </div>
- </form>
- </div>
- </div>
- <?php
- }
- function licence_deactivate_form()
- {
- $licence_data = IELMS_licence::get_licence_data();
- ?>
- <div class="wrap">
- <div id="form_data">
- <h3><?php _e( "Licence", 'wp-hide-security-enhancer' ) ?></h3>
- <form name="form" method="post">
- <?php wp_nonce_field('slt_license','slt_license_nonce'); ?>
- <input type="hidden" name="slt_licence_form_submit" value="true" />
- <input type="hidden" name="slt_licence_deactivate" value="true" />
- <div class="start-container licence-key">
- <div class="text">
- <h2><?php _e( "License Key", 'import-export-lms-data' ) ?></h2>
- <div class="option">
- <div class="controls">
- <p><b><?php echo substr($licence_data['key'], 0, 20) ?>-xxxxxxxx-xxxxxxxx</b> <a class="button-secondary" title="Deactivate" href="javascript: void(0)" onclick="jQuery(this).closest('form').submit();"><?php _e( "Deactivate", 'wp-hide-security-enhancer' ) ?></a></p>
- </div>
- <div class="explain"><?php _e( "You can generate more keys at ", 'import-export-lms-data' ) ?> <a href="https://terradigita.com/my-account/" target="_blank"><?php _e( "My Account", 'import-export-lms-data' ) ?></a></div>
- </div>
- <?php
- if ( isset( $licence_data ) && ! empty ( $licence_data['licence_status'] ) )
- {
- ?><br /><p><?php _e( "License Status", 'wp-hide-security-enhancer' ) ?>: <b><?php echo ucfirst( __( $licence_data['licence_status'], 'import-export-lms-data' ) ); ?></b></p><?php
- }
- if ( isset( $licence_data ) && ! empty ( $licence_data['licence_expire'] ) )
- {
- ?><p><?php _e( "License Expiration", 'import-export-lms-data' ) ?>: <b><?php echo date_i18n( get_option( 'date_format' ), strtotime( $licence_data['licence_expire'] ) ); ?></b><?php
- if ( strtotime( $licence_data['licence_expire'] ) < strtotime( date('Y-m-d') ) )
- {
- ?> <span class="warning"><?php _e( "Licence is expired, plugin <b>Updates</b> and <b>Support</b> are not available", 'import-export-lms-data' ) ?>.</span><?php
- }
- ?></p><?php
- }
- ?>
- </div>
- </div>
- </form>
- </div>
- </div>
- <?php
- }
- function licence_multisite_require_nottice()
- {
- ?>
- <div class="wrap">
- <h1><?php _e( "Software License", 'import-export-lms-data' ) ?><br /> </h1>
- <div id="form_data">
- <div class="postbox">
- <div class="section section-text ">
- <h4 class="heading"><?php _e( "License Key Required", 'import-export-lms-data' ) ?>!</h4>
- <div class="option">
- <div class="explain"><?php _e( "Enter the License Key you got when bought this product. If you lost the key, you can always retrieve it from", 'import-export-lms-data' ) ?> <a href="http://www.nsp-code.com/premium-plugins/my-account/" target="_blank"><?php _e( "My Account", 'import-export-lms-data' ) ?></a><br />
- <?php _e( "More keys can be generate from", 'import-export-lms-data' ) ?> <a href="http://www.nsp-code.com/premium-plugins/my-account/" target="_blank"><?php _e( "My Account", 'import-export-lms-data' ) ?></a>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <?php
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement