|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class GV_License_Handler { |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @var GravityView_Settings |
|
7
|
|
|
*/ |
|
8
|
|
|
private $Addon; |
|
9
|
|
|
|
|
10
|
|
|
const name = 'GravityView'; |
|
11
|
|
|
|
|
12
|
|
|
const author = 'Katz Web Services, Inc.'; |
|
13
|
|
|
|
|
14
|
|
|
const url = 'https://gravityview.co'; |
|
15
|
|
|
|
|
16
|
|
|
const version = GravityView_Plugin::version; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Post ID on gravityview.co |
|
20
|
|
|
* @since 1.15 |
|
21
|
|
|
*/ |
|
22
|
|
|
const item_id = 17; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Name of the transient used to store license status for GV |
|
26
|
|
|
* @since 1.17 |
|
27
|
|
|
*/ |
|
28
|
|
|
const status_transient_key = 'gravityview_edd-activate_valid'; |
|
29
|
|
|
|
|
30
|
|
|
private $EDD_SL_Plugin_Updater; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var GV_License_Handler |
|
34
|
|
|
*/ |
|
35
|
|
|
public static $instance; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param GravityView_Settings $GFAddOn |
|
39
|
|
|
* |
|
40
|
|
|
* @return GV_License_Handler |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function get_instance( GravityView_Settings $GFAddOn ) { |
|
43
|
|
|
if( empty( self::$instance ) ) { |
|
44
|
|
|
self::$instance = new self( $GFAddOn ); |
|
45
|
|
|
} |
|
46
|
|
|
return self::$instance; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
private function __construct( GravityView_Settings $GFAddOn ) { |
|
50
|
|
|
|
|
51
|
|
|
$this->Addon = $GFAddOn; |
|
52
|
|
|
|
|
53
|
|
|
$this->setup_edd(); |
|
54
|
|
|
|
|
55
|
|
|
$this->add_hooks(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function add_hooks() { |
|
59
|
|
|
add_action( 'wp_ajax_gravityview_license', array( $this, 'license_call' ) ); |
|
60
|
|
|
add_action( 'admin_init', array( $this, 'refresh_license_status' ) ); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* When the status transient expires (or is deleted on activation), re-check the status |
|
65
|
|
|
* |
|
66
|
|
|
* @since 1.17 |
|
67
|
|
|
* |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
public function refresh_license_status() { |
|
71
|
|
|
|
|
72
|
|
|
// Only perform on GravityView pages |
|
73
|
|
|
if( ! gravityview_is_admin_page() ) { |
|
74
|
|
|
return; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
// The transient is fresh; don't fetch. |
|
78
|
|
|
if( $status = get_transient( self::status_transient_key ) ) { |
|
79
|
|
|
return; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$data = array( |
|
83
|
|
|
'edd_action' => 'check_license', |
|
84
|
|
|
'license' => trim( $this->Addon->get_app_setting( 'license_key' ) ), |
|
85
|
|
|
'update' => true, |
|
86
|
|
|
'format' => 'object', |
|
87
|
|
|
'field_id' => 'refresh_license_status', // Required to set the `status_transient_key` transient |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
$license_call = GravityView_Settings::get_instance()->get_license_handler()->license_call( $data ); |
|
91
|
|
|
|
|
92
|
|
|
do_action( 'gravityview_log_debug', __METHOD__ . ': Refreshed the license.', $license_call ); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
function settings_edd_license_activation( $field, $echo ) { |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
$script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
98
|
|
|
|
|
99
|
|
|
wp_enqueue_script( 'gv-admin-edd-license', GRAVITYVIEW_URL . 'assets/js/admin-edd-license' . $script_debug . '.js', array( 'jquery' ) ); |
|
100
|
|
|
|
|
101
|
|
|
$status = trim( $this->Addon->get_app_setting( 'license_key_status' ) ); |
|
102
|
|
|
$key = trim( $this->Addon->get_app_setting( 'license_key' ) ); |
|
103
|
|
|
|
|
104
|
|
|
if( !empty( $key ) ) { |
|
|
|
|
|
|
105
|
|
|
$response = $this->Addon->get_app_setting( 'license_key_response' ); |
|
106
|
|
|
$response = is_array( $response ) ? (object) $response : json_decode( $response ); |
|
107
|
|
|
} else { |
|
108
|
|
|
$response = array(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
wp_localize_script( 'gv-admin-edd-license', 'GVGlobals', array( |
|
112
|
|
|
'license_box' => $this->get_license_message( $response ) |
|
113
|
|
|
)); |
|
114
|
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
$fields = array( |
|
117
|
|
|
array( |
|
118
|
|
|
'name' => 'edd-activate', |
|
119
|
|
|
'value' => __('Activate License', 'gravityview'), |
|
|
|
|
|
|
120
|
|
|
'data-pending_text' => __('Verifying license…', 'gravityview'), |
|
|
|
|
|
|
121
|
|
|
'data-edd_action' => 'activate_license', |
|
122
|
|
|
'class' => 'button-primary', |
|
123
|
|
|
), |
|
124
|
|
|
array( |
|
125
|
|
|
'name' => 'edd-deactivate', |
|
126
|
|
|
'value' => __('Deactivate License', 'gravityview'), |
|
|
|
|
|
|
127
|
|
|
'data-pending_text' => __('Deactivating license…', 'gravityview'), |
|
|
|
|
|
|
128
|
|
|
'data-edd_action' => 'deactivate_license', |
|
129
|
|
|
'class' => ( empty( $status ) ? 'button-primary hide' : 'button-primary' ), |
|
130
|
|
|
), |
|
131
|
|
|
array( |
|
132
|
|
|
'name' => 'edd-check', |
|
133
|
|
|
'value' => __('Check License', 'gravityview'), |
|
|
|
|
|
|
134
|
|
|
'data-pending_text' => __('Verifying license…', 'gravityview'), |
|
|
|
|
|
|
135
|
|
|
'title' => 'Check the license before saving it', |
|
136
|
|
|
'data-edd_action' => 'check_license', |
|
137
|
|
|
'class' => 'button-secondary', |
|
138
|
|
|
), |
|
139
|
|
|
); |
|
140
|
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
$class = 'button gv-edd-action'; |
|
143
|
|
|
|
|
144
|
|
|
$class .= ( !empty( $key ) && $status !== 'valid' ) ? '' : ' hide'; |
|
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
$disabled_attribute = GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled'; |
|
147
|
|
|
|
|
148
|
|
|
$submit = '<div class="gv-edd-button-wrapper">'; |
|
149
|
|
|
foreach ( $fields as $field ) { |
|
150
|
|
|
$field['type'] = 'button'; |
|
151
|
|
|
$field['class'] = isset( $field['class'] ) ? $field['class'] . ' '. $class : $class; |
|
152
|
|
|
$field['style'] = 'margin-left: 10px;'; |
|
153
|
|
|
if( $disabled_attribute ) { |
|
154
|
|
|
$field['disabled'] = $disabled_attribute; |
|
155
|
|
|
} |
|
156
|
|
|
$submit .= $this->Addon->settings_submit( $field, $echo ); |
|
157
|
|
|
} |
|
158
|
|
|
$submit .= '</div>'; |
|
159
|
|
|
|
|
160
|
|
|
return $submit; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Include the EDD plugin updater class, if not exists |
|
165
|
|
|
* @since 1.7.4 |
|
166
|
|
|
* @return void |
|
167
|
|
|
*/ |
|
168
|
|
|
private function setup_edd() { |
|
169
|
|
|
|
|
170
|
|
|
if( !class_exists('EDD_SL_Plugin_Updater') ) { |
|
|
|
|
|
|
171
|
|
|
require_once( GRAVITYVIEW_DIR . 'includes/lib/EDD_SL_Plugin_Updater.php'); |
|
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
// setup the updater |
|
175
|
|
|
$this->EDD_SL_Plugin_Updater = new EDD_SL_Plugin_Updater( |
|
176
|
|
|
self::url, |
|
177
|
|
|
GRAVITYVIEW_FILE, |
|
178
|
|
|
$this->_get_edd_settings() |
|
179
|
|
|
); |
|
180
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Generate the array of settings passed to the EDD license call |
|
185
|
|
|
* |
|
186
|
|
|
* @since 1.7.4 |
|
187
|
|
|
* |
|
188
|
|
|
* @param string $action The action to send to edd, such as `check_license` |
|
189
|
|
|
* @param string $license The license key to have passed to EDD |
|
190
|
|
|
* |
|
191
|
|
|
* @return array |
|
192
|
|
|
*/ |
|
193
|
|
|
function _get_edd_settings( $action = '', $license = '' ) { |
|
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
// retrieve our license key from the DB |
|
196
|
|
|
$license_key = empty( $license ) ? trim( $this->Addon->get_app_setting( 'license_key' ) ) : $license; |
|
197
|
|
|
|
|
198
|
|
|
$settings = array( |
|
199
|
|
|
'version' => self::version, |
|
200
|
|
|
'license' => $license_key, |
|
201
|
|
|
'item_name' => self::name, |
|
202
|
|
|
'item_id' => self::item_id, |
|
203
|
|
|
'author' => self::author, |
|
204
|
|
|
'language' => get_locale(), |
|
205
|
|
|
'url' => home_url(), |
|
206
|
|
|
); |
|
207
|
|
|
|
|
208
|
|
|
if( !empty( $action ) ) { |
|
|
|
|
|
|
209
|
|
|
$settings['edd_action'] = esc_attr( $action ); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
$settings = array_map( 'urlencode', $settings ); |
|
213
|
|
|
|
|
214
|
|
|
return $settings; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* Perform the call |
|
219
|
|
|
* @return array|WP_Error |
|
220
|
|
|
*/ |
|
221
|
|
|
private function _license_get_remote_response( $data, $license = '' ) { |
|
222
|
|
|
|
|
223
|
|
|
$api_params = $this->_get_edd_settings( $data['edd_action'], $license ); |
|
224
|
|
|
|
|
225
|
|
|
$url = add_query_arg( $api_params, self::url ); |
|
226
|
|
|
|
|
227
|
|
|
$response = wp_remote_get( $url, array( |
|
|
|
|
|
|
228
|
|
|
'timeout' => 15, |
|
229
|
|
|
'sslverify' => false, |
|
230
|
|
|
)); |
|
231
|
|
|
|
|
232
|
|
|
if ( is_wp_error( $response ) ) { |
|
233
|
|
|
return array(); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
$license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
|
237
|
|
|
|
|
238
|
|
|
// Not JSON |
|
239
|
|
|
if ( empty( $license_data ) ) { |
|
240
|
|
|
|
|
241
|
|
|
delete_transient( self::status_transient_key ); |
|
242
|
|
|
|
|
243
|
|
|
// Change status |
|
244
|
|
|
return array(); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
// Store the license key inside the data array |
|
248
|
|
|
$license_data->license_key = $license; |
|
249
|
|
|
|
|
250
|
|
|
return $license_data; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Generate the status message displayed in the license field |
|
255
|
|
|
* |
|
256
|
|
|
* @since 1.7.4 |
|
257
|
|
|
* @param $license_data |
|
258
|
|
|
* |
|
259
|
|
|
* @return string |
|
260
|
|
|
*/ |
|
261
|
|
|
function get_license_message( $license_data ) { |
|
|
|
|
|
|
262
|
|
|
|
|
263
|
|
|
if( empty( $license_data ) ) { |
|
264
|
|
|
$message = ''; |
|
265
|
|
|
} else { |
|
266
|
|
|
|
|
267
|
|
|
if( ! empty( $license_data->error ) ) { |
|
268
|
|
|
$class = 'error'; |
|
269
|
|
|
$string_key = $license_data->error; |
|
270
|
|
|
} else { |
|
271
|
|
|
$class = $license_data->license; |
|
272
|
|
|
$string_key = $license_data->license; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
$message = sprintf( '<p><strong>%s: %s</strong></p>', $this->strings('status'), $this->strings( $string_key, $license_data ) ); |
|
|
|
|
|
|
276
|
|
|
|
|
277
|
|
|
$message = $this->generate_license_box( $message, $class ); |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
return $message; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* Generate the status message box HTML based on the current status |
|
285
|
|
|
* |
|
286
|
|
|
* @since 1.7.4 |
|
287
|
|
|
* @param $message |
|
288
|
|
|
* @param string $class |
|
289
|
|
|
* |
|
290
|
|
|
* @return string |
|
291
|
|
|
*/ |
|
292
|
|
|
private function generate_license_box( $message, $class = '' ) { |
|
293
|
|
|
|
|
294
|
|
|
$template = '<div id="gv-edd-status" aria-live="polite" aria-busy="false" class="gv-edd-message inline %s">%s</div>'; |
|
295
|
|
|
|
|
296
|
|
|
$output = sprintf( $template, esc_attr( $class ), $message ); |
|
297
|
|
|
|
|
298
|
|
|
return $output; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* Allow pure HTML in settings fields |
|
303
|
|
|
* |
|
304
|
|
|
* @since 1.17 |
|
305
|
|
|
* |
|
306
|
|
|
* @param array $response License response |
|
307
|
|
|
* |
|
308
|
|
|
* @return string `html` key of the $field |
|
309
|
|
|
*/ |
|
310
|
|
|
public function license_details( $response = array() ) { |
|
311
|
|
|
|
|
312
|
|
|
$response = (array) $response; |
|
313
|
|
|
|
|
314
|
|
|
$return = ''; |
|
315
|
|
|
$return .= '<span class="gv-license-details" aria-live="polite" aria-busy="false">'; |
|
316
|
|
|
$return .= '<h3>' . esc_html__( 'License Details:', 'gravityview' ) . '</h3>'; |
|
317
|
|
|
|
|
318
|
|
|
if( in_array( rgar( $response, 'license' ), array( 'invalid', 'deactivated' ) ) ) { |
|
319
|
|
|
$return .= $this->strings( $response['license'], $response ); |
|
320
|
|
|
} elseif( ! empty( $response['license_name'] ) ) { |
|
321
|
|
|
|
|
322
|
|
|
$response_keys = array( |
|
323
|
|
|
'license_name' => '', |
|
324
|
|
|
'license_limit' => '', |
|
325
|
|
|
'customer_name' => '', |
|
326
|
|
|
'customer_email' => '', |
|
327
|
|
|
'site_count' => '', |
|
328
|
|
|
'expires' => '', |
|
329
|
|
|
'upgrades' => '' |
|
|
|
|
|
|
330
|
|
|
); |
|
331
|
|
|
|
|
332
|
|
|
// Make sure all the keys are set |
|
333
|
|
|
$response = wp_parse_args( $response, $response_keys ); |
|
334
|
|
|
|
|
335
|
|
|
$login_link = sprintf( '<a href="%s" class="howto" rel="external">%s</a>', esc_url( sprintf( 'https://gravityview.co/wp-login.php?username=%s', $response['customer_email'] ) ), esc_html__( 'Access your GravityView account', 'gravityview' ) ); |
|
336
|
|
|
$local_text = ( ! empty( $response['is_local'] ) ? '<span class="howto">' . __( 'This development site does not count toward license activation limits', 'gravityview' ) . '</span>' : '' ); |
|
337
|
|
|
$details = array( |
|
338
|
|
|
'license' => sprintf( esc_html__( 'License level: %s', 'gravityview' ), esc_html( $response['license_name'] ), esc_html( $response['license_limit'] ) ), |
|
339
|
|
|
'licensed_to' => sprintf( esc_html_x( 'Licensed to: %1$s (%2$s)', '1: Customer name; 2: Customer email', 'gravityview' ), esc_html__( $response['customer_name'], 'gravityview' ), esc_html__( $response['customer_email'], 'gravityview' ) ) . $login_link, |
|
340
|
|
|
'activations' => sprintf( esc_html__( 'Activations: %d of %s sites', 'gravityview' ), intval( $response['site_count'] ), esc_html( $response['license_limit'] ) ) . $local_text, |
|
341
|
|
|
'expires' => sprintf( esc_html__( 'Renew on: %s', 'gravityview' ), date_i18n( get_option( 'date_format' ), strtotime( $response['expires'] ) - DAY_IN_SECONDS ) ), |
|
342
|
|
|
'upgrade' => $this->get_upgrade_html( $response['upgrades'] ), |
|
343
|
|
|
); |
|
344
|
|
|
|
|
345
|
|
|
if ( ! empty( $response['error'] ) && 'expired' === $response['error'] ) { |
|
346
|
|
|
unset( $details['upgrade'] ); |
|
347
|
|
|
$details['expires'] = '<div class="error inline"><p>' . $this->strings( 'expired', $response ) . '</p></div>'; |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
$return .= '<ul><li>' . implode( '</li><li>', array_filter( $details ) ) . '</li></ul>'; |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
$return .= '</span>'; |
|
354
|
|
|
|
|
355
|
|
|
return $return; |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
/** |
|
359
|
|
|
* Display possible upgrades for a license |
|
360
|
|
|
* |
|
361
|
|
|
* @since 1.17 |
|
362
|
|
|
* |
|
363
|
|
|
* @param array $upgrades Array of upgrade paths, returned from the GV website |
|
364
|
|
|
* |
|
365
|
|
|
* @return string HTML list of upgrades available for the current license |
|
366
|
|
|
*/ |
|
367
|
|
|
function get_upgrade_html( $upgrades ) { |
|
|
|
|
|
|
368
|
|
|
|
|
369
|
|
|
$output = ''; |
|
370
|
|
|
|
|
371
|
|
|
if( ! empty( $upgrades ) ) { |
|
372
|
|
|
|
|
373
|
|
|
$locale_parts = explode( '_', get_locale() ); |
|
374
|
|
|
|
|
375
|
|
|
$is_english = ( 'en' === $locale_parts[0] ); |
|
376
|
|
|
|
|
377
|
|
|
$output .= '<h4>' . esc_html__( 'Upgrades available:', 'gravityview' ) . '</h4>'; |
|
378
|
|
|
|
|
379
|
|
|
$output .= '<ul class="ul-disc">'; |
|
380
|
|
|
|
|
381
|
|
|
foreach ( $upgrades as $upgrade_id => $upgrade ) { |
|
382
|
|
|
|
|
383
|
|
|
$upgrade = (object) $upgrade; |
|
384
|
|
|
|
|
385
|
|
|
$anchor_text = sprintf( esc_html_x( 'Upgrade to %1$s for %2$s', '1: GravityView upgrade name, 2: Cost of upgrade', 'gravityview' ), esc_attr( $upgrade->name ), esc_attr( $upgrade->price ) ); |
|
386
|
|
|
|
|
387
|
|
|
if( $is_english && isset( $upgrade->description ) ) { |
|
388
|
|
|
$message = esc_html( $upgrade->description ); |
|
389
|
|
|
} else { |
|
390
|
|
|
switch( $upgrade->price_id ) { |
|
391
|
|
|
// Interstellar |
|
392
|
|
|
case 1: |
|
393
|
|
|
default: |
|
394
|
|
|
$message = esc_html__( 'Get access to Extensions', 'gravityview' ); |
|
395
|
|
|
break; |
|
396
|
|
|
// Galactic |
|
397
|
|
|
case 2: |
|
|
|
|
|
|
398
|
|
|
$message = esc_html__( 'Get access to Entry Importer and other Premium plugins', 'gravityview' ); |
|
399
|
|
|
break; |
|
400
|
|
|
} |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
$output .= sprintf( '<li><a href="%s">%s</a><span class="howto">%s</span></li>', esc_url( add_query_arg( array( 'utm_source' => 'settings', 'utm_medium' => 'admin', 'utm_content' => 'license-details', 'utm_campaign' => 'Upgrades' ), $upgrade->url ) ), $anchor_text, $message ); |
|
404
|
|
|
} |
|
405
|
|
|
$output .= '</ul>'; |
|
406
|
|
|
} |
|
407
|
|
|
|
|
408
|
|
|
return $output; |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
/** |
|
412
|
|
|
* Perform the call to EDD based on the AJAX call or passed data |
|
413
|
|
|
* |
|
414
|
|
|
* @since 1.7.4 |
|
415
|
|
|
* |
|
416
|
|
|
* @param array $array { |
|
417
|
|
|
* @type string $license The license key |
|
418
|
|
|
* @type string $edd_action The EDD action to perform, like `check_license` |
|
419
|
|
|
* @type string $field_id The ID of the field to check |
|
420
|
|
|
* @type boolean $update Whether to update plugin settings. Prevent updating the data by setting an `update` key to false |
|
421
|
|
|
* @type string $format If `object`, return the object of the license data. Else, return the JSON-encoded object |
|
422
|
|
|
* } |
|
423
|
|
|
* |
|
424
|
|
|
* @return mixed|string|void |
|
425
|
|
|
*/ |
|
426
|
|
|
public function license_call( $array = array() ) { |
|
427
|
|
|
|
|
428
|
|
|
$is_ajax = ( defined('DOING_AJAX') && DOING_AJAX ); |
|
|
|
|
|
|
429
|
|
|
$data = empty( $array ) ? $_POST['data'] : $array; |
|
|
|
|
|
|
430
|
|
|
$has_cap = GVCommon::has_cap( 'gravityview_edit_settings' ); |
|
431
|
|
|
|
|
432
|
|
|
if ( $is_ajax && empty( $data['license'] ) ) { |
|
433
|
|
|
die( - 1 ); |
|
|
|
|
|
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
|
|
// If the user isn't allowed to edit settings, show an error message |
|
437
|
|
|
if( ! $has_cap ) { |
|
438
|
|
|
$license_data = new stdClass(); |
|
439
|
|
|
$license_data->error = 'capability'; |
|
440
|
|
|
$license_data->message = $this->get_license_message( $license_data ); |
|
441
|
|
|
$json = json_encode( $license_data ); |
|
442
|
|
|
} else { |
|
443
|
|
|
|
|
444
|
|
|
$license = esc_attr( rgget( 'license', $data ) ); |
|
445
|
|
|
$license_data = $this->_license_get_remote_response( $data, $license ); |
|
446
|
|
|
|
|
447
|
|
|
// Empty is returned when there's an error. |
|
448
|
|
|
if ( empty( $license_data ) ) { |
|
449
|
|
|
if ( $is_ajax ) { |
|
450
|
|
|
exit( json_encode( array() ) ); |
|
|
|
|
|
|
451
|
|
|
} else { // Non-ajax call |
|
452
|
|
|
return json_encode( array() ); |
|
453
|
|
|
} |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
$license_data->details = $this->license_details( $license_data ); |
|
457
|
|
|
$license_data->message = $this->get_license_message( $license_data ); |
|
458
|
|
|
|
|
459
|
|
|
$json = json_encode( $license_data ); |
|
460
|
|
|
|
|
461
|
|
|
$update_license = ( ! isset( $data['update'] ) || ! empty( $data['update'] ) ); |
|
462
|
|
|
|
|
463
|
|
|
$is_check_action_button = ( 'check_license' === $data['edd_action'] && defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
464
|
|
|
|
|
465
|
|
|
// Failed is the response from trying to de-activate a license and it didn't work. |
|
466
|
|
|
// This likely happened because people entered in a different key and clicked "Deactivate", |
|
467
|
|
|
// meaning to deactivate the original key. We don't want to save this response, since it is |
|
468
|
|
|
// most likely a mistake. |
|
469
|
|
|
if ( $license_data->license !== 'failed' && ! $is_check_action_button && $update_license ) { |
|
|
|
|
|
|
470
|
|
|
|
|
471
|
|
|
if ( ! empty( $data['field_id'] ) ) { |
|
472
|
|
|
set_transient( self::status_transient_key, $license_data, DAY_IN_SECONDS ); |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
$this->license_call_update_settings( $license_data, $data ); |
|
476
|
|
|
} |
|
477
|
|
|
} // End $has_cap |
|
478
|
|
|
|
|
479
|
|
|
if ( $is_ajax ) { |
|
480
|
|
|
exit( $json ); |
|
|
|
|
|
|
481
|
|
|
} else { // Non-ajax call |
|
482
|
|
|
return ( rgget('format', $data ) === 'object' ) ? $license_data : $json; |
|
|
|
|
|
|
483
|
|
|
} |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
|
|
/** |
|
487
|
|
|
* Update the license after fetching it |
|
488
|
|
|
* @param object $license_data |
|
489
|
|
|
* @return void |
|
490
|
|
|
*/ |
|
491
|
|
|
private function license_call_update_settings( $license_data, $data ) { |
|
492
|
|
|
|
|
493
|
|
|
// Update option with passed data license |
|
494
|
|
|
$settings = $this->Addon->get_app_settings(); |
|
495
|
|
|
|
|
496
|
|
|
$settings['license_key'] = $license_data->license_key = trim( $data['license'] ); |
|
497
|
|
|
$settings['license_key_status'] = $license_data->license; |
|
498
|
|
|
$settings['license_key_response'] = (array)$license_data; |
|
|
|
|
|
|
499
|
|
|
|
|
500
|
|
|
$this->Addon->update_app_settings( $settings ); |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
/** |
|
504
|
|
|
* URL to direct license renewal, or if license key is not set, then just the account page |
|
505
|
|
|
* @since 1.13.1 |
|
506
|
|
|
* @param object|null $license_data Object with license data |
|
507
|
|
|
* @return string Renewal or account URL |
|
508
|
|
|
*/ |
|
509
|
|
|
private function get_license_renewal_url( $license_data ) { |
|
510
|
|
|
$license_data = is_array( $license_data ) ? (object)$license_data : $license_data; |
|
|
|
|
|
|
511
|
|
|
$renew_license_url = ( ! empty( $license_data ) && !empty( $license_data->license_key ) ) ? sprintf( 'https://gravityview.co/checkout/?download_id=17&edd_license_key=%s&utm_source=admin_notice&utm_medium=admin&utm_content=expired&utm_campaign=Activation&force_login=1', $license_data->license_key ) : 'https://gravityview.co/account/'; |
|
|
|
|
|
|
512
|
|
|
return $renew_license_url; |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
/** |
|
516
|
|
|
* Override the text used in the GravityView EDD license Javascript |
|
517
|
|
|
* |
|
518
|
|
|
* @param array|null $status Status to get. If empty, get all strings. |
|
519
|
|
|
* @param object|null $license_data Object with license data |
|
520
|
|
|
* @return array Modified array of content |
|
521
|
|
|
*/ |
|
522
|
|
|
public function strings( $status = NULL, $license_data = null ) { |
|
|
|
|
|
|
523
|
|
|
|
|
|
|
|
|
|
524
|
|
|
|
|
525
|
|
|
$strings = array( |
|
526
|
|
|
'status' => esc_html__('Status', 'gravityview'), |
|
|
|
|
|
|
527
|
|
|
'error' => esc_html__('There was an error processing the request.', 'gravityview'), |
|
|
|
|
|
|
528
|
|
|
'failed' => esc_html__('Could not deactivate the license. The license key you attempted to deactivate may not be active or valid.', 'gravityview'), |
|
|
|
|
|
|
529
|
|
|
'site_inactive' => esc_html__('The license key is valid, but it has not been activated for this site.', 'gravityview'), |
|
|
|
|
|
|
530
|
|
|
'inactive' => esc_html__('The license key is valid, but it has not been activated for this site.', 'gravityview'), |
|
|
|
|
|
|
531
|
|
|
'no_activations_left' => esc_html__('Invalid: this license has reached its activation limit.', 'gravityview') . ' ' . sprintf( esc_html__('You can manage license activations %son your GravityView account page%s.', 'gravityview'), '<a href="https://gravityview.co/account/#licenses">', '</a>' ), |
|
|
|
|
|
|
532
|
|
|
'deactivated' => esc_html__('The license has been deactivated.', 'gravityview'), |
|
|
|
|
|
|
533
|
|
|
'valid' => esc_html__('The license key is valid and active.', 'gravityview'), |
|
|
|
|
|
|
534
|
|
|
'invalid' => esc_html__('The license key entered is invalid.', 'gravityview'), |
|
|
|
|
|
|
535
|
|
|
'missing' => esc_html__('Invalid license key.', 'gravityview'), |
|
|
|
|
|
|
536
|
|
|
'revoked' => esc_html__('This license key has been revoked.', 'gravityview'), |
|
|
|
|
|
|
537
|
|
|
'expired' => sprintf( esc_html__('This license key has expired. %sRenew your license on the GravityView website%s to receive updates and support.', 'gravityview'), '<a href="'. esc_url( $this->get_license_renewal_url( $license_data ) ) .'">', '</a>' ), |
|
|
|
|
|
|
538
|
|
|
'capability' => esc_html__( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ), |
|
539
|
|
|
|
|
540
|
|
|
'verifying_license' => esc_html__('Verifying license…', 'gravityview'), |
|
|
|
|
|
|
541
|
|
|
'activate_license' => esc_html__('Activate License', 'gravityview'), |
|
|
|
|
|
|
542
|
|
|
'deactivate_license' => esc_html__('Deactivate License', 'gravityview'), |
|
|
|
|
|
|
543
|
|
|
'check_license' => esc_html__('Verify License', 'gravityview'), |
|
|
|
|
|
|
544
|
|
|
); |
|
545
|
|
|
|
|
546
|
|
|
if( empty( $status ) ) { |
|
547
|
|
|
return $strings; |
|
548
|
|
|
} |
|
549
|
|
|
|
|
550
|
|
|
if( isset( $strings[ $status ] ) ) { |
|
551
|
|
|
return $strings[ $status ]; |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
return NULL; |
|
|
|
|
|
|
555
|
|
|
} |
|
556
|
|
|
|
|
557
|
|
|
} |