Skip to content

Commit

Permalink
Merge pull request #6 from G3ronim0/develop
Browse files Browse the repository at this point in the history
Release 1.0.4
  • Loading branch information
G3ronim0 authored Jun 16, 2016
2 parents f983950 + a315e56 commit de802a9
Show file tree
Hide file tree
Showing 22 changed files with 1,063 additions and 99 deletions.
24 changes: 23 additions & 1 deletion assets/css/wptxu-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,26 @@ div[id*=wptxu-input-] {
transform: rotate(359deg);
}

}
}

.wptxu-license-information {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}

.wptxu-vam {
vertical-align: middle;
}
51 changes: 51 additions & 0 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,55 @@ jQuery(document).ready(function($) {

});

$('#wptxu_license_activate').live( "click", function(e) {
e.preventDefault();

$.ajax({
type: "POST",
url: wptxu_ajax.ajaxurl,
data: {
'action': 'wptxu_activate_license',
'wptxu_nonce': wptxu_ajax.wptxu_nonce,
},
beforeSend: function(reponse) {
$('#wptxu-spinner-key').addClass('is-active');
},
success: function(response) {
$('#wptxu-spinner-key').removeClass('is-active');
$('#wptxu-key-response').html(response);
},
fail: function() {
$('h1').after('<div class="wptxu-error"><p>' + wptxu_ajax.ajax_fail.ajax_fail + '</p></div>');
}

});

});

$('#wptxu_license_deactivate').live( "click", function(e) {
e.preventDefault();

$.ajax({
type: "POST",
url: wptxu_ajax.ajaxurl,
data: {
'action': 'wptxu_deactivate_license',
'wptxu_nonce': wptxu_ajax.wptxu_nonce,
},
beforeSend: function(reponse) {
$('#wptxu-spinner-key').addClass('is-active');
},
success: function(response) {
$('#wptxu-spinner-key').removeClass('is-active');
$('#wptxu-key-response').html(response);
$('#wptxu-sl-key').val('');
$('h1').after('<div class="updated notice is-dismissible"><p>' + wptxu_ajax.license_deactivate.license_deactivate + '</p></div>');
},
fail: function() {
$('h1').after('<div class="wptxu-error"><p>' + wptxu_ajax.ajax_fail.ajax_fail + '</p></div>');
}
});

});

});
4 changes: 4 additions & 0 deletions inc/admin/enqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function wptxu_load_admin_assets() {

$translation_array = array(
'ajax_loading' => __( 'Check for update...', 'wpt-tx-updater' ),
'license_deactivate' => 'WPT tx updater : '.__( 'License deactivate', 'wpt-tx-updater' ),
'ajax_fail' => __( 'Please try again soon.', 'wpt-tx-updater' ),
);

wp_register_style( 'wptxu-styles', WPTXU_URL_ASSETS_CSS . 'wptxu-styles.css' );
Expand All @@ -22,6 +24,8 @@ function wptxu_load_admin_assets() {
wp_localize_script( 'wptxu-script', 'wptxu_ajax', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'ajax_loading' => $translation_array,
'license_deactivate' => $translation_array,
'ajax_fail' => $translation_array,
'wptxu_nonce' => wp_create_nonce( 'wptxu-nonce' ),
) );

Expand Down
9 changes: 9 additions & 0 deletions inc/admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ function wptxu_save_extra_profile_fields( $user_id ) {

} else {

$old = get_option( 'wptxu_sl_key' );

if ( $old && $old != $new ) {
delete_option( 'wptxu_license_status' );
delete_transient( '_wptxu_license_data' );
delete_transient( '_wptxu_license_error' );
}

update_usermeta( absint( $user_id ), 'wptxu_transifex_auth', base64_encode( $_POST['wptxu-tx-username'] . ':' . $_POST['wptxu-tx-password'] ) );
update_usermeta( absint( $user_id ), 'wptxu_transifex_user', $_POST['wptxu-tx-username'] );
update_option( 'wptxu_sl_key', $_POST['wptxu-sl-key'] );

}

Expand Down
49 changes: 49 additions & 0 deletions inc/admin/ui/actions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );

/**
* Ouput Activate license button
*
* @since 1.0.4
*/
function wptxu_action_add_license() {
?>

<div><button type="button" id="wptxu_license_activate" class="button-secondary"> <?php _e( 'Activate License', 'wpt-tx-updater' ); ?></button><span id="wptxu-spinner-key" class="spinner"></span></div>

<?php }

