first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
{
"name": "wpdesk\/wp-wpdesk-license",
"authors": [
{
"name": "Krzysiek",
"email": "krzysiek@wpdesk.pl"
}
],
"require": {
"php": ">=5.6",
"ext-curl": "*",
"ext-json": "*",
"wpdesk\/wp-builder": "^1.3.1",
"wpdesk\/wp-notice": "^3.0"
},
"require-dev": {
"phpunit\/phpunit": "<7",
"wp-coding-standards\/wpcs": "^0.14.1",
"squizlabs\/php_codesniffer": "^3.0.2",
"mockery\/mockery": "*",
"10up\/wp_mock": "*"
},
"autoload": {
"classmap": [
"src\/ApiManager"
],
"psr-4": {
"ActivePaymentsVendor\\WPDesk\\License\\": "src\/"
}
},
"autoload-dev": {},
"scripts": {
"phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
"phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
"phpunit-integration": "phpunit --configuration phpunit-integration.xml --coverage-text --colors=never",
"phpunit-integration-fast": "phpunit --configuration phpunit-integration.xml --no-coverage"
}
}

View File

@@ -0,0 +1,331 @@
<?php
namespace ActivePaymentsVendor;
/**
* Admin Menu Class
*
* @package Update API Manager/Admin
* @author Todd Lahman LLC, WPDesk
* @copyright Copyright (c) Todd Lahman LLC
* @since 1.3
*
*/
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
if (!\class_exists('ActivePaymentsVendor\\WPDesk_API_MENU')) {
class WPDesk_API_MENU
{
private $api_manager;
// Load admin menu
public function __construct($api_manager)
{
$this->api_manager = $api_manager;
\add_action('admin_menu', [$this, 'add_menu'], 100);
// add_action( 'admin_init', array( $this, 'load_settings' ) );
}
// Add option page menu
public function add_menu()
{
/*
add_submenu_page( 'wpdesk-helper',
__( $this->api_manager->settings_menu_title, $this->api_manager->text_domain ),
__( $this->api_manager->settings_menu_title, $this->api_manager->text_domain ),
'manage_options',
$this->api_manager->activation_tab_key,
array( $this, 'config_page')
);
*/
}
// Draw option page
public function config_page()
{
$settings_tabs = [$this->api_manager->activation_tab_key => \__($this->api_manager->menu_tab_activation_title, $this->api_manager->text_domain), $this->api_manager->deactivation_tab_key => \__($this->api_manager->menu_tab_deactivation_title, $this->api_manager->text_domain)];
$current_tab = isset($_GET['tab']) ? $_GET['tab'] : $this->api_manager->activation_tab_key;
$tab = isset($_GET['tab']) ? $_GET['tab'] : $this->api_manager->activation_tab_key;
?>
<div class='wrap'>
<?php
/* screen_icon(); */
?>
<h2><?php
\_e($this->api_manager->settings_title, $this->api_manager->text_domain);
?></h2>
<?php
\settings_errors();
?>
<h2 class="nav-tab-wrapper">
<?php
foreach ($settings_tabs as $tab_page => $tab_name) {
$active_tab = $current_tab == $tab_page ? 'nav-tab-active' : '';
echo '<a class="nav-tab ' . $active_tab . '" href="?page=' . $this->api_manager->activation_tab_key . '&tab=' . $tab_page . '">' . $tab_name . '</a>';
}
?>
</h2>
<form action='options.php' method='post'>
<div class="main">
<?php
if ($tab == $this->api_manager->activation_tab_key) {
\settings_fields($this->api_manager->data_key);
\do_settings_sections($this->api_manager->activation_tab_key);
//if (get_option( $this->api_manager->activated_key, '0' ) != 'Activated') {
\submit_button(\__('Save Changes', $this->api_manager->text_domain));
//}
} else {
\settings_fields($this->api_manager->deactivate_checkbox);
\do_settings_sections($this->api_manager->deactivation_tab_key);
\submit_button(\__('Save Changes', $this->api_manager->text_domain));
}
?>
</div>
</form>
</div>
<?php
}
// Register settings
public function load_settings()
{
\register_setting($this->api_manager->data_key, $this->api_manager->data_key, [$this, 'validate_options']);
// API Key
\add_settings_section($this->api_manager->api_key, \__('API Key Activation', $this->api_manager->text_domain), [$this, 'wc_am_api_key_text'], $this->api_manager->activation_tab_key);
\add_settings_field('status', \__('API Key Status', $this->api_manager->text_domain), [$this, 'wc_am_api_key_status'], $this->api_manager->activation_tab_key, $this->api_manager->api_key);
\add_settings_field($this->api_manager->api_key, \__('API Subscription Key', $this->api_manager->text_domain), [$this, 'wc_am_api_key_field'], $this->api_manager->activation_tab_key, $this->api_manager->api_key);
\add_settings_field($this->api_manager->activation_email, \__('API Subscription email', $this->api_manager->text_domain), [$this, 'wc_am_api_email_field'], $this->api_manager->activation_tab_key, $this->api_manager->api_key);
// Activation settings
\register_setting($this->api_manager->deactivate_checkbox, $this->api_manager->deactivate_checkbox, [$this, 'wc_am_license_key_deactivation']);
\add_settings_section('deactivate_button', \__('API Key Deactivation', $this->api_manager->text_domain), [$this, 'wc_am_deactivate_text'], $this->api_manager->deactivation_tab_key);
\add_settings_field('deactivate_button', \__('Deactivate API Key', $this->api_manager->text_domain), [$this, 'wc_am_deactivate_textarea'], $this->api_manager->deactivation_tab_key, 'deactivate_button');
}
// Provides text for api key section
public function wc_am_api_key_text()
{
//
}
// Returns the API License Key status from the WooCommerce API Manager on the server
public function wc_am_api_key_status()
{
$license_status = $this->license_key_status();
$license_status_check = !empty($license_status['status_check']) && $license_status['status_check'] == 'active' ? 'Activated' : 'Deactivated';
if (!empty($license_status_check)) {
echo $license_status_check;
}
}
// Returns API License text field
public function wc_am_api_key_field()
{
echo "<input id='api_key' name='" . $this->api_manager->data_key . "[" . $this->api_manager->api_key . "]' size='55' type='text' value='" . $this->api_manager->options[$this->api_manager->api_key] . "' />";
if ($this->api_manager->options[$this->api_manager->api_key]) {
echo "<span class='icon-pos'><img src='" . \plugins_url("wpdesk-helper/assets/images/complete.png") . "' title='' style='padding-bottom: 4px; vertical-align: middle; margin-right:3px;' /></span>";
} else {
echo "<span class='icon-pos'><img src='" . \plugins_url("wpdesk-helper/assets/images/warn.png") . "' title='' style='padding-bottom: 4px; vertical-align: middle; margin-right:3px;' /></span>";
}
}
// Returns API License email text field
public function wc_am_api_email_field()
{
echo "<input id='activation_email' name='" . $this->api_manager->data_key . "[" . $this->api_manager->activation_email . "]' size='55' type='text' value='" . $this->api_manager->options[$this->api_manager->activation_email] . "' />";
if ($this->api_manager->options[$this->api_manager->activation_email]) {
echo "<span class='icon-pos'><img src='" . \plugins_url("wpdesk-helper/assets/images/complete.png") . "' title='' style='padding-bottom: 4px; vertical-align: middle; margin-right:3px;' /></span>";
} else {
echo "<span class='icon-pos'><img src='" . \plugins_url("wpdesk-helper/assets/images/warn.png") . "' title='' style='padding-bottom: 4px; vertical-align: middle; margin-right:3px;' /></span>";
}
}
// Sanitizes and validates all input and output for Dashboard
public function validate_options($input)
{
// Load existing options, validate, and update with changes from input before returning
$options = $this->api_manager->options;
$options[$this->api_manager->api_key] = \trim($input[$this->api_manager->api_key]);
$options[$this->api_manager->activation_email] = \trim($input[$this->api_manager->activation_email]);
/**
* Plugin Activation
*/
$api_email = \trim($input[$this->api_manager->activation_email]);
$api_key = \trim($input[$this->api_manager->api_key]);
$activation_status = \get_option($this->api_manager->activated_key);
$checkbox_status = \get_option($this->api_manager->deactivate_checkbox);
$current_api_key = $this->api_manager->options[$this->api_manager->api_key];
// Should match the settings_fields() value
if ($_REQUEST['option_page'] != $this->api_manager->deactivate_checkbox) {
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
if ($activation_status == 'Deactivated' || $activation_status == '' || $api_key == '' || $api_email == '' || $checkbox_status == 'on' || $current_api_key != $api_key) {
/**
* If this is a new key, and an existing key already exists in the database,
* deactivate the existing key before activating the new key.
*/
if ($current_api_key != $api_key) {
$this->replace_license_key($current_api_key);
}
$args = ['email' => $api_email, 'licence_key' => $api_key];
$activate_results = \json_decode($this->api_manager->key()->activate($args), \true);
if ($activate_results['activated'] === \true) {
\add_settings_error('activate_text', 'activate_msg', \__('Plugin activated. ', $this->api_manager->text_domain) . "{$activate_results['message']}.", 'updated');
\update_option($this->api_manager->activated_key, 'Activated');
\update_option($this->api_manager->deactivate_checkbox, 'off');
}
if ($activate_results == \false) {
\add_settings_error('api_key_check_text', 'api_key_check_error', \__('Connection failed to the API Key server. Try again later.', $this->api_manager->text_domain), 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
}
if (isset($activate_results['code'])) {
switch ($activate_results['code']) {
case '100':
\add_settings_error('api_email_text', 'api_email_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->activation_email] = '';
$options[$this->api_manager->api_key] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '101':
\add_settings_error('api_key_text', 'api_key_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '102':
\add_settings_error('api_key_purchase_incomplete_text', 'api_key_purchase_incomplete_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '103':
\add_settings_error('api_key_exceeded_text', 'api_key_exceeded_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '104':
\add_settings_error('api_key_not_activated_text', 'api_key_not_activated_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '105':
\add_settings_error('api_key_invalid_text', 'api_key_invalid_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '106':
\add_settings_error('sub_not_active_text', 'sub_not_active_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
}
}
}
// End Plugin Activation
}
return $options;
}
// Returns the API License Key status from the WooCommerce API Manager on the server
public function license_key_status()
{
$activation_status = \get_option($this->api_manager->activated_key);
$args = ['email' => $this->api_manager->options[$this->api_manager->activation_email], 'licence_key' => $this->api_manager->options[$this->api_manager->api_key]];
return \json_decode($this->api_manager->key()->status($args), \true);
}
// Deactivate the current license key before activating the new license key
public function replace_license_key($current_api_key)
{
$args = ['email' => $this->api_manager->options[$this->api_manager->activation_email], 'licence_key' => $current_api_key];
$reset = $this->api_manager->key()->deactivate($args);
// reset license key activation
if ($reset == \true) {
return \true;
}
return \add_settings_error('not_deactivated_text', 'not_deactivated_error', \__('The subscription could not be deactivated. Use the Subscription Deactivation tab to manually deactivate the subscription before activating a new subscription.', $this->api_manager->text_domain), 'updated');
}
// Deactivates the license key to allow key to be used on another blog
public function wc_am_license_key_deactivation($input)
{
$activation_status = \get_option($this->api_manager->activated_key);
$args = ['email' => $this->api_manager->options[$this->api_manager->activation_email], 'licence_key' => $this->api_manager->options[$this->api_manager->api_key]];
// For testing activation status_extra data
// $activate_results = json_decode( $this->api_manager->key()->status( $args ), true );
// print_r($activate_results); exit;
$options = $input == 'on' ? 'on' : 'off';
if ($options == 'on' && $activation_status == 'Activated' && $this->api_manager->options[$this->api_manager->api_key] != '' && $this->api_manager->options[$this->api_manager->activation_email] != '') {
// deactivates license key activation
$activate_results = \json_decode($this->api_manager->key()->deactivate($args), \true);
// Used to display results for development
//print_r($activate_results); exit();
if ($activate_results['deactivated'] === \true) {
$update = [$this->api_manager->api_key => '', $this->api_manager->activation_email => ''];
$merge_options = \array_merge($this->api_manager->options, $update);
\update_option($this->api_manager->data_key, $merge_options);
\update_option($this->api_manager->activated_key, 'Deactivated');
\add_settings_error('wc_am_deactivate_text', 'deactivate_msg', \__('Plugin subscription deactivated. ', $this->api_manager->text_domain) . "{$activate_results['activations_remaining']}.", 'updated');
return $options;
}
if (isset($activate_results['code'])) {
switch ($activate_results['code']) {
case '100':
\add_settings_error('api_email_text', 'api_email_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->activation_email] = '';
$options[$this->api_manager->api_key] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '101':
\add_settings_error('api_key_text', 'api_key_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '102':
\add_settings_error('api_key_purchase_incomplete_text', 'api_key_purchase_incomplete_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '103':
\add_settings_error('api_key_exceeded_text', 'api_key_exceeded_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '104':
\add_settings_error('api_key_not_activated_text', 'api_key_not_activated_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '105':
\add_settings_error('api_key_invalid_text', 'api_key_invalid_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
case '106':
\add_settings_error('sub_not_active_text', 'sub_not_active_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$this->api_manager->api_key] = '';
$options[$this->api_manager->activation_email] = '';
\update_option($this->api_manager->options[$this->api_manager->activated_key], 'Deactivated');
break;
}
}
} else {
return $options;
}
}
public function wc_am_deactivate_text()
{
}
public function wc_am_deactivate_textarea()
{
echo '<input type="checkbox" id="' . $this->api_manager->deactivate_checkbox . '" name="' . $this->api_manager->deactivate_checkbox . '" value="on"';
echo \checked(\get_option($this->api_manager->deactivate_checkbox), 'on');
echo '/>';
?><span class="description"><?php
\_e('Deactivates an API Key so it can be used on another blog.', $this->api_manager->text_domain);
?></span>
<?php
}
}
// class WPDesk_API_MENU
}
// if (!class_exists('WPDesk_API_MENU'))

View File

@@ -0,0 +1,74 @@
<?php
namespace ActivePaymentsVendor;
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
/**
* WooCommerce API Manager Passwords Class
*
* @package Update API Manager/Passwords
* @author Todd Lahman LLC, WPDesk
* @copyright Copyright (c) Todd Lahman LLC
* @since 1.0.0
*
*/
if (!\class_exists('ActivePaymentsVendor\\WPDesk_API_Password_Management')) {
class WPDesk_API_Password_Management
{
private function rand($min = 0, $max = 0)
{
global $rnd_value;
// Reset $rnd_value after 14 uses
// 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
if (\strlen($rnd_value) < 8) {
if (\defined('ActivePaymentsVendor\\WP_SETUP_CONFIG')) {
static $seed = '';
} else {
$seed = \get_transient('random_seed');
}
$rnd_value = \md5(\uniqid(\microtime() . \mt_rand(), \true) . $seed);
$rnd_value .= \sha1($rnd_value);
$rnd_value .= \sha1($rnd_value . $seed);
$seed = \md5($seed . $rnd_value);
if (!\defined('ActivePaymentsVendor\\WP_SETUP_CONFIG')) {
\set_transient('random_seed', $seed);
}
}
// Take the first 8 digits for our value
$value = \substr($rnd_value, 0, 8);
// Strip the first eight, leaving the remainder for the next call to wp_rand().
$rnd_value = \substr($rnd_value, 8);
$value = \abs(\hexdec($value));
// Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
$max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295;
// 4294967295 = 0xffffffff
// Reduce the value to be within the min - max range
if ($max != 0) {
$value = $min + ($max - $min + 1) * $value / ($max_random_number + 1);
}
return \abs(\intval($value));
}
// Creates a unique instance ID
public function generate_password($length = 12, $special_chars = \true, $extra_special_chars = \false)
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
if ($special_chars) {
$chars .= '!@#$%^&*()';
}
if ($extra_special_chars) {
$chars .= '-_ []{}<>~`+=,.;:/?|';
}
$password = '';
for ($i = 0; $i < $length; $i++) {
$password .= \substr($chars, self::rand(0, \strlen($chars) - 1), 1);
}
// random_password filter was previously in random_password function which was deprecated
return $password;
}
}
// class Ilabs_API_Password_Management
}
// if (!class_exists('Ilabs_API_Password_Management'))

View File

@@ -0,0 +1,357 @@
<?php
namespace ActivePaymentsVendor;
// Exit if accessed directly
use ActivePaymentsVendor\WPDesk\Notice\AjaxHandler;
use ActivePaymentsVendor\WPDesk\Notice\PermanentDismissibleNotice;
if (!\defined('ABSPATH')) {
exit;
}
if (!\class_exists('ActivePaymentsVendor\\WPDesk_API_Manager_With_Update_Flag')) {
class WPDesk_API_Manager_With_Update_Flag
{
/**
* Self Upgrade Values
*/
// Base URL to the remote upgrade API Manager server. If not set then the Author URI is used.
public $upgrade_url;
/**
* @var string
*/
//public $version = '4.0';
public $version;
/**
* @var string
* This version is saved after an upgrade to compare this db version to $version
*/
public $api_version_name;
/**
* Software Product ID is the product title string
* This value must be unique, and it must match the API tab for the product in WooCommerce
*/
private $software_product_id;
public $settings_menu_title;
public $settings_title;
public $plugin_dir;
/**
* @var string
* used to defined localization for translation, but a string literal is preferred
*
* https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/issues/59
* http://markjaquith.wordpress.com/2011/10/06/translating-wordpress-plugins-and-themes-dont-get-clever/
* http://ottopress.com/2012/internationalization-youre-probably-doing-it-wrong/
*/
public $text_domain = 'wpdesk-helper';
/**
* @var string
*/
public $plugin_url;
/**
* Data defaults
* @var mixed
*/
public $data_key;
public $api_key;
public $activation_email;
public $product_id_key;
public $instance_key;
public $deactivate_checkbox_key;
public $activated_key;
public $upgrade_url_key;
public $deactivate_checkbox;
public $activation_tab_key;
public $deactivation_tab_key;
public $menu_tab_activation_title;
public $menu_tab_deactivation_title;
public $options;
public $plugin_name;
public $product_id;
public $renew_license_url;
public $instance_id;
public $domain;
public $software_version;
public $plugin_or_theme;
public $update_version;
public $config_uri;
/**
* Used to send any extra information.
* @var mixed array, object, string, etc.
*/
public $extra;
/**
*/
private $key_insance = null;
private $update_check_insance = null;
/**
* Cloning is forbidden.
*
* @since 1.2
*/
private function __clone()
{
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.2
*/
private function __wakeup()
{
}
public function __construct($upgrade_url, $version, $name, $product_id, $menu_title, $title, $plugin_file, $plugin_dir, $config_uri, $hook_to_updates = \true)
{
global $wpdesk_installed_plugins;
if (!$wpdesk_installed_plugins) {
$wpdesk_installed_plugins = [];
}
$wpdesk_installed_plugins[\trailingslashit($plugin_dir) . $plugin_file] = $this;
//
$this->upgrade_url_key = "api_{$plugin_dir}_upgrade_url";
$tmp_upgrade_url = \get_option($this->upgrade_url_key, '');
if ($tmp_upgrade_url == '') {
$tmp_upgrade_url = $upgrade_url;
\update_option($this->upgrade_url_key, $tmp_upgrade_url);
}
$this->upgrade_url = $tmp_upgrade_url;
$this->version = $version;
$this->api_version_name = 'plugin_' . $name . '_version';
$this->software_product_id = $product_id;
$this->settings_menu_title = $menu_title;
$this->settings_title = $title;
$this->plugin_dir = $plugin_dir;
$this->config_uri = $config_uri;
$this->plugin_url = \plugins_url('/', $plugin_file);
if (\is_admin()) {
// Check for external connection blocking
\add_action('admin_notices', [$this, 'check_external_blocking']);
/**
* Set all data defaults here
*/
$this->data_key = 'api_' . $plugin_dir;
$this->api_key = "api_{$plugin_dir}_key";
$this->activation_email = "api_{$plugin_dir}_activation_email";
$this->product_id_key = "api_{$plugin_dir}_product_id";
$this->instance_key = "api_{$plugin_dir}_instance";
$this->deactivate_checkbox_key = "api_{$plugin_dir}_deactivate_checkbox";
$this->activated_key = "api_{$plugin_dir}_activated";
/**
* Set all admin menu data
*/
$this->deactivate_checkbox = 'am_deactivate_example_checkbox';
$this->activation_tab_key = "api_{$plugin_dir}_dashboard";
$this->deactivation_tab_key = "api_{$plugin_dir}_deactivation";
$this->menu_tab_activation_title = \__('Subscription Activation', $this->text_domain);
$this->menu_tab_deactivation_title = \__('Subscription Deactivation', $this->text_domain);
/**
* Set all software update data here
*/
$this->options = \get_option($this->data_key);
//$this->plugin_name = untrailingslashit( dirname( $plugin_file) ); // same as plugin slug. if a theme use a theme name like 'twentyeleven'
$this->plugin_name = $name;
// same as plugin slug. if a theme use a theme name like 'twentyeleven'
$this->product_id = $this->software_product_id;
//get_option( $this->product_id_key ); // Software Title
$this->renew_license_url = $this->upgrade_url . '/my-account';
// URL to renew a license. Trailing slash in the upgrade_url is required.
$this->instance_id = \get_option($this->instance_key);
// Instance ID (unique to each blog activation)
if (\get_option($this->activated_key, '0') != 'Activated') {
$this->inactive_notice();
}
/* grola */
if (!$this->instance_id) {
$this->create_instance_id();
}
/**
* Some web hosts have security policies that block the : (colon) and // (slashes) in http://,
* so only the host portion of the URL can be sent. For example the host portion might be
* www.example.com or example.com. http://www.example.com includes the scheme http,
* and the host www.example.com.
* Sending only the host also eliminates issues when a client site changes from http to https,
* but their activation still uses the original scheme.
* To send only the host, use a line like the one below:
*
* $this->domain = str_ireplace( array( 'http://', 'https://' ), '', home_url() ); // blog domain name
*/
$this->domain = \str_ireplace(['http://', 'https://'], '', \home_url());
// blog domain name
$this->software_version = $this->version;
// The software version
$this->plugin_or_theme = 'plugin';
// 'theme' or 'plugin'
// Performs activations and deactivations of API License Keys
require_once 'class-wc-key-api.php';
// Checks for software updatess
require_once 'class-wc-plugin-update.php';
// Admin menu with the license key and license email form
// require_once( 'class-wc-api-manager-menu.php' );
// new WPDesk_API_MENU( $this );
$options = \get_option($this->data_key);
/**
* Check for software updates
*/
if ($hook_to_updates) {
if (!empty($options) && $options !== \false) {
$this->update_check($this->upgrade_url, $this->plugin_name, $this->product_id, $this->options[$this->api_key], $this->options[$this->activation_email], $this->renew_license_url, $this->instance_id, $this->domain, $this->software_version, $this->plugin_or_theme, $this->text_domain);
}
$this->add_not_possible_update_message();
}
}
}
/**
* Adds message to plugins page when plugin is not activated with info about subscription.
*/
private function add_not_possible_update_message()
{
\add_action('in_plugin_update_message-' . $this->plugin_name, function (array $plugin_data, \stdClass $response) {
if (isset($response, $response->package) && empty($response->package)) {
echo \sprintf(\__(" <a target='_blank' href='%s'>Enter a valid subscription key for automatic updates.</a>,", 'wpdesk-helper'), \admin_url('admin.php?page=wpdesk-licenses'));
}
}, 10, 2);
}
public function create_instance_id()
{
require_once 'class-wc-api-manager-passwords.php';
$password_management = new \ActivePaymentsVendor\WPDesk_API_Password_Management();
// Generate a unique installation $instance id
$instance = $password_management->generate_password(12, \false);
$this->instance_id = $instance;
\update_option($this->instance_key, $instance);
\update_option($this->activated_key, 'Deactivated');
$this->options = [];
$this->options[$this->api_key] = '';
$this->options[$this->activation_email] = '';
\update_option($this->data_key, $this->options);
}
/** Load Shared Classes as on-demand Instances **********************************************/
/**
* API Key Class.
*
* @return WPDesk_API_KEY
*/
public function key()
{
if ($this->key_insance == null) {
$this->key_insance = new \ActivePaymentsVendor\WPDesk_API_KEY($this);
}
return $this->key_insance;
}
/**
* Update Check Class.
*
* @return WPDesk_Update_API_Check
*/
public function update_check($upgrade_url, $plugin_name, $product_id, $api_key, $activation_email, $renew_license_url, $instance, $domain, $software_version, $plugin_or_theme, $text_domain, $extra = '')
{
if ($this->update_check_insance == null) {
$this->update_check_insance = new \ActivePaymentsVendor\WPDesk_Update_API_Check($this, $upgrade_url, $plugin_name, $product_id, $api_key, $activation_email, $renew_license_url, $instance, $domain, $software_version, $plugin_or_theme, $text_domain, $extra);
}
return $this->update_check_insance;
}
public function plugin_url()
{
if (isset($this->plugin_url)) {
return $this->plugin_url;
}
return $this->plugin_url = \plugins_url('/', __FILE__);
}
/**
* Generate the default data arrays
*/
public function activation()
{
$global_options = [$this->api_key => '', $this->activation_email => ''];
\update_option($this->data_key, $global_options);
require_once $this->plugin_dir . 'am/classes/class-wc-api-manager-passwords.php';
$password_management = new \ActivePaymentsVendor\WPDesk_API_Password_Management();
// Generate a unique installation $instance id
$instance = $password_management->generate_password(12, \false);
$single_options = [$this->product_id_key => $this->software_product_id, $this->instance_key => $instance, $this->deactivate_checkbox_key => 'on', $this->activated_key => 'Deactivated'];
foreach ($single_options as $key => $value) {
\update_option($key, $value);
}
$curr_ver = \get_option($this->api_version_name);
// checks if the current plugin version is lower than the version being installed
if (\version_compare($this->version, $curr_ver, '>')) {
// update the version
\update_option($this->api_version_name, $this->version);
}
}
/**
* Deletes all data if plugin deactivated
* @return void
*/
public function uninstall()
{
global $blog_id;
$this->license_key_deactivation();
// Remove options
if (\is_multisite()) {
\switch_to_blog($blog_id);
foreach ([$this->data_key, $this->product_id_key, $this->instance_key, $this->deactivate_checkbox_key, $this->activated_key] as $option) {
\delete_option($option);
}
\restore_current_blog();
} else {
foreach ([$this->data_key, $this->product_id_key, $this->instance_key, $this->deactivate_checkbox_key, $this->activated_key] as $option) {
\delete_option($option);
}
}
}
/**
* Deactivates the license on the API server
* @return void
*/
public function license_key_deactivation()
{
$activation_status = \get_option($this->activated_key);
$api_email = $this->options[$this->activation_email];
$api_key = $this->options[$this->api_key];
$args = ['email' => $api_email, 'licence_key' => $api_key];
if ($activation_status == 'Activated' && $api_key != '' && $api_email != '') {
$this->key()->deactivate($args);
// reset license key activation
}
}
/**
* Displays an inactive notice when the software is inactive.
*/
public function inactive_notice()
{
if (!\current_user_can('manage_options')) {
return;
}
if (isset($_GET['page']) && 'wpdesk-licenses' === $_GET['page']) {
return;
}
if (\apply_filters('wpdesk_show_plugin_activation_notice', \true)) {
(new \ActivePaymentsVendor\WPDesk\Notice\AjaxHandler())->hooks();
new \ActivePaymentsVendor\WPDesk\Notice\PermanentDismissibleNotice(\sprintf(\__('The %s%s%s API Key has not been activated, so you won\'t be supported and your plugin won\'t be updated! %sClick here%s to activate the API key and the plugin.', $this->text_domain), '<strong>', $this->software_product_id, '</strong>', '<a href="' . \esc_url(\admin_url('admin.php?page=wpdesk-licenses')) . '">', '</a>'), "notice-{$this->software_product_id}", \ActivePaymentsVendor\WPDesk\Notice\PermanentDismissibleNotice::NOTICE_TYPE_WARNING);
}
}
/**
* Check for external blocking contstant
* @return string
*/
public function check_external_blocking()
{
// show notice if external requests are blocked through the WP_HTTP_BLOCK_EXTERNAL constant
if (\defined('ActivePaymentsVendor\\WP_HTTP_BLOCK_EXTERNAL') && \ActivePaymentsVendor\WP_HTTP_BLOCK_EXTERNAL === \true) {
// check if our API endpoint is in the allowed hosts
$host = \parse_url($this->upgrade_url, \PHP_URL_HOST);
if (!\defined('ActivePaymentsVendor\\WP_ACCESSIBLE_HOSTS') || \stristr(\ActivePaymentsVendor\WP_ACCESSIBLE_HOSTS, $host) === \false) {
?>
<div class="error">
<p><?php
\printf(\__('<b>Warning!</b> You\'re blocking external requests which means you won\'t be able to get %s updates. Please add %s to %s.', $this->text_domain), $this->software_product_id, '<strong>' . $host . '</strong>', '<code>WP_ACCESSIBLE_HOSTS</code>');
?></p>
</div>
<?php
}
}
}
}
// class Ilabs_API_Manager
}
// if (!class_exists('Ilabs_API_Manager')) {

View File

@@ -0,0 +1,111 @@
<?php
namespace ActivePaymentsVendor;
/**
* WooCommerce API Manager API Key Class
*
* @package Update API Manager/Key Handler
* @author Todd Lahman LLC, WPDesk
* @copyright Copyright (c) Todd Lahman LLC
* @since 1.3
*
*/
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
if (!\class_exists('ActivePaymentsVendor\\WPDesk_API_KEY')) {
class WPDesk_API_KEY
{
/**
* @var The single instance of the class
*/
protected static $_instance = null;
private $api_manager;
public function __construct($api_manager)
{
$this->api_manager = $api_manager;
}
// API Key URL
public function create_software_api_url($args)
{
$api_url = \add_query_arg('wc-api', 'am-software-api', $this->api_manager->upgrade_url);
return $api_url . '&' . \http_build_query($args);
}
public function activate($args)
{
$this->api_manager->create_instance_id();
$defaults = ['request' => 'activation', 'product_id' => $this->api_manager->product_id, 'instance' => $this->api_manager->instance_id, 'platform' => $this->api_manager->domain, 'software_version' => $this->api_manager->software_version];
$args = \wp_parse_args($defaults, $args);
$target_url = \esc_url_raw($this->create_software_api_url($args));
$target_url = \str_replace('&amp;', '&', $target_url);
$request = \wp_safe_remote_get($target_url, ['timeout' => 30, 'sslverify' => \false]);
if (\is_wp_error($request) || \wp_remote_retrieve_response_code($request) != 200) {
if (\class_exists('ActivePaymentsVendor\\WPDesk_Logger_Factory')) {
// Request failed
if (\is_wp_error($request)) {
\ActivePaymentsVendor\WPDesk_Logger_Factory::log_wp_error($request, \debug_backtrace());
} else {
\ActivePaymentsVendor\WPDesk_Logger_Factory::log_message_backtrace('Response is invalid. Response: ' . \json_encode($request), \ActivePaymentsVendor\WPDesk_Logger::ERROR, \debug_backtrace());
}
}
return \false;
}
$response = \wp_remote_retrieve_body($request);
return $response;
}
public function deactivate($args)
{
$defaults = ['request' => 'deactivation', 'product_id' => $this->api_manager->product_id, 'instance' => $this->api_manager->instance_id, 'platform' => $this->api_manager->domain];
$args = \wp_parse_args($defaults, $args);
$target_url = \esc_url_raw($this->create_software_api_url($args));
$target_url = \str_replace('&amp;', '&', $target_url);
$request = \wp_safe_remote_get($target_url, ['timeout' => 30, 'sslverify' => \false]);
if (\is_wp_error($request) || \wp_remote_retrieve_response_code($request) != 200) {
if (\class_exists('ActivePaymentsVendor\\WPDesk_Logger_Factory')) {
if (\is_wp_error($request)) {
\ActivePaymentsVendor\WPDesk_Logger_Factory::log_wp_error($request, \debug_backtrace());
} else {
\ActivePaymentsVendor\WPDesk_Logger_Factory::log_message_backtrace('Response is invalid. Response: ' . \json_encode($request), \ActivePaymentsVendor\WPDesk_Logger::ERROR, \debug_backtrace());
}
}
// Request failed
return \false;
}
$response = \wp_remote_retrieve_body($request);
return $response;
}
/**
* Checks if the software is activated or deactivated
*
* @param array $args
*
* @return array
*/
public function status($args)
{
$defaults = ['request' => 'status', 'product_id' => $this->api_manager->product_id, 'instance' => $this->api_manager->instance_id, 'platform' => $this->api_manager->domain];
$args = \wp_parse_args($defaults, $args);
$target_url = \esc_url_raw($this->create_software_api_url($args));
$target_url = \str_replace('&amp;', '&', $target_url);
$request = \wp_safe_remote_get($target_url, ['timeout' => 30, 'sslverify' => \false]);
// $request = wp_remote_post( $this->api_manager->upgrade_url . 'wc-api/am-software-api/', array( 'body' => $args ) );
if (\is_wp_error($request) || \wp_remote_retrieve_response_code($request) != 200) {
if (\class_exists('ActivePaymentsVendor\\WPDesk_Logger_Factory')) {
if (\is_wp_error($request)) {
\ActivePaymentsVendor\WPDesk_Logger_Factory::log_wp_error($request, \debug_backtrace());
} else {
\ActivePaymentsVendor\WPDesk_Logger_Factory::log_message_backtrace('Response is invalid. Response: ' . \json_encode($request), \ActivePaymentsVendor\WPDesk_Logger::ERROR, \debug_backtrace());
}
}
// Request failed
return \false;
}
$response = \wp_remote_retrieve_body($request);
return $response;
}
}
// class WPDesk_API_KEY
}
// if (!class_exists('WPDesk_API_KEY'))

View File

@@ -0,0 +1,463 @@
<?php
namespace ActivePaymentsVendor;
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
/**
* Todd Lahman LLC Updater - Single Updater Class
*
* @package Update API Manager/Update Handler
* @author Todd Lahman LLC
* @copyright Copyright (c) Todd Lahman LLC
* @since 1.0.0
*
*/
if (!\class_exists('ActivePaymentsVendor\\WPDesk_Update_API_Check')) {
class WPDesk_Update_API_Check
{
/**
* @var The single instance of the class
*/
protected static $_instance = null;
private $api_manager;
/**
*
* Ensures only one instance is loaded or can be loaded.
*
* @static
* @return class instance
*/
public static function instance($upgrade_url, $plugin_name, $product_id, $api_key, $activation_email, $renew_license_url, $instance, $domain, $software_version, $plugin_or_theme, $text_domain, $extra = '')
{
if (\is_null(self::$_instance)) {
self::$_instance = new self($upgrade_url, $plugin_name, $product_id, $api_key, $activation_email, $renew_license_url, $instance, $domain, $software_version, $plugin_or_theme, $text_domain, $extra);
}
return self::$_instance;
}
private $upgrade_url;
// URL to access the Update API Manager.
private $plugin_name;
private $plugin_file;
private $product_id;
// Software Title
private $api_key;
// API License Key
private $activation_email;
// License Email
private $renew_license_url;
// URL to renew a license
private $instance;
// Instance ID (unique to each blog activation)
private $domain;
// blog domain name
private $software_version;
private $plugin_or_theme;
// 'theme' or 'plugin'
private $text_domain;
// localization for translation
private $extra;
// Used to send any extra information.
/**
* Constructor.
*
* @access public
* @since 1.0.0
* @return void
*/
public function __construct($api_manager, $upgrade_url, $plugin_name, $product_id, $api_key, $activation_email, $renew_license_url, $instance, $domain, $software_version, $plugin_or_theme, $text_domain, $extra, $free = \false)
{
$this->api_manager = $api_manager;
// API data
$this->upgrade_url = $upgrade_url;
$this->plugin_name = $plugin_name;
$this->product_id = $product_id;
$this->api_key = $api_key;
$this->activation_email = $activation_email;
$this->renew_license_url = $renew_license_url;
$this->instance = $instance;
$this->domain = $domain;
$this->software_version = $software_version;
$this->text_domain = $text_domain;
$this->extra = $extra;
$this->free = $free;
// Slug should be the same as the plugin/theme directory name
if (\strpos($this->plugin_name, '.php') !== 0) {
$this->slug = \dirname($this->plugin_name);
} else {
$this->slug = $this->plugin_name;
}
/**
* Flag for plugin or theme updates
* @access public
* @since 1.0.0
*
* @param string, plugin or theme
*/
$this->plugin_or_theme = $plugin_or_theme;
// 'theme' or 'plugin'
/*********************************************************************
* The plugin and theme filters should not be active at the same time
*********************************************************************/
/**
* More info:
* function set_site_transient moved from wp-includes/functions.php
* to wp-includes/option.php in WordPress 3.4
*
* set_site_transient() contains the pre_set_site_transient_{$transient} filter
* {$transient} is either update_plugins or update_themes
*
* Transient data for plugins and themes exist in the Options table:
* _site_transient_update_themes
* _site_transient_update_plugins
*/
// uses the flag above to determine if this is a plugin or a theme update request
if ($this->plugin_or_theme == 'plugin') {
/**
* Plugin Updates
*/
// Check For Plugin Updates
\add_filter('pre_set_site_transient_update_plugins', [$this, 'update_check']);
// Check For Plugin Information to display on the update details page
\add_filter('plugins_api', [$this, 'request'], 10, 3);
} elseif ($this->plugin_or_theme == 'theme') {
/**
* Theme Updates
*/
// Check For Theme Updates
\add_filter('pre_set_site_transient_update_themes', [$this, 'update_check']);
// Check For Theme Information to display on the update details page
\add_filter('themes_api', [$this, 'request'], 10, 3);
}
}
// Upgrade API URL
private function create_upgrade_api_url($args)
{
if ($this->free) {
$upgrade_url = \add_query_arg('wc-api', 'wpdesk-upgrade-api', $this->upgrade_url);
} else {
$upgrade_url = \add_query_arg('wc-api', 'upgrade-api', $this->upgrade_url);
}
return $upgrade_url . '&' . \http_build_query($args);
}
/**
* Check for updates against the remote server.
*
* @access public
* @since 1.0.0
*
* @param object $transient
*
* @return object $transient
*/
public function update_check($transient)
{
if (empty($transient->checked)) {
return $transient;
}
$args = ['request' => 'pluginupdatecheck', 'slug' => $this->slug, 'plugin_name' => $this->plugin_name, 'version' => $this->software_version, 'product_id' => $this->product_id, 'api_key' => $this->api_key, 'activation_email' => $this->activation_email, 'instance' => $this->instance, 'domain' => $this->domain, 'software_version' => $this->software_version, 'extra' => $this->extra];
// Check for a plugin update
$response = $this->plugin_information($args);
// Displays an admin error message in the WordPress dashboard
$this->check_response_for_errors($response);
// Set version variables
if (isset($response) && \is_object($response) && $response !== \false) {
// New plugin version from the API
$new_ver = (string) $response->new_version;
// Current installed plugin version
$curr_ver = (string) $this->software_version;
//$curr_ver = (string)$transient->checked[$this->plugin_name];
}
// If there is a new version, modify the transient to reflect an update is available
if (isset($new_ver) && isset($curr_ver)) {
if ($response !== \false && \version_compare($new_ver, $curr_ver, '>')) {
if ($this->plugin_or_theme == 'plugin') {
$transient->response[$this->plugin_name] = $response;
} elseif ($this->plugin_or_theme == 'theme') {
$transient->response[$this->plugin_name]['new_version'] = $response->new_version;
$transient->response[$this->plugin_name]['url'] = $response->url;
$transient->response[$this->plugin_name]['package'] = $response->package;
}
}
}
return $transient;
}
/**
* Sends and receives data to and from the server API
*
* @access public
* @since 1.0.0
* @return object|bool $response
*/
public function plugin_information($args)
{
$target_url = \esc_url_raw($this->create_upgrade_api_url($args));
$target_url = \str_replace('&amp;', '&', $target_url);
$request = \wp_safe_remote_get($target_url, ['timeout' => 30, 'sslverify' => \false]);
if (\is_wp_error($request) || \wp_remote_retrieve_response_code($request) != 200) {
if (\class_exists('ActivePaymentsVendor\\WPDesk_Logger_Factory')) {
if (\is_wp_error($request)) {
\ActivePaymentsVendor\WPDesk_Logger_Factory::log_wp_error($request, \debug_backtrace());
} else {
\ActivePaymentsVendor\WPDesk_Logger_Factory::log_message_backtrace('Response is invalid. Response: ' . \json_encode($request), \ActivePaymentsVendor\WPDesk_Logger::ERROR, \debug_backtrace());
}
}
return \false;
}
$response = \unserialize(\wp_remote_retrieve_body($request));
/**
* For debugging errors from the API
* For errors like: unserialize(): Error at offset 0 of 170 bytes
* Comment out $response above first
*/
// $response = wp_remote_retrieve_body( $request );
// print_r($response); exit;
if (\is_object($response)) {
if (isset($response->sections)) {
$response->sections['description'] = \apply_filters('the_content', isset($response->sections['description_base64']) ? \base64_decode($response->sections['description_base64']) : '');
if (isset($response->sections['installation'])) {
$response->sections['installation'] = \apply_filters('the_content', $response->sections['installation']);
}
if (isset($response->sections['faq'])) {
$response->sections['faq'] = \apply_filters('the_content', $response->sections['faq']);
}
if (isset($response->sections['screenshots'])) {
$response->sections['screenshots'] = \apply_filters('the_content', $response->sections['screenshots']);
}
if (isset($response->sections['changelog'])) {
$response->sections['changelog'] = \apply_filters('the_content', $response->sections['changelog']);
}
if (isset($response->sections['other_notes'])) {
$response->sections['other_notes'] = \apply_filters('the_content', $response->sections['other_notes']);
}
}
if (isset($response->author)) {
$response->author = "<a href='http://www.wpdesk.pl'>{$response->author}</a>";
}
unset($response->sections['description_base64']);
return $response;
} else {
if (\class_exists('ActivePaymentsVendor\\WPDesk_Logger_Factory')) {
\ActivePaymentsVendor\WPDesk_Logger_Factory::log_message_backtrace('Response is not an object', \ActivePaymentsVendor\WPDesk_Logger::DEBUG, \debug_backtrace());
}
return \false;
}
}
/**
* Generic request helper.
*
* @access public
* @since 1.0.0
*
* @param array $args
*
* @return object $response or boolean false
*/
public function request($false, $action, $args)
{
// Is this a plugin or a theme?
if ($this->plugin_or_theme == 'plugin') {
$version = \get_site_transient('update_plugins');
} elseif ($this->plugin_or_theme == 'theme') {
$version = \get_site_transient('update_themes');
}
// Check if this plugins API is about this plugin
if (isset($args->slug)) {
//if ( $args->slug != dirname($this->slug)) {
if ($args->slug != $this->slug) {
return $false;
}
} else {
return $false;
}
$args = ['request' => 'plugininformation', 'plugin_name' => $this->plugin_name, 'slug' => $this->slug, 'version' => $this->software_version, 'product_id' => $this->product_id, 'api_key' => $this->api_key, 'activation_email' => $this->activation_email, 'instance' => $this->instance, 'domain' => $this->domain, 'software_version' => $this->software_version, 'extra' => $this->extra];
$response = $this->plugin_information($args);
if ($response) {
$response->slug = $this->slug;
$response->product_id = $this->product_id;
// If everything is okay return the $response
if (isset($response) && \is_object($response) && $response !== \false) {
return $response;
}
} else {
return \false;
}
}
/**
* Displays an admin error message in the WordPress dashboard
*
* @param array $response
*
* @return string
*/
public function check_response_for_errors($response)
{
if (!empty($response)) {
if (isset($response->errors['no_key']) && $response->errors['no_key'] == 'no_key' && isset($response->errors['no_subscription']) && $response->errors['no_subscription'] == 'no_subscription') {
\add_action('admin_notices', [$this, 'no_key_error_notice']);
\add_action('admin_notices', [$this, 'no_subscription_error_notice']);
} elseif (isset($response->errors['exp_license']) && $response->errors['exp_license'] == 'exp_license') {
\add_action('admin_notices', [$this, 'expired_license_error_notice']);
} elseif (isset($response->errors['hold_subscription']) && $response->errors['hold_subscription'] == 'hold_subscription') {
\add_action('admin_notices', [$this, 'on_hold_subscription_error_notice']);
} elseif (isset($response->errors['cancelled_subscription']) && $response->errors['cancelled_subscription'] == 'cancelled_subscription') {
\add_action('admin_notices', [$this, 'cancelled_subscription_error_notice']);
} elseif (isset($response->errors['exp_subscription']) && $response->errors['exp_subscription'] == 'exp_subscription') {
\add_action('admin_notices', [$this, 'expired_subscription_error_notice']);
} elseif (isset($response->errors['suspended_subscription']) && $response->errors['suspended_subscription'] == 'suspended_subscription') {
\add_action('admin_notices', [$this, 'suspended_subscription_error_notice']);
} elseif (isset($response->errors['pending_subscription']) && $response->errors['pending_subscription'] == 'pending_subscription') {
\add_action('admin_notices', [$this, 'pending_subscription_error_notice']);
} elseif (isset($response->errors['trash_subscription']) && $response->errors['trash_subscription'] == 'trash_subscription') {
\add_action('admin_notices', [$this, 'trash_subscription_error_notice']);
} elseif (isset($response->errors['no_subscription']) && $response->errors['no_subscription'] == 'no_subscription') {
\add_action('admin_notices', [$this, 'no_subscription_error_notice']);
} elseif (isset($response->errors['no_activation']) && $response->errors['no_activation'] == 'no_activation') {
\add_action('admin_notices', [$this, 'no_activation_error_notice']);
} elseif (isset($response->errors['no_key']) && $response->errors['no_key'] == 'no_key') {
\add_action('admin_notices', [$this, 'no_key_error_notice']);
} elseif (isset($response->errors['download_revoked']) && $response->errors['download_revoked'] == 'download_revoked') {
\add_action('admin_notices', [$this, 'download_revoked_error_notice']);
} elseif (isset($response->errors['switched_subscription']) && $response->errors['switched_subscription'] == 'switched_subscription') {
\add_action('admin_notices', [$this, 'switched_subscription_error_notice']);
}
}
}
/**
* Display license expired error notice
*
* @param string $message
*
* @return void
*/
public function expired_license_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('The API key for %s has expired. You can reactivate or purchase a API key from your account <a href="%s" target="_blank">dashboard</a>.', $this->text_domain) . '</p></div>', $this->product_id, $this->renew_license_url);
}
/**
* Display subscription on-hold error notice
*
* @param string $message
*
* @return void
*/
public function on_hold_subscription_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('The subscription for %s is on-hold. You can reactivate the subscription from your account <a href="%s" target="_blank">dashboard</a>.', $this->text_domain) . '</p></div>', $this->product_id, $this->renew_license_url);
}
/**
* Display subscription cancelled error notice
*
* @param string $message
*
* @return void
*/
public function cancelled_subscription_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('The subscription for %s has been cancelled. You can renew the subscription from your account <a href="%s" target="_blank">dashboard</a>. A new API key will be emailed to you after your order has been completed.', $this->text_domain) . '</p></div>', $this->product_id, $this->renew_license_url);
}
/**
* Display subscription expired error notice
*
* @param string $message
*
* @return void
*/
public function expired_subscription_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('The subscription for %s has expired. You can reactivate the subscription from your account <a href="%s" target="_blank">dashboard</a>.', $this->text_domain) . '</p></div>', $this->product_id, $this->renew_license_url);
}
/**
* Display subscription expired error notice
*
* @param string $message
*
* @return void
*/
public function suspended_subscription_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('The subscription for %s has been suspended. You can reactivate the subscription from your account <a href="%s" target="_blank">dashboard</a>.', $this->text_domain) . '</p></div>', $this->product_id, $this->renew_license_url);
}
/**
* Display subscription expired error notice
*
* @param string $message
*
* @return void
*/
public function pending_subscription_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('The subscription for %s is still pending. You can check on the status of the subscription from your account <a href="%s" target="_blank">dashboard</a>.', $this->text_domain) . '</p></div>', $this->product_id, $this->renew_license_url);
}
/**
* Display subscription expired error notice
*
* @param string $message
*
* @return void
*/
public function trash_subscription_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('The subscription for %s has been placed in the trash and will be deleted soon. You can purchase a new subscription from your account <a href="%s" target="_blank">dashboard</a>.', $this->text_domain) . '</p></div>', $this->product_id, $this->renew_license_url);
}
/**
* Display subscription expired error notice
*
* @param string $message
*
* @return void
*/
public function no_subscription_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('A subscription for %s could not be found. You can purchase a subscription from your account <a href="%s" target="_blank">dashboard</a>.', $this->text_domain) . '</p></div>', $this->product_id, $this->renew_license_url);
}
/**
* Display missing key error notice
*
* @param string $message
*
* @return void
*/
public function no_key_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('A API key for %s could not be found. Maybe you forgot to enter a API key when setting up %s, or the key was deactivated in your account. You can reactivate or purchase a subscription key from your account <a href="%s" target="_blank">dashboard</a>.', $this->text_domain) . '</p></div>', $this->product_id, $this->product_id, $this->renew_license_url);
}
/**
* Display missing download permission revoked error notice
*
* @param string $message
*
* @return void
*/
public function download_revoked_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('Download permission for %s has been revoked possibly due to a API key or subscription expiring. You can reactivate or purchase a API key from your account <a href="%s" target="_blank">dashboard</a>.', $this->text_domain) . '</p></div>', $this->product_id, $this->renew_license_url);
}
/**
* Display no activation error notice
*
* @param string $message
*
* @return void
*/
public function no_activation_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('%s has not been activated. Go to the settings page and enter the API key and subscription email to activate %s.', $this->text_domain) . '</p></div>', $this->product_id, $this->product_id);
}
/**
* Display switched activation error notice
*
* @param string $message
*
* @return void
*/
public function switched_subscription_error_notice($message)
{
echo \sprintf('<div id="message" class="error"><p>' . \__('You changed the subscription for %s, so you will need to enter your new API Key in the settings page. The API Key should have arrived in your email inbox, if not you can get it by logging into your account <a href="%s" target="_blank">dashboard</a>.', $this->text_domain) . '</p></div>', $this->product_id, $this->renew_license_url);
}
}
// class WPDesk_Update_API_Check
}
// if (!class_exists('WPDesk_Update_API_Check')) {

