mirror of
https://github.com/rwsite/wc-plugin-update-server.git
synced 2025-10-04 00:47:35 +08:00
1.0.6 - Added renewal license functions
This commit is contained in:
parent
35dd92fa1b
commit
0fdc19220b
10 changed files with 506 additions and 112 deletions
27
README.md
27
README.md
|
@ -1,16 +1,29 @@
|
|||
# wc-plugin-update-server
|
||||
Woocommerce and Plugin Update Server integration
|
||||
Woocommerce and Plugin Update Server(PUS) integration.
|
||||
Simple and powerfully!
|
||||
Licenses are created automatically after payment for the order. The plugin provides the ability to renew the license.
|
||||
|
||||
**WP Plugin Update Server**
|
||||
https://github.com/froger-me/wp-plugin-update-server
|
||||
|
||||
**WooCommerce**
|
||||
https://github.com/woocommerce/woocommerce
|
||||
|
||||
## Screenshots
|
||||
|
||||
#### Product page
|
||||

|
||||
Plugin create additional settings for WP PUS.
|
||||
|
||||
#### Orders
|
||||

|
||||

|
||||
|
||||
#### Edit order. Manage licences.
|
||||

|
||||
#### WC Product settings. admin part
|
||||

|
||||
|
||||
#### All Orders. admin part
|
||||

|
||||
|
||||
#### WC Order metabox: showing and adding licenses. admin part
|
||||

|
||||

|
||||
|
||||
#### Showing licence data for customer. Renewal function. Front part.
|
||||