/**
* Ouput Deactivate license button and license informations
*
* @since 1.0.4
*/
function wptxu_action_remove_license( $expires ) {
$now = current_time( 'timestamp' );
$expiration = strtotime( $expires, current_time( 'timestamp' ) );
$key = get_option( 'wptxu-sl-key' );
$license = get_transient( '_wptxu_license_data' );

if ( 'lifetime' === $expires ) {
$expiration_message = __( 'License key never expires.', 'wpt-tx-updater' );
} elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
$expiration_message = sprintf(
__( 'Your license key expires soon! It expires on %s. <a href="%s" target="_blank" title="Renew license">Renew your license key</a>.', 'wpt-tx-updater' ),
date_i18n( 'j F Y', strtotime( $expires, current_time( 'timestamp' ) ) ),
WPTXU_STORE_URL.'/commander/?edd_license_key=' . $key
);
} else {
$expiration_message = sprintf(
__( 'Your license key expires on %s.', 'wpt-tx-updater' ),
date_i18n( 'j F Y', strtotime( $expires, current_time( 'timestamp' ) ) )
);
}

?>
<div class="wptxu-license-information">
<div><span class="wptxu-success dashicons dashicons-yes"></span> <?php _e( 'License active', 'wpt-tx-updater' ); ?></div>
<div><span class="dashicons dashicons-backup"></span> <?php echo $expiration_message; ?></strong></div>
<div><button type="button" id="wptxu_license_deactivate" class="button-secondary"><span class="wptxu-vam dashicons dashicons-no"></span> <?php _e( 'Deactivate License', 'wpt-tx-updater' ); ?></button><span id="wptxu-spinner-key" class="spinner"></span></div>
</div>

<?php }
1 change: 0 additions & 1 deletion inc/admin/ui/meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ function wptxu_metaboxes() {
add_meta_box( 'wptxu_project_meta_metaboxe', __( 'Project attributs', 'wpt-tx-updater' ), 'wptxu_project_attributs', 'wptxu-project', 'side', 'high' );

}

51 changes: 50 additions & 1 deletion inc/admin/ui/notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,53 @@ function wptxu_http_notices( $http_code ) {

return $notice;

}
}

/**
* Return notices for AJAX
*
* @since 1.0.4
*/
function wptxu_ajax_notices() {

$notice = get_transient( '_wptxu_license_error' );
$key = get_option( 'wptxu_sl_key' );

if ( $notice !== false ) {

switch ( $notice ) {

case 'expired' :
$message = sprintf(
__( 'Your license key expired. Please <a href="%s" target="_blank" title="Renew your license key">renew your license key</a>.', 'wpt-tx-updater' ),
WPTXU_STORE_URL.'/commander/?edd_license_key=' . $key
);
break;

case 'missing' :
$message = sprintf(
__( 'Invalid license. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> and verify it.', 'wpt-tx-updater' ),
WPTXU_STORE_URL.'/votre-compte'
);
break;

case 'invalid' :
case 'site_inactive' :
$message = sprintf( __( 'There was a problem activating your license key, please try again or contact support. Error code: %s', 'wpt-tx-updater' ), $notice );
break;

case 'item_name_mismatch' :
$message = __( 'This license does not belong to the product you have entered it for.', 'wpt-tx-updater' );
break;

case 'no_activations_left':
$message = sprintf( __( 'Your license key has reached its activation limit. <a href="%s">View possible upgrades</a> now.', 'wpt-tx-updater' ), WPTXU_STORE_URL.'/votre-compte' );
break;

}

return print_r($notice);

}

}
51 changes: 47 additions & 4 deletions inc/admin/ui/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,52 @@
add_action( 'edit_user_profile', 'wptxu_extra_profile_fields' );

