| 1 |
<?php |
| 2 |
/** |
| 3 |
* Give Settings Page/Tab |
| 4 |
* |
| 5 |
* @package Give |
| 6 |
* @subpackage Classes/Give_Settings_License |
| 7 |
* @copyright Copyright (c) 2016, GiveWP |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.8 |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
if ( ! class_exists( 'Give_Settings_License' ) ) : |
| 17 |
|
| 18 |
/** |
| 19 |
* Give_Settings_License. |
| 20 |
* |
| 21 |
* @since 4.15.0 added legacy license page notice |
| 22 |
* @since 1.8 |
| 23 |
*/ |
| 24 |
class Give_Settings_License extends Give_Settings_Page { |
| 25 |
protected $enable_save = false; |
| 26 |
|
| 27 |
/** |
| 28 |
* Constructor. |
| 29 |
*/ |
| 30 |
public function __construct() { |
| 31 |
$this->id = 'licenses'; |
| 32 |
$this->label = esc_html__( 'Licenses', 'give' ); |
| 33 |
|
| 34 |
parent::__construct(); |
| 35 |
|
| 36 |
// Do not use main form for this tab. |
| 37 |
if ( give_get_current_setting_tab() === $this->id ) { |
| 38 |
|
| 39 |
// Remove default parent form. |
| 40 |
add_action( 'give-settings_open_form', '__return_empty_string' ); |
| 41 |
add_action( 'give-settings_close_form', '__return_empty_string' ); |
| 42 |
|
| 43 |
lw_harbor_display_legacy_license_page_notice('GiveWP'); |
| 44 |
|
| 45 |
// Refresh licenses when visit license setting page. |
| 46 |
give_refresh_licenses(); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Get settings array. |
| 52 |
* |
| 53 |
* @return array |
| 54 |
* @since 1.8 |
| 55 |
*/ |
| 56 |
public function get_settings() { |
| 57 |
$settings = array(); |
| 58 |
|
| 59 |
/** |
| 60 |
* Filter the licenses settings. |
| 61 |
* Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8 |
| 62 |
*/ |
| 63 |
$settings = apply_filters( 'give_settings_licenses', $settings ); |
| 64 |
|
| 65 |
/** |
| 66 |
* Filter the settings. |
| 67 |
* |
| 68 |
* @param array $settings |
| 69 |
* |
| 70 |
* @since 1.8 |
| 71 |
*/ |
| 72 |
$settings = apply_filters( 'give_get_settings_' . $this->id, $settings ); |
| 73 |
|
| 74 |
// Output. |
| 75 |
return $settings; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Render license key field |
| 80 |
* |
| 81 |
* @since 2.5.0 |
| 82 |
*/ |
| 83 |
public function output() { |
| 84 |
ob_start(); |
| 85 |
?> |
| 86 |
<div class="give-license-settings-wrap"> |
| 87 |
|
| 88 |
<div class="give-grid-row"> |
| 89 |
|
| 90 |
<div class="give-grid-col-6"> |
| 91 |
<div id="give-license-activator-wrap" class="give-license-top-widget"> |
| 92 |
<div id="give-license-activator-inner"> |
| 93 |
|
| 94 |
<h2 class="give-license-widget-heading"> |
| 95 |
<span class="dashicons dashicons-plugins-checked"></span> |
| 96 |
<?php _e( 'Activate an Add-on License', 'give' ); ?> |
| 97 |
</h2> |
| 98 |
|
| 99 |
<p class="give-field-description"> |
| 100 |
<?php |
| 101 |
printf( |
| 102 |
__( 'Enter your license key below to unlock your GiveWP add-ons. You can access your licenses anytime from the <a href="%1$s" target="_blank">My Account</a> section on the GiveWP website. ', 'give' ), |
| 103 |
Give_License::get_account_url() |
| 104 |
); |
| 105 |
?> |
| 106 |
</p> |
| 107 |
|
| 108 |
<form method="post" action="" class="give-license-activation-form"> |
| 109 |
|
| 110 |
<div class="give-license-notices"></div> |
| 111 |
|
| 112 |
<?php wp_nonce_field( 'give-license-activator-nonce', 'give_license_activator_nonce' ); ?> |
| 113 |
|
| 114 |
<label |
| 115 |
for="give-license-activator" |
| 116 |
class="screen-reader-text"> |
| 117 |
<?php _e( 'Activate License', 'give' ); ?> |
| 118 |
</label> |
| 119 |
|
| 120 |
<input |
| 121 |
id="give-license-activator" |
| 122 |
type="text" |
| 123 |
name="give_license_key" |
| 124 |
placeholder="<?php _e( 'Enter your license key', 'give' ); ?>" |
| 125 |
/> |
| 126 |
|
| 127 |
<input |
| 128 |
data-activate="<?php _e( 'Activate License', 'give' ); ?>" |
| 129 |
data-activating="<?php _e( 'Verifying License...', 'give' ); ?>" |
| 130 |
value="<?php _e( 'Activate License', 'give' ); ?>" |
| 131 |
type="submit" |
| 132 |
class="button button-primary" |
| 133 |
/> |
| 134 |
|
| 135 |
</form> |
| 136 |
|
| 137 |
</div> |
| 138 |
</div> |
| 139 |
</div><!-- /.give-grid-col-6 --> |
| 140 |
|
| 141 |
<div class="give-grid-col-6"> |
| 142 |
<div id="give-addon-uploader-wrap" class="give-license-top-widget" |
| 143 |
ondragover="event.preventDefault()"> |
| 144 |
<div id="give-addon-uploader-inner"> |
| 145 |
<h2 class="give-license-widget-heading"> |
| 146 |
<span class="dashicons dashicons-upload"></span> |
| 147 |
<?php _e( 'Upload and Activate an Add-on', 'give' ); ?> |
| 148 |
</h2> |
| 149 |
|
| 150 |
<?php if ( ! is_multisite() ) : ?> |
| 151 |
|
| 152 |
<p class="give-field-description"> |
| 153 |
<?php |
| 154 |
printf( |
| 155 |
__( 'Drag an add-on zip file below to upload and activate it. Access your downloads by activating a license or via the <a href="%1$s" target="_blank">My Downloads</a> section on the GiveWP website. ', 'give' ), |
| 156 |
Give_License::get_downloads_url() |
| 157 |
); |
| 158 |
?> |
| 159 |
</p> |
| 160 |
|
| 161 |
<?php if ( 'direct' !== get_filesystem_method() ) : ?> |
| 162 |
<div class="give-notice notice notice-error inline"> |
| 163 |
<p> |
| 164 |
<?php |
| 165 |
echo sprintf( |
| 166 |
__( 'Sorry, you can not upload plugin from here because we do not have direct access to file system. Please <a href="%1$s" target="_blank">click here</a> to upload GiveWP Add-on.', 'give' ), |
| 167 |
admin_url( 'plugin-install.php?tab=upload' ) |
| 168 |
); |
| 169 |
?> |
| 170 |
</p> |
| 171 |
</div> |
| 172 |
<?php else : ?> |
| 173 |
<div class="give-upload-addon-form-wrap"> |
| 174 |
<form |
| 175 |
method="post" |
| 176 |
enctype="multipart/form-data" |
| 177 |
class="give-upload-addon-form" |
| 178 |
action="/"> |
| 179 |
|
| 180 |
<div class="give-addon-upload-notices"></div> |
| 181 |
|
| 182 |
<div class="give-activate-addon-wrap"> |
| 183 |
<p><span |
| 184 |
class="dashicons dashicons-yes"></span> <?php _e( 'Add-on succesfully uploaded.', 'give' ); ?> |
| 185 |
</p> |
| 186 |
<button |
| 187 |
class="give-activate-addon-btn button-primary" |
| 188 |
data-activate="<?php _e( 'Activate Add-on', 'give' ); ?>" |
| 189 |
data-activating="<?php _e( 'Activating Add-on...', 'give' ); ?>" |
| 190 |
><?php _e( 'Activate Add-on', 'give' ); ?></button> |
| 191 |
</div> |
| 192 |
|
| 193 |
<?php wp_nonce_field( 'give-upload-addon', '_give_upload_addon' ); ?> |
| 194 |
|
| 195 |
<p class="give-upload-addon-instructions"> |
| 196 |
<?php _e( 'Drag a plugin zip file here to upload', 'give' ); ?><br> |
| 197 |
<span><?php _e( 'or', 'give' ); ?></span> |
| 198 |
</p> |
| 199 |
|
| 200 |
<label for="give-upload-addon-file-select" class="button button-small"> |
| 201 |
<?php _e( 'Select a File', 'give' ); ?> |
| 202 |
</label> |
| 203 |
|
| 204 |
<input |
| 205 |
id="give-upload-addon-file-select" |
| 206 |
type="file" |
| 207 |
name="addon" |
| 208 |
value="<?php _e( 'Select File', 'give' ); ?>" |
| 209 |
/> |
| 210 |
|
| 211 |
</form> |
| 212 |
</div> |
| 213 |
<?php endif; ?> |
| 214 |
<?php |
| 215 |
else : |
| 216 |
printf( |
| 217 |
__( 'Because of security reasons you can not upload add-ons from here. Please <a href="%1$s" target="_blank">visit network plugin install page</a> to install add-ons.', 'give' ), |
| 218 |
network_admin_url( 'plugin-install.php' ) |
| 219 |
); |
| 220 |
?> |
| 221 |
<?php endif; ?> |
| 222 |
</div> |
| 223 |
</div> |
| 224 |
</div> |
| 225 |
</div> |
| 226 |
|
| 227 |
<div class="give-grid-row<?php echo get_option( 'give_licenses', array() ) ? '' : ' give-hidden'; ?>"> |
| 228 |
<div class="give-grid-col-12"> |
| 229 |
|
| 230 |
<div class="give-licenses-list-header give-clearfix"> |
| 231 |
<h2><?php _e( 'Licenses and Add-ons', 'give' ); ?></h2> |
| 232 |
|
| 233 |
<?php |
| 234 |
$refresh_status = Give_License::refresh_license_status(); |
| 235 |
$is_allow_refresh = ( $refresh_status['compare'] === date( 'Ymd' ) && 5 > $refresh_status['count'] ) || ( $refresh_status['compare'] < date( 'Ymd' ) ); |
| 236 |
$button_title = __( 'Refresh limit reached. Licenses can only be refreshed 5 times per day.', 'give' ); |
| 237 |
$local_date = strtotime( get_date_from_gmt( date( 'Y-m-d H:i:s', $refresh_status['time'] ) ) ); |
| 238 |
?> |
| 239 |
|
| 240 |
<div id="give-refresh-button-wrap"> |
| 241 |
<button id="give-button__refresh-licenses" |
| 242 |
class="button-secondary" |
| 243 |
data-activate="<?php _e( 'Refresh All Licenses', 'give' ); ?>" |
| 244 |
data-activating="<?php _e( 'Refreshing All Licenses...', 'give' ); ?>" |
| 245 |
data-nonce="<?php echo wp_create_nonce( 'give-refresh-all-licenses' ); ?>" |
| 246 |
<?php echo $is_allow_refresh ? '' : 'disabled'; ?> |
| 247 |
<?php echo $is_allow_refresh ? '' : sprintf( 'title="%1$s"', $button_title ); ?>> |
| 248 |
<?php _e( 'Refresh All Licenses', 'give' ); ?> |
| 249 |
</button> |
| 250 |
<span id="give-last-refresh-notice"> |
| 251 |
<?php |
| 252 |
echo sprintf( |
| 253 |
__( 'Last refreshed on %1$s at %2$s', 'give' ), |
| 254 |
date( give_date_format(), $local_date ), |
| 255 |
date( 'g:i a', $local_date ) |
| 256 |
); |
| 257 |
?> |
| 258 |
</span> |
| 259 |
</div> |
| 260 |
|
| 261 |
<hr> |
| 262 |
<p class="give-field-description"><?php _e( 'The following list displays your add-ons and their corresponding activation and license statuses.', 'give' ); ?></p> |
| 263 |
|
| 264 |
</div> |
| 265 |
|
| 266 |
<section id="give-licenses-container"> |
| 267 |
<?php echo Give_License::render_licenses_list(); ?> |
| 268 |
</section> |
| 269 |
|
| 270 |
</div> |
| 271 |
</div> |
| 272 |
</div> |
| 273 |
|
| 274 |
<?php |
| 275 |
echo ob_get_clean(); |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
endif; |
| 280 |
|
| 281 |
return new Give_Settings_License(); |
| 282 |
|