| @@ -1,60 +1,155 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +// Exit if accessed directly. | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 2 | 8 | /** |
| 3 | 9 | * Display the table of products requiring licenses. |
| 4 | 10 | * |
| 5 | 11 | * @author David Bisset |
| 6 | 12 | * @package Charitable/Admin View/Settings |
| 7 | - * @copyright Copyright (c) 2022, WP Charitable LLC | |
| 13 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | 14 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | 15 | * @since 1.0.0 |
| 10 | - * @version 1.0.0 | |
| 16 | + * @version 1.8.8.6 | |
| 11 | 17 | */ |
| 12 | 18 | |
| 13 | -$helper = charitable_get_helper( 'licenses' ); | |
| 14 | -$products = $helper->get_products(); | |
| 19 | +$charitable_helper = charitable_get_helper( 'licenses' ); | |
| 20 | +$charitable_products = $charitable_helper->get_products(); | |
| 15 | 21 | |
| 16 | -if ( empty( $products ) ) : | |
| 22 | +if ( empty( $charitable_products ) ) : | |
| 17 | 23 | return; |
| 18 | 24 | endif; |
| 19 | -?> | |
| 20 | -<div class="charitable-settings-notice" style="margin-bottom: 20px;"> | |
| 21 | - <p><?php _e( 'By adding your license keys, you agree for your website to send requests to wpcharitable.com to check license details and provide automatic plugin updates.', 'charitable' ); ?></p> | |
| 22 | - <p><?php _e( 'Your license can be disconnected at any time.', 'charitable' ); ?></p> | |
| 25 | + | |
| 26 | +$charitable_slug = Charitable_Addons_Directory::get_current_plan_slug(); | |
| 27 | +$charitable_is_legacy = Charitable_Addons_Directory::is_current_plan_legacy(); | |
| 28 | + | |
| 29 | +if ( false !== $charitable_slug && strtolower( $charitable_slug ) !== 'lite' && ! $charitable_is_legacy ) { | |
| 30 | + | |
| 31 | + // there is a valid legacy license present. | |
| 32 | + $charitable_new_tab_notification = | |
| 33 | + '<p>' . | |
| 34 | + sprintf( | |
| 35 | + wp_kses( | |
| 36 | + /* translators: %s - charitable.com upgrade URL. */ | |
| 37 | + __( 'You already have a non-legacy license activated on this install, which you can deactivate <a href="%s">in the "General" tab</a>.', 'charitable' ), | |
| 38 | + array( | |
| 39 | + 'a' => array( | |
| 40 | + 'href' => array(), | |
| 41 | + 'class' => array(), | |
| 42 | + 'target' => array(), | |
| 43 | + 'rel' => array(), | |
| 44 | + ), | |
| 45 | + 'br' => array(), | |
| 46 | + 'strong' => array(), | |
| 47 | + ) | |
| 48 | + ), | |
| 49 | + esc_url( admin_url( 'admin.php?page=charitable-settings&tab=general' ) ) | |
| 50 | + ) . | |
| 51 | + '</p>'; | |
| 52 | + | |
| 53 | + ?> | |
| 54 | + | |
| 55 | +<div class="charitable-settings-notice license-notice" style="margin-bottom: 20px;"> | |
| 56 | +<p><?php esc_html_e( 'This area is reserved for older (legacy) license keys.', 'charitable' ); ?></p> | |
| 57 | +<p><?php echo $charitable_new_tab_notification; // phpcs:ignore ?></p> | |
| 23 | 58 | </div> |
| 24 | -<?php | |
| 25 | -foreach ( $products as $key => $product ) : | |
| 26 | 59 | |
| 27 | - $license = $helper->get_license_details( $key ); | |
| 60 | + <?php | |
| 28 | 61 | |
| 29 | - if ( is_array( $license ) ) { | |
| 30 | - $is_active = $license['valid']; | |
| 31 | - $license_key = $license['license']; | |
| 32 | - } else { | |
| 33 | - $is_active = false; | |
| 34 | - $license_key = $license; | |
| 35 | - } | |
| 62 | +} else { | |
| 36 | 63 | |
| 64 | + $charitable_new_tab_notification = | |
| 65 | + '<p>' . | |
| 66 | + sprintf( | |
| 67 | + wp_kses( | |
| 68 | + /* translators: %s - charitable.com upgrade URL. */ | |
| 69 | + __( 'If you have purchased your license key for <strong>Basic</strong>, <strong>Plus</strong>, <strong>Pro</strong>, or <strong>Agency / Elite</strong> recently, please enter your charitable license key <a href="%s">in the "General" tab</a>.', 'charitable' ), | |
| 70 | + array( | |
| 71 | + 'a' => array( | |
| 72 | + 'href' => array(), | |
| 73 | + 'class' => array(), | |
| 74 | + 'target' => array(), | |
| 75 | + 'rel' => array(), | |
| 76 | + ), | |
| 77 | + 'br' => array(), | |
| 78 | + 'strong' => array(), | |
| 79 | + ) | |
| 80 | + ), | |
| 81 | + esc_url( admin_url( 'admin.php?page=charitable-settings&tab=general' ) ) | |
| 82 | + ) . | |
| 83 | + '</p>'; | |
| 84 | + | |
| 37 | 85 | ?> |
| 38 | - <div class="charitable-settings-object charitable-licensed-product cf"> | |
| 39 | - <h4><?php echo $product['name']; ?></h4> | |
| 40 | - <input type="text" name="charitable_settings[licenses][<?php echo $key; ?>]" id="charitable_settings_licenses_<?php echo $key; ?>" class="charitable-settings-field" placeholder="<?php _e( 'Add your license key', 'charitable' ); ?>" value="<?php echo $license_key; ?>" /> | |
| 41 | - <?php if ( $license ) : ?> | |
| 86 | +<div class="charitable-settings-notice license-notice" style="margin-bottom: 20px;"> | |
| 87 | + <p><?php esc_html_e( 'This area is reserved for older (legacy) license keys.', 'charitable' ); ?></p> | |
| 88 | + <p><?php echo $charitable_new_tab_notification; // phpcs:ignore ?></p> | |
| 89 | + <p><?php esc_html_e( 'By adding your license keys, you agree for your website to send requests to wpcharitable.com to check license details and provide automatic plugin updates. Your license(s) can be disconnected at any time.', 'charitable' ); ?></p> | |
| 90 | +</div> | |
| 91 | + <?php | |
| 92 | + | |
| 93 | + $_charitable_legacy_license_info = get_transient( '_charitable_legacy_license_info' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- $_charitable_legacy_license_info is a transient key used by WordPress transients API. | |
| 94 | + | |
| 95 | + foreach ( $charitable_products as $charitable_key => $charitable_product ) : | |
| 96 | + | |
| 97 | + $charitable_license = $charitable_helper->get_license_details( $charitable_key ); | |
| 98 | + | |
| 99 | + // set a default invalid message. | |
| 100 | + $charitable_invalid_message = __( 'This is an invalid license.', 'charitable' ); | |
| 101 | + | |
| 102 | + if ( is_array( $charitable_license ) ) { | |
| 103 | + if ( isset( $charitable_license['expiration_date'] ) && false !== $charitable_license['expiration_date'] && isset( $charitable_license['valid'] ) && false !== $charitable_license['valid'] ) { | |
| 104 | + $charitable_is_active = $charitable_license['valid']; | |
| 105 | + $charitable_license_key = $charitable_license['license']; | |
| 106 | + } else { | |
| 107 | + $charitable_is_active = false; | |
| 108 | + $charitable_license_key = false; | |
| 109 | + // this is different because we try to avoid just a BAD license vs. an invalid-but-could-be-expired license. | |
| 110 | + $charitable_referer = wp_get_referer(); | |
| 111 | + if ( admin_url( 'admin.php?page=charitable-settings&tab=advanced' ) === $charitable_referer ) { | |
| 112 | + if ( false !== $_charitable_legacy_license_info && is_array( $_charitable_legacy_license_info ) && array_key_exists( $charitable_key, $_charitable_legacy_license_info ) && '' !== trim( $_charitable_legacy_license_info[ $charitable_key ] ) ) { | |
| 113 | + $charitable_invalid_message = __( 'The license was not valid.', 'charitable' ); | |
| 114 | + } else { | |
| 115 | + $charitable_invalid_message = false; | |
| 116 | + } | |
| 117 | + } else { | |
| 118 | + $charitable_invalid_message = false; | |
| 119 | + } | |
| 120 | + } | |
| 121 | + } else { | |
| 122 | + $charitable_is_active = false; | |
| 123 | + $charitable_license_key = $charitable_license; | |
| 124 | + } | |
| 125 | + | |
| 126 | + ?> | |
| 127 | + <div class="charitable-settings-object charitable-licensed-product"> | |
| 128 | + <h4><?php echo esc_html( $charitable_product['name'] ); ?></h4> | |
| 129 | + <input type="text" name="charitable_settings[legacy_licenses][<?php echo esc_attr( $charitable_key ); ?>]" id="charitable_settings_licenses_<?php echo esc_attr( $charitable_key ); ?>" class="charitable-settings-field" placeholder="<?php esc_attr_e( 'Add your license key', 'charitable' ); ?>" value="<?php echo esc_attr( $charitable_license_key ); ?>" /> | |
| 130 | + <?php if ( $charitable_license ) : ?> | |
| 42 | 131 | <div class="license-meta"> |
| 43 | - <?php if ( $is_active ) : ?> | |
| 44 | - <a href="<?php echo $helper->get_license_deactivation_url( $key ); ?>" class="button-secondary license-deactivation"><?php _e( 'Deactivate License', 'charitable' ); ?></a> | |
| 45 | - <?php if ( 'lifetime' == $license['expiration_date'] ) : ?> | |
| 46 | - <span class="license-expiration-date"><?php _e( 'Lifetime license', 'charitable' ); ?></span> | |
| 132 | + <?php if ( $charitable_is_active ) : ?> | |
| 133 | + <a href="<?php echo esc_url( $charitable_helper->get_license_deactivation_url( $charitable_key ) ); ?>" class="button-secondary license-deactivation"><?php esc_html_e( 'Deactivate License', 'charitable' ); ?></a> | |
| 134 | + <?php if ( 'lifetime' === $charitable_license['expiration_date'] ) : ?> | |
| 135 | + <span class="license-expiration-date"><?php esc_html_e( 'Lifetime license', 'charitable' ); ?></span> | |
| 47 | 136 | <?php else : ?> |
| 48 | - <span class="license-expiration-date"><?php printf( '%s %s.', __( 'Expiring in', 'charitable' ), human_time_diff( strtotime( $license['expiration_date'] ), time() ) ); ?></span> | |
| 137 | + <span class="license-expiration-date"><?php printf( '%s %s.', esc_html__( 'Expiring in', 'charitable' ), human_time_diff( strtotime( $charitable_license['expiration_date'] ), time() ) ); // phpcs:ignore ?></span> | |
| 49 | 138 | <?php endif ?> |
| 50 | - <?php elseif ( is_array( $license ) ) : ?> | |
| 51 | - <span class="license-invalid"><?php _e( 'This license is not valid', 'charitable' ); ?></span> | |
| 139 | + <?php elseif ( is_array( $charitable_license ) ) : ?> | |
| 140 | + <span class="license-invalid"><?php echo $charitable_invalid_message; // phpcs:ignore ?></span> | |
| 52 | 141 | <?php else : ?> |
| 53 | - <span class="license-invalid"><?php _e( 'We could not validate this license', 'charitable' ); ?></span> | |
| 142 | + <span class="license-invalid"><?php esc_html_e( 'We could not validate this license.', 'charitable' ); ?></span> | |
| 54 | 143 | <?php endif ?> |
| 55 | 144 | </div> |
| 56 | 145 | <?php endif ?> |
| 57 | 146 | </div> |
| 58 | 147 | |
| 59 | - <?php | |
| 148 | + <?php | |
| 60 | 149 | endforeach; |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + delete_transient( '_charitable_legacy_license_info' ); | |
| 154 | + | |
| 155 | +} | |