View File

@@ -0,0 +1,54 @@
<?php
namespace ActivePaymentsVendor\WPDesk\License;
use ActivePaymentsVendor\WPDesk_API_Manager_With_Update_Flag;
/**
* Provides info about activation/update state and can refresh that state
*
* @package WPDesk\License
*/
class InstalledPlugins
{
const KEY_API_MANAGER = 'api_manager';
const KEY_ACTIVATION_STATUS = 'activation_status';
/**
* Refresh WP info about updates.
*
* @return void
*/
public function refresh_plugin_update_info()
{
$this->get_plugins_activation_info(\true);
}
/**
* Returns info about activation/update state of plugins.
*
* @param bool $hook_to_updates If updates api should be called. If not sure then no!
*
* @return array Info about plugins.
* Key is plugin name and values are plugin_info + KEY_API_MANAGER + KEY_ACTIVATION_STATUS
*/
public function get_plugins_activation_info($hook_to_updates = \false)
{
global $wpdesk_helper_plugins;
if (!isset($wpdesk_helper_plugins)) {
$wpdesk_helper_plugins = [];
}
$plugins = [];
foreach ($wpdesk_helper_plugins as $key => $wpdesk_helper_plugin) {
$config_uri = null;
if (isset($wpdesk_helper_plugin['config_uri'])) {
$config_uri = $wpdesk_helper_plugin['config_uri'];
}
$menu_title = $wpdesk_helper_plugin['product_id'];
if (isset($wpdesk_helper_plugin['title'])) {
$menu_title = $wpdesk_helper_plugin['title'];
}
$plugins[$key] = $wpdesk_helper_plugin;
$plugins[$key][self::KEY_API_MANAGER] = new \ActivePaymentsVendor\WPDesk_API_Manager_With_Update_Flag($upgrade_url = 'https://www.wpdesk.pl', $version = $wpdesk_helper_plugin['version'], $name = $wpdesk_helper_plugin['plugin'], $product_id = $wpdesk_helper_plugin['product_id'], $menu_title, $title = $menu_title, $plugin_file = \basename($wpdesk_helper_plugin['plugin']), $plugin_dir = \dirname($wpdesk_helper_plugin['plugin']), $config_uri, $hook_to_updates);
$plugins[$key][self::KEY_ACTIVATION_STATUS] = \get_option($plugins[$key][self::KEY_API_MANAGER]->activated_key, 'Deactivated');
}
return $plugins;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace ActivePaymentsVendor\WPDesk\License\Page;
/**
* Action that can be executed relative to plugin.
*
* @package WPDesk\License\Page
*/
interface Action
{
public function execute(array $plugin);
}

View File

@@ -0,0 +1,182 @@
<?php
namespace ActivePaymentsVendor\WPDesk\License\Page\License\Action;
use ActivePaymentsVendor\WPDesk\License\Page\Action;
use ActivePaymentsVendor\WPDesk_API_Manager_With_Update_Flag;
/**
* Can activate plugin license.
*
* @package WPDesk\License\Page\License\Action
*/
class LicenseActivation implements \ActivePaymentsVendor\WPDesk\License\Page\Action
{
/**
* Upgrade URLs.
*
* @var array
*/
private $upgrade_urls = ['pl' => 'https://www.wpdesk.pl', 'net' => 'https://www.wpdesk.net', 'fs' => 'https://flexibleshipping.com'];
/**
* Plugin data.
*
* @var array
*/
private $plugin_data;
/**
* Activate plugin license.
*
* @param $plugin array Info about plugin
*/
public function execute(array $plugin)
{
$activation_email = \trim($_POST['activation_email']);
$api_key = \trim($_POST['api_key']);
$this->plugin_data = $plugin;
$this->activate_license($activation_email, $api_key);
}
/**
* Get api manager from plugin data.
*
* @return WPDesk_API_Manager_With_Update_Flag
*/
private function get_api_manager_from_plugin_data()
{
return $this->plugin_data['api_manager'];
}
/**
* Is activated?
*
* @param mixed $activate_results Activate result.
*
* @return bool
*/
private function is_activated($activate_results)
{
if (\is_array($activate_results)) {
if (isset($activate_results['activated']) && \true === $activate_results['activated']) {
return \true;
}
}
return \false;
}
/**
* Is json error?
*
* @return bool
*/
private function is_json_error()
{
if (\JSON_ERROR_NONE !== \json_last_error()) {
return \true;
}
return \false;
}
/**
* Is invalid api license key?
*
* @param mixed $activate_results Activate result.
*
* @return bool
*/
private function is_invalid_api_license_key($activate_results)
{
if (\is_array($activate_results)) {
if (isset($activate_results['code']) && '101' === $activate_results['code']) {
return \true;
}
}
return \false;
}
/**
* Activate and save data.
*
* @param WPDesk_API_Manager_With_Update_Flag $plugin_api_manager Api manager.
* @param string $activation_email Activation email.
* @param string $api_key Api key.
*/
private function activate_and_save_data($plugin_api_manager, $activation_email, $api_key)
{
$plugin_api_manager->options[$plugin_api_manager->api_key] = $api_key;
$plugin_api_manager->options[$plugin_api_manager->activation_email] = $activation_email;
\update_option($plugin_api_manager->data_key, $plugin_api_manager->options);
\update_option($plugin_api_manager->upgrade_url_key, $plugin_api_manager->upgrade_url);
\update_option($plugin_api_manager->activated_key, 'Activated');
}
/**
* Activate and save data.
*
* @param WPDesk_API_Manager_With_Update_Flag $plugin_api_manager Api manager.
*/
private function deactivate_and_save_data($plugin_api_manager)
{
$plugin_api_manager->options[$plugin_api_manager->api_key] = '';
$plugin_api_manager->options[$plugin_api_manager->activation_email] = '';
\update_option($plugin_api_manager->data_key, $plugin_api_manager->options);
\update_option($plugin_api_manager->activated_key, 'Deactivated');
}
/**
* Show error from reposne.
*
* @param array $activate_results Activate results.
*/
private function show_error(array $activate_results)
{
if (!isset($activate_results['additional info'])) {
$activate_results['additional info'] = '';
}
$message = "{$activate_results['error']}. {$activate_results['additional info']}";
\add_settings_error('api_manager_message', 'api_manager_error', $message, 'error');
}
/**
* Show unknown error.
*/
private function show_unknown_error()
{
\add_settings_error('api_key_check_text', 'api_key_check_error', \__('Connection failed to the Subscription Key API server. Try again later.', 'wpdesk-helper'), 'error');
}
/**
* Show activation message.
*
* @param array $activate_results Activation results.
*/
private function show_activation_message(array $activate_results)
{
\add_settings_error('activate_text', 'activate_msg', \__('Plugin activated. ', 'wpdesk-helper') . "{$activate_results['message']}.", 'updated');
}
/**
* Activate license.
*
* @param string $activation_email Activation email.
* @param string $api_key Api key.
*/
public function activate_license($activation_email, $api_key)
{
$plugin_api_manager = $this->get_api_manager_from_plugin_data();
$activation_args = ['email' => $activation_email, 'licence_key' => $api_key];
$activate_results = ['activated' => \false];
foreach ($this->upgrade_urls as $upgrade_url) {
$plugin_api_manager->upgrade_url = $upgrade_url;
$activate_raw_response = $plugin_api_manager->key()->activate($activation_args);
$activate_results = \json_decode($activate_raw_response, \true);
if ($this->is_json_error()) {
$activate_results = ['activated' => \false, 'error' => 'Invalid response from API Server', 'additional info' => $activate_raw_response, 'code' => '500'];
break;
}
if ($this->is_activated($activate_results) || !$this->is_invalid_api_license_key($activate_results)) {
break;
}
}
if (\true === $activate_results['activated']) {
$this->activate_and_save_data($plugin_api_manager, $activation_email, $api_key);
$this->show_activation_message($activate_results);
} else {
$this->deactivate_and_save_data($plugin_api_manager);
if (isset($activate_results['code'])) {
$this->show_error($activate_results);
} else {
$this->show_unknown_error();
}
}
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace ActivePaymentsVendor\WPDesk\License\Page\License\Action;
use ActivePaymentsVendor\WPDesk\License\Page\Action;
/**
* Can deactivate plugin license.
*
* @package WPDesk\License\Page\License\Action
*/
class LicenseDeactivation implements \ActivePaymentsVendor\WPDesk\License\Page\Action
{
/**
* Deactivate plugin subscription.
*
* @param $plugin array Info about plugin
*/
public function execute(array $plugin)
{
$args = ['email' => $plugin['api_manager']->options[$plugin['api_manager']->activation_email], 'licence_key' => $plugin['api_manager']->options[$plugin['api_manager']->api_key]];
$activate_results = \json_decode($plugin['api_manager']->key()->deactivate($args), \true);
// Used to display results for development
//print_r($activate_results); exit();
$deactivated = \false;
if ($activate_results['deactivated'] === \true) {
$update = [$plugin['api_manager']->api_key => '', $plugin['api_manager']->activation_email => ''];
$merge_options = \array_merge($plugin['api_manager']->options, $update);
\update_option($plugin['api_manager']->data_key, $merge_options);
\update_option($plugin['api_manager']->activated_key, 'Deactivated');
\delete_option($plugin['api_manager']->upgrade_url_key);
\add_settings_error('wc_am_deactivate_text', 'deactivate_msg', \__('Plugin subscription deactivated. ', 'wpdesk-helper') . "{$activate_results['activations_remaining']}.", 'updated');
$deactivated = \true;
$plugin_wpdesk_name = $plugin['plugin'];
$plugin_product_id = $plugin['product_id'];
\do_action('wpdesk_subscription_deactivated', $plugin_wpdesk_name, $plugin_product_id);
}
if (!$deactivated && isset($activate_results['code'])) {
switch ($activate_results['code']) {
case '100':
\add_settings_error('api_email_text', 'api_email_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$plugin['api_manager']->activation_email] = '';
$options[$plugin['api_manager']->api_key] = '';
\update_option($plugin['api_manager']->data_key, $plugin['api_manager']->options);
\update_option($plugin['api_manager']->activated_key, 'Deactivated');
break;
case '101':
\add_settings_error('api_key_text', 'api_key_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$plugin['api_manager']->api_key] = '';
$options[$plugin['api_manager']->activation_email] = '';
\update_option($plugin['api_manager']->data_key, $plugin['api_manager']->options);
\update_option($plugin['api_manager']->activated_key, 'Deactivated');
break;
case '102':
\add_settings_error('api_key_purchase_incomplete_text', 'api_key_purchase_incomplete_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$plugin['api_manager']->api_key] = '';
$options[$plugin['api_manager']->activation_email] = '';
\update_option($plugin['api_manager']->data_key, $plugin['api_manager']->options);
\update_option($plugin['api_manager']->activated_key, 'Deactivated');
break;
case '103':
\add_settings_error('api_key_exceeded_text', 'api_key_exceeded_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$plugin['api_manager']->api_key] = '';
$options[$plugin['api_manager']->activation_email] = '';
\update_option($plugin['api_manager']->data_key, $plugin['api_manager']->options);
\update_option($plugin['api_manager']->activated_key, 'Deactivated');
break;
case '104':
\add_settings_error('api_key_not_activated_text', 'api_key_not_activated_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$plugin['api_manager']->api_key] = '';
$options[$plugin['api_manager']->activation_email] = '';
\update_option($plugin['api_manager']->data_key, $plugin['api_manager']->options);
\update_option($plugin['api_manager']->activated_key, 'Deactivated');
break;
case '105':
\add_settings_error('api_key_invalid_text', 'api_key_invalid_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$plugin['api_manager']->api_key] = '';
$options[$plugin['api_manager']->activation_email] = '';
\update_option($plugin['api_manager']->data_key, $plugin['api_manager']->options);
\update_option($plugin['api_manager']->activated_key, 'Deactivated');
break;
case '106':
\add_settings_error('sub_not_active_text', 'sub_not_active_error', "{$activate_results['error']}. {$activate_results['additional info']}", 'error');
$options[$plugin['api_manager']->api_key] = '';
$options[$plugin['api_manager']->activation_email] = '';
\update_option($plugin['api_manager']->data_key, $plugin['api_manager']->options);
\update_option($plugin['api_manager']->activated_key, 'Deactivated');
break;
}
}
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace ActivePaymentsVendor\WPDesk\License\Page\License\Action;
use ActivePaymentsVendor\WPDesk\License\Page\Action;
/**
* Do nothing.
*
* @package WPDesk\License\Page\License\Action
*/
class Nothing implements \ActivePaymentsVendor\WPDesk\License\Page\Action
{
public function execute(array $plugin)
{
// NOOP
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace ActivePaymentsVendor;
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
if (!\class_exists('WP_List_Table')) {
require_once \ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
class WPDesk_Helper_List_Table extends \WP_List_Table
{
public $per_page = 100;
public $data;
public function __construct($args = [])
{
global $status, $page;
parent::__construct(['singular' => 'subscription', 'plural' => 'subscriptions', 'ajax' => \false]);
$status = 'all';
$page = $this->get_pagenum();
$this->data = [];
parent::__construct($args);
}
public function no_items()
{
echo \wpautop(\__('No WP Desk plugins found.', 'wpdesk-helper'));
}
public function column_default($item, $column_name)
{
return $item[$column_name];
}
public function get_sortable_columns()
{
return [];
}
public function get_columns()
{
$columns = ['product_name' => \__('Plugin', 'wpdesk-helper'), 'product_status' => \__('Subscription Status', 'wpdesk-helper'), 'product_license' => \__('Subscription Data', 'wpdesk-helper')];
return $columns;
}
public function column_plugin_data($item)
{
return '<pre>' . \print_r($item, \true) . '</pre>';
}
public function column_product_name($item)
{
return \wpautop('<strong>' . $item['api_manager']->product_id . '</strong>');
}
public function column_product_version($item)
{
return \wpautop($item['api_manager']->version);
}
public function column_product_status($item)
{
$status = \__('Deactivated', 'wpdesk-helper');
if ($item['activation_status'] == 'Activated') {
$status = \__('Activated', 'wpdesk-helper');
}
return $status;
}
public function column_product_license($item)
{
$disabled = 'disabled';
$api_key = '';
$activation_email = '';
if ($item['activation_status'] == 'Deactivated') {
$disabled = '';
} else {
$api_key = $item['api_manager']->options[$item['api_manager']->api_key];
$activation_email = $item['api_manager']->options[$item['api_manager']->activation_email];
}
$plugin = $item['plugin'];
$activation_status = $item['activation_status'];
\ob_start();
include 'license-actions.php';
$output = \ob_get_contents();
\ob_end_clean();
return $output;
}
public function get_bulk_actions()
{
$actions = [];
return $actions;
}
public function prepare_items()
{
$columns = $this->get_columns();
$hidden = [];
$sortable = $this->get_sortable_columns();
$this->_column_headers = [$columns, $hidden, $sortable];
$total_items = \count($this->data);
$this->set_pagination_args(['total_items' => $total_items, 'per_page' => $total_items]);
$this->items = $this->data;
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace ActivePaymentsVendor;
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
?>
<form method="POST">
<table class="wpdesk_helper_key_table">
<tr>
<td><?php
\_e('Key:', 'wpdesk-helper');
?></td>
<td><input class="wpdesk_helper_input" name="api_key" size="55" type="text"
value="<?php
echo $api_key;
?>" <?php
echo $disabled;
?> /></td>
</tr>
<tr>
<td><?php
\_e('Email:', 'wpdesk-helper');
?></td>
<td><input class="wpdesk_helper_input" name="activation_email" size="55" type="email"
value="<?php
echo $activation_email;
?>" <?php
echo $disabled;
?> /></td>
</tr>
<tr>
<td></td>
<td>
<?php
if ($activation_status == 'Deactivated') {
?>
<button class="wpdesk_helper_button button button-primary"><?php
\_e('Activate', 'wpdesk-helper');
?></button>
<?php
} else {
?>
<button class="wpdesk_helper_button button"><?php
\_e('Deactivate', 'wpdesk-helper');
?></button>
<?php
}
?>
</td>
</tr>
</table>
<input type="hidden" name="plugin" value="<?php
echo $plugin;
?>"/>
<?php
if ($activation_status == 'Deactivated') {
?>
<input type="hidden" name="action" value="activate"/>
<?php
} else {
?>
<input type="hidden" name="action" value="deactivate"/>
<?php
}
?>
</form>
<?php

View File

@@ -0,0 +1,42 @@
<?php
namespace ActivePaymentsVendor;
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
?>
<div class="wrap">
<?php
/* screen_icon(); */
?>
<h1><?php
\_e('WP Desk Subscriptions', 'wpdesk-helper');
?></h1>
<p class="mb0">
<?php
if (\get_locale() === 'pl_PL') {
$url = 'https://www.wpdesk.pl/moje-konto/';
} else {
$url = 'https://www.wpdesk.net/my-account/';
}
$link = \sprintf(\__('Get your subscription keys <a href="%s" target="_blank">here</a>. You can activate/deactivate API keys <strong>unlimited times on different domains</strong> as long as you have an active subscription.', 'wpdesk-helper'), \esc_url($url));
echo $link;
?>
</p>
<?php
\settings_errors();
?>
<?php
$list_table = new \ActivePaymentsVendor\WPDesk_Helper_List_Table();
$list_table->data = $plugins;
$list_table->prepare_items();
$list_table->display();
?>
</div> <!-- class="wrap" -->
<?php

View File

@@ -0,0 +1,128 @@
<?php
namespace ActivePaymentsVendor\WPDesk\License\Page;
use ActivePaymentsVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use ActivePaymentsVendor\WPDesk\License\InstalledPlugins;
/**
* Can render and manage license page.
*
* @package WPDesk\License\Page\License
*/
class LicensePage implements \ActivePaymentsVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
const PAGE_SLUG = 'wpdesk-licenses';
/** @var string Css/Js version */
private $scripts_version = '1';
/** @var InstalledPlugins */
private $plugin_database;
public function __construct(\ActivePaymentsVendor\WPDesk\License\InstalledPlugins $plugin_database)
{
$this->plugin_database = $plugin_database;
}
/**
* Attach license page hooks.
*
* @return void
*/
public function hooks()
{
\add_action('wp_ajax_wpdesk_api_hide_message', [$this, 'handle_api_hide_message']);
\add_action('admin_enqueue_scripts', [$this, 'handle_css_scripts'], 100);
}
/**
* Adds license page submenu.
* Have to be called from admin_menu action.
*
* @return void
*/
public function handle_add_page_submenu_item()
{
\add_submenu_page('wpdesk-helper', \__('Subscriptions', 'wpdesk-helper'), \__('Subscriptions', 'wpdesk-helper'), 'manage_options', self::PAGE_SLUG, [$this, 'handle_render_wpdesk_licenses_page']);
}
/**
* Renders license page.
*
* @return void
*/
public function handle_render_wpdesk_licenses_page()
{
global $wpdesk_helper_plugins;
if (!isset($wpdesk_helper_plugins)) {
$wpdesk_helper_plugins = [];
}
if (isset($_POST['plugin']) && $_POST['action']) {
$this->execute_plugin_action($_POST['plugin'], $_POST['action']);
}
$plugins = $this->plugin_database->get_plugins_activation_info();
/** @noinspection PhpUnusedLocalVariableInspection */
$plugins = $this->ensure_unique_product($plugins);
if (!\class_exists('ActivePaymentsVendor\\WPDesk_Helper_List_Table')) {
require_once __DIR__ . '/License/views/class-wpdesk-helper-list-table.php';
}
include __DIR__ . '/License/views/licenses.php';
}
/**
* Ensures that no product are shown more than once
*
* @param array $plugins
*
* @return array
*/
private function ensure_unique_product(array $plugins)
{
$uniqueness = [];
return \array_filter($plugins, static function ($item) use(&$uniqueness) {
$key = $item['product_id'];
if (!isset($uniqueness[$key])) {
$uniqueness[$key] = \true;
return \true;
}
return \false;
});
}
/**
* Find plugin with given name and execute action with given name.
*
* @param $plugin string Plugin name
* @param $action string to execute
*/
private function execute_plugin_action($plugin, $action)
{
$plugins = $this->plugin_database->get_plugins_activation_info();
foreach ($plugins as $plugin_key => $wpdesk_helper_plugin) {
if ($wpdesk_helper_plugin['plugin'] === $plugin) {
$plugin_info = $wpdesk_helper_plugin;
}
}
if (isset($plugin_info)) {
(new \ActivePaymentsVendor\WPDesk\License\Page\LicensePageActions())->create_action($action)->execute($plugin_info);
}
}
/**
* Remember that the given in request message should be closed.
* Have to be called from wp_ajax_wpdesk_api_hide_message action.
*/
public function handle_api_hide_message()
{
if (\wp_verify_nonce($_REQUEST['nonce'], 'wpdesk-api-ajax-notification-nonce')) {
if (\update_option('wpdesk_api_message_close', $_REQUEST['value'])) {
die('1');
}
die('0');
}
}
/**
* Append license page css.
*
* Have to be called from admin_enqueue_scripts action.
*/
public function handle_css_scripts()
{
$screen = \get_current_screen();
if (isset($screen) && \in_array($screen->base, ['toplevel_page_wpdesk-helper', 'wp-desk_page_wpdesk-licenses', 'wp-desk-1_page_wpdesk-licenses'], \true)) {
\wp_register_style('wpdesk-helper', \plugins_url('wpdesk-helper/assets/css/admin-settings.css'), [], $this->scripts_version);
\wp_enqueue_style('wpdesk-helper');
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace ActivePaymentsVendor\WPDesk\License\Page;
use ActivePaymentsVendor\WPDesk\License\Page\License\Action\LicenseActivation;
use ActivePaymentsVendor\WPDesk\License\Page\License\Action\LicenseDeactivation;
use ActivePaymentsVendor\WPDesk\License\Page\License\Action\Nothing;
/**
* Action factory.
*
* @package WPDesk\License\Page\License
*/
class LicensePageActions
{
/**
* Creates action object according to given param
*
* @param string $action
*
* @return Action
*/
public function create_action($action)
{
if ($action === 'activate') {
return new \ActivePaymentsVendor\WPDesk\License\Page\License\Action\LicenseActivation();
}
if ($action === 'deactivate') {
return new \ActivePaymentsVendor\WPDesk\License\Page\License\Action\LicenseDeactivation();
}
return new \ActivePaymentsVendor\WPDesk\License\Page\License\Action\Nothing();
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace ActivePaymentsVendor\WPDesk\License;
use ActivePaymentsVendor\WPDesk_Plugin_Info;
/**
* Replaces WPDesk_Helper_Plugin. Gets info from plugin and sends it to subscription/update integrations
*
* @package WPDesk\License
*/
class PluginRegistrator
{
/** @var WPDesk_Plugin_Info */
private $plugin_info;
public function __construct(\ActivePaymentsVendor\WPDesk_Plugin_Info $info)
{
$this->plugin_info = $info;
}
/**
* @return bool
*/
public function is_active()
{
return \get_option($this->get_activation_key(), \true) === 'Activated';
}
/**
* @return string
*/
/**
* @return string
*/
private function get_activation_key()
{
return 'api_' . \basename($this->plugin_info->get_plugin_dir()) . '_activated';
}
/**
* Get plugin name in dir/file.php format
*
* @return string
*/
private function get_plugin_wordpress_name()
{
return \basename($this->plugin_info->get_plugin_dir()) . '/' . \basename($this->plugin_info->get_plugin_file_name());
}
/**
* Push info about plugin to the subscription libraries
*
* @TODO: change when wp-wpdesk-license migrate to 2.0
*
* @return void
*/
public function add_plugin_to_installed_plugins()
{
global $wpdesk_helper_plugins;
if (!\is_array($wpdesk_helper_plugins)) {
$wpdesk_helper_plugins = [];
}
if (!$this->is_plugin_already_registered($wpdesk_helper_plugins, $this->plugin_info->get_product_id())) {
$wpdesk_helper_plugins[] = $this->get_plugin_data();
}
}
/**
* @param array $wpdesk_helper_plugins
* @param string $plugin_id
*
* @return bool
*/
private function is_plugin_already_registered(array $wpdesk_helper_plugins, $plugin_id)
{
return \array_reduce($wpdesk_helper_plugins, static function ($carry, $plugin_data) use($plugin_id) {
return $carry || $plugin_data['product_id'] === $plugin_id;
}, \false);
}
/**
* @return array
*/
private function get_plugin_data()
{
return ['plugin' => $this->get_plugin_wordpress_name(), 'product_id' => $this->plugin_info->get_product_id(), 'version' => $this->plugin_info->get_version(), 'config_uri' => ''];
}
}