function wptxu_extra_profile_fields( $user ) {

$license = get_option( 'wptxu_sl_key' );
$status = get_option( 'wptxu_license_status' );

?>

<h3 id="wptxu-transifex-account"><?php _e( 'transifex Account Informations', 'wpt-tx-updater' ); ?></h3>
<h2 id="wptxu-sl">WPT transifex updater</h2>

<table class="form-table">

<tr>
<th><label for="wptxu-sl-key"><?php _e( 'License key', 'wpt-tx-updater' ); ?></label></th>

<td>
<input type="password" name="wptxu-sl-key" id="wptxu-sl-key" value="<?php echo $license; ?>" class="regular-text" /><br />
<span class="description"><?php _e( 'Please enter your WPT transifex updater license key.', 'wpt-tx-updater' ); ?></span>
</td>
</tr>
<tr>
<th></th>
<td id="wptxu-key-response">

<?php

if ( false !== $license ) {

if ( $status !== false && $status == 'valid' ) {

$license_data = get_transient( '_wptxu_license_data' );
echo wptxu_action_remove_license( $license_data->expires );

} elseif ( $status === false or $status != 'invalid' ) {

echo wptxu_action_add_license();

}
}

?>

</td>
</tr>

</table>

<h2 id="wptxu-transifex-account"><?php _e( 'transifex Account Informations', 'wpt-tx-updater' ); ?></h2>

<table class="form-table">

Expand All @@ -36,15 +79,15 @@ function wptxu_extra_profile_fields( $user ) {
</td>
</tr>

<?php else : ?>
<?php else : ?>

<tr>
<th><?php _e( 'Connected as:&nbsp;', 'wpt-tx-updater' );?></th>
<td><?php echo get_the_author_meta( 'wptxu_transifex_user', $user->ID ); ?></td>
<td><?php echo get_the_author_meta( 'wptxu_transifex_user', $user->ID ); ?><input type="hidden" name="wptxu-tx-username" value="<?php echo get_the_author_meta( 'wptxu_transifex_user', $user->ID ); ?>"></td>
<td> <button type="submit" value="wptxu-tx-loggout" name="wptxu-tx-loggout" class="button button-secondary"><?php _e( 'Logout', 'wpt-tx-updater' ); ?></button></td>
</tr>

<?php endif; ?>
<?php endif; ?>

</table>
<?php }
48 changes: 48 additions & 0 deletions inc/api/wptxu-sl-api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );

/**
* Make a http call to EDD software licensing API
*
* @since 1.0.4
*
* @param (string) $action (activate_license|check_license|delete_license)
*/
function wptxu_sl_call( $action, $key ) {

if ( $action == 'activate_license' ) {
$api_params = array(
'edd_action' => $action,
'license' => $key,
'item_name' => urlencode( WPTXU_SLUG ), // The name of our product in EDD.
'url' => home_url(),
);
} else {
$api_params = array(
'edd_action' => $action,
'license' => $key,
'item_name' => urlencode( WPTXU_SLUG ),
);
}

$args = array(
'timeout' => 30,
'sslverify' => false,
'body' => $api_params,
);

// Call the custom API.
$remote_call = wp_remote_post( add_query_arg( $api_params, WPTXU_STORE_URL ), $args );

// Make sure the response came back okay.
if ( is_wp_error( $remote_call ) ) {
$error_message = sprintf( __( '<p class="wptxu-error"><span class="dashicons dashicons-info"></span>There is a problem with remote site, please try again. %s</p>', 'wpt-tx-updater' ), $remote_call->get_error_message() );
return $error_message;
} else {
// Decode the license data.
$license_data = json_decode( wp_remote_retrieve_body( $remote_call ) );
}

return $license_data;

}
8 changes: 3 additions & 5 deletions inc/classes/wptxu-translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ public function __construct( $project_id, $tx_infos, $project_type, $text_domain
$this->content = $content;

if( get_post_meta( $this->project_id, 'wptxu_mo_filename', true ) ) {
$this->filename = get_post_meta( $this->project_id, 'wptxu_mo_filename', true );
} else {
$this->filename = $text_domain;
$this->text_domain = get_post_meta( $this->project_id, 'wptxu_mo_filename', true );
}

if( $this->project_type == 'plugins') {

$this->text_domain_path = WPTXU_CONTENT_PATH . '/' . $this->project_type . '/' . $this->text_domain . '/' . $this->lang_code . '/';
$this->po_file_path = $this->text_domain_path . $this->filename . '-' . $this->lang_code . '.po';
$this->mo_file_path = $this->text_domain_path . $this->filename . '-' . $this->lang_code . '.mo';
$this->po_file_path = $this->text_domain_path . $this->text_domain . '-' . $this->lang_code . '.po';
$this->mo_file_path = $this->text_domain_path . $this->text_domain . '-' . $this->lang_code . '.mo';

} else {

Expand Down
Loading

0 comments on commit de802a9

Please sign in to comment.