|
||||
|
|
|
@ -90,4 +90,16 @@ class LicHelper {
|
|||
public static function get_package_by_path( $path ) {
|
||||
return Wpup_Package::fromArchive( $path, null, new Wpup_FileCache( WPPUS_Data_Manager::get_data_dir( 'cache' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type
|
||||
* @return array
|
||||
*/
|
||||
public static function get_types($package_type=null){
|
||||
$types = [
|
||||
'plugin' => esc_html__('Plugin', 'wc-pus'),
|
||||
'theme' => esc_html__('Theme', 'wc-pus'),
|
||||
];
|
||||
return !empty($package_type) ? $types[$package_type] : $package_type;
|
||||
}
|
||||
}
|
|
@ -26,10 +26,10 @@ final class LicOrder
|
|||
/**
|
||||
* Generate licences and save to order data
|
||||
*
|
||||
* @param int $order_id Order ID.
|
||||
* @param int|null $order_id Order ID.
|
||||
* @return void
|
||||
*/
|
||||
public function create_license_keys( int $order_id)
|
||||
public function create_license_keys( $order_id = null)
|
||||
{
|
||||
$payment_meta = $licenses = [];
|
||||
$order = wc_get_order($order_id);
|
||||
|
@ -51,17 +51,33 @@ final class LicOrder
|
|||
$payment_meta['user_info']['company'] = $get_user_meta['billing_company'][0] ?? '';
|
||||
|
||||
// Generate license keys for all products in order
|
||||
$items = $order->get_items();
|
||||
foreach ($items as $item => $values) {
|
||||
foreach ($order->get_items() as $item => $values) {
|
||||
|
||||
$product_id = $values['product_id'];
|
||||
if(!$values instanceof WC_Order_Item_Product){
|
||||
trigger_error('!$values instanceof WC_Order_Item_Product');
|
||||
}
|
||||
|
||||
$lic_key = $values->get_meta('_wc_pus_license');
|
||||
$product_id = $values->get_product_id();
|
||||
$product = new WC_Product($product_id);
|
||||
|
||||
if ( !LicProduct::get_licensing_enabled($product_id) || !$product->is_downloadable() ) {
|
||||
if ( false === LicProduct::get_licensing_enabled($product_id) && empty($lic_key) ) {
|
||||
continue; // Лицензии выключены или товар не имеет разрешения на загрузку
|
||||
}
|
||||
|
||||
$download_quantity = absint($values['qty']);
|
||||
$old_lic = LicProlong::I()->get_old_lic_data($lic_key);
|
||||
if(!empty($old_lic)){
|
||||
if(LicProlong::I()->update_old_lic($old_lic)) {
|
||||
$message = esc_html__('License key successfully renewed', 'wc-pus');
|
||||
} else {
|
||||
$message = esc_html__('An error occurred while updating the license', 'wc-pus');
|
||||
trigger_error($message);
|
||||
}
|
||||
self::add_order_note($order_id, $message);
|
||||
return;
|
||||
}
|
||||
|
||||
$download_quantity = absint($values->get_quantity());
|
||||
for ($i = 1; $i <= $download_quantity; $i++) {
|
||||
|
||||
$renewal_period = LicProduct::get_renewal_period($product_id);
|
||||
|
@ -92,7 +108,6 @@ final class LicOrder
|
|||
}
|
||||
|
||||
// Build item name
|
||||
$item_name = $product->get_title();
|
||||
$owner_name = (isset($payment_meta['user_info']['first_name'])) ? $payment_meta['user_info']['first_name'] : '';
|
||||
$owner_name .= (isset($payment_meta['user_info']['last_name'])) ? ' ' . $payment_meta['user_info']['last_name'] : '';
|
||||
|
||||
|
@ -101,17 +116,16 @@ final class LicOrder
|
|||
$api_params['linknonce'] = wp_create_nonce('linknonce');
|
||||
$api_params['wppus_license_action'] = 'create';
|
||||
$api_params['page'] = 'wppus-page-licenses';
|
||||
$today = mysql2date('Y-m-d', current_time('mysql'), false);
|
||||
|
||||
$payload = [
|
||||
// default data
|
||||
'license_key' => bin2hex(openssl_random_pseudo_bytes(16)),
|
||||
'date_created' => $today,
|
||||
'date_created' => mysql2date('Y-m-d', current_time('mysql'), false),
|
||||
'status' => 'pending',
|
||||
// setup
|
||||
'max_allowed_domains' => $sites_allowed,
|
||||
'email' => $payment_meta['user_info']['email'] ?? '',
|
||||
'date_renewed' => $today,
|
||||
'date_renewed' => mysql2date('Y-m-d', current_time('mysql'), false),
|
||||
'date_expiry' => $renewal_period,
|
||||
'package_slug' => $product_slug,
|
||||
'package_type' => $product_type,
|
||||
|
@ -129,11 +143,18 @@ final class LicOrder
|
|||
// Collect license keys
|
||||
if (isset($result->license_key)) {
|
||||
$licenses[] = [
|
||||
'item' => $item_name,
|
||||
'item' => $product->get_title(),
|
||||
'key' => $result->license_key,
|
||||
'expires' => $renewal_period,
|
||||
'lic_id' => $result->id
|
||||
];
|
||||
} else {
|
||||
$message = __('License Key(s) could not be created.', 'wc-pus');
|
||||
if(!empty($result['errors'][0])){
|
||||
$message .= $result['errors'][0];
|
||||
}
|
||||
trigger_error($message);
|
||||
self::add_order_note($order_id, $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,14 +169,8 @@ final class LicOrder
|
|||
foreach ($licenses as $license) {
|
||||
$message .= '<br />' . $license['item'] . ': ' . $license['key'];
|
||||
}
|
||||
} else {
|
||||
$message = __('License Key(s) could not be created.', 'wc-pus');
|
||||
if(!empty($result['errors'][0])){
|
||||
$message .= $result['errors'][0];
|
||||
}
|
||||
self::add_order_note($order_id, $message);
|
||||
}
|
||||
|
||||
self::add_order_note($order_id, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,16 +186,22 @@ final class LicOrder
|
|||
*
|
||||
* @param WC_Order $order
|
||||
*/
|
||||
public function print_order_meta(WC_Order $order){
|
||||
$licenses = get_post_meta($order->get_id(), LicOrder::key, true);
|
||||
public function print_order_meta($order, $show_title = true){
|
||||
$licenses = get_post_meta( is_int($order) ? $order : $order->get_id() , LicOrder::key, true);
|
||||
|
||||
if (!empty($licenses) && count($licenses) != 0) {
|
||||
$output = '<h2>' . __('Your Licenses', 'wc-pus') . ':</h2>';
|
||||
$output = '';
|
||||
if($show_title) {
|
||||
$output .= '<h2>' . __( 'Your Licenses', 'wc-pus' ) . ':</h2>';
|
||||
}
|
||||
$output .= '<table class="shop_table shop_table_responsive"><tr>';
|
||||
$output .= '<th class="td">' . __('Expires', 'wc-pus') . '</th>';
|
||||
$output .= '<th class="td">' . __('Key', 'wc-pus') . '</th>';
|
||||
$output .= '<th class="td">' . __('Domain', 'wc-pus') . '</th>';
|
||||
$output .= '<th class="td">' . __('Domain', 'wc-pus' ) . '</th>';
|
||||
$output .= '<th class="td">' . __('Download', 'wc-pus') . '</th></tr>';
|
||||
|
||||
$output = apply_filters('wc_pus_table_header', $output, $licenses);
|
||||
|
||||
$lic_manager = new WPPUS_License_Server();
|
||||
foreach ($licenses as $license) {
|
||||
/*
|
||||
|
@ -199,7 +220,7 @@ final class LicOrder
|
|||
[package_slug] => woo-to-iiko
|
||||
[package_type] => plugin
|
||||
*/
|
||||
$lic = (array)$lic_manager->read_license(['id' => $license['lic_id'] ?? $license]);
|
||||
$lic = (array) $lic_manager->read_license(['id' => $license['lic_id'] ?? $license]);
|
||||
if(empty($lic)){
|
||||
continue;
|
||||
}
|
||||
|
@ -207,28 +228,31 @@ final class LicOrder
|
|||
$lic['download'] = $this->generate_download_link($lic);
|
||||
$html = '';
|
||||
foreach ($lic['allowed_domains'] as $domain){
|
||||
$html .= '<a href="https://'.$domain.'" target="_blank">' .$domain . '</a><br>';
|
||||
$html .= '<a href="https://'.$domain.'" target="_blank" class="domain">' .$domain . '</a><br>';
|
||||
}
|
||||
|
||||
$output .= '<tr>';
|
||||
$output .= '<td class="td">' . $lic['date_expiry'] . '</td>';
|
||||
$output .= '<td class="td">' . $lic['license_key'] . '</td>';
|
||||
$output .= '<td class="td">' . $html . '</td>';
|
||||
$output .= '<td class="td">'. $lic['license_key'] .'</td>';
|
||||
$output .= '<td class="td">' . $html . '</td>';
|
||||
|
||||
if(strtotime($lic['date_expiry']) > time()) {
|
||||
$output .= '<td class="td"><a href="' . $lic['download'] . '" target="_blank" class="button alt">'
|
||||
. $lic['package_slug'] . '</a></td>';
|
||||
|
||||
$bs4['class'] = LicProlong::I()->bs4 ? 'btn btn-primary' : 'button';
|
||||
$bs4['icon'] = LicProlong::I()->bs4 ? '<i class="las la-cloud-download-alt"></i>' : '';
|
||||
|
||||
$output .= '<td class="td"><a href="' . $lic['download'] . '"
|
||||
target="_blank" class="'.$bs4['class'].' download">' . $bs4['icon'] . $lic['package_slug'] . '</a></td>';
|
||||
} else {
|
||||
$output .= '<td class="td">' . __( 'Licence has expired', 'wc-pus' ) . '</td>';
|
||||
$output .= '<td class="td">' . __( 'Licence has expired', 'wc-pus' ) . '</td>';
|
||||
}
|
||||
$output .= '</tr>';
|
||||
$output .= '<tr><td colspan="2">'. LicProlong::I()->render_renewal_checkout_link($lic) . '</td></tr>';
|
||||
}
|
||||
$output .= '</table>';
|
||||
}
|
||||
|
||||
if (isset($output)) {
|
||||
echo $output;
|
||||
}
|
||||
echo apply_filters('wc_pus_table', $output ?? '', $licenses, $order);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -266,22 +290,13 @@ final class LicOrder
|
|||
}
|
||||
$output .= '</table>';
|
||||
} else {
|
||||
// $output .= 'No License Generatred';
|
||||
// $output .= 'No License Generated';
|
||||
}
|
||||
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function get_types(){
|
||||
return [
|
||||
'plugin' => __('Plugin', 'wc-pus'),
|
||||
'theme' => __('Theme', 'wc-pus'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Render link to download file
|
||||
|
|
|
@ -311,23 +311,21 @@ final class LicOrderMetaBox
|
|||
{
|
||||
$options_products = [];
|
||||
$line_items = $order->get_items();
|
||||
|
||||
$can_add = false;
|
||||
foreach ($line_items as $item) {
|
||||
if($item instanceof WC_Order_Item_Product) {
|
||||
$product = $item->get_product();
|
||||
if('1' == $product->get_meta('_wc_slm_licensing_enabled')) {
|
||||
$options_products[ $product->get_id() ] = $item->get_name();
|
||||
$can_add = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*$packages = LicHelper::get_package() ?: ['slug' => ''];
|
||||
$options = [];
|
||||
foreach ($packages as $package){
|
||||
$options[$package['slug']] = $package['name'];
|
||||
if(!$can_add){
|
||||
_e('Licenses cannot be added to this order.', 'wc-pus');
|
||||
return;
|
||||
}
|
||||
|
||||
$package = array_shift($packages);*/
|
||||
?>
|
||||
|
||||
<h3><?php _e('Add new licence', 'wc-pus')?>:</h3>
|
||||
|
@ -442,8 +440,8 @@ final class LicOrderMetaBox
|
|||
global $wpdb;
|
||||
|
||||
if(!empty($id)) {
|
||||
$result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wppus_licenses WHERE `id` = '%d'",
|
||||
$id ) );
|
||||
$result = $wpdb->get_results(
|
||||
$wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wppus_licenses WHERE `id` = '%d'",$id ) );
|
||||
}
|
||||
|
||||
return $result[0] ?? null;
|
||||
|
|
|
@ -50,14 +50,15 @@ final class LicPlugin {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( is_admin() ) {
|
||||
//if ( is_admin() ) {
|
||||
// new Software_Licence_Manager_integration();
|
||||
}
|
||||
//}
|
||||
|
||||
( new LicOrderMetaBox() )->add_actions();
|
||||
( new LicProduct() )->add_actions();
|
||||
( new LicOrder() )->add_actions();
|
||||
( new LicHelper() )->add_actions();
|
||||
LicProlong::I()->add_actions();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
263
includes/LicProlong.php
Normal file
263
includes/LicProlong.php
Normal file
|
@ -0,0 +1,263 @@
|
|||
<?php
|
||||
/**
|
||||
* Name: WooCommerce make order on the fly
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class LicProlong
|
||||
{
|
||||
|
||||
private static $instance;
|
||||
|
||||
/** @var false|int */
|
||||
public $base_product;
|
||||
|
||||
/** @var string */
|
||||
public $renewal_period;
|
||||
|
||||
/** @var bool */
|
||||
public $bs4;
|
||||
|
||||
|
||||
/**
|
||||
* @return LicProlong
|
||||
*/
|
||||
public static function I() {
|
||||
if ( static::$instance === null ) {
|
||||
static::$instance = new self();
|
||||
}
|
||||
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
private function __construct(){
|
||||
$this->base_product = !empty(get_option('wc_pus_product')) ? absint(get_option('wc_pus_product')) : null;
|
||||
$this->renewal_period = get_option('wc_pus_renewal_period', null);
|
||||
$this->bs4 = (bool) get_option('wc_pus_bs4', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add actions
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add_actions(){
|
||||
|
||||
add_action( 'admin_menu', function (){
|
||||
$function = array( $this, 'plugin_help_page' );
|
||||
$page_title = __( 'WP Plugin Update Server - WcooCommerce', 'wppus' );
|
||||
$menu_title = __( 'WooCommerce', 'wppus' );
|
||||
$menu_slug = 'wppus-page-wc';
|
||||
$capability = 'manage_options';
|
||||
$parent_slug = 'wppus-page';
|
||||
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
|
||||
}, 199, 0 );
|
||||
|
||||
/* 1. Add lic key to product. Make order with product. */
|
||||
add_action('template_redirect', [$this, 'checkout_render']);
|
||||
|
||||
/* 2. Display information as Meta on Cart page. */
|
||||
add_filter('woocommerce_get_item_data', [$this, 'woocommerce_get_item_data'], 99, 2);
|
||||
|
||||
/* 3. Save to order data. Showing on order received page. */
|
||||
add_action('woocommerce_checkout_create_order_line_item', [$this, 'woocommerce_checkout_create_order_line_item'],9,4);
|
||||
}
|
||||
|
||||
public function checkout_render(){
|
||||
if(!is_checkout() || empty($this->base_product) || !isset($_GET['wcpus_lic'])){
|
||||
return;
|
||||
}
|
||||
$lic = $_GET['wcpus_lic'];
|
||||
$lic_data = $this->get_old_lic_data($lic);
|
||||
WC()->cart->empty_cart(true);
|
||||
WC()->cart->add_to_cart($this->base_product, 1, 0, [], [
|
||||
'wc_pus_license' => $lic,
|
||||
'wc_pus_label' => LicHelper::get_types($lic_data->package_type) .' '. $lic_data->package_slug,
|
||||
'wc_pus_public_info' => substr($lic, 0, 5) .
|
||||
implode('', array_fill(1, mb_strlen($lic, 'UTF-8') - 8, 'x')) .
|
||||
substr($lic, -3, 3),
|
||||
'wc_pus_license_data' => $lic_data
|
||||
]);
|
||||
}
|
||||
|
||||
public function woocommerce_get_item_data(array $item_data, array $cart_item){
|
||||
if(isset($cart_item['wc_pus_license'])){
|
||||
$item_data[] = [
|
||||
'key' => $cart_item['wc_pus_label'], // showing
|
||||
'value' => $cart_item['wc_pus_public_info'], // showing
|
||||
'wc_pus_license' => $cart_item['wc_pus_license']
|
||||
];
|
||||
}
|
||||
return $item_data;
|
||||
}
|
||||
|
||||
public function woocommerce_checkout_create_order_line_item(WC_Order_Item_Product $item, $cart_item_key, $cart_items, $order){
|
||||
if(isset($cart_items['wc_pus_license'])){
|
||||
$item->add_meta_data($cart_items['wc_pus_label'], $cart_items['wc_pus_public_info']);
|
||||
$item->add_meta_data('_wc_pus_license', $cart_items['wc_pus_license']);
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render settings page. ADM
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function plugin_help_page() {
|
||||
|
||||
$chosen = $this->base_product;
|
||||
$products = ['' => ''] + get_posts(['post_type' => 'product']);
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( __( 'Sorry, you are not allowed to access this page.' ) ); // @codingStandardsIgnoreLine
|
||||
}
|
||||
|
||||
if(isset($_POST['wc_pus_product'])){
|
||||
$chosen = is_numeric($_POST['wc_pus_product']) ? absint($_POST['wc_pus_product']) : '';
|
||||
update_option('wc_pus_product', $chosen);
|
||||
}
|
||||
|
||||
if(isset($_POST['wc_pus_renewal_period'])){
|
||||
$this->renewal_period = absint($_POST['wc_pus_renewal_period']);
|
||||
update_option('wc_pus_renewal_period', $this->renewal_period);
|
||||
}
|
||||
|
||||
if(isset($_POST['wc_pus_bs4'])){
|
||||
$this->bs4 = 'on' === $_POST['wc_pus_bs4'] ? 1 : 0;
|
||||
update_option('wc_pus_bs4', $this->bs4);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="wrap wppus-wrap">
|
||||
<h1><?php esc_html_e('WP Plugin Update Server', 'wppus'); ?></h1>
|
||||
<h2 class="nav-tab-wrapper">
|
||||
<a href="admin.php?page=wppus-page" class="nav-tab">
|
||||
<span class='dashicons dashicons-welcome-view-site'></span> <?php esc_html_e('Overview', 'wppus'); ?>
|
||||
</a>
|
||||
<a href="admin.php?page=wppus-page-remote-sources" class="nav-tab">
|
||||
<span class='dashicons dashicons-networking'></span> <?php esc_html_e('Remote Sources', 'wppus'); ?>
|
||||
</a>
|
||||
<a href="admin.php?page=wppus-page-licenses" class="nav-tab">
|
||||
<span class='dashicons dashicons-admin-network'></span> <?php esc_html_e('Licenses', 'wppus'); ?>
|
||||
</a>
|
||||
<a href="admin.php?page=wppus-page-help" class="nav-tab nav-tab">
|
||||
<span class='dashicons dashicons-editor-help'></span> <?php esc_html_e('Help', 'wppus'); ?>
|
||||
</a>
|
||||
<a href="admin.php?page=wppus-page-wc" class="nav-tab nav-tab-active">
|
||||
<span class='dashicons dashicons-cart'></span> <?php esc_html_e('WooCommerce', 'wc-pus'); ?>
|
||||
</a>
|
||||
</h2>
|
||||
<h2><?php esc_html_e('WooCommerce integration settings', 'wc-pus'); ?></h2>
|
||||
<form action="" method="post">
|
||||
<p>
|
||||
<label for="wc_pus_bs4"><?php esc_html_e('Enable bootstrap styles capability?', 'wc-pus') ?></label>
|
||||
<input type="hidden" name="wc_pus_bs4" value="0" />
|
||||
<input id="wc_pus_bs4" name="wc_pus_bs4" type="checkbox" <?= $this->bs4 ? 'checked' : ''; ?> >
|
||||
</p>
|
||||
<hr>
|
||||
<h3><?php esc_html_e('Renewal settings', 'wc-pus'); ?></h3>
|
||||
<p><label><?php esc_html_e('Renewal period in days', 'wc-pus'); ?>: <input name="wc_pus_renewal_period" type="number" min="0" max="99999" value="<?=$this->renewal_period?>"></label></p>
|
||||
<p><label for="wc_pus_product"><?php _e('Base product as prolongation', 'wc-pus') ?>:</label><br/>
|
||||
<select id="wc_pus_product" name="wc_pus_product" style="width:99%; max-width:25em;">
|
||||
<?php
|
||||
foreach ($products as $product) {
|
||||
$selected = ( isset($product->ID) && $product->ID === $chosen) ? ' selected="selected"' : '';
|
||||
if(empty($product)) {
|
||||
echo '<option value="' . $product . '"' . $selected . '>' . $product . '</option>';
|
||||
continue;
|
||||
}
|
||||
$wc_product = wc_get_product($product);
|
||||
echo '<option value="' . $product->ID . '"' . $selected . '>' . $wc_product->get_name() .' - '. $wc_product->get_price() . '</option>';
|
||||
} ?>
|
||||
<select>
|
||||
<button type="submit" class="close-panel button button-primary"><?php esc_html_e('Save', 'wc-pus'); ?></button>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
echo ob_get_clean(); // @codingStandardsIgnoreLine
|
||||
}
|
||||
|
||||
/**
|
||||
* Render renewal link
|
||||
*
|
||||
* @param array $lic
|
||||
* @return void
|
||||
*/
|
||||
public function render_renewal_checkout_link($lic)
|
||||
{
|
||||
$product = wc_get_product($this->base_product);
|
||||
|
||||
$bs4['class'] = LicProlong::I()->bs4 ? 'btn btn-outline-primary' : 'button';
|
||||
$bs4['icon'] = LicProlong::I()->bs4 ? '<i class="las la-cart-arrow-down"></i>' : '';
|
||||
|
||||
$html = '<small>' . sprintf(esc_html__('Your can renew this license key until: %s', 'wc-pus'),
|
||||
'<strong>' . $this->get_renewal_period((object)$lic) . '</strong>') . '</small>';
|
||||
$html .= '</td><td colspan="2" style="text-align: right">
|
||||
<a href="' . wc_get_checkout_url() . '?wcpus_lic=' . $lic['license_key'] . '"
|
||||
class="' . $bs4['class'] . ' renew">' . $bs4['icon'] .
|
||||
sprintf(esc_html__('Renew license for %s', 'wc-pus'),
|
||||
'<span style="margin-left: 5px">' . $product->get_price_html() . '</span>') . '</a>';
|
||||
|
||||
return apply_filters('wc_pus_renew_link', $html);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set new renewal period
|
||||
*
|
||||
* @param stdClass $old_lic
|
||||
* @return string num days
|
||||
*/
|
||||
public function get_renewal_period($old_lic){
|
||||
$days = LicProlong::I()->renewal_period;
|
||||
if(strtotime('now') > strtotime($old_lic->date_expiry) ){ // license has already expired
|
||||
$period = date('Y-m-d', strtotime('+'.$days.' days'));
|
||||
} else {
|
||||
$period = date('Y-m-d', strtotime('+'.$days.' days', strtotime($old_lic->date_expiry)));
|
||||
}
|
||||
return $period;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return today day
|
||||
* @return false|int|string
|
||||
*/
|
||||
private function get_date_renewed(){
|
||||
return mysql2date('Y-m-d', current_time('mysql'), false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get old licence data from DB
|
||||
*
|
||||
* @param string $lic_key
|
||||
* @return stdClass|null
|
||||
*/
|
||||
public function get_old_lic_data($lic_key){
|
||||
global $wpdb;
|
||||
return $wpdb->get_results("SELECT * FROM {$wpdb->prefix}wppus_licenses WHERE `license_key` = '{$lic_key}'")[0] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update old lic data
|
||||
*
|
||||
* @param stdClass $old_lic_data
|
||||
* @return bool|int|mysqli_result|resource|null
|
||||
*/
|
||||
public function update_old_lic(stdClass $old_lic_data){
|
||||
global $wpdb;
|
||||
$renewal_period = $this->get_renewal_period($old_lic_data);
|
||||
return $wpdb->update("{$wpdb->prefix}wppus_licenses",
|
||||
['date_expiry' => $renewal_period, 'date_renewed' => $this->get_date_renewed()],['id' => $old_lic_data->id] );
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
|
@ -3,7 +3,7 @@ msgstr ""
|
|||
"Project-Id-Version: WC Plugin Update Server integration\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-02-06 12:22+0000\n"
|
||||
"PO-Revision-Date: 2023-05-12 21:10+0000\n"
|
||||
"PO-Revision-Date: 2023-07-22 00:12+0000\n"
|
||||
"Last-Translator: Алексей\n"
|
||||
"Language-Team: Русский\n"
|
||||
"Language: ru_RU\n"
|
||||
|
@ -16,31 +16,39 @@ msgstr ""
|
|||
"X-Loco-Version: 2.6.4; wp-6.2\n"
|
||||
"X-Domain: wc-pus"
|
||||
|
||||
#: includes/LicOrderMetaBox.php:387
|
||||
#: includes/LicOrderMetaBox.php:331 includes/LicOrderMetaBox.php:385
|
||||
msgid "Add new licence"
|
||||
msgstr "Добавить новую лицензию"
|
||||
|
||||
#: includes/LicOrderMetaBox.php:333
|
||||
msgid "Add new license"
|
||||
msgstr ""
|
||||
|
||||
#. Author of the plugin
|
||||
#| msgid "Aleksey Tikhomirov"
|
||||
msgid "Aleksei Tikhomirov"
|
||||
msgstr "Алексей Тихомиров"
|
||||
|
||||
#: includes/LicOrderMetaBox.php:339
|
||||
#: includes/LicOrder.php:73
|
||||
msgid "An error occurred while updating the license"
|
||||
msgstr "Произошла ошибка при обновлении лицензии"
|
||||
|
||||
#: includes/LicProlong.php:167
|
||||
msgid "Base product as prolongation"
|
||||
msgstr "Базовый товар в качестве продления"
|
||||
|
||||
#: includes/LicOrderMetaBox.php:337
|
||||
msgid "Choose product"
|
||||
msgstr "Выберите товар"
|
||||
|
||||
#: includes/LicOrder.php:181
|
||||
#: includes/LicOrder.php:200
|
||||
msgid "Domain"
|
||||
msgstr "Домен"
|
||||
|
||||
#: includes/LicOrder.php:182
|
||||
#: includes/LicOrder.php:201
|
||||
msgid "Download"
|
||||
msgstr "Скачать"
|
||||
|
||||
#: includes/LicProlong.php:160
|
||||
msgid "Enable bootstrap styles capability?"
|
||||
msgstr "Включить совместимые bootstrap стили?"
|
||||
|
||||
#: includes/LicProduct.php:59
|
||||
msgid "Enable licensing for this download."
|
||||
msgstr "Включить лицензии"
|
||||
|
@ -49,11 +57,11 @@ msgstr "Включить лицензии"
|
|||
msgid "Error! The license key creating has been failed."
|
||||
msgstr "Ошибка! Не удалось создать лицензионный ключ."
|
||||
|
||||
#: includes/LicOrder.php:179
|
||||
#: includes/LicOrder.php:198
|
||||
msgid "Expires"
|
||||
msgstr "Истекает"
|
||||
|
||||
#: includes/LicOrder.php:251
|
||||
#: includes/LicOrder.php:275
|
||||
msgid "Expiry"
|
||||
msgstr "Срок действия"
|
||||
|
||||
|
@ -67,45 +75,49 @@ msgstr ""
|
|||
msgid "http://rwsite.ru"
|
||||
msgstr "http://rwsite.ru"
|
||||
|
||||
#: includes/LicOrder.php:249
|
||||
#: includes/LicOrder.php:273
|
||||
msgid "Item"
|
||||
msgstr "Позиция"
|
||||
|
||||
#: includes/LicOrder.php:180
|
||||
#: includes/LicOrder.php:199
|
||||
msgid "Key"
|
||||
msgstr "Ключ"
|
||||
|
||||
#: includes/LicOrder.php:222
|
||||
#: includes/LicOrder.php:247
|
||||
msgid "Licence has expired"
|
||||
msgstr "Срок действия лицензии истек"
|
||||
|
||||
#: includes/LicOrderMetaBox.php:264 includes/LicOrderMetaBox.php:403
|
||||
#: includes/LicOrderMetaBox.php:264 includes/LicOrderMetaBox.php:401
|
||||
#| msgid "Licence: "
|
||||
msgid "Licences"
|
||||
msgstr "Лицензии:"
|
||||
|
||||
#: includes/LicOrder.php:250
|
||||
#: includes/LicOrder.php:274
|
||||
msgid "License"
|
||||
msgstr "Лицензия"
|
||||
|
||||
#: includes/LicOrder.php:84
|
||||
#: includes/LicOrder.php:100
|
||||
msgid "License could not be created: Invalid product slug."
|
||||
msgstr "Не удалось создать лицензию: недопустимый slug."
|
||||
|
||||
#: includes/LicOrder.php:90
|
||||
#: includes/LicOrder.php:106
|
||||
msgid "License could not be created: Invalid product type."
|
||||
msgstr "Не удалось создать лицензию: неверный тип продукта."
|
||||
|
||||
#: includes/LicOrder.php:77
|
||||
#: includes/LicOrder.php:93
|
||||
msgid "License could not be created: Invalid sites allowed number."
|
||||
msgstr ""
|
||||
"Не удалось создать лицензию: недопустимое разрешенное количество сайтов."
|
||||
|
||||
#: includes/LicOrder.php:71
|
||||
msgid "License key successfully renewed"
|
||||
msgstr "Лицензионный ключ успешно обновлен"
|
||||
|
||||
#: includes/LicOrder.php:152
|
||||
msgid "License Key(s) could not be created."
|
||||
msgstr "Ошибка! Не удалось создать лицензии."
|
||||
|
||||
#: includes/LicOrder.php:147
|
||||
#: includes/LicOrder.php:168
|
||||
msgid "License Key(s) generated"
|
||||
msgstr "Лицензионный ключ создан"
|
||||
|
||||
|
@ -113,11 +125,15 @@ msgstr "Лицензионный ключ создан"
|
|||
msgid "license renewal period(yearly). Enter 0 for lifetime."
|
||||
msgstr "период продления лицензии (ежегодно). Введите 0 для lifetime."
|
||||
|
||||
#: includes/LicOrderMetaBox.php:326
|
||||
msgid "Licenses cannot be added to this order."
|
||||
msgstr "Лицензии не могут быть добавлены к этому заказу."
|
||||
|
||||
#: includes/LicOrderMetaBox.php:39
|
||||
msgid "Manage licences"
|
||||
msgstr "Управление лицензиями"
|
||||
|
||||
#: includes/LicOrder.php:281
|
||||
#: includes/LicHelper.php:100
|
||||
msgid "Plugin"
|
||||
msgstr "Плагин"
|
||||
|
||||
|
@ -129,20 +145,45 @@ msgstr "Product slug"
|
|||
msgid "Product type (plugin or theme)."
|
||||
msgstr "Тип продукта (плагин или тема)."
|
||||
|
||||
#: includes/LicProlong.php:206
|
||||
#, php-format
|
||||
msgid "Renew license for %s"
|
||||
msgstr "Продление лицензию для %s"
|
||||
|
||||
#: includes/LicProlong.php:166
|
||||
msgid "Renewal period in days"
|
||||
msgstr "Срок продления в днях"
|
||||
|
||||
#: includes/LicProlong.php:165
|
||||
msgid "Renewal settings"
|
||||
msgstr "Настройки продления"
|
||||
|
||||
#: includes/LicProlong.php:180
|
||||
msgid "Save"
|
||||
msgstr "Схранить"
|
||||
|
||||
#: includes/LicOrderMetaBox.php:143
|
||||
msgid "The license Key has been generated success"
|
||||
msgstr "Лицензионный ключ сгенерирован успешно"
|
||||
|
||||
#: includes/LicOrder.php:282
|
||||
#: includes/LicHelper.php:101
|
||||
msgid "Theme"
|
||||
msgstr "Тема"
|
||||
|
||||
#: includes/LicProlong.php:154
|
||||
msgid "WooCommerce"
|
||||
msgstr "WooCommerce"
|
||||
|
||||
#. Name of the plugin
|
||||
#| msgid "WooCommerce Plugin Update Server integration"
|
||||
msgid "WooCommerce and Plugin Update Server integration"
|
||||
msgstr "Интеграция WooCommerce и Сервера Обновлений Плагинов"
|
||||
|
||||
#: includes/LicPlugin.php:56
|
||||
#: includes/LicProlong.php:157
|
||||
msgid "WooCommerce integration settings"
|
||||
msgstr "Настройки интеграции c WooCommerce"
|
||||
|
||||
#: includes/LicPlugin.php:45
|
||||
#| msgid ""
|
||||
#| "Woocommerce or WPPUS_License_Server is not activated. To work this plugin,"
|
||||
#| " you need to install and activate WooCommerce and WPPUS_License_Server "
|
||||
|
@ -160,6 +201,11 @@ msgstr ""
|
|||
msgid "You can change this data in WP PUS"
|
||||
msgstr "Вы можете изменить эти данные в WP PUS"
|
||||
|
||||
#: includes/LicOrder.php:177 includes/LicOrder.php:248
|
||||
#: includes/LicProlong.php:201
|
||||
#, php-format
|
||||
msgid "Your can renew this license key until: %s"
|
||||
msgstr "Вы можете продлить этот ключ до: %s"
|
||||
|
||||
#: includes/LicOrder.php:195 includes/LicOrder.php:272
|
||||
msgid "Your Licenses"
|
||||
msgstr "Ваши лицензии"
|
||||
|
|
|
@ -3,7 +3,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: WC Plugin Update Server integration\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2023-05-12 06:10+0000\n"
|
||||
"POT-Creation-Date: 2023-07-22 00:11+0000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: \n"
|
||||
|
@ -16,11 +16,7 @@ msgstr ""
|
|||
"X-Loco-Version: 2.5.0; wp-5.6.1\n"
|
||||
"X-Domain: wc-pus"
|
||||
|
||||
#: includes/LicOrderMetaBox.php:387
|
||||
msgid "Add new licence"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrderMetaBox.php:333
|
||||
#: includes/LicOrderMetaBox.php:331 includes/LicOrderMetaBox.php:385
|
||||
msgid "Add new licence"
|
||||
msgstr ""
|
||||
|
||||
|
@ -28,18 +24,30 @@ msgstr ""
|
|||
msgid "Aleksei Tikhomirov"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrderMetaBox.php:339
|
||||
#: includes/LicOrder.php:73
|
||||
msgid "An error occurred while updating the license"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicProlong.php:167
|
||||
msgid "Base product as prolongation"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrderMetaBox.php:337
|
||||
msgid "Choose product"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:181
|
||||
#: includes/LicOrder.php:200
|
||||
msgid "Domain"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:182
|
||||
#: includes/LicOrder.php:201
|
||||
msgid "Download"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicProlong.php:160
|
||||
msgid "Enable bootstrap styles capability?"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicProduct.php:59
|
||||
msgid "Enable licensing for this download."
|
||||
msgstr ""
|
||||
|
@ -48,11 +56,11 @@ msgstr ""
|
|||
msgid "Error! The license key creating has been failed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:179
|
||||
#: includes/LicOrder.php:198
|
||||
msgid "Expires"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:251
|
||||
#: includes/LicOrder.php:275
|
||||
msgid "Expiry"
|
||||
msgstr ""
|
||||
|
||||
|
@ -65,43 +73,47 @@ msgstr ""
|
|||
msgid "http://rwsite.ru"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:249
|
||||
#: includes/LicOrder.php:273
|
||||
msgid "Item"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:180
|
||||
#: includes/LicOrder.php:199
|
||||
msgid "Key"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:222
|
||||
#: includes/LicOrder.php:247
|
||||
msgid "Licence has expired"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrderMetaBox.php:264 includes/LicOrderMetaBox.php:403
|
||||
#: includes/LicOrderMetaBox.php:264 includes/LicOrderMetaBox.php:401
|
||||
msgid "Licences"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:250
|
||||
#: includes/LicOrder.php:274
|
||||
msgid "License"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:84
|
||||
#: includes/LicOrder.php:100
|
||||
msgid "License could not be created: Invalid product slug."
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:90
|
||||
#: includes/LicOrder.php:106
|
||||
msgid "License could not be created: Invalid product type."
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:77
|
||||
#: includes/LicOrder.php:93
|
||||
msgid "License could not be created: Invalid sites allowed number."
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:71
|
||||
msgid "License key successfully renewed"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:152
|
||||
msgid "License Key(s) could not be created."
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:147
|
||||
#: includes/LicOrder.php:168
|
||||
msgid "License Key(s) generated"
|
||||
msgstr ""
|
||||
|
||||
|
@ -109,11 +121,15 @@ msgstr ""
|
|||
msgid "license renewal period(yearly). Enter 0 for lifetime."
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrderMetaBox.php:326
|
||||
msgid "Licenses cannot be added to this order."
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrderMetaBox.php:39
|
||||
msgid "Manage licences"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:281
|
||||
#: includes/LicHelper.php:100
|
||||
msgid "Plugin"
|
||||
msgstr ""
|
||||
|
||||
|
@ -125,19 +141,44 @@ msgstr ""
|
|||
msgid "Product type (plugin or theme)."
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicProlong.php:206
|
||||
#, php-format
|
||||
msgid "Renew license for %s"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicProlong.php:166
|
||||
msgid "Renewal period in days"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicProlong.php:165
|
||||
msgid "Renewal settings"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicProlong.php:180
|
||||
msgid "Save"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrderMetaBox.php:143
|
||||
msgid "The license Key has been generated success"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:282
|
||||
#: includes/LicHelper.php:101
|
||||
msgid "Theme"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicProlong.php:154
|
||||
msgid "WooCommerce"
|
||||
msgstr ""
|
||||
|
||||
#. Name of the plugin
|
||||
msgid "WooCommerce and Plugin Update Server integration"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicPlugin.php:56
|
||||
#: includes/LicProlong.php:157
|
||||
msgid "WooCommerce integration settings"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicPlugin.php:45
|
||||
msgid ""
|
||||
"Woocommerce or WP Plugin Update Server is not activated. To work this plugin,"
|
||||
" you need to install and activate WooCommerce and WPPUS_License_Server "
|
||||
|
@ -148,6 +189,11 @@ msgstr ""
|
|||
msgid "You can change this data in WP PUS"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:177 includes/LicOrder.php:248
|
||||
#: includes/LicProlong.php:201
|
||||
#, php-format
|
||||
msgid "Your can renew this license key until: %s"
|
||||
msgstr ""
|
||||
|
||||
#: includes/LicOrder.php:195 includes/LicOrder.php:272
|
||||
msgid "Your Licenses"
|
||||
msgstr ""
|
||||
|
|
|
@ -3,18 +3,18 @@
|
|||
* Plugin Name: WooCommerce and Plugin Update Server integration
|
||||
* Plugin URI: http://rwsite.ru
|
||||
* Description:
|
||||
* Version: 1.0.5
|
||||
* Version: 1.0.6
|
||||
* Author: Aleksei Tikhomirov
|
||||
* Author URI: http://rwsite.ru
|
||||
* Text Domain: wc-pus
|
||||
* Domain Path: /languages
|
||||
*
|
||||
* Tested up to: 6.3.0
|
||||
* Tested up to: 6.2.3
|
||||
* Requires at least: 5.6
|
||||
* Requires PHP: 7.4+
|
||||
*
|
||||
* WC requires at least: 6.0
|
||||
* WC tested up to: 7.7.0
|
||||
* WC tested up to: 7.9.0
|
||||
*
|
||||
*
|
||||
* @author <alex@rwsite.ru>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue