PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.5.0
GiveWP – Donation Plugin and Fundraising Platform v2.5.0
4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / class-give-license-handler.php
give / includes Last commit date
admin 7 years ago api 7 years ago deprecated 7 years ago donors 7 years ago emails 7 years ago forms 7 years ago frontend 7 years ago gateways 7 years ago libraries 7 years ago payments 7 years ago actions.php 7 years ago ajax-functions.php 7 years ago class-give-async-process.php 7 years ago class-give-background-updater.php 7 years ago class-give-cache-setting.php 7 years ago class-give-cache.php 7 years ago class-give-cli-commands.php 7 years ago class-give-comment.php 7 years ago class-give-cron.php 7 years ago class-give-db-comments-meta.php 7 years ago class-give-db-comments.php 7 years ago class-give-db-donor-meta.php 7 years ago class-give-db-donors.php 7 years ago class-give-db-form-meta.php 7 years ago class-give-db-logs-meta.php 7 years ago class-give-db-logs.php 7 years ago class-give-db-meta.php 7 years ago class-give-db-payment-meta.php 7 years ago class-give-db-sequential-ordering.php 7 years ago class-give-db-sessions.php 7 years ago class-give-db.php 7 years ago class-give-donate-form.php 7 years ago class-give-donor-wall-widget.php 7 years ago class-give-donor.php 7 years ago class-give-email-access.php 7 years ago class-give-license-handler.php 7 years ago class-give-logging.php 7 years ago class-give-readme-parser.php 7 years ago class-give-roles.php 7 years ago class-give-scripts.php 7 years ago class-give-session.php 7 years ago class-give-stats.php 7 years ago class-give-template-loader.php 8 years ago class-give-tooltips.php 7 years ago class-give-translation.php 8 years ago class-notices.php 7 years ago country-functions.php 7 years ago currencies-list.php 7 years ago currency-functions.php 7 years ago error-tracking.php 7 years ago filters.php 7 years ago formatting.php 7 years ago install.php 7 years ago login-register.php 7 years ago misc-functions.php 7 years ago plugin-compatibility.php 7 years ago post-types.php 7 years ago price-functions.php 7 years ago process-donation.php 7 years ago setting-functions.php 7 years ago shortcodes.php 7 years ago template-functions.php 7 years ago user-functions.php 7 years ago
class-give-license-handler.php
918 lines
1 <?php
2 /**
3 * Give License handler
4 *
5 * @package Give
6 * @subpackage Admin/License
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Give_License' ) ) :
18
19 /**
20 * Give_License Class
21 *
22 * This class simplifies the process of adding license information
23 * to new Give add-ons.
24 *
25 * @since 1.0
26 */
27 class Give_License {
28
29 /**
30 * File
31 *
32 * @access private
33 * @since 1.0
34 *
35 * @var string
36 */
37 private $file;
38
39 /**
40 * License
41 *
42 * @access private
43 * @since 1.0
44 *
45 * @var string
46 */
47 private $license;
48
49 /**
50 * Item name
51 *
52 * @access private
53 * @since 1.0
54 *
55 * @var string
56 */
57 private $item_name;
58
59 /**
60 * Item ID
61 *
62 * @access private
63 * @since 2.2.4
64 *
65 * @var int
66 */
67 private $item_id;
68
69 /**
70 * License Information object.
71 *
72 * @access private
73 * @since 1.7
74 *
75 * @var object
76 */
77 private $license_data;
78
79 /**
80 * Item shortname
81 *
82 * @access private
83 * @since 1.0
84 *
85 * @var string
86 */
87 private $item_shortname;
88
89 /**
90 * Version
91 *
92 * @access private
93 * @since 1.0
94 *
95 * @var string
96 */
97 private $version;
98
99 /**
100 * Author
101 *
102 * @access private
103 * @since 1.0
104 *
105 * @var string
106 */
107 private $author;
108
109 /**
110 * Plugin directory name
111 *
112 * @access private
113 * @since 2.5.0
114 *
115 * @var string
116 */
117 private $plugin_dirname;
118
119 /**
120 * Website URL
121 *
122 * @access private
123 * @since 1.0
124 *
125 * @var string
126 */
127 private static $site_url = 'https://givewp.com/';
128
129 /**
130 * API URL
131 *
132 * @access private
133 * @since 1.0
134 *
135 * @var string
136 */
137 private $api_url = 'https://givewp.com/edd-sl-api/';
138
139 /**
140 * array of licensed addons
141 *
142 * @since 2.1.4
143 * @access private
144 *
145 * @var array
146 */
147 private static $licensed_addons = array();
148
149 /**
150 * Account URL
151 *
152 * @access private
153 * @since 1.7
154 *
155 * @var null|string
156 */
157 private static $account_url = 'https://givewp.com/my-account/';
158
159 /**
160 * Downloads URL
161 *
162 * @access private
163 * @since 2.5.0
164 *
165 * @var null|string
166 */
167 private static $downloads_url = 'https://givewp.com/my-downloads/';
168
169 /**
170 * Checkout URL
171 *
172 * @access private
173 * @since 1.7
174 *
175 * @var null|string
176 */
177 private static $checkout_url = 'https://givewp.com/checkout/';
178
179 /**
180 * Class Constructor
181 *
182 * Set up the Give License Class.
183 *
184 * @access public
185 *
186 * @param string $_file
187 * @param string $_item_name
188 * @param string $_version
189 * @param string $_author
190 * @param string $_optname
191 * @param string $_api_url
192 * @param string $_checkout_url
193 * @param string $_account_url
194 * @param int $_item_id
195 *
196 * @since 1.0
197 */
198 public function __construct(
199 $_file,
200 $_item_name,
201 $_version,
202 $_author,
203 $_optname = null,
204 $_api_url = null,
205 $_checkout_url = null,
206 $_account_url = null,
207 $_item_id = null
208 ) {
209
210 // Only load in wp-admin.
211 if ( ! is_admin() ) {
212 return;
213 }
214
215 if ( is_numeric( $_item_id ) ) {
216 $this->item_id = absint( $_item_id );
217 }
218
219 $this->file = $_file;
220 $this->item_name = $_item_name;
221 $this->plugin_dirname = dirname( plugin_basename( $this->file ) );
222 $this->item_shortname = self::get_short_name( $this->item_name );
223 $this->license_data = self::get_license_by_plugin_dirname( $this->plugin_dirname );
224 $this->version = $_version;
225 $this->license = ! empty( $this->license_data['license_key'] ) ? $this->license_data['license_key'] : '';
226 $this->author = $_author;
227 $this->api_url = is_null( $_api_url ) ? $this->api_url : $_api_url;
228 self::$checkout_url = is_null( $_checkout_url ) ? self::$checkout_url : $_checkout_url;
229 self::$account_url = is_null( $_account_url ) ? self::$account_url : $_account_url;
230 $this->auto_updater_obj = null;
231
232 // Add plugin to registered licenses list.
233 array_push( self::$licensed_addons, plugin_basename( $this->file ) );
234 }
235
236
237 /**
238 * Get plugin shortname
239 *
240 * @param $plugin_name
241 *
242 * @return string
243 * @since 2.1.0
244 * @access public
245 */
246 public static function get_short_name( $plugin_name ) {
247 $plugin_name = trim( str_replace( 'Give - ', '', $plugin_name ) );
248 $plugin_name = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $plugin_name ) ) );
249
250 return $plugin_name;
251 }
252
253 /**
254 * Activate License
255 *
256 * Activate the license key.
257 *
258 * @access public
259 * @return void
260 * @since 1.0
261 */
262 public function activate_license() {
263 }
264
265 /**
266 * Deactivate License
267 *
268 * Deactivate the license key.
269 *
270 * @access public
271 * @return void
272 * @since 1.0
273 */
274 public function deactivate_license() {
275 }
276
277
278 /**
279 * Get license information.
280 *
281 * @param string $edd_action
282 * @param bool $response_in_array
283 *
284 * @return mixed
285 * @deprecated 2.5.0 Use self::request_license_api instead.
286 *
287 * @since 1.8.9
288 * @access public
289 */
290 public function get_license_info( $edd_action = '', $response_in_array = false ) {
291
292 if ( empty( $edd_action ) ) {
293 return false;
294 }
295
296 give_doing_it_wrong( __FUNCTION__, 'Use self::request_license_api instead', '2.5.0' );
297
298 // Data to send to the API.
299 $api_params = array(
300 'edd_action' => $edd_action, // never change from "edd_" to "give_"!
301 'license' => $this->license,
302 'item_name' => urlencode( $this->item_name ),
303 );
304
305 return self::request_license_api( $api_params, $response_in_array );
306 }
307
308 /**
309 * Return licensed addons info
310 *
311 * Note: note only for internal logic
312 *
313 * @return array
314 * @since 2.1.4
315 */
316 static function get_licensed_addons() {
317 return self::$licensed_addons;
318 }
319
320
321 /**
322 * Check if license key attached to subscription
323 *
324 * @param string $license_key
325 *
326 * @return array
327 * @since 2.5.0
328 */
329 static function is_subscription( $license_key = '' ) {
330 // Check if current license is part of subscription or not.
331 $subscriptions = get_option( 'give_subscriptions' );
332 $subscription = array();
333
334 if ( $subscriptions ) {
335 foreach ( $subscriptions as $subs ) {
336 if ( in_array( $license_key, $subs['licenses'] ) ) {
337 $subscription = $subs;
338 break;
339 }
340 }
341 }
342
343 return $subscription;
344 }
345
346 /**
347 * Get license information.
348 *
349 * @param array $api_params
350 * @param bool $response_in_array
351 *
352 * @return array|WP_Error
353 * @since 1.8.9
354 * @access public
355 */
356 public static function request_license_api( $api_params = array(), $response_in_array = false ) {
357 // Bailout.
358 if ( empty( $api_params['edd_action'] ) ) {
359 return new WP_Error( 'give-invalid-edd-action', __( 'Valid edd_action not defined', 'give' ) );
360 }
361
362 // Data to send to the API.
363 $default_api_params = array(
364 // 'edd_action' => $edd_action, never change from "edd_" to "give_"!
365 // 'license' => $this->license,
366 // 'item_name' => urlencode( $this->item_name ),
367 'url' => home_url(),
368 );
369
370 $api_params = wp_parse_args( $api_params, $default_api_params );
371
372 // Call the API.
373 $response = wp_remote_post(
374 self::$checkout_url,
375 apply_filters(
376 'give_request_license_api_args',
377 array(
378 'timeout' => 15,
379 'sslverify' => false,
380 'body' => $api_params,
381 )
382 )
383 );
384
385 // Make sure there are no errors.
386 if ( is_wp_error( $response ) ) {
387 return $response;
388 }
389
390 return json_decode( wp_remote_retrieve_body( $response ), $response_in_array );
391 }
392
393 /**
394 * Get license by plugin dirname
395 *
396 * @param string $plugin_dirname
397 *
398 * @return array
399 *
400 * @since 2.5.0
401 * @access public
402 */
403 public static function get_license_by_plugin_dirname( $plugin_dirname ) {
404 $license = array();
405 $give_licenses = get_option( 'give_licenses', array() );
406
407 if ( ! empty( $give_licenses ) ) {
408 foreach ( $give_licenses as $give_license ) {
409
410 // Logic to match all access pass license to add-on.
411 $compares = $give_license['is_all_access_pass']
412 ? $give_license['download']
413
414 // Prevent PHP notice if somehow automatic update does not run properly.
415 // Because plugin_slug will only define in updated license rest api response.
416 : array( array( 'plugin_slug' => ! empty( $give_license['plugin_slug'] ) ? $give_license['plugin_slug'] : '' ) );
417
418 foreach ( $compares as $compare ) {
419 if ( ! empty( $compare['plugin_slug'] ) && $plugin_dirname === $compare['plugin_slug'] ) {
420 $license = $give_license;
421 break;
422 }
423 }
424 }
425 }
426
427 return $license;
428 }
429
430
431 /**
432 * Get checkout url
433 *
434 * @return string|null
435 * @since 2.5.0
436 */
437 public static function get_checkout_url() {
438 return self::$checkout_url;
439 }
440
441 /**
442 * Get account url
443 *
444 * @return string|null
445 * @since 2.5.0
446 */
447 public static function get_account_url() {
448 return self::$account_url;
449 }
450
451 /**
452 * Get downloads url
453 *
454 * @return string|null
455 * @since 2.5.0
456 */
457 public static function get_downloads_url() {
458 return self::$downloads_url;
459 }
460
461 /**
462 * Get account url
463 *
464 * @return string|null
465 * @since 2.5.0
466 */
467 public static function get_website_url() {
468 return self::$site_url;
469 }
470
471
472 /**
473 * Get plugin information by id.
474 * Note: only for internal use
475 *
476 * @param string $plugin_slug
477 *
478 * @return array
479 * @since 2.5.0
480 */
481 public static function get_plugin_by_slug( $plugin_slug ) {
482 $give_plugins = give_get_plugins();
483 $matching_list = wp_list_pluck( $give_plugins, 'Dir', 'Path' );
484 $is_match_found = array_search( $plugin_slug, $matching_list, true );
485
486 return $is_match_found ? $give_plugins[ $is_match_found ] : array();
487 }
488
489 /**
490 * Get plugin information by id.
491 * Note: only for internal use
492 *
493 * @param string $plugin_slug
494 *
495 * @return string
496 * @since 2.5.0
497 */
498 public static function build_plugin_name_from_slug( $plugin_slug ) {
499 $plugin_name = str_replace( array( '-', 'give ' ), array( ' ', 'Give - ' ), $plugin_slug );
500
501 return ucwords( $plugin_name );
502 }
503
504 /**
505 * Render license section
506 *
507 * @return string
508 * @since 2.5.0
509 */
510 public static function render_licenses_list() {
511 $give_plugins = give_get_plugins( array( 'only_premium_add_ons' => true ) );
512 $give_licenses = get_option( 'give_licenses', array() );
513
514 // Get all access pass licenses
515 $all_access_pass_licenses = array();
516 $all_access_pass_addon_list = array();
517 foreach ( $give_licenses as $key => $give_license ) {
518 if ( $give_license['is_all_access_pass'] ) {
519 $all_access_pass_licenses[ $key ] = $give_license;
520
521 foreach ( $give_license['download'] as $download ) {
522 $all_access_pass_addon_list[] = $download['plugin_slug'];
523 }
524 }
525 }
526
527 $html = array(
528 'unlicensed' => '',
529 'licensed' => '',
530 'all_access_licensed' => '',
531 );
532
533 foreach ( $give_plugins as $give_plugin ) {
534 if ( in_array( $give_plugin['Dir'], $all_access_pass_addon_list ) ) {
535 continue;
536 }
537
538 $addon_license = self::get_license_by_plugin_dirname( $give_plugin['Dir'] );
539 $html_arr_key = 'unlicensed';
540
541 if ( $addon_license ) {
542 $html_arr_key = 'licensed';
543 }
544
545 $html["{$html_arr_key}"] .= self::html_by_plugin( $give_plugin );
546 }
547
548 if ( ! empty( $all_access_pass_licenses ) ) {
549 foreach ( $all_access_pass_licenses as $key => $all_access_pass_license ) {
550 $html['all_access_licensed'] .= self::html_by_license( $all_access_pass_license );
551 }
552 }
553
554 ksort( $html );
555
556 // After sorting order will be all_access_licensed -> licensed -> unlicensed
557
558 return implode( '', $html );
559 }
560
561 /**
562 * Get add-on item html
563 * Note: only for internal use
564 *
565 * @param $plugin
566 *
567 * @return string
568 * @since 2.5.0
569 */
570 public static function html_by_plugin( $plugin ) {
571 // Bailout.
572 if ( empty( $plugin ) ) {
573 return '';
574 }
575
576 ob_start();
577 $license = self::get_license_by_plugin_dirname( $plugin['Dir'] );
578
579 $default_plugin = array(
580 'ChangeLogSlug' => $plugin['Dir'],
581 'DownloadURL' => '',
582 );
583
584 if ( false !== strpos( $default_plugin['ChangeLogSlug'], '-gateway' ) ) {
585 // We found that each gateway addon does not have `-gateway` in changelog file slug
586 $default_plugin['ChangeLogSlug'] = str_replace( '-gateway', '', $default_plugin['ChangeLogSlug'] );
587 }
588
589 if ( $license ) {
590 $license['renew_url'] = self::$checkout_url . "?edd_license_key={$license['license_key']}";
591 $default_plugin['ChangeLogSlug'] = $license['readme'];
592 $default_plugin['DownloadURL'] = $license['download'];
593 }
594
595 $plugin['License'] = $license = wp_parse_args(
596 $license, array(
597 'item_name' => str_replace( 'give-', '', $plugin['Dir'] ),
598 'purchase_link' => $plugin['PluginURI'],
599 )
600 );
601
602 $plugin = wp_parse_args( $plugin, $default_plugin );
603 ?>
604 <div class="give-addon-wrap">
605 <div class="give-addon-inner">
606 <?php echo self::html_license_row( $license, $plugin ); ?>
607 <?php echo self::html_plugin_row( $plugin ); ?>
608 </div>
609 </div>
610 <?php
611
612 return ob_get_clean();
613 }
614
615 /**
616 * Get add-on item html
617 * Note: only for internal use
618 *
619 * @param array $license
620 *
621 * @return string
622 * @since 2.5.0
623 */
624 private static function html_by_license( $license ) {
625 ob_start();
626
627 $license['renew_url'] = self::$checkout_url . "?edd_license_key={$license['license_key']}";
628 ?>
629 <div class="give-addon-wrap">
630 <div class="give-addon-inner">
631 <?php
632 echo self::html_license_row( $license );
633
634 foreach ( $license['download'] as $addon ) {
635 $default_plugin = array(
636 'Name' => $addon['name'],
637 'ChangeLogSlug' => $addon['readme'],
638 'Version' => $addon['current_version'],
639 'Status' => 'not installed',
640 'DownloadURL' => $addon['file'],
641 );
642
643 $plugin = wp_parse_args(
644 self::get_plugin_by_slug( $addon['plugin_slug'] ),
645 $default_plugin
646 );
647
648 $plugin['Name'] = false !== strpos( $plugin['Name'], 'Give' )
649 ? $plugin['Name']
650 : self::build_plugin_name_from_slug( $addon['plugin_slug'] );
651
652 $plugin['License'] = $license;
653
654 echo self::html_plugin_row( $plugin );
655 }
656 ?>
657 </div>
658 </div>
659 <?php
660
661 return ob_get_clean();
662 }
663
664
665 /**
666 * license row html
667 *
668 * @param array $license
669 * @param array $plugin
670 *
671 * @return string
672 * @since 2.5.0
673 */
674 private static function html_license_row( $license, $plugin = array() ) {
675 ob_start();
676
677 $is_license = $license && ! empty( $license['license_key'] );
678 $license_key = $is_license ? $license['license_key'] : '';
679 $license_is_inactive = $license_key && ! in_array( $license['license'], array( 'valid', 'expired' ) );
680 $expires_timestamp = $is_license ? strtotime( $license['expires'] ) : '';
681 $is_license_expired = $is_license && ( 'expired' === $license['license'] || $expires_timestamp < current_time( 'timestamp', 1 ) );
682 ?>
683 <div class="give-license-row give-clearfix">
684 <div class="give-license-notice-container"></div>
685 <div class="give-license-top give-clearfix">
686
687 <div class="give-license-top-column give-license-key-field-wrap">
688
689 <div class="give-license__key<?php echo $license_key ? ' give-has-license-key' : ''; ?>">
690 <?php $value = $license_key ? give_hide_char( $license['license_key'], 5 ) : ''; ?>
691 <label for="give-license-addon-key-field" class="give-license-top-header"><?php _e( 'License Key', 'give' ); ?></label>
692 <input id="give-license-addon-key-field" type="text" autocomplete="off" value="<?php echo $value; ?>"<?php echo $value ? ' readonly' : ''; ?>>
693 <?php if ( ! $license_key ) : ?>
694 <button class="give-button__license-activate button-primary" data-addon="<?php echo $plugin['Dir']; ?>">
695 <?php _e( 'Activate', 'give' ); ?>
696 </button>
697 <?php elseif ( $license_is_inactive ): ?>
698 <button class="give-button__license-reactivate button-primary" data-addon="<?php echo $plugin['Dir']; ?>" data-license="<?php echo $license['license_key'] ?>">
699 <?php _e( 'Reactivate', 'give' ); ?>
700 </button>
701 <?php else : ?>
702
703 <?php
704 echo sprintf(
705 '<button class="give-license__deactivate button button-secondary" data-license-key="%2$s" data-item-name="%3$s" data-plugin-dirname="%5$s" data-nonce="%4$s">%1$s</button>',
706 __( 'Deactivate', 'give' ),
707 $license['license_key'],
708 $license['item_name'],
709 wp_create_nonce( "give-deactivate-license-{$license['item_name']}" ),
710 ! empty( $license['plugin_slug'] ) ? $license['plugin_slug'] : ''
711 ); ?>
712
713 <?php endif; ?>
714
715 <div class="give-license__status">
716 <?php
717 echo $license_key && ! $license_is_inactive
718 ? sprintf(
719 '<span class="dashicons dashicons-%2$s"></span>&nbsp;%1$s',
720 $is_license_expired
721 ? __( 'License is expired. Please activate your license key.', 'give' )
722 : __( 'License is active and you are receiving updates and support.', 'give' ),
723 $is_license_expired
724 ? 'no'
725 : 'yes'
726 )
727 : sprintf(
728 '<span class="dashicons dashicons-no"></span> %1$s %2$s',
729 __( 'License is inactive.', 'give' ),
730 $license_is_inactive
731 ? sprintf(
732 __( 'Please <a href="%1$s" target="_blank">Visit your dashboard</a> to check this license details and activate this license to receive updates and support.', 'give' ),
733 self::get_account_url()
734 )
735 : __( 'Please activate your license key.', 'give' )
736 );
737 ?>
738 </div>
739 </div>
740 </div>
741
742 <div class="give-license-top-column give-license-info-field-wrap">
743 <h3 class="give-license-top-header"><?php _e( 'License Information', 'give' ); ?></h3>
744 <?php
745 // @todo: handle all license status;
746 if ( $license_key ) : ?>
747
748 <?php if ( $license_key ) : ?>
749 <?php
750 echo sprintf(
751 '<p class="give-license-renewal-date"><span class="dashicons dashicons-calendar-alt"></span> <strong>%1$s</strong> %2$s</p>',
752 $is_license_expired ? __( 'Expired:' ) : __( 'Renews:' ),
753 date( give_date_format(), $expires_timestamp )
754 );
755 ?>
756 <?php endif; ?>
757
758 <?php if ( $is_license_expired ) {
759 // @todo: need to test renew license link
760 echo sprintf(
761 '<a href="%1$s" target="_blank">%2$s</a>',
762 $license['renew_url'],
763 __( 'Renew to manage sites', 'give' )
764 );
765 } elseif ( $license_key ) {
766 if ( ! $license['activations_left'] ) {
767 echo sprintf(
768 '<span class="give-license-activations-left">%1$s</span>',
769 __( 'No activation remaining', 'give' )
770 );
771 } else {
772 echo sprintf(
773 '<span class="give-license-activations-left"><span class="give-license-activations-remaining-icon wp-ui-highlight">%1$s</span> %2$s</span>',
774 $license['activations_left'],
775 _n( 'Activation Remaining', 'Activations Remaining', $license['activations_left'], 'give' )
776 );
777 }
778 } ?>
779 <?php else : ?>
780
781 <p class="give-field-description"><?php _e( 'This is an unlicensed add-on and is not receiving updates or support. Please activate your license key to fix the issue.', 'give' ); ?></p>
782
783 <?php endif; ?>
784 </div>
785
786 <div class="give-license-top-column">
787 <h3 class="give-license-top-header"><?php _e( 'License Actions', 'give' ); ?></h3>
788
789 <?php
790 // Purchase license link.
791 if ( ! $license_key ) : ?>
792 <?php
793 echo sprintf(
794 '<a class="give-button button-secondary" href="%1$s" target="_blank">%2$s</a>',
795 $license['purchase_link'],
796 __( 'Purchase License', 'give' )
797 );
798 ?>
799 <?php endif; ?>
800
801 <?php
802 // Manage license link on GiveWP.com
803 if ( ! $is_license_expired && $license_key ) {
804 echo sprintf(
805 '<a href="%1$spurchase-history/?license_id=%2$s&action=manage_licenses&payment_id=%3$s" target="_blank" class="give-license-action-link">%4$s</a>',
806 trailingslashit( Give_License::get_website_url() ),
807 $license['license_id'],
808 $license['payment_id'],
809 __( 'Manage License', 'give' )
810 );
811 echo sprintf(
812 '<a href="%1$spriority-support/" target="_blank" class="give-license-action-link">%2$s</a>',
813 trailingslashit( Give_License::get_website_url() ),
814 __( 'Access Support', 'give' )
815 );
816 }
817 ?>
818
819 </div>
820 </div>
821 </div>
822 <?php
823 return ob_get_clean();
824 }
825
826
827 /**
828 * Plugin row html
829 *
830 * @param array $plugin
831 *
832 * @return string
833 * @since 2.5.0
834 */
835 public static function html_plugin_row( $plugin ) {
836 // Bailout.
837 if ( ! $plugin ) {
838 return '';
839 }
840
841 $is_license = $plugin['License'] && ! empty( $plugin['License']['license_key'] );
842 $expires_timestamp = $is_license ? strtotime( $plugin['License']['expires'] ) : '';
843 $is_license_expired = $is_license && ( 'expired' === $plugin['License']['license'] || $expires_timestamp < current_time( 'timestamp', 1 ) );
844 ob_start();
845 ?>
846 <div class="give-addon-info-wrap give-clearfix">
847
848 <div class="give-addon-info-left">
849 <span class="give-addon-name">
850 <?php echo $plugin['Name']; ?>
851 </span>
852 <span class="give-addon-version">
853 <?php echo sprintf( '%1$s %2$s', __( 'Version' ), $plugin['Version'] ); ?>
854 </span>
855 </div>
856
857 <div class="give-addon-info-right">
858 <?php
859 echo sprintf(
860 '<a href="%1$s" class="give-ajax-modal give-addon-view-changelog" title="%3$s">%2$s</a>',
861 give_modal_ajax_url(
862 array(
863 'url' => filter_var( $plugin['ChangeLogSlug'], FILTER_VALIDATE_URL )
864 ? urldecode_deep( $plugin['ChangeLogSlug'] )
865 : urlencode_deep( give_get_addon_readme_url( $plugin['ChangeLogSlug'] ) ),
866 'show_changelog' => 1,
867 )
868 ),
869 __( 'View Changelog', 'give' ),
870 __( 'Changelog of' ) . " {$plugin['Name']}"
871 );
872 ?>
873
874 <?php
875 // Activation status.
876 if ( in_array( $plugin['Status'], array( 'active', 'inactive' ) ) ) {
877 echo sprintf(
878 '<span class="give-addon-activation-status give-addon-activation-status__%1$s">%1$s</span>',
879 'active' === $plugin['Status'] ? __( 'activated', 'give' ) : __( 'installed', 'give' )
880 );
881 }
882
883 printf(
884 '<%3$s class="give-button button button-secondary button-small" href="%1$s"%4$s><span class="dashicons dashicons-download"></span>%2$s</%3$s>',
885 $plugin['DownloadURL'],
886 __( 'Download', 'give' ),
887 $is_license_expired || ! $plugin['DownloadURL'] ? 'button' : 'a',
888 $is_license_expired || ! $plugin['DownloadURL'] ? ' disabled' : ''
889 );
890 ?>
891 </div>
892 </div>
893 <?php
894
895 return ob_get_clean();
896 }
897
898
899 /**
900 * Get refresh license status
901 *
902 * @return mixed|void
903 * @since 2.5.0
904 */
905 public static function refresh_license_status() {
906 return get_option(
907 'give_licenses_refreshed_last_checked',
908 array(
909 'compare' => date( 'Ymd' ),
910 'time' => current_time( 'timestamp', 1 ),
911 'count' => 0,
912 )
913 );
914 }
915 }
916
917 endif; // end class_exists check.
918