Skip to content

Commit

Permalink
[ #401 ] Alt server & license tab
Browse files Browse the repository at this point in the history
  • Loading branch information
TeoAlex committed Jun 14, 2023
1 parent b8dc0c0 commit 13e2835
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 41 deletions.
146 changes: 113 additions & 33 deletions admin/class-strong-testimonials-addons.php
Expand Up @@ -15,6 +15,9 @@ public function __construct() {
add_action( 'wp_ajax_wpmtst_reload_extensions', array( $this, 'reload_extensions' ), 20 );

add_filter( 'wpmtst_addon_button_action', array( $this, 'output_download_link' ), 5 );

add_action( 'wpmtst_settings_tabs', array( $this, 'register_tab' ), 1, 2 );
add_filter( 'wpmtst_settings_callbacks', array( $this, 'register_settings_page' ) );
}

private function check_for_addons() {
Expand Down Expand Up @@ -113,7 +116,6 @@ public function addons_page() {
<a id="wpmtst-reload-extensions" class="button button-primary" style="margin: 10px 0 0 30px;" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wpmtst-reload-extensions' ) ); ?>"><?php esc_html_e( 'Reload Extensions', 'strong-testimonials' ); ?></a>

<?php $this->display_extension_tab(); ?>
<?php $this->render_license(); ?>
<div class="wpmtst-addons-container">
<?php $this->render_addons(); ?>
</div>
Expand Down Expand Up @@ -184,18 +186,45 @@ public function get_addons() {
return $this->check_for_addons();
}

/**
* Register settings tab.
*
* @param $active_tab
* @param $url
*/
public function register_tab( $active_tab, $url ) {
printf( '<a href="%s" class="nav-tab %s">%s</a>',
esc_url( add_query_arg( 'tab', 'license', $url ) ),
esc_attr( $active_tab == 'license' ? 'nav-tab-active' : '' ),
esc_html__( 'License', 'strong-testimonials' )
);
}

/**
* Register settings page.
*
* @param $pages
*
* @return mixed
*/
public function register_settings_page( $pages ) {
$pages[ 'license' ] = array( $this, 'render_license' );

return $pages;
}

/**
* Render the license field.
*
* @return void
*/
public function render_license() {

$license = get_option( 'strong_testimonials_license_key' );
$email = get_option( 'strong_testimonials_email' );
$status = get_option( 'strong_testimonials_license_status', false );

$messages = array(
$license = get_option( 'strong_testimonials_license_key' );
$email = get_option( 'strong_testimonials_email' );
$status = get_option( 'strong_testimonials_license_status', false );
$alt_server = get_option( 'strong_testimonials_alt_server', false );
$messages = array(
'no-license' => esc_html__( 'Enter your license key', 'strong-testimonials-assignment' ),
'activate-license' => esc_html__( 'Activate your license key', 'strong-testimonials-assignment' ),
'all-good' => __( 'Your license is active until <strong>%s</strong>', 'strong-testimonials-assignment' ),
Expand Down Expand Up @@ -240,39 +269,90 @@ public function render_license() {
}

?>
<div class="row">
<?php do_action( 'wpmtst_license_errors' ); ?>



<h2><?php esc_html_e( 'License', 'strong-testimonials' ); ?></h2>
<?php do_action( 'wpmtst_license_errors' ); ?>
<?php
$valid_license = false;
if ( false !== $license && $status && 'valid' === $status->license ) {
$valid_license = true;
}
?>
?>
<table class="form-table wpmtst_license_table" cellpadding="0" cellspacing="0">

<tr valign="top">
<th scope="row">
<?php esc_html_e( 'Email Address', 'strong-testimonials' ); ?>
</th>
<td>
<fieldset>

<input type="email" id="strong_testimonials_email" name="strong_testimonials_email" value="<?php echo esc_attr( $email ); ?>">
<p class="description"><?php esc_html_e( 'The email address used for license aquisition.', 'strong-testimonials' ); ?></p>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row">
<?php esc_html_e( 'License Key', 'strong-testimonials' ); ?>
</th>
<td>
<fieldset>

<input type="password" id="strong_testimonials_license_key" name="strong_testimonials_license_key" value="<?php echo esc_attr( $license ); ?>"> <a href="#" target="_blank" id="st-forgot-license" data-nonce="<?php echo esc_attr( wp_create_nonce( 'strong_testimonials_license_nonce' ) ); ?>"><?php esc_html_e( 'Forgot your license?', 'strong-testimonials' ); ?></a><br>
<p class="description"><?php echo wp_kses_post( $license_message ); ?></p>

<input type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'strong_testimonials_license_nonce' ) ); ?>"/>

<label class="description strong-testimonials-license-label" for="strong_testimonials_license_key"></label>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row">
<?php esc_html_e( 'Use Alternative Server', 'strong-testimonials' ); ?>
</th>
<td>
<fieldset>
<div class="wpmtst-toggle">
<input class="wpmtst-toggle__input" type="checkbox"
data-setting="strong_testimonials_alt_server"
id="strong_testimonials_alt_server"
name="strong_testimonials_alt_server"
value="1" <?php checked( $alt_server, 'true', 'false' ); ?>>
<div class="wpmtst-toggle__items">
<span class="wpmtst-toggle__track"></span>
<span class="wpmtst-toggle__thumb"></span>
<svg class="wpmtst-toggle__off" width="6" height="6" aria-hidden="true" role="img"
focusable="false" viewBox="0 0 6 6">
<path d="M3 1.5c.8 0 1.5.7 1.5 1.5S3.8 4.5 3 4.5 1.5 3.8 1.5 3 2.2 1.5 3 1.5M3 0C1.3 0 0 1.3 0 3s1.3 3 3 3 3-1.3 3-3-1.3-3-3-3z"></path>
</svg>
<svg class="wpmtst-toggle__on" width="2" height="6" aria-hidden="true" role="img"
focusable="false" viewBox="0 0 2 6">
<path d="M0 0h2v6H0z"></path>
</svg>
</div>
</div>
<p class="description">
<?php esc_html_e( 'Sometimes there can be problems with the activation server, in which case please try the alternative one.', 'strong-testimonials' ); ?>
</p>
</fieldset>
</td>
</tr>
<tr valign="top" <?php echo ( !isset( $options['disable_rewrite'] ) || '1' != $options['disable_rewrite'] ) ? '' : 'style="display:none;"'; ?> data-setting="single_testimonial_slug" >
<th scope="row">
<?php esc_html_e( 'Action', 'strong-testimonials' ); ?>
</th>
<td>
<button class="button button-primary" id="st-master-license-btn" data-action="<?php echo ( ! $valid_license ) ? 'activate' : 'deactivate'; ?>"><?php ( ! $valid_license ) ? esc_html_e( 'Activate', 'strong-testimonials' ) : esc_html_e( 'Deactivate', 'strong-testimonials' ); ?></button>
</td>
</tr>

</table>


<div class="wpmtst-master-license">
<div>
<label for="strong_testimonials_email"><?php esc_html_e( 'Email', 'strong-testimonials' ); ?></label>
<input type="email" id="strong_testimonials_email" name="strong_testimonials_email"
value="<?php echo esc_attr( $email ); ?>">
<label for="st-master-license"><?php esc_html_e( 'License key', 'strong-testimonials' ); ?></label>
<input type="password" id="strong_testimonials_license_key" name="strong_testimonials_license_key"
value="<?php echo esc_attr( $license ); ?>">
<input type="hidden"
value="<?php echo esc_attr( wp_create_nonce( 'strong_testimonials_license_nonce' ) ); ?>"/>
<button class="button button-primary" id="st-master-license-btn"
data-action="<?php echo ( ! $valid_license ) ? 'activate' : 'deactivate'; ?>"><?php ( ! $valid_license ) ? esc_html_e( 'Activate', 'strong-testimonials' ) : esc_html_e( 'Deactivate', 'strong-testimonials' ); ?></button>

&nbsp;<a href="#" target="_blank" id="st-forgot-license"
data-nonce="<?php echo esc_attr( wp_create_nonce( 'strong_testimonials_license_nonce' ) ); ?>"><?php esc_html_e( 'Forgot your license?', 'strong-testimonials' ); ?></a>
</div>
<label class="description strong-testimonials-license-label"
for="strong_testimonials_license_key">
<?php
echo wp_kses_post( $license_message );
?>
</label>
</div>
</div>
<?php
}

Expand Down
12 changes: 10 additions & 2 deletions admin/class-strong-testimonials-license-activator.php
Expand Up @@ -132,6 +132,8 @@ public function force_license_activation( $regular_action = false, $extensions =
}
}

$store_url = ( 'false' !== get_option( 'strong_testimonials_alt_server', 'false' ) ) ? WPMTST_ALT_STORE_URL : WPMTST_STORE_URL;

// data to send in our API request.
$api_params = array(
'edd_action' => 'activate_license',
Expand All @@ -144,7 +146,7 @@ public function force_license_activation( $regular_action = false, $extensions =

// Call the custom API.
$response = wp_remote_post(
WPMTST_STORE_URL,
$store_url,
array(
'timeout' => 15,
'sslverify' => false,
Expand Down Expand Up @@ -242,6 +244,8 @@ public function force_license_deactivation( $regular_action = false, $extensions
}
}

$store_url = ( 'false' !== get_option( 'strong_testimonials_alt_server', 'false' ) ) ? WPMTST_ALT_STORE_URL : WPMTST_STORE_URL;

// data to send in our API request.
$api_params = array(
'edd_action' => 'deactivate_license',
Expand All @@ -254,7 +258,7 @@ public function force_license_deactivation( $regular_action = false, $extensions

// Call the custom API.
$response = wp_remote_post(
WPMTST_STORE_URL,
$store_url,
array(
'timeout' => 15,
'sslverify' => false,
Expand Down Expand Up @@ -405,6 +409,10 @@ public function ajax_license_action() {
);
}

if ( isset( $_POST['alt_server'] ) ) {
update_option( 'strong_testimonials_alt_server', sanitize_text_field( $_POST['alt_server'] ) );
}

$action = sanitize_text_field( $_POST['click_action'] );

if ( 'activate' === $action ) {
Expand Down
10 changes: 6 additions & 4 deletions admin/js/admin-global.js
Expand Up @@ -39,15 +39,17 @@ jQuery(document).ready(function ($) {
action = target.data('action'),
nextAction = ('activate' === action) ? 'deactivate' : 'activate',
nextText = ('activate' === action) ? wpmtst_admin.deactivate : wpmtst_admin.activate,
nonce = target.parent().find('input[type="hidden"]').val(),
nonce = target.closest('table.wpmtst_license_table').find('input[type="hidden"]').val(),
license = jQuery('input#strong_testimonials_license_key').val(),
email = jQuery('input#strong_testimonials_email').val(),
label = target.parents('.wpmtst-master-license').find('.strong-testimonials-license-label'),
alt_server = jQuery('input#strong_testimonials_alt_server').is(':checked'),
label = target.closest('table.wpmtst_license_table').find('.strong-testimonials-license-label'),
data = {
action : 'wpmtst_license_action',
nonce : nonce,
license : license,
email : email,
alt_server : alt_server,
click_action: action
},
buttonText = ('deactivate' === action) ? wpmtst_admin.deactivating : wpmtst_admin.activating;
Expand Down Expand Up @@ -84,8 +86,8 @@ jQuery(document).ready(function ($) {

const target = jQuery(event.target),
nonce = target.data('nonce'),
email = target.parent().find('input[type="email"]').val(),
label = target.parents('.wpmtst-master-license').find('.strong-testimonials-license-label'),
email = target.closest('table.wpmtst_license_table').find('input[type="email"]').val(),
label = target.closest('table.wpmtst_license_table').find('.strong-testimonials-license-label'),
buttonText = target.text(),
actionText = wpmtst_admin.retrieving_data;

Expand Down
98 changes: 97 additions & 1 deletion assets/css/admin.css
Expand Up @@ -908,4 +908,100 @@ p.wpmtst-onboarding-doc a:hover {
p.wpmtst-onboarding-doc > a {
text-decoration: none;
color: #219962;
}
}

/* Toggles */
.wpmtst-toggle {
position: relative;
position: relative;
user-select: none;
display: inline-block;
}

.wpmtst-toggle__items {
box-sizing: border-box;
display: inline-block;
position: relative;
}
.wpmtst-toggle__items > * {
box-sizing: inherit;
}

.wpmtst-toggle__input[type=checkbox],
body .media-modal-content .attachment-details .wpmtst-toggle__input[type=checkbox] {
border-radius: 2px;
border: 2px solid #6c7781;
margin-right: 12px;
transition: none;
height: 100%;
left: 0;
top: 0;
margin: 0;
padding: 0;
opacity: 0;
position: absolute;
width: 100%;
z-index: 1; }

.wpmtst-toggle__track,
body .media-modal-content .attachment-details .wpmtst-toggle__track {
background-color: #fff;
border: 2px solid #6c7781;
border-radius: 9px;
display: inline-block;
height: 18px;
width: 36px;
vertical-align: top;
transition: background .2s ease; }

.wpmtst-toggle__thumb,
body .media-modal-content .attachment-details .wpmtst-toggle__thumb {
background-color: #6c7781;
border: 5px solid #6c7781;
border-radius: 50%;
display: block;
height: 10px;
width: 10px;
position: absolute;
left: 4px;
top: 4px;
transition: transform .2s ease; }

body .media-modal-content .attachment-details .wpmtst-toggle__thumb,
body .media-modal-content .attachment-details .wpmtst-toggle__track {
min-width:auto;
min-height:auto;
float:none;
padding:0;
}

.wpmtst-toggle__off {
position: absolute;
right: 6px;
top: 6px;
color: #6c7781;
fill: currentColor; }

.wpmtst-toggle__on {
position: absolute;
top: 6px;
left: 8px;
border: 1px solid #fff;
outline: 1px solid transparent;
outline-offset: -1px;
display: none; }

.wpmtst-toggle__input[type=checkbox]:checked + .wpmtst-toggle__items .wpmtst-toggle__track {
background-color: #11a0d2;
border: 9px solid transparent; }

.wpmtst-toggle__input[type=checkbox]:checked + .wpmtst-toggle__items .wpmtst-toggle__thumb {
background-color: #fff;
border-width: 0;
transform: translateX(18px); }

.wpmtst-toggle__input[type=checkbox]:checked + .wpmtst-toggle__items .wpmtst-toggle__off {
display: none; }

.wpmtst-toggle__input[type=checkbox]:checked + .wpmtst-toggle__items .wpmtst-toggle__on {
display: inline-block; }

0 comments on commit 13e2835

Please sign in to comment.