* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
/**
* Licensing Manager Page
*
* License page is a place where a user can check updated and manage the license.
*
* @since 1.0.0
*/
class OnpLicensing325_LicenseManagerPage extends FactoryPages321_AdminPage {
public $id = 'license-manager';
public $purchasePrice = '$';
/**
* If true, offers to activate a trial version.
*
* @since 3.1.1
* @var boolean
*/
public $trial = true;
/**
* If true, shows hits regarding where the user can get a key linked with CodeCanyon.
*
* @since 3.1.1
* @var boolean
*/
public $codecanyon = true;
/**
* If true, shows the FAQ section.
*
* @since 3.1.1
* @var boolean
*/
public $faq = true;
/**
* If true, then tells how to activate a 'premium version',
* otherwise tells how to activate 'plugin'.
* @since 3.1.1
* @var boolean
*/
public $premium = true;
public function __construct( $plugin) {
parent::__construct($plugin);
if ( !$this->menuTitle ) $this->menuTitle = __('License Manager', 'onp_licensing_325');
// turns off the license manager if we use the embedded license key
if ( $plugin->license && $plugin->license->isEmbedded() ) {
$this->hidden = true;
}
$this->site = site_url();
$this->domain = parse_url( $this->site, PHP_URL_HOST );
}
/**
* [MAGIC] Magic method that configures assets for a page.
*/
public function assets($scripts, $styles) {
$this->styles->request( array(
'bootstrap.core'
), 'bootstrap' );
$this->styles->add(ONP_LICENSING_325_URL . '/assets/css/license-manager.css');
$this->scripts->add(ONP_LICENSING_325_URL . '/assets/js/license-manager.js');
}
// ------------------------------------------------------------------
// Page Actions
// ------------------------------------------------------------------
/**
* Shows current license type.
*/
public function indexAction() {
$licenseManager = $license = $this->plugin->license;
$updatesManager = $this->plugin->updates;
$licenseKey = isset( $_POST['licensekey'] ) ? trim( $_POST['licensekey'] ) : null;
$scope = isset( $_GET['scope'] ) ? $_GET['scope'] : null;
$error = $response = null;
// processing a form submission for activation a key
if ( isset( $_POST['licensekey'] ) ) {
$scope = 'submit-key';
$licenseKey = trim( $_POST['licensekey'] );
if ( empty( $licenseKey ) ) {
$error = new WP_Error('FORM:KeyEmpty', __('Please enter your license key to continue.', 'onp_licensing_325'));
} else {
$response = $licenseManager->activateKey( $licenseKey );
if ( is_wp_error( $response ) ) $error = $response;
else $licenseKey = null;
}
// displaying results of other actions (deletion of a key, checking updates and so on)
} else {
$code = isset( $_GET['code'] ) ? $_GET['code'] : null;
$message = isset( $_GET['message'] ) ? $_GET['message'] : null;
if ( $code && $message ) $error = new WP_Error($code, urldecode ( base64_decode($message) ) );
}
// preparing some data to display
$licenseData = $licenseManager->data;
$remained = round( ( $licenseData['Expired'] - time() ) / (60 * 60 * 24), 2 );
$isInfinity = empty( $licenseData['Expired']);
// preparing an error data to dispaly
if ( $error ) {
$parts = explode( ':', $error->get_error_code() );
$errorSource = $parts[0];
}
// creating a customer account if it's required
if ( $response && !$error && ( isset( $licenseManager->data['KeyBound'] ) && !$licenseManager->data['KeyBound'] ) ) {
$this->redirectToAction('createAccount', array('onp_ref' => 'key-activation'));
}
if ( $response && !$error && ( isset( $licenseManager->data['KeyBound'] ) && $licenseManager->data['KeyBound'] ) ) {
$this->redirectToAction('finish');
}
?>
showError($error, $scope) ?>
Plugins page and update the plugin to complete deletion if it\'s needed.', 'onp_licensing_325') ?>
isActualVersion() ) { ?>
needChangeAssembly() ) { ?>
Click here to get the update.', 'onp_licensing_325'), $this->plugin->license->build ) ?>
Click here to get the update.', 'onp_licensing_325'),
$updatesManager->lastCheck['Build'] . '-' . $updatesManager->lastCheck['Version'] ) ?>
hasUpgrade() ) { ?>
purchasePrice ) ) { ?>
purchasePrice ) ?>
plugin->pluginTitle ) ) { ?>
plugin->pluginTitle ) ?>
hasKey() ) { ?>
hasKey() ) { ?>
data['Build'] !== 'free' ) { ?>
data['Category'] == 'free' ) { ?>
codecanyon ) { ?>
Click here.', 'onp_licensing_325') ?>
trial ) { ?>
trial version for 7 days to test the plugin on this site.', 'onp_licensing_325'), $this->getActionUrl('activateTrial') ) ?>
data['Category'] == 'free' ) { ?>
activate a premium version for a trial period (7 days).', 'onp_licensing_325'), $this->getActionUrl('activateTrial') ) ?>
here to learn more about the premium version.', 'onp_licensing_325'), onp_licensing_325_get_purchase_url( $this->plugin ) ) ?>
data['Build'] !== 'free' ) { ?>
isVersionChecked() ) { ?>
lastCheck['Checked'] ) ) { ?>
%1$s.', 'onp_licensing_325'), date( 'g:i a, j M y', $updatesManager->lastCheck['Checked'] ) ) ?>
never.', 'onp_licensing_325') ?>
isActualVersion() ) { ?>
%1$s, you use the up-to-date version. ', 'onp_licensing_325'), date( 'g:i a, j M y', $updatesManager->lastCheck['Checked'] ) ) ?>
%1$s,
%2$s. ', 'onp_licensing_325'), date( 'g:i a, j M y', $updatesManager->lastCheck['Checked'] ), $updatesManager->lastCheck['Version'] ) ?>
here to check updates manually.', 'onp_licensing_325'), $this->getActionUrl('checkUpdates') ) ?>
[ ]
faq ) { ?>
-
-
-
-
Plugins and download the update.', 'onp_licensing_325'), admin_url('plugins.php') ) ?>
click here to reset your license details.', 'onp_licensing_325'), $this->getActionUrl('resetLicense') ) ?>
plugin->updates;
$licenseManager = $license = $this->plugin->license;
$email = isset( $_GET['email'] ) ? $_REQUEST['email'] : null;
$urlToRedirect = apply_filters('onp_license_manager_success_redirect_' . $this->plugin->pluginName, $this->getActionUrl('index') );
$btnText = apply_filters('onp_license_manager_success_button_' . $this->plugin->pluginName, __('Okay, I got it', 'onp_licensing_325') );
?>
data;
$remained = round( ( $licenseData['Expired'] - time() ) / (60 * 60 * 24), 2 );
?>
%s).', 'onp_licensing_325'), $email ) ?>
plugin->options['account'] ?>
needChangeAssembly() ) { ?>
plugin->license;
$currentUser = wp_get_current_user();
$email = isset( $_REQUEST['email'] ) ? $_REQUEST['email'] : $currentUser->user_email;
$key = $this->plugin->license->key;
$pluginName = $this->plugin->pluginTitle;
// if true, the congratulation text will be shown
$ref = isset( $_REQUEST['onp_ref'] ) ? $_REQUEST['onp_ref'] : null;
// if not empty, the error message will be shown
$error = false;
if ( isset( $_POST['submit'] ) ) {
$congrats = false;
$subscribe = isset( $_REQUEST['subscribe'] ) ? true: false;
if ( empty($email) ) {
$error = new WP_Error('FORM:EmailEmpty', __('Please enter your email adress to create a customer account.', 'onp_licensing_325'));
} else {
$result = $licenseManager->createAccount( $email, $subscribe );
if ( is_wp_error( $result ) ) $error = $result;
}
// everything is ok, account created
if ( !$error ) {
$this->redirectToAction('accountCreated', array(
'email' => rawurlencode( $email ),
'cancelCode' => isset( $result['CancelCode'] ) ? $result['CancelCode'] : null,
'confirmationId' => isset( $result['ConfirmationId'] ) ? $result['ConfirmationId'] : null
));
}
if ( $error ) {
$code = $error->get_error_code();
// the account for this email is already crated, are you sure to link the key to this account?
if ( $code === 'API:KeyBinding.CustomerExiststsAreYouSureToBindKey' ) {
$this->redirectToAction('accountAlreadyCreated', array('email' => rawurlencode( $email )));
}
// the key already is linked to this email
if ( $code === 'API:KeyBinding.KeyAlreadyBoundToThisEmail' ) {
$this->redirectToAction('finish', array('email' => rawurlencode( $email ), 'onp_ref' => 'binding'));
}
}
}
?>
get_error_message() ?>
click here for trying to activate your key manualy.', 'onp_licensing_325'),
$this->getActionUrl('activateKeyManualy', array('key' => $_POST['licensekey'] ))
);
} elseif ($action == 'trial') {
printf(
__('Please click here for trying to activate your trial manualy.', 'onp_licensing_325'),
$this->getActionUrl('activateTrialManualy')
);
} elseif ($action == 'delete-key') {
printf(
__('Please click here for trying to delete key manualy.', 'onp_licensing_325'),
$this->getActionUrl('deleteKeyManualy')
);
} else {
?>
plugin->license;
$licenseManager->resetLicense(true);
$this->redirectToAction('index', array('scope' => 'reset-license'));
}
/**
* Deletes a current key.
*/
public function deleteKeyAction() {
$licenseManager = $license = $this->plugin->license;
if ( $licenseManager->hasKey()) {
$error = $licenseManager->deleteKey();
if (is_wp_error($error)) {
$this->redirectToAction('index', array(
'scope' => 'delete-key',
'code' => $error->get_error_code(),
'message' => base64_encode( $error->get_error_message())));
}
$this->redirectToAction('index', array('scope' => 'delete-key'));
}
$this->indexAction();
}
/**
* Trys to activate the trial license and then redirect to the index page.
*/
public function activateTrialAction() {
$licenseManager = $this->plugin->license;
$response = $licenseManager->activateTrial();
if (is_wp_error($response)) {
$this->redirectToAction('index', array(
'scope' => 'trial',
'code' => $response->get_error_code(),
'message' => urlencode( base64_encode( $response->get_error_message()))) );
}
$this->redirectToAction('finish', array('onp_ref' => 'trial'));
}
/**
* Allows to activate a key manualy.
*/
public function activateKeyManualyAction() {
$licenseManager = $this->plugin->license;
if ( isset( $_POST['response'] ) ) {
$error = $licenseManager->activateKeyManualy( $_POST['response'] );
if (is_wp_error($error)) {
$this->redirectToAction('index', array(
'scope' => 'submit-key',
'code' => $error->get_error_code(),
'message' => urlencode( base64_encode( $error->get_error_message()))) );
}
$this->redirectToAction('finish', array('onp_ref' => 'manual-key-activation'));
} else {
$this->requestUrl = $licenseManager->getLinkToActivateKey( $_GET['key'] );
}
?>