Completed
Push — master ( 5d7bd1...022e44 )
by Zack
04:13
created

GV_License_Handler::get_instance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class GV_License_Handler {
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
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
		);
88
89
		$license_call = GravityView_Settings::get_instance()->get_license_handler()->license_call( $data );
90
91
		do_action( 'gravityview_log_debug', __METHOD__ . ': Refreshed the license.', $license_call );
92
	}
93
94
	function settings_edd_license_activation( $field, $echo ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
95
96
		$script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
97
98
		wp_enqueue_script( 'gv-admin-edd-license', GRAVITYVIEW_URL . 'assets/js/admin-edd-license' . $script_debug . '.js', array( 'jquery' ) );
99
100
		$status = trim( $this->Addon->get_app_setting( 'license_key_status' ) );
101
		$key = trim( $this->Addon->get_app_setting( 'license_key' ) );
102
103
		if( !empty( $key ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
104
			$response = $this->Addon->get_app_setting( 'license_key_response' );
105
			$response = is_array( $response ) ? (object) $response : json_decode( $response );
106
		} else {
107
			$response = array();
108
		}
109
110
		wp_localize_script( 'gv-admin-edd-license', 'GVGlobals', array(
111
			'license_box' => $this->get_license_message( $response )
112
		));
113
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
114
115
		$fields = array(
116
			array(
117
				'name'  => 'edd-activate',
118
				'value' => __('Activate License', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
119
				'data-pending_text' => __('Verifying license&hellip;', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
120
				'data-edd_action' => 'activate_license',
121
				'class' => 'button-primary',
122
			),
123
			array(
124
				'name'  => 'edd-deactivate',
125
				'value' => __('Deactivate License', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
126
				'data-pending_text' => __('Deactivating license&hellip;', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
127
				'data-edd_action' => 'deactivate_license',
128
				'class' => ( empty( $status ) ? 'button-primary hide' : 'button-primary' ),
129
			),
130
			array(
131
				'name'  => 'edd-check',
132
				'value' => __('Check License', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
133
				'data-pending_text' => __('Verifying license&hellip;', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
134
				'title' => 'Check the license before saving it',
135
				'data-edd_action' => 'check_license',
136
				'class' => 'button-secondary',
137
			),
138
		);
139
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
140
141
		$class = 'button gv-edd-action';
142
143
		$class .= ( !empty( $key ) && $status !== 'valid' ) ? '' : ' hide';
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
144
145
		$disabled_attribute = GVCommon::has_cap( 'gravityview_edit_settings' ) ? false : 'disabled';
146
147
		$submit = '<div class="gv-edd-button-wrapper">';
148
		foreach ( $fields as $field ) {
149
			$field['type'] = 'button';
150
			$field['class'] = isset( $field['class'] ) ? $field['class'] . ' '. $class : $class;
151
			$field['style'] = 'margin-left: 10px;';
152
			if( $disabled_attribute ) {
153
				$field['disabled'] = $disabled_attribute;
154
			}
155
			$submit .= $this->Addon->settings_submit( $field, $echo );
156
		}
157
		$submit .= '</div>';
158
159
		return $submit;
160
	}
161
162
	/**
163
	 * Include the EDD plugin updater class, if not exists
164
	 * @since 1.7.4
165
	 * @return void
166
	 */
167
	private function setup_edd() {
168
169
		if( !class_exists('EDD_SL_Plugin_Updater') ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
170
			require_once( GRAVITYVIEW_DIR . 'includes/lib/EDD_SL_Plugin_Updater.php');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
171
		}
172
173
		// setup the updater
174
		$this->EDD_SL_Plugin_Updater = new EDD_SL_Plugin_Updater(
175
			self::url,
176
			GRAVITYVIEW_FILE,
177
			$this->_get_edd_settings()
178
		);
179
180
	}
181
182
	/**
183
	 * Generate the array of settings passed to the EDD license call
184
	 *
185
	 * @since 1.7.4
186
	 *
187
	 * @param string $action The action to send to edd, such as `check_license`
188
	 * @param string $license The license key to have passed to EDD
189
	 *
190
	 * @return array
191
	 */
192
	function _get_edd_settings( $action = '', $license = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
193
194
		// retrieve our license key from the DB
195
		$license_key = empty( $license ) ? trim( $this->Addon->get_app_setting( 'license_key' ) ) : $license;
196
197
		$settings = array(
198
			'version'   => self::version,
199
			'license'   => $license_key,
200
			'item_name' => self::name,
201
			'item_id'   => self::item_id,
202
			'author'    => self::author,
203
			'language'  => get_locale(),
204
			'url'       => home_url(),
205
		);
206
207
		if( !empty( $action ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
208
			$settings['edd_action'] = esc_attr( $action );
209
		}
210
211
		$settings = array_map( 'urlencode', $settings );
212
213
		return $settings;
214
	}
215
216
	/**
217
	 * Perform the call
218
	 * @return array|WP_Error
219
	 */
220
	private function _license_get_remote_response( $data, $license = '' ) {
221
222
		$api_params = $this->_get_edd_settings( $data['edd_action'], $license );
223
224
		$url = add_query_arg( $api_params, self::url );
225
226
		$response = wp_remote_get( $url, array(
0 ignored issues
show
introduced by
wp_remote_get is highly discouraged, please use vip_safe_wp_remote_get() instead.
Loading history...
227
			'timeout'   => 15,
228
			'sslverify' => false,
229
		));
230
231
		if ( is_wp_error( $response ) ) {
232
			return array();
233
		}
234
235
		$license_data = json_decode( wp_remote_retrieve_body( $response ) );
236
237
		// Not JSON
238
		if ( empty( $license_data ) ) {
239
240
			delete_transient( self::status_transient_key );
241
242
			// Change status
243
			return array();
244
		}
245
246
		// Store the license key inside the data array
247
		$license_data->license_key = $license;
248
249
		return $license_data;
250
	}
251
252
	/**
253
	 * Generate the status message displayed in the license field
254
	 *
255
	 * @since 1.7.4
256
	 * @param $license_data
257
	 *
258
	 * @return string
259
	 */
260
	function get_license_message( $license_data ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
261
262
		if( empty( $license_data ) ) {
263
			$message = '';
264
		} else {
265
266
			if( ! empty( $license_data->error ) ) {
267
				$class = 'error';
268
				$string_key = $license_data->error;
269
			} else {
270
				$class = $license_data->license;
271
				$string_key = $license_data->license;
272
			}
273
274
			$message = sprintf( '<p><strong>%s: %s</strong></p>', $this->strings('status'), $this->strings( $string_key, $license_data ) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
275
276
			$message = $this->generate_license_box( $message, $class );
277
		}
278
279
		return $message;
280
	}
281
282
	/**
283
	 * Generate the status message box HTML based on the current status
284
	 *
285
	 * @since 1.7.4
286
	 * @param $message
287
	 * @param string $class
288
	 *
289
	 * @return string
290
	 */
291
	private function generate_license_box( $message, $class = '' ) {
292
293
		$template = '<div id="gv-edd-status" aria-live="polite" aria-busy="false" class="gv-edd-message inline %s">%s</div>';
294
295
		$output = sprintf( $template, esc_attr( $class ), $message );
296
297
		return $output;
298
	}
299
300
	/**
301
	 * Allow pure HTML in settings fields
302
	 *
303
	 * @since 1.17
304
	 *
305
	 * @param array $response License response
306
	 *
307
	 * @return string `html` key of the $field
308
	 */
309
	public function license_details( $response = array() ) {
310
311
		$response = (array) $response;
312
313
		$return = '';
314
		$return .= '<span class="gv-license-details" aria-live="polite" aria-busy="false">';
315
		$return .= '<h3>' . esc_html__( 'License Details:', 'gravityview' ) . '</h3>';
316
317
		if( in_array( rgar( $response, 'license' ), array( 'invalid', 'deactivated' ) ) ) {
318
			$return .= $this->strings( $response['license'], $response );
319
		} elseif( ! empty( $response['license_name'] ) ) {
320
321
			$response_keys = array(
322
				'license_name'   => '',
323
				'license_limit'  => '',
324
				'customer_name'  => '',
325
				'customer_email' => '',
326
				'site_count'     => '',
327
				'expires'        => '',
328
				'upgrades'       => ''
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
329
			);
330
331
			// Make sure all the keys are set
332
			$response = wp_parse_args( $response, $response_keys );
333
334
			$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' ) );
335
			$local_text = ( ! empty( $response['is_local'] ) ? '<span class="howto">' . __( 'This development site does not count toward license activation limits', 'gravityview' ) . '</span>' : '' );
336
			$details = array(
337
				'license'     => sprintf( esc_html__( 'License level: %s', 'gravityview' ), esc_html( $response['license_name'] ), esc_html( $response['license_limit'] ) ),
338
				'licensed_to' => sprintf( esc_html_x( 'Licensed to: %1$s (%2$s)', '1: Customer name; 2: Customer email', 'gravityview' ), esc_html__( $response['customer_name'] ), esc_html__( $response['customer_email'] ) ) . $login_link,
339
				'activations' => sprintf( esc_html__( 'Activations: %d of %s sites', 'gravityview' ), intval( $response['site_count'] ), esc_html( $response['license_limit'] ) ) . $local_text,
340
				'expires'     => sprintf( esc_html__( 'Renew on: %s', 'gravityview' ), date_i18n( get_option( 'date_format' ), strtotime( $response['expires'] ) - DAY_IN_SECONDS ) ),
341
				'upgrade'     => $this->get_upgrade_html( $response['upgrades'] ),
342
			);
343
344
			if ( ! empty( $response['error'] ) && 'expired' === $response['error'] ) {
345
				unset( $details['upgrade'] );
346
				$details['expires'] = '<div class="error inline"><p>' . $this->strings( 'expired', $response ) . '</p></div>';
347
			}
348
349
			$return .= '<ul><li>' . implode( '</li><li>', array_filter( $details ) ) . '</li></ul>';
350
		}
351
352
		$return .= '</span>';
353
354
		return $return;
355
	}
356
357
	/**
358
	 * Display possible upgrades for a license
359
	 *
360
	 * @since 1.17
361
	 *
362
	 * @param array $upgrades Array of upgrade paths, returned from the GV website
363
	 *
364
	 * @return string HTML list of upgrades available for the current license
365
	 */
366
	function get_upgrade_html( $upgrades ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
367
368
		$output = '';
369
370
		if( ! empty( $upgrades ) ) {
371
372
			$locale_parts = explode( '_', get_locale() );
373
374
			$is_english = ( 'en' === $locale_parts[0] );
375
376
			$output .= '<h4>' . esc_html__( 'Upgrades available:', 'gravityview' ) . '</h4>';
377
378
			$output .= '<ul class="ul-disc">';
379
380
			foreach ( $upgrades as $upgrade_id => $upgrade ) {
381
382
				$upgrade = (object) $upgrade;
383
384
				$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 ) );
385
386
				if( $is_english && isset( $upgrade->description ) ) {
387
					$message = esc_html( $upgrade->description );
388
				} else {
389
					switch( $upgrade->price_id ) {
390
						// Interstellar
391
						case 1:
392
						default:
393
							$message = esc_html__( 'Get access to Extensions', 'gravityview' );
394
							break;
395
						// Galactic
396
						case 2:
0 ignored issues
show
Unused Code introduced by
// Galactic case 2: ...avityview'); break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
397
							$message = esc_html__( 'Get access to Entry Importer and other Premium plugins', 'gravityview' );
398
							break;
399
					}
400
				}
401
402
				$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 );
403
			}
404
			$output .= '</ul>';
405
		}
406
407
		return $output;
408
	}
409
410
	/**
411
	 * Perform the call to EDD based on the AJAX call or passed data
412
	 *
413
	 * @since 1.7.4
414
	 *
415
	 * @param array $array {
416
	 * @type string $license The license key
417
	 * @type string $edd_action The EDD action to perform, like `check_license`
418
	 * @type string $field_id The ID of the field to check
419
	 * @type boolean $update Whether to update plugin settings. Prevent updating the data by setting an `update` key to false
420
	 * @type string $format If `object`, return the object of the license data. Else, return the JSON-encoded object
421
	 * }
422
	 *
423
	 * @return mixed|string|void
424
	 */
425
	public function license_call( $array = array() ) {
426
427
		$is_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
428
		$data = empty( $array ) ? $_POST['data'] : $array;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
429
		$has_cap = GVCommon::has_cap( 'gravityview_edit_settings' );
430
431
		if ( $is_ajax && empty( $data['license'] ) ) {
432
			die( - 1 );
0 ignored issues
show
Coding Style Compatibility introduced by
The method license_call() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
433
		}
434
435
		// If the user isn't allowed to edit settings, show an error message
436
		if( ! $has_cap ) {
437
			$license_data = new stdClass();
438
			$license_data->error = 'capability';
439
			$license_data->message = $this->get_license_message( $license_data );
440
			$json = json_encode( $license_data );
441
		} else {
442
443
			$license      = esc_attr( rgget( 'license', $data ) );
444
			$license_data = $this->_license_get_remote_response( $data, $license );
445
446
			// Empty is returned when there's an error.
447
			if ( empty( $license_data ) ) {
448
				if ( $is_ajax ) {
449
					exit( json_encode( array() ) );
0 ignored issues
show
Coding Style Compatibility introduced by
The method license_call() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
450
				} else { // Non-ajax call
451
					return json_encode( array() );
452
				}
453
			}
454
455
			$license_data->details = $this->license_details( $license_data );
456
			$license_data->message = $this->get_license_message( $license_data );
457
458
			$json = json_encode( $license_data );
459
460
			$update_license = ( ! isset( $data['update'] ) || ! empty( $data['update'] ) );
461
462
			$is_check_action_button = ( 'check_license' === $data['edd_action'] && defined( 'DOING_AJAX' ) && DOING_AJAX );
463
464
			// Failed is the response from trying to de-activate a license and it didn't work.
465
			// This likely happened because people entered in a different key and clicked "Deactivate",
466
			// meaning to deactivate the original key. We don't want to save this response, since it is
467
			// most likely a mistake.
468
			if ( $license_data->license !== 'failed' && ! $is_check_action_button && $update_license ) {
0 ignored issues
show
introduced by
Found "!== '". Use Yoda Condition checks, you must
Loading history...
469
470
				if ( ! empty( $data['field_id'] ) ) {
471
					set_transient( self::status_transient_key, $license_data, DAY_IN_SECONDS );
472
				}
473
474
				$this->license_call_update_settings( $license_data, $data );
475
			}
476
		} // End $has_cap
477
478
		if ( $is_ajax ) {
479
			exit( $json );
0 ignored issues
show
Coding Style Compatibility introduced by
The method license_call() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
480
		} else { // Non-ajax call
481
			return ( rgget('format', $data ) === 'object' ) ? $license_data : $json;
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
482
		}
483
	}
484
485
	/**
486
	 * Update the license after fetching it
487
	 * @param object $license_data
488
	 * @return void
489
	 */
490
	private function license_call_update_settings( $license_data, $data ) {
491
492
		// Update option with passed data license
493
		$settings = $this->Addon->get_app_settings();
494
495
        $settings['license_key'] = $license_data->license_key = trim( $data['license'] );
496
		$settings['license_key_status'] = $license_data->license;
497
		$settings['license_key_response'] = (array)$license_data;
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
498
499
		$this->Addon->update_app_settings( $settings );
500
	}
501
502
	/**
503
	 * URL to direct license renewal, or if license key is not set, then just the account page
504
	 * @since 1.13.1
505
	 * @param  object|null $license_data Object with license data
506
	 * @return string Renewal or account URL
507
	 */
508
	private function get_license_renewal_url( $license_data ) {
509
		$license_data = is_array( $license_data ) ? (object)$license_data : $license_data;
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
510
		$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/';
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
511
		return $renew_license_url;
512
	}
513
514
	/**
515
	 * Override the text used in the GravityView EDD license Javascript
516
	 *
517
	 * @param  array|null $status Status to get. If empty, get all strings.
518
	 * @param  object|null $license_data Object with license data
519
	 * @return array          Modified array of content
520
	 */
521
	public function strings( $status = NULL, $license_data = null ) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
522
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
523
524
		$strings = array(
525
			'status' => esc_html__('Status', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
526
			'error' => esc_html__('There was an error processing the request.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
527
			'failed'  => esc_html__('Could not deactivate the license. The license key you attempted to deactivate may not be active or valid.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
528
			'site_inactive' => esc_html__('The license key is valid, but it has not been activated for this site.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
529
			'inactive' => esc_html__('The license key is valid, but it has not been activated for this site.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
530
			'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>' ),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
531
			'deactivated' => esc_html__('The license has been deactivated.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
532
			'valid' => esc_html__('The license key is valid and active.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
533
			'invalid' => esc_html__('The license key entered is invalid.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
534
			'missing' => esc_html__('Invalid license key.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
535
			'revoked' => esc_html__('This license key has been revoked.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
536
			'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>' ),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
537
			'capability' => esc_html__( 'You don\'t have the ability to edit plugin settings.', 'gravityview' ),
538
539
			'verifying_license' => esc_html__('Verifying license&hellip;', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
540
			'activate_license' => esc_html__('Activate License', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
541
			'deactivate_license' => esc_html__('Deactivate License', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
542
			'check_license' => esc_html__('Verify License', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
543
		);
544
545
		if( empty( $status ) ) {
546
			return $strings;
547
		}
548
549
		if( isset( $strings[ $status ] ) ) {
550
			return $strings[ $status ];
551
		}
552
553
		return NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
554
	}
555
